Misha Brukman | 2a8350a | 2005-02-05 02:24:26 +0000 | [diff] [blame] | 1 | //===- AlphaISelPattern.cpp - A pattern matching inst selector for Alpha --===// |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2 | // |
| 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. |
| 7 | // |
| 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" |
| 18 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 19 | #include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE |
| 20 | #include "llvm/CodeGen/MachineFunction.h" |
| 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 22 | #include "llvm/CodeGen/SelectionDAG.h" |
| 23 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 24 | #include "llvm/CodeGen/SSARegMap.h" |
| 25 | #include "llvm/Target/TargetData.h" |
| 26 | #include "llvm/Target/TargetLowering.h" |
| 27 | #include "llvm/Support/MathExtras.h" |
| 28 | #include "llvm/ADT/Statistic.h" |
| 29 | #include <set> |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 30 | #include <algorithm> |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 31 | using namespace llvm; |
| 32 | |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | // AlphaTargetLowering - Alpha Implementation of the TargetLowering interface |
| 35 | namespace { |
| 36 | class AlphaTargetLowering : public TargetLowering { |
| 37 | int VarArgsFrameIndex; // FrameIndex for start of varargs area. |
| 38 | unsigned GP; //GOT vreg |
| 39 | public: |
| 40 | AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) { |
| 41 | // Set up the TargetLowering object. |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 42 | //I am having problems with shr n ubyte 1 |
Andrew Lenharth | 879ef22 | 2005-02-02 17:00:21 +0000 | [diff] [blame] | 43 | setShiftAmountType(MVT::i64); |
| 44 | setSetCCResultType(MVT::i64); |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 45 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 46 | addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass); |
| 47 | addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass); |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 48 | addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 49 | |
Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 50 | setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote); |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 51 | |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 52 | setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 53 | setOperationAction(ISD::ZEXTLOAD , MVT::i32 , Expand); |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 54 | |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 55 | setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 56 | setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand); |
| 57 | setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand); |
| 58 | |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 59 | setOperationAction(ISD::SREM , MVT::f32 , Expand); |
| 60 | setOperationAction(ISD::SREM , MVT::f64 , Expand); |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 61 | |
Andrew Lenharth | 8d163d2 | 2005-02-02 05:49:42 +0000 | [diff] [blame] | 62 | setOperationAction(ISD::MEMMOVE , MVT::Other, Expand); |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 63 | setOperationAction(ISD::MEMSET , MVT::Other, Expand); |
| 64 | setOperationAction(ISD::MEMCPY , MVT::Other, Expand); |
| 65 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 66 | computeRegisterProperties(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 67 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 68 | addLegalFPImmediate(+0.0); //F31 |
| 69 | addLegalFPImmediate(-0.0); //-F31 |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /// LowerArguments - This hook must be implemented to indicate how we should |
| 73 | /// lower the arguments for the specified function, into the specified DAG. |
| 74 | virtual std::vector<SDOperand> |
| 75 | LowerArguments(Function &F, SelectionDAG &DAG); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 76 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 77 | /// LowerCallTo - This hook lowers an abstract call to a function into an |
| 78 | /// actual call. |
| 79 | virtual std::pair<SDOperand, SDOperand> |
| 80 | LowerCallTo(SDOperand Chain, const Type *RetTy, SDOperand Callee, |
| 81 | ArgListTy &Args, SelectionDAG &DAG); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 82 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 83 | virtual std::pair<SDOperand, SDOperand> |
| 84 | LowerVAStart(SDOperand Chain, SelectionDAG &DAG); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 85 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 86 | virtual std::pair<SDOperand,SDOperand> |
| 87 | LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList, |
| 88 | const Type *ArgTy, SelectionDAG &DAG); |
| 89 | |
| 90 | virtual std::pair<SDOperand, SDOperand> |
| 91 | LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth, |
| 92 | SelectionDAG &DAG); |
| 93 | |
| 94 | void restoreGP(MachineBasicBlock* BB) |
| 95 | { |
| 96 | BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP); |
| 97 | } |
| 98 | }; |
| 99 | } |
| 100 | |
| 101 | //http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21 |
| 102 | |
| 103 | //For now, just use variable size stack frame format |
| 104 | |
| 105 | //In a standard call, the first six items are passed in registers $16 |
| 106 | //- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details |
| 107 | //of argument-to-register correspondence.) The remaining items are |
| 108 | //collected in a memory argument list that is a naturally aligned |
| 109 | //array of quadwords. In a standard call, this list, if present, must |
| 110 | //be passed at 0(SP). |
| 111 | //7 ... n 0(SP) ... (n-7)*8(SP) |
| 112 | |
| 113 | std::vector<SDOperand> |
| 114 | AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) |
| 115 | { |
| 116 | std::vector<SDOperand> ArgValues; |
| 117 | |
| 118 | // //#define FP $15 |
| 119 | // //#define RA $26 |
| 120 | // //#define PV $27 |
| 121 | // //#define GP $29 |
| 122 | // //#define SP $30 |
| 123 | |
| 124 | // assert(0 && "TODO"); |
| 125 | MachineFunction &MF = DAG.getMachineFunction(); |
Andrew Lenharth | 0538034 | 2005-02-07 05:07:00 +0000 | [diff] [blame] | 126 | MachineFrameInfo*MFI = MF.getFrameInfo(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 127 | |
| 128 | GP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64)); |
| 129 | MachineBasicBlock& BB = MF.front(); |
| 130 | |
| 131 | //Handle the return address |
| 132 | //BuildMI(&BB, Alpha::IDEF, 0, Alpha::R26); |
| 133 | |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 134 | unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18, |
| 135 | Alpha::R19, Alpha::R20, Alpha::R21}; |
| 136 | unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18, |
| 137 | Alpha::F19, Alpha::F20, Alpha::F21}; |
Andrew Lenharth | 2c9e38c | 2005-02-06 21:07:31 +0000 | [diff] [blame] | 138 | unsigned argVreg[6]; |
| 139 | unsigned argPreg[6]; |
| 140 | unsigned argOpc[6]; |
| 141 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 142 | int count = 0; |
Andrew Lenharth | 2c9e38c | 2005-02-06 21:07:31 +0000 | [diff] [blame] | 143 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 144 | for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 145 | { |
| 146 | SDOperand newroot, argt; |
| 147 | if (count < 6) { |
| 148 | switch (getValueType(I->getType())) { |
| 149 | default: |
| 150 | std::cerr << "Unknown Type " << getValueType(I->getType()) << "\n"; |
| 151 | abort(); |
| 152 | case MVT::f64: |
| 153 | case MVT::f32: |
| 154 | BuildMI(&BB, Alpha::IDEF, 0, args_float[count]); |
| 155 | argVreg[count] = |
| 156 | MF.getSSARegMap()->createVirtualRegister( |
| 157 | getRegClassFor(getValueType(I->getType()))); |
| 158 | argPreg[count] = args_float[count]; |
| 159 | argOpc[count] = Alpha::CPYS; |
| 160 | argt = newroot = DAG.getCopyFromReg(argVreg[count], |
| 161 | getValueType(I->getType()), |
| 162 | DAG.getRoot()); |
| 163 | break; |
| 164 | case MVT::i1: |
| 165 | case MVT::i8: |
| 166 | case MVT::i16: |
| 167 | case MVT::i32: |
| 168 | case MVT::i64: |
| 169 | BuildMI(&BB, Alpha::IDEF, 0, args_int[count]); |
| 170 | argVreg[count] = |
| 171 | MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64)); |
| 172 | argPreg[count] = args_int[count]; |
| 173 | argOpc[count] = Alpha::BIS; |
| 174 | argt = newroot = |
| 175 | DAG.getCopyFromReg(argVreg[count], MVT::i64, DAG.getRoot()); |
| 176 | if (getValueType(I->getType()) != MVT::i64) |
| 177 | argt = |
| 178 | DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()), newroot); |
| 179 | break; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 180 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 181 | ++count; |
| 182 | } else { //more args |
| 183 | // Create the frame index object for this incoming parameter... |
| 184 | int FI = MFI->CreateFixedObject(8, 8 * (count - 6)); |
| 185 | |
| 186 | // Create the SelectionDAG nodes corresponding to a load |
| 187 | //from this parameter |
| 188 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64); |
| 189 | argt = newroot = DAG.getLoad(getValueType(I->getType()), |
| 190 | DAG.getEntryNode(), FIN); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 191 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 192 | DAG.setRoot(newroot.getValue(1)); |
| 193 | ArgValues.push_back(argt); |
| 194 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 195 | |
| 196 | BuildMI(&BB, Alpha::IDEF, 0, Alpha::R29); |
| 197 | BuildMI(&BB, Alpha::BIS, 2, GP).addReg(Alpha::R29).addReg(Alpha::R29); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 198 | for (int i = 0; i < count; ++i) { |
| 199 | if (argPreg[i] == Alpha::F16 || argPreg[i] == Alpha::F17 || |
| 200 | argPreg[i] == Alpha::F18 || argPreg[i] == Alpha::F19 || |
| 201 | argPreg[i] == Alpha::F20 || argPreg[i] == Alpha::F21) |
Andrew Lenharth | 2c9e38c | 2005-02-06 21:07:31 +0000 | [diff] [blame] | 202 | { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 203 | assert(argOpc[i] == Alpha::CPYS && "Using BIS for a float??"); |
Andrew Lenharth | 2c9e38c | 2005-02-06 21:07:31 +0000 | [diff] [blame] | 204 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 205 | BuildMI(&BB, argOpc[i], 2, |
| 206 | argVreg[i]).addReg(argPreg[i]).addReg(argPreg[i]); |
| 207 | } |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 208 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 209 | return ArgValues; |
| 210 | } |
| 211 | |
| 212 | std::pair<SDOperand, SDOperand> |
| 213 | AlphaTargetLowering::LowerCallTo(SDOperand Chain, |
| 214 | const Type *RetTy, SDOperand Callee, |
| 215 | ArgListTy &Args, SelectionDAG &DAG) { |
| 216 | int NumBytes = 0; |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 217 | if (Args.size() > 6) |
| 218 | NumBytes = (Args.size() - 6) * 8; |
| 219 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 220 | Chain = DAG.getNode(ISD::ADJCALLSTACKDOWN, MVT::Other, Chain, |
| 221 | DAG.getConstant(NumBytes, getPointerTy())); |
| 222 | std::vector<SDOperand> args_to_use; |
| 223 | for (unsigned i = 0, e = Args.size(); i != e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 224 | { |
| 225 | switch (getValueType(Args[i].second)) { |
| 226 | default: assert(0 && "Unexpected ValueType for argument!"); |
| 227 | case MVT::i1: |
| 228 | case MVT::i8: |
| 229 | case MVT::i16: |
| 230 | case MVT::i32: |
| 231 | // Promote the integer to 64 bits. If the input type is signed use a |
| 232 | // sign extend, otherwise use a zero extend. |
| 233 | if (Args[i].second->isSigned()) |
| 234 | Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first); |
| 235 | else |
| 236 | Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first); |
| 237 | break; |
| 238 | case MVT::i64: |
| 239 | case MVT::f64: |
| 240 | case MVT::f32: |
| 241 | break; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 242 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 243 | args_to_use.push_back(Args[i].first); |
| 244 | } |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 245 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 246 | std::vector<MVT::ValueType> RetVals; |
| 247 | MVT::ValueType RetTyVT = getValueType(RetTy); |
| 248 | if (RetTyVT != MVT::isVoid) |
| 249 | RetVals.push_back(RetTyVT); |
| 250 | RetVals.push_back(MVT::Other); |
| 251 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 252 | SDOperand TheCall = SDOperand(DAG.getCall(RetVals, |
| 253 | Chain, Callee, args_to_use), 0); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 254 | Chain = TheCall.getValue(RetTyVT != MVT::isVoid); |
| 255 | Chain = DAG.getNode(ISD::ADJCALLSTACKUP, MVT::Other, Chain, |
| 256 | DAG.getConstant(NumBytes, getPointerTy())); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 257 | return std::make_pair(TheCall, Chain); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | std::pair<SDOperand, SDOperand> |
| 261 | AlphaTargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) { |
| 262 | //vastart just returns the address of the VarArgsFrameIndex slot. |
| 263 | return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64), Chain); |
| 264 | } |
| 265 | |
| 266 | std::pair<SDOperand,SDOperand> AlphaTargetLowering:: |
| 267 | LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList, |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 268 | const Type *ArgTy, SelectionDAG &DAG) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 269 | abort(); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | std::pair<SDOperand, SDOperand> AlphaTargetLowering:: |
| 274 | LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth, |
| 275 | SelectionDAG &DAG) { |
| 276 | abort(); |
| 277 | } |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | namespace { |
| 284 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 285 | //===--------------------------------------------------------------------===// |
| 286 | /// ISel - Alpha specific code to select Alpha machine instructions for |
| 287 | /// SelectionDAG operations. |
| 288 | //===--------------------------------------------------------------------===// |
| 289 | class ISel : public SelectionDAGISel { |
| 290 | |
| 291 | /// AlphaLowering - This object fully describes how to lower LLVM code to an |
| 292 | /// Alpha-specific SelectionDAG. |
| 293 | AlphaTargetLowering AlphaLowering; |
| 294 | |
| 295 | |
| 296 | /// ExprMap - As shared expressions are codegen'd, we keep track of which |
| 297 | /// vreg the value is produced in, so we only emit one copy of each compiled |
| 298 | /// tree. |
| 299 | static const unsigned notIn = (unsigned)(-1); |
| 300 | std::map<SDOperand, unsigned> ExprMap; |
| 301 | |
| 302 | //CCInvMap sometimes (SetNE) we have the inverse CC code for free |
| 303 | std::map<SDOperand, unsigned> CCInvMap; |
| 304 | |
| 305 | public: |
| 306 | ISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM) |
| 307 | {} |
| 308 | |
| 309 | /// InstructionSelectBasicBlock - This callback is invoked by |
| 310 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 311 | virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) { |
| 312 | // Codegen the basic block. |
| 313 | Select(DAG.getRoot()); |
| 314 | |
| 315 | // Clear state used for selection. |
| 316 | ExprMap.clear(); |
| 317 | CCInvMap.clear(); |
| 318 | } |
| 319 | |
| 320 | unsigned SelectExpr(SDOperand N); |
| 321 | unsigned SelectExprFP(SDOperand N, unsigned Result); |
| 322 | void Select(SDOperand N); |
| 323 | |
| 324 | void SelectAddr(SDOperand N, unsigned& Reg, long& offset); |
| 325 | void SelectBranchCC(SDOperand N); |
| 326 | }; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 329 | static unsigned GetSymVersion(unsigned opcode) |
| 330 | { |
| 331 | switch (opcode) { |
| 332 | default: assert(0 && "unknown load or store"); return 0; |
| 333 | case Alpha::LDQ: return Alpha::LDQ_SYM; |
| 334 | case Alpha::LDS: return Alpha::LDS_SYM; |
| 335 | case Alpha::LDT: return Alpha::LDT_SYM; |
| 336 | case Alpha::LDL: return Alpha::LDL_SYM; |
| 337 | case Alpha::LDBU: return Alpha::LDBU_SYM; |
| 338 | case Alpha::LDWU: return Alpha::LDWU_SYM; |
| 339 | case Alpha::LDW: return Alpha::LDW_SYM; |
| 340 | case Alpha::LDB: return Alpha::LDB_SYM; |
| 341 | case Alpha::STQ: return Alpha::STQ_SYM; |
| 342 | case Alpha::STS: return Alpha::STS_SYM; |
| 343 | case Alpha::STT: return Alpha::STT_SYM; |
| 344 | case Alpha::STL: return Alpha::STL_SYM; |
| 345 | case Alpha::STW: return Alpha::STW_SYM; |
| 346 | case Alpha::STB: return Alpha::STB_SYM; |
| 347 | } |
| 348 | } |
| 349 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 350 | //Check to see if the load is a constant offset from a base register |
| 351 | void ISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset) |
| 352 | { |
| 353 | unsigned opcode = N.getOpcode(); |
| 354 | if (opcode == ISD::ADD) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 355 | if(N.getOperand(1).getOpcode() == ISD::Constant && |
| 356 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767) |
| 357 | { //Normal imm add |
| 358 | Reg = SelectExpr(N.getOperand(0)); |
| 359 | offset = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 360 | return; |
| 361 | } |
| 362 | else if(N.getOperand(0).getOpcode() == ISD::Constant && |
| 363 | cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 32767) |
| 364 | { |
| 365 | Reg = SelectExpr(N.getOperand(1)); |
| 366 | offset = cast<ConstantSDNode>(N.getOperand(0))->getValue(); |
| 367 | return; |
| 368 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 369 | } |
| 370 | Reg = SelectExpr(N); |
| 371 | offset = 0; |
| 372 | return; |
| 373 | } |
| 374 | |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 375 | void ISel::SelectBranchCC(SDOperand N) |
| 376 | { |
| 377 | assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???"); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 378 | MachineBasicBlock *Dest = |
| 379 | cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock(); |
| 380 | unsigned Opc = Alpha::WTF; |
| 381 | |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 382 | Select(N.getOperand(0)); //chain |
| 383 | SDOperand CC = N.getOperand(1); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 384 | |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 385 | if (CC.getOpcode() == ISD::SETCC) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 386 | { |
| 387 | SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val); |
| 388 | if (MVT::isInteger(SetCC->getOperand(0).getValueType())) { |
| 389 | //Dropping the CC is only useful if we are comparing to 0 |
| 390 | bool isZero0 = false; |
| 391 | bool isZero1 = false; |
| 392 | bool isNE = false; |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 393 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 394 | if(SetCC->getOperand(0).getOpcode() == ISD::Constant && |
| 395 | cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0) |
| 396 | isZero0 = true; |
| 397 | if(SetCC->getOperand(1).getOpcode() == ISD::Constant && |
| 398 | cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0) |
| 399 | isZero1 = true; |
| 400 | if(SetCC->getCondition() == ISD::SETNE) |
| 401 | isNE = true; |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 402 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 403 | if (isZero0) { |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 404 | switch (SetCC->getCondition()) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 405 | default: CC.Val->dump(); assert(0 && "Unknown integer comparison!"); |
| 406 | case ISD::SETEQ: Opc = Alpha::BEQ; break; |
| 407 | case ISD::SETLT: Opc = Alpha::BGT; break; |
| 408 | case ISD::SETLE: Opc = Alpha::BGE; break; |
| 409 | case ISD::SETGT: Opc = Alpha::BLT; break; |
| 410 | case ISD::SETGE: Opc = Alpha::BLE; break; |
| 411 | case ISD::SETULT: Opc = Alpha::BNE; break; |
| 412 | case ISD::SETUGT: assert(0 && "0 > (unsigned) x is never true"); break; |
| 413 | case ISD::SETULE: assert(0 && "0 <= (unsigned) x is always true"); break; |
| 414 | case ISD::SETUGE: Opc = Alpha::BEQ; break; //Technically you could have this CC |
| 415 | case ISD::SETNE: Opc = Alpha::BNE; break; |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 416 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 417 | unsigned Tmp1 = SelectExpr(SetCC->getOperand(1)); |
| 418 | BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest); |
| 419 | return; |
| 420 | } else if (isZero1) { |
| 421 | switch (SetCC->getCondition()) { |
| 422 | default: CC.Val->dump(); assert(0 && "Unknown integer comparison!"); |
| 423 | case ISD::SETEQ: Opc = Alpha::BEQ; break; |
| 424 | case ISD::SETLT: Opc = Alpha::BLT; break; |
| 425 | case ISD::SETLE: Opc = Alpha::BLE; break; |
| 426 | case ISD::SETGT: Opc = Alpha::BGT; break; |
| 427 | case ISD::SETGE: Opc = Alpha::BGE; break; |
| 428 | case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break; |
| 429 | case ISD::SETUGT: Opc = Alpha::BNE; break; |
| 430 | case ISD::SETULE: Opc = Alpha::BEQ; break; //Technically you could have this CC |
| 431 | case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break; |
| 432 | case ISD::SETNE: Opc = Alpha::BNE; break; |
| 433 | } |
| 434 | unsigned Tmp1 = SelectExpr(SetCC->getOperand(0)); |
| 435 | BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest); |
| 436 | return; |
| 437 | } else { |
| 438 | unsigned Tmp1 = SelectExpr(CC); |
| 439 | if (isNE) |
| 440 | BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest); |
| 441 | else |
| 442 | BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest); |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 443 | return; |
| 444 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 445 | } else { //FP |
| 446 | //Any comparison between 2 values should be codegened as an folded branch, as moving |
| 447 | //CC to the integer register is very expensive |
| 448 | //for a cmp b: c = a - b; |
| 449 | //a = b: c = 0 |
| 450 | //a < b: c < 0 |
| 451 | //a > b: c > 0 |
| 452 | unsigned Tmp1 = SelectExpr(SetCC->getOperand(0)); |
| 453 | unsigned Tmp2 = SelectExpr(SetCC->getOperand(1)); |
| 454 | unsigned Tmp3 = MakeReg(MVT::f64); |
| 455 | BuildMI(BB, Alpha::SUBT, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); |
| 456 | |
| 457 | switch (SetCC->getCondition()) { |
| 458 | default: CC.Val->dump(); assert(0 && "Unknown FP comparison!"); |
| 459 | case ISD::SETEQ: Opc = Alpha::FBEQ; break; |
| 460 | case ISD::SETLT: Opc = Alpha::FBLT; break; |
| 461 | case ISD::SETLE: Opc = Alpha::FBLE; break; |
| 462 | case ISD::SETGT: Opc = Alpha::FBGT; break; |
| 463 | case ISD::SETGE: Opc = Alpha::FBGE; break; |
| 464 | case ISD::SETNE: Opc = Alpha::FBNE; break; |
| 465 | } |
| 466 | BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest); |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 467 | return; |
| 468 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 469 | abort(); //Should never be reached |
| 470 | } else { |
| 471 | //Giveup and do the stupid thing |
| 472 | unsigned Tmp1 = SelectExpr(CC); |
| 473 | BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest); |
| 474 | return; |
| 475 | } |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 476 | abort(); //Should never be reached |
| 477 | } |
| 478 | |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 479 | unsigned ISel::SelectExprFP(SDOperand N, unsigned Result) |
| 480 | { |
| 481 | unsigned Tmp1, Tmp2, Tmp3; |
| 482 | unsigned Opc = 0; |
| 483 | SDNode *Node = N.Val; |
| 484 | MVT::ValueType DestType = N.getValueType(); |
| 485 | unsigned opcode = N.getOpcode(); |
| 486 | |
| 487 | switch (opcode) { |
| 488 | default: |
| 489 | Node->dump(); |
| 490 | assert(0 && "Node not handled!\n"); |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 491 | |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 492 | case ISD::SELECT: |
| 493 | { |
| 494 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
| 495 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 496 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 497 | |
| 498 | |
| 499 | // Spill the cond to memory and reload it from there. |
| 500 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; |
| 501 | MachineFunction *F = BB->getParent(); |
| 502 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); |
| 503 | unsigned Tmp4 = MakeReg(MVT::f64); |
| 504 | BuildMI(BB, Alpha::STQ, 3).addReg(Tmp1).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 505 | BuildMI(BB, Alpha::LDT, 2, Tmp4).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 506 | //now ideally, we don't have to do anything to the flag... |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 507 | // Get the condition into the zero flag. |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 508 | BuildMI(BB, Alpha::FCMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp4); |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 509 | return Result; |
| 510 | } |
| 511 | |
Andrew Lenharth | c1faced | 2005-02-01 01:37:24 +0000 | [diff] [blame] | 512 | case ISD::FP_ROUND: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 513 | assert (DestType == MVT::f32 && |
| 514 | N.getOperand(0).getValueType() == MVT::f64 && |
| 515 | "only f64 to f32 conversion supported here"); |
Andrew Lenharth | c1faced | 2005-02-01 01:37:24 +0000 | [diff] [blame] | 516 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 517 | BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1); |
| 518 | return Result; |
| 519 | |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 520 | case ISD::FP_EXTEND: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 521 | assert (DestType == MVT::f64 && |
| 522 | N.getOperand(0).getValueType() == MVT::f32 && |
| 523 | "only f32 to f64 conversion supported here"); |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 524 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 525 | BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1); |
| 526 | return Result; |
| 527 | |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 528 | case ISD::CopyFromReg: |
| 529 | { |
| 530 | // Make sure we generate both values. |
| 531 | if (Result != notIn) |
| 532 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 533 | else |
| 534 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
| 535 | |
| 536 | SDOperand Chain = N.getOperand(0); |
| 537 | |
| 538 | Select(Chain); |
| 539 | unsigned r = dyn_cast<RegSDNode>(Node)->getReg(); |
| 540 | //std::cerr << "CopyFromReg " << Result << " = " << r << "\n"; |
| 541 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r); |
| 542 | return Result; |
| 543 | } |
| 544 | |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 545 | case ISD::LOAD: |
| 546 | { |
| 547 | // Make sure we generate both values. |
| 548 | if (Result != notIn) |
| 549 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 550 | else |
| 551 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 552 | |
Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 553 | DestType = N.getValue(0).getValueType(); |
Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 554 | |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 555 | SDOperand Chain = N.getOperand(0); |
| 556 | SDOperand Address = N.getOperand(1); |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 557 | Select(Chain); |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 558 | Opc = DestType == MVT::f64 ? Alpha::LDT : Alpha::LDS; |
| 559 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 560 | if (Address.getOpcode() == ISD::GlobalAddress) { |
| 561 | AlphaLowering.restoreGP(BB); |
| 562 | Opc = GetSymVersion(Opc); |
| 563 | BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); |
| 564 | } |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 565 | else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) { |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 566 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 567 | Opc = GetSymVersion(Opc); |
Andrew Lenharth | 97127a1 | 2005-02-05 17:41:39 +0000 | [diff] [blame] | 568 | BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex()); |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 569 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 570 | else if(Address.getOpcode() == ISD::FrameIndex) { |
| 571 | Tmp1 = cast<FrameIndexSDNode>(Address)->getIndex(); |
| 572 | BuildMI(BB, Opc, 2, Result).addFrameIndex(Tmp1).addReg(Alpha::F31); |
| 573 | } else { |
| 574 | long offset; |
| 575 | SelectAddr(Address, Tmp1, offset); |
| 576 | BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1); |
| 577 | } |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 578 | return Result; |
| 579 | } |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 580 | case ISD::ConstantFP: |
| 581 | if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) { |
| 582 | if (CN->isExactlyValue(+0.0)) { |
| 583 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31); |
Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 584 | } else if ( CN->isExactlyValue(-0.0)) { |
| 585 | BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31); |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 586 | } else { |
| 587 | abort(); |
| 588 | } |
| 589 | } |
| 590 | return Result; |
| 591 | |
| 592 | case ISD::MUL: |
| 593 | case ISD::ADD: |
| 594 | case ISD::SUB: |
| 595 | case ISD::SDIV: |
| 596 | switch( opcode ) { |
| 597 | case ISD::MUL: Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; break; |
| 598 | case ISD::ADD: Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; break; |
| 599 | case ISD::SUB: Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; break; |
| 600 | case ISD::SDIV: Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; break; |
| 601 | }; |
| 602 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 603 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 604 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 605 | return Result; |
| 606 | |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 607 | case ISD::EXTLOAD: |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 608 | { |
| 609 | //include a conversion sequence for float loads to double |
| 610 | if (Result != notIn) |
| 611 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 612 | else |
| 613 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
| 614 | |
Andrew Lenharth | a549deb | 2005-02-07 05:33:15 +0000 | [diff] [blame] | 615 | Tmp1 = MakeReg(MVT::f32); |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 616 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 617 | assert(cast<MVTSDNode>(Node)->getExtraValueType() == MVT::f32 && |
| 618 | "EXTLOAD not from f32"); |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 619 | assert(Node->getValueType(0) == MVT::f64 && "EXTLOAD not to f64"); |
| 620 | |
| 621 | SDOperand Chain = N.getOperand(0); |
| 622 | SDOperand Address = N.getOperand(1); |
| 623 | Select(Chain); |
| 624 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 625 | if (Address.getOpcode() == ISD::GlobalAddress) { |
| 626 | AlphaLowering.restoreGP(BB); |
| 627 | BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); |
| 628 | } |
| 629 | else if (ConstantPoolSDNode *CP = |
| 630 | dyn_cast<ConstantPoolSDNode>(N.getOperand(1))) |
| 631 | { |
| 632 | AlphaLowering.restoreGP(BB); |
| 633 | BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addConstantPoolIndex(CP->getIndex()); |
| 634 | } |
| 635 | else if(Address.getOpcode() == ISD::FrameIndex) { |
| 636 | Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex(); |
| 637 | BuildMI(BB, Alpha::LDS, 2, Tmp1).addFrameIndex(Tmp2).addReg(Alpha::F31); |
| 638 | } else { |
| 639 | long offset; |
| 640 | SelectAddr(Address, Tmp2, offset); |
| 641 | BuildMI(BB, Alpha::LDS, 1, Tmp1).addImm(offset).addReg(Tmp2); |
| 642 | } |
Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 643 | BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 12dd262 | 2005-02-03 21:01:15 +0000 | [diff] [blame] | 644 | return Result; |
| 645 | } |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 646 | |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 647 | case ISD::UINT_TO_FP: |
| 648 | case ISD::SINT_TO_FP: |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 649 | { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 650 | assert (N.getOperand(0).getValueType() == MVT::i64 |
| 651 | && "only quads can be loaded from"); |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 652 | Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 653 | Tmp2 = MakeReg(MVT::f64); |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 654 | |
| 655 | //The hard way: |
| 656 | // Spill the integer to memory and reload it from there. |
| 657 | unsigned Size = MVT::getSizeInBits(MVT::i64)/8; |
| 658 | MachineFunction *F = BB->getParent(); |
| 659 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, Size); |
| 660 | |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 661 | BuildMI(BB, Alpha::STQ, 3).addReg(Tmp1).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 662 | BuildMI(BB, Alpha::LDT, 2, Tmp2).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 663 | Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS; |
| 664 | BuildMI(BB, Opc, 1, Result).addReg(Tmp2); |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 665 | |
| 666 | //The easy way: doesn't work |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 667 | // //so these instructions are not supported on ev56 |
| 668 | // Opc = DestType == MVT::f64 ? Alpha::ITOFT : Alpha::ITOFS; |
| 669 | // BuildMI(BB, Opc, 1, Tmp2).addReg(Tmp1); |
| 670 | // Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS; |
| 671 | // BuildMI(BB, Opc, 1, Result).addReg(Tmp1); |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 672 | |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 673 | return Result; |
| 674 | } |
| 675 | } |
| 676 | assert(0 && "should not get here"); |
| 677 | return 0; |
| 678 | } |
| 679 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 680 | unsigned ISel::SelectExpr(SDOperand N) { |
| 681 | unsigned Result; |
| 682 | unsigned Tmp1, Tmp2, Tmp3; |
| 683 | unsigned Opc = 0; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 684 | unsigned opcode = N.getOpcode(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 685 | |
| 686 | SDNode *Node = N.Val; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 687 | MVT::ValueType DestType = N.getValueType(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 688 | |
| 689 | unsigned &Reg = ExprMap[N]; |
| 690 | if (Reg) return Reg; |
| 691 | |
| 692 | if (N.getOpcode() != ISD::CALL) |
| 693 | Reg = Result = (N.getValueType() != MVT::Other) ? |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 694 | MakeReg(N.getValueType()) : notIn; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 695 | else { |
| 696 | // If this is a call instruction, make sure to prepare ALL of the result |
| 697 | // values as well as the chain. |
| 698 | if (Node->getNumValues() == 1) |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 699 | Reg = Result = notIn; // Void call, just a chain. |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 700 | else { |
| 701 | Result = MakeReg(Node->getValueType(0)); |
| 702 | ExprMap[N.getValue(0)] = Result; |
| 703 | for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i) |
| 704 | ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i)); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 705 | ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Andrew Lenharth | 22088bb | 2005-02-02 15:05:33 +0000 | [diff] [blame] | 709 | if (DestType == MVT::f64 || DestType == MVT::f32 || |
Andrew Lenharth | 06342c3 | 2005-02-07 06:21:37 +0000 | [diff] [blame] | 710 | ( |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 711 | (opcode == ISD::LOAD || opcode == ISD::CopyFromReg || |
| 712 | opcode == ISD::EXTLOAD) && |
| 713 | (N.getValue(0).getValueType() == MVT::f32 || |
| 714 | N.getValue(0).getValueType() == MVT::f64) |
Andrew Lenharth | 06342c3 | 2005-02-07 06:21:37 +0000 | [diff] [blame] | 715 | ) |
| 716 | ) |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 717 | return SelectExprFP(N, Result); |
| 718 | |
| 719 | switch (opcode) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 720 | default: |
| 721 | Node->dump(); |
| 722 | assert(0 && "Node not handled!\n"); |
| 723 | |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 724 | case ISD::ConstantPool: |
| 725 | Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex(); |
| 726 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 727 | BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(Tmp1); |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 728 | return Result; |
| 729 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 730 | case ISD::FrameIndex: |
| 731 | Tmp1 = cast<FrameIndexSDNode>(N)->getIndex(); |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 732 | BuildMI(BB, Alpha::LDA, 2, Result).addFrameIndex(Tmp1).addReg(Alpha::F31); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 733 | return Result; |
| 734 | |
| 735 | case ISD::EXTLOAD: |
Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 736 | case ISD::ZEXTLOAD: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 737 | case ISD::SEXTLOAD: |
Andrew Lenharth | a549deb | 2005-02-07 05:33:15 +0000 | [diff] [blame] | 738 | case ISD::LOAD: |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 739 | { |
| 740 | // Make sure we generate both values. |
| 741 | if (Result != notIn) |
| 742 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
| 743 | else |
| 744 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 745 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 746 | SDOperand Chain = N.getOperand(0); |
| 747 | SDOperand Address = N.getOperand(1); |
| 748 | Select(Chain); |
| 749 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 750 | assert(Node->getValueType(0) == MVT::i64 && |
| 751 | "Unknown type to sign extend to."); |
Andrew Lenharth | 0382401 | 2005-02-07 05:55:55 +0000 | [diff] [blame] | 752 | if (opcode == ISD::LOAD) |
| 753 | Opc = Alpha::LDQ; |
| 754 | else |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 755 | switch (cast<MVTSDNode>(Node)->getExtraValueType()) { |
| 756 | default: Node->dump(); assert(0 && "Bad sign extend!"); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 757 | case MVT::i32: Opc = Alpha::LDL; |
| 758 | assert(opcode != ISD::ZEXTLOAD && "Not sext"); break; |
| 759 | case MVT::i16: Opc = Alpha::LDWU; |
| 760 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; |
Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 761 | case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 762 | case MVT::i8: Opc = Alpha::LDBU; |
| 763 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 764 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 765 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 766 | if (Address.getOpcode() == ISD::GlobalAddress) { |
| 767 | AlphaLowering.restoreGP(BB); |
| 768 | Opc = GetSymVersion(Opc); |
| 769 | BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); |
| 770 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 771 | else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) { |
| 772 | AlphaLowering.restoreGP(BB); |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 773 | Opc = GetSymVersion(Opc); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 774 | BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex()); |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 775 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 776 | else if(Address.getOpcode() == ISD::FrameIndex) { |
| 777 | Tmp1 = cast<FrameIndexSDNode>(Address)->getIndex(); |
| 778 | BuildMI(BB, Opc, 2, Result).addFrameIndex(Tmp1).addReg(Alpha::F31); |
| 779 | } else { |
| 780 | long offset; |
| 781 | SelectAddr(Address, Tmp1, offset); |
| 782 | BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1); |
| 783 | } |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 784 | return Result; |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 785 | } |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 786 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 787 | case ISD::GlobalAddress: |
| 788 | AlphaLowering.restoreGP(BB); |
| 789 | BuildMI(BB, Alpha::LOAD_ADDR, 1, Result) |
| 790 | .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal()); |
| 791 | return Result; |
| 792 | |
| 793 | case ISD::CALL: |
| 794 | { |
| 795 | Select(N.getOperand(0)); |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 796 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 797 | // The chain for this call is now lowered. |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 798 | ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn)); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 799 | |
| 800 | //grab the arguments |
| 801 | std::vector<unsigned> argvregs; |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 802 | //assert(Node->getNumOperands() < 8 && "Only 6 args supported"); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 803 | for(int i = 2, e = Node->getNumOperands(); i < e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 804 | argvregs.push_back(SelectExpr(N.getOperand(i))); |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 805 | |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 806 | //in reg args |
| 807 | 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] | 808 | { |
| 809 | unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18, |
| 810 | Alpha::R19, Alpha::R20, Alpha::R21}; |
| 811 | unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18, |
| 812 | Alpha::F19, Alpha::F20, Alpha::F21}; |
| 813 | switch(N.getOperand(i+2).getValueType()) { |
| 814 | default: |
| 815 | Node->dump(); |
| 816 | N.getOperand(i).Val->dump(); |
| 817 | std::cerr << "Type for " << i << " is: " << |
| 818 | N.getOperand(i+2).getValueType() << "\n"; |
| 819 | assert(0 && "Unknown value type for call"); |
| 820 | case MVT::i1: |
| 821 | case MVT::i8: |
| 822 | case MVT::i16: |
| 823 | case MVT::i32: |
| 824 | case MVT::i64: |
| 825 | BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]).addReg(argvregs[i]); |
| 826 | break; |
| 827 | case MVT::f32: |
| 828 | case MVT::f64: |
| 829 | BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i]).addReg(argvregs[i]); |
| 830 | break; |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 831 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 832 | } |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 833 | //in mem args |
| 834 | for (int i = 6, e = argvregs.size(); i < e; ++i) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 835 | { |
| 836 | switch(N.getOperand(i+2).getValueType()) { |
| 837 | default: |
| 838 | Node->dump(); |
| 839 | N.getOperand(i).Val->dump(); |
| 840 | std::cerr << "Type for " << i << " is: " << |
| 841 | N.getOperand(i+2).getValueType() << "\n"; |
| 842 | assert(0 && "Unknown value type for call"); |
| 843 | case MVT::i1: |
| 844 | case MVT::i8: |
| 845 | case MVT::i16: |
| 846 | case MVT::i32: |
| 847 | case MVT::i64: |
| 848 | BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); |
| 849 | break; |
| 850 | case MVT::f32: |
| 851 | BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); |
| 852 | break; |
| 853 | case MVT::f64: |
| 854 | BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30); |
| 855 | break; |
Andrew Lenharth | 684f229 | 2005-01-30 00:35:27 +0000 | [diff] [blame] | 856 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 857 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 858 | //build the right kind of call |
| 859 | if (GlobalAddressSDNode *GASD = |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 860 | dyn_cast<GlobalAddressSDNode>(N.getOperand(1))) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 861 | { |
Andrew Lenharth | 3e31592 | 2005-02-10 20:10:38 +0000 | [diff] [blame] | 862 | //if (GASD->getGlobal()->isExternal()) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 863 | //use safe calling convention |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 864 | AlphaLowering.restoreGP(BB); |
| 865 | BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal(),true); |
Andrew Lenharth | 3e31592 | 2005-02-10 20:10:38 +0000 | [diff] [blame] | 866 | //} else { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 867 | //use PC relative branch call |
Andrew Lenharth | 3e31592 | 2005-02-10 20:10:38 +0000 | [diff] [blame] | 868 | //BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true); |
| 869 | //} |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 870 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 871 | else if (ExternalSymbolSDNode *ESSDN = |
Andrew Lenharth | 7b2a527 | 2005-01-30 20:42:36 +0000 | [diff] [blame] | 872 | dyn_cast<ExternalSymbolSDNode>(N.getOperand(1))) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 873 | { |
| 874 | AlphaLowering.restoreGP(BB); |
| 875 | BuildMI(BB, Alpha::CALL, 0).addExternalSymbol(ESSDN->getSymbol(), true); |
| 876 | } else { |
| 877 | //no need to restore GP as we are doing an indirect call |
| 878 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 879 | BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1); |
| 880 | BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0); |
| 881 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 882 | |
| 883 | //push the result into a virtual register |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 884 | |
| 885 | switch (Node->getValueType(0)) { |
| 886 | default: Node->dump(); assert(0 && "Unknown value type for call result!"); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 887 | case MVT::Other: return notIn; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 888 | case MVT::i1: |
| 889 | case MVT::i8: |
| 890 | case MVT::i16: |
| 891 | case MVT::i32: |
| 892 | case MVT::i64: |
| 893 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0); |
| 894 | break; |
| 895 | case MVT::f32: |
| 896 | case MVT::f64: |
| 897 | BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0); |
| 898 | break; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 899 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 900 | return Result+N.ResNo; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 901 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 902 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 903 | case ISD::SIGN_EXTEND: |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 904 | abort(); |
| 905 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 906 | case ISD::SIGN_EXTEND_INREG: |
| 907 | { |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 908 | //Alpha has instructions for a bunch of signed 32 bit stuff |
| 909 | if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 910 | { |
| 911 | switch (N.getOperand(0).getOpcode()) { |
| 912 | case ISD::ADD: |
| 913 | case ISD::SUB: |
| 914 | case ISD::MUL: |
| 915 | { |
| 916 | bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD; |
| 917 | bool isMul = N.getOperand(0).getOpcode() == ISD::MUL; |
| 918 | //FIXME: first check for Scaled Adds and Subs! |
| 919 | if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant && |
| 920 | cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255) |
| 921 | { //Normal imm add/sub |
| 922 | Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi); |
| 923 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 924 | Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue(); |
| 925 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 926 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 927 | else |
| 928 | { //Normal add/sub |
| 929 | Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULLi : Alpha::SUBL); |
| 930 | Tmp1 = SelectExpr(N.getOperand(0).getOperand(0)); |
| 931 | Tmp2 = SelectExpr(N.getOperand(0).getOperand(1)); |
| 932 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 933 | } |
| 934 | return Result; |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 935 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 936 | default: break; //Fall Though; |
| 937 | } |
| 938 | } //Every thing else fall though too, including unhandled opcodes above |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 939 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 940 | MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node); |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 941 | //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n"; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 942 | switch(MVN->getExtraValueType()) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 943 | { |
| 944 | default: |
| 945 | Node->dump(); |
| 946 | assert(0 && "Sign Extend InReg not there yet"); |
| 947 | break; |
| 948 | case MVT::i32: |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 949 | { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 950 | BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0); |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 951 | break; |
| 952 | } |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 953 | case MVT::i16: |
| 954 | BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1); |
| 955 | break; |
| 956 | case MVT::i8: |
| 957 | BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1); |
| 958 | break; |
Andrew Lenharth | ebce504 | 2005-02-12 19:35:12 +0000 | [diff] [blame^] | 959 | case MVT::i1: |
| 960 | Tmp2 = MakeReg(MVT::i64); |
| 961 | BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1); |
| 962 | BuildMI(BB, Alpha::SUB, 2, Result).addReg(Alpha::F31).addReg(Tmp2); |
| 963 | break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 964 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 965 | return Result; |
| 966 | } |
| 967 | case ISD::ZERO_EXTEND_INREG: |
| 968 | { |
| 969 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 970 | MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node); |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 971 | //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n"; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 972 | switch(MVN->getExtraValueType()) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 973 | { |
| 974 | default: |
| 975 | Node->dump(); |
| 976 | assert(0 && "Zero Extend InReg not there yet"); |
| 977 | break; |
| 978 | case MVT::i32: Tmp2 = 0xf0; break; |
| 979 | case MVT::i16: Tmp2 = 0xfc; break; |
| 980 | case MVT::i8: Tmp2 = 0xfe; break; |
| 981 | case MVT::i1: //handle this one special |
| 982 | BuildMI(BB, Alpha::ANDi, 2, Result).addReg(Tmp1).addImm(1); |
| 983 | return Result; |
| 984 | } |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 985 | BuildMI(BB, Alpha::ZAPi, 2, Result).addReg(Tmp1).addImm(Tmp2); |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 986 | return Result; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | case ISD::SETCC: |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 990 | { |
| 991 | if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) { |
| 992 | if (MVT::isInteger(SetCC->getOperand(0).getValueType())) { |
| 993 | bool isConst1 = false; |
| 994 | bool isConst2 = false; |
| 995 | int dir; |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 996 | |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 997 | //Tmp1 = SelectExpr(N.getOperand(0)); |
| 998 | if(N.getOperand(0).getOpcode() == ISD::Constant && |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 999 | cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 255) |
| 1000 | isConst1 = true; |
| 1001 | if(N.getOperand(1).getOpcode() == ISD::Constant && |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1002 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255) |
| 1003 | isConst2 = true; |
| 1004 | |
| 1005 | switch (SetCC->getCondition()) { |
| 1006 | default: Node->dump(); assert(0 && "Unknown integer comparison!"); |
| 1007 | case ISD::SETEQ: Opc = Alpha::CMPEQ; dir=0; break; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1008 | case ISD::SETLT: |
| 1009 | Opc = isConst2 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break; |
| 1010 | case ISD::SETLE: |
| 1011 | Opc = isConst2 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break; |
| 1012 | case ISD::SETGT: |
| 1013 | Opc = isConst1 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 2; break; |
| 1014 | case ISD::SETGE: |
| 1015 | Opc = isConst1 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 2; break; |
| 1016 | case ISD::SETULT: |
| 1017 | Opc = isConst2 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break; |
| 1018 | case ISD::SETUGT: |
| 1019 | Opc = isConst1 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 2; break; |
| 1020 | case ISD::SETULE: |
| 1021 | Opc = isConst2 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break; |
| 1022 | case ISD::SETUGE: |
| 1023 | Opc = isConst1 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 2; break; |
Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1024 | case ISD::SETNE: {//Handle this one special |
| 1025 | //std::cerr << "Alpha does not have a setne.\n"; |
| 1026 | //abort(); |
| 1027 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1028 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1029 | Tmp3 = MakeReg(MVT::i64); |
| 1030 | BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1031 | //Remeber we have the Inv for this CC |
| 1032 | CCInvMap[N] = Tmp3; |
Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1033 | //and invert |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1034 | BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3); |
Andrew Lenharth | d2bb960 | 2005-01-27 07:50:35 +0000 | [diff] [blame] | 1035 | return Result; |
| 1036 | } |
| 1037 | } |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1038 | if (dir == 1) { |
| 1039 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1040 | if (isConst2) { |
| 1041 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1042 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1043 | } else { |
| 1044 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1045 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1046 | } |
| 1047 | } else if (dir == 2) { |
| 1048 | Tmp1 = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 1049 | if (isConst1) { |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1050 | Tmp2 = cast<ConstantSDNode>(N.getOperand(0))->getValue(); |
| 1051 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1052 | } else { |
| 1053 | Tmp2 = SelectExpr(N.getOperand(0)); |
| 1054 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1055 | } |
| 1056 | } else { //dir == 0 |
| 1057 | if (isConst1) { |
| 1058 | Tmp1 = cast<ConstantSDNode>(N.getOperand(0))->getValue(); |
| 1059 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1060 | BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp2).addImm(Tmp1); |
| 1061 | } else if (isConst2) { |
| 1062 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1063 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1064 | BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1065 | } else { |
| 1066 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1067 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1068 | BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1069 | } |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1070 | } |
| 1071 | } else { |
| 1072 | //assert(SetCC->getOperand(0).getValueType() != MVT::f32 && "SetCC f32 should have been promoted"); |
| 1073 | bool rev = false; |
| 1074 | bool inv = false; |
| 1075 | |
| 1076 | switch (SetCC->getCondition()) { |
| 1077 | default: Node->dump(); assert(0 && "Unknown FP comparison!"); |
| 1078 | case ISD::SETEQ: Opc = Alpha::CMPTEQ; break; |
| 1079 | case ISD::SETLT: Opc = Alpha::CMPTLT; break; |
| 1080 | case ISD::SETLE: Opc = Alpha::CMPTLE; break; |
| 1081 | case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break; |
| 1082 | case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break; |
| 1083 | case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break; |
| 1084 | } |
| 1085 | |
| 1086 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1087 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1088 | //Can only compare doubles, and dag won't promote for me |
| 1089 | if (SetCC->getOperand(0).getValueType() == MVT::f32) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1090 | { |
| 1091 | Tmp3 = MakeReg(MVT::f64); |
| 1092 | BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1); |
| 1093 | Tmp1 = Tmp3; |
| 1094 | } |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1095 | if (SetCC->getOperand(1).getValueType() == MVT::f32) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1096 | { |
| 1097 | Tmp3 = MakeReg(MVT::f64); |
| 1098 | BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2); |
| 1099 | Tmp1 = Tmp2; |
| 1100 | } |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1101 | |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1102 | if (rev) std::swap(Tmp1, Tmp2); |
| 1103 | Tmp3 = MakeReg(MVT::f64); |
| 1104 | //do the comparison |
| 1105 | BuildMI(BB, Opc, 2, Tmp3).addReg(Tmp1).addReg(Tmp2); |
| 1106 | |
| 1107 | //now arrange for Result (int) to have a 1 or 0 |
| 1108 | |
| 1109 | // Spill the FP to memory and reload it from there. |
| 1110 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; |
| 1111 | MachineFunction *F = BB->getParent(); |
| 1112 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); |
| 1113 | unsigned Tmp4 = MakeReg(MVT::f64); |
| 1114 | BuildMI(BB, Alpha::CVTTQ, 1, Tmp4).addReg(Tmp3); |
| 1115 | BuildMI(BB, Alpha::STT, 3).addReg(Tmp4).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 1116 | unsigned Tmp5 = MakeReg(MVT::i64); |
| 1117 | BuildMI(BB, Alpha::LDQ, 2, Tmp5).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1118 | |
Andrew Lenharth | d4bdd54 | 2005-02-05 16:41:03 +0000 | [diff] [blame] | 1119 | //now, set result based on Tmp5 |
| 1120 | //Set Tmp6 if fp cmp was false |
| 1121 | unsigned Tmp6 = MakeReg(MVT::i64); |
| 1122 | BuildMI(BB, Alpha::CMPEQ, 2, Tmp6).addReg(Tmp5).addReg(Alpha::R31); |
| 1123 | //and invert |
| 1124 | BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp6).addReg(Alpha::R31); |
| 1125 | |
| 1126 | } |
| 1127 | // else |
| 1128 | // { |
| 1129 | // Node->dump(); |
| 1130 | // assert(0 && "Not a setcc in setcc"); |
| 1131 | // } |
Andrew Lenharth | 9818c05 | 2005-02-05 13:19:12 +0000 | [diff] [blame] | 1132 | } |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1133 | return Result; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1134 | } |
Andrew Lenharth | 3d65d31 | 2005-01-27 03:49:45 +0000 | [diff] [blame] | 1135 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1136 | case ISD::CopyFromReg: |
| 1137 | { |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1138 | // Make sure we generate both values. |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1139 | if (Result != notIn) |
| 1140 | ExprMap[N.getValue(1)] = notIn; // Generate the token |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1141 | else |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1142 | Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType()); |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1143 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1144 | SDOperand Chain = N.getOperand(0); |
| 1145 | |
| 1146 | Select(Chain); |
| 1147 | unsigned r = dyn_cast<RegSDNode>(Node)->getReg(); |
| 1148 | //std::cerr << "CopyFromReg " << Result << " = " << r << "\n"; |
| 1149 | BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r); |
| 1150 | return Result; |
| 1151 | } |
| 1152 | |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1153 | //Most of the plain arithmetic and logic share the same form, and the same |
| 1154 | //constant immediate test |
| 1155 | case ISD::AND: |
| 1156 | case ISD::OR: |
| 1157 | case ISD::XOR: |
| 1158 | case ISD::SHL: |
| 1159 | case ISD::SRL: |
Andrew Lenharth | 2c59435 | 2005-01-29 15:42:07 +0000 | [diff] [blame] | 1160 | case ISD::SRA: |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1161 | case ISD::MUL: |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1162 | assert (DestType == MVT::i64 && "Only do arithmetic on i64s!"); |
| 1163 | if(N.getOperand(1).getOpcode() == ISD::Constant && |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1164 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1165 | { |
| 1166 | switch(opcode) { |
| 1167 | case ISD::AND: Opc = Alpha::ANDi; break; |
| 1168 | case ISD::OR: Opc = Alpha::BISi; break; |
| 1169 | case ISD::XOR: Opc = Alpha::XORi; break; |
| 1170 | case ISD::SHL: Opc = Alpha::SLi; break; |
| 1171 | case ISD::SRL: Opc = Alpha::SRLi; break; |
| 1172 | case ISD::SRA: Opc = Alpha::SRAi; break; |
| 1173 | case ISD::MUL: Opc = Alpha::MULQi; break; |
| 1174 | }; |
| 1175 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1176 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1177 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1178 | } else { |
| 1179 | switch(opcode) { |
| 1180 | case ISD::AND: Opc = Alpha::AND; break; |
| 1181 | case ISD::OR: Opc = Alpha::BIS; break; |
| 1182 | case ISD::XOR: Opc = Alpha::XOR; break; |
| 1183 | case ISD::SHL: Opc = Alpha::SL; break; |
| 1184 | case ISD::SRL: Opc = Alpha::SRL; break; |
| 1185 | case ISD::SRA: Opc = Alpha::SRA; break; |
| 1186 | case ISD::MUL: Opc = Alpha::MULQ; break; |
| 1187 | }; |
| 1188 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1189 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1190 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1191 | } |
Andrew Lenharth | 2d6f022 | 2005-01-24 19:44:07 +0000 | [diff] [blame] | 1192 | return Result; |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1193 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1194 | case ISD::ADD: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1195 | case ISD::SUB: |
Andrew Lenharth | 2f8fb77 | 2005-01-25 00:35:34 +0000 | [diff] [blame] | 1196 | { |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1197 | bool isAdd = opcode == ISD::ADD; |
| 1198 | |
| 1199 | //FIXME: first check for Scaled Adds and Subs! |
| 1200 | if(N.getOperand(1).getOpcode() == ISD::Constant && |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1201 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1202 | { //Normal imm add/sub |
| 1203 | Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi; |
| 1204 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1205 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1206 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2); |
| 1207 | } |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1208 | else if(N.getOperand(1).getOpcode() == ISD::Constant && |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1209 | cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1210 | { //LDA //FIXME: expand the above condition a bit |
| 1211 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1212 | Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1213 | if (!isAdd) |
| 1214 | Tmp2 = -Tmp2; |
| 1215 | BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1); |
| 1216 | } else { |
| 1217 | //Normal add/sub |
| 1218 | Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ; |
| 1219 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1220 | Tmp2 = SelectExpr(N.getOperand(1)); |
| 1221 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
| 1222 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1223 | return Result; |
| 1224 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1225 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1226 | case ISD::UREM: |
Andrew Lenharth | 0298118 | 2005-01-26 01:24:38 +0000 | [diff] [blame] | 1227 | case ISD::SREM: |
| 1228 | case ISD::SDIV: |
| 1229 | case ISD::UDIV: |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1230 | //FIXME: alpha really doesn't support any of these operations, |
| 1231 | // the ops are expanded into special library calls with |
| 1232 | // special calling conventions |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1233 | //Restore GP because it is a call after all... |
Andrew Lenharth | 40831c5 | 2005-01-28 06:57:18 +0000 | [diff] [blame] | 1234 | switch(opcode) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1235 | case ISD::UREM: AlphaLowering.restoreGP(BB); Opc = Alpha::REMQU; break; |
| 1236 | case ISD::SREM: AlphaLowering.restoreGP(BB); Opc = Alpha::REMQ; break; |
| 1237 | case ISD::UDIV: AlphaLowering.restoreGP(BB); Opc = Alpha::DIVQU; break; |
| 1238 | case ISD::SDIV: AlphaLowering.restoreGP(BB); Opc = Alpha::DIVQ; break; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1239 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1240 | Tmp1 = SelectExpr(N.getOperand(0)); |
| 1241 | Tmp2 = SelectExpr(N.getOperand(1)); |
Andrew Lenharth | 0298118 | 2005-01-26 01:24:38 +0000 | [diff] [blame] | 1242 | BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1243 | return Result; |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1244 | |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1245 | case ISD::FP_TO_UINT: |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 1246 | case ISD::FP_TO_SINT: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1247 | { |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 1248 | assert (DestType == MVT::i64 && "only quads can be loaded to"); |
| 1249 | MVT::ValueType SrcType = N.getOperand(0).getValueType(); |
Andrew Lenharth | 0382401 | 2005-02-07 05:55:55 +0000 | [diff] [blame] | 1250 | assert (SrcType == MVT::f32 || SrcType == MVT::f64); |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 1251 | Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register |
| 1252 | |
| 1253 | //The hard way: |
| 1254 | // Spill the integer to memory and reload it from there. |
| 1255 | unsigned Size = MVT::getSizeInBits(MVT::f64)/8; |
| 1256 | MachineFunction *F = BB->getParent(); |
| 1257 | int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8); |
| 1258 | |
| 1259 | //CVTTQ STT LDQ |
| 1260 | //CVTST CVTTQ STT LDQ |
| 1261 | if (SrcType == MVT::f32) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1262 | { |
| 1263 | Tmp2 = MakeReg(MVT::f64); |
| 1264 | BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1); |
| 1265 | Tmp1 = Tmp2; |
| 1266 | } |
Andrew Lenharth | 7efadce | 2005-01-31 01:44:26 +0000 | [diff] [blame] | 1267 | Tmp2 = MakeReg(MVT::f64); |
| 1268 | BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1); |
| 1269 | BuildMI(BB, Alpha::STT, 3).addReg(Tmp2).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 1270 | BuildMI(BB, Alpha::LDQ, 2, Result).addFrameIndex(FrameIdx).addReg(Alpha::F31); |
| 1271 | |
| 1272 | return Result; |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1273 | } |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1274 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1275 | // // case ISD::FP_TO_UINT: |
Andrew Lenharth | 3e98fde | 2005-01-26 21:54:09 +0000 | [diff] [blame] | 1276 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1277 | case ISD::SELECT: |
| 1278 | { |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1279 | Tmp1 = SelectExpr(N.getOperand(0)); //Cond |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1280 | Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE |
| 1281 | Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1282 | // Get the condition into the zero flag. |
Andrew Lenharth | e76797c | 2005-02-01 20:40:27 +0000 | [diff] [blame] | 1283 | BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1284 | return Result; |
| 1285 | } |
| 1286 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1287 | case ISD::Constant: |
| 1288 | { |
Andrew Lenharth | 22d5a41 | 2005-02-02 00:51:15 +0000 | [diff] [blame] | 1289 | unsigned long val = cast<ConstantSDNode>(N)->getValue(); |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1290 | if (val < 32000 && (long)val > -32000) |
| 1291 | BuildMI(BB, Alpha::LOAD_IMM, 1, Result).addImm(val); |
| 1292 | else { |
| 1293 | MachineConstantPool *CP = BB->getParent()->getConstantPool(); |
| 1294 | ConstantUInt *C = ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val); |
| 1295 | unsigned CPI = CP->getConstantPoolIndex(C); |
| 1296 | AlphaLowering.restoreGP(BB); |
| 1297 | BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(CPI); |
| 1298 | } |
| 1299 | return Result; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1300 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | return 0; |
| 1304 | } |
| 1305 | |
| 1306 | void ISel::Select(SDOperand N) { |
| 1307 | unsigned Tmp1, Tmp2, Opc; |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1308 | unsigned opcode = N.getOpcode(); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1309 | |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 1310 | // FIXME: Disable for our current expansion model! |
Andrew Lenharth | cc1b16f | 2005-01-28 23:17:54 +0000 | [diff] [blame] | 1311 | if (/*!N->hasOneUse() &&*/ !ExprMap.insert(std::make_pair(N, notIn)).second) |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 1312 | return; // Already selected. |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1313 | |
| 1314 | SDNode *Node = N.Val; |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1315 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1316 | |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1317 | switch (opcode) { |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1318 | |
| 1319 | default: |
| 1320 | Node->dump(); std::cerr << "\n"; |
| 1321 | assert(0 && "Node not handled yet!"); |
| 1322 | |
| 1323 | case ISD::BRCOND: { |
Andrew Lenharth | 445171a | 2005-02-08 00:40:03 +0000 | [diff] [blame] | 1324 | SelectBranchCC(N); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1325 | return; |
| 1326 | } |
| 1327 | |
| 1328 | case ISD::BR: { |
| 1329 | MachineBasicBlock *Dest = |
| 1330 | cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock(); |
| 1331 | |
| 1332 | Select(N.getOperand(0)); |
| 1333 | BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
| 1337 | case ISD::ImplicitDef: |
| 1338 | Select(N.getOperand(0)); |
| 1339 | BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg()); |
| 1340 | return; |
| 1341 | |
| 1342 | case ISD::EntryToken: return; // Noop |
| 1343 | |
| 1344 | case ISD::TokenFactor: |
| 1345 | for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) |
| 1346 | Select(Node->getOperand(i)); |
| 1347 | |
| 1348 | //N.Val->dump(); std::cerr << "\n"; |
| 1349 | //assert(0 && "Node not handled yet!"); |
| 1350 | |
| 1351 | return; |
| 1352 | |
| 1353 | case ISD::CopyToReg: |
| 1354 | Select(N.getOperand(0)); |
| 1355 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1356 | Tmp2 = cast<RegSDNode>(N)->getReg(); |
| 1357 | |
| 1358 | if (Tmp1 != Tmp2) { |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1359 | if (N.getOperand(1).getValueType() == MVT::f64 || |
| 1360 | N.getOperand(1).getValueType() == MVT::f32) |
Andrew Lenharth | 2921916 | 2005-02-07 06:31:44 +0000 | [diff] [blame] | 1361 | BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); |
| 1362 | else |
| 1363 | BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1364 | } |
| 1365 | return; |
| 1366 | |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1367 | case ISD::RET: |
| 1368 | switch (N.getNumOperands()) { |
| 1369 | default: |
| 1370 | std::cerr << N.getNumOperands() << "\n"; |
| 1371 | for (unsigned i = 0; i < N.getNumOperands(); ++i) |
| 1372 | std::cerr << N.getOperand(i).getValueType() << "\n"; |
| 1373 | Node->dump(); |
| 1374 | assert(0 && "Unknown return instruction!"); |
| 1375 | case 2: |
| 1376 | Select(N.getOperand(0)); |
| 1377 | Tmp1 = SelectExpr(N.getOperand(1)); |
| 1378 | switch (N.getOperand(1).getValueType()) { |
| 1379 | default: Node->dump(); |
| 1380 | assert(0 && "All other types should have been promoted!!"); |
| 1381 | case MVT::f64: |
| 1382 | case MVT::f32: |
| 1383 | BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1); |
| 1384 | break; |
| 1385 | case MVT::i32: |
| 1386 | case MVT::i64: |
| 1387 | BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1); |
| 1388 | break; |
| 1389 | } |
| 1390 | break; |
| 1391 | case 1: |
| 1392 | Select(N.getOperand(0)); |
| 1393 | break; |
| 1394 | } |
| 1395 | //Tmp2 = AlphaLowering.getRetAddr(); |
| 1396 | //BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(Tmp2).addReg(Tmp2); |
| 1397 | BuildMI(BB, Alpha::RETURN, 0); // Just emit a 'ret' instruction |
| 1398 | return; |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1399 | |
Andrew Lenharth | f311e8b | 2005-02-07 05:18:02 +0000 | [diff] [blame] | 1400 | case ISD::TRUNCSTORE: |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1401 | case ISD::STORE: |
Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 1402 | { |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1403 | SDOperand Chain = N.getOperand(0); |
| 1404 | SDOperand Value = N.getOperand(1); |
| 1405 | SDOperand Address = N.getOperand(2); |
| 1406 | Select(Chain); |
| 1407 | |
| 1408 | Tmp1 = SelectExpr(Value); //value |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1409 | |
| 1410 | if (opcode == ISD::STORE) { |
| 1411 | switch(Value.getValueType()) { |
| 1412 | default: assert(0 && "unknown Type in store"); |
| 1413 | case MVT::i64: Opc = Alpha::STQ; break; |
| 1414 | case MVT::f64: Opc = Alpha::STT; break; |
| 1415 | case MVT::f32: Opc = Alpha::STS; break; |
| 1416 | } |
| 1417 | } else { //ISD::TRUNCSTORE |
| 1418 | switch(cast<MVTSDNode>(Node)->getExtraValueType()) { |
| 1419 | default: assert(0 && "unknown Type in store"); |
| 1420 | case MVT::i1: //FIXME: DAG does not promote this load |
| 1421 | case MVT::i8: Opc = Alpha::STB; break; |
| 1422 | case MVT::i16: Opc = Alpha::STW; break; |
| 1423 | case MVT::i32: Opc = Alpha::STL; break; |
| 1424 | } |
Andrew Lenharth | 6583890 | 2005-02-06 16:22:15 +0000 | [diff] [blame] | 1425 | } |
Andrew Lenharth | 760270d | 2005-02-07 23:02:23 +0000 | [diff] [blame] | 1426 | |
Andrew Lenharth | 9e8d109 | 2005-02-06 15:40:40 +0000 | [diff] [blame] | 1427 | if (Address.getOpcode() == ISD::GlobalAddress) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1428 | { |
| 1429 | AlphaLowering.restoreGP(BB); |
| 1430 | Opc = GetSymVersion(Opc); |
| 1431 | BuildMI(BB, Opc, 2).addReg(Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal()); |
| 1432 | } |
Andrew Lenharth | 0538034 | 2005-02-07 05:07:00 +0000 | [diff] [blame] | 1433 | else if(Address.getOpcode() == ISD::FrameIndex) |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1434 | { |
| 1435 | Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex(); |
| 1436 | BuildMI(BB, Opc, 3).addReg(Tmp1).addFrameIndex(Tmp2).addReg(Alpha::F31); |
| 1437 | } |
Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 1438 | else |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1439 | { |
| 1440 | long offset; |
| 1441 | SelectAddr(Address, Tmp2, offset); |
| 1442 | BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2); |
| 1443 | } |
Andrew Lenharth | b014d3e | 2005-02-02 17:32:39 +0000 | [diff] [blame] | 1444 | return; |
| 1445 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1446 | |
| 1447 | case ISD::EXTLOAD: |
| 1448 | case ISD::SEXTLOAD: |
| 1449 | case ISD::ZEXTLOAD: |
| 1450 | case ISD::LOAD: |
| 1451 | case ISD::CopyFromReg: |
| 1452 | case ISD::CALL: |
Andrew Lenharth | 63f2ab2 | 2005-02-10 06:25:22 +0000 | [diff] [blame] | 1453 | // case ISD::DYNAMIC_STACKALLOC: |
Andrew Lenharth | 6b9870a | 2005-01-28 14:06:46 +0000 | [diff] [blame] | 1454 | ExprMap.erase(N); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1455 | SelectExpr(N); |
| 1456 | return; |
| 1457 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 1458 | case ISD::ADJCALLSTACKDOWN: |
| 1459 | case ISD::ADJCALLSTACKUP: |
| 1460 | Select(N.getOperand(0)); |
| 1461 | Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue(); |
| 1462 | |
| 1463 | Opc = N.getOpcode() == ISD::ADJCALLSTACKDOWN ? Alpha::ADJUSTSTACKDOWN : |
| 1464 | Alpha::ADJUSTSTACKUP; |
| 1465 | BuildMI(BB, Opc, 1).addImm(Tmp1); |
| 1466 | return; |
| 1467 | } |
| 1468 | assert(0 && "Should not be reached!"); |
| 1469 | } |
| 1470 | |
| 1471 | |
| 1472 | /// createAlphaPatternInstructionSelector - This pass converts an LLVM function |
| 1473 | /// into a machine code representation using pattern matching and a machine |
| 1474 | /// description file. |
| 1475 | /// |
| 1476 | FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) { |
| 1477 | return new ISel(TM); |
| 1478 | } |