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