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