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