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