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