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