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