Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 1 | //===-- SparcISelLowering.cpp - Sparc DAG Lowering Implementation ---------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the interfaces that Sparc uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "SparcISelLowering.h" |
| 16 | #include "SparcTargetMachine.h" |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 17 | #include "llvm/Function.h" |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/CallingConvLower.h" |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 20 | #include "llvm/CodeGen/MachineFunction.h" |
| 21 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 22 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 23 | #include "llvm/CodeGen/SelectionDAG.h" |
Anton Korobeynikov | 0eefda1 | 2008-10-10 20:28:10 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/VectorExtras.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 28 | |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | // Calling Convention Implementation |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | |
| 33 | #include "SparcGenCallingConv.inc" |
| 34 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 35 | static SDValue LowerRET(SDValue Op, SelectionDAG &DAG) { |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 36 | // CCValAssign - represent the assignment of the return value to locations. |
| 37 | SmallVector<CCValAssign, 16> RVLocs; |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 38 | unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 39 | bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg(); |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 40 | DebugLoc dl = Op.getDebugLoc(); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 41 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 42 | // CCState - Info about the registers and stack slot. |
Owen Anderson | d1474d0 | 2009-07-09 17:57:24 +0000 | [diff] [blame] | 43 | CCState CCInfo(CC, isVarArg, DAG.getTarget(), RVLocs, DAG.getContext()); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 44 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 45 | // Analize return values of ISD::RET |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 46 | CCInfo.AnalyzeReturn(Op.getNode(), RetCC_Sparc32); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 48 | // If this is the first return lowered for this function, add the regs to the |
| 49 | // liveout set for the function. |
| 50 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 51 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 52 | if (RVLocs[i].isRegLoc()) |
| 53 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
| 54 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 55 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 56 | SDValue Chain = Op.getOperand(0); |
| 57 | SDValue Flag; |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 58 | |
| 59 | // Copy the result values into the output registers. |
| 60 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 61 | CCValAssign &VA = RVLocs[i]; |
| 62 | assert(VA.isRegLoc() && "Can only return in registers!"); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 63 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 64 | // ISD::RET => ret chain, (regnum1,val1), ... |
| 65 | // So i*2+1 index only the regnums. |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 66 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 67 | Op.getOperand(i*2+1), Flag); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 68 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 69 | // Guarantee that all emitted copies are stuck together with flags. |
| 70 | Flag = Chain.getValue(1); |
| 71 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 72 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 73 | if (Flag.getNode()) |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 74 | return DAG.getNode(SPISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
| 75 | return DAG.getNode(SPISD::RET_FLAG, dl, MVT::Other, Chain); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /// LowerArguments - V8 uses a very simple ABI, where all values are passed in |
| 79 | /// either one or two GPRs, including FP values. TODO: we should pass FP values |
| 80 | /// in FP registers for fastcc functions. |
Dan Gohman | a44b674 | 2008-06-30 20:31:15 +0000 | [diff] [blame] | 81 | void |
| 82 | SparcTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG, |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 83 | SmallVectorImpl<SDValue> &ArgValues, |
| 84 | DebugLoc dl) { |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 85 | MachineFunction &MF = DAG.getMachineFunction(); |
| 86 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 88 | static const unsigned ArgRegs[] = { |
| 89 | SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5 |
| 90 | }; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 92 | const unsigned *CurArgReg = ArgRegs, *ArgRegEnd = ArgRegs+6; |
| 93 | unsigned ArgOffset = 68; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 94 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 95 | SDValue Root = DAG.getRoot(); |
| 96 | std::vector<SDValue> OutChains; |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 97 | |
| 98 | for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 99 | MVT ObjectVT = getValueType(I->getType()); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 100 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 101 | switch (ObjectVT.getSimpleVT()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 102 | default: llvm_unreachable("Unhandled argument type!"); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 103 | case MVT::i1: |
| 104 | case MVT::i8: |
| 105 | case MVT::i16: |
| 106 | case MVT::i32: |
| 107 | if (I->use_empty()) { // Argument is dead. |
| 108 | if (CurArgReg < ArgRegEnd) ++CurArgReg; |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 109 | ArgValues.push_back(DAG.getUNDEF(ObjectVT)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 110 | } else if (CurArgReg < ArgRegEnd) { // Lives in an incoming GPR |
| 111 | unsigned VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass); |
| 112 | MF.getRegInfo().addLiveIn(*CurArgReg++, VReg); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 113 | SDValue Arg = DAG.getCopyFromReg(Root, dl, VReg, MVT::i32); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 114 | if (ObjectVT != MVT::i32) { |
| 115 | unsigned AssertOp = ISD::AssertSext; |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 116 | Arg = DAG.getNode(AssertOp, dl, MVT::i32, Arg, |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 117 | DAG.getValueType(ObjectVT)); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 118 | Arg = DAG.getNode(ISD::TRUNCATE, dl, ObjectVT, Arg); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 119 | } |
| 120 | ArgValues.push_back(Arg); |
| 121 | } else { |
| 122 | int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 123 | SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32); |
| 124 | SDValue Load; |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 125 | if (ObjectVT == MVT::i32) { |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 126 | Load = DAG.getLoad(MVT::i32, dl, Root, FIPtr, NULL, 0); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 127 | } else { |
| 128 | ISD::LoadExtType LoadOp = ISD::SEXTLOAD; |
| 129 | |
| 130 | // Sparc is big endian, so add an offset based on the ObjectVT. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 131 | unsigned Offset = 4-std::max(1U, ObjectVT.getSizeInBits()/8); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 132 | FIPtr = DAG.getNode(ISD::ADD, dl, MVT::i32, FIPtr, |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 133 | DAG.getConstant(Offset, MVT::i32)); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 134 | Load = DAG.getExtLoad(LoadOp, dl, MVT::i32, Root, FIPtr, |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 135 | NULL, 0, ObjectVT); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 136 | Load = DAG.getNode(ISD::TRUNCATE, dl, ObjectVT, Load); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 137 | } |
| 138 | ArgValues.push_back(Load); |
| 139 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 140 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 141 | ArgOffset += 4; |
| 142 | break; |
| 143 | case MVT::f32: |
| 144 | if (I->use_empty()) { // Argument is dead. |
| 145 | if (CurArgReg < ArgRegEnd) ++CurArgReg; |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 146 | ArgValues.push_back(DAG.getUNDEF(ObjectVT)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 147 | } else if (CurArgReg < ArgRegEnd) { // Lives in an incoming GPR |
| 148 | // FP value is passed in an integer register. |
| 149 | unsigned VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass); |
| 150 | MF.getRegInfo().addLiveIn(*CurArgReg++, VReg); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 151 | SDValue Arg = DAG.getCopyFromReg(Root, dl, VReg, MVT::i32); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 152 | |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 153 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, Arg); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 154 | ArgValues.push_back(Arg); |
| 155 | } else { |
| 156 | int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 157 | SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 158 | SDValue Load = DAG.getLoad(MVT::f32, dl, Root, FIPtr, NULL, 0); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 159 | ArgValues.push_back(Load); |
| 160 | } |
| 161 | ArgOffset += 4; |
| 162 | break; |
| 163 | |
| 164 | case MVT::i64: |
| 165 | case MVT::f64: |
| 166 | if (I->use_empty()) { // Argument is dead. |
| 167 | if (CurArgReg < ArgRegEnd) ++CurArgReg; |
| 168 | if (CurArgReg < ArgRegEnd) ++CurArgReg; |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 169 | ArgValues.push_back(DAG.getUNDEF(ObjectVT)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 170 | } else { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 171 | SDValue HiVal; |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 172 | if (CurArgReg < ArgRegEnd) { // Lives in an incoming GPR |
| 173 | unsigned VRegHi = RegInfo.createVirtualRegister(&SP::IntRegsRegClass); |
| 174 | MF.getRegInfo().addLiveIn(*CurArgReg++, VRegHi); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 175 | HiVal = DAG.getCopyFromReg(Root, dl, VRegHi, MVT::i32); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 176 | } else { |
| 177 | int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 178 | SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 179 | HiVal = DAG.getLoad(MVT::i32, dl, Root, FIPtr, NULL, 0); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 180 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 181 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 182 | SDValue LoVal; |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 183 | if (CurArgReg < ArgRegEnd) { // Lives in an incoming GPR |
| 184 | unsigned VRegLo = RegInfo.createVirtualRegister(&SP::IntRegsRegClass); |
| 185 | MF.getRegInfo().addLiveIn(*CurArgReg++, VRegLo); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 186 | LoVal = DAG.getCopyFromReg(Root, dl, VRegLo, MVT::i32); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 187 | } else { |
| 188 | int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset+4); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 189 | SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 190 | LoVal = DAG.getLoad(MVT::i32, dl, Root, FIPtr, NULL, 0); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 191 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 192 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 193 | // Compose the two halves together into an i64 unit. |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 194 | SDValue WholeValue = |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 195 | DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, LoVal, HiVal); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 196 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 197 | // If we want a double, do a bit convert. |
| 198 | if (ObjectVT == MVT::f64) |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 199 | WholeValue = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, WholeValue); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 200 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 201 | ArgValues.push_back(WholeValue); |
| 202 | } |
| 203 | ArgOffset += 8; |
| 204 | break; |
| 205 | } |
| 206 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 207 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 208 | // Store remaining ArgRegs to the stack if this is a varargs function. |
| 209 | if (F.isVarArg()) { |
| 210 | // Remember the vararg offset for the va_start implementation. |
| 211 | VarArgsFrameOffset = ArgOffset; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 212 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 213 | for (; CurArgReg != ArgRegEnd; ++CurArgReg) { |
| 214 | unsigned VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass); |
| 215 | MF.getRegInfo().addLiveIn(*CurArgReg, VReg); |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 216 | SDValue Arg = DAG.getCopyFromReg(DAG.getRoot(), dl, VReg, MVT::i32); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 217 | |
| 218 | int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 219 | SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 220 | |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 221 | OutChains.push_back(DAG.getStore(DAG.getRoot(), dl, Arg, FIPtr, NULL, 0)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 222 | ArgOffset += 4; |
| 223 | } |
| 224 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 225 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 226 | if (!OutChains.empty()) |
Dale Johannesen | 39355f9 | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 227 | DAG.setRoot(DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 228 | &OutChains[0], OutChains.size())); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 231 | static SDValue LowerCALL(SDValue Op, SelectionDAG &DAG) { |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 232 | CallSDNode *TheCall = cast<CallSDNode>(Op.getNode()); |
| 233 | unsigned CallingConv = TheCall->getCallingConv(); |
| 234 | SDValue Chain = TheCall->getChain(); |
| 235 | SDValue Callee = TheCall->getCallee(); |
| 236 | bool isVarArg = TheCall->isVarArg(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 237 | DebugLoc dl = TheCall->getDebugLoc(); |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 238 | |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 239 | #if 0 |
| 240 | // Analyze operands of the call, assigning locations to each operand. |
| 241 | SmallVector<CCValAssign, 16> ArgLocs; |
| 242 | CCState CCInfo(CallingConv, isVarArg, DAG.getTarget(), ArgLocs); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 243 | CCInfo.AnalyzeCallOperands(Op.getNode(), CC_Sparc32); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 244 | |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 245 | // Get the size of the outgoing arguments stack space requirement. |
| 246 | unsigned ArgsSize = CCInfo.getNextStackOffset(); |
| 247 | // FIXME: We can't use this until f64 is known to take two GPRs. |
| 248 | #else |
| 249 | (void)CC_Sparc32; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 250 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 251 | // Count the size of the outgoing arguments. |
| 252 | unsigned ArgsSize = 0; |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 253 | for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; ++i) { |
| 254 | switch (TheCall->getArg(i).getValueType().getSimpleVT()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 255 | default: llvm_unreachable("Unknown value type!"); |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 256 | case MVT::i1: |
| 257 | case MVT::i8: |
| 258 | case MVT::i16: |
| 259 | case MVT::i32: |
| 260 | case MVT::f32: |
| 261 | ArgsSize += 4; |
| 262 | break; |
| 263 | case MVT::i64: |
| 264 | case MVT::f64: |
| 265 | ArgsSize += 8; |
| 266 | break; |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | if (ArgsSize > 4*6) |
| 270 | ArgsSize -= 4*6; // Space for first 6 arguments is prereserved. |
| 271 | else |
| 272 | ArgsSize = 0; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 273 | #endif |
| 274 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 275 | // Keep stack frames 8-byte aligned. |
| 276 | ArgsSize = (ArgsSize+7) & ~7; |
| 277 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 278 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(ArgsSize, true)); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 279 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 280 | SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass; |
| 281 | SmallVector<SDValue, 8> MemOpChains; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 282 | |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 283 | #if 0 |
| 284 | // Walk the register/memloc assignments, inserting copies/loads. |
| 285 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 286 | CCValAssign &VA = ArgLocs[i]; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 287 | |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 288 | // Arguments start after the 5 first operands of ISD::CALL |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 289 | SDValue Arg = TheCall->getArg(i); |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 290 | |
| 291 | // Promote the value if needed. |
| 292 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 293 | default: llvm_unreachable("Unknown loc info!"); |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 294 | case CCValAssign::Full: break; |
| 295 | case CCValAssign::SExt: |
| 296 | Arg = DAG.getNode(ISD::SIGN_EXTEND, VA.getLocVT(), Arg); |
| 297 | break; |
| 298 | case CCValAssign::ZExt: |
| 299 | Arg = DAG.getNode(ISD::ZERO_EXTEND, VA.getLocVT(), Arg); |
| 300 | break; |
| 301 | case CCValAssign::AExt: |
| 302 | Arg = DAG.getNode(ISD::ANY_EXTEND, VA.getLocVT(), Arg); |
| 303 | break; |
| 304 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 305 | |
| 306 | // Arguments that can be passed on register must be kept at |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 307 | // RegsToPass vector |
| 308 | if (VA.isRegLoc()) { |
| 309 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| 310 | continue; |
| 311 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 312 | |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 313 | assert(VA.isMemLoc()); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 314 | |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 315 | // Create a store off the stack pointer for this argument. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 316 | SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32); |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 317 | // FIXME: VERIFY THAT 68 IS RIGHT. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 318 | SDValue PtrOff = DAG.getIntPtrConstant(VA.getLocMemOffset()+68); |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 319 | PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff); |
| 320 | MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0)); |
| 321 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 322 | |
| 323 | #else |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 324 | static const unsigned ArgRegs[] = { |
| 325 | SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5 |
| 326 | }; |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 327 | unsigned ArgOffset = 68; |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 328 | |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 329 | for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; ++i) { |
| 330 | SDValue Val = TheCall->getArg(i); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 331 | MVT ObjectVT = Val.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 332 | SDValue ValToStore(0, 0); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 333 | unsigned ObjSize; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 334 | switch (ObjectVT.getSimpleVT()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 335 | default: llvm_unreachable("Unhandled argument type!"); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 336 | case MVT::i32: |
| 337 | ObjSize = 4; |
| 338 | |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 339 | if (RegsToPass.size() >= 6) { |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 340 | ValToStore = Val; |
| 341 | } else { |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 342 | RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Val)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 343 | } |
| 344 | break; |
| 345 | case MVT::f32: |
| 346 | ObjSize = 4; |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 347 | if (RegsToPass.size() >= 6) { |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 348 | ValToStore = Val; |
| 349 | } else { |
| 350 | // Convert this to a FP value in an int reg. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 351 | Val = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Val); |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 352 | RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Val)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 353 | } |
| 354 | break; |
Duncan Sands | 8c0f244 | 2008-12-12 08:05:40 +0000 | [diff] [blame] | 355 | case MVT::f64: { |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 356 | ObjSize = 8; |
Duncan Sands | 8c0f244 | 2008-12-12 08:05:40 +0000 | [diff] [blame] | 357 | if (RegsToPass.size() >= 6) { |
| 358 | ValToStore = Val; // Whole thing is passed in memory. |
| 359 | break; |
| 360 | } |
| 361 | |
| 362 | // Break into top and bottom parts by storing to the stack and loading |
| 363 | // out the parts as integers. Top part goes in a reg. |
| 364 | SDValue StackPtr = DAG.CreateStackTemporary(MVT::f64, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 365 | SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, |
| 366 | Val, StackPtr, NULL, 0); |
Duncan Sands | 8c0f244 | 2008-12-12 08:05:40 +0000 | [diff] [blame] | 367 | // Sparc is big-endian, so the high part comes first. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 368 | SDValue Hi = DAG.getLoad(MVT::i32, dl, Store, StackPtr, NULL, 0, 0); |
Duncan Sands | 8c0f244 | 2008-12-12 08:05:40 +0000 | [diff] [blame] | 369 | // Increment the pointer to the other half. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 370 | StackPtr = DAG.getNode(ISD::ADD, dl, StackPtr.getValueType(), StackPtr, |
Duncan Sands | 8c0f244 | 2008-12-12 08:05:40 +0000 | [diff] [blame] | 371 | DAG.getIntPtrConstant(4)); |
| 372 | // Load the low part. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 373 | SDValue Lo = DAG.getLoad(MVT::i32, dl, Store, StackPtr, NULL, 0, 0); |
Duncan Sands | 8c0f244 | 2008-12-12 08:05:40 +0000 | [diff] [blame] | 374 | |
| 375 | RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Hi)); |
| 376 | |
| 377 | if (RegsToPass.size() >= 6) { |
| 378 | ValToStore = Lo; |
| 379 | ArgOffset += 4; |
| 380 | ObjSize = 4; |
| 381 | } else { |
| 382 | RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Lo)); |
| 383 | } |
| 384 | break; |
| 385 | } |
| 386 | case MVT::i64: { |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 387 | ObjSize = 8; |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 388 | if (RegsToPass.size() >= 6) { |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 389 | ValToStore = Val; // Whole thing is passed in memory. |
| 390 | break; |
| 391 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 392 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 393 | // Split the value into top and bottom part. Top part goes in a reg. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 394 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Val, |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 395 | DAG.getConstant(1, MVT::i32)); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 396 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Val, |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 397 | DAG.getConstant(0, MVT::i32)); |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 398 | RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Hi)); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 399 | |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 400 | if (RegsToPass.size() >= 6) { |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 401 | ValToStore = Lo; |
| 402 | ArgOffset += 4; |
| 403 | ObjSize = 4; |
| 404 | } else { |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 405 | RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Lo)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 406 | } |
| 407 | break; |
| 408 | } |
Duncan Sands | 8c0f244 | 2008-12-12 08:05:40 +0000 | [diff] [blame] | 409 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 410 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 411 | if (ValToStore.getNode()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 412 | SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32); |
| 413 | SDValue PtrOff = DAG.getConstant(ArgOffset, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 414 | PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff); |
| 415 | MemOpChains.push_back(DAG.getStore(Chain, dl, ValToStore, |
| 416 | PtrOff, NULL, 0)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 417 | } |
| 418 | ArgOffset += ObjSize; |
| 419 | } |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 420 | #endif |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 421 | |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 422 | // Emit all stores, make sure the occur before any copies into physregs. |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 423 | if (!MemOpChains.empty()) |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 424 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 425 | &MemOpChains[0], MemOpChains.size()); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 426 | |
| 427 | // Build a sequence of copy-to-reg nodes chained together with token |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 428 | // chain and flag operands which copy the outgoing args into registers. |
| 429 | // The InFlag in necessary since all emited instructions must be |
| 430 | // stuck together. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 431 | SDValue InFlag; |
Chris Lattner | 315123f | 2008-03-17 06:58:37 +0000 | [diff] [blame] | 432 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 433 | unsigned Reg = RegsToPass[i].first; |
| 434 | // Remap I0->I7 -> O0->O7. |
| 435 | if (Reg >= SP::I0 && Reg <= SP::I7) |
| 436 | Reg = Reg-SP::I0+SP::O0; |
| 437 | |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 438 | Chain = DAG.getCopyToReg(Chain, dl, Reg, RegsToPass[i].second, InFlag); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 439 | InFlag = Chain.getValue(1); |
| 440 | } |
| 441 | |
| 442 | // If the callee is a GlobalAddress node (quite common, every direct call is) |
| 443 | // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 444 | // Likewise ExternalSymbol -> TargetExternalSymbol. |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 445 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) |
| 446 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i32); |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 447 | else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee)) |
| 448 | Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 449 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 450 | std::vector<MVT> NodeTys; |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 451 | NodeTys.push_back(MVT::Other); // Returns a chain |
| 452 | NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 453 | SDValue Ops[] = { Chain, Callee, InFlag }; |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 454 | Chain = DAG.getNode(SPISD::CALL, dl, NodeTys, Ops, InFlag.getNode() ? 3 : 2); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 455 | InFlag = Chain.getValue(1); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 456 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 457 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(ArgsSize, true), |
| 458 | DAG.getIntPtrConstant(0, true), InFlag); |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 459 | InFlag = Chain.getValue(1); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 460 | |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 461 | // Assign locations to each value returned by this call. |
| 462 | SmallVector<CCValAssign, 16> RVLocs; |
Owen Anderson | d1474d0 | 2009-07-09 17:57:24 +0000 | [diff] [blame] | 463 | CCState RVInfo(CallingConv, isVarArg, DAG.getTarget(), |
| 464 | RVLocs, DAG.getContext()); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 465 | |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 466 | RVInfo.AnalyzeCallResult(TheCall, RetCC_Sparc32); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 467 | SmallVector<SDValue, 8> ResultVals; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 468 | |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 469 | // Copy all of the result registers out of their specified physreg. |
| 470 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 471 | unsigned Reg = RVLocs[i].getLocReg(); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 472 | |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 473 | // Remap I0->I7 -> O0->O7. |
| 474 | if (Reg >= SP::I0 && Reg <= SP::I7) |
| 475 | Reg = Reg-SP::I0+SP::O0; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 476 | |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 477 | Chain = DAG.getCopyFromReg(Chain, dl, Reg, |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 478 | RVLocs[i].getValVT(), InFlag).getValue(1); |
| 479 | InFlag = Chain.getValue(2); |
| 480 | ResultVals.push_back(Chain.getValue(0)); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 481 | } |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 482 | |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 483 | ResultVals.push_back(Chain); |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 484 | |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 485 | // Merge everything together with a MERGE_VALUES node. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 486 | return DAG.getNode(ISD::MERGE_VALUES, dl, |
| 487 | TheCall->getVTList(), &ResultVals[0], |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 488 | ResultVals.size()); |
Chris Lattner | 5a65b92 | 2008-03-17 05:41:48 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | |
| 492 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 493 | //===----------------------------------------------------------------------===// |
| 494 | // TargetLowering Implementation |
| 495 | //===----------------------------------------------------------------------===// |
| 496 | |
| 497 | /// IntCondCCodeToICC - Convert a DAG integer condition code to a SPARC ICC |
| 498 | /// condition. |
| 499 | static SPCC::CondCodes IntCondCCodeToICC(ISD::CondCode CC) { |
| 500 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 501 | default: llvm_unreachable("Unknown integer condition code!"); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 502 | case ISD::SETEQ: return SPCC::ICC_E; |
| 503 | case ISD::SETNE: return SPCC::ICC_NE; |
| 504 | case ISD::SETLT: return SPCC::ICC_L; |
| 505 | case ISD::SETGT: return SPCC::ICC_G; |
| 506 | case ISD::SETLE: return SPCC::ICC_LE; |
| 507 | case ISD::SETGE: return SPCC::ICC_GE; |
| 508 | case ISD::SETULT: return SPCC::ICC_CS; |
| 509 | case ISD::SETULE: return SPCC::ICC_LEU; |
| 510 | case ISD::SETUGT: return SPCC::ICC_GU; |
| 511 | case ISD::SETUGE: return SPCC::ICC_CC; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | /// FPCondCCodeToFCC - Convert a DAG floatingp oint condition code to a SPARC |
| 516 | /// FCC condition. |
| 517 | static SPCC::CondCodes FPCondCCodeToFCC(ISD::CondCode CC) { |
| 518 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 519 | default: llvm_unreachable("Unknown fp condition code!"); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 520 | case ISD::SETEQ: |
| 521 | case ISD::SETOEQ: return SPCC::FCC_E; |
| 522 | case ISD::SETNE: |
| 523 | case ISD::SETUNE: return SPCC::FCC_NE; |
| 524 | case ISD::SETLT: |
| 525 | case ISD::SETOLT: return SPCC::FCC_L; |
| 526 | case ISD::SETGT: |
| 527 | case ISD::SETOGT: return SPCC::FCC_G; |
| 528 | case ISD::SETLE: |
| 529 | case ISD::SETOLE: return SPCC::FCC_LE; |
| 530 | case ISD::SETGE: |
| 531 | case ISD::SETOGE: return SPCC::FCC_GE; |
| 532 | case ISD::SETULT: return SPCC::FCC_UL; |
| 533 | case ISD::SETULE: return SPCC::FCC_ULE; |
| 534 | case ISD::SETUGT: return SPCC::FCC_UG; |
| 535 | case ISD::SETUGE: return SPCC::FCC_UGE; |
| 536 | case ISD::SETUO: return SPCC::FCC_U; |
| 537 | case ISD::SETO: return SPCC::FCC_O; |
| 538 | case ISD::SETONE: return SPCC::FCC_LG; |
| 539 | case ISD::SETUEQ: return SPCC::FCC_UE; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | |
| 544 | SparcTargetLowering::SparcTargetLowering(TargetMachine &TM) |
| 545 | : TargetLowering(TM) { |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 546 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 547 | // Set up the register classes. |
| 548 | addRegisterClass(MVT::i32, SP::IntRegsRegisterClass); |
| 549 | addRegisterClass(MVT::f32, SP::FPRegsRegisterClass); |
| 550 | addRegisterClass(MVT::f64, SP::DFPRegsRegisterClass); |
| 551 | |
| 552 | // Turn FP extload into load/fextend |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 553 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 554 | // Sparc doesn't have i1 sign extending load |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 555 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 556 | // Turn FP truncstore into trunc + store. |
| 557 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
| 558 | |
| 559 | // Custom legalize GlobalAddress nodes into LO/HI parts. |
| 560 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 561 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| 562 | setOperationAction(ISD::ConstantPool , MVT::i32, Custom); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 563 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 564 | // Sparc doesn't have sext_inreg, replace them with shl/sra |
| 565 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 566 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Expand); |
| 567 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1 , Expand); |
| 568 | |
| 569 | // Sparc has no REM or DIVREM operations. |
| 570 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 571 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 572 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 573 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
| 574 | |
| 575 | // Custom expand fp<->sint |
| 576 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 577 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 578 | |
| 579 | // Expand fp<->uint |
| 580 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); |
| 581 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 582 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 583 | setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand); |
| 584 | setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 585 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 586 | // Sparc has no select or setcc: expand to SELECT_CC. |
| 587 | setOperationAction(ISD::SELECT, MVT::i32, Expand); |
| 588 | setOperationAction(ISD::SELECT, MVT::f32, Expand); |
| 589 | setOperationAction(ISD::SELECT, MVT::f64, Expand); |
| 590 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 591 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 592 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 593 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 594 | // Sparc doesn't have BRCOND either, it has BR_CC. |
| 595 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 596 | setOperationAction(ISD::BRIND, MVT::Other, Expand); |
| 597 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
| 598 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 599 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 600 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 601 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 602 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 603 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 604 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 605 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 606 | // SPARC has no intrinsics for these particular operations. |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 607 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
| 608 | |
| 609 | setOperationAction(ISD::FSIN , MVT::f64, Expand); |
| 610 | setOperationAction(ISD::FCOS , MVT::f64, Expand); |
| 611 | setOperationAction(ISD::FREM , MVT::f64, Expand); |
| 612 | setOperationAction(ISD::FSIN , MVT::f32, Expand); |
| 613 | setOperationAction(ISD::FCOS , MVT::f32, Expand); |
| 614 | setOperationAction(ISD::FREM , MVT::f32, Expand); |
| 615 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| 616 | setOperationAction(ISD::CTTZ , MVT::i32, Expand); |
| 617 | setOperationAction(ISD::CTLZ , MVT::i32, Expand); |
| 618 | setOperationAction(ISD::ROTL , MVT::i32, Expand); |
| 619 | setOperationAction(ISD::ROTR , MVT::i32, Expand); |
| 620 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
| 621 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 622 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); |
| 623 | setOperationAction(ISD::FPOW , MVT::f64, Expand); |
| 624 | setOperationAction(ISD::FPOW , MVT::f32, Expand); |
| 625 | |
| 626 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand); |
| 627 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand); |
| 628 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand); |
| 629 | |
| 630 | // FIXME: Sparc provides these multiplies, but we don't have them yet. |
| 631 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
Anton Korobeynikov | 4b58b6a | 2008-10-10 20:29:31 +0000 | [diff] [blame] | 632 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 633 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 634 | // We don't have line number support yet. |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 635 | setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 636 | setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 637 | setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand); |
| 638 | setOperationAction(ISD::EH_LABEL, MVT::Other, Expand); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 639 | |
| 640 | // RET must be custom lowered, to meet ABI requirements |
| 641 | setOperationAction(ISD::RET , MVT::Other, Custom); |
| 642 | |
| 643 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex. |
| 644 | setOperationAction(ISD::VASTART , MVT::Other, Custom); |
| 645 | // VAARG needs to be lowered to not do unaligned accesses for doubles. |
| 646 | setOperationAction(ISD::VAARG , MVT::Other, Custom); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 647 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 648 | // Use the default implementation. |
| 649 | setOperationAction(ISD::VACOPY , MVT::Other, Expand); |
| 650 | setOperationAction(ISD::VAEND , MVT::Other, Expand); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 651 | setOperationAction(ISD::STACKSAVE , MVT::Other, Expand); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 652 | setOperationAction(ISD::STACKRESTORE , MVT::Other, Expand); |
| 653 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Custom); |
| 654 | |
| 655 | // No debug info support yet. |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 656 | setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 657 | setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand); |
| 658 | setOperationAction(ISD::EH_LABEL, MVT::Other, Expand); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 659 | setOperationAction(ISD::DECLARE, MVT::Other, Expand); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 660 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 661 | setStackPointerRegisterToSaveRestore(SP::O6); |
| 662 | |
| 663 | if (TM.getSubtarget<SparcSubtarget>().isV9()) |
| 664 | setOperationAction(ISD::CTPOP, MVT::i32, Legal); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 665 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 666 | computeRegisterProperties(); |
| 667 | } |
| 668 | |
| 669 | const char *SparcTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 670 | switch (Opcode) { |
| 671 | default: return 0; |
| 672 | case SPISD::CMPICC: return "SPISD::CMPICC"; |
| 673 | case SPISD::CMPFCC: return "SPISD::CMPFCC"; |
| 674 | case SPISD::BRICC: return "SPISD::BRICC"; |
| 675 | case SPISD::BRFCC: return "SPISD::BRFCC"; |
| 676 | case SPISD::SELECT_ICC: return "SPISD::SELECT_ICC"; |
| 677 | case SPISD::SELECT_FCC: return "SPISD::SELECT_FCC"; |
| 678 | case SPISD::Hi: return "SPISD::Hi"; |
| 679 | case SPISD::Lo: return "SPISD::Lo"; |
| 680 | case SPISD::FTOI: return "SPISD::FTOI"; |
| 681 | case SPISD::ITOF: return "SPISD::ITOF"; |
| 682 | case SPISD::CALL: return "SPISD::CALL"; |
| 683 | case SPISD::RET_FLAG: return "SPISD::RET_FLAG"; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | /// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to |
| 688 | /// be zero. Op is expected to be a target specific node. Used by DAG |
| 689 | /// combiner. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 690 | void SparcTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 691 | const APInt &Mask, |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 692 | APInt &KnownZero, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 693 | APInt &KnownOne, |
| 694 | const SelectionDAG &DAG, |
| 695 | unsigned Depth) const { |
| 696 | APInt KnownZero2, KnownOne2; |
| 697 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); // Don't know anything. |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 698 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 699 | switch (Op.getOpcode()) { |
| 700 | default: break; |
| 701 | case SPISD::SELECT_ICC: |
| 702 | case SPISD::SELECT_FCC: |
| 703 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, KnownZero, KnownOne, |
| 704 | Depth+1); |
| 705 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero2, KnownOne2, |
| 706 | Depth+1); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 707 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 708 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 709 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 710 | // Only known if known in both the LHS and RHS. |
| 711 | KnownOne &= KnownOne2; |
| 712 | KnownZero &= KnownZero2; |
| 713 | break; |
| 714 | } |
| 715 | } |
| 716 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 717 | // Look at LHS/RHS/CC and see if they are a lowered setcc instruction. If so |
| 718 | // set LHS/RHS and SPCC to the LHS/RHS of the setcc and SPCC to the condition. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 719 | static void LookThroughSetCC(SDValue &LHS, SDValue &RHS, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 720 | ISD::CondCode CC, unsigned &SPCC) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 721 | if (isa<ConstantSDNode>(RHS) && |
| 722 | cast<ConstantSDNode>(RHS)->getZExtValue() == 0 && |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 723 | CC == ISD::SETNE && |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 724 | ((LHS.getOpcode() == SPISD::SELECT_ICC && |
| 725 | LHS.getOperand(3).getOpcode() == SPISD::CMPICC) || |
| 726 | (LHS.getOpcode() == SPISD::SELECT_FCC && |
| 727 | LHS.getOperand(3).getOpcode() == SPISD::CMPFCC)) && |
| 728 | isa<ConstantSDNode>(LHS.getOperand(0)) && |
| 729 | isa<ConstantSDNode>(LHS.getOperand(1)) && |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 730 | cast<ConstantSDNode>(LHS.getOperand(0))->getZExtValue() == 1 && |
| 731 | cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue() == 0) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 732 | SDValue CMPCC = LHS.getOperand(3); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 733 | SPCC = cast<ConstantSDNode>(LHS.getOperand(2))->getZExtValue(); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 734 | LHS = CMPCC.getOperand(0); |
| 735 | RHS = CMPCC.getOperand(1); |
| 736 | } |
| 737 | } |
| 738 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 739 | static SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) { |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 740 | GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 741 | // FIXME there isn't really any debug info here |
| 742 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 743 | SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 744 | SDValue Hi = DAG.getNode(SPISD::Hi, dl, MVT::i32, GA); |
| 745 | SDValue Lo = DAG.getNode(SPISD::Lo, dl, MVT::i32, GA); |
| 746 | return DAG.getNode(ISD::ADD, dl, MVT::i32, Lo, Hi); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 749 | static SDValue LowerCONSTANTPOOL(SDValue Op, SelectionDAG &DAG) { |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 750 | ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 751 | // FIXME there isn't really any debug info here |
| 752 | DebugLoc dl = Op.getDebugLoc(); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 753 | Constant *C = N->getConstVal(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 754 | SDValue CP = DAG.getTargetConstantPool(C, MVT::i32, N->getAlignment()); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 755 | SDValue Hi = DAG.getNode(SPISD::Hi, dl, MVT::i32, CP); |
| 756 | SDValue Lo = DAG.getNode(SPISD::Lo, dl, MVT::i32, CP); |
| 757 | return DAG.getNode(ISD::ADD, dl, MVT::i32, Lo, Hi); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 760 | static SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) { |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 761 | DebugLoc dl = Op.getDebugLoc(); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 762 | // Convert the fp value to integer in an FP register. |
| 763 | assert(Op.getValueType() == MVT::i32); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 764 | Op = DAG.getNode(SPISD::FTOI, dl, MVT::f32, Op.getOperand(0)); |
| 765 | return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Op); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 766 | } |
| 767 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 768 | static SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 769 | DebugLoc dl = Op.getDebugLoc(); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 770 | assert(Op.getOperand(0).getValueType() == MVT::i32); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 771 | SDValue Tmp = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, Op.getOperand(0)); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 772 | // Convert the int value to FP in an FP register. |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 773 | return DAG.getNode(SPISD::ITOF, dl, Op.getValueType(), Tmp); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 776 | static SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) { |
| 777 | SDValue Chain = Op.getOperand(0); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 778 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 779 | SDValue LHS = Op.getOperand(2); |
| 780 | SDValue RHS = Op.getOperand(3); |
| 781 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | 3484c09 | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 782 | DebugLoc dl = Op.getDebugLoc(); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 783 | unsigned Opc, SPCC = ~0U; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 784 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 785 | // If this is a br_cc of a "setcc", and if the setcc got lowered into |
| 786 | // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values. |
| 787 | LookThroughSetCC(LHS, RHS, CC, SPCC); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 788 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 789 | // Get the condition flag. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 790 | SDValue CompareFlag; |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 791 | if (LHS.getValueType() == MVT::i32) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 792 | std::vector<MVT> VTs; |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 793 | VTs.push_back(MVT::i32); |
| 794 | VTs.push_back(MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 795 | SDValue Ops[2] = { LHS, RHS }; |
Dale Johannesen | 3484c09 | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 796 | CompareFlag = DAG.getNode(SPISD::CMPICC, dl, VTs, Ops, 2).getValue(1); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 797 | if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC); |
| 798 | Opc = SPISD::BRICC; |
| 799 | } else { |
Dale Johannesen | 3484c09 | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 800 | CompareFlag = DAG.getNode(SPISD::CMPFCC, dl, MVT::Flag, LHS, RHS); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 801 | if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC); |
| 802 | Opc = SPISD::BRFCC; |
| 803 | } |
Dale Johannesen | 3484c09 | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 804 | return DAG.getNode(Opc, dl, MVT::Other, Chain, Dest, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 805 | DAG.getConstant(SPCC, MVT::i32), CompareFlag); |
| 806 | } |
| 807 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 808 | static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) { |
| 809 | SDValue LHS = Op.getOperand(0); |
| 810 | SDValue RHS = Op.getOperand(1); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 811 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 812 | SDValue TrueVal = Op.getOperand(2); |
| 813 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | 3484c09 | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 814 | DebugLoc dl = Op.getDebugLoc(); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 815 | unsigned Opc, SPCC = ~0U; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 816 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 817 | // If this is a select_cc of a "setcc", and if the setcc got lowered into |
| 818 | // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values. |
| 819 | LookThroughSetCC(LHS, RHS, CC, SPCC); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 820 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 821 | SDValue CompareFlag; |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 822 | if (LHS.getValueType() == MVT::i32) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 823 | std::vector<MVT> VTs; |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 824 | VTs.push_back(LHS.getValueType()); // subcc returns a value |
| 825 | VTs.push_back(MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 826 | SDValue Ops[2] = { LHS, RHS }; |
Dale Johannesen | 3484c09 | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 827 | CompareFlag = DAG.getNode(SPISD::CMPICC, dl, VTs, Ops, 2).getValue(1); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 828 | Opc = SPISD::SELECT_ICC; |
| 829 | if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC); |
| 830 | } else { |
Dale Johannesen | 3484c09 | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 831 | CompareFlag = DAG.getNode(SPISD::CMPFCC, dl, MVT::Flag, LHS, RHS); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 832 | Opc = SPISD::SELECT_FCC; |
| 833 | if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC); |
| 834 | } |
Dale Johannesen | 3484c09 | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 835 | return DAG.getNode(Opc, dl, TrueVal.getValueType(), TrueVal, FalseVal, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 836 | DAG.getConstant(SPCC, MVT::i32), CompareFlag); |
| 837 | } |
| 838 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 839 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 840 | SparcTargetLowering &TLI) { |
| 841 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 842 | // memory location argument. |
Dale Johannesen | 6f38cb6 | 2009-02-07 19:59:05 +0000 | [diff] [blame] | 843 | DebugLoc dl = Op.getDebugLoc(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 844 | SDValue Offset = DAG.getNode(ISD::ADD, dl, MVT::i32, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 845 | DAG.getRegister(SP::I6, MVT::i32), |
| 846 | DAG.getConstant(TLI.getVarArgsFrameOffset(), |
| 847 | MVT::i32)); |
| 848 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 849 | return DAG.getStore(Op.getOperand(0), dl, Offset, Op.getOperand(1), SV, 0); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 852 | static SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 853 | SDNode *Node = Op.getNode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 854 | MVT VT = Node->getValueType(0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 855 | SDValue InChain = Node->getOperand(0); |
| 856 | SDValue VAListPtr = Node->getOperand(1); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 857 | const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 858 | DebugLoc dl = Node->getDebugLoc(); |
| 859 | SDValue VAList = DAG.getLoad(MVT::i32, dl, InChain, VAListPtr, SV, 0); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 860 | // Increment the pointer, VAList, to the next vaarg |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 861 | SDValue NextPtr = DAG.getNode(ISD::ADD, dl, MVT::i32, VAList, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 862 | DAG.getConstant(VT.getSizeInBits()/8, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 863 | MVT::i32)); |
| 864 | // Store the incremented VAList to the legalized pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 865 | InChain = DAG.getStore(VAList.getValue(1), dl, NextPtr, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 866 | VAListPtr, SV, 0); |
| 867 | // Load the actual argument out of the pointer VAList, unless this is an |
| 868 | // f64 load. |
| 869 | if (VT != MVT::f64) |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 870 | return DAG.getLoad(VT, dl, InChain, VAList, NULL, 0); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 871 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 872 | // Otherwise, load it as i64, then do a bitconvert. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 873 | SDValue V = DAG.getLoad(MVT::i64, dl, InChain, VAList, NULL, 0); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 874 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 875 | // Bit-Convert the value to f64. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 876 | SDValue Ops[2] = { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 877 | DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, V), |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 878 | V.getValue(1) |
| 879 | }; |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 880 | return DAG.getMergeValues(Ops, 2, dl); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 883 | static SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) { |
| 884 | SDValue Chain = Op.getOperand(0); // Legalize the chain. |
| 885 | SDValue Size = Op.getOperand(1); // Legalize the size. |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 886 | DebugLoc dl = Op.getDebugLoc(); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 887 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 888 | unsigned SPReg = SP::O6; |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 889 | SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, MVT::i32); |
| 890 | SDValue NewSP = DAG.getNode(ISD::SUB, dl, MVT::i32, SP, Size); // Value |
| 891 | Chain = DAG.getCopyToReg(SP.getValue(1), dl, SPReg, NewSP); // Output chain |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 892 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 893 | // The resultant pointer is actually 16 words from the bottom of the stack, |
| 894 | // to provide a register spill area. |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 895 | SDValue NewVal = DAG.getNode(ISD::ADD, dl, MVT::i32, NewSP, |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 896 | DAG.getConstant(96, MVT::i32)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 897 | SDValue Ops[2] = { NewVal, Chain }; |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 898 | return DAG.getMergeValues(Ops, 2, dl); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 901 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 902 | SDValue SparcTargetLowering:: |
| 903 | LowerOperation(SDValue Op, SelectionDAG &DAG) { |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 904 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 905 | default: llvm_unreachable("Should not custom lower this!"); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 906 | // Frame & Return address. Currently unimplemented |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 907 | case ISD::RETURNADDR: return SDValue(); |
| 908 | case ISD::FRAMEADDR: return SDValue(); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 909 | case ISD::GlobalTLSAddress: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 910 | llvm_unreachable("TLS not implemented for Sparc."); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 911 | case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG); |
| 912 | case ISD::ConstantPool: return LowerCONSTANTPOOL(Op, DAG); |
| 913 | case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG); |
| 914 | case ISD::SINT_TO_FP: return LowerSINT_TO_FP(Op, DAG); |
| 915 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
| 916 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 917 | case ISD::VASTART: return LowerVASTART(Op, DAG, *this); |
| 918 | case ISD::VAARG: return LowerVAARG(Op, DAG); |
| 919 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
Chris Lattner | 98949a6 | 2008-03-17 06:01:07 +0000 | [diff] [blame] | 920 | case ISD::CALL: return LowerCALL(Op, DAG); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 921 | case ISD::RET: return LowerRET(Op, DAG); |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | MachineBasicBlock * |
| 926 | SparcTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | 1fdbc1d | 2009-02-07 16:15:20 +0000 | [diff] [blame] | 927 | MachineBasicBlock *BB) const { |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 928 | const TargetInstrInfo &TII = *getTargetMachine().getInstrInfo(); |
| 929 | unsigned BROpcode; |
| 930 | unsigned CC; |
Dale Johannesen | d552eee | 2009-02-13 02:31:35 +0000 | [diff] [blame] | 931 | DebugLoc dl = MI->getDebugLoc(); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 932 | // Figure out the conditional branch opcode to use for this select_cc. |
| 933 | switch (MI->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame^] | 934 | default: llvm_unreachable("Unknown SELECT_CC!"); |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 935 | case SP::SELECT_CC_Int_ICC: |
| 936 | case SP::SELECT_CC_FP_ICC: |
| 937 | case SP::SELECT_CC_DFP_ICC: |
| 938 | BROpcode = SP::BCOND; |
| 939 | break; |
| 940 | case SP::SELECT_CC_Int_FCC: |
| 941 | case SP::SELECT_CC_FP_FCC: |
| 942 | case SP::SELECT_CC_DFP_FCC: |
| 943 | BROpcode = SP::FBCOND; |
| 944 | break; |
| 945 | } |
| 946 | |
| 947 | CC = (SPCC::CondCodes)MI->getOperand(3).getImm(); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 948 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 949 | // To "insert" a SELECT_CC instruction, we actually have to insert the diamond |
| 950 | // control-flow pattern. The incoming instruction knows the destination vreg |
| 951 | // to set, the condition code register to branch on, the true/false values to |
| 952 | // select between, and a branch opcode to use. |
| 953 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 954 | MachineFunction::iterator It = BB; |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 955 | ++It; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 956 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 957 | // thisMBB: |
| 958 | // ... |
| 959 | // TrueVal = ... |
| 960 | // [f]bCC copy1MBB |
| 961 | // fallthrough --> copy0MBB |
| 962 | MachineBasicBlock *thisMBB = BB; |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 963 | MachineFunction *F = BB->getParent(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 964 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 965 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dale Johannesen | d552eee | 2009-02-13 02:31:35 +0000 | [diff] [blame] | 966 | BuildMI(BB, dl, TII.get(BROpcode)).addMBB(sinkMBB).addImm(CC); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 967 | F->insert(It, copy0MBB); |
| 968 | F->insert(It, sinkMBB); |
Dan Gohman | 0011dc4 | 2008-06-21 20:21:19 +0000 | [diff] [blame] | 969 | // Update machine-CFG edges by transferring all successors of the current |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 970 | // block to the new block which will contain the Phi node for the select. |
Dan Gohman | 0011dc4 | 2008-06-21 20:21:19 +0000 | [diff] [blame] | 971 | sinkMBB->transferSuccessors(BB); |
| 972 | // Next, add the true and fallthrough blocks as its successors. |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 973 | BB->addSuccessor(copy0MBB); |
| 974 | BB->addSuccessor(sinkMBB); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 975 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 976 | // copy0MBB: |
| 977 | // %FalseValue = ... |
| 978 | // # fallthrough to sinkMBB |
| 979 | BB = copy0MBB; |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 980 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 981 | // Update machine-CFG edges |
| 982 | BB->addSuccessor(sinkMBB); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 983 | |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 984 | // sinkMBB: |
| 985 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 986 | // ... |
| 987 | BB = sinkMBB; |
Dale Johannesen | d552eee | 2009-02-13 02:31:35 +0000 | [diff] [blame] | 988 | BuildMI(BB, dl, TII.get(SP::PHI), MI->getOperand(0).getReg()) |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 989 | .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB) |
| 990 | .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB); |
Anton Korobeynikov | 5383570 | 2008-10-10 20:27:31 +0000 | [diff] [blame] | 991 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 992 | F->DeleteMachineInstr(MI); // The pseudo instruction is gone now. |
Chris Lattner | d23405e | 2008-03-17 03:21:36 +0000 | [diff] [blame] | 993 | return BB; |
| 994 | } |
Anton Korobeynikov | 0eefda1 | 2008-10-10 20:28:10 +0000 | [diff] [blame] | 995 | |
| 996 | //===----------------------------------------------------------------------===// |
| 997 | // Sparc Inline Assembly Support |
| 998 | //===----------------------------------------------------------------------===// |
| 999 | |
| 1000 | /// getConstraintType - Given a constraint letter, return the type of |
| 1001 | /// constraint it is for this target. |
| 1002 | SparcTargetLowering::ConstraintType |
| 1003 | SparcTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 1004 | if (Constraint.size() == 1) { |
| 1005 | switch (Constraint[0]) { |
| 1006 | default: break; |
| 1007 | case 'r': return C_RegisterClass; |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | return TargetLowering::getConstraintType(Constraint); |
| 1012 | } |
| 1013 | |
| 1014 | std::pair<unsigned, const TargetRegisterClass*> |
| 1015 | SparcTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
| 1016 | MVT VT) const { |
| 1017 | if (Constraint.size() == 1) { |
| 1018 | switch (Constraint[0]) { |
| 1019 | case 'r': |
| 1020 | return std::make_pair(0U, SP::IntRegsRegisterClass); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 1025 | } |
| 1026 | |
| 1027 | std::vector<unsigned> SparcTargetLowering:: |
| 1028 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
| 1029 | MVT VT) const { |
| 1030 | if (Constraint.size() != 1) |
| 1031 | return std::vector<unsigned>(); |
| 1032 | |
| 1033 | switch (Constraint[0]) { |
| 1034 | default: break; |
| 1035 | case 'r': |
| 1036 | return make_vector<unsigned>(SP::L0, SP::L1, SP::L2, SP::L3, |
| 1037 | SP::L4, SP::L5, SP::L6, SP::L7, |
| 1038 | SP::I0, SP::I1, SP::I2, SP::I3, |
| 1039 | SP::I4, SP::I5, |
| 1040 | SP::O0, SP::O1, SP::O2, SP::O3, |
| 1041 | SP::O4, SP::O5, SP::O7, 0); |
| 1042 | } |
| 1043 | |
| 1044 | return std::vector<unsigned>(); |
| 1045 | } |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 1046 | |
| 1047 | bool |
| 1048 | SparcTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 1049 | // The Sparc target isn't yet aware of offsets. |
| 1050 | return false; |
| 1051 | } |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 1052 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 1053 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 1054 | unsigned SparcTargetLowering::getFunctionAlignment(const Function *) const { |
| 1055 | return 4; |
| 1056 | } |