blob: 22936dd5e4fd218745eb9be2971417dee4af6801 [file] [log] [blame]
Anton Korobeynikov10138002009-05-03 12:57:15 +00001//===-- MSP430ISelLowering.cpp - MSP430 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 MSP430TargetLowering class.
11//
12//===----------------------------------------------------------------------===//
13
Anton Korobeynikov10138002009-05-03 12:57:15 +000014#include "MSP430ISelLowering.h"
15#include "MSP430.h"
Anton Korobeynikovff4ab512009-12-07 02:28:10 +000016#include "MSP430MachineFunctionInfo.h"
Anton Korobeynikov10138002009-05-03 12:57:15 +000017#include "MSP430Subtarget.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "MSP430TargetMachine.h"
Anton Korobeynikov10138002009-05-03 12:57:15 +000019#include "llvm/CodeGen/CallingConvLower.h"
20#include "llvm/CodeGen/MachineFrameInfo.h"
21#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
23#include "llvm/CodeGen/MachineRegisterInfo.h"
24#include "llvm/CodeGen/SelectionDAGISel.h"
Anton Korobeynikovab663a02010-02-15 22:37:53 +000025#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
Anton Korobeynikov10138002009-05-03 12:57:15 +000026#include "llvm/CodeGen/ValueTypes.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000027#include "llvm/IR/CallingConv.h"
28#include "llvm/IR/DerivedTypes.h"
29#include "llvm/IR/Function.h"
30#include "llvm/IR/GlobalAlias.h"
31#include "llvm/IR/GlobalVariable.h"
32#include "llvm/IR/Intrinsics.h"
Anton Korobeynikov28d3c732009-12-07 02:27:08 +000033#include "llvm/Support/CommandLine.h"
Anton Korobeynikov10138002009-05-03 12:57:15 +000034#include "llvm/Support/Debug.h"
Torok Edwinfa040022009-07-08 19:04:27 +000035#include "llvm/Support/ErrorHandling.h"
Chris Lattner317dbbc2009-08-23 07:05:07 +000036#include "llvm/Support/raw_ostream.h"
Anton Korobeynikov10138002009-05-03 12:57:15 +000037using namespace llvm;
38
Chandler Carruth84e68b22014-04-22 02:41:26 +000039#define DEBUG_TYPE "msp430-lower"
40
Anton Korobeynikov28d3c732009-12-07 02:27:08 +000041typedef enum {
42 NoHWMult,
43 HWMultIntr,
44 HWMultNoIntr
45} HWMultUseMode;
46
47static cl::opt<HWMultUseMode>
Nadav Rotem7f27e0b2013-10-18 23:38:13 +000048HWMultMode("msp430-hwmult-mode", cl::Hidden,
Anton Korobeynikov28d3c732009-12-07 02:27:08 +000049 cl::desc("Hardware multiplier use mode"),
50 cl::init(HWMultNoIntr),
51 cl::values(
52 clEnumValN(NoHWMult, "no",
53 "Do not use hardware multiplier"),
54 clEnumValN(HWMultIntr, "interrupts",
55 "Assume hardware multiplier can be used inside interrupts"),
56 clEnumValN(HWMultNoIntr, "use",
57 "Assume hardware multiplier cannot be used inside interrupts"),
58 clEnumValEnd));
59
Eric Christopherdc13b212014-06-27 00:37:59 +000060MSP430TargetLowering::MSP430TargetLowering(const TargetMachine &TM)
Aditya Nandakumar30531552014-11-13 21:29:21 +000061 : TargetLowering(TM) {
Anton Korobeynikovff4ab512009-12-07 02:28:10 +000062
Anton Korobeynikov10138002009-05-03 12:57:15 +000063 // Set up the register classes.
Craig Topperc7242e02012-04-20 07:30:17 +000064 addRegisterClass(MVT::i8, &MSP430::GR8RegClass);
65 addRegisterClass(MVT::i16, &MSP430::GR16RegClass);
Anton Korobeynikov10138002009-05-03 12:57:15 +000066
67 // Compute derived properties from the register classes
68 computeRegisterProperties();
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +000069
Anton Korobeynikov55a085b2009-05-03 13:03:14 +000070 // Provide all sorts of operation actions
71
72 // Division is expensive
73 setIntDivIsCheap(false);
74
Job Noormaneb19aea2014-09-10 06:58:14 +000075 setStackPointerRegisterToSaveRestore(MSP430::SP);
Anton Korobeynikov7212c152009-05-03 13:11:35 +000076 setBooleanContents(ZeroOrOneBooleanContent);
Duncan Sandsf2641e12011-09-06 19:07:46 +000077 setBooleanVectorContents(ZeroOrOneBooleanContent); // FIXME: Is this correct?
Anton Korobeynikov7212c152009-05-03 13:11:35 +000078
Anton Korobeynikovcf84ab52009-11-07 17:15:25 +000079 // We have post-incremented loads / stores.
Anton Korobeynikovd3c83192009-11-07 17:15:06 +000080 setIndexedLoadAction(ISD::POST_INC, MVT::i8, Legal);
81 setIndexedLoadAction(ISD::POST_INC, MVT::i16, Legal);
82
83 setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
84 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
85 setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
86 setLoadExtAction(ISD::SEXTLOAD, MVT::i8, Expand);
Owen Anderson9f944592009-08-11 20:47:22 +000087 setLoadExtAction(ISD::SEXTLOAD, MVT::i16, Expand);
Anton Korobeynikov31ecd232009-05-03 13:06:03 +000088
Anton Korobeynikoved1c3df2009-05-03 13:06:26 +000089 // We don't have any truncstores
Owen Anderson9f944592009-08-11 20:47:22 +000090 setTruncStoreAction(MVT::i16, MVT::i8, Expand);
Anton Korobeynikoved1c3df2009-05-03 13:06:26 +000091
Owen Anderson9f944592009-08-11 20:47:22 +000092 setOperationAction(ISD::SRA, MVT::i8, Custom);
93 setOperationAction(ISD::SHL, MVT::i8, Custom);
94 setOperationAction(ISD::SRL, MVT::i8, Custom);
95 setOperationAction(ISD::SRA, MVT::i16, Custom);
96 setOperationAction(ISD::SHL, MVT::i16, Custom);
97 setOperationAction(ISD::SRL, MVT::i16, Custom);
98 setOperationAction(ISD::ROTL, MVT::i8, Expand);
99 setOperationAction(ISD::ROTR, MVT::i8, Expand);
100 setOperationAction(ISD::ROTL, MVT::i16, Expand);
101 setOperationAction(ISD::ROTR, MVT::i16, Expand);
102 setOperationAction(ISD::GlobalAddress, MVT::i16, Custom);
103 setOperationAction(ISD::ExternalSymbol, MVT::i16, Custom);
Anton Korobeynikovebbdfef2010-05-01 12:04:32 +0000104 setOperationAction(ISD::BlockAddress, MVT::i16, Custom);
Owen Anderson9f944592009-08-11 20:47:22 +0000105 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
Owen Anderson9f944592009-08-11 20:47:22 +0000106 setOperationAction(ISD::BR_CC, MVT::i8, Custom);
107 setOperationAction(ISD::BR_CC, MVT::i16, Custom);
108 setOperationAction(ISD::BRCOND, MVT::Other, Expand);
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000109 setOperationAction(ISD::SETCC, MVT::i8, Custom);
110 setOperationAction(ISD::SETCC, MVT::i16, Custom);
Owen Anderson9f944592009-08-11 20:47:22 +0000111 setOperationAction(ISD::SELECT, MVT::i8, Expand);
112 setOperationAction(ISD::SELECT, MVT::i16, Expand);
113 setOperationAction(ISD::SELECT_CC, MVT::i8, Custom);
114 setOperationAction(ISD::SELECT_CC, MVT::i16, Custom);
115 setOperationAction(ISD::SIGN_EXTEND, MVT::i16, Custom);
Anton Korobeynikov271cdda2009-08-25 17:00:23 +0000116 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i8, Expand);
117 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i16, Expand);
Anton Korobeynikovde60d1c2009-05-03 13:14:25 +0000118
Owen Anderson9f944592009-08-11 20:47:22 +0000119 setOperationAction(ISD::CTTZ, MVT::i8, Expand);
120 setOperationAction(ISD::CTTZ, MVT::i16, Expand);
Chandler Carruth637cc6a2011-12-13 01:56:10 +0000121 setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i8, Expand);
122 setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i16, Expand);
Owen Anderson9f944592009-08-11 20:47:22 +0000123 setOperationAction(ISD::CTLZ, MVT::i8, Expand);
124 setOperationAction(ISD::CTLZ, MVT::i16, Expand);
Chandler Carruth637cc6a2011-12-13 01:56:10 +0000125 setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i8, Expand);
126 setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i16, Expand);
Owen Anderson9f944592009-08-11 20:47:22 +0000127 setOperationAction(ISD::CTPOP, MVT::i8, Expand);
128 setOperationAction(ISD::CTPOP, MVT::i16, Expand);
Eli Friedman6a60a66b2009-07-17 07:28:06 +0000129
Owen Anderson9f944592009-08-11 20:47:22 +0000130 setOperationAction(ISD::SHL_PARTS, MVT::i8, Expand);
131 setOperationAction(ISD::SHL_PARTS, MVT::i16, Expand);
132 setOperationAction(ISD::SRL_PARTS, MVT::i8, Expand);
133 setOperationAction(ISD::SRL_PARTS, MVT::i16, Expand);
134 setOperationAction(ISD::SRA_PARTS, MVT::i8, Expand);
135 setOperationAction(ISD::SRA_PARTS, MVT::i16, Expand);
Eli Friedman6a60a66b2009-07-17 07:28:06 +0000136
Owen Anderson9f944592009-08-11 20:47:22 +0000137 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
Eli Friedman6a60a66b2009-07-17 07:28:06 +0000138
Anton Korobeynikovde60d1c2009-05-03 13:14:25 +0000139 // FIXME: Implement efficiently multiplication by a constant
Anton Korobeynikovf93bb392009-11-07 17:14:39 +0000140 setOperationAction(ISD::MUL, MVT::i8, Expand);
141 setOperationAction(ISD::MULHS, MVT::i8, Expand);
142 setOperationAction(ISD::MULHU, MVT::i8, Expand);
143 setOperationAction(ISD::SMUL_LOHI, MVT::i8, Expand);
144 setOperationAction(ISD::UMUL_LOHI, MVT::i8, Expand);
Owen Anderson9f944592009-08-11 20:47:22 +0000145 setOperationAction(ISD::MUL, MVT::i16, Expand);
146 setOperationAction(ISD::MULHS, MVT::i16, Expand);
147 setOperationAction(ISD::MULHU, MVT::i16, Expand);
148 setOperationAction(ISD::SMUL_LOHI, MVT::i16, Expand);
149 setOperationAction(ISD::UMUL_LOHI, MVT::i16, Expand);
Anton Korobeynikoveb2152f2009-05-03 13:18:33 +0000150
Anton Korobeynikovf93bb392009-11-07 17:14:39 +0000151 setOperationAction(ISD::UDIV, MVT::i8, Expand);
152 setOperationAction(ISD::UDIVREM, MVT::i8, Expand);
153 setOperationAction(ISD::UREM, MVT::i8, Expand);
154 setOperationAction(ISD::SDIV, MVT::i8, Expand);
155 setOperationAction(ISD::SDIVREM, MVT::i8, Expand);
156 setOperationAction(ISD::SREM, MVT::i8, Expand);
Owen Anderson9f944592009-08-11 20:47:22 +0000157 setOperationAction(ISD::UDIV, MVT::i16, Expand);
158 setOperationAction(ISD::UDIVREM, MVT::i16, Expand);
159 setOperationAction(ISD::UREM, MVT::i16, Expand);
160 setOperationAction(ISD::SDIV, MVT::i16, Expand);
161 setOperationAction(ISD::SDIVREM, MVT::i16, Expand);
162 setOperationAction(ISD::SREM, MVT::i16, Expand);
Anton Korobeynikov28d3c732009-12-07 02:27:08 +0000163
Anton Korobeynikov568afeb2012-11-21 17:28:27 +0000164 // varargs support
165 setOperationAction(ISD::VASTART, MVT::Other, Custom);
166 setOperationAction(ISD::VAARG, MVT::Other, Expand);
167 setOperationAction(ISD::VAEND, MVT::Other, Expand);
168 setOperationAction(ISD::VACOPY, MVT::Other, Expand);
Anton Korobeynikov82bedb12013-07-01 19:44:44 +0000169 setOperationAction(ISD::JumpTable, MVT::i16, Custom);
Anton Korobeynikov568afeb2012-11-21 17:28:27 +0000170
Anton Korobeynikov28d3c732009-12-07 02:27:08 +0000171 // Libcalls names.
172 if (HWMultMode == HWMultIntr) {
173 setLibcallName(RTLIB::MUL_I8, "__mulqi3hw");
174 setLibcallName(RTLIB::MUL_I16, "__mulhi3hw");
175 } else if (HWMultMode == HWMultNoIntr) {
176 setLibcallName(RTLIB::MUL_I8, "__mulqi3hw_noint");
177 setLibcallName(RTLIB::MUL_I16, "__mulhi3hw_noint");
178 }
Eli Friedman2518f832011-05-06 20:34:06 +0000179
180 setMinFunctionAlignment(1);
181 setPrefFunctionAlignment(2);
Anton Korobeynikov10138002009-05-03 12:57:15 +0000182}
183
Dan Gohman21cea8a2010-04-17 15:26:15 +0000184SDValue MSP430TargetLowering::LowerOperation(SDValue Op,
185 SelectionDAG &DAG) const {
Anton Korobeynikov10138002009-05-03 12:57:15 +0000186 switch (Op.getOpcode()) {
Anton Korobeynikova3f7a832009-05-03 13:13:17 +0000187 case ISD::SHL: // FALLTHROUGH
Anton Korobeynikov61763b52009-05-03 13:16:17 +0000188 case ISD::SRL:
Anton Korobeynikov56135102009-05-03 13:07:31 +0000189 case ISD::SRA: return LowerShifts(Op, DAG);
Anton Korobeynikovcfc97052009-05-03 13:08:33 +0000190 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
Anton Korobeynikovebbdfef2010-05-01 12:04:32 +0000191 case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
Anton Korobeynikovba0e81d2009-05-03 13:14:46 +0000192 case ISD::ExternalSymbol: return LowerExternalSymbol(Op, DAG);
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000193 case ISD::SETCC: return LowerSETCC(Op, DAG);
Anton Korobeynikov47fcd722009-05-03 13:19:09 +0000194 case ISD::BR_CC: return LowerBR_CC(Op, DAG);
195 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
Anton Korobeynikov29747e92009-05-03 13:17:49 +0000196 case ISD::SIGN_EXTEND: return LowerSIGN_EXTEND(Op, DAG);
Anton Korobeynikovff4ab512009-12-07 02:28:10 +0000197 case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG);
198 case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
Anton Korobeynikov568afeb2012-11-21 17:28:27 +0000199 case ISD::VASTART: return LowerVASTART(Op, DAG);
Anton Korobeynikov82bedb12013-07-01 19:44:44 +0000200 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
Anton Korobeynikov10138002009-05-03 12:57:15 +0000201 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000202 llvm_unreachable("unimplemented operand");
Anton Korobeynikov10138002009-05-03 12:57:15 +0000203 }
204}
205
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000206//===----------------------------------------------------------------------===//
Anton Korobeynikova0e01be2009-08-26 13:44:29 +0000207// MSP430 Inline Assembly Support
208//===----------------------------------------------------------------------===//
209
210/// getConstraintType - Given a constraint letter, return the type of
211/// constraint it is for this target.
212TargetLowering::ConstraintType
213MSP430TargetLowering::getConstraintType(const std::string &Constraint) const {
214 if (Constraint.size() == 1) {
215 switch (Constraint[0]) {
216 case 'r':
217 return C_RegisterClass;
218 default:
219 break;
220 }
221 }
222 return TargetLowering::getConstraintType(Constraint);
223}
224
225std::pair<unsigned, const TargetRegisterClass*>
226MSP430TargetLowering::
227getRegForInlineAsmConstraint(const std::string &Constraint,
Chad Rosier295bd432013-06-22 18:37:38 +0000228 MVT VT) const {
Anton Korobeynikova0e01be2009-08-26 13:44:29 +0000229 if (Constraint.size() == 1) {
230 // GCC Constraint Letters
231 switch (Constraint[0]) {
232 default: break;
233 case 'r': // GENERAL_REGS
234 if (VT == MVT::i8)
Craig Topperc7242e02012-04-20 07:30:17 +0000235 return std::make_pair(0U, &MSP430::GR8RegClass);
Anton Korobeynikova0e01be2009-08-26 13:44:29 +0000236
Craig Topperc7242e02012-04-20 07:30:17 +0000237 return std::make_pair(0U, &MSP430::GR16RegClass);
Anton Korobeynikova0e01be2009-08-26 13:44:29 +0000238 }
239 }
240
241 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
242}
243
244//===----------------------------------------------------------------------===//
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000245// Calling Convention Implementation
246//===----------------------------------------------------------------------===//
247
Anton Korobeynikov10138002009-05-03 12:57:15 +0000248#include "MSP430GenCallingConv.inc"
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000249
Job Noormane9a1d4c2013-10-15 08:19:39 +0000250/// For each argument in a function store the number of pieces it is composed
251/// of.
252template<typename ArgT>
253static void ParseFunctionArgs(const SmallVectorImpl<ArgT> &Args,
254 SmallVectorImpl<unsigned> &Out) {
255 unsigned CurrentArgIndex = ~0U;
256 for (unsigned i = 0, e = Args.size(); i != e; i++) {
257 if (CurrentArgIndex == Args[i].OrigArgIndex) {
258 Out.back()++;
259 } else {
260 Out.push_back(1);
261 CurrentArgIndex++;
262 }
263 }
264}
265
266static void AnalyzeVarArgs(CCState &State,
267 const SmallVectorImpl<ISD::OutputArg> &Outs) {
268 State.AnalyzeCallOperands(Outs, CC_MSP430_AssignStack);
269}
270
271static void AnalyzeVarArgs(CCState &State,
272 const SmallVectorImpl<ISD::InputArg> &Ins) {
273 State.AnalyzeFormalArguments(Ins, CC_MSP430_AssignStack);
274}
275
276/// Analyze incoming and outgoing function arguments. We need custom C++ code
277/// to handle special constraints in the ABI like reversing the order of the
278/// pieces of splitted arguments. In addition, all pieces of a certain argument
279/// have to be passed either using registers or the stack but never mixing both.
280template<typename ArgT>
281static void AnalyzeArguments(CCState &State,
282 SmallVectorImpl<CCValAssign> &ArgLocs,
283 const SmallVectorImpl<ArgT> &Args) {
Craig Topper840beec2014-04-04 05:16:06 +0000284 static const MCPhysReg RegList[] = {
Job Noormaneb19aea2014-09-10 06:58:14 +0000285 MSP430::R15, MSP430::R14, MSP430::R13, MSP430::R12
Job Noormane9a1d4c2013-10-15 08:19:39 +0000286 };
287 static const unsigned NbRegs = array_lengthof(RegList);
288
289 if (State.isVarArg()) {
290 AnalyzeVarArgs(State, Args);
291 return;
292 }
293
294 SmallVector<unsigned, 4> ArgsParts;
295 ParseFunctionArgs(Args, ArgsParts);
296
297 unsigned RegsLeft = NbRegs;
298 bool UseStack = false;
299 unsigned ValNo = 0;
300
301 for (unsigned i = 0, e = ArgsParts.size(); i != e; i++) {
302 MVT ArgVT = Args[ValNo].VT;
303 ISD::ArgFlagsTy ArgFlags = Args[ValNo].Flags;
304 MVT LocVT = ArgVT;
305 CCValAssign::LocInfo LocInfo = CCValAssign::Full;
306
307 // Promote i8 to i16
308 if (LocVT == MVT::i8) {
309 LocVT = MVT::i16;
310 if (ArgFlags.isSExt())
311 LocInfo = CCValAssign::SExt;
312 else if (ArgFlags.isZExt())
313 LocInfo = CCValAssign::ZExt;
314 else
315 LocInfo = CCValAssign::AExt;
316 }
317
318 // Handle byval arguments
319 if (ArgFlags.isByVal()) {
320 State.HandleByVal(ValNo++, ArgVT, LocVT, LocInfo, 2, 2, ArgFlags);
321 continue;
322 }
323
324 unsigned Parts = ArgsParts[i];
325
326 if (!UseStack && Parts <= RegsLeft) {
327 unsigned FirstVal = ValNo;
328 for (unsigned j = 0; j < Parts; j++) {
329 unsigned Reg = State.AllocateReg(RegList, NbRegs);
330 State.addLoc(CCValAssign::getReg(ValNo++, ArgVT, Reg, LocVT, LocInfo));
331 RegsLeft--;
332 }
333
334 // Reverse the order of the pieces to agree with the "big endian" format
335 // required in the calling convention ABI.
336 SmallVectorImpl<CCValAssign>::iterator B = ArgLocs.begin() + FirstVal;
337 std::reverse(B, B + Parts);
338 } else {
339 UseStack = true;
340 for (unsigned j = 0; j < Parts; j++)
341 CC_MSP430_AssignStack(ValNo++, ArgVT, LocVT, LocInfo, ArgFlags, State);
342 }
343 }
344}
345
346static void AnalyzeRetResult(CCState &State,
347 const SmallVectorImpl<ISD::InputArg> &Ins) {
348 State.AnalyzeCallResult(Ins, RetCC_MSP430);
349}
350
351static void AnalyzeRetResult(CCState &State,
352 const SmallVectorImpl<ISD::OutputArg> &Outs) {
353 State.AnalyzeReturn(Outs, RetCC_MSP430);
354}
355
356template<typename ArgT>
357static void AnalyzeReturnValues(CCState &State,
358 SmallVectorImpl<CCValAssign> &RVLocs,
359 const SmallVectorImpl<ArgT> &Args) {
360 AnalyzeRetResult(State, Args);
361
362 // Reverse splitted return values to get the "big endian" format required
363 // to agree with the calling convention ABI.
364 std::reverse(RVLocs.begin(), RVLocs.end());
365}
366
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000367SDValue
368MSP430TargetLowering::LowerFormalArguments(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000369 CallingConv::ID CallConv,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000370 bool isVarArg,
371 const SmallVectorImpl<ISD::InputArg>
372 &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000373 SDLoc dl,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000374 SelectionDAG &DAG,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000375 SmallVectorImpl<SDValue> &InVals)
376 const {
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000377
378 switch (CallConv) {
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000379 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000380 llvm_unreachable("Unsupported calling convention");
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000381 case CallingConv::C:
382 case CallingConv::Fast:
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000383 return LowerCCCArguments(Chain, CallConv, isVarArg, Ins, dl, DAG, InVals);
Anton Korobeynikovb4be8ce2009-12-07 02:27:53 +0000384 case CallingConv::MSP430_INTR:
David Blaikie46a9f012012-01-20 21:51:11 +0000385 if (Ins.empty())
386 return Chain;
Chris Lattner2104b8d2010-04-07 22:58:41 +0000387 report_fatal_error("ISRs cannot have arguments");
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000388 }
389}
390
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000391SDValue
Justin Holewinskiaa583972012-05-25 16:35:28 +0000392MSP430TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000393 SmallVectorImpl<SDValue> &InVals) const {
Justin Holewinskiaa583972012-05-25 16:35:28 +0000394 SelectionDAG &DAG = CLI.DAG;
Andrew Trickef9de2a2013-05-25 02:42:55 +0000395 SDLoc &dl = CLI.DL;
Craig Topperb94011f2013-07-14 04:42:23 +0000396 SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs;
397 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
398 SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins;
Justin Holewinskiaa583972012-05-25 16:35:28 +0000399 SDValue Chain = CLI.Chain;
400 SDValue Callee = CLI.Callee;
401 bool &isTailCall = CLI.IsTailCall;
402 CallingConv::ID CallConv = CLI.CallConv;
403 bool isVarArg = CLI.IsVarArg;
404
Evan Cheng67a69dd2010-01-27 00:07:07 +0000405 // MSP430 target does not yet support tail call optimization.
406 isTailCall = false;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000407
408 switch (CallConv) {
Anton Korobeynikov56135102009-05-03 13:07:31 +0000409 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000410 llvm_unreachable("Unsupported calling convention");
Anton Korobeynikov56135102009-05-03 13:07:31 +0000411 case CallingConv::Fast:
412 case CallingConv::C:
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000413 return LowerCCCCallTo(Chain, Callee, CallConv, isVarArg, isTailCall,
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000414 Outs, OutVals, Ins, dl, DAG, InVals);
Anton Korobeynikovb4be8ce2009-12-07 02:27:53 +0000415 case CallingConv::MSP430_INTR:
Chris Lattner2104b8d2010-04-07 22:58:41 +0000416 report_fatal_error("ISRs cannot be called directly");
Anton Korobeynikov56135102009-05-03 13:07:31 +0000417 }
418}
419
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000420/// LowerCCCArguments - transform physical registers into virtual registers and
421/// generate load operations for arguments places on the stack.
422// FIXME: struct return stuff
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000423SDValue
424MSP430TargetLowering::LowerCCCArguments(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000425 CallingConv::ID CallConv,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000426 bool isVarArg,
427 const SmallVectorImpl<ISD::InputArg>
428 &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000429 SDLoc dl,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000430 SelectionDAG &DAG,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000431 SmallVectorImpl<SDValue> &InVals)
432 const {
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000433 MachineFunction &MF = DAG.getMachineFunction();
434 MachineFrameInfo *MFI = MF.getFrameInfo();
435 MachineRegisterInfo &RegInfo = MF.getRegInfo();
Anton Korobeynikov568afeb2012-11-21 17:28:27 +0000436 MSP430MachineFunctionInfo *FuncInfo = MF.getInfo<MSP430MachineFunctionInfo>();
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000437
438 // Assign locations to all of the incoming arguments.
439 SmallVector<CCValAssign, 16> ArgLocs;
Eric Christopherb5217502014-08-06 18:45:26 +0000440 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
441 *DAG.getContext());
Job Noormane9a1d4c2013-10-15 08:19:39 +0000442 AnalyzeArguments(CCInfo, ArgLocs, Ins);
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000443
Anton Korobeynikov568afeb2012-11-21 17:28:27 +0000444 // Create frame index for the start of the first vararg value
445 if (isVarArg) {
446 unsigned Offset = CCInfo.getNextStackOffset();
447 FuncInfo->setVarArgsFrameIndex(MFI->CreateFixedObject(1, Offset, true));
448 }
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000449
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000450 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
451 CCValAssign &VA = ArgLocs[i];
452 if (VA.isRegLoc()) {
453 // Arguments passed in registers
Owen Anderson53aa7a92009-08-10 22:56:29 +0000454 EVT RegVT = VA.getLocVT();
Owen Anderson9f944592009-08-11 20:47:22 +0000455 switch (RegVT.getSimpleVT().SimpleTy) {
Owen Andersonb2c80da2011-02-25 21:41:48 +0000456 default:
Torok Edwinfa040022009-07-08 19:04:27 +0000457 {
Torok Edwinfb8d6d52009-07-08 20:53:28 +0000458#ifndef NDEBUG
Chris Lattner317dbbc2009-08-23 07:05:07 +0000459 errs() << "LowerFormalArguments Unhandled argument type: "
Owen Anderson9f944592009-08-11 20:47:22 +0000460 << RegVT.getSimpleVT().SimpleTy << "\n";
Torok Edwinfb8d6d52009-07-08 20:53:28 +0000461#endif
Craig Toppere73658d2014-04-28 04:05:08 +0000462 llvm_unreachable(nullptr);
Torok Edwinfa040022009-07-08 19:04:27 +0000463 }
Owen Anderson9f944592009-08-11 20:47:22 +0000464 case MVT::i16:
Craig Topperc7242e02012-04-20 07:30:17 +0000465 unsigned VReg = RegInfo.createVirtualRegister(&MSP430::GR16RegClass);
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000466 RegInfo.addLiveIn(VA.getLocReg(), VReg);
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000467 SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, VReg, RegVT);
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000468
469 // If this is an 8-bit value, it is really passed promoted to 16
470 // bits. Insert an assert[sz]ext to capture this, then truncate to the
471 // right size.
472 if (VA.getLocInfo() == CCValAssign::SExt)
473 ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue,
474 DAG.getValueType(VA.getValVT()));
475 else if (VA.getLocInfo() == CCValAssign::ZExt)
476 ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue,
477 DAG.getValueType(VA.getValVT()));
478
479 if (VA.getLocInfo() != CCValAssign::Full)
480 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
481
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000482 InVals.push_back(ArgValue);
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000483 }
484 } else {
485 // Sanity check
486 assert(VA.isMemLoc());
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000487
Anton Korobeynikov34148722012-11-21 17:23:03 +0000488 SDValue InVal;
489 ISD::ArgFlagsTy Flags = Ins[i].Flags;
490
491 if (Flags.isByVal()) {
492 int FI = MFI->CreateFixedObject(Flags.getByValSize(),
493 VA.getLocMemOffset(), true);
494 InVal = DAG.getFrameIndex(FI, getPointerTy());
495 } else {
496 // Load the argument to a virtual register
497 unsigned ObjSize = VA.getLocVT().getSizeInBits()/8;
498 if (ObjSize > 2) {
499 errs() << "LowerFormalArguments Unhandled argument type: "
500 << EVT(VA.getLocVT()).getEVTString()
501 << "\n";
502 }
503 // Create the frame index object for this incoming parameter...
504 int FI = MFI->CreateFixedObject(ObjSize, VA.getLocMemOffset(), true);
505
506 // Create the SelectionDAG nodes corresponding to a load
507 //from this parameter
508 SDValue FIN = DAG.getFrameIndex(FI, MVT::i16);
509 InVal = DAG.getLoad(VA.getLocVT(), dl, Chain, FIN,
510 MachinePointerInfo::getFixedStack(FI),
511 false, false, false, 0);
512 }
513
514 InVals.push_back(InVal);
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000515 }
516 }
517
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000518 return Chain;
Anton Korobeynikov3849be62009-05-03 12:59:33 +0000519}
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000520
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000521SDValue
522MSP430TargetLowering::LowerReturn(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000523 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000524 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000525 const SmallVectorImpl<SDValue> &OutVals,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000526 SDLoc dl, SelectionDAG &DAG) const {
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000527
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000528 // CCValAssign - represent the assignment of the return value to a location
529 SmallVector<CCValAssign, 16> RVLocs;
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000530
Anton Korobeynikovb4be8ce2009-12-07 02:27:53 +0000531 // ISRs cannot return any value.
David Blaikie46a9f012012-01-20 21:51:11 +0000532 if (CallConv == CallingConv::MSP430_INTR && !Outs.empty())
Chris Lattner2104b8d2010-04-07 22:58:41 +0000533 report_fatal_error("ISRs cannot return any value");
Anton Korobeynikovb4be8ce2009-12-07 02:27:53 +0000534
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000535 // CCState - Info about the registers and stack slot.
Eric Christopherb5217502014-08-06 18:45:26 +0000536 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
537 *DAG.getContext());
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000538
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000539 // Analize return values.
Job Noormane9a1d4c2013-10-15 08:19:39 +0000540 AnalyzeReturnValues(CCInfo, RVLocs, Outs);
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000541
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000542 SDValue Flag;
Jakob Stoklund Olesenb52a3ec2013-02-05 18:12:06 +0000543 SmallVector<SDValue, 4> RetOps(1, Chain);
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000544
545 // Copy the result values into the output registers.
546 for (unsigned i = 0; i != RVLocs.size(); ++i) {
547 CCValAssign &VA = RVLocs[i];
548 assert(VA.isRegLoc() && "Can only return in registers!");
549
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000550 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(),
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000551 OutVals[i], Flag);
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000552
Anton Korobeynikovc10f98a2009-05-03 13:00:11 +0000553 // Guarantee that all emitted copies are stuck together,
554 // avoiding something bad.
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000555 Flag = Chain.getValue(1);
Jakob Stoklund Olesenb52a3ec2013-02-05 18:12:06 +0000556 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000557 }
558
Anton Korobeynikovb4be8ce2009-12-07 02:27:53 +0000559 unsigned Opc = (CallConv == CallingConv::MSP430_INTR ?
560 MSP430ISD::RETI_FLAG : MSP430ISD::RET_FLAG);
561
Jakob Stoklund Olesenb52a3ec2013-02-05 18:12:06 +0000562 RetOps[0] = Chain; // Update chain.
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000563
Jakob Stoklund Olesenb52a3ec2013-02-05 18:12:06 +0000564 // Add the flag if we have it.
565 if (Flag.getNode())
566 RetOps.push_back(Flag);
567
Craig Topper48d114b2014-04-26 18:35:24 +0000568 return DAG.getNode(Opc, dl, MVT::Other, RetOps);
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +0000569}
570
Anton Korobeynikov56135102009-05-03 13:07:31 +0000571/// LowerCCCCallTo - functions arguments are copied from virtual regs to
572/// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
Job Noormana928e1d2013-07-15 14:25:26 +0000573// TODO: sret.
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000574SDValue
575MSP430TargetLowering::LowerCCCCallTo(SDValue Chain, SDValue Callee,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000576 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000577 bool isTailCall,
578 const SmallVectorImpl<ISD::OutputArg>
579 &Outs,
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000580 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000581 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000582 SDLoc dl, SelectionDAG &DAG,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000583 SmallVectorImpl<SDValue> &InVals) const {
Anton Korobeynikov56135102009-05-03 13:07:31 +0000584 // Analyze operands of the call, assigning locations to each operand.
585 SmallVector<CCValAssign, 16> ArgLocs;
Eric Christopherb5217502014-08-06 18:45:26 +0000586 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
587 *DAG.getContext());
Job Noormane9a1d4c2013-10-15 08:19:39 +0000588 AnalyzeArguments(CCInfo, ArgLocs, Outs);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000589
590 // Get a count of how many bytes are to be pushed on the stack.
591 unsigned NumBytes = CCInfo.getNextStackOffset();
592
593 Chain = DAG.getCALLSEQ_START(Chain ,DAG.getConstant(NumBytes,
Andrew Trickad6d08a2013-05-29 22:03:55 +0000594 getPointerTy(), true),
595 dl);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000596
597 SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
598 SmallVector<SDValue, 12> MemOpChains;
599 SDValue StackPtr;
600
601 // Walk the register/memloc assignments, inserting copies/loads.
602 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
603 CCValAssign &VA = ArgLocs[i];
604
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000605 SDValue Arg = OutVals[i];
Anton Korobeynikov56135102009-05-03 13:07:31 +0000606
607 // Promote the value if needed.
608 switch (VA.getLocInfo()) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000609 default: llvm_unreachable("Unknown loc info!");
Anton Korobeynikov56135102009-05-03 13:07:31 +0000610 case CCValAssign::Full: break;
611 case CCValAssign::SExt:
612 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
613 break;
614 case CCValAssign::ZExt:
615 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
616 break;
617 case CCValAssign::AExt:
618 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
619 break;
620 }
621
622 // Arguments that can be passed on register must be kept at RegsToPass
623 // vector
624 if (VA.isRegLoc()) {
625 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
626 } else {
627 assert(VA.isMemLoc());
628
Craig Topper062a2ba2014-04-25 05:30:21 +0000629 if (!StackPtr.getNode())
Job Noormaneb19aea2014-09-10 06:58:14 +0000630 StackPtr = DAG.getCopyFromReg(Chain, dl, MSP430::SP, getPointerTy());
Anton Korobeynikov56135102009-05-03 13:07:31 +0000631
632 SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(),
633 StackPtr,
634 DAG.getIntPtrConstant(VA.getLocMemOffset()));
635
Anton Korobeynikov34148722012-11-21 17:23:03 +0000636 SDValue MemOp;
637 ISD::ArgFlagsTy Flags = Outs[i].Flags;
Anton Korobeynikov56135102009-05-03 13:07:31 +0000638
Anton Korobeynikov34148722012-11-21 17:23:03 +0000639 if (Flags.isByVal()) {
640 SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i16);
641 MemOp = DAG.getMemcpy(Chain, dl, PtrOff, Arg, SizeNode,
642 Flags.getByValAlign(),
643 /*isVolatile*/false,
644 /*AlwaysInline=*/true,
645 MachinePointerInfo(),
646 MachinePointerInfo());
647 } else {
648 MemOp = DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo(),
649 false, false, 0);
650 }
651
652 MemOpChains.push_back(MemOp);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000653 }
654 }
655
656 // Transform all store nodes into one single node because all store nodes are
657 // independent of each other.
658 if (!MemOpChains.empty())
Craig Topper48d114b2014-04-26 18:35:24 +0000659 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000660
661 // Build a sequence of copy-to-reg nodes chained together with token chain and
662 // flag operands which copy the outgoing args into registers. The InFlag in
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000663 // necessary since all emitted instructions must be stuck together.
Anton Korobeynikov56135102009-05-03 13:07:31 +0000664 SDValue InFlag;
665 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
666 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
667 RegsToPass[i].second, InFlag);
668 InFlag = Chain.getValue(1);
669 }
670
671 // If the callee is a GlobalAddress node (quite common, every direct call is)
672 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
673 // Likewise ExternalSymbol -> TargetExternalSymbol.
674 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
Devang Patela3ca21b2010-07-06 22:08:15 +0000675 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i16);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000676 else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
Owen Anderson9f944592009-08-11 20:47:22 +0000677 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i16);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000678
679 // Returns a chain & a flag for retval copy to use.
Chris Lattner3e5fbd72010-12-21 02:38:05 +0000680 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000681 SmallVector<SDValue, 8> Ops;
682 Ops.push_back(Chain);
683 Ops.push_back(Callee);
684
685 // Add argument registers to the end of the list so that they are
686 // known live into the call.
687 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
688 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
689 RegsToPass[i].second.getValueType()));
690
691 if (InFlag.getNode())
692 Ops.push_back(InFlag);
693
Craig Topper48d114b2014-04-26 18:35:24 +0000694 Chain = DAG.getNode(MSP430ISD::CALL, dl, NodeTys, Ops);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000695 InFlag = Chain.getValue(1);
696
697 // Create the CALLSEQ_END node.
698 Chain = DAG.getCALLSEQ_END(Chain,
699 DAG.getConstant(NumBytes, getPointerTy(), true),
700 DAG.getConstant(0, getPointerTy(), true),
Andrew Trickad6d08a2013-05-29 22:03:55 +0000701 InFlag, dl);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000702 InFlag = Chain.getValue(1);
703
704 // Handle result values, copying them out of physregs into vregs that we
705 // return.
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000706 return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, dl,
707 DAG, InVals);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000708}
709
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000710/// LowerCallResult - Lower the result values of a call into the
711/// appropriate copies out of appropriate physical registers.
712///
713SDValue
Anton Korobeynikov56135102009-05-03 13:07:31 +0000714MSP430TargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000715 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000716 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000717 SDLoc dl, SelectionDAG &DAG,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000718 SmallVectorImpl<SDValue> &InVals) const {
Anton Korobeynikov56135102009-05-03 13:07:31 +0000719
720 // Assign locations to each value returned by this call.
721 SmallVector<CCValAssign, 16> RVLocs;
Eric Christopherb5217502014-08-06 18:45:26 +0000722 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
723 *DAG.getContext());
Anton Korobeynikov56135102009-05-03 13:07:31 +0000724
Job Noormane9a1d4c2013-10-15 08:19:39 +0000725 AnalyzeReturnValues(CCInfo, RVLocs, Ins);
Anton Korobeynikov56135102009-05-03 13:07:31 +0000726
727 // Copy all of the result registers out of their specified physreg.
728 for (unsigned i = 0; i != RVLocs.size(); ++i) {
729 Chain = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
730 RVLocs[i].getValVT(), InFlag).getValue(1);
731 InFlag = Chain.getValue(2);
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000732 InVals.push_back(Chain.getValue(0));
Anton Korobeynikov56135102009-05-03 13:07:31 +0000733 }
734
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000735 return Chain;
Anton Korobeynikov56135102009-05-03 13:07:31 +0000736}
737
Anton Korobeynikov15a515b2009-05-03 13:03:33 +0000738SDValue MSP430TargetLowering::LowerShifts(SDValue Op,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000739 SelectionDAG &DAG) const {
Anton Korobeynikova3f7a832009-05-03 13:13:17 +0000740 unsigned Opc = Op.getOpcode();
Anton Korobeynikov15a515b2009-05-03 13:03:33 +0000741 SDNode* N = Op.getNode();
Owen Anderson53aa7a92009-08-10 22:56:29 +0000742 EVT VT = Op.getValueType();
Andrew Trickef9de2a2013-05-25 02:42:55 +0000743 SDLoc dl(N);
Anton Korobeynikov15a515b2009-05-03 13:03:33 +0000744
Anton Korobeynikovd8f32092009-12-12 18:55:37 +0000745 // Expand non-constant shifts to loops:
Anton Korobeynikov15a515b2009-05-03 13:03:33 +0000746 if (!isa<ConstantSDNode>(N->getOperand(1)))
Anton Korobeynikovd8f32092009-12-12 18:55:37 +0000747 switch (Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +0000748 default: llvm_unreachable("Invalid shift opcode!");
Anton Korobeynikovd8f32092009-12-12 18:55:37 +0000749 case ISD::SHL:
750 return DAG.getNode(MSP430ISD::SHL, dl,
751 VT, N->getOperand(0), N->getOperand(1));
752 case ISD::SRA:
753 return DAG.getNode(MSP430ISD::SRA, dl,
754 VT, N->getOperand(0), N->getOperand(1));
755 case ISD::SRL:
756 return DAG.getNode(MSP430ISD::SRL, dl,
757 VT, N->getOperand(0), N->getOperand(1));
758 }
Anton Korobeynikov15a515b2009-05-03 13:03:33 +0000759
760 uint64_t ShiftAmount = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
761
762 // Expand the stuff into sequence of shifts.
763 // FIXME: for some shift amounts this might be done better!
764 // E.g.: foo >> (8 + N) => sxt(swpb(foo)) >> N
765 SDValue Victim = N->getOperand(0);
Anton Korobeynikov61763b52009-05-03 13:16:17 +0000766
767 if (Opc == ISD::SRL && ShiftAmount) {
768 // Emit a special goodness here:
769 // srl A, 1 => clrc; rrc A
Anton Korobeynikovf3a6bc82009-05-03 13:16:37 +0000770 Victim = DAG.getNode(MSP430ISD::RRC, dl, VT, Victim);
Anton Korobeynikov61763b52009-05-03 13:16:17 +0000771 ShiftAmount -= 1;
772 }
773
Anton Korobeynikov15a515b2009-05-03 13:03:33 +0000774 while (ShiftAmount--)
Anton Korobeynikov6b5523a2009-05-17 10:15:22 +0000775 Victim = DAG.getNode((Opc == ISD::SHL ? MSP430ISD::RLA : MSP430ISD::RRA),
Anton Korobeynikova3f7a832009-05-03 13:13:17 +0000776 dl, VT, Victim);
Anton Korobeynikov15a515b2009-05-03 13:03:33 +0000777
778 return Victim;
779}
780
Dan Gohman21cea8a2010-04-17 15:26:15 +0000781SDValue MSP430TargetLowering::LowerGlobalAddress(SDValue Op,
782 SelectionDAG &DAG) const {
Anton Korobeynikovcfc97052009-05-03 13:08:33 +0000783 const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
784 int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset();
785
786 // Create the TargetGlobalAddress node, folding in the constant offset.
Andrew Trickef9de2a2013-05-25 02:42:55 +0000787 SDValue Result = DAG.getTargetGlobalAddress(GV, SDLoc(Op),
Devang Patela3ca21b2010-07-06 22:08:15 +0000788 getPointerTy(), Offset);
Andrew Trickef9de2a2013-05-25 02:42:55 +0000789 return DAG.getNode(MSP430ISD::Wrapper, SDLoc(Op),
Anton Korobeynikovcfc97052009-05-03 13:08:33 +0000790 getPointerTy(), Result);
791}
792
Anton Korobeynikovba0e81d2009-05-03 13:14:46 +0000793SDValue MSP430TargetLowering::LowerExternalSymbol(SDValue Op,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000794 SelectionDAG &DAG) const {
Andrew Trickef9de2a2013-05-25 02:42:55 +0000795 SDLoc dl(Op);
Anton Korobeynikovba0e81d2009-05-03 13:14:46 +0000796 const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol();
797 SDValue Result = DAG.getTargetExternalSymbol(Sym, getPointerTy());
798
Chad Rosier5dfe6da2012-02-22 17:25:00 +0000799 return DAG.getNode(MSP430ISD::Wrapper, dl, getPointerTy(), Result);
Anton Korobeynikovba0e81d2009-05-03 13:14:46 +0000800}
801
Anton Korobeynikovebbdfef2010-05-01 12:04:32 +0000802SDValue MSP430TargetLowering::LowerBlockAddress(SDValue Op,
803 SelectionDAG &DAG) const {
Andrew Trickef9de2a2013-05-25 02:42:55 +0000804 SDLoc dl(Op);
Anton Korobeynikovebbdfef2010-05-01 12:04:32 +0000805 const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
Michael Liaoabb87d42012-09-12 21:43:09 +0000806 SDValue Result = DAG.getTargetBlockAddress(BA, getPointerTy());
Anton Korobeynikovebbdfef2010-05-01 12:04:32 +0000807
Chad Rosier5dfe6da2012-02-22 17:25:00 +0000808 return DAG.getNode(MSP430ISD::Wrapper, dl, getPointerTy(), Result);
Anton Korobeynikovebbdfef2010-05-01 12:04:32 +0000809}
810
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000811static SDValue EmitCMP(SDValue &LHS, SDValue &RHS, SDValue &TargetCC,
Anton Korobeynikov47fcd722009-05-03 13:19:09 +0000812 ISD::CondCode CC,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000813 SDLoc dl, SelectionDAG &DAG) {
Anton Korobeynikov96272012009-05-03 13:12:06 +0000814 // FIXME: Handle bittests someday
815 assert(!LHS.getValueType().isFloatingPoint() && "We don't handle FP yet");
816
817 // FIXME: Handle jump negative someday
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000818 MSP430CC::CondCodes TCC = MSP430CC::COND_INVALID;
Anton Korobeynikov96272012009-05-03 13:12:06 +0000819 switch (CC) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000820 default: llvm_unreachable("Invalid integer condition!");
Anton Korobeynikov96272012009-05-03 13:12:06 +0000821 case ISD::SETEQ:
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000822 TCC = MSP430CC::COND_E; // aka COND_Z
Anton Korobeynikovcefa7ad2010-01-15 01:29:49 +0000823 // Minor optimization: if LHS is a constant, swap operands, then the
Anton Korobeynikovabdf86d2009-11-22 01:14:08 +0000824 // constant can be folded into comparison.
Anton Korobeynikovcefa7ad2010-01-15 01:29:49 +0000825 if (LHS.getOpcode() == ISD::Constant)
Anton Korobeynikovabdf86d2009-11-22 01:14:08 +0000826 std::swap(LHS, RHS);
Anton Korobeynikov96272012009-05-03 13:12:06 +0000827 break;
828 case ISD::SETNE:
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000829 TCC = MSP430CC::COND_NE; // aka COND_NZ
Anton Korobeynikovcefa7ad2010-01-15 01:29:49 +0000830 // Minor optimization: if LHS is a constant, swap operands, then the
Anton Korobeynikovabdf86d2009-11-22 01:14:08 +0000831 // constant can be folded into comparison.
Anton Korobeynikovcefa7ad2010-01-15 01:29:49 +0000832 if (LHS.getOpcode() == ISD::Constant)
Anton Korobeynikovabdf86d2009-11-22 01:14:08 +0000833 std::swap(LHS, RHS);
Anton Korobeynikov96272012009-05-03 13:12:06 +0000834 break;
835 case ISD::SETULE:
836 std::swap(LHS, RHS); // FALLTHROUGH
837 case ISD::SETUGE:
Anton Korobeynikov6826ce72010-01-15 21:18:02 +0000838 // Turn lhs u>= rhs with lhs constant into rhs u< lhs+1, this allows us to
839 // fold constant into instruction.
840 if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
841 LHS = RHS;
842 RHS = DAG.getConstant(C->getSExtValue() + 1, C->getValueType(0));
843 TCC = MSP430CC::COND_LO;
844 break;
845 }
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000846 TCC = MSP430CC::COND_HS; // aka COND_C
Anton Korobeynikov96272012009-05-03 13:12:06 +0000847 break;
848 case ISD::SETUGT:
849 std::swap(LHS, RHS); // FALLTHROUGH
850 case ISD::SETULT:
Anton Korobeynikov6826ce72010-01-15 21:18:02 +0000851 // Turn lhs u< rhs with lhs constant into rhs u>= lhs+1, this allows us to
852 // fold constant into instruction.
853 if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
854 LHS = RHS;
855 RHS = DAG.getConstant(C->getSExtValue() + 1, C->getValueType(0));
856 TCC = MSP430CC::COND_HS;
857 break;
858 }
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000859 TCC = MSP430CC::COND_LO; // aka COND_NC
Anton Korobeynikov96272012009-05-03 13:12:06 +0000860 break;
861 case ISD::SETLE:
862 std::swap(LHS, RHS); // FALLTHROUGH
863 case ISD::SETGE:
Anton Korobeynikov6826ce72010-01-15 21:18:02 +0000864 // Turn lhs >= rhs with lhs constant into rhs < lhs+1, this allows us to
865 // fold constant into instruction.
866 if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
867 LHS = RHS;
868 RHS = DAG.getConstant(C->getSExtValue() + 1, C->getValueType(0));
869 TCC = MSP430CC::COND_L;
870 break;
871 }
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000872 TCC = MSP430CC::COND_GE;
Anton Korobeynikov96272012009-05-03 13:12:06 +0000873 break;
874 case ISD::SETGT:
875 std::swap(LHS, RHS); // FALLTHROUGH
876 case ISD::SETLT:
Anton Korobeynikov6826ce72010-01-15 21:18:02 +0000877 // Turn lhs < rhs with lhs constant into rhs >= lhs+1, this allows us to
878 // fold constant into instruction.
879 if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
880 LHS = RHS;
881 RHS = DAG.getConstant(C->getSExtValue() + 1, C->getValueType(0));
882 TCC = MSP430CC::COND_GE;
883 break;
884 }
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000885 TCC = MSP430CC::COND_L;
Anton Korobeynikov96272012009-05-03 13:12:06 +0000886 break;
887 }
888
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000889 TargetCC = DAG.getConstant(TCC, MVT::i8);
Chris Lattner3e5fbd72010-12-21 02:38:05 +0000890 return DAG.getNode(MSP430ISD::CMP, dl, MVT::Glue, LHS, RHS);
Anton Korobeynikov96272012009-05-03 13:12:06 +0000891}
892
Anton Korobeynikov47fcd722009-05-03 13:19:09 +0000893
Dan Gohman21cea8a2010-04-17 15:26:15 +0000894SDValue MSP430TargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const {
Anton Korobeynikov96272012009-05-03 13:12:06 +0000895 SDValue Chain = Op.getOperand(0);
Anton Korobeynikov47fcd722009-05-03 13:19:09 +0000896 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
897 SDValue LHS = Op.getOperand(2);
898 SDValue RHS = Op.getOperand(3);
899 SDValue Dest = Op.getOperand(4);
Andrew Trickef9de2a2013-05-25 02:42:55 +0000900 SDLoc dl (Op);
Anton Korobeynikov96272012009-05-03 13:12:06 +0000901
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000902 SDValue TargetCC;
Anton Korobeynikov47fcd722009-05-03 13:19:09 +0000903 SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
Anton Korobeynikov96272012009-05-03 13:12:06 +0000904
Anton Korobeynikov47fcd722009-05-03 13:19:09 +0000905 return DAG.getNode(MSP430ISD::BR_CC, dl, Op.getValueType(),
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000906 Chain, Dest, TargetCC, Flag);
Anton Korobeynikov96272012009-05-03 13:12:06 +0000907}
908
Dan Gohman21cea8a2010-04-17 15:26:15 +0000909SDValue MSP430TargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const {
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000910 SDValue LHS = Op.getOperand(0);
911 SDValue RHS = Op.getOperand(1);
Andrew Trickef9de2a2013-05-25 02:42:55 +0000912 SDLoc dl (Op);
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000913
914 // If we are doing an AND and testing against zero, then the CMP
915 // will not be generated. The AND (or BIT) will generate the condition codes,
916 // but they are different from CMP.
Anton Korobeynikov93a7d022010-01-15 21:18:18 +0000917 // FIXME: since we're doing a post-processing, use a pseudoinstr here, so
918 // lowering & isel wouldn't diverge.
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000919 bool andCC = false;
920 if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) {
921 if (RHSC->isNullValue() && LHS.hasOneUse() &&
922 (LHS.getOpcode() == ISD::AND ||
923 (LHS.getOpcode() == ISD::TRUNCATE &&
924 LHS.getOperand(0).getOpcode() == ISD::AND))) {
925 andCC = true;
926 }
927 }
928 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
929 SDValue TargetCC;
930 SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
931
932 // Get the condition codes directly from the status register, if its easy.
933 // Otherwise a branch will be generated. Note that the AND and BIT
934 // instructions generate different flags than CMP, the carry bit can be used
935 // for NE/EQ.
936 bool Invert = false;
937 bool Shift = false;
938 bool Convert = true;
939 switch (cast<ConstantSDNode>(TargetCC)->getZExtValue()) {
940 default:
941 Convert = false;
942 break;
943 case MSP430CC::COND_HS:
Job Noormaneb19aea2014-09-10 06:58:14 +0000944 // Res = SR & 1, no processing is required
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000945 break;
Anton Korobeynikov93a7d022010-01-15 21:18:18 +0000946 case MSP430CC::COND_LO:
Job Noormaneb19aea2014-09-10 06:58:14 +0000947 // Res = ~(SR & 1)
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000948 Invert = true;
949 break;
Anton Korobeynikov93a7d022010-01-15 21:18:18 +0000950 case MSP430CC::COND_NE:
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000951 if (andCC) {
Job Noormaneb19aea2014-09-10 06:58:14 +0000952 // C = ~Z, thus Res = SR & 1, no processing is required
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000953 } else {
Job Noormaneb19aea2014-09-10 06:58:14 +0000954 // Res = ~((SR >> 1) & 1)
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000955 Shift = true;
Anton Korobeynikove96503f2010-02-21 12:28:58 +0000956 Invert = true;
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000957 }
958 break;
Anton Korobeynikov93a7d022010-01-15 21:18:18 +0000959 case MSP430CC::COND_E:
Anton Korobeynikove96503f2010-02-21 12:28:58 +0000960 Shift = true;
Job Noormaneb19aea2014-09-10 06:58:14 +0000961 // C = ~Z for AND instruction, thus we can put Res = ~(SR & 1), however,
962 // Res = (SR >> 1) & 1 is 1 word shorter.
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000963 break;
964 }
965 EVT VT = Op.getValueType();
966 SDValue One = DAG.getConstant(1, VT);
967 if (Convert) {
Job Noormaneb19aea2014-09-10 06:58:14 +0000968 SDValue SR = DAG.getCopyFromReg(DAG.getEntryNode(), dl, MSP430::SR,
Anton Korobeynikov93a7d022010-01-15 21:18:18 +0000969 MVT::i16, Flag);
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000970 if (Shift)
971 // FIXME: somewhere this is turned into a SRL, lower it MSP specific?
972 SR = DAG.getNode(ISD::SRA, dl, MVT::i16, SR, One);
973 SR = DAG.getNode(ISD::AND, dl, MVT::i16, SR, One);
974 if (Invert)
975 SR = DAG.getNode(ISD::XOR, dl, MVT::i16, SR, One);
976 return SR;
977 } else {
978 SDValue Zero = DAG.getConstant(0, VT);
Chris Lattner3e5fbd72010-12-21 02:38:05 +0000979 SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::Glue);
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000980 SmallVector<SDValue, 4> Ops;
981 Ops.push_back(One);
982 Ops.push_back(Zero);
983 Ops.push_back(TargetCC);
984 Ops.push_back(Flag);
Craig Topper48d114b2014-04-26 18:35:24 +0000985 return DAG.getNode(MSP430ISD::SELECT_CC, dl, VTs, Ops);
Anton Korobeynikove27e0282009-12-11 23:01:29 +0000986 }
987}
988
Dan Gohman21cea8a2010-04-17 15:26:15 +0000989SDValue MSP430TargetLowering::LowerSELECT_CC(SDValue Op,
990 SelectionDAG &DAG) const {
Anton Korobeynikov47fcd722009-05-03 13:19:09 +0000991 SDValue LHS = Op.getOperand(0);
992 SDValue RHS = Op.getOperand(1);
993 SDValue TrueV = Op.getOperand(2);
994 SDValue FalseV = Op.getOperand(3);
995 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
Andrew Trickef9de2a2013-05-25 02:42:55 +0000996 SDLoc dl (Op);
Anton Korobeynikovb6321e152009-05-03 13:12:23 +0000997
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +0000998 SDValue TargetCC;
Anton Korobeynikov47fcd722009-05-03 13:19:09 +0000999 SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001000
Chris Lattner3e5fbd72010-12-21 02:38:05 +00001001 SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::Glue);
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001002 SmallVector<SDValue, 4> Ops;
1003 Ops.push_back(TrueV);
1004 Ops.push_back(FalseV);
Anton Korobeynikov2983dcb2009-10-21 19:16:49 +00001005 Ops.push_back(TargetCC);
Anton Korobeynikov47fcd722009-05-03 13:19:09 +00001006 Ops.push_back(Flag);
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001007
Craig Topper48d114b2014-04-26 18:35:24 +00001008 return DAG.getNode(MSP430ISD::SELECT_CC, dl, VTs, Ops);
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001009}
1010
Anton Korobeynikov29747e92009-05-03 13:17:49 +00001011SDValue MSP430TargetLowering::LowerSIGN_EXTEND(SDValue Op,
Dan Gohman21cea8a2010-04-17 15:26:15 +00001012 SelectionDAG &DAG) const {
Anton Korobeynikov29747e92009-05-03 13:17:49 +00001013 SDValue Val = Op.getOperand(0);
Owen Anderson53aa7a92009-08-10 22:56:29 +00001014 EVT VT = Op.getValueType();
Andrew Trickef9de2a2013-05-25 02:42:55 +00001015 SDLoc dl(Op);
Anton Korobeynikov29747e92009-05-03 13:17:49 +00001016
Owen Anderson9f944592009-08-11 20:47:22 +00001017 assert(VT == MVT::i16 && "Only support i16 for now!");
Anton Korobeynikov29747e92009-05-03 13:17:49 +00001018
1019 return DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, VT,
1020 DAG.getNode(ISD::ANY_EXTEND, dl, VT, Val),
1021 DAG.getValueType(Val.getValueType()));
1022}
1023
Dan Gohman21cea8a2010-04-17 15:26:15 +00001024SDValue
1025MSP430TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) const {
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001026 MachineFunction &MF = DAG.getMachineFunction();
1027 MSP430MachineFunctionInfo *FuncInfo = MF.getInfo<MSP430MachineFunctionInfo>();
1028 int ReturnAddrIndex = FuncInfo->getRAIndex();
1029
1030 if (ReturnAddrIndex == 0) {
1031 // Set up a frame object for the return address.
Eric Christopherdc13b212014-06-27 00:37:59 +00001032 uint64_t SlotSize = getDataLayout()->getPointerSize();
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001033 ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(SlotSize, -SlotSize,
Evan Cheng0664a672010-07-03 00:40:23 +00001034 true);
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001035 FuncInfo->setRAIndex(ReturnAddrIndex);
1036 }
1037
1038 return DAG.getFrameIndex(ReturnAddrIndex, getPointerTy());
1039}
1040
Dan Gohman21cea8a2010-04-17 15:26:15 +00001041SDValue MSP430TargetLowering::LowerRETURNADDR(SDValue Op,
1042 SelectionDAG &DAG) const {
Evan Cheng168ced92010-05-22 01:47:14 +00001043 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
1044 MFI->setReturnAddressIsTaken(true);
1045
Bill Wendling908bf812014-01-06 00:43:20 +00001046 if (verifyReturnAddressArgumentIsConstant(Op, DAG))
Bill Wendlingdf7dd282014-01-05 01:47:20 +00001047 return SDValue();
Bill Wendlingdf7dd282014-01-05 01:47:20 +00001048
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001049 unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
Andrew Trickef9de2a2013-05-25 02:42:55 +00001050 SDLoc dl(Op);
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001051
1052 if (Depth > 0) {
1053 SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
1054 SDValue Offset =
Eric Christopherdc13b212014-06-27 00:37:59 +00001055 DAG.getConstant(getDataLayout()->getPointerSize(), MVT::i16);
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001056 return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
1057 DAG.getNode(ISD::ADD, dl, getPointerTy(),
1058 FrameAddr, Offset),
Pete Cooper82cd9e82011-11-08 18:42:53 +00001059 MachinePointerInfo(), false, false, false, 0);
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001060 }
1061
1062 // Just load the return address.
1063 SDValue RetAddrFI = getReturnAddressFrameIndex(DAG);
1064 return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
Pete Cooper82cd9e82011-11-08 18:42:53 +00001065 RetAddrFI, MachinePointerInfo(), false, false, false, 0);
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001066}
1067
Dan Gohman21cea8a2010-04-17 15:26:15 +00001068SDValue MSP430TargetLowering::LowerFRAMEADDR(SDValue Op,
1069 SelectionDAG &DAG) const {
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001070 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
1071 MFI->setFrameAddressIsTaken(true);
Evan Cheng168ced92010-05-22 01:47:14 +00001072
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001073 EVT VT = Op.getValueType();
Andrew Trickef9de2a2013-05-25 02:42:55 +00001074 SDLoc dl(Op); // FIXME probably not meaningful
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001075 unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
1076 SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl,
Job Noormaneb19aea2014-09-10 06:58:14 +00001077 MSP430::FP, VT);
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001078 while (Depth--)
Chris Lattner7727d052010-09-21 06:44:06 +00001079 FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr,
1080 MachinePointerInfo(),
Pete Cooper82cd9e82011-11-08 18:42:53 +00001081 false, false, false, 0);
Anton Korobeynikovff4ab512009-12-07 02:28:10 +00001082 return FrameAddr;
1083}
1084
Anton Korobeynikov568afeb2012-11-21 17:28:27 +00001085SDValue MSP430TargetLowering::LowerVASTART(SDValue Op,
1086 SelectionDAG &DAG) const {
1087 MachineFunction &MF = DAG.getMachineFunction();
1088 MSP430MachineFunctionInfo *FuncInfo = MF.getInfo<MSP430MachineFunctionInfo>();
1089
1090 // Frame index of first vararg argument
1091 SDValue FrameIndex = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(),
1092 getPointerTy());
1093 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
1094
1095 // Create a store of the frame index to the location operand
Andrew Trickef9de2a2013-05-25 02:42:55 +00001096 return DAG.getStore(Op.getOperand(0), SDLoc(Op), FrameIndex,
Anton Korobeynikov568afeb2012-11-21 17:28:27 +00001097 Op.getOperand(1), MachinePointerInfo(SV),
1098 false, false, 0);
1099}
1100
Anton Korobeynikov82bedb12013-07-01 19:44:44 +00001101SDValue MSP430TargetLowering::LowerJumpTable(SDValue Op,
1102 SelectionDAG &DAG) const {
1103 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
1104 SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy());
Anton Korobeynikovfee796d2013-07-14 15:11:00 +00001105 return DAG.getNode(MSP430ISD::Wrapper, SDLoc(JT),
1106 getPointerTy(), Result);
Anton Korobeynikov82bedb12013-07-01 19:44:44 +00001107}
1108
Anton Korobeynikovd3c83192009-11-07 17:15:06 +00001109/// getPostIndexedAddressParts - returns true by value, base pointer and
1110/// offset pointer and addressing mode by reference if this node can be
1111/// combined with a load / store to form a post-indexed load / store.
1112bool MSP430TargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
1113 SDValue &Base,
1114 SDValue &Offset,
1115 ISD::MemIndexedMode &AM,
1116 SelectionDAG &DAG) const {
1117
1118 LoadSDNode *LD = cast<LoadSDNode>(N);
1119 if (LD->getExtensionType() != ISD::NON_EXTLOAD)
1120 return false;
1121
1122 EVT VT = LD->getMemoryVT();
1123 if (VT != MVT::i8 && VT != MVT::i16)
1124 return false;
1125
1126 if (Op->getOpcode() != ISD::ADD)
1127 return false;
1128
1129 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Op->getOperand(1))) {
1130 uint64_t RHSC = RHS->getZExtValue();
1131 if ((VT == MVT::i16 && RHSC != 2) ||
1132 (VT == MVT::i8 && RHSC != 1))
1133 return false;
1134
1135 Base = Op->getOperand(0);
1136 Offset = DAG.getConstant(RHSC, VT);
1137 AM = ISD::POST_INC;
1138 return true;
1139 }
1140
1141 return false;
1142}
1143
1144
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +00001145const char *MSP430TargetLowering::getTargetNodeName(unsigned Opcode) const {
1146 switch (Opcode) {
Craig Topper062a2ba2014-04-25 05:30:21 +00001147 default: return nullptr;
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +00001148 case MSP430ISD::RET_FLAG: return "MSP430ISD::RET_FLAG";
Anton Korobeynikov24a63162009-12-07 02:28:41 +00001149 case MSP430ISD::RETI_FLAG: return "MSP430ISD::RETI_FLAG";
Anton Korobeynikov15a515b2009-05-03 13:03:33 +00001150 case MSP430ISD::RRA: return "MSP430ISD::RRA";
Anton Korobeynikov61763b52009-05-03 13:16:17 +00001151 case MSP430ISD::RLA: return "MSP430ISD::RLA";
1152 case MSP430ISD::RRC: return "MSP430ISD::RRC";
Anton Korobeynikovec3f0b32009-05-03 13:07:54 +00001153 case MSP430ISD::CALL: return "MSP430ISD::CALL";
Anton Korobeynikovcfc97052009-05-03 13:08:33 +00001154 case MSP430ISD::Wrapper: return "MSP430ISD::Wrapper";
Anton Korobeynikov47fcd722009-05-03 13:19:09 +00001155 case MSP430ISD::BR_CC: return "MSP430ISD::BR_CC";
Anton Korobeynikov96272012009-05-03 13:12:06 +00001156 case MSP430ISD::CMP: return "MSP430ISD::CMP";
Anton Korobeynikov47fcd722009-05-03 13:19:09 +00001157 case MSP430ISD::SELECT_CC: return "MSP430ISD::SELECT_CC";
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001158 case MSP430ISD::SHL: return "MSP430ISD::SHL";
1159 case MSP430ISD::SRA: return "MSP430ISD::SRA";
Anton Korobeynikov7bfc3ea2009-05-03 12:59:50 +00001160 }
1161}
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001162
Chris Lattner229907c2011-07-18 04:54:35 +00001163bool MSP430TargetLowering::isTruncateFree(Type *Ty1,
1164 Type *Ty2) const {
Duncan Sands9dff9be2010-02-15 16:12:20 +00001165 if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy())
Anton Korobeynikova6450df2010-01-15 21:19:43 +00001166 return false;
1167
1168 return (Ty1->getPrimitiveSizeInBits() > Ty2->getPrimitiveSizeInBits());
1169}
1170
1171bool MSP430TargetLowering::isTruncateFree(EVT VT1, EVT VT2) const {
1172 if (!VT1.isInteger() || !VT2.isInteger())
1173 return false;
1174
1175 return (VT1.getSizeInBits() > VT2.getSizeInBits());
1176}
1177
Chris Lattner229907c2011-07-18 04:54:35 +00001178bool MSP430TargetLowering::isZExtFree(Type *Ty1, Type *Ty2) const {
Anton Korobeynikova6450df2010-01-15 21:19:43 +00001179 // MSP430 implicitly zero-extends 8-bit results in 16-bit registers.
Duncan Sands9dff9be2010-02-15 16:12:20 +00001180 return 0 && Ty1->isIntegerTy(8) && Ty2->isIntegerTy(16);
Anton Korobeynikova6450df2010-01-15 21:19:43 +00001181}
1182
1183bool MSP430TargetLowering::isZExtFree(EVT VT1, EVT VT2) const {
1184 // MSP430 implicitly zero-extends 8-bit results in 16-bit registers.
1185 return 0 && VT1 == MVT::i8 && VT2 == MVT::i16;
1186}
1187
Eli Bendersky39e7c6e2012-12-18 18:21:29 +00001188bool MSP430TargetLowering::isZExtFree(SDValue Val, EVT VT2) const {
1189 return isZExtFree(Val.getValueType(), VT2);
1190}
1191
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001192//===----------------------------------------------------------------------===//
1193// Other Lowering Code
1194//===----------------------------------------------------------------------===//
1195
1196MachineBasicBlock*
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001197MSP430TargetLowering::EmitShiftInstr(MachineInstr *MI,
Dan Gohman25c16532010-05-01 00:01:06 +00001198 MachineBasicBlock *BB) const {
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001199 MachineFunction *F = BB->getParent();
1200 MachineRegisterInfo &RI = F->getRegInfo();
1201 DebugLoc dl = MI->getDebugLoc();
Eric Christopherd9134482014-08-04 21:25:23 +00001202 const TargetInstrInfo &TII =
1203 *getTargetMachine().getSubtargetImpl()->getInstrInfo();
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001204
1205 unsigned Opc;
1206 const TargetRegisterClass * RC;
1207 switch (MI->getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00001208 default: llvm_unreachable("Invalid shift opcode!");
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001209 case MSP430::Shl8:
1210 Opc = MSP430::SHL8r1;
Craig Topperc7242e02012-04-20 07:30:17 +00001211 RC = &MSP430::GR8RegClass;
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001212 break;
1213 case MSP430::Shl16:
1214 Opc = MSP430::SHL16r1;
Craig Topperc7242e02012-04-20 07:30:17 +00001215 RC = &MSP430::GR16RegClass;
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001216 break;
1217 case MSP430::Sra8:
1218 Opc = MSP430::SAR8r1;
Craig Topperc7242e02012-04-20 07:30:17 +00001219 RC = &MSP430::GR8RegClass;
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001220 break;
1221 case MSP430::Sra16:
1222 Opc = MSP430::SAR16r1;
Craig Topperc7242e02012-04-20 07:30:17 +00001223 RC = &MSP430::GR16RegClass;
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001224 break;
1225 case MSP430::Srl8:
1226 Opc = MSP430::SAR8r1c;
Craig Topperc7242e02012-04-20 07:30:17 +00001227 RC = &MSP430::GR8RegClass;
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001228 break;
1229 case MSP430::Srl16:
1230 Opc = MSP430::SAR16r1c;
Craig Topperc7242e02012-04-20 07:30:17 +00001231 RC = &MSP430::GR16RegClass;
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001232 break;
1233 }
1234
1235 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1236 MachineFunction::iterator I = BB;
1237 ++I;
1238
1239 // Create loop block
1240 MachineBasicBlock *LoopBB = F->CreateMachineBasicBlock(LLVM_BB);
1241 MachineBasicBlock *RemBB = F->CreateMachineBasicBlock(LLVM_BB);
1242
1243 F->insert(I, LoopBB);
1244 F->insert(I, RemBB);
1245
1246 // Update machine-CFG edges by transferring all successors of the current
1247 // block to the block containing instructions after shift.
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +00001248 RemBB->splice(RemBB->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
Dan Gohman34396292010-07-06 20:24:04 +00001249 BB->end());
1250 RemBB->transferSuccessorsAndUpdatePHIs(BB);
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001251
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001252 // Add adges BB => LoopBB => RemBB, BB => RemBB, LoopBB => LoopBB
1253 BB->addSuccessor(LoopBB);
1254 BB->addSuccessor(RemBB);
1255 LoopBB->addSuccessor(RemBB);
1256 LoopBB->addSuccessor(LoopBB);
1257
Craig Topperc7242e02012-04-20 07:30:17 +00001258 unsigned ShiftAmtReg = RI.createVirtualRegister(&MSP430::GR8RegClass);
1259 unsigned ShiftAmtReg2 = RI.createVirtualRegister(&MSP430::GR8RegClass);
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001260 unsigned ShiftReg = RI.createVirtualRegister(RC);
1261 unsigned ShiftReg2 = RI.createVirtualRegister(RC);
1262 unsigned ShiftAmtSrcReg = MI->getOperand(2).getReg();
1263 unsigned SrcReg = MI->getOperand(1).getReg();
1264 unsigned DstReg = MI->getOperand(0).getReg();
1265
1266 // BB:
1267 // cmp 0, N
1268 // je RemBB
Anton Korobeynikovcefa7ad2010-01-15 01:29:49 +00001269 BuildMI(BB, dl, TII.get(MSP430::CMP8ri))
1270 .addReg(ShiftAmtSrcReg).addImm(0);
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001271 BuildMI(BB, dl, TII.get(MSP430::JCC))
1272 .addMBB(RemBB)
1273 .addImm(MSP430CC::COND_E);
1274
1275 // LoopBB:
1276 // ShiftReg = phi [%SrcReg, BB], [%ShiftReg2, LoopBB]
1277 // ShiftAmt = phi [%N, BB], [%ShiftAmt2, LoopBB]
1278 // ShiftReg2 = shift ShiftReg
1279 // ShiftAmt2 = ShiftAmt - 1;
1280 BuildMI(LoopBB, dl, TII.get(MSP430::PHI), ShiftReg)
1281 .addReg(SrcReg).addMBB(BB)
1282 .addReg(ShiftReg2).addMBB(LoopBB);
1283 BuildMI(LoopBB, dl, TII.get(MSP430::PHI), ShiftAmtReg)
1284 .addReg(ShiftAmtSrcReg).addMBB(BB)
1285 .addReg(ShiftAmtReg2).addMBB(LoopBB);
1286 BuildMI(LoopBB, dl, TII.get(Opc), ShiftReg2)
1287 .addReg(ShiftReg);
1288 BuildMI(LoopBB, dl, TII.get(MSP430::SUB8ri), ShiftAmtReg2)
1289 .addReg(ShiftAmtReg).addImm(1);
1290 BuildMI(LoopBB, dl, TII.get(MSP430::JCC))
1291 .addMBB(LoopBB)
1292 .addImm(MSP430CC::COND_NE);
1293
1294 // RemBB:
1295 // DestReg = phi [%SrcReg, BB], [%ShiftReg, LoopBB]
Dan Gohman34396292010-07-06 20:24:04 +00001296 BuildMI(*RemBB, RemBB->begin(), dl, TII.get(MSP430::PHI), DstReg)
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001297 .addReg(SrcReg).addMBB(BB)
1298 .addReg(ShiftReg2).addMBB(LoopBB);
1299
Dan Gohman34396292010-07-06 20:24:04 +00001300 MI->eraseFromParent(); // The pseudo instruction is gone now.
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001301 return RemBB;
1302}
1303
1304MachineBasicBlock*
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001305MSP430TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohman25c16532010-05-01 00:01:06 +00001306 MachineBasicBlock *BB) const {
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001307 unsigned Opc = MI->getOpcode();
1308
1309 if (Opc == MSP430::Shl8 || Opc == MSP430::Shl16 ||
1310 Opc == MSP430::Sra8 || Opc == MSP430::Sra16 ||
1311 Opc == MSP430::Srl8 || Opc == MSP430::Srl16)
Dan Gohman25c16532010-05-01 00:01:06 +00001312 return EmitShiftInstr(MI, BB);
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001313
Eric Christopherd9134482014-08-04 21:25:23 +00001314 const TargetInstrInfo &TII =
1315 *getTargetMachine().getSubtargetImpl()->getInstrInfo();
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001316 DebugLoc dl = MI->getDebugLoc();
Anton Korobeynikovd8f32092009-12-12 18:55:37 +00001317
1318 assert((Opc == MSP430::Select16 || Opc == MSP430::Select8) &&
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001319 "Unexpected instr type to insert");
1320
1321 // To "insert" a SELECT instruction, we actually have to insert the diamond
1322 // control-flow pattern. The incoming instruction knows the destination vreg
1323 // to set, the condition code register to branch on, the true/false values to
1324 // select between, and a branch opcode to use.
1325 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1326 MachineFunction::iterator I = BB;
1327 ++I;
1328
1329 // thisMBB:
1330 // ...
1331 // TrueVal = ...
1332 // cmpTY ccX, r1, r2
1333 // jCC copy1MBB
1334 // fallthrough --> copy0MBB
1335 MachineBasicBlock *thisMBB = BB;
1336 MachineFunction *F = BB->getParent();
1337 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
1338 MachineBasicBlock *copy1MBB = F->CreateMachineBasicBlock(LLVM_BB);
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001339 F->insert(I, copy0MBB);
1340 F->insert(I, copy1MBB);
1341 // Update machine-CFG edges by transferring all successors of the current
1342 // block to the new block which will contain the Phi node for the select.
Dan Gohman34396292010-07-06 20:24:04 +00001343 copy1MBB->splice(copy1MBB->begin(), BB,
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +00001344 std::next(MachineBasicBlock::iterator(MI)), BB->end());
Dan Gohman34396292010-07-06 20:24:04 +00001345 copy1MBB->transferSuccessorsAndUpdatePHIs(BB);
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001346 // Next, add the true and fallthrough blocks as its successors.
1347 BB->addSuccessor(copy0MBB);
1348 BB->addSuccessor(copy1MBB);
1349
Dan Gohman34396292010-07-06 20:24:04 +00001350 BuildMI(BB, dl, TII.get(MSP430::JCC))
1351 .addMBB(copy1MBB)
1352 .addImm(MI->getOperand(3).getImm());
1353
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001354 // copy0MBB:
1355 // %FalseValue = ...
1356 // # fallthrough to copy1MBB
1357 BB = copy0MBB;
1358
1359 // Update machine-CFG edges
1360 BB->addSuccessor(copy1MBB);
1361
1362 // copy1MBB:
1363 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1364 // ...
1365 BB = copy1MBB;
Dan Gohman34396292010-07-06 20:24:04 +00001366 BuildMI(*BB, BB->begin(), dl, TII.get(MSP430::PHI),
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001367 MI->getOperand(0).getReg())
1368 .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
1369 .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB);
1370
Dan Gohman34396292010-07-06 20:24:04 +00001371 MI->eraseFromParent(); // The pseudo instruction is gone now.
Anton Korobeynikovb6321e152009-05-03 13:12:23 +00001372 return BB;
1373}