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