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