blob: 55b22aae39766ab3ba9a8394866ec3fce9c34db4 [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===-- ARMISelLowering.cpp - ARM DAG Lowering Implementation -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Evan Cheng and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the interfaces that ARM uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#include "ARM.h"
16#include "ARMAddressingModes.h"
17#include "ARMConstantPoolValue.h"
18#include "ARMISelLowering.h"
19#include "ARMMachineFunctionInfo.h"
20#include "ARMRegisterInfo.h"
21#include "ARMSubtarget.h"
22#include "ARMTargetMachine.h"
23#include "llvm/CallingConv.h"
24#include "llvm/Constants.h"
25#include "llvm/CodeGen/MachineBasicBlock.h"
26#include "llvm/CodeGen/MachineFrameInfo.h"
27#include "llvm/CodeGen/MachineFunction.h"
28#include "llvm/CodeGen/MachineInstrBuilder.h"
29#include "llvm/CodeGen/SelectionDAG.h"
30#include "llvm/CodeGen/SSARegMap.h"
31#include "llvm/ADT/VectorExtras.h"
32using namespace llvm;
33
34ARMTargetLowering::ARMTargetLowering(TargetMachine &TM)
35 : TargetLowering(TM), ARMPCLabelIndex(0) {
36 Subtarget = &TM.getSubtarget<ARMSubtarget>();
37
38 // Uses VFP for Thumb libfuncs if available.
39 if (Subtarget->isThumb() && Subtarget->hasVFP2()) {
40 // Single-precision floating-point arithmetic.
41 setLibcallName(RTLIB::ADD_F32, "__addsf3vfp");
42 setLibcallName(RTLIB::SUB_F32, "__subsf3vfp");
43 setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp");
44 setLibcallName(RTLIB::DIV_F32, "__divsf3vfp");
45
46 // Double-precision floating-point arithmetic.
47 setLibcallName(RTLIB::ADD_F64, "__adddf3vfp");
48 setLibcallName(RTLIB::SUB_F64, "__subdf3vfp");
49 setLibcallName(RTLIB::MUL_F64, "__muldf3vfp");
50 setLibcallName(RTLIB::DIV_F64, "__divdf3vfp");
51
52 // Single-precision comparisons.
53 setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp");
54 setLibcallName(RTLIB::UNE_F32, "__nesf2vfp");
55 setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp");
56 setLibcallName(RTLIB::OLE_F32, "__lesf2vfp");
57 setLibcallName(RTLIB::OGE_F32, "__gesf2vfp");
58 setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp");
59 setLibcallName(RTLIB::UO_F32, "__unordsf2vfp");
60
61 // Double-precision comparisons.
62 setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp");
63 setLibcallName(RTLIB::UNE_F64, "__nedf2vfp");
64 setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp");
65 setLibcallName(RTLIB::OLE_F64, "__ledf2vfp");
66 setLibcallName(RTLIB::OGE_F64, "__gedf2vfp");
67 setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp");
68 setLibcallName(RTLIB::UO_F64, "__unorddf2vfp");
69
70 // Floating-point to integer conversions.
71 // i64 conversions are done via library routines even when generating VFP
72 // instructions, so use the same ones.
73 setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp");
74 setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp");
75 setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp");
76 setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp");
77
78 // Conversions between floating types.
79 setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp");
80 setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp");
81
82 // Integer to floating-point conversions.
83 // i64 conversions are done via library routines even when generating VFP
84 // instructions, so use the same ones.
85 // FIXME: There appears to be some naming inconsistency in ARM libgcc: e.g.
86 // __floatunsidf vs. __floatunssidfvfp.
87 setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp");
88 setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp");
89 setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp");
90 setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp");
91 }
92
93 addRegisterClass(MVT::i32, ARM::GPRRegisterClass);
94 if (Subtarget->hasVFP2() && !Subtarget->isThumb()) {
95 addRegisterClass(MVT::f32, ARM::SPRRegisterClass);
96 addRegisterClass(MVT::f64, ARM::DPRRegisterClass);
97 }
98
99 // ARM does not have f32 extending load.
100 setLoadXAction(ISD::EXTLOAD, MVT::f32, Expand);
101
102 // ARM supports all 4 flavors of integer indexed load / store.
103 for (unsigned im = (unsigned)ISD::PRE_INC;
104 im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) {
105 setIndexedLoadAction(im, MVT::i1, Legal);
106 setIndexedLoadAction(im, MVT::i8, Legal);
107 setIndexedLoadAction(im, MVT::i16, Legal);
108 setIndexedLoadAction(im, MVT::i32, Legal);
109 setIndexedStoreAction(im, MVT::i1, Legal);
110 setIndexedStoreAction(im, MVT::i8, Legal);
111 setIndexedStoreAction(im, MVT::i16, Legal);
112 setIndexedStoreAction(im, MVT::i32, Legal);
113 }
114
115 // i64 operation support.
116 if (Subtarget->isThumb()) {
117 setOperationAction(ISD::MUL, MVT::i64, Expand);
118 setOperationAction(ISD::MULHU, MVT::i32, Expand);
119 setOperationAction(ISD::MULHS, MVT::i32, Expand);
120 } else {
121 setOperationAction(ISD::MUL, MVT::i64, Custom);
122 setOperationAction(ISD::MULHU, MVT::i32, Custom);
123 if (!Subtarget->hasV6Ops())
124 setOperationAction(ISD::MULHS, MVT::i32, Custom);
125 }
126 setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
127 setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand);
128 setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand);
129 setOperationAction(ISD::SRL, MVT::i64, Custom);
130 setOperationAction(ISD::SRA, MVT::i64, Custom);
131
132 // ARM does not have ROTL.
133 setOperationAction(ISD::ROTL, MVT::i32, Expand);
134 setOperationAction(ISD::CTTZ , MVT::i32, Expand);
135 setOperationAction(ISD::CTPOP, MVT::i32, Expand);
136 if (!Subtarget->hasV5TOps())
137 setOperationAction(ISD::CTLZ, MVT::i32, Expand);
138
139 // These are expanded into libcalls.
140 setOperationAction(ISD::SDIV, MVT::i32, Expand);
141 setOperationAction(ISD::UDIV, MVT::i32, Expand);
142 setOperationAction(ISD::SREM, MVT::i32, Expand);
143 setOperationAction(ISD::UREM, MVT::i32, Expand);
144
145 // Support label based line numbers.
146 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
147 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
148 // FIXME - use subtarget debug flags
Evan Cheng970a4192007-01-19 19:28:01 +0000149 if (Subtarget->isTargetDarwin())
Jim Laskey1ee29252007-01-26 14:34:52 +0000150 setOperationAction(ISD::LABEL, MVT::Other, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000151
152 setOperationAction(ISD::RET, MVT::Other, Custom);
153 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
154 setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
155
156 // Expand mem operations genericly.
157 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
158 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
159 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
160
161 // Use the default implementation.
162 setOperationAction(ISD::VASTART , MVT::Other, Expand);
163 setOperationAction(ISD::VAARG , MVT::Other, Expand);
164 setOperationAction(ISD::VACOPY , MVT::Other, Expand);
165 setOperationAction(ISD::VAEND , MVT::Other, Expand);
166 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
167 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
168 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand);
169
170 if (!Subtarget->hasV6Ops()) {
171 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
172 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand);
173 }
174 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
175
176 if (Subtarget->hasVFP2() && !Subtarget->isThumb())
177 // Turn f64->i64 into FMRRD iff target supports vfp2.
178 setOperationAction(ISD::BIT_CONVERT, MVT::i64, Custom);
179
180 setOperationAction(ISD::SETCC , MVT::i32, Expand);
181 setOperationAction(ISD::SETCC , MVT::f32, Expand);
182 setOperationAction(ISD::SETCC , MVT::f64, Expand);
183 setOperationAction(ISD::SELECT , MVT::i32, Expand);
184 setOperationAction(ISD::SELECT , MVT::f32, Expand);
185 setOperationAction(ISD::SELECT , MVT::f64, Expand);
186 setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
187 setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
188 setOperationAction(ISD::SELECT_CC, MVT::f64, Custom);
189
190 setOperationAction(ISD::BRCOND , MVT::Other, Expand);
191 setOperationAction(ISD::BR_CC , MVT::i32, Custom);
192 setOperationAction(ISD::BR_CC , MVT::f32, Custom);
193 setOperationAction(ISD::BR_CC , MVT::f64, Custom);
194 setOperationAction(ISD::BR_JT , MVT::Other, Custom);
195
196 setOperationAction(ISD::VASTART, MVT::Other, Custom);
197 setOperationAction(ISD::VACOPY, MVT::Other, Expand);
198 setOperationAction(ISD::VAEND, MVT::Other, Expand);
199 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
200 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
201
202 // FP Constants can't be immediates.
203 setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
204 setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
205
206 // We don't support sin/cos/fmod/copysign
207 setOperationAction(ISD::FSIN , MVT::f64, Expand);
208 setOperationAction(ISD::FSIN , MVT::f32, Expand);
209 setOperationAction(ISD::FCOS , MVT::f32, Expand);
210 setOperationAction(ISD::FCOS , MVT::f64, Expand);
211 setOperationAction(ISD::FREM , MVT::f64, Expand);
212 setOperationAction(ISD::FREM , MVT::f32, Expand);
213 setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom);
214 setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom);
215
216 // int <-> fp are custom expanded into bit_convert + ARMISD ops.
217 setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
218 setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom);
219 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
220 setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
221
222 setStackPointerRegisterToSaveRestore(ARM::SP);
223
224 setSchedulingPreference(SchedulingForRegPressure);
225 computeRegisterProperties();
226}
227
228
229const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const {
230 switch (Opcode) {
231 default: return 0;
232 case ARMISD::Wrapper: return "ARMISD::Wrapper";
233 case ARMISD::WrapperCall: return "ARMISD::WrapperCall";
234 case ARMISD::WrapperJT: return "ARMISD::WrapperJT";
235 case ARMISD::CALL: return "ARMISD::CALL";
236 case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK";
237 case ARMISD::tCALL: return "ARMISD::tCALL";
238 case ARMISD::BRCOND: return "ARMISD::BRCOND";
239 case ARMISD::BR_JT: return "ARMISD::BR_JT";
240 case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG";
241 case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD";
242 case ARMISD::CMP: return "ARMISD::CMP";
243 case ARMISD::CMPFP: return "ARMISD::CMPFP";
244 case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0";
245 case ARMISD::FMSTAT: return "ARMISD::FMSTAT";
246 case ARMISD::CMOV: return "ARMISD::CMOV";
247 case ARMISD::CNEG: return "ARMISD::CNEG";
248
249 case ARMISD::FTOSI: return "ARMISD::FTOSI";
250 case ARMISD::FTOUI: return "ARMISD::FTOUI";
251 case ARMISD::SITOF: return "ARMISD::SITOF";
252 case ARMISD::UITOF: return "ARMISD::UITOF";
253 case ARMISD::MULHILOU: return "ARMISD::MULHILOU";
254 case ARMISD::MULHILOS: return "ARMISD::MULHILOS";
255
256 case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG";
257 case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG";
258 case ARMISD::RRX: return "ARMISD::RRX";
259
260 case ARMISD::FMRRD: return "ARMISD::FMRRD";
261 case ARMISD::FMDRR: return "ARMISD::FMDRR";
262 }
263}
264
265//===----------------------------------------------------------------------===//
266// Lowering Code
267//===----------------------------------------------------------------------===//
268
269
270/// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC
271static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) {
272 switch (CC) {
273 default: assert(0 && "Unknown condition code!");
274 case ISD::SETNE: return ARMCC::NE;
275 case ISD::SETEQ: return ARMCC::EQ;
276 case ISD::SETGT: return ARMCC::GT;
277 case ISD::SETGE: return ARMCC::GE;
278 case ISD::SETLT: return ARMCC::LT;
279 case ISD::SETLE: return ARMCC::LE;
280 case ISD::SETUGT: return ARMCC::HI;
281 case ISD::SETUGE: return ARMCC::HS;
282 case ISD::SETULT: return ARMCC::LO;
283 case ISD::SETULE: return ARMCC::LS;
284 }
285}
286
287/// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. It
288/// returns true if the operands should be inverted to form the proper
289/// comparison.
290static bool FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode,
291 ARMCC::CondCodes &CondCode2) {
292 bool Invert = false;
293 CondCode2 = ARMCC::AL;
294 switch (CC) {
295 default: assert(0 && "Unknown FP condition!");
296 case ISD::SETEQ:
297 case ISD::SETOEQ: CondCode = ARMCC::EQ; break;
298 case ISD::SETGT:
299 case ISD::SETOGT: CondCode = ARMCC::GT; break;
300 case ISD::SETGE:
301 case ISD::SETOGE: CondCode = ARMCC::GE; break;
302 case ISD::SETOLT: CondCode = ARMCC::MI; break;
303 case ISD::SETOLE: CondCode = ARMCC::GT; Invert = true; break;
304 case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break;
305 case ISD::SETO: CondCode = ARMCC::VC; break;
306 case ISD::SETUO: CondCode = ARMCC::VS; break;
307 case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break;
308 case ISD::SETUGT: CondCode = ARMCC::HI; break;
309 case ISD::SETUGE: CondCode = ARMCC::PL; break;
310 case ISD::SETLT:
311 case ISD::SETULT: CondCode = ARMCC::LT; break;
312 case ISD::SETLE:
313 case ISD::SETULE: CondCode = ARMCC::LE; break;
314 case ISD::SETNE:
315 case ISD::SETUNE: CondCode = ARMCC::NE; break;
316 }
317 return Invert;
318}
319
320static void
321HowToPassArgument(MVT::ValueType ObjectVT,
322 unsigned NumGPRs, unsigned &ObjSize, unsigned &ObjGPRs) {
323 ObjSize = 0;
324 ObjGPRs = 0;
325
326 switch (ObjectVT) {
327 default: assert(0 && "Unhandled argument type!");
328 case MVT::i32:
329 case MVT::f32:
330 if (NumGPRs < 4)
331 ObjGPRs = 1;
332 else
333 ObjSize = 4;
334 break;
335 case MVT::i64:
336 case MVT::f64:
337 if (NumGPRs < 3)
338 ObjGPRs = 2;
339 else if (NumGPRs == 3) {
340 ObjGPRs = 1;
341 ObjSize = 4;
342 } else
343 ObjSize = 8;
344 }
345}
346
347// This transforms a ISD::CALL node into a
348// callseq_star <- ARMISD:CALL <- callseq_end
349// chain
350SDOperand ARMTargetLowering::LowerCALL(SDOperand Op, SelectionDAG &DAG) {
351 MVT::ValueType RetVT= Op.Val->getValueType(0);
352 SDOperand Chain = Op.getOperand(0);
353 unsigned CallConv = cast<ConstantSDNode>(Op.getOperand(1))->getValue();
354 assert((CallConv == CallingConv::C ||
Evan Chenga8e29892007-01-19 07:51:42 +0000355 CallConv == CallingConv::Fast) && "unknown calling convention");
356 SDOperand Callee = Op.getOperand(4);
357 unsigned NumOps = (Op.getNumOperands() - 5) / 2;
358 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
359 unsigned NumGPRs = 0; // GPRs used for parameter passing.
360
361 // Count how many bytes are to be pushed on the stack.
362 unsigned NumBytes = 0;
363
364 // Add up all the space actually used.
365 for (unsigned i = 0; i < NumOps; ++i) {
366 unsigned ObjSize = 0;
367 unsigned ObjGPRs = 0;
368 MVT::ValueType ObjectVT = Op.getOperand(5+2*i).getValueType();
369 HowToPassArgument(ObjectVT, NumGPRs, ObjSize, ObjGPRs);
370 NumBytes += ObjSize;
371 NumGPRs += ObjGPRs;
372 }
373
374 // Adjust the stack pointer for the new arguments...
375 // These operations are automatically eliminated by the prolog/epilog pass
376 Chain = DAG.getCALLSEQ_START(Chain,
377 DAG.getConstant(NumBytes, MVT::i32));
378
379 SDOperand StackPtr = DAG.getRegister(ARM::SP, MVT::i32);
380
381 static const unsigned GPRArgRegs[] = {
382 ARM::R0, ARM::R1, ARM::R2, ARM::R3
383 };
384
385 NumGPRs = 0;
386 std::vector<std::pair<unsigned, SDOperand> > RegsToPass;
387 std::vector<SDOperand> MemOpChains;
388 for (unsigned i = 0; i != NumOps; ++i) {
389 SDOperand Arg = Op.getOperand(5+2*i);
390 MVT::ValueType ArgVT = Arg.getValueType();
391
392 unsigned ObjSize = 0;
393 unsigned ObjGPRs = 0;
394 HowToPassArgument(ArgVT, NumGPRs, ObjSize, ObjGPRs);
395 if (ObjGPRs > 0) {
396 switch (ArgVT) {
397 default: assert(0 && "Unexpected ValueType for argument!");
398 case MVT::i32:
399 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs], Arg));
400 break;
401 case MVT::f32:
402 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs],
403 DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Arg)));
404 break;
405 case MVT::i64: {
406 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Arg,
407 DAG.getConstant(0, getPointerTy()));
408 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Arg,
409 DAG.getConstant(1, getPointerTy()));
410 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs], Lo));
411 if (ObjGPRs == 2)
412 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs+1], Hi));
413 else {
414 SDOperand PtrOff= DAG.getConstant(ArgOffset, StackPtr.getValueType());
415 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
416 MemOpChains.push_back(DAG.getStore(Chain, Hi, PtrOff, NULL, 0));
417 }
418 break;
419 }
420 case MVT::f64: {
421 SDOperand Cvt = DAG.getNode(ARMISD::FMRRD,
422 DAG.getVTList(MVT::i32, MVT::i32),
423 &Arg, 1);
424 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs], Cvt));
425 if (ObjGPRs == 2)
426 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs+1],
427 Cvt.getValue(1)));
428 else {
429 SDOperand PtrOff= DAG.getConstant(ArgOffset, StackPtr.getValueType());
430 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
431 MemOpChains.push_back(DAG.getStore(Chain, Cvt.getValue(1), PtrOff,
432 NULL, 0));
433 }
434 break;
435 }
436 }
437 } else {
438 assert(ObjSize != 0);
439 SDOperand PtrOff = DAG.getConstant(ArgOffset, StackPtr.getValueType());
440 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
441 MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0));
442 }
443
444 NumGPRs += ObjGPRs;
445 ArgOffset += ObjSize;
446 }
447
448 if (!MemOpChains.empty())
449 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other,
450 &MemOpChains[0], MemOpChains.size());
451
452 // Build a sequence of copy-to-reg nodes chained together with token chain
453 // and flag operands which copy the outgoing args into the appropriate regs.
454 SDOperand InFlag;
455 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
456 Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first, RegsToPass[i].second,
457 InFlag);
458 InFlag = Chain.getValue(1);
459 }
460
461 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
462 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
463 // node so that legalize doesn't hack it.
464 bool isDirect = false;
465 bool isARMFunc = false;
466 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
467 GlobalValue *GV = G->getGlobal();
468 Callee = DAG.getTargetGlobalAddress(GV, getPointerTy());
469 isDirect = true;
470 bool isExt = (GV->isExternal() || GV->hasWeakLinkage() ||
471 GV->hasLinkOnceLinkage());
Evan Cheng970a4192007-01-19 19:28:01 +0000472 bool isStub = (isExt && Subtarget->isTargetDarwin()) &&
Evan Chenga8e29892007-01-19 07:51:42 +0000473 getTargetMachine().getRelocationModel() != Reloc::Static;
474 isARMFunc = !Subtarget->isThumb() || isStub;
475 // Wrap it since tBX takes a register source operand.
476 if (isARMFunc && Subtarget->isThumb() && !Subtarget->hasV5TOps())
477 Callee = DAG.getNode(ARMISD::WrapperCall, MVT::i32, Callee);
478 } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
479 Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
480 isDirect = true;
Evan Cheng970a4192007-01-19 19:28:01 +0000481 bool isStub = Subtarget->isTargetDarwin() &&
Evan Chenga8e29892007-01-19 07:51:42 +0000482 getTargetMachine().getRelocationModel() != Reloc::Static;
483 isARMFunc = !Subtarget->isThumb() || isStub;
484 // Wrap it since tBX takes a register source operand.
Evan Cheng2576f132007-01-22 19:40:10 +0000485 if (isARMFunc && Subtarget->isThumb() && !Subtarget->hasV5TOps())
Evan Chenga8e29892007-01-19 07:51:42 +0000486 Callee = DAG.getNode(ARMISD::WrapperCall, MVT::i32, Callee);
487 }
488
489 std::vector<MVT::ValueType> NodeTys;
490 NodeTys.push_back(MVT::Other); // Returns a chain
491 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
492
493 std::vector<SDOperand> Ops;
494 Ops.push_back(Chain);
495 Ops.push_back(Callee);
496
497 // Add argument registers to the end of the list so that they are known live
498 // into the call.
499 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
500 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
501 RegsToPass[i].second.getValueType()));
502
503 // FIXME: handle tail calls differently.
504 unsigned CallOpc;
505 if (Subtarget->isThumb()) {
506 if (!Subtarget->hasV5TOps() && (!isDirect || isARMFunc))
507 CallOpc = ARMISD::CALL_NOLINK;
508 else
509 CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL;
510 } else {
511 CallOpc = (isDirect || Subtarget->hasV5TOps())
512 ? ARMISD::CALL : ARMISD::CALL_NOLINK;
513 }
514 if (InFlag.Val)
515 Ops.push_back(InFlag);
516 Chain = DAG.getNode(CallOpc, NodeTys, &Ops[0], Ops.size());
517 InFlag = Chain.getValue(1);
518
519 SDOperand CSOps[] = { Chain, DAG.getConstant(NumBytes, MVT::i32), InFlag };
520 Chain = DAG.getNode(ISD::CALLSEQ_END,
521 DAG.getNodeValueTypes(MVT::Other, MVT::Flag),
522 ((RetVT != MVT::Other) ? 2 : 1), CSOps, 3);
523 if (RetVT != MVT::Other)
524 InFlag = Chain.getValue(1);
525
526 std::vector<SDOperand> ResultVals;
527 NodeTys.clear();
528
529 // If the call has results, copy the values out of the ret val registers.
530 switch (RetVT) {
531 default: assert(0 && "Unexpected ret value!");
532 case MVT::Other:
533 break;
534 case MVT::i32:
535 Chain = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag).getValue(1);
536 ResultVals.push_back(Chain.getValue(0));
537 if (Op.Val->getValueType(1) == MVT::i32) {
538 // Returns a i64 value.
539 Chain = DAG.getCopyFromReg(Chain, ARM::R1, MVT::i32,
540 Chain.getValue(2)).getValue(1);
541 ResultVals.push_back(Chain.getValue(0));
542 NodeTys.push_back(MVT::i32);
543 }
544 NodeTys.push_back(MVT::i32);
545 break;
546 case MVT::f32:
547 Chain = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag).getValue(1);
548 ResultVals.push_back(DAG.getNode(ISD::BIT_CONVERT, MVT::f32,
549 Chain.getValue(0)));
550 NodeTys.push_back(MVT::f32);
551 break;
552 case MVT::f64: {
553 SDOperand Lo = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag);
554 SDOperand Hi = DAG.getCopyFromReg(Lo, ARM::R1, MVT::i32, Lo.getValue(2));
555 ResultVals.push_back(DAG.getNode(ARMISD::FMDRR, MVT::f64, Lo, Hi));
556 NodeTys.push_back(MVT::f64);
557 break;
558 }
559 }
560
561 NodeTys.push_back(MVT::Other);
562
563 if (ResultVals.empty())
564 return Chain;
565
566 ResultVals.push_back(Chain);
567 SDOperand Res = DAG.getNode(ISD::MERGE_VALUES, NodeTys, &ResultVals[0],
568 ResultVals.size());
569 return Res.getValue(Op.ResNo);
570}
571
572static SDOperand LowerRET(SDOperand Op, SelectionDAG &DAG) {
573 SDOperand Copy;
574 SDOperand Chain = Op.getOperand(0);
575 switch(Op.getNumOperands()) {
576 default:
577 assert(0 && "Do not know how to return this many arguments!");
578 abort();
579 case 1: {
580 SDOperand LR = DAG.getRegister(ARM::LR, MVT::i32);
581 return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Chain);
582 }
583 case 3:
584 Op = Op.getOperand(1);
585 if (Op.getValueType() == MVT::f32) {
586 Op = DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Op);
587 } else if (Op.getValueType() == MVT::f64) {
588 // Recursively legalize f64 -> i64.
589 Op = DAG.getNode(ISD::BIT_CONVERT, MVT::i64, Op);
590 return DAG.getNode(ISD::RET, MVT::Other, Chain, Op,
591 DAG.getConstant(0, MVT::i32));
592 }
593 Copy = DAG.getCopyToReg(Chain, ARM::R0, Op, SDOperand());
594 if (DAG.getMachineFunction().liveout_empty())
595 DAG.getMachineFunction().addLiveOut(ARM::R0);
596 break;
597 case 5:
598 Copy = DAG.getCopyToReg(Chain, ARM::R1, Op.getOperand(3), SDOperand());
599 Copy = DAG.getCopyToReg(Copy, ARM::R0, Op.getOperand(1), Copy.getValue(1));
600 // If we haven't noted the R0+R1 are live out, do so now.
601 if (DAG.getMachineFunction().liveout_empty()) {
602 DAG.getMachineFunction().addLiveOut(ARM::R0);
603 DAG.getMachineFunction().addLiveOut(ARM::R1);
604 }
605 break;
606 }
607
608 //We must use RET_FLAG instead of BRIND because BRIND doesn't have a flag
609 return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1));
610}
611
612// ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as
613// their target countpart wrapped in the ARMISD::Wrapper node. Suppose N is
614// one of the above mentioned nodes. It has to be wrapped because otherwise
615// Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only
616// be used to form addressing mode. These wrapped nodes will be selected
617// into MOVri.
618static SDOperand LowerConstantPool(SDOperand Op, SelectionDAG &DAG) {
619 MVT::ValueType PtrVT = Op.getValueType();
620 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
621 SDOperand Res;
622 if (CP->isMachineConstantPoolEntry())
623 Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT,
624 CP->getAlignment());
625 else
626 Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT,
627 CP->getAlignment());
628 return DAG.getNode(ARMISD::Wrapper, MVT::i32, Res);
629}
630
631/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol
632/// even in dynamic-no-pic mode.
633static bool GVIsIndirectSymbol(GlobalValue *GV) {
634 return (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
635 (GV->isExternal() && !GV->hasNotBeenReadFromBytecode()));
636}
637
638SDOperand ARMTargetLowering::LowerGlobalAddress(SDOperand Op,
639 SelectionDAG &DAG) {
640 MVT::ValueType PtrVT = getPointerTy();
641 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
642 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
Evan Cheng970a4192007-01-19 19:28:01 +0000643 bool IsIndirect = Subtarget->isTargetDarwin() && GVIsIndirectSymbol(GV);
Evan Chenga8e29892007-01-19 07:51:42 +0000644 SDOperand CPAddr;
645 if (RelocM == Reloc::Static)
646 CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 2);
647 else {
648 unsigned PCAdj = (RelocM != Reloc::PIC_)
649 ? 0 : (Subtarget->isThumb() ? 4 : 8);
650 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex,
651 IsIndirect, PCAdj);
652 CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2);
653 }
654 CPAddr = DAG.getNode(ARMISD::Wrapper, MVT::i32, CPAddr);
655
656 SDOperand Result = DAG.getLoad(PtrVT, DAG.getEntryNode(), CPAddr, NULL, 0);
657 SDOperand Chain = Result.getValue(1);
658
659 if (RelocM == Reloc::PIC_) {
660 SDOperand PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
661 Result = DAG.getNode(ARMISD::PIC_ADD, PtrVT, Result, PICLabel);
662 }
663 if (IsIndirect)
664 Result = DAG.getLoad(PtrVT, Chain, Result, NULL, 0);
665
666 return Result;
667}
668
669static SDOperand LowerVASTART(SDOperand Op, SelectionDAG &DAG,
670 unsigned VarArgsFrameIndex) {
671 // vastart just stores the address of the VarArgsFrameIndex slot into the
672 // memory location argument.
673 MVT::ValueType PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
674 SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT);
675 SrcValueSDNode *SV = cast<SrcValueSDNode>(Op.getOperand(2));
676 return DAG.getStore(Op.getOperand(0), FR, Op.getOperand(1), SV->getValue(),
677 SV->getOffset());
678}
679
680static SDOperand LowerFORMAL_ARGUMENT(SDOperand Op, SelectionDAG &DAG,
681 unsigned *vRegs, unsigned ArgNo,
682 unsigned &NumGPRs, unsigned &ArgOffset) {
683 MachineFunction &MF = DAG.getMachineFunction();
684 MVT::ValueType ObjectVT = Op.getValue(ArgNo).getValueType();
685 SDOperand Root = Op.getOperand(0);
686 std::vector<SDOperand> ArgValues;
687 SSARegMap *RegMap = MF.getSSARegMap();
688
689 static const unsigned GPRArgRegs[] = {
690 ARM::R0, ARM::R1, ARM::R2, ARM::R3
691 };
692
693 unsigned ObjSize = 0;
694 unsigned ObjGPRs = 0;
695 HowToPassArgument(ObjectVT, NumGPRs, ObjSize, ObjGPRs);
696
697 SDOperand ArgValue;
698 if (ObjGPRs == 1) {
699 unsigned VReg = RegMap->createVirtualRegister(&ARM::GPRRegClass);
700 MF.addLiveIn(GPRArgRegs[NumGPRs], VReg);
701 vRegs[NumGPRs] = VReg;
702 ArgValue = DAG.getCopyFromReg(Root, VReg, MVT::i32);
703 if (ObjectVT == MVT::f32)
704 ArgValue = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, ArgValue);
705 } else if (ObjGPRs == 2) {
706 unsigned VReg = RegMap->createVirtualRegister(&ARM::GPRRegClass);
707 MF.addLiveIn(GPRArgRegs[NumGPRs], VReg);
708 vRegs[NumGPRs] = VReg;
709 ArgValue = DAG.getCopyFromReg(Root, VReg, MVT::i32);
710
711 VReg = RegMap->createVirtualRegister(&ARM::GPRRegClass);
712 MF.addLiveIn(GPRArgRegs[NumGPRs+1], VReg);
713 vRegs[NumGPRs+1] = VReg;
714 SDOperand ArgValue2 = DAG.getCopyFromReg(Root, VReg, MVT::i32);
715
716 if (ObjectVT == MVT::i64)
717 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, ArgValue, ArgValue2);
718 else
719 ArgValue = DAG.getNode(ARMISD::FMDRR, MVT::f64, ArgValue, ArgValue2);
720 }
721 NumGPRs += ObjGPRs;
722
723 if (ObjSize) {
724 // If the argument is actually used, emit a load from the right stack
725 // slot.
726 if (!Op.Val->hasNUsesOfValue(0, ArgNo)) {
727 MachineFrameInfo *MFI = MF.getFrameInfo();
728 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
729 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
730 if (ObjGPRs == 0)
731 ArgValue = DAG.getLoad(ObjectVT, Root, FIN, NULL, 0);
732 else {
733 SDOperand ArgValue2 =
734 DAG.getLoad(MVT::i32, Root, FIN, NULL, 0);
735 if (ObjectVT == MVT::i64)
736 ArgValue= DAG.getNode(ISD::BUILD_PAIR, MVT::i64, ArgValue, ArgValue2);
737 else
738 ArgValue= DAG.getNode(ARMISD::FMDRR, MVT::f64, ArgValue, ArgValue2);
739 }
740 } else {
741 // Don't emit a dead load.
742 ArgValue = DAG.getNode(ISD::UNDEF, ObjectVT);
743 }
744
745 ArgOffset += ObjSize; // Move on to the next argument.
746 }
747
748 return ArgValue;
749}
750
751SDOperand
752ARMTargetLowering::LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) {
753 std::vector<SDOperand> ArgValues;
754 SDOperand Root = Op.getOperand(0);
755 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
756 unsigned NumGPRs = 0; // GPRs used for parameter passing.
757 unsigned VRegs[4];
758
759 unsigned NumArgs = Op.Val->getNumValues()-1;
760 for (unsigned ArgNo = 0; ArgNo < NumArgs; ++ArgNo)
761 ArgValues.push_back(LowerFORMAL_ARGUMENT(Op, DAG, VRegs, ArgNo,
762 NumGPRs, ArgOffset));
763
764 bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
765 if (isVarArg) {
766 static const unsigned GPRArgRegs[] = {
767 ARM::R0, ARM::R1, ARM::R2, ARM::R3
768 };
769
770 MachineFunction &MF = DAG.getMachineFunction();
771 SSARegMap *RegMap = MF.getSSARegMap();
772 MachineFrameInfo *MFI = MF.getFrameInfo();
773 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
774 unsigned VARegSaveSize = (4 - NumGPRs) * 4;
775 if (VARegSaveSize) {
776 // If this function is vararg, store any remaining integer argument regs
777 // to their spots on the stack so that they may be loaded by deferencing
778 // the result of va_next.
779 AFI->setVarArgsRegSaveSize(VARegSaveSize);
780 VarArgsFrameIndex = MFI->CreateFixedObject(VARegSaveSize, ArgOffset);
781 SDOperand FIN = DAG.getFrameIndex(VarArgsFrameIndex, getPointerTy());
782
783 SmallVector<SDOperand, 4> MemOps;
784 for (; NumGPRs < 4; ++NumGPRs) {
785 unsigned VReg = RegMap->createVirtualRegister(&ARM::GPRRegClass);
786 MF.addLiveIn(GPRArgRegs[NumGPRs], VReg);
787 SDOperand Val = DAG.getCopyFromReg(Root, VReg, MVT::i32);
788 SDOperand Store = DAG.getStore(Val.getValue(1), Val, FIN, NULL, 0);
789 MemOps.push_back(Store);
790 FIN = DAG.getNode(ISD::ADD, getPointerTy(), FIN,
791 DAG.getConstant(4, getPointerTy()));
792 }
793 if (!MemOps.empty())
794 Root = DAG.getNode(ISD::TokenFactor, MVT::Other,
795 &MemOps[0], MemOps.size());
796 } else
797 // This will point to the next argument passed via stack.
798 VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset);
799 }
800
801 ArgValues.push_back(Root);
802
803 // Return the new list of results.
804 std::vector<MVT::ValueType> RetVT(Op.Val->value_begin(),
805 Op.Val->value_end());
806 return DAG.getNode(ISD::MERGE_VALUES, RetVT, &ArgValues[0], ArgValues.size());
807}
808
809/// isFloatingPointZero - Return true if this is +0.0.
810static bool isFloatingPointZero(SDOperand Op) {
811 if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op))
812 return CFP->isExactlyValue(0.0);
813 else if (ISD::isEXTLoad(Op.Val) || ISD::isNON_EXTLoad(Op.Val)) {
814 // Maybe this has already been legalized into the constant pool?
815 if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) {
816 SDOperand WrapperOp = Op.getOperand(1).getOperand(0);
817 if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp))
818 if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal()))
819 return CFP->isExactlyValue(0.0);
820 }
821 }
822 return false;
823}
824
825static bool isLegalCmpImmediate(int C, bool isThumb) {
826 return ( isThumb && (C & ~255U) == 0) ||
827 (!isThumb && ARM_AM::getSOImmVal(C) != -1);
828}
829
830/// Returns appropriate ARM CMP (cmp) and corresponding condition code for
831/// the given operands.
832static SDOperand getARMCmp(SDOperand LHS, SDOperand RHS, ISD::CondCode CC,
833 SDOperand &ARMCC, SelectionDAG &DAG, bool isThumb) {
834 if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.Val)) {
835 int C = (int)RHSC->getValue();
836 if (!isLegalCmpImmediate(C, isThumb)) {
837 // Constant does not fit, try adjusting it by one?
838 switch (CC) {
839 default: break;
840 case ISD::SETLT:
841 case ISD::SETULT:
842 case ISD::SETGE:
843 case ISD::SETUGE:
844 if (isLegalCmpImmediate(C-1, isThumb)) {
845 switch (CC) {
846 default: break;
847 case ISD::SETLT: CC = ISD::SETLE; break;
848 case ISD::SETULT: CC = ISD::SETULE; break;
849 case ISD::SETGE: CC = ISD::SETGT; break;
850 case ISD::SETUGE: CC = ISD::SETUGT; break;
851 }
852 RHS = DAG.getConstant(C-1, MVT::i32);
853 }
854 break;
855 case ISD::SETLE:
856 case ISD::SETULE:
857 case ISD::SETGT:
858 case ISD::SETUGT:
859 if (isLegalCmpImmediate(C+1, isThumb)) {
860 switch (CC) {
861 default: break;
862 case ISD::SETLE: CC = ISD::SETLT; break;
863 case ISD::SETULE: CC = ISD::SETULT; break;
864 case ISD::SETGT: CC = ISD::SETGE; break;
865 case ISD::SETUGT: CC = ISD::SETUGE; break;
866 }
867 RHS = DAG.getConstant(C+1, MVT::i32);
868 }
869 break;
870 }
871 }
872 }
873
874 ARMCC::CondCodes CondCode = IntCCToARMCC(CC);
875 ARMCC = DAG.getConstant(CondCode, MVT::i32);
876 return DAG.getNode(ARMISD::CMP, MVT::Flag, LHS, RHS);
877}
878
879/// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands.
880static SDOperand getVFPCmp(SDOperand LHS, SDOperand RHS, SelectionDAG &DAG) {
881 SDOperand Cmp;
882 if (!isFloatingPointZero(RHS))
883 Cmp = DAG.getNode(ARMISD::CMPFP, MVT::Flag, LHS, RHS);
884 else
885 Cmp = DAG.getNode(ARMISD::CMPFPw0, MVT::Flag, LHS);
886 return DAG.getNode(ARMISD::FMSTAT, MVT::Flag, Cmp);
887}
888
889static SDOperand LowerSELECT_CC(SDOperand Op, SelectionDAG &DAG,
890 const ARMSubtarget *ST) {
891 MVT::ValueType VT = Op.getValueType();
892 SDOperand LHS = Op.getOperand(0);
893 SDOperand RHS = Op.getOperand(1);
894 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
895 SDOperand TrueVal = Op.getOperand(2);
896 SDOperand FalseVal = Op.getOperand(3);
897
898 if (LHS.getValueType() == MVT::i32) {
899 SDOperand ARMCC;
900 SDOperand Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, ST->isThumb());
901 return DAG.getNode(ARMISD::CMOV, VT, FalseVal, TrueVal, ARMCC, Cmp);
902 }
903
904 ARMCC::CondCodes CondCode, CondCode2;
905 if (FPCCToARMCC(CC, CondCode, CondCode2))
906 std::swap(TrueVal, FalseVal);
907
908 SDOperand ARMCC = DAG.getConstant(CondCode, MVT::i32);
909 SDOperand Cmp = getVFPCmp(LHS, RHS, DAG);
910 SDOperand Result = DAG.getNode(ARMISD::CMOV, VT, FalseVal, TrueVal,
911 ARMCC, Cmp);
912 if (CondCode2 != ARMCC::AL) {
913 SDOperand ARMCC2 = DAG.getConstant(CondCode2, MVT::i32);
914 // FIXME: Needs another CMP because flag can have but one use.
915 SDOperand Cmp2 = getVFPCmp(LHS, RHS, DAG);
916 Result = DAG.getNode(ARMISD::CMOV, VT, Result, TrueVal, ARMCC2, Cmp2);
917 }
918 return Result;
919}
920
921static SDOperand LowerBR_CC(SDOperand Op, SelectionDAG &DAG,
922 const ARMSubtarget *ST) {
923 SDOperand Chain = Op.getOperand(0);
924 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
925 SDOperand LHS = Op.getOperand(2);
926 SDOperand RHS = Op.getOperand(3);
927 SDOperand Dest = Op.getOperand(4);
928
929 if (LHS.getValueType() == MVT::i32) {
930 SDOperand ARMCC;
931 SDOperand Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, ST->isThumb());
932 return DAG.getNode(ARMISD::BRCOND, MVT::Other, Chain, Dest, ARMCC, Cmp);
933 }
934
935 assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64);
936 ARMCC::CondCodes CondCode, CondCode2;
937 if (FPCCToARMCC(CC, CondCode, CondCode2))
938 // Swap the LHS/RHS of the comparison if needed.
939 std::swap(LHS, RHS);
940
941 SDOperand Cmp = getVFPCmp(LHS, RHS, DAG);
942 SDOperand ARMCC = DAG.getConstant(CondCode, MVT::i32);
943 SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Flag);
944 SDOperand Ops[] = { Chain, Dest, ARMCC, Cmp };
945 SDOperand Res = DAG.getNode(ARMISD::BRCOND, VTList, Ops, 4);
946 if (CondCode2 != ARMCC::AL) {
947 ARMCC = DAG.getConstant(CondCode2, MVT::i32);
948 SDOperand Ops[] = { Res, Dest, ARMCC, Res.getValue(1) };
949 Res = DAG.getNode(ARMISD::BRCOND, VTList, Ops, 4);
950 }
951 return Res;
952}
953
954SDOperand ARMTargetLowering::LowerBR_JT(SDOperand Op, SelectionDAG &DAG) {
955 SDOperand Chain = Op.getOperand(0);
956 SDOperand Table = Op.getOperand(1);
957 SDOperand Index = Op.getOperand(2);
958
959 MVT::ValueType PTy = getPointerTy();
960 JumpTableSDNode *JT = cast<JumpTableSDNode>(Table);
961 ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>();
962 SDOperand UId = DAG.getConstant(AFI->createJumpTableUId(), PTy);
963 SDOperand JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy);
964 Table = DAG.getNode(ARMISD::WrapperJT, MVT::i32, JTI, UId);
965 Index = DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(4, PTy));
966 SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table);
967 bool isPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_;
968 Addr = DAG.getLoad(isPIC ? MVT::i32 : PTy, Chain, Addr, NULL, 0);
969 Chain = Addr.getValue(1);
970 if (isPIC)
971 Addr = DAG.getNode(ISD::ADD, PTy, Addr, Table);
972 return DAG.getNode(ARMISD::BR_JT, MVT::Other, Chain, Addr, JTI, UId);
973}
974
975static SDOperand LowerFP_TO_INT(SDOperand Op, SelectionDAG &DAG) {
976 unsigned Opc =
977 Op.getOpcode() == ISD::FP_TO_SINT ? ARMISD::FTOSI : ARMISD::FTOUI;
978 Op = DAG.getNode(Opc, MVT::f32, Op.getOperand(0));
979 return DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Op);
980}
981
982static SDOperand LowerINT_TO_FP(SDOperand Op, SelectionDAG &DAG) {
983 MVT::ValueType VT = Op.getValueType();
984 unsigned Opc =
985 Op.getOpcode() == ISD::SINT_TO_FP ? ARMISD::SITOF : ARMISD::UITOF;
986
987 Op = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, Op.getOperand(0));
988 return DAG.getNode(Opc, VT, Op);
989}
990
991static SDOperand LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) {
992 // Implement fcopysign with a fabs and a conditional fneg.
993 SDOperand Tmp0 = Op.getOperand(0);
994 SDOperand Tmp1 = Op.getOperand(1);
995 MVT::ValueType VT = Op.getValueType();
996 MVT::ValueType SrcVT = Tmp1.getValueType();
997 SDOperand AbsVal = DAG.getNode(ISD::FABS, VT, Tmp0);
998 SDOperand Cmp = getVFPCmp(Tmp1, DAG.getConstantFP(0.0, SrcVT), DAG);
999 SDOperand ARMCC = DAG.getConstant(ARMCC::LT, MVT::i32);
1000 return DAG.getNode(ARMISD::CNEG, VT, AbsVal, AbsVal, ARMCC, Cmp);
1001}
1002
1003static SDOperand LowerBIT_CONVERT(SDOperand Op, SelectionDAG &DAG) {
1004 // Turn f64->i64 into FMRRD.
1005 assert(Op.getValueType() == MVT::i64 &&
1006 Op.getOperand(0).getValueType() == MVT::f64);
1007
1008 Op = Op.getOperand(0);
1009 SDOperand Cvt = DAG.getNode(ARMISD::FMRRD, DAG.getVTList(MVT::i32, MVT::i32),
1010 &Op, 1);
1011
1012 // Merge the pieces into a single i64 value.
1013 return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Cvt, Cvt.getValue(1));
1014}
1015
1016static SDOperand LowerMUL(SDOperand Op, SelectionDAG &DAG) {
1017 // FIXME: All this code is target-independent. Create a new target-indep
1018 // MULHILO node and move this code to the legalizer.
1019 //
1020 assert(Op.getValueType() == MVT::i64 && "Only handles i64 expand right now!");
1021
1022 SDOperand LL = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
1023 DAG.getConstant(0, MVT::i32));
1024 SDOperand RL = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(1),
1025 DAG.getConstant(0, MVT::i32));
1026
1027 const TargetLowering &TL = DAG.getTargetLoweringInfo();
1028 unsigned LHSSB = TL.ComputeNumSignBits(Op.getOperand(0));
1029 unsigned RHSSB = TL.ComputeNumSignBits(Op.getOperand(1));
1030
1031 SDOperand Lo, Hi;
1032 // Figure out how to lower this multiply.
1033 if (LHSSB >= 33 && RHSSB >= 33) {
1034 // If the input values are both sign extended, we can emit a mulhs+mul.
1035 Lo = DAG.getNode(ISD::MUL, MVT::i32, LL, RL);
1036 Hi = DAG.getNode(ISD::MULHS, MVT::i32, LL, RL);
1037 } else if (LHSSB == 32 && RHSSB == 32 &&
1038 TL.MaskedValueIsZero(Op.getOperand(0), 0xFFFFFFFF00000000ULL) &&
1039 TL.MaskedValueIsZero(Op.getOperand(1), 0xFFFFFFFF00000000ULL)) {
1040 // If the inputs are zero extended, use mulhu.
1041 Lo = DAG.getNode(ISD::MUL, MVT::i32, LL, RL);
1042 Hi = DAG.getNode(ISD::MULHU, MVT::i32, LL, RL);
1043 } else {
1044 SDOperand LH = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
1045 DAG.getConstant(1, MVT::i32));
1046 SDOperand RH = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(1),
1047 DAG.getConstant(1, MVT::i32));
1048
1049 // Lo,Hi = umul LHS, RHS.
1050 SDOperand Ops[] = { LL, RL };
1051 SDOperand UMul64 = DAG.getNode(ARMISD::MULHILOU,
1052 DAG.getVTList(MVT::i32, MVT::i32), Ops, 2);
1053 Lo = UMul64;
1054 Hi = UMul64.getValue(1);
1055 RH = DAG.getNode(ISD::MUL, MVT::i32, LL, RH);
1056 LH = DAG.getNode(ISD::MUL, MVT::i32, LH, RL);
1057 Hi = DAG.getNode(ISD::ADD, MVT::i32, Hi, RH);
1058 Hi = DAG.getNode(ISD::ADD, MVT::i32, Hi, LH);
1059 }
1060
1061 // Merge the pieces into a single i64 value.
1062 return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
1063}
1064
1065static SDOperand LowerMULHU(SDOperand Op, SelectionDAG &DAG) {
1066 SDOperand Ops[] = { Op.getOperand(0), Op.getOperand(1) };
1067 return DAG.getNode(ARMISD::MULHILOU,
1068 DAG.getVTList(MVT::i32, MVT::i32), Ops, 2).getValue(1);
1069}
1070
1071static SDOperand LowerMULHS(SDOperand Op, SelectionDAG &DAG) {
1072 SDOperand Ops[] = { Op.getOperand(0), Op.getOperand(1) };
1073 return DAG.getNode(ARMISD::MULHILOS,
1074 DAG.getVTList(MVT::i32, MVT::i32), Ops, 2).getValue(1);
1075}
1076
1077static SDOperand LowerSRx(SDOperand Op, SelectionDAG &DAG,
1078 const ARMSubtarget *ST) {
1079 assert(Op.getValueType() == MVT::i64 &&
1080 (Op.getOpcode() == ISD::SRL || Op.getOpcode() == ISD::SRA) &&
1081 "Unknown shift to lower!");
1082
1083 // We only lower SRA, SRL of 1 here, all others use generic lowering.
1084 if (!isa<ConstantSDNode>(Op.getOperand(1)) ||
1085 cast<ConstantSDNode>(Op.getOperand(1))->getValue() != 1)
1086 return SDOperand();
1087
1088 // If we are in thumb mode, we don't have RRX.
1089 if (ST->isThumb()) return SDOperand();
1090
1091 // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr.
1092 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
1093 DAG.getConstant(0, MVT::i32));
1094 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
1095 DAG.getConstant(1, MVT::i32));
1096
1097 // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and
1098 // captures the result into a carry flag.
1099 unsigned Opc = Op.getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG;
1100 Hi = DAG.getNode(Opc, DAG.getVTList(MVT::i32, MVT::Flag), &Hi, 1);
1101
1102 // The low part is an ARMISD::RRX operand, which shifts the carry in.
1103 Lo = DAG.getNode(ARMISD::RRX, MVT::i32, Lo, Hi.getValue(1));
1104
1105 // Merge the pieces into a single i64 value.
1106 return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
1107}
1108
1109SDOperand ARMTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
1110 switch (Op.getOpcode()) {
1111 default: assert(0 && "Don't know how to custom lower this!"); abort();
1112 case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
1113 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
1114 case ISD::CALL: return LowerCALL(Op, DAG);
1115 case ISD::RET: return LowerRET(Op, DAG);
1116 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG, Subtarget);
1117 case ISD::BR_CC: return LowerBR_CC(Op, DAG, Subtarget);
1118 case ISD::BR_JT: return LowerBR_JT(Op, DAG);
1119 case ISD::VASTART: return LowerVASTART(Op, DAG, VarArgsFrameIndex);
1120 case ISD::SINT_TO_FP:
1121 case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG);
1122 case ISD::FP_TO_SINT:
1123 case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG);
1124 case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG);
1125 case ISD::BIT_CONVERT: return LowerBIT_CONVERT(Op, DAG);
1126 case ISD::MUL: return LowerMUL(Op, DAG);
1127 case ISD::MULHU: return LowerMULHU(Op, DAG);
1128 case ISD::MULHS: return LowerMULHS(Op, DAG);
1129 case ISD::SRL:
1130 case ISD::SRA: return LowerSRx(Op, DAG, Subtarget);
1131 case ISD::FORMAL_ARGUMENTS:
1132 return LowerFORMAL_ARGUMENTS(Op, DAG);
Nate Begemanbcc5f362007-01-29 22:58:52 +00001133 case ISD::RETURNADDR: break;
1134 case ISD::FRAMEADDR: break;
Evan Chenga8e29892007-01-19 07:51:42 +00001135 }
Nate Begemanbcc5f362007-01-29 22:58:52 +00001136 return SDOperand();
Evan Chenga8e29892007-01-19 07:51:42 +00001137}
1138
1139//===----------------------------------------------------------------------===//
1140// ARM Scheduler Hooks
1141//===----------------------------------------------------------------------===//
1142
1143MachineBasicBlock *
1144ARMTargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI,
1145 MachineBasicBlock *BB) {
1146 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
1147 switch (MI->getOpcode()) {
1148 default: assert(false && "Unexpected instr type to insert");
1149 case ARM::tMOVCCr: {
1150 // To "insert" a SELECT_CC instruction, we actually have to insert the
1151 // diamond control-flow pattern. The incoming instruction knows the
1152 // destination vreg to set, the condition code register to branch on, the
1153 // true/false values to select between, and a branch opcode to use.
1154 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1155 ilist<MachineBasicBlock>::iterator It = BB;
1156 ++It;
1157
1158 // thisMBB:
1159 // ...
1160 // TrueVal = ...
1161 // cmpTY ccX, r1, r2
1162 // bCC copy1MBB
1163 // fallthrough --> copy0MBB
1164 MachineBasicBlock *thisMBB = BB;
1165 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1166 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1167 BuildMI(BB, TII->get(ARM::tBcc)).addMBB(sinkMBB)
1168 .addImm(MI->getOperand(3).getImm());
1169 MachineFunction *F = BB->getParent();
1170 F->getBasicBlockList().insert(It, copy0MBB);
1171 F->getBasicBlockList().insert(It, sinkMBB);
1172 // Update machine-CFG edges by first adding all successors of the current
1173 // block to the new block which will contain the Phi node for the select.
1174 for(MachineBasicBlock::succ_iterator i = BB->succ_begin(),
1175 e = BB->succ_end(); i != e; ++i)
1176 sinkMBB->addSuccessor(*i);
1177 // Next, remove all successors of the current block, and add the true
1178 // and fallthrough blocks as its successors.
1179 while(!BB->succ_empty())
1180 BB->removeSuccessor(BB->succ_begin());
1181 BB->addSuccessor(copy0MBB);
1182 BB->addSuccessor(sinkMBB);
1183
1184 // copy0MBB:
1185 // %FalseValue = ...
1186 // # fallthrough to sinkMBB
1187 BB = copy0MBB;
1188
1189 // Update machine-CFG edges
1190 BB->addSuccessor(sinkMBB);
1191
1192 // sinkMBB:
1193 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1194 // ...
1195 BB = sinkMBB;
1196 BuildMI(BB, TII->get(ARM::PHI), MI->getOperand(0).getReg())
1197 .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
1198 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
1199
1200 delete MI; // The pseudo instruction is gone now.
1201 return BB;
1202 }
1203 }
1204}
1205
1206//===----------------------------------------------------------------------===//
1207// ARM Optimization Hooks
1208//===----------------------------------------------------------------------===//
1209
1210/// isLegalAddressImmediate - Return true if the integer value or
1211/// GlobalValue can be used as the offset of the target addressing mode.
1212bool ARMTargetLowering::isLegalAddressImmediate(int64_t V) const {
1213 // ARM allows a 12-bit immediate field.
1214 return V == V & ((1LL << 12) - 1);
1215}
1216
1217bool ARMTargetLowering::isLegalAddressImmediate(GlobalValue *GV) const {
1218 return false;
1219}
1220
1221static bool getIndexedAddressParts(SDNode *Ptr, MVT::ValueType VT,
1222 bool isSEXTLoad, SDOperand &Base,
1223 SDOperand &Offset, bool &isInc,
1224 SelectionDAG &DAG) {
1225 if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB)
1226 return false;
1227
1228 if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) {
1229 // AddressingMode 3
1230 Base = Ptr->getOperand(0);
1231 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) {
1232 int RHSC = (int)RHS->getValue();
1233 if (RHSC < 0 && RHSC > -256) {
1234 isInc = false;
1235 Offset = DAG.getConstant(-RHSC, RHS->getValueType(0));
1236 return true;
1237 }
1238 }
1239 isInc = (Ptr->getOpcode() == ISD::ADD);
1240 Offset = Ptr->getOperand(1);
1241 return true;
1242 } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) {
1243 // AddressingMode 2
1244 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) {
1245 int RHSC = (int)RHS->getValue();
1246 if (RHSC < 0 && RHSC > -0x1000) {
1247 isInc = false;
1248 Offset = DAG.getConstant(-RHSC, RHS->getValueType(0));
1249 Base = Ptr->getOperand(0);
1250 return true;
1251 }
1252 }
1253
1254 if (Ptr->getOpcode() == ISD::ADD) {
1255 isInc = true;
1256 ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0));
1257 if (ShOpcVal != ARM_AM::no_shift) {
1258 Base = Ptr->getOperand(1);
1259 Offset = Ptr->getOperand(0);
1260 } else {
1261 Base = Ptr->getOperand(0);
1262 Offset = Ptr->getOperand(1);
1263 }
1264 return true;
1265 }
1266
1267 isInc = (Ptr->getOpcode() == ISD::ADD);
1268 Base = Ptr->getOperand(0);
1269 Offset = Ptr->getOperand(1);
1270 return true;
1271 }
1272
1273 // FIXME: Use FLDM / FSTM to emulate indexed FP load / store.
1274 return false;
1275}
1276
1277/// getPreIndexedAddressParts - returns true by value, base pointer and
1278/// offset pointer and addressing mode by reference if the node's address
1279/// can be legally represented as pre-indexed load / store address.
1280bool
1281ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDOperand &Base,
1282 SDOperand &Offset,
1283 ISD::MemIndexedMode &AM,
1284 SelectionDAG &DAG) {
1285 if (Subtarget->isThumb())
1286 return false;
1287
1288 MVT::ValueType VT;
1289 SDOperand Ptr;
1290 bool isSEXTLoad = false;
1291 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
1292 Ptr = LD->getBasePtr();
1293 VT = LD->getLoadedVT();
1294 isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD;
1295 } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
1296 Ptr = ST->getBasePtr();
1297 VT = ST->getStoredVT();
1298 } else
1299 return false;
1300
1301 bool isInc;
1302 bool isLegal = getIndexedAddressParts(Ptr.Val, VT, isSEXTLoad, Base, Offset,
1303 isInc, DAG);
1304 if (isLegal) {
1305 AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC;
1306 return true;
1307 }
1308 return false;
1309}
1310
1311/// getPostIndexedAddressParts - returns true by value, base pointer and
1312/// offset pointer and addressing mode by reference if this node can be
1313/// combined with a load / store to form a post-indexed load / store.
1314bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
1315 SDOperand &Base,
1316 SDOperand &Offset,
1317 ISD::MemIndexedMode &AM,
1318 SelectionDAG &DAG) {
1319 if (Subtarget->isThumb())
1320 return false;
1321
1322 MVT::ValueType VT;
1323 SDOperand Ptr;
1324 bool isSEXTLoad = false;
1325 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
1326 VT = LD->getLoadedVT();
1327 isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD;
1328 } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
1329 VT = ST->getStoredVT();
1330 } else
1331 return false;
1332
1333 bool isInc;
1334 bool isLegal = getIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset,
1335 isInc, DAG);
1336 if (isLegal) {
1337 AM = isInc ? ISD::POST_INC : ISD::POST_DEC;
1338 return true;
1339 }
1340 return false;
1341}
1342
1343void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
1344 uint64_t Mask,
1345 uint64_t &KnownZero,
1346 uint64_t &KnownOne,
1347 unsigned Depth) const {
1348 KnownZero = 0;
1349 KnownOne = 0;
1350 switch (Op.getOpcode()) {
1351 default: break;
1352 case ARMISD::CMOV: {
1353 // Bits are known zero/one if known on the LHS and RHS.
1354 ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1);
1355 if (KnownZero == 0 && KnownOne == 0) return;
1356
1357 uint64_t KnownZeroRHS, KnownOneRHS;
1358 ComputeMaskedBits(Op.getOperand(1), Mask,
1359 KnownZeroRHS, KnownOneRHS, Depth+1);
1360 KnownZero &= KnownZeroRHS;
1361 KnownOne &= KnownOneRHS;
1362 return;
1363 }
1364 }
1365}
1366
1367//===----------------------------------------------------------------------===//
1368// ARM Inline Assembly Support
1369//===----------------------------------------------------------------------===//
1370
1371/// getConstraintType - Given a constraint letter, return the type of
1372/// constraint it is for this target.
1373ARMTargetLowering::ConstraintType
1374ARMTargetLowering::getConstraintType(char ConstraintLetter) const {
1375 switch (ConstraintLetter) {
1376 case 'l':
1377 return C_RegisterClass;
1378 default: return TargetLowering::getConstraintType(ConstraintLetter);
1379 }
1380}
1381
1382std::pair<unsigned, const TargetRegisterClass*>
1383ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
1384 MVT::ValueType VT) const {
1385 if (Constraint.size() == 1) {
1386 // GCC RS6000 Constraint Letters
1387 switch (Constraint[0]) {
1388 case 'l':
1389 // FIXME: in thumb mode, 'l' is only low-regs.
1390 // FALL THROUGH.
1391 case 'r':
1392 return std::make_pair(0U, ARM::GPRRegisterClass);
1393 break;
1394 }
1395 }
1396 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
1397}
1398
1399std::vector<unsigned> ARMTargetLowering::
1400getRegClassForInlineAsmConstraint(const std::string &Constraint,
1401 MVT::ValueType VT) const {
1402 if (Constraint.size() != 1)
1403 return std::vector<unsigned>();
1404
1405 switch (Constraint[0]) { // GCC ARM Constraint Letters
1406 default: break;
1407 case 'l':
1408 case 'r':
1409 return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3,
1410 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
1411 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
1412 ARM::R12, ARM::LR, 0);
1413 }
1414
1415 return std::vector<unsigned>();
1416}