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