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