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