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