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