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