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