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