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