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