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