Misha Brukman | 2a8350a | 2005-02-05 02:24:26 +0000 | [diff] [blame] | 1 | //===- AlphaISelPattern.cpp - A pattern matching inst selector for Alpha --===// |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2 | // |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 7 | // |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a pattern matching instruction selector for Alpha. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Alpha.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 15 | #include "AlphaRegisterInfo.h" |
| 16 | #include "llvm/Constants.h" // FIXME: REMOVE |
| 17 | #include "llvm/Function.h" |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 20 | #include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE |
| 21 | #include "llvm/CodeGen/MachineFunction.h" |
| 22 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 23 | #include "llvm/CodeGen/SelectionDAG.h" |
| 24 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 25 | #include "llvm/CodeGen/SSARegMap.h" |
| 26 | #include "llvm/Target/TargetData.h" |
| 27 | #include "llvm/Target/TargetLowering.h" |
| 28 | #include "llvm/Support/MathExtras.h" |
| 29 | #include "llvm/ADT/Statistic.h" |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Debug.h" |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 31 | #include "llvm/Support/CommandLine.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 32 | #include <set> |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 33 | #include <algorithm> |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 34 | using namespace llvm; |
| 35 | |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 36 | namespace llvm { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 37 | cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv", |
| 38 | cl::desc("Use the FP div instruction for integer div when possible"), |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 39 | cl::Hidden); |
Andrew Lenharth | 5900919 | 2005-05-04 19:12:09 +0000 | [diff] [blame] | 40 | cl::opt<bool> EnableAlphaFTOI("enable-alpha-FTOI", |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 41 | cl::desc("Enable use of ftoi* and itof* instructions (ev6 and higher)"), |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 42 | cl::Hidden); |
Andrew Lenharth | 5900919 | 2005-05-04 19:12:09 +0000 | [diff] [blame] | 43 | cl::opt<bool> EnableAlphaCT("enable-alpha-CT", |
| 44 | cl::desc("Enable use of the ctpop, ctlz, and cttz instructions"), |
| 45 | cl::Hidden); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 46 | cl::opt<bool> EnableAlphaCount("enable-alpha-count", |
| 47 | cl::desc("Print estimates on live ins and outs"), |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 48 | cl::Hidden); |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 49 | cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark", |
Misha Brukman | 5e96a3a | 2005-06-06 19:08:04 +0000 | [diff] [blame] | 50 | cl::desc("Emit symbols to correlate Mem ops to LLVM Values"), |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 51 | cl::Hidden); |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 54 | namespace { |
| 55 | // Alpha Specific DAG Nodes |
| 56 | namespace AlphaISD { |
| 57 | enum NodeType { |
| 58 | // Start the numbering where the builtin ops leave off. |
| 59 | FIRST_NUMBER = ISD::BUILTIN_OP_END, |
| 60 | |
| 61 | //Convert an int bit pattern in an FP reg to a Double or Float |
| 62 | //Has a dest type and a source |
| 63 | CVTQ, |
| 64 | //Move an Ireg to a FPreg |
| 65 | ITOF, |
| 66 | //Move a FPreg to an Ireg |
| 67 | FTOI, |
| 68 | }; |
| 69 | } |
| 70 | } |
| 71 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 72 | //===----------------------------------------------------------------------===// |
| 73 | // AlphaTargetLowering - Alpha Implementation of the TargetLowering interface |
| 74 | namespace { |
| 75 | class AlphaTargetLowering : public TargetLowering { |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 76 | int VarArgsOffset; // What is the offset to the first vaarg |
| 77 | int VarArgsBase; // What is the base FrameIndex |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 78 | unsigned GP; //GOT vreg |
| 79 | public: |
| 80 | AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) { |
| 81 | // Set up the TargetLowering object. |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 82 | //I am having problems with shr n ubyte 1 |
Andrew Lenharth | 879ef22 | 2005-02-02 17:00:21 +0000 | [diff] [blame] | 83 | setShiftAmountType(MVT::i64); |
| 84 | setSetCCResultType(MVT::i64); |
Andrew Lenharth | d3355e2 | 2005-04-07 20:11:32 +0000 | [diff] [blame] | 85 | setSetCCResultContents(ZeroOrOneSetCCResult); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 86 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 87 | addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass); |
| 88 | addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass); |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 89 | addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 90 | |
Chris Lattner | da4d469 | 2005-04-09 03:22:37 +0000 | [diff] [blame] | 91 | setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand); |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 92 | setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote); |
| 93 | setOperationAction(ISD::EXTLOAD , MVT::f32 , Promote); |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 94 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 95 | setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand); |
| 96 | setOperationAction(ISD::ZEXTLOAD , MVT::i32 , Expand); |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 97 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 98 | setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand); |
| 99 | setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand); |
| 100 | setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 101 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 102 | setOperationAction(ISD::SREM , MVT::f32 , Expand); |
| 103 | setOperationAction(ISD::SREM , MVT::f64 , Expand); |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 104 | |
Andrew Lenharth | 5900919 | 2005-05-04 19:12:09 +0000 | [diff] [blame] | 105 | if (!EnableAlphaCT) { |
| 106 | setOperationAction(ISD::CTPOP , MVT::i64 , Expand); |
| 107 | setOperationAction(ISD::CTTZ , MVT::i64 , Expand); |
Andrew Lenharth | b5884d3 | 2005-05-04 19:25:37 +0000 | [diff] [blame] | 108 | setOperationAction(ISD::CTLZ , MVT::i64 , Expand); |
Andrew Lenharth | 5900919 | 2005-05-04 19:12:09 +0000 | [diff] [blame] | 109 | } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 110 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 111 | //If this didn't legalize into a div.... |
| 112 | // setOperationAction(ISD::SREM , MVT::i64, Expand); |
| 113 | // setOperationAction(ISD::UREM , MVT::i64, Expand); |
| 114 | |
| 115 | setOperationAction(ISD::MEMMOVE , MVT::Other, Expand); |
| 116 | setOperationAction(ISD::MEMSET , MVT::Other, Expand); |
| 117 | setOperationAction(ISD::MEMCPY , MVT::Other, Expand); |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 118 | |
Chris Lattner | 17234b7 | 2005-04-30 04:26:06 +0000 | [diff] [blame] | 119 | // We don't support sin/cos/sqrt |
| 120 | setOperationAction(ISD::FSIN , MVT::f64, Expand); |
| 121 | setOperationAction(ISD::FCOS , MVT::f64, Expand); |
| 122 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); |
| 123 | setOperationAction(ISD::FSIN , MVT::f32, Expand); |
| 124 | setOperationAction(ISD::FCOS , MVT::f32, Expand); |
| 125 | setOperationAction(ISD::FSQRT, MVT::f32, Expand); |
| 126 | |
Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 127 | //Doesn't work yet |
Chris Lattner | 17234b7 | 2005-04-30 04:26:06 +0000 | [diff] [blame] | 128 | setOperationAction(ISD::SETCC, MVT::f32, Promote); |
Andrew Lenharth | 572af90 | 2005-02-14 05:41:43 +0000 | [diff] [blame] | 129 | |
Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 130 | //Try a couple things with a custom expander |
| 131 | //setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom); |
| 132 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 133 | computeRegisterProperties(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 134 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 135 | addLegalFPImmediate(+0.0); //F31 |
| 136 | addLegalFPImmediate(-0.0); //-F31 |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 139 | /// LowerOperation - Provide custom lowering hooks for some operations. |
| 140 | /// |
| 141 | virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG); |
| 142 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 143 | /// LowerArguments - This hook must be implemented to indicate how we should |
| 144 | /// lower the arguments for the specified function, into the specified DAG. |
| 145 | virtual std::vector<SDOperand> |
| 146 | LowerArguments(Function &F, SelectionDAG &DAG); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 147 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 148 | /// LowerCallTo - This hook lowers an abstract call to a function into an |
| 149 | /// actual call. |
| 150 | virtual std::pair<SDOperand, SDOperand> |
Chris Lattner | c57f682 | 2005-05-12 19:56:45 +0000 | [diff] [blame] | 151 | LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC, |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 152 | bool isTailCall, SDOperand Callee, ArgListTy &Args, |
| 153 | SelectionDAG &DAG); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 154 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 155 | virtual std::pair<SDOperand, SDOperand> |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 156 | LowerVAStart(SDOperand Chain, SelectionDAG &DAG, SDOperand Dest); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 157 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 158 | virtual std::pair<SDOperand,SDOperand> |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 159 | LowerVAArgNext(SDOperand Chain, SDOperand VAList, |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 160 | const Type *ArgTy, SelectionDAG &DAG); |
| 161 | |
Andrew Lenharth | cdf233d | 2005-06-22 23:04:28 +0000 | [diff] [blame^] | 162 | std::pair<SDOperand,SDOperand> |
| 163 | LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest, |
| 164 | SelectionDAG &DAG); |
| 165 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 166 | virtual std::pair<SDOperand, SDOperand> |
| 167 | LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth, |
| 168 | SelectionDAG &DAG); |
| 169 | |
| 170 | void restoreGP(MachineBasicBlock* BB) |
| 171 | { |
| 172 | BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP); |
| 173 | } |
| 174 | }; |
| 175 | } |
| 176 | |
Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 177 | /// LowerOperation - Provide custom lowering hooks for some operations. |
| 178 | /// |
| 179 | SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { |
| 180 | MachineFunction &MF = DAG.getMachineFunction(); |
| 181 | switch (Op.getOpcode()) { |
| 182 | default: assert(0 && "Should not custom lower this!"); |
Misha Brukman | b8ee91a | 2005-06-06 17:39:46 +0000 | [diff] [blame] | 183 | #if 0 |
| 184 | case ISD::SINT_TO_FP: |
| 185 | { |
| 186 | assert (Op.getOperand(0).getValueType() == MVT::i64 |
| 187 | && "only quads can be loaded from"); |
| 188 | SDOperand SRC; |
| 189 | if (EnableAlphaFTOI) |
| 190 | { |
| 191 | std::vector<MVT::ValueType> RTs; |
| 192 | RTs.push_back(Op.getValueType()); |
| 193 | std::vector<SDOperand> Ops; |
| 194 | Ops.push_back(Op.getOperand(0)); |
| 195 | SRC = DAG.getNode(AlphaISD::ITOF, RTs, Ops); |
| 196 | } else { |
| 197 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8); |
| 198 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 199 | SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(), |
| 200 | Op.getOperand(0), StackSlot, DAG.getSrcValue(NULL)); |
| 201 | SRC = DAG.getLoad(Op.getValueType(), Store.getValue(0), StackSlot, |
| 202 | DAG.getSrcValue(NULL)); |
| 203 | } |
| 204 | std::vector<MVT::ValueType> RTs; |
| 205 | RTs.push_back(Op.getValueType()); |
| 206 | std::vector<SDOperand> Ops; |
| 207 | Ops.push_back(SRC); |
| 208 | return DAG.getNode(AlphaISD::CVTQ, RTs, Ops); |
| 209 | } |
| 210 | #endif |
Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 211 | } |
Misha Brukman | b8ee91a | 2005-06-06 17:39:46 +0000 | [diff] [blame] | 212 | return SDOperand(); |
Andrew Lenharth | e3c8c0a4 | 2005-05-31 19:49:34 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 216 | /// AddLiveIn - This helper function adds the specified physical register to the |
| 217 | /// MachineFunction as a live in value. It also creates a corresponding virtual |
| 218 | /// register for it. |
| 219 | static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg, |
| 220 | TargetRegisterClass *RC) { |
| 221 | assert(RC->contains(PReg) && "Not the correct regclass!"); |
| 222 | unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC); |
| 223 | MF.addLiveIn(PReg, VReg); |
| 224 | return VReg; |
| 225 | } |
| 226 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 227 | //http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21 |
| 228 | |
| 229 | //For now, just use variable size stack frame format |
| 230 | |
| 231 | //In a standard call, the first six items are passed in registers $16 |
| 232 | //- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details |
| 233 | //of argument-to-register correspondence.) The remaining items are |
| 234 | //collected in a memory argument list that is a naturally aligned |
| 235 | //array of quadwords. In a standard call, this list, if present, must |
| 236 | //be passed at 0(SP). |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 237 | //7 ... n 0(SP) ... (n-7)*8(SP) |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 238 | |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 239 | // //#define FP $15 |
| 240 | // //#define RA $26 |
| 241 | // //#define PV $27 |
| 242 | // //#define GP $29 |
| 243 | // //#define SP $30 |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 244 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 245 | std::vector<SDOperand> |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 246 | AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 247 | { |
| 248 | std::vector<SDOperand> ArgValues; |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 249 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 250 | MachineFunction &MF = DAG.getMachineFunction(); |
Andrew Lenharth | 0538034 | 2005-02-07 05:07:00 +0000 | [diff] [blame] | 251 | MachineFrameInfo*MFI = MF.getFrameInfo(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 252 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 253 | MachineBasicBlock& BB = MF.front(); |
| 254 | |
| 255 | //Handle the return address |
| 256 | //BuildMI(&BB, Alpha::IDEF, 0, Alpha::R26); |
| 257 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 258 | unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 259 | Alpha::R19, Alpha::R20, Alpha::R21}; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 260 | unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 261 | Alpha::F19, Alpha::F20, Alpha::F21}; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 262 | int count = 0; |
Andrew Lenharth | 2c9e38c | 2005-02-06 21:07:31 +0000 | [diff] [blame] | 263 | |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 264 | GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64)); |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 265 | |
Chris Lattner | e4d5c44 | 2005-03-15 04:54:21 +0000 | [diff] [blame] | 266 | for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 267 | { |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 268 | SDOperand argt; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 269 | if (count < 6) { |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 270 | unsigned Vreg; |
| 271 | MVT::ValueType VT = getValueType(I->getType()); |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 272 | switch (VT) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 273 | default: |
| 274 | std::cerr << "Unknown Type " << VT << "\n"; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 275 | abort(); |
| 276 | case MVT::f64: |
| 277 | case MVT::f32: |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 278 | args_float[count] = AddLiveIn(MF,args_float[count], getRegClassFor(VT)); |
| 279 | argt = DAG.getCopyFromReg(args_float[count], VT, DAG.getRoot()); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 280 | break; |
| 281 | case MVT::i1: |
| 282 | case MVT::i8: |
| 283 | case MVT::i16: |
| 284 | case MVT::i32: |
| 285 | case MVT::i64: |
Andrew Lenharth | 591ec57 | 2005-05-31 18:42:18 +0000 | [diff] [blame] | 286 | args_int[count] = AddLiveIn(MF, args_int[count], getRegClassFor(MVT::i64)); |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 287 | argt = DAG.getCopyFromReg(args_int[count], VT, DAG.getRoot()); |
Andrew Lenharth | 14f30c9 | 2005-05-31 18:37:16 +0000 | [diff] [blame] | 288 | if (VT != MVT::i64) |
| 289 | argt = DAG.getNode(ISD::TRUNCATE, VT, argt); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 290 | break; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 291 | } |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 292 | DAG.setRoot(argt.getValue(1)); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 293 | } else { //more args |
| 294 | // Create the frame index object for this incoming parameter... |
| 295 | int FI = MFI->CreateFixedObject(8, 8 * (count - 6)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 296 | |
| 297 | // Create the SelectionDAG nodes corresponding to a load |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 298 | //from this parameter |
| 299 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64); |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 300 | argt = DAG.getLoad(getValueType(I->getType()), |
| 301 | DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL)); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 302 | } |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 303 | ++count; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 304 | ArgValues.push_back(argt); |
| 305 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 306 | |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 307 | // If the functions takes variable number of arguments, copy all regs to stack |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 308 | if (F.isVarArg()) { |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 309 | VarArgsOffset = count * 8; |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 310 | std::vector<SDOperand> LS; |
| 311 | for (int i = 0; i < 6; ++i) { |
| 312 | if (args_int[i] < 1024) |
| 313 | args_int[i] = AddLiveIn(MF,args_int[i], getRegClassFor(MVT::i64)); |
| 314 | SDOperand argt = DAG.getCopyFromReg(args_int[i], MVT::i64, DAG.getRoot()); |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 315 | int FI = MFI->CreateFixedObject(8, -8 * (6 - i)); |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 316 | if (i == 0) VarArgsBase = FI; |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 317 | SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64); |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 318 | LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt, SDFI, DAG.getSrcValue(NULL))); |
| 319 | |
| 320 | if (args_float[i] < 1024) |
| 321 | args_float[i] = AddLiveIn(MF,args_float[i], getRegClassFor(MVT::f64)); |
| 322 | argt = DAG.getCopyFromReg(args_float[i], MVT::f64, DAG.getRoot()); |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 323 | FI = MFI->CreateFixedObject(8, - 8 * (12 - i)); |
| 324 | SDFI = DAG.getFrameIndex(FI, MVT::i64); |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 325 | LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt, SDFI, DAG.getSrcValue(NULL))); |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 328 | //Set up a token factor with all the stack traffic |
| 329 | DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS)); |
| 330 | } |
Andrew Lenharth | e1c5a00 | 2005-04-12 17:35:16 +0000 | [diff] [blame] | 331 | |
| 332 | // Finally, inform the code generator which regs we return values in. |
| 333 | switch (getValueType(F.getReturnType())) { |
| 334 | default: assert(0 && "Unknown type!"); |
| 335 | case MVT::isVoid: break; |
| 336 | case MVT::i1: |
| 337 | case MVT::i8: |
| 338 | case MVT::i16: |
| 339 | case MVT::i32: |
| 340 | case MVT::i64: |
| 341 | MF.addLiveOut(Alpha::R0); |
| 342 | break; |
| 343 | case MVT::f32: |
| 344 | case MVT::f64: |
| 345 | MF.addLiveOut(Alpha::F0); |
| 346 | break; |
| 347 | } |
| 348 | |
Andrew Lenharth | 2513ddc | 2005-04-05 20:51:46 +0000 | [diff] [blame] | 349 | //return the arguments |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 350 | return ArgValues; |
| 351 | } |
| 352 | |
| 353 | std::pair<SDOperand, SDOperand> |
| 354 | AlphaTargetLowering::LowerCallTo(SDOperand Chain, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 355 | const Type *RetTy, bool isVarArg, |
Chris Lattner | adf6a96 | 2005-05-13 18:50:42 +0000 | [diff] [blame] | 356 | unsigned CallingConv, bool isTailCall, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 357 | SDOperand Callee, ArgListTy &Args, |
| 358 | SelectionDAG &DAG) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 359 | int NumBytes = 0; |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 360 | if (Args.size() > 6) |
| 361 | NumBytes = (Args.size() - 6) * 8; |
| 362 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 363 | Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 364 | DAG.getConstant(NumBytes, getPointerTy())); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 365 | std::vector<SDOperand> args_to_use; |
| 366 | for (unsigned i = 0, e = Args.size(); i != e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 367 | { |
| 368 | switch (getValueType(Args[i].second)) { |
| 369 | default: assert(0 && "Unexpected ValueType for argument!"); |
| 370 | case MVT::i1: |
| 371 | case MVT::i8: |
| 372 | case MVT::i16: |
| 373 | case MVT::i32: |
| 374 | // Promote the integer to 64 bits. If the input type is signed use a |
| 375 | // sign extend, otherwise use a zero extend. |
| 376 | if (Args[i].second->isSigned()) |
| 377 | Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first); |
| 378 | else |
| 379 | Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first); |
| 380 | break; |
| 381 | case MVT::i64: |
| 382 | case MVT::f64: |
| 383 | case MVT::f32: |
| 384 | break; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 385 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 386 | args_to_use.push_back(Args[i].first); |
| 387 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 388 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 389 | std::vector<MVT::ValueType> RetVals; |
| 390 | MVT::ValueType RetTyVT = getValueType(RetTy); |
| 391 | if (RetTyVT != MVT::isVoid) |
| 392 | RetVals.push_back(RetTyVT); |
| 393 | RetVals.push_back(MVT::Other); |
| 394 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 395 | SDOperand TheCall = SDOperand(DAG.getCall(RetVals, |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 396 | Chain, Callee, args_to_use), 0); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 397 | Chain = TheCall.getValue(RetTyVT != MVT::isVoid); |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 398 | Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain, |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 399 | DAG.getConstant(NumBytes, getPointerTy())); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 400 | return std::make_pair(TheCall, Chain); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | std::pair<SDOperand, SDOperand> |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 404 | AlphaTargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG, SDOperand Dest) { |
| 405 | // vastart just stores the address of the VarArgsBase and VarArgsOffset |
| 406 | SDOperand FR = DAG.getFrameIndex(VarArgsBase, MVT::i32); |
| 407 | SDOperand S1 = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, Dest, DAG.getSrcValue(NULL)); |
| 408 | SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, Dest, DAG.getConstant(8, MVT::i64)); |
| 409 | SDOperand S2 = DAG.getNode(ISD::STORE, MVT::Other, S1, |
| 410 | DAG.getConstant(VarArgsOffset, MVT::i64), SA2, |
| 411 | DAG.getSrcValue(NULL)); |
| 412 | |
| 413 | return std::make_pair(S2, S2); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | std::pair<SDOperand,SDOperand> AlphaTargetLowering:: |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 417 | LowerVAArgNext(SDOperand Chain, SDOperand VAList, |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 418 | const Type *ArgTy, SelectionDAG &DAG) { |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 419 | //FIXME: For now, ignore FP |
| 420 | SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAList, DAG.getSrcValue(NULL)); |
| 421 | SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAList, |
| 422 | DAG.getConstant(8, MVT::i64)); |
| 423 | SDOperand Offset = DAG.getLoad(MVT::i64, Chain, Tmp, DAG.getSrcValue(NULL)); |
| 424 | SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset); |
Andrew Lenharth | cdf233d | 2005-06-22 23:04:28 +0000 | [diff] [blame^] | 425 | if (ArgTy->isFloatingPoint()) |
| 426 | { |
| 427 | //if fp && Offset < 6*8, then subtract 6*8 from DataPtr |
| 428 | SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr, |
| 429 | DAG.getConstant(8*6, MVT::i64)); |
| 430 | SDOperand CC = DAG.getSetCC(ISD::SETLT, MVT::i64, |
| 431 | Offset, DAG.getConstant(8*6, MVT::i64)); |
| 432 | DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr); |
| 433 | } |
| 434 | |
| 435 | SDOperand Result = DAG.getLoad(getValueType(ArgTy), Chain, DataPtr, |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 436 | DAG.getSrcValue(NULL)); |
| 437 | SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset, |
| 438 | DAG.getConstant(8, MVT::i64)); |
| 439 | SDOperand Update = DAG.getNode(ISD::STORE, MVT::Other, Result, NewOffset, |
| 440 | Tmp, DAG.getSrcValue(NULL)); |
| 441 | return std::make_pair(Result, Update); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 442 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 443 | |
Andrew Lenharth | cdf233d | 2005-06-22 23:04:28 +0000 | [diff] [blame^] | 444 | std::pair<SDOperand,SDOperand> AlphaTargetLowering:: |
| 445 | LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest, |
| 446 | SelectionDAG &DAG) { |
| 447 | //Default to returning the input list |
| 448 | SDOperand Val = DAG.getLoad(getPointerTy(), Chain, Src, DAG.getSrcValue(NULL)); |
| 449 | SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1), |
| 450 | Val, Dest, DAG.getSrcValue(NULL)); |
| 451 | SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, Src, |
| 452 | DAG.getConstant(8, MVT::i64)); |
| 453 | Val = DAG.getLoad(MVT::i32, Chain, NP, DAG.getSrcValue(NULL)); |
| 454 | Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1), |
| 455 | Val, Dest, DAG.getSrcValue(NULL)); |
| 456 | return std::make_pair(Result, Result); |
| 457 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 458 | |
| 459 | std::pair<SDOperand, SDOperand> AlphaTargetLowering:: |
| 460 | LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth, |
| 461 | SelectionDAG &DAG) { |
| 462 | abort(); |
| 463 | } |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | namespace { |
| 470 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 471 | //===--------------------------------------------------------------------===// |
| 472 | /// ISel - Alpha specific code to select Alpha machine instructions for |
| 473 | /// SelectionDAG operations. |
| 474 | //===--------------------------------------------------------------------===// |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 475 | class AlphaISel : public SelectionDAGISel { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 476 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 477 | /// AlphaLowering - This object fully describes how to lower LLVM code to an |
| 478 | /// Alpha-specific SelectionDAG. |
| 479 | AlphaTargetLowering AlphaLowering; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 480 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 481 | SelectionDAG *ISelDAG; // Hack to support us having a dag->dag transform |
| 482 | // for sdiv and udiv until it is put into the future |
| 483 | // dag combiner. |
| 484 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 485 | /// ExprMap - As shared expressions are codegen'd, we keep track of which |
| 486 | /// vreg the value is produced in, so we only emit one copy of each compiled |
| 487 | /// tree. |
| 488 | static const unsigned notIn = (unsigned)(-1); |
| 489 | std::map<SDOperand, unsigned> ExprMap; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 490 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 491 | //CCInvMap sometimes (SetNE) we have the inverse CC code for free |
| 492 | std::map<SDOperand, unsigned> CCInvMap; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 493 | |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 494 | int count_ins; |
| 495 | int count_outs; |
| 496 | bool has_sym; |
Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 497 | int max_depth; |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 498 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 499 | public: |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 500 | AlphaISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 501 | {} |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 502 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 503 | /// InstructionSelectBasicBlock - This callback is invoked by |
| 504 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 505 | virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) { |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 506 | DEBUG(BB->dump()); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 507 | count_ins = 0; |
| 508 | count_outs = 0; |
Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 509 | max_depth = 0; |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 510 | has_sym = false; |
| 511 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 512 | // Codegen the basic block. |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 513 | ISelDAG = &DAG; |
Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 514 | max_depth = DAG.getRoot().getNodeDepth(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 515 | Select(DAG.getRoot()); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 516 | |
| 517 | if(has_sym) |
| 518 | ++count_ins; |
| 519 | if(EnableAlphaCount) |
Andrew Lenharth | 500b4db | 2005-04-22 13:35:18 +0000 | [diff] [blame] | 520 | std::cerr << "COUNT: " << BB->getParent()->getFunction ()->getName() << " " |
| 521 | << BB->getNumber() << " " |
| 522 | << max_depth << " " |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 523 | << count_ins << " " |
| 524 | << count_outs << "\n"; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 525 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 526 | // Clear state used for selection. |
| 527 | ExprMap.clear(); |
| 528 | CCInvMap.clear(); |
| 529 | } |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 530 | |
| 531 | virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 532 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 533 | unsigned SelectExpr(SDOperand N); |
| 534 | unsigned SelectExprFP(SDOperand N, unsigned Result); |
| 535 | void Select(SDOperand N); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 536 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 537 | void SelectAddr(SDOperand N, unsigned& Reg, long& offset); |
| 538 | void SelectBranchCC(SDOperand N); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 539 | void MoveFP2Int(unsigned src, unsigned dst, bool isDouble); |
| 540 | void MoveInt2FP(unsigned src, unsigned dst, bool isDouble); |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 541 | //returns whether the sense of the comparison was inverted |
| 542 | bool SelectFPSetCC(SDOperand N, unsigned dst); |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 543 | |
| 544 | // dag -> dag expanders for integer divide by constant |
| 545 | SDOperand BuildSDIVSequence(SDOperand N); |
| 546 | SDOperand BuildUDIVSequence(SDOperand N); |
| 547 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 548 | }; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 551 | void AlphaISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) { |
Andrew Lenharth | fd5e4b7 | 2005-05-31 18:35:43 +0000 | [diff] [blame] | 552 | // If this function has live-in values, emit the copies from pregs to vregs at |
| 553 | // the top of the function, before anything else. |
| 554 | MachineBasicBlock *BB = MF.begin(); |
| 555 | if (MF.livein_begin() != MF.livein_end()) { |
| 556 | SSARegMap *RegMap = MF.getSSARegMap(); |
| 557 | for (MachineFunction::livein_iterator LI = MF.livein_begin(), |
| 558 | E = MF.livein_end(); LI != E; ++LI) { |
| 559 | const TargetRegisterClass *RC = RegMap->getRegClass(LI->second); |
| 560 | if (RC == Alpha::GPRCRegisterClass) { |
| 561 | BuildMI(BB, Alpha::BIS, 2, LI->second).addReg(LI->first).addReg(LI->first); |
| 562 | } else if (RC == Alpha::FPRCRegisterClass) { |
| 563 | BuildMI(BB, Alpha::CPYS, 2, LI->second).addReg(LI->first).addReg(LI->first); |
| 564 | } else { |
| 565 | assert(0 && "Unknown regclass!"); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 571 | //Find the offset of the arg in it's parent's function |
| 572 | static int getValueOffset(const Value* v) |
| 573 | { |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 574 | static int uniqneg = -1; |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 575 | if (v == NULL) |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 576 | return uniqneg--; |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 577 | |
| 578 | const Instruction* itarget = dyn_cast<Instruction>(v); |
| 579 | const BasicBlock* btarget = itarget->getParent(); |
| 580 | const Function* ftarget = btarget->getParent(); |
| 581 | |
| 582 | //offset due to earlier BBs |
| 583 | int i = 0; |
| 584 | for(Function::const_iterator ii = ftarget->begin(); &*ii != btarget; ++ii) |
| 585 | i += ii->size(); |
| 586 | |
| 587 | for(BasicBlock::const_iterator ii = btarget->begin(); &*ii != itarget; ++ii) |
| 588 | ++i; |
| 589 | |
| 590 | return i; |
| 591 | } |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 592 | //Find the offset of the function in it's module |
| 593 | static int getFunctionOffset(const Function* fun) |
| 594 | { |
| 595 | const Module* M = fun->getParent(); |
| 596 | |
| 597 | //offset due to earlier BBs |
| 598 | int i = 0; |
| 599 | for(Module::const_iterator ii = M->begin(); &*ii != fun; ++ii) |
| 600 | ++i; |
| 601 | |
| 602 | return i; |
| 603 | } |
| 604 | |
| 605 | static int getUID() |
| 606 | { |
| 607 | static int id = 0; |
| 608 | return ++id; |
| 609 | } |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 610 | |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 611 | //Factorize a number using the list of constants |
| 612 | static bool factorize(int v[], int res[], int size, uint64_t c) |
| 613 | { |
| 614 | bool cont = true; |
| 615 | while (c != 1 && cont) |
| 616 | { |
| 617 | cont = false; |
| 618 | for(int i = 0; i < size; ++i) |
| 619 | { |
| 620 | if (c % v[i] == 0) |
| 621 | { |
| 622 | c /= v[i]; |
| 623 | ++res[i]; |
| 624 | cont=true; |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | return c == 1; |
| 629 | } |
| 630 | |
| 631 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 632 | //Shamelessly adapted from PPC32 |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 633 | // Structure used to return the necessary information to codegen an SDIV as |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 634 | // a multiply. |
| 635 | struct ms { |
| 636 | int64_t m; // magic number |
| 637 | int64_t s; // shift amount |
| 638 | }; |
| 639 | |
| 640 | struct mu { |
| 641 | uint64_t m; // magic number |
| 642 | int64_t a; // add indicator |
| 643 | int64_t s; // shift amount |
| 644 | }; |
| 645 | |
| 646 | /// magic - calculate the magic numbers required to codegen an integer sdiv as |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 647 | /// a sequence of multiply and shifts. Requires that the divisor not be 0, 1, |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 648 | /// or -1. |
| 649 | static struct ms magic(int64_t d) { |
| 650 | int64_t p; |
| 651 | uint64_t ad, anc, delta, q1, r1, q2, r2, t; |
| 652 | const uint64_t two63 = 9223372036854775808ULL; // 2^63 |
| 653 | struct ms mag; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 654 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 655 | ad = abs(d); |
| 656 | t = two63 + ((uint64_t)d >> 63); |
| 657 | anc = t - 1 - t%ad; // absolute value of nc |
Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 658 | p = 63; // initialize p |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 659 | q1 = two63/anc; // initialize q1 = 2p/abs(nc) |
| 660 | r1 = two63 - q1*anc; // initialize r1 = rem(2p,abs(nc)) |
| 661 | q2 = two63/ad; // initialize q2 = 2p/abs(d) |
| 662 | r2 = two63 - q2*ad; // initialize r2 = rem(2p,abs(d)) |
| 663 | do { |
| 664 | p = p + 1; |
| 665 | q1 = 2*q1; // update q1 = 2p/abs(nc) |
| 666 | r1 = 2*r1; // update r1 = rem(2p/abs(nc)) |
| 667 | if (r1 >= anc) { // must be unsigned comparison |
| 668 | q1 = q1 + 1; |
| 669 | r1 = r1 - anc; |
| 670 | } |
| 671 | q2 = 2*q2; // update q2 = 2p/abs(d) |
| 672 | r2 = 2*r2; // update r2 = rem(2p/abs(d)) |
| 673 | if (r2 >= ad) { // must be unsigned comparison |
| 674 | q2 = q2 + 1; |
| 675 | r2 = r2 - ad; |
| 676 | } |
| 677 | delta = ad - r2; |
| 678 | } while (q1 < delta || (q1 == delta && r1 == 0)); |
| 679 | |
| 680 | mag.m = q2 + 1; |
| 681 | if (d < 0) mag.m = -mag.m; // resulting magic number |
| 682 | mag.s = p - 64; // resulting shift |
| 683 | return mag; |
| 684 | } |
| 685 | |
| 686 | /// magicu - calculate the magic numbers required to codegen an integer udiv as |
| 687 | /// a sequence of multiply, add and shifts. Requires that the divisor not be 0. |
| 688 | static struct mu magicu(uint64_t d) |
| 689 | { |
| 690 | int64_t p; |
| 691 | uint64_t nc, delta, q1, r1, q2, r2; |
| 692 | struct mu magu; |
| 693 | magu.a = 0; // initialize "add" indicator |
| 694 | nc = - 1 - (-d)%d; |
Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 695 | p = 63; // initialize p |
| 696 | q1 = 0x8000000000000000ull/nc; // initialize q1 = 2p/nc |
| 697 | r1 = 0x8000000000000000ull - q1*nc; // initialize r1 = rem(2p,nc) |
| 698 | q2 = 0x7FFFFFFFFFFFFFFFull/d; // initialize q2 = (2p-1)/d |
| 699 | r2 = 0x7FFFFFFFFFFFFFFFull - q2*d; // initialize r2 = rem((2p-1),d) |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 700 | do { |
| 701 | p = p + 1; |
| 702 | if (r1 >= nc - r1 ) { |
| 703 | q1 = 2*q1 + 1; // update q1 |
| 704 | r1 = 2*r1 - nc; // update r1 |
| 705 | } |
| 706 | else { |
| 707 | q1 = 2*q1; // update q1 |
| 708 | r1 = 2*r1; // update r1 |
| 709 | } |
| 710 | if (r2 + 1 >= d - r2) { |
Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 711 | if (q2 >= 0x7FFFFFFFFFFFFFFFull) magu.a = 1; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 712 | q2 = 2*q2 + 1; // update q2 |
| 713 | r2 = 2*r2 + 1 - d; // update r2 |
| 714 | } |
| 715 | else { |
Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 716 | if (q2 >= 0x8000000000000000ull) magu.a = 1; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 717 | q2 = 2*q2; // update q2 |
| 718 | r2 = 2*r2 + 1; // update r2 |
| 719 | } |
| 720 | delta = d - 1 - r2; |
| 721 | } while (p < 64 && (q1 < delta || (q1 == delta && r1 == 0))); |
| 722 | magu.m = q2 + 1; // resulting magic number |
Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 723 | magu.s = p - 64; // resulting shift |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 724 | return magu; |
| 725 | } |
| 726 | |
| 727 | /// BuildSDIVSequence - Given an ISD::SDIV node expressing a divide by constant, |
| 728 | /// return a DAG expression to select that will generate the same value by |
| 729 | /// multiplying by a magic number. See: |
| 730 | /// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html> |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 731 | SDOperand AlphaISel::BuildSDIVSequence(SDOperand N) { |
Andrew Lenharth | 320174f | 2005-04-07 17:19:16 +0000 | [diff] [blame] | 732 | int64_t d = (int64_t)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended(); |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 733 | ms magics = magic(d); |
| 734 | // Multiply the numerator (operand 0) by the magic value |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 735 | SDOperand Q = ISelDAG->getNode(ISD::MULHS, MVT::i64, N.getOperand(0), |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 736 | ISelDAG->getConstant(magics.m, MVT::i64)); |
| 737 | // If d > 0 and m < 0, add the numerator |
| 738 | if (d > 0 && magics.m < 0) |
| 739 | Q = ISelDAG->getNode(ISD::ADD, MVT::i64, Q, N.getOperand(0)); |
| 740 | // If d < 0 and m > 0, subtract the numerator. |
| 741 | if (d < 0 && magics.m > 0) |
| 742 | Q = ISelDAG->getNode(ISD::SUB, MVT::i64, Q, N.getOperand(0)); |
| 743 | // Shift right algebraic if shift value is nonzero |
| 744 | if (magics.s > 0) |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 745 | Q = ISelDAG->getNode(ISD::SRA, MVT::i64, Q, |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 746 | ISelDAG->getConstant(magics.s, MVT::i64)); |
| 747 | // Extract the sign bit and add it to the quotient |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 748 | SDOperand T = |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 749 | ISelDAG->getNode(ISD::SRL, MVT::i64, Q, ISelDAG->getConstant(63, MVT::i64)); |
| 750 | return ISelDAG->getNode(ISD::ADD, MVT::i64, Q, T); |
| 751 | } |
| 752 | |
| 753 | /// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant, |
| 754 | /// return a DAG expression to select that will generate the same value by |
| 755 | /// multiplying by a magic number. See: |
| 756 | /// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html> |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 757 | SDOperand AlphaISel::BuildUDIVSequence(SDOperand N) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 758 | unsigned d = |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 759 | (unsigned)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended(); |
| 760 | mu magics = magicu(d); |
| 761 | // Multiply the numerator (operand 0) by the magic value |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 762 | SDOperand Q = ISelDAG->getNode(ISD::MULHU, MVT::i64, N.getOperand(0), |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 763 | ISelDAG->getConstant(magics.m, MVT::i64)); |
| 764 | if (magics.a == 0) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 765 | Q = ISelDAG->getNode(ISD::SRL, MVT::i64, Q, |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 766 | ISelDAG->getConstant(magics.s, MVT::i64)); |
| 767 | } else { |
| 768 | SDOperand NPQ = ISelDAG->getNode(ISD::SUB, MVT::i64, N.getOperand(0), Q); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 769 | NPQ = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ, |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 770 | ISelDAG->getConstant(1, MVT::i64)); |
| 771 | NPQ = ISelDAG->getNode(ISD::ADD, MVT::i64, NPQ, Q); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 772 | Q = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ, |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 773 | ISelDAG->getConstant(magics.s-1, MVT::i64)); |
| 774 | } |
| 775 | return Q; |
| 776 | } |
| 777 | |
Andrew Lenharth | a565c27 | 2005-04-06 22:03:13 +0000 | [diff] [blame] | 778 | //From PPC32 |
| 779 | /// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It |
| 780 | /// returns zero when the input is not exactly a power of two. |
| 781 | static unsigned ExactLog2(uint64_t Val) { |
| 782 | if (Val == 0 || (Val & (Val-1))) return 0; |
| 783 | unsigned Count = 0; |
| 784 | while (Val != 1) { |
| 785 | Val >>= 1; |
| 786 | ++Count; |
| 787 | } |
| 788 | return Count; |
| 789 | } |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 790 | |
| 791 | |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 792 | //These describe LDAx |
Andrew Lenharth | c051383 | 2005-03-29 19:24:04 +0000 | [diff] [blame] | 793 | static const int IMM_LOW = -32768; |
| 794 | static const int IMM_HIGH = 32767; |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 795 | static const int IMM_MULT = 65536; |
| 796 | |
| 797 | static long getUpper16(long l) |
| 798 | { |
| 799 | long y = l / IMM_MULT; |
| 800 | if (l % IMM_MULT > IMM_HIGH) |
| 801 | ++y; |
| 802 | return y; |
| 803 | } |
| 804 | |
| 805 | static long getLower16(long l) |
| 806 | { |
| 807 | long h = getUpper16(l); |
| 808 | return l - h * IMM_MULT; |
| 809 | } |
| 810 | |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 811 | static unsigned GetSymVersion(unsigned opcode) |
| 812 | { |
| 813 | switch (opcode) { |
| 814 | default: assert(0 && "unknown load or store"); return 0; |
| 815 | case Alpha::LDQ: return Alpha::LDQ_SYM; |
| 816 | case Alpha::LDS: return Alpha::LDS_SYM; |
| 817 | case Alpha::LDT: return Alpha::LDT_SYM; |
| 818 | case Alpha::LDL: return Alpha::LDL_SYM; |
| 819 | case Alpha::LDBU: return Alpha::LDBU_SYM; |
| 820 | case Alpha::LDWU: return Alpha::LDWU_SYM; |
| 821 | case Alpha::LDW: return Alpha::LDW_SYM; |
| 822 | case Alpha::LDB: return Alpha::LDB_SYM; |
| 823 | case Alpha::STQ: return Alpha::STQ_SYM; |
| 824 | case Alpha::STS: return Alpha::STS_SYM; |
| 825 | case Alpha::STT: return Alpha::STT_SYM; |
| 826 | case Alpha::STL: return Alpha::STL_SYM; |
| 827 | case Alpha::STW: return Alpha::STW_SYM; |
| 828 | case Alpha::STB: return Alpha::STB_SYM; |
| 829 | } |
| 830 | } |
| 831 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 832 | void AlphaISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble) |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 833 | { |
| 834 | unsigned Opc; |
| 835 | if (EnableAlphaFTOI) { |
| 836 | Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS; |
| 837 | BuildMI(BB, Opc, 1, dst).addReg(src); |
| 838 | } else { |
| 839 | //The hard way: |
| 840 | // Spill the integer to memory and reload it from there. |
| 841 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; |
| 842 | MachineFunction *F = BB->getParent(); |
| 843 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); |
| 844 | |
| 845 | Opc = isDouble ? Alpha::STT : Alpha::STS; |
| 846 | BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 847 | Opc = isDouble ? Alpha::LDQ : Alpha::LDL; |
| 848 | BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 849 | } |
| 850 | } |
| 851 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 852 | void AlphaISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble) |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 853 | { |
| 854 | unsigned Opc; |
| 855 | if (EnableAlphaFTOI) { |
| 856 | Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS; |
| 857 | BuildMI(BB, Opc, 1, dst).addReg(src); |
| 858 | } else { |
| 859 | //The hard way: |
| 860 | // Spill the integer to memory and reload it from there. |
| 861 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; |
| 862 | MachineFunction *F = BB->getParent(); |
| 863 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); |
| 864 | |
| 865 | Opc = isDouble ? Alpha::STQ : Alpha::STL; |
| 866 | BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 867 | Opc = isDouble ? Alpha::LDT : Alpha::LDS; |
| 868 | BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 869 | } |
| 870 | } |
| 871 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 872 | bool AlphaISel::SelectFPSetCC(SDOperand N, unsigned dst) |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 873 | { |
| 874 | SDNode *Node = N.Val; |
| 875 | unsigned Opc, Tmp1, Tmp2, Tmp3; |
| 876 | SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node); |
| 877 | |
| 878 | //assert(SetCC->getOperand(0).getValueType() != MVT::f32 && "SetCC f32 should have been promoted"); |
| 879 | bool rev = false; |
| 880 | bool inv = false; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 881 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 882 | switch (SetCC->getCondition()) { |
| 883 | default: Node->dump(); assert(0 && "Unknown FP comparison!"); |
| 884 | case ISD::SETEQ: Opc = Alpha::CMPTEQ; break; |
| 885 | case ISD::SETLT: Opc = Alpha::CMPTLT; break; |
| 886 | case ISD::SETLE: Opc = Alpha::CMPTLE; break; |
| 887 | case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break; |
| 888 | case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break; |
| 889 | case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break; |
| 890 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 891 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 892 | //FIXME: check for constant 0.0 |
| 893 | ConstantFPSDNode *CN; |
| 894 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0))) |
| 895 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 896 | Tmp1 = Alpha::F31; |
| 897 | else |
| 898 | Tmp1 = SelectExpr(N.getOperand(0)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 899 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 900 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1))) |
| 901 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 902 | Tmp2 = Alpha::F31; |
| 903 | else |
Chris Lattner | 9c9183a | 2005-04-30 04:44:07 +0000 | [diff] [blame] | 904 | Tmp2 = SelectExpr(N.getOperand(1)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 905 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 906 | //Can only compare doubles, and dag won't promote for me |
| 907 | if (SetCC->getOperand(0).getValueType() == MVT::f32) |
| 908 | { |
| 909 | //assert(0 && "Setcc On float?\n"); |
| 910 | std::cerr << "Setcc on float!\n"; |
| 911 | Tmp3 = MakeReg(MVT::f64); |
| 912 | BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1); |
| 913 | Tmp1 = Tmp3; |
| 914 | } |
| 915 | if (SetCC->getOperand(1).getValueType() == MVT::f32) |
| 916 | { |
| 917 | //assert (0 && "Setcc On float?\n"); |
| 918 | std::cerr << "Setcc on float!\n"; |
| 919 | Tmp3 = MakeReg(MVT::f64); |
| 920 | BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2); |
| 921 | Tmp2 = Tmp3; |
| 922 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 923 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 924 | if (rev) std::swap(Tmp1, Tmp2); |
| 925 | //do the comparison |
| 926 | BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2); |
| 927 | return inv; |
| 928 | } |
| 929 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 930 | //Check to see if the load is a constant offset from a base register |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 931 | void AlphaISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset) |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 932 | { |
| 933 | unsigned opcode = N.getOpcode(); |
| 934 | if (opcode == ISD::ADD) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 935 | if(N.getOperand(1).getOpcode() == ISD::Constant && |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 936 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767) |
| 937 | { //Normal imm add |
| 938 | Reg = SelectExpr(N.getOperand(0)); |
| 939 | offset = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 940 | return; |
| 941 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 942 | else if(N.getOperand(0).getOpcode() == ISD::Constant && |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 943 | cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 32767) |
| 944 | { |
| 945 | Reg = SelectExpr(N.getOperand(1)); |
| 946 | offset = cast<ConstantSDNode>(N.getOperand(0))->getValue(); |
| 947 | return; |
| 948 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 949 | } |
| 950 | Reg = SelectExpr(N); |
| 951 | offset = 0; |
| 952 | return; |
| 953 | } |
| 954 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 955 | void AlphaISel::SelectBranchCC(SDOperand N) |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 956 | { |
| 957 | assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 958 | MachineBasicBlock *Dest = |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 959 | cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock(); |
| 960 | unsigned Opc = Alpha::WTF; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 961 | |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 962 | Select(N.getOperand(0)); //chain |
| 963 | SDOperand CC = N.getOperand(1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 964 | |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 965 | if (CC.getOpcode() == ISD::SETCC) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 966 | { |
| 967 | SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val); |
| 968 | if (MVT::isInteger(SetCC->getOperand(0).getValueType())) { |
| 969 | //Dropping the CC is only useful if we are comparing to 0 |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 970 | bool LeftZero = SetCC->getOperand(0).getOpcode() == ISD::Constant && |
| 971 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0; |
Andrew Lenharth | 09552bf | 2005-06-08 18:02:21 +0000 | [diff] [blame] | 972 | bool RightZero = SetCC->getOperand(1).getOpcode() == ISD::Constant && |
| 973 | cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 974 | bool isNE = false; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 975 | |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 976 | //Fix up CC |
| 977 | ISD::CondCode cCode= SetCC->getCondition(); |
| 978 | if (LeftZero && !RightZero) //Swap Operands |
| 979 | cCode = ISD::getSetCCSwappedOperands(cCode); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 980 | |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 981 | if(cCode == ISD::SETNE) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 982 | isNE = true; |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 983 | |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 984 | if (LeftZero || RightZero) { |
Andrew Lenharth | 09552bf | 2005-06-08 18:02:21 +0000 | [diff] [blame] | 985 | switch (cCode) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 986 | default: CC.Val->dump(); assert(0 && "Unknown integer comparison!"); |
| 987 | case ISD::SETEQ: Opc = Alpha::BEQ; break; |
| 988 | case ISD::SETLT: Opc = Alpha::BLT; break; |
| 989 | case ISD::SETLE: Opc = Alpha::BLE; break; |
| 990 | case ISD::SETGT: Opc = Alpha::BGT; break; |
| 991 | case ISD::SETGE: Opc = Alpha::BGE; break; |
| 992 | case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break; |
| 993 | case ISD::SETUGT: Opc = Alpha::BNE; break; |
| 994 | case ISD::SETULE: Opc = Alpha::BEQ; break; //Technically you could have this CC |
| 995 | case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break; |
| 996 | case ISD::SETNE: Opc = Alpha::BNE; break; |
| 997 | } |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 998 | unsigned Tmp1; |
| 999 | if(LeftZero && !RightZero) //swap Operands |
| 1000 | Tmp1 = SelectExpr(SetCC->getOperand(1)); //Cond |
| 1001 | else |
| 1002 | Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1003 | BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest); |
| 1004 | return; |
| 1005 | } else { |
| 1006 | unsigned Tmp1 = SelectExpr(CC); |
| 1007 | if (isNE) |
| 1008 | BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest); |
| 1009 | else |
| 1010 | BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest); |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1011 | return; |
| 1012 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1013 | } else { //FP |
| 1014 | //Any comparison between 2 values should be codegened as an folded branch, as moving |
| 1015 | //CC to the integer register is very expensive |
| 1016 | //for a cmp b: c = a - b; |
| 1017 | //a = b: c = 0 |
| 1018 | //a < b: c < 0 |
| 1019 | //a > b: c > 0 |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 1020 | |
| 1021 | bool invTest = false; |
| 1022 | unsigned Tmp3; |
| 1023 | |
| 1024 | ConstantFPSDNode *CN; |
| 1025 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1))) |
| 1026 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 1027 | Tmp3 = SelectExpr(SetCC->getOperand(0)); |
| 1028 | else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0))) |
| 1029 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 1030 | { |
| 1031 | Tmp3 = SelectExpr(SetCC->getOperand(1)); |
| 1032 | invTest = true; |
| 1033 | } |
| 1034 | else |
| 1035 | { |
| 1036 | unsigned Tmp1 = SelectExpr(SetCC->getOperand(0)); |
| 1037 | unsigned Tmp2 = SelectExpr(SetCC->getOperand(1)); |
| 1038 | bool isD = SetCC->getOperand(0).getValueType() == MVT::f64; |
| 1039 | Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32); |
| 1040 | BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3) |
| 1041 | .addReg(Tmp1).addReg(Tmp2); |
| 1042 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1043 | |
| 1044 | switch (SetCC->getCondition()) { |
| 1045 | default: CC.Val->dump(); assert(0 && "Unknown FP comparison!"); |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 1046 | case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break; |
| 1047 | case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break; |
| 1048 | case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break; |
| 1049 | case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break; |
| 1050 | case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break; |
| 1051 | case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1052 | } |
| 1053 | BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest); |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1054 | return; |
| 1055 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1056 | abort(); //Should never be reached |
| 1057 | } else { |
| 1058 | //Giveup and do the stupid thing |
| 1059 | unsigned Tmp1 = SelectExpr(CC); |
| 1060 | BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest); |
| 1061 | return; |
| 1062 | } |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1063 | abort(); //Should never be reached |
| 1064 | } |
| 1065 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1066 | unsigned AlphaISel::SelectExprFP(SDOperand N, unsigned Result) |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1067 | { |
| 1068 | unsigned Tmp1, Tmp2, Tmp3; |
| 1069 | unsigned Opc = 0; |
| 1070 | SDNode *Node = N.Val; |
| 1071 | MVT::ValueType DestType = N.getValueType(); |
| 1072 | unsigned opcode = N.getOpcode(); |
| 1073 | |
| 1074 | switch (opcode) { |
| 1075 | default: |
| 1076 | Node->dump(); |
| 1077 | assert(0 && "Node not handled!\n"); |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1078 | |
Andrew Lenharth | 7332f3e | 2005-04-02 19:11:07 +0000 | [diff] [blame] | 1079 | case ISD::UNDEF: { |
| 1080 | BuildMI(BB, Alpha::IDEF, 0, Result); |
| 1081 | return Result; |
| 1082 | } |
| 1083 | |
Andrew Lenharth | 30b46d4 | 2005-04-02 19:04:58 +0000 | [diff] [blame] | 1084 | case ISD::FNEG: |
| 1085 | if(ISD::FABS == N.getOperand(0).getOpcode()) |
| 1086 | { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1087 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1088 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Tmp1); |
Andrew Lenharth | 30b46d4 | 2005-04-02 19:04:58 +0000 | [diff] [blame] | 1089 | } else { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1090 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1091 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp1).addReg(Tmp1); |
Andrew Lenharth | 30b46d4 | 2005-04-02 19:04:58 +0000 | [diff] [blame] | 1092 | } |
| 1093 | return Result; |
| 1094 | |
| 1095 | case ISD::FABS: |
| 1096 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1097 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Tmp1); |
| 1098 | return Result; |
| 1099 | |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1100 | case ISD::SELECT: |
| 1101 | { |
Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1102 | //Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
| 1103 | unsigned TV = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 1104 | unsigned FV = SelectExpr(N.getOperand(2)); //Use if FALSE |
| 1105 | |
| 1106 | SDOperand CC = N.getOperand(0); |
| 1107 | SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val); |
| 1108 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1109 | if (CC.getOpcode() == ISD::SETCC && |
Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1110 | !MVT::isInteger(SetCC->getOperand(0).getValueType())) |
| 1111 | { //FP Setcc -> Select yay! |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1112 | |
| 1113 | |
Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1114 | //for a cmp b: c = a - b; |
| 1115 | //a = b: c = 0 |
| 1116 | //a < b: c < 0 |
| 1117 | //a > b: c > 0 |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1118 | |
Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1119 | bool invTest = false; |
| 1120 | unsigned Tmp3; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1121 | |
Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1122 | ConstantFPSDNode *CN; |
| 1123 | if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1))) |
| 1124 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 1125 | Tmp3 = SelectExpr(SetCC->getOperand(0)); |
| 1126 | else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0))) |
| 1127 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 1128 | { |
| 1129 | Tmp3 = SelectExpr(SetCC->getOperand(1)); |
| 1130 | invTest = true; |
| 1131 | } |
| 1132 | else |
| 1133 | { |
| 1134 | unsigned Tmp1 = SelectExpr(SetCC->getOperand(0)); |
| 1135 | unsigned Tmp2 = SelectExpr(SetCC->getOperand(1)); |
| 1136 | bool isD = SetCC->getOperand(0).getValueType() == MVT::f64; |
| 1137 | Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32); |
| 1138 | BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3) |
| 1139 | .addReg(Tmp1).addReg(Tmp2); |
| 1140 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1141 | |
Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1142 | switch (SetCC->getCondition()) { |
| 1143 | default: CC.Val->dump(); assert(0 && "Unknown FP comparison!"); |
| 1144 | case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNE : Alpha::FCMOVEQ; break; |
| 1145 | case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGT : Alpha::FCMOVLT; break; |
| 1146 | case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGE : Alpha::FCMOVLE; break; |
| 1147 | case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLT : Alpha::FCMOVGT; break; |
| 1148 | case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLE : Alpha::FCMOVGE; break; |
| 1149 | case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQ : Alpha::FCMOVNE; break; |
| 1150 | } |
Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 1151 | BuildMI(BB, Opc, 3, Result).addReg(FV).addReg(TV).addReg(Tmp3); |
Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1152 | return Result; |
| 1153 | } |
| 1154 | else |
| 1155 | { |
| 1156 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1157 | BuildMI(BB, Alpha::FCMOVEQ_INT, 3, Result).addReg(TV).addReg(FV).addReg(Tmp1); |
| 1158 | // // Spill the cond to memory and reload it from there. |
| 1159 | // unsigned Tmp4 = MakeReg(MVT::f64); |
| 1160 | // MoveIntFP(Tmp1, Tmp4, true); |
| 1161 | // //now ideally, we don't have to do anything to the flag... |
| 1162 | // // Get the condition into the zero flag. |
| 1163 | // BuildMI(BB, Alpha::FCMOVEQ, 3, Result).addReg(TV).addReg(FV).addReg(Tmp4); |
Andrew Lenharth | 4585969 | 2005-03-03 21:47:53 +0000 | [diff] [blame] | 1164 | return Result; |
| 1165 | } |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Andrew Lenharth | c1faced | 2005-02-01 01:37:24 +0000 | [diff] [blame] | 1168 | case ISD::FP_ROUND: |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1169 | assert (DestType == MVT::f32 && |
| 1170 | N.getOperand(0).getValueType() == MVT::f64 && |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1171 | "only f64 to f32 conversion supported here"); |
Andrew Lenharth | c1faced | 2005-02-01 01:37:24 +0000 | [diff] [blame] | 1172 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1173 | BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1); |
| 1174 | return Result; |
| 1175 | |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 1176 | case ISD::FP_EXTEND: |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1177 | assert (DestType == MVT::f64 && |
| 1178 | N.getOperand(0).getValueType() == MVT::f32 && |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1179 | "only f32 to f64 conversion supported here"); |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 1180 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1181 | BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1); |
| 1182 | return Result; |
| 1183 | |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1184 | case ISD::CopyFromReg: |
| 1185 | { |
| 1186 | // Make sure we generate both values. |
| 1187 | if (Result != notIn) |
| 1188 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 1189 | else |
| 1190 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1191 | |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1192 | SDOperand Chain = N.getOperand(0); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1193 | |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1194 | Select(Chain); |
| 1195 | unsigned r = dyn_cast<RegSDNode>(Node)->getReg(); |
| 1196 | //std::cerr << "CopyFromReg " << Result << " = " << r << "\n"; |
| 1197 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r); |
| 1198 | return Result; |
| 1199 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1200 | |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1201 | case ISD::LOAD: |
| 1202 | { |
| 1203 | // Make sure we generate both values. |
| 1204 | if (Result != notIn) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1205 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1206 | else |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1207 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 1208 | |
Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 1209 | DestType = N.getValue(0).getValueType(); |
Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 1210 | |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1211 | SDOperand Chain = N.getOperand(0); |
| 1212 | SDOperand Address = N.getOperand(1); |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1213 | Select(Chain); |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 1214 | Opc = DestType == MVT::f64 ? Alpha::LDT : Alpha::LDS; |
| 1215 | |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 1216 | if (EnableAlphaLSMark) |
| 1217 | { |
| 1218 | int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue()); |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1219 | int j = getFunctionOffset(BB->getParent()->getFunction()); |
| 1220 | BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID()); |
Andrew Lenharth | cd7f8cf | 2005-06-06 19:03:55 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1223 | if (Address.getOpcode() == ISD::GlobalAddress) { |
| 1224 | AlphaLowering.restoreGP(BB); |
| 1225 | Opc = GetSymVersion(Opc); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1226 | has_sym = true; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1227 | BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); |
| 1228 | } |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1229 | else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) { |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1230 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 1231 | Opc = GetSymVersion(Opc); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1232 | has_sym = true; |
Andrew Lenharth | 97127a1 | 2005-02-05 17:41:39 +0000 | [diff] [blame] | 1233 | BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex()); |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1234 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1235 | else if(Address.getOpcode() == ISD::FrameIndex) { |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1236 | BuildMI(BB, Opc, 2, Result) |
| 1237 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) |
| 1238 | .addReg(Alpha::F31); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1239 | } else { |
| 1240 | long offset; |
| 1241 | SelectAddr(Address, Tmp1, offset); |
| 1242 | BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1); |
| 1243 | } |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1244 | return Result; |
| 1245 | } |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1246 | case ISD::ConstantFP: |
| 1247 | if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) { |
| 1248 | if (CN->isExactlyValue(+0.0)) { |
| 1249 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31); |
Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 1250 | } else if ( CN->isExactlyValue(-0.0)) { |
| 1251 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31); |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1252 | } else { |
| 1253 | abort(); |
| 1254 | } |
| 1255 | } |
| 1256 | return Result; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1257 | |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1258 | case ISD::SDIV: |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1259 | case ISD::MUL: |
| 1260 | case ISD::ADD: |
| 1261 | case ISD::SUB: |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1262 | switch( opcode ) { |
| 1263 | case ISD::MUL: Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; break; |
| 1264 | case ISD::ADD: Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; break; |
| 1265 | case ISD::SUB: Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; break; |
| 1266 | case ISD::SDIV: Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; break; |
| 1267 | }; |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 1268 | |
| 1269 | ConstantFPSDNode *CN; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1270 | if (opcode == ISD::SUB |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 1271 | && (CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0))) |
| 1272 | && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0))) |
| 1273 | { |
| 1274 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1275 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp2).addReg(Tmp2); |
| 1276 | } else { |
| 1277 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1278 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1279 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1280 | } |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1281 | return Result; |
| 1282 | |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1283 | case ISD::EXTLOAD: |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1284 | { |
| 1285 | //include a conversion sequence for float loads to double |
| 1286 | if (Result != notIn) |
| 1287 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 1288 | else |
| 1289 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1290 | |
Andrew Lenharth | a549deb | 2005-02-07 05:33:15 +0000 | [diff] [blame] | 1291 | Tmp1 = MakeReg(MVT::f32); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1292 | |
| 1293 | assert(cast<MVTSDNode>(Node)->getExtraValueType() == MVT::f32 && |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1294 | "EXTLOAD not from f32"); |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1295 | assert(Node->getValueType(0) == MVT::f64 && "EXTLOAD not to f64"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1296 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1297 | SDOperand Chain = N.getOperand(0); |
| 1298 | SDOperand Address = N.getOperand(1); |
| 1299 | Select(Chain); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1300 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1301 | if (Address.getOpcode() == ISD::GlobalAddress) { |
| 1302 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1303 | has_sym = true; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1304 | BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); |
| 1305 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1306 | else if (ConstantPoolSDNode *CP = |
| 1307 | dyn_cast<ConstantPoolSDNode>(N.getOperand(1))) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1308 | { |
| 1309 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1310 | has_sym = true; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1311 | BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addConstantPoolIndex(CP->getIndex()); |
| 1312 | } |
| 1313 | else if(Address.getOpcode() == ISD::FrameIndex) { |
| 1314 | Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex(); |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1315 | BuildMI(BB, Alpha::LDS, 2, Tmp1) |
| 1316 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) |
| 1317 | .addReg(Alpha::F31); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1318 | } else { |
| 1319 | long offset; |
| 1320 | SelectAddr(Address, Tmp2, offset); |
| 1321 | BuildMI(BB, Alpha::LDS, 1, Tmp1).addImm(offset).addReg(Tmp2); |
| 1322 | } |
Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 1323 | BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 1324 | return Result; |
| 1325 | } |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1326 | |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1327 | case ISD::UINT_TO_FP: |
Andrew Lenharth | 69520ed | 2005-05-26 18:18:34 +0000 | [diff] [blame] | 1328 | { |
| 1329 | //FIXME: First test if we will have problems with the sign bit before doing the slow thing |
| 1330 | assert (N.getOperand(0).getValueType() == MVT::i64 |
| 1331 | && "only quads can be loaded from"); |
| 1332 | Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register |
| 1333 | Tmp2 = MakeReg(MVT::i64); |
| 1334 | BuildMI(BB, Alpha::SRL, 2, Tmp2).addReg(Tmp1).addImm(1); |
| 1335 | Tmp3 = MakeReg(MVT::i64); |
| 1336 | BuildMI(BB, Alpha::CMPLT, 2, Tmp3).addReg(Tmp1).addReg(Alpha::R31); |
| 1337 | unsigned Tmp4 = MakeReg(MVT::f64), Tmp5 = MakeReg(MVT::f64), Tmp6 = MakeReg(MVT::f64); |
| 1338 | MoveInt2FP(Tmp1, Tmp4, true); |
| 1339 | MoveInt2FP(Tmp2, Tmp5, true); |
| 1340 | MoveInt2FP(Tmp3, Tmp6, true); |
| 1341 | Tmp1 = MakeReg(MVT::f64); |
| 1342 | Tmp2 = MakeReg(MVT::f64); |
| 1343 | Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS; |
| 1344 | BuildMI(BB, Opc, 1, Tmp1).addReg(Tmp4); |
| 1345 | BuildMI(BB, Opc, 1, Tmp2).addReg(Tmp5); |
| 1346 | Tmp3 = MakeReg(MVT::f64); |
| 1347 | BuildMI(BB, Alpha::ADDT, 2, Tmp3).addReg(Tmp2).addReg(Tmp2); |
| 1348 | //Ok, now tmp1 had the plain covereted |
| 1349 | //tmp3 has the reduced converted and added |
| 1350 | //tmp6 has the conditional to use |
| 1351 | BuildMI(BB, Alpha::FCMOVNE, 3, Result).addReg(Tmp1).addReg(Tmp3).addReg(Tmp6); |
| 1352 | return Result; |
| 1353 | } |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1354 | case ISD::SINT_TO_FP: |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1355 | { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1356 | assert (N.getOperand(0).getValueType() == MVT::i64 |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1357 | && "only quads can be loaded from"); |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1358 | Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 1359 | Tmp2 = MakeReg(MVT::f64); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1360 | MoveInt2FP(Tmp1, Tmp2, true); |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 1361 | Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS; |
| 1362 | BuildMI(BB, Opc, 1, Result).addReg(Tmp2); |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1363 | return Result; |
| 1364 | } |
| 1365 | } |
| 1366 | assert(0 && "should not get here"); |
| 1367 | return 0; |
| 1368 | } |
| 1369 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1370 | unsigned AlphaISel::SelectExpr(SDOperand N) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1371 | unsigned Result; |
Andrew Lenharth | 2966e84 | 2005-04-07 18:15:28 +0000 | [diff] [blame] | 1372 | unsigned Tmp1, Tmp2 = 0, Tmp3; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1373 | unsigned Opc = 0; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1374 | unsigned opcode = N.getOpcode(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1375 | |
| 1376 | SDNode *Node = N.Val; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1377 | MVT::ValueType DestType = N.getValueType(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1378 | |
| 1379 | unsigned &Reg = ExprMap[N]; |
| 1380 | if (Reg) return Reg; |
| 1381 | |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 1382 | if (N.getOpcode() != ISD::CALL && N.getOpcode() != ISD::TAILCALL) |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1383 | Reg = Result = (N.getValueType() != MVT::Other) ? |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1384 | MakeReg(N.getValueType()) : notIn; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1385 | else { |
| 1386 | // If this is a call instruction, make sure to prepare ALL of the result |
| 1387 | // values as well as the chain. |
| 1388 | if (Node->getNumValues() == 1) |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1389 | Reg = Result = notIn; // Void call, just a chain. |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1390 | else { |
| 1391 | Result = MakeReg(Node->getValueType(0)); |
| 1392 | ExprMap[N.getValue(0)] = Result; |
| 1393 | for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i) |
| 1394 | ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i)); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1395 | ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | |
Andrew Lenharth | 50d91d7 | 2005-04-30 14:19:13 +0000 | [diff] [blame] | 1399 | if ((DestType == MVT::f64 || DestType == MVT::f32 || |
| 1400 | ( |
| 1401 | (opcode == ISD::LOAD || opcode == ISD::CopyFromReg || |
| 1402 | opcode == ISD::EXTLOAD) && |
| 1403 | (N.getValue(0).getValueType() == MVT::f32 || |
| 1404 | N.getValue(0).getValueType() == MVT::f64) |
| 1405 | )) |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 1406 | && opcode != ISD::CALL && opcode != ISD::TAILCALL |
Andrew Lenharth | 06342c3 | 2005-02-07 06:21:37 +0000 | [diff] [blame] | 1407 | ) |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1408 | return SelectExprFP(N, Result); |
| 1409 | |
| 1410 | switch (opcode) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1411 | default: |
| 1412 | Node->dump(); |
| 1413 | assert(0 && "Node not handled!\n"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1414 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 1415 | case ISD::CTPOP: |
| 1416 | case ISD::CTTZ: |
| 1417 | case ISD::CTLZ: |
| 1418 | Opc = opcode == ISD::CTPOP ? Alpha::CTPOP : |
| 1419 | (opcode == ISD::CTTZ ? Alpha::CTTZ : Alpha::CTLZ); |
| 1420 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1421 | BuildMI(BB, Opc, 1, Result).addReg(Tmp1); |
| 1422 | return Result; |
| 1423 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1424 | case ISD::MULHU: |
| 1425 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1426 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1427 | BuildMI(BB, Alpha::UMULH, 2, Result).addReg(Tmp1).addReg(Tmp2); |
Andrew Lenharth | 706be91 | 2005-04-07 13:55:53 +0000 | [diff] [blame] | 1428 | return Result; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 1429 | case ISD::MULHS: |
| 1430 | { |
| 1431 | //MULHU - Ra<63>*Rb - Rb<63>*Ra |
| 1432 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1433 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1434 | Tmp3 = MakeReg(MVT::i64); |
| 1435 | BuildMI(BB, Alpha::UMULH, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); |
| 1436 | unsigned V1 = MakeReg(MVT::i64); |
| 1437 | unsigned V2 = MakeReg(MVT::i64); |
| 1438 | BuildMI(BB, Alpha::CMOVGE, 3, V1).addReg(Tmp2).addReg(Alpha::R31).addReg(Tmp1); |
| 1439 | BuildMI(BB, Alpha::CMOVGE, 3, V2).addReg(Tmp1).addReg(Alpha::R31).addReg(Tmp2); |
| 1440 | unsigned IRes = MakeReg(MVT::i64); |
| 1441 | BuildMI(BB, Alpha::SUBQ, 2, IRes).addReg(Tmp3).addReg(V1); |
| 1442 | BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(IRes).addReg(V2); |
| 1443 | return Result; |
| 1444 | } |
Andrew Lenharth | 7332f3e | 2005-04-02 19:11:07 +0000 | [diff] [blame] | 1445 | case ISD::UNDEF: { |
| 1446 | BuildMI(BB, Alpha::IDEF, 0, Result); |
| 1447 | return Result; |
| 1448 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1449 | |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1450 | case ISD::DYNAMIC_STACKALLOC: |
| 1451 | // Generate both result values. |
Andrew Lenharth | 3a7118d | 2005-02-23 17:33:42 +0000 | [diff] [blame] | 1452 | if (Result != notIn) |
| 1453 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1454 | else |
| 1455 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
| 1456 | |
| 1457 | // FIXME: We are currently ignoring the requested alignment for handling |
| 1458 | // greater than the stack alignment. This will need to be revisited at some |
| 1459 | // point. Align = N.getOperand(2); |
| 1460 | |
| 1461 | if (!isa<ConstantSDNode>(N.getOperand(2)) || |
| 1462 | cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) { |
| 1463 | std::cerr << "Cannot allocate stack object with greater alignment than" |
| 1464 | << " the stack alignment yet!"; |
| 1465 | abort(); |
| 1466 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1467 | |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1468 | Select(N.getOperand(0)); |
| 1469 | if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) |
| 1470 | { |
| 1471 | if (CN->getValue() < 32000) |
| 1472 | { |
| 1473 | BuildMI(BB, Alpha::LDA, 2, Alpha::R30) |
| 1474 | .addImm(-CN->getValue()).addReg(Alpha::R30); |
| 1475 | } else { |
| 1476 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1477 | // Subtract size from stack pointer, thereby allocating some space. |
| 1478 | BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1); |
| 1479 | } |
| 1480 | } else { |
| 1481 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1482 | // Subtract size from stack pointer, thereby allocating some space. |
| 1483 | BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1); |
| 1484 | } |
| 1485 | |
| 1486 | // Put a pointer to the space into the result register, by copying the stack |
| 1487 | // pointer. |
Andrew Lenharth | 7bc4702 | 2005-02-22 23:29:25 +0000 | [diff] [blame] | 1488 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30); |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1489 | return Result; |
| 1490 | |
Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 1491 | // case ISD::ConstantPool: |
| 1492 | // Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex(); |
| 1493 | // AlphaLowering.restoreGP(BB); |
| 1494 | // BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(Tmp1); |
| 1495 | // return Result; |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1496 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1497 | case ISD::FrameIndex: |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1498 | BuildMI(BB, Alpha::LDA, 2, Result) |
| 1499 | .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex()) |
| 1500 | .addReg(Alpha::F31); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1501 | return Result; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1502 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1503 | case ISD::EXTLOAD: |
Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 1504 | case ISD::ZEXTLOAD: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1505 | case ISD::SEXTLOAD: |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1506 | case ISD::LOAD: |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1507 | { |
| 1508 | // Make sure we generate both values. |
| 1509 | if (Result != notIn) |
| 1510 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 1511 | else |
| 1512 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1513 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1514 | SDOperand Chain = N.getOperand(0); |
| 1515 | SDOperand Address = N.getOperand(1); |
| 1516 | Select(Chain); |
| 1517 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1518 | assert(Node->getValueType(0) == MVT::i64 && |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1519 | "Unknown type to sign extend to."); |
Andrew Lenharth | 0382401 | 2005-02-07 05:55:55 +0000 | [diff] [blame] | 1520 | if (opcode == ISD::LOAD) |
| 1521 | Opc = Alpha::LDQ; |
| 1522 | else |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1523 | switch (cast<MVTSDNode>(Node)->getExtraValueType()) { |
| 1524 | default: Node->dump(); assert(0 && "Bad sign extend!"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1525 | case MVT::i32: Opc = Alpha::LDL; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1526 | assert(opcode != ISD::ZEXTLOAD && "Not sext"); break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1527 | case MVT::i16: Opc = Alpha::LDWU; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1528 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; |
Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 1529 | case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1530 | case MVT::i8: Opc = Alpha::LDBU; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1531 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1532 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1533 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 1534 | if (EnableAlphaLSMark) |
| 1535 | { |
| 1536 | int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue()); |
| 1537 | int j = getFunctionOffset(BB->getParent()->getFunction()); |
| 1538 | BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID()); |
| 1539 | } |
| 1540 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1541 | if (Address.getOpcode() == ISD::GlobalAddress) { |
| 1542 | AlphaLowering.restoreGP(BB); |
| 1543 | Opc = GetSymVersion(Opc); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1544 | has_sym = true; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1545 | BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); |
| 1546 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1547 | else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) { |
| 1548 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 1549 | Opc = GetSymVersion(Opc); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1550 | has_sym = true; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1551 | BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex()); |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1552 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1553 | else if(Address.getOpcode() == ISD::FrameIndex) { |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 1554 | BuildMI(BB, Opc, 2, Result) |
| 1555 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) |
| 1556 | .addReg(Alpha::F31); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1557 | } else { |
| 1558 | long offset; |
| 1559 | SelectAddr(Address, Tmp1, offset); |
| 1560 | BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1); |
| 1561 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1562 | return Result; |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 1563 | } |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 1564 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1565 | case ISD::GlobalAddress: |
| 1566 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1567 | has_sym = true; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1568 | BuildMI(BB, Alpha::LOAD_ADDR, 1, Result) |
| 1569 | .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal()); |
| 1570 | return Result; |
| 1571 | |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 1572 | case ISD::TAILCALL: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1573 | case ISD::CALL: |
| 1574 | { |
| 1575 | Select(N.getOperand(0)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1576 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1577 | // The chain for this call is now lowered. |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1578 | ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1579 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1580 | //grab the arguments |
| 1581 | std::vector<unsigned> argvregs; |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 1582 | //assert(Node->getNumOperands() < 8 && "Only 6 args supported"); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1583 | for(int i = 2, e = Node->getNumOperands(); i < e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1584 | argvregs.push_back(SelectExpr(N.getOperand(i))); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1585 | |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 1586 | //in reg args |
| 1587 | for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1588 | { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1589 | unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18, |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1590 | Alpha::R19, Alpha::R20, Alpha::R21}; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1591 | unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18, |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1592 | Alpha::F19, Alpha::F20, Alpha::F21}; |
| 1593 | switch(N.getOperand(i+2).getValueType()) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1594 | default: |
| 1595 | Node->dump(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1596 | N.getOperand(i).Val->dump(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1597 | std::cerr << "Type for " << i << " is: " << |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1598 | N.getOperand(i+2).getValueType() << "\n"; |
| 1599 | assert(0 && "Unknown value type for call"); |
| 1600 | case MVT::i1: |
| 1601 | case MVT::i8: |
| 1602 | case MVT::i16: |
| 1603 | case MVT::i32: |
| 1604 | case MVT::i64: |
| 1605 | BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]).addReg(argvregs[i]); |
| 1606 | break; |
| 1607 | case MVT::f32: |
| 1608 | case MVT::f64: |
| 1609 | BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i]).addReg(argvregs[i]); |
| 1610 | break; |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 1611 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1612 | } |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 1613 | //in mem args |
| 1614 | for (int i = 6, e = argvregs.size(); i < e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1615 | { |
| 1616 | switch(N.getOperand(i+2).getValueType()) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1617 | default: |
| 1618 | Node->dump(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1619 | N.getOperand(i).Val->dump(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1620 | std::cerr << "Type for " << i << " is: " << |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1621 | N.getOperand(i+2).getValueType() << "\n"; |
| 1622 | assert(0 && "Unknown value type for call"); |
| 1623 | case MVT::i1: |
| 1624 | case MVT::i8: |
| 1625 | case MVT::i16: |
| 1626 | case MVT::i32: |
| 1627 | case MVT::i64: |
| 1628 | BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); |
| 1629 | break; |
| 1630 | case MVT::f32: |
| 1631 | BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); |
| 1632 | break; |
| 1633 | case MVT::f64: |
| 1634 | BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); |
| 1635 | break; |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 1636 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1637 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1638 | //build the right kind of call |
| 1639 | if (GlobalAddressSDNode *GASD = |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1640 | dyn_cast<GlobalAddressSDNode>(N.getOperand(1))) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1641 | { |
Andrew Lenharth | c24b537 | 2005-04-13 17:17:28 +0000 | [diff] [blame] | 1642 | if (GASD->getGlobal()->isExternal()) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1643 | //use safe calling convention |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 1644 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1645 | has_sym = true; |
Andrew Lenharth | c24b537 | 2005-04-13 17:17:28 +0000 | [diff] [blame] | 1646 | BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal()); |
| 1647 | } else { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1648 | //use PC relative branch call |
Andrew Lenharth | 1e0d9bd | 2005-04-14 17:34:20 +0000 | [diff] [blame] | 1649 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | c24b537 | 2005-04-13 17:17:28 +0000 | [diff] [blame] | 1650 | BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true); |
| 1651 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1652 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1653 | else if (ExternalSymbolSDNode *ESSDN = |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1654 | dyn_cast<ExternalSymbolSDNode>(N.getOperand(1))) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1655 | { |
| 1656 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1657 | has_sym = true; |
Andrew Lenharth | ba05ad6 | 2005-03-30 18:22:52 +0000 | [diff] [blame] | 1658 | BuildMI(BB, Alpha::CALL, 1).addExternalSymbol(ESSDN->getSymbol(), true); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1659 | } else { |
| 1660 | //no need to restore GP as we are doing an indirect call |
| 1661 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1662 | BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1); |
| 1663 | BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0); |
| 1664 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1665 | |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1666 | //push the result into a virtual register |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1667 | |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1668 | switch (Node->getValueType(0)) { |
| 1669 | default: Node->dump(); assert(0 && "Unknown value type for call result!"); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1670 | case MVT::Other: return notIn; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1671 | case MVT::i1: |
| 1672 | case MVT::i8: |
| 1673 | case MVT::i16: |
| 1674 | case MVT::i32: |
| 1675 | case MVT::i64: |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1676 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0); |
| 1677 | break; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1678 | case MVT::f32: |
| 1679 | case MVT::f64: |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1680 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0); |
| 1681 | break; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1682 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1683 | return Result+N.ResNo; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1686 | case ISD::SIGN_EXTEND_INREG: |
| 1687 | { |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1688 | //do SDIV opt for all levels of ints if not dividing by a constant |
| 1689 | if (EnableAlphaIDIV && N.getOperand(0).getOpcode() == ISD::SDIV |
| 1690 | && N.getOperand(0).getOperand(1).getOpcode() != ISD::Constant) |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1691 | { |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1692 | unsigned Tmp4 = MakeReg(MVT::f64); |
| 1693 | unsigned Tmp5 = MakeReg(MVT::f64); |
| 1694 | unsigned Tmp6 = MakeReg(MVT::f64); |
| 1695 | unsigned Tmp7 = MakeReg(MVT::f64); |
| 1696 | unsigned Tmp8 = MakeReg(MVT::f64); |
| 1697 | unsigned Tmp9 = MakeReg(MVT::f64); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1698 | |
| 1699 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1700 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
| 1701 | MoveInt2FP(Tmp1, Tmp4, true); |
| 1702 | MoveInt2FP(Tmp2, Tmp5, true); |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1703 | BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Tmp4); |
| 1704 | BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Tmp5); |
| 1705 | BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7); |
| 1706 | BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Tmp8); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1707 | MoveFP2Int(Tmp9, Result, true); |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1708 | return Result; |
| 1709 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1710 | |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1711 | //Alpha has instructions for a bunch of signed 32 bit stuff |
| 1712 | if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32) |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1713 | { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1714 | switch (N.getOperand(0).getOpcode()) { |
| 1715 | case ISD::ADD: |
| 1716 | case ISD::SUB: |
| 1717 | case ISD::MUL: |
| 1718 | { |
| 1719 | bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD; |
| 1720 | bool isMul = N.getOperand(0).getOpcode() == ISD::MUL; |
| 1721 | //FIXME: first check for Scaled Adds and Subs! |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1722 | ConstantSDNode* CSD = NULL; |
| 1723 | if(!isMul && N.getOperand(0).getOperand(0).getOpcode() == ISD::SHL && |
| 1724 | (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(0).getOperand(1))) && |
| 1725 | (CSD->getValue() == 2 || CSD->getValue() == 3)) |
| 1726 | { |
| 1727 | bool use4 = CSD->getValue() == 2; |
| 1728 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0)); |
| 1729 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
| 1730 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDL:Alpha::S8ADDL):(use4?Alpha::S4SUBL:Alpha::S8SUBL), |
| 1731 | 2,Result).addReg(Tmp1).addReg(Tmp2); |
| 1732 | } |
| 1733 | else if(isAdd && N.getOperand(0).getOperand(1).getOpcode() == ISD::SHL && |
| 1734 | (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1).getOperand(1))) && |
| 1735 | (CSD->getValue() == 2 || CSD->getValue() == 3)) |
| 1736 | { |
| 1737 | bool use4 = CSD->getValue() == 2; |
| 1738 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0)); |
| 1739 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1740 | BuildMI(BB, use4?Alpha::S4ADDL:Alpha::S8ADDL, 2,Result).addReg(Tmp1).addReg(Tmp2); |
| 1741 | } |
| 1742 | else if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant && |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1743 | cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255) |
| 1744 | { //Normal imm add/sub |
| 1745 | Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1746 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1747 | Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue(); |
| 1748 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1749 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1750 | else |
| 1751 | { //Normal add/sub |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1752 | Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULL : Alpha::SUBL); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1753 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 1754 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1755 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1756 | } |
| 1757 | return Result; |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1758 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1759 | default: break; //Fall Though; |
| 1760 | } |
| 1761 | } //Every thing else fall though too, including unhandled opcodes above |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1762 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1763 | MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node); |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1764 | //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n"; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1765 | switch(MVN->getExtraValueType()) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1766 | { |
| 1767 | default: |
| 1768 | Node->dump(); |
| 1769 | assert(0 && "Sign Extend InReg not there yet"); |
| 1770 | break; |
| 1771 | case MVT::i32: |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1772 | { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1773 | BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0); |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1774 | break; |
| 1775 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1776 | case MVT::i16: |
| 1777 | BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1); |
| 1778 | break; |
| 1779 | case MVT::i8: |
| 1780 | BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1); |
| 1781 | break; |
Andrew Lenharth | ebce504 | 2005-02-12 19:35:12 +0000 | [diff] [blame] | 1782 | case MVT::i1: |
| 1783 | Tmp2 = MakeReg(MVT::i64); |
| 1784 | BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1785 | BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp2); |
Andrew Lenharth | ebce504 | 2005-02-12 19:35:12 +0000 | [diff] [blame] | 1786 | break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1787 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1788 | return Result; |
| 1789 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1790 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1791 | case ISD::SETCC: |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1792 | { |
| 1793 | if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) { |
| 1794 | if (MVT::isInteger(SetCC->getOperand(0).getValueType())) { |
| 1795 | bool isConst1 = false; |
| 1796 | bool isConst2 = false; |
| 1797 | int dir; |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1798 | |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1799 | //Tmp1 = SelectExpr(N.getOperand(0)); |
| 1800 | if(N.getOperand(0).getOpcode() == ISD::Constant && |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1801 | cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 255) |
| 1802 | isConst1 = true; |
| 1803 | if(N.getOperand(1).getOpcode() == ISD::Constant && |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1804 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255) |
| 1805 | isConst2 = true; |
| 1806 | |
| 1807 | switch (SetCC->getCondition()) { |
| 1808 | default: Node->dump(); assert(0 && "Unknown integer comparison!"); |
| 1809 | case ISD::SETEQ: Opc = Alpha::CMPEQ; dir=0; break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1810 | case ISD::SETLT: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1811 | Opc = isConst2 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1812 | case ISD::SETLE: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1813 | Opc = isConst2 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1814 | case ISD::SETGT: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1815 | Opc = isConst1 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 2; break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1816 | case ISD::SETGE: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1817 | Opc = isConst1 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 2; break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1818 | case ISD::SETULT: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1819 | Opc = isConst2 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1820 | case ISD::SETUGT: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1821 | Opc = isConst1 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 2; break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1822 | case ISD::SETULE: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1823 | Opc = isConst2 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1824 | case ISD::SETUGE: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1825 | Opc = isConst1 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 2; break; |
Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1826 | case ISD::SETNE: {//Handle this one special |
| 1827 | //std::cerr << "Alpha does not have a setne.\n"; |
| 1828 | //abort(); |
| 1829 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1830 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1831 | Tmp3 = MakeReg(MVT::i64); |
| 1832 | BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1833 | //Remeber we have the Inv for this CC |
| 1834 | CCInvMap[N] = Tmp3; |
Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1835 | //and invert |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1836 | BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3); |
Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1837 | return Result; |
| 1838 | } |
| 1839 | } |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1840 | if (dir == 1) { |
| 1841 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1842 | if (isConst2) { |
| 1843 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1844 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1845 | } else { |
| 1846 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1847 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1848 | } |
| 1849 | } else if (dir == 2) { |
| 1850 | Tmp1 = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 1851 | if (isConst1) { |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1852 | Tmp2 = cast<ConstantSDNode>(N.getOperand(0))->getValue(); |
| 1853 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1854 | } else { |
| 1855 | Tmp2 = SelectExpr(N.getOperand(0)); |
| 1856 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1857 | } |
| 1858 | } else { //dir == 0 |
| 1859 | if (isConst1) { |
| 1860 | Tmp1 = cast<ConstantSDNode>(N.getOperand(0))->getValue(); |
| 1861 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1862 | BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp2).addImm(Tmp1); |
| 1863 | } else if (isConst2) { |
| 1864 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1865 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1866 | BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1867 | } else { |
| 1868 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1869 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1870 | BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1871 | } |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1872 | } |
| 1873 | } else { |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1874 | //do the comparison |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1875 | Tmp1 = MakeReg(MVT::f64); |
| 1876 | bool inv = SelectFPSetCC(N, Tmp1); |
| 1877 | |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1878 | //now arrange for Result (int) to have a 1 or 0 |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1879 | Tmp2 = MakeReg(MVT::i64); |
| 1880 | BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1); |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 1881 | Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP; |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 1882 | BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1); |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1883 | } |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1884 | } |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1885 | return Result; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1886 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1887 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1888 | case ISD::CopyFromReg: |
| 1889 | { |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1890 | ++count_ins; |
| 1891 | |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1892 | // Make sure we generate both values. |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1893 | if (Result != notIn) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1894 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1895 | else |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1896 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1897 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1898 | SDOperand Chain = N.getOperand(0); |
| 1899 | |
| 1900 | Select(Chain); |
| 1901 | unsigned r = dyn_cast<RegSDNode>(Node)->getReg(); |
| 1902 | //std::cerr << "CopyFromReg " << Result << " = " << r << "\n"; |
| 1903 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r); |
| 1904 | return Result; |
| 1905 | } |
| 1906 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1907 | //Most of the plain arithmetic and logic share the same form, and the same |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1908 | //constant immediate test |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1909 | case ISD::XOR: |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1910 | //Match Not |
| 1911 | if (N.getOperand(1).getOpcode() == ISD::Constant && |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1912 | cast<ConstantSDNode>(N.getOperand(1))->getSignExtended() == -1) |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1913 | { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1914 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1915 | BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1); |
| 1916 | return Result; |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1917 | } |
| 1918 | //Fall through |
| 1919 | case ISD::AND: |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1920 | //handle zap |
| 1921 | if (opcode == ISD::AND && N.getOperand(1).getOpcode() == ISD::Constant) |
| 1922 | { |
| 1923 | uint64_t k = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1924 | unsigned int build = 0; |
| 1925 | for(int i = 0; i < 8; ++i) |
| 1926 | { |
Andrew Lenharth | 3ae1829 | 2005-04-14 16:24:00 +0000 | [diff] [blame] | 1927 | if ((k & 0x00FF) == 0x00FF) |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1928 | build |= 1 << i; |
Andrew Lenharth | 3ae1829 | 2005-04-14 16:24:00 +0000 | [diff] [blame] | 1929 | else if ((k & 0x00FF) != 0) |
Andrew Lenharth | 483f22d | 2005-04-13 03:47:03 +0000 | [diff] [blame] | 1930 | { build = 0; break; } |
| 1931 | k >>= 8; |
| 1932 | } |
| 1933 | if (build) |
| 1934 | { |
| 1935 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1936 | BuildMI(BB, Alpha::ZAPNOTi, 2, Result).addReg(Tmp1).addImm(build); |
| 1937 | return Result; |
| 1938 | } |
| 1939 | } |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 1940 | case ISD::OR: |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1941 | //Check operand(0) == Not |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1942 | if (N.getOperand(0).getOpcode() == ISD::XOR && |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1943 | N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant && |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1944 | cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getSignExtended() == -1) |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1945 | { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1946 | switch(opcode) { |
| 1947 | case ISD::AND: Opc = Alpha::BIC; break; |
| 1948 | case ISD::OR: Opc = Alpha::ORNOT; break; |
| 1949 | case ISD::XOR: Opc = Alpha::EQV; break; |
| 1950 | } |
| 1951 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1952 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 1953 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1954 | return Result; |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1955 | } |
| 1956 | //Check operand(1) == Not |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 1957 | if (N.getOperand(1).getOpcode() == ISD::XOR && |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1958 | N.getOperand(1).getOperand(1).getOpcode() == ISD::Constant && |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1959 | cast<ConstantSDNode>(N.getOperand(1).getOperand(1))->getSignExtended() == -1) |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1960 | { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 1961 | switch(opcode) { |
| 1962 | case ISD::AND: Opc = Alpha::BIC; break; |
| 1963 | case ISD::OR: Opc = Alpha::ORNOT; break; |
| 1964 | case ISD::XOR: Opc = Alpha::EQV; break; |
| 1965 | } |
| 1966 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1967 | Tmp2 = SelectExpr(N.getOperand(1).getOperand(0)); |
| 1968 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1969 | return Result; |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 1970 | } |
| 1971 | //Fall through |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1972 | case ISD::SHL: |
| 1973 | case ISD::SRL: |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1974 | case ISD::SRA: |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1975 | case ISD::MUL: |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1976 | assert (DestType == MVT::i64 && "Only do arithmetic on i64s!"); |
| 1977 | if(N.getOperand(1).getOpcode() == ISD::Constant && |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1978 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1979 | { |
| 1980 | switch(opcode) { |
| 1981 | case ISD::AND: Opc = Alpha::ANDi; break; |
| 1982 | case ISD::OR: Opc = Alpha::BISi; break; |
| 1983 | case ISD::XOR: Opc = Alpha::XORi; break; |
| 1984 | case ISD::SHL: Opc = Alpha::SLi; break; |
| 1985 | case ISD::SRL: Opc = Alpha::SRLi; break; |
| 1986 | case ISD::SRA: Opc = Alpha::SRAi; break; |
| 1987 | case ISD::MUL: Opc = Alpha::MULQi; break; |
| 1988 | }; |
| 1989 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1990 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1991 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1992 | } else { |
| 1993 | switch(opcode) { |
| 1994 | case ISD::AND: Opc = Alpha::AND; break; |
| 1995 | case ISD::OR: Opc = Alpha::BIS; break; |
| 1996 | case ISD::XOR: Opc = Alpha::XOR; break; |
| 1997 | case ISD::SHL: Opc = Alpha::SL; break; |
| 1998 | case ISD::SRL: Opc = Alpha::SRL; break; |
| 1999 | case ISD::SRA: Opc = Alpha::SRA; break; |
| 2000 | case ISD::MUL: Opc = Alpha::MULQ; break; |
| 2001 | }; |
| 2002 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 2003 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 2004 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 2005 | } |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 2006 | return Result; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2007 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2008 | case ISD::ADD: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2009 | case ISD::SUB: |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 2010 | { |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 2011 | bool isAdd = opcode == ISD::ADD; |
| 2012 | |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2013 | //first check for Scaled Adds and Subs! |
| 2014 | //Valid for add and sub |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2015 | ConstantSDNode* CSD = NULL; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2016 | if(N.getOperand(0).getOpcode() == ISD::SHL && |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2017 | (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) && |
| 2018 | (CSD->getValue() == 2 || CSD->getValue() == 3)) |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2019 | { |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2020 | bool use4 = CSD->getValue() == 2; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2021 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(0)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2022 | if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && CSD->getValue() <= 255) |
| 2023 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi), |
| 2024 | 2, Result).addReg(Tmp2).addImm(CSD->getValue()); |
Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 2025 | else { |
| 2026 | Tmp1 = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2027 | BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi), |
| 2028 | 2, Result).addReg(Tmp2).addReg(Tmp1); |
Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 2029 | } |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2030 | } |
| 2031 | //Position prevents subs |
Andrew Lenharth | 273a1f9 | 2005-04-07 14:18:13 +0000 | [diff] [blame] | 2032 | else if(N.getOperand(1).getOpcode() == ISD::SHL && isAdd && |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2033 | (CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) && |
| 2034 | (CSD->getValue() == 2 || CSD->getValue() == 3)) |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2035 | { |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2036 | bool use4 = CSD->getValue() == 2; |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2037 | Tmp2 = SelectExpr(N.getOperand(1).getOperand(0)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2038 | if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(0))) && CSD->getValue() <= 255) |
| 2039 | BuildMI(BB, use4?Alpha::S4ADDQi:Alpha::S8ADDQi, 2, Result).addReg(Tmp2) |
| 2040 | .addImm(CSD->getValue()); |
Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 2041 | else { |
| 2042 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2043 | BuildMI(BB, use4?Alpha::S4ADDQ:Alpha::S8ADDQ, 2, Result).addReg(Tmp2).addReg(Tmp1); |
Andrew Lenharth | f77f395 | 2005-04-06 20:59:59 +0000 | [diff] [blame] | 2044 | } |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2045 | } |
| 2046 | //small addi |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2047 | else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && |
| 2048 | CSD->getValue() <= 255) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2049 | { //Normal imm add/sub |
| 2050 | Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi; |
| 2051 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2052 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(CSD->getValue()); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2053 | } |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2054 | //larger addi |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2055 | else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && |
| 2056 | CSD->getSignExtended() <= 32767 && |
| 2057 | CSD->getSignExtended() >= -32767) |
Andrew Lenharth | 74d00d8 | 2005-03-02 17:23:03 +0000 | [diff] [blame] | 2058 | { //LDA |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2059 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2060 | Tmp2 = (long)CSD->getSignExtended(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2061 | if (!isAdd) |
| 2062 | Tmp2 = -Tmp2; |
| 2063 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1); |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2064 | } |
| 2065 | //give up and do the operation |
| 2066 | else { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2067 | //Normal add/sub |
| 2068 | Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ; |
| 2069 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 2070 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 2071 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 2072 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 2073 | return Result; |
| 2074 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2075 | |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 2076 | case ISD::SDIV: |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2077 | { |
Andrew Lenharth | a565c27 | 2005-04-06 22:03:13 +0000 | [diff] [blame] | 2078 | ConstantSDNode* CSD; |
| 2079 | //check if we can convert into a shift! |
| 2080 | if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) && |
| 2081 | (int64_t)CSD->getSignExtended() != 0 && |
| 2082 | ExactLog2(abs((int64_t)CSD->getSignExtended())) != 0) |
| 2083 | { |
| 2084 | unsigned k = ExactLog2(abs(CSD->getSignExtended())); |
| 2085 | Tmp1 = SelectExpr(N.getOperand(0)); |
Andrew Lenharth | a565c27 | 2005-04-06 22:03:13 +0000 | [diff] [blame] | 2086 | if (k == 1) |
| 2087 | Tmp2 = Tmp1; |
| 2088 | else |
| 2089 | { |
| 2090 | Tmp2 = MakeReg(MVT::i64); |
| 2091 | BuildMI(BB, Alpha::SRAi, 2, Tmp2).addReg(Tmp1).addImm(k - 1); |
| 2092 | } |
| 2093 | Tmp3 = MakeReg(MVT::i64); |
| 2094 | BuildMI(BB, Alpha::SRLi, 2, Tmp3).addReg(Tmp2).addImm(64-k); |
| 2095 | unsigned Tmp4 = MakeReg(MVT::i64); |
| 2096 | BuildMI(BB, Alpha::ADDQ, 2, Tmp4).addReg(Tmp3).addReg(Tmp1); |
| 2097 | if ((int64_t)CSD->getSignExtended() > 0) |
| 2098 | BuildMI(BB, Alpha::SRAi, 2, Result).addReg(Tmp4).addImm(k); |
| 2099 | else |
| 2100 | { |
| 2101 | unsigned Tmp5 = MakeReg(MVT::i64); |
| 2102 | BuildMI(BB, Alpha::SRAi, 2, Tmp5).addReg(Tmp4).addImm(k); |
| 2103 | BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp5); |
| 2104 | } |
| 2105 | return Result; |
| 2106 | } |
| 2107 | } |
| 2108 | //Else fall through |
| 2109 | |
| 2110 | case ISD::UDIV: |
| 2111 | { |
| 2112 | ConstantSDNode* CSD; |
| 2113 | if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) && |
| 2114 | ((int64_t)CSD->getSignExtended() >= 2 || |
| 2115 | (int64_t)CSD->getSignExtended() <= -2)) |
| 2116 | { |
| 2117 | // If this is a divide by constant, we can emit code using some magic |
| 2118 | // constants to implement it as a multiply instead. |
| 2119 | ExprMap.erase(N); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2120 | if (opcode == ISD::SDIV) |
Andrew Lenharth | a565c27 | 2005-04-06 22:03:13 +0000 | [diff] [blame] | 2121 | return SelectExpr(BuildSDIVSequence(N)); |
| 2122 | else |
| 2123 | return SelectExpr(BuildUDIVSequence(N)); |
| 2124 | } |
Andrew Lenharth | 4b8ac15 | 2005-04-06 20:25:34 +0000 | [diff] [blame] | 2125 | } |
| 2126 | //else fall though |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2127 | case ISD::UREM: |
Andrew Lenharth | 0298118 | 2005-01-26 01:24:38 +0000 | [diff] [blame] | 2128 | case ISD::SREM: |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2129 | //FIXME: alpha really doesn't support any of these operations, |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 2130 | // the ops are expanded into special library calls with |
| 2131 | // special calling conventions |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2132 | //Restore GP because it is a call after all... |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 2133 | switch(opcode) { |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 2134 | case ISD::UREM: Opc = Alpha::REMQU; break; |
| 2135 | case ISD::SREM: Opc = Alpha::REMQ; break; |
| 2136 | case ISD::UDIV: Opc = Alpha::DIVQU; break; |
| 2137 | case ISD::SDIV: Opc = Alpha::DIVQ; break; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 2138 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2139 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 2140 | Tmp2 = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 2141 | //set up regs explicitly (helps Reg alloc) |
| 2142 | BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp1).addReg(Tmp1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2143 | BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp2).addReg(Tmp2); |
Andrew Lenharth | 2b6c4f5 | 2005-02-25 22:55:15 +0000 | [diff] [blame] | 2144 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | 3381913 | 2005-03-04 20:09:23 +0000 | [diff] [blame] | 2145 | BuildMI(BB, Opc, 2).addReg(Alpha::R24).addReg(Alpha::R25); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2146 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2147 | return Result; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 2148 | |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 2149 | case ISD::FP_TO_UINT: |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2150 | case ISD::FP_TO_SINT: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2151 | { |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2152 | assert (DestType == MVT::i64 && "only quads can be loaded to"); |
| 2153 | MVT::ValueType SrcType = N.getOperand(0).getValueType(); |
Andrew Lenharth | 0382401 | 2005-02-07 05:55:55 +0000 | [diff] [blame] | 2154 | assert (SrcType == MVT::f32 || SrcType == MVT::f64); |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2155 | Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2156 | if (SrcType == MVT::f32) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2157 | { |
| 2158 | Tmp2 = MakeReg(MVT::f64); |
| 2159 | BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1); |
| 2160 | Tmp1 = Tmp2; |
| 2161 | } |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2162 | Tmp2 = MakeReg(MVT::f64); |
| 2163 | BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1); |
Andrew Lenharth | 0eaf6ce | 2005-04-02 21:06:51 +0000 | [diff] [blame] | 2164 | MoveFP2Int(Tmp2, Result, true); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2165 | |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 2166 | return Result; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2167 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 2168 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2169 | case ISD::SELECT: |
| 2170 | { |
Andrew Lenharth | dc0b71b | 2005-03-22 00:24:07 +0000 | [diff] [blame] | 2171 | //FIXME: look at parent to decide if intCC can be folded, or if setCC(FP) and can save stack use |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2172 | //Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2173 | //Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 2174 | //Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2175 | // Get the condition into the zero flag. |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2176 | //BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2177 | |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2178 | SDOperand CC = N.getOperand(0); |
| 2179 | SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val); |
| 2180 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2181 | if (CC.getOpcode() == ISD::SETCC && |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2182 | !MVT::isInteger(SetCC->getOperand(0).getValueType())) |
| 2183 | { //FP Setcc -> Int Select |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2184 | Tmp1 = MakeReg(MVT::f64); |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2185 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 2186 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2187 | bool inv = SelectFPSetCC(CC, Tmp1); |
| 2188 | BuildMI(BB, inv?Alpha::CMOVNE_FP:Alpha::CMOVEQ_FP, 2, Result) |
| 2189 | .addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); |
| 2190 | return Result; |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2191 | } |
| 2192 | if (CC.getOpcode() == ISD::SETCC) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2193 | //Int SetCC -> Select |
| 2194 | //Dropping the CC is only useful if we are comparing to 0 |
| 2195 | if((SetCC->getOperand(1).getOpcode() == ISD::Constant && |
| 2196 | cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0) || |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2197 | (SetCC->getOperand(0).getOpcode() == ISD::Constant && |
| 2198 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0)) |
| 2199 | { |
| 2200 | //figure out a few things |
| 2201 | bool LeftZero = SetCC->getOperand(0).getOpcode() == ISD::Constant && |
| 2202 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0; |
| 2203 | bool RightZero = SetCC->getOperand(0).getOpcode() == ISD::Constant && |
| 2204 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0; |
| 2205 | bool LeftConst = N.getOperand(1).getOpcode() == ISD::Constant && |
| 2206 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255; |
| 2207 | bool RightConst = N.getOperand(2).getOpcode() == ISD::Constant && |
| 2208 | cast<ConstantSDNode>(N.getOperand(2))->getValue() <= 255; |
| 2209 | bool useImm = LeftConst || RightConst; |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2210 | |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2211 | //Fix up CC |
| 2212 | ISD::CondCode cCode= SetCC->getCondition(); |
| 2213 | if (RightConst && !LeftConst) //Invert sense to get Imm field right |
| 2214 | cCode = ISD::getSetCCInverse(cCode, true); |
| 2215 | if (LeftZero && !RightZero) //Swap Operands |
| 2216 | cCode = ISD::getSetCCSwappedOperands(cCode); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2217 | |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2218 | //Choose the CMOV |
| 2219 | switch (cCode) { |
| 2220 | default: CC.Val->dump(); assert(0 && "Unknown integer comparison!"); |
| 2221 | case ISD::SETEQ: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break; |
| 2222 | case ISD::SETLT: Opc = useImm?Alpha::CMOVLTi:Alpha::CMOVLT; break; |
| 2223 | case ISD::SETLE: Opc = useImm?Alpha::CMOVLEi:Alpha::CMOVLE; break; |
| 2224 | case ISD::SETGT: Opc = useImm?Alpha::CMOVGTi:Alpha::CMOVGT; break; |
| 2225 | case ISD::SETGE: Opc = useImm?Alpha::CMOVGEi:Alpha::CMOVGE; break; |
| 2226 | case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break; |
| 2227 | case ISD::SETUGT: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break; |
| 2228 | case ISD::SETULE: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break; //Technically you could have this CC |
| 2229 | case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break; |
| 2230 | case ISD::SETNE: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break; |
| 2231 | } |
| 2232 | if(LeftZero && !RightZero) //swap Operands |
| 2233 | Tmp1 = SelectExpr(SetCC->getOperand(1)); //Cond |
| 2234 | else |
| 2235 | Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond |
| 2236 | |
| 2237 | if (LeftConst) { |
| 2238 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
| 2239 | BuildMI(BB, Opc, 2, Result).addReg(Tmp3) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2240 | .addImm(cast<ConstantSDNode>(N.getOperand(1))->getValue()) |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2241 | .addReg(Tmp1); |
| 2242 | } else if (RightConst) { |
| 2243 | Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE |
| 2244 | BuildMI(BB, Opc, 2, Result).addReg(Tmp3) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2245 | .addImm(cast<ConstantSDNode>(N.getOperand(2))->getValue()) |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2246 | .addReg(Tmp1); |
| 2247 | } else { |
| 2248 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 2249 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
| 2250 | BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addReg(Tmp2).addReg(Tmp1); |
| 2251 | } |
| 2252 | return Result; |
| 2253 | } |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2254 | //Otherwise, fall though |
Andrew Lenharth | 10c085b | 2005-04-02 22:32:39 +0000 | [diff] [blame] | 2255 | } |
| 2256 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
Andrew Lenharth | 63b720a | 2005-04-03 20:35:21 +0000 | [diff] [blame] | 2257 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 2258 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 2259 | BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2260 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2261 | return Result; |
| 2262 | } |
| 2263 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2264 | case ISD::Constant: |
| 2265 | { |
Andrew Lenharth | c051383 | 2005-03-29 19:24:04 +0000 | [diff] [blame] | 2266 | int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue(); |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 2267 | if (val <= IMM_HIGH && val >= IMM_LOW) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2268 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31); |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 2269 | } |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 2270 | else if (val <= (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT && |
| 2271 | val >= (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) { |
| 2272 | Tmp1 = MakeReg(MVT::i64); |
| 2273 | BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val)).addReg(Alpha::R31); |
| 2274 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1); |
Andrew Lenharth | e87f6c3 | 2005-03-11 17:48:05 +0000 | [diff] [blame] | 2275 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2276 | else { |
| 2277 | MachineConstantPool *CP = BB->getParent()->getConstantPool(); |
| 2278 | ConstantUInt *C = ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val); |
| 2279 | unsigned CPI = CP->getConstantPoolIndex(C); |
| 2280 | AlphaLowering.restoreGP(BB); |
| 2281 | BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(CPI); |
| 2282 | } |
| 2283 | return Result; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2284 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | return 0; |
| 2288 | } |
| 2289 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 2290 | void AlphaISel::Select(SDOperand N) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2291 | unsigned Tmp1, Tmp2, Opc; |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 2292 | unsigned opcode = N.getOpcode(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2293 | |
Nate Begeman | 85fdeb2 | 2005-03-24 04:39:54 +0000 | [diff] [blame] | 2294 | if (!ExprMap.insert(std::make_pair(N, notIn)).second) |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 2295 | return; // Already selected. |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2296 | |
| 2297 | SDNode *Node = N.Val; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2298 | |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 2299 | switch (opcode) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2300 | |
| 2301 | default: |
| 2302 | Node->dump(); std::cerr << "\n"; |
| 2303 | assert(0 && "Node not handled yet!"); |
| 2304 | |
| 2305 | case ISD::BRCOND: { |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 2306 | SelectBranchCC(N); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2307 | return; |
| 2308 | } |
| 2309 | |
| 2310 | case ISD::BR: { |
| 2311 | MachineBasicBlock *Dest = |
| 2312 | cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock(); |
| 2313 | |
| 2314 | Select(N.getOperand(0)); |
| 2315 | BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest); |
| 2316 | return; |
| 2317 | } |
| 2318 | |
| 2319 | case ISD::ImplicitDef: |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 2320 | ++count_ins; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2321 | Select(N.getOperand(0)); |
| 2322 | BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg()); |
| 2323 | return; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2324 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2325 | case ISD::EntryToken: return; // Noop |
| 2326 | |
| 2327 | case ISD::TokenFactor: |
| 2328 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 2329 | Select(Node->getOperand(i)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2330 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2331 | //N.Val->dump(); std::cerr << "\n"; |
| 2332 | //assert(0 && "Node not handled yet!"); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2333 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2334 | return; |
| 2335 | |
| 2336 | case ISD::CopyToReg: |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 2337 | ++count_outs; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2338 | Select(N.getOperand(0)); |
| 2339 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 2340 | Tmp2 = cast<RegSDNode>(N)->getReg(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2341 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2342 | if (Tmp1 != Tmp2) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2343 | if (N.getOperand(1).getValueType() == MVT::f64 || |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2344 | N.getOperand(1).getValueType() == MVT::f32) |
Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 2345 | BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); |
| 2346 | else |
| 2347 | BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2348 | } |
| 2349 | return; |
| 2350 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2351 | case ISD::RET: |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 2352 | ++count_outs; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2353 | switch (N.getNumOperands()) { |
| 2354 | default: |
| 2355 | std::cerr << N.getNumOperands() << "\n"; |
| 2356 | for (unsigned i = 0; i < N.getNumOperands(); ++i) |
| 2357 | std::cerr << N.getOperand(i).getValueType() << "\n"; |
| 2358 | Node->dump(); |
| 2359 | assert(0 && "Unknown return instruction!"); |
| 2360 | case 2: |
| 2361 | Select(N.getOperand(0)); |
| 2362 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 2363 | switch (N.getOperand(1).getValueType()) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2364 | default: Node->dump(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2365 | assert(0 && "All other types should have been promoted!!"); |
| 2366 | case MVT::f64: |
| 2367 | case MVT::f32: |
| 2368 | BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1); |
| 2369 | break; |
| 2370 | case MVT::i32: |
| 2371 | case MVT::i64: |
| 2372 | BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1); |
| 2373 | break; |
| 2374 | } |
| 2375 | break; |
| 2376 | case 1: |
| 2377 | Select(N.getOperand(0)); |
| 2378 | break; |
| 2379 | } |
| 2380 | //Tmp2 = AlphaLowering.getRetAddr(); |
| 2381 | //BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(Tmp2).addReg(Tmp2); |
| 2382 | BuildMI(BB, Alpha::RETURN, 0); // Just emit a 'ret' instruction |
| 2383 | return; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2384 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2385 | case ISD::TRUNCSTORE: |
| 2386 | case ISD::STORE: |
Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 2387 | { |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 2388 | SDOperand Chain = N.getOperand(0); |
| 2389 | SDOperand Value = N.getOperand(1); |
| 2390 | SDOperand Address = N.getOperand(2); |
| 2391 | Select(Chain); |
| 2392 | |
| 2393 | Tmp1 = SelectExpr(Value); //value |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 2394 | |
| 2395 | if (opcode == ISD::STORE) { |
| 2396 | switch(Value.getValueType()) { |
| 2397 | default: assert(0 && "unknown Type in store"); |
| 2398 | case MVT::i64: Opc = Alpha::STQ; break; |
| 2399 | case MVT::f64: Opc = Alpha::STT; break; |
| 2400 | case MVT::f32: Opc = Alpha::STS; break; |
| 2401 | } |
| 2402 | } else { //ISD::TRUNCSTORE |
| 2403 | switch(cast<MVTSDNode>(Node)->getExtraValueType()) { |
| 2404 | default: assert(0 && "unknown Type in store"); |
| 2405 | case MVT::i1: //FIXME: DAG does not promote this load |
| 2406 | case MVT::i8: Opc = Alpha::STB; break; |
| 2407 | case MVT::i16: Opc = Alpha::STW; break; |
| 2408 | case MVT::i32: Opc = Alpha::STL; break; |
| 2409 | } |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 2410 | } |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 2411 | |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 2412 | if (EnableAlphaLSMark) |
| 2413 | { |
| 2414 | int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(3))->getValue()); |
| 2415 | int j = getFunctionOffset(BB->getParent()->getFunction()); |
| 2416 | BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID()); |
| 2417 | } |
| 2418 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 2419 | if (Address.getOpcode() == ISD::GlobalAddress) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2420 | { |
| 2421 | AlphaLowering.restoreGP(BB); |
| 2422 | Opc = GetSymVersion(Opc); |
Andrew Lenharth | a32b9e3 | 2005-04-08 17:28:49 +0000 | [diff] [blame] | 2423 | has_sym = true; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2424 | BuildMI(BB, Opc, 2).addReg(Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); |
| 2425 | } |
Andrew Lenharth | 0538034 | 2005-02-07 05:07:00 +0000 | [diff] [blame] | 2426 | else if(Address.getOpcode() == ISD::FrameIndex) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2427 | { |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 2428 | BuildMI(BB, Opc, 3).addReg(Tmp1) |
| 2429 | .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex()) |
| 2430 | .addReg(Alpha::F31); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2431 | } |
Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 2432 | else |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 2433 | { |
| 2434 | long offset; |
| 2435 | SelectAddr(Address, Tmp2, offset); |
| 2436 | BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2); |
| 2437 | } |
Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 2438 | return; |
| 2439 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2440 | |
| 2441 | case ISD::EXTLOAD: |
| 2442 | case ISD::SEXTLOAD: |
| 2443 | case ISD::ZEXTLOAD: |
| 2444 | case ISD::LOAD: |
| 2445 | case ISD::CopyFromReg: |
Chris Lattner | b5d8e6e | 2005-05-13 20:29:26 +0000 | [diff] [blame] | 2446 | case ISD::TAILCALL: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2447 | case ISD::CALL: |
Andrew Lenharth | 032f235 | 2005-02-22 21:59:48 +0000 | [diff] [blame] | 2448 | case ISD::DYNAMIC_STACKALLOC: |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 2449 | ExprMap.erase(N); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2450 | SelectExpr(N); |
| 2451 | return; |
| 2452 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2453 | case ISD::CALLSEQ_START: |
| 2454 | case ISD::CALLSEQ_END: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2455 | Select(N.getOperand(0)); |
| 2456 | Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2457 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 2458 | Opc = N.getOpcode() == ISD::CALLSEQ_START ? Alpha::ADJUSTSTACKDOWN : |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2459 | Alpha::ADJUSTSTACKUP; |
| 2460 | BuildMI(BB, Opc, 1).addImm(Tmp1); |
| 2461 | return; |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2462 | |
| 2463 | case ISD::PCMARKER: |
| 2464 | Select(N.getOperand(0)); //Chain |
| 2465 | BuildMI(BB, Alpha::PCLABEL, 2).addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue()); |
| 2466 | return; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2467 | } |
| 2468 | assert(0 && "Should not be reached!"); |
| 2469 | } |
| 2470 | |
| 2471 | |
| 2472 | /// createAlphaPatternInstructionSelector - This pass converts an LLVM function |
| 2473 | /// into a machine code representation using pattern matching and a machine |
| 2474 | /// description file. |
| 2475 | /// |
| 2476 | FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) { |
Andrew Lenharth | b69f342 | 2005-06-22 17:19:45 +0000 | [diff] [blame] | 2477 | return new AlphaISel(TM); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2478 | } |
Andrew Lenharth | 4f7cba5 | 2005-04-13 05:19:55 +0000 | [diff] [blame] | 2479 | |