blob: b19c1d7c7d307efc743bf86dd5cc4f10d5cd4588 [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===-- ARMISelLowering.cpp - ARM DAG Lowering Implementation -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
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"
Evan Cheng27707472007-03-16 08:43:56 +000025#include "llvm/Instruction.h"
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +000026#include "llvm/Intrinsics.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000027#include "llvm/GlobalValue.h"
Evan Chenga8e29892007-01-19 07:51:42 +000028#include "llvm/CodeGen/MachineBasicBlock.h"
29#include "llvm/CodeGen/MachineFrameInfo.h"
30#include "llvm/CodeGen/MachineFunction.h"
31#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000032#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Chenga8e29892007-01-19 07:51:42 +000033#include "llvm/CodeGen/SelectionDAG.h"
Evan Chengb6ab2542007-01-31 08:40:13 +000034#include "llvm/Target/TargetOptions.h"
Evan Chenga8e29892007-01-19 07:51:42 +000035#include "llvm/ADT/VectorExtras.h"
Evan Chengb01fad62007-03-12 23:30:29 +000036#include "llvm/Support/MathExtras.h"
Evan Chenga8e29892007-01-19 07:51:42 +000037using namespace llvm;
38
39ARMTargetLowering::ARMTargetLowering(TargetMachine &TM)
40 : TargetLowering(TM), ARMPCLabelIndex(0) {
41 Subtarget = &TM.getSubtarget<ARMSubtarget>();
42
Evan Chengb1df8f22007-04-27 08:15:43 +000043 if (Subtarget->isTargetDarwin()) {
44 // Don't have these.
45 setLibcallName(RTLIB::UINTTOFP_I64_F32, NULL);
46 setLibcallName(RTLIB::UINTTOFP_I64_F64, NULL);
Evan Chenga8e29892007-01-19 07:51:42 +000047
Evan Chengb1df8f22007-04-27 08:15:43 +000048 // Uses VFP for Thumb libfuncs if available.
49 if (Subtarget->isThumb() && Subtarget->hasVFP2()) {
50 // Single-precision floating-point arithmetic.
51 setLibcallName(RTLIB::ADD_F32, "__addsf3vfp");
52 setLibcallName(RTLIB::SUB_F32, "__subsf3vfp");
53 setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp");
54 setLibcallName(RTLIB::DIV_F32, "__divsf3vfp");
Evan Chenga8e29892007-01-19 07:51:42 +000055
Evan Chengb1df8f22007-04-27 08:15:43 +000056 // Double-precision floating-point arithmetic.
57 setLibcallName(RTLIB::ADD_F64, "__adddf3vfp");
58 setLibcallName(RTLIB::SUB_F64, "__subdf3vfp");
59 setLibcallName(RTLIB::MUL_F64, "__muldf3vfp");
60 setLibcallName(RTLIB::DIV_F64, "__divdf3vfp");
Evan Cheng193f8502007-01-31 09:30:58 +000061
Evan Chengb1df8f22007-04-27 08:15:43 +000062 // Single-precision comparisons.
63 setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp");
64 setLibcallName(RTLIB::UNE_F32, "__nesf2vfp");
65 setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp");
66 setLibcallName(RTLIB::OLE_F32, "__lesf2vfp");
67 setLibcallName(RTLIB::OGE_F32, "__gesf2vfp");
68 setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp");
69 setLibcallName(RTLIB::UO_F32, "__unordsf2vfp");
70 setLibcallName(RTLIB::O_F32, "__unordsf2vfp");
Evan Chenga8e29892007-01-19 07:51:42 +000071
Evan Chengb1df8f22007-04-27 08:15:43 +000072 setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE);
73 setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE);
74 setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE);
75 setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE);
76 setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE);
77 setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE);
78 setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE);
79 setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ);
Evan Cheng193f8502007-01-31 09:30:58 +000080
Evan Chengb1df8f22007-04-27 08:15:43 +000081 // Double-precision comparisons.
82 setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp");
83 setLibcallName(RTLIB::UNE_F64, "__nedf2vfp");
84 setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp");
85 setLibcallName(RTLIB::OLE_F64, "__ledf2vfp");
86 setLibcallName(RTLIB::OGE_F64, "__gedf2vfp");
87 setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp");
88 setLibcallName(RTLIB::UO_F64, "__unorddf2vfp");
89 setLibcallName(RTLIB::O_F64, "__unorddf2vfp");
Evan Chenga8e29892007-01-19 07:51:42 +000090
Evan Chengb1df8f22007-04-27 08:15:43 +000091 setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE);
92 setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE);
93 setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE);
94 setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE);
95 setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE);
96 setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE);
97 setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE);
98 setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ);
Evan Chenga8e29892007-01-19 07:51:42 +000099
Evan Chengb1df8f22007-04-27 08:15:43 +0000100 // Floating-point to integer conversions.
101 // i64 conversions are done via library routines even when generating VFP
102 // instructions, so use the same ones.
103 setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp");
104 setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp");
105 setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp");
106 setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp");
Evan Chenga8e29892007-01-19 07:51:42 +0000107
Evan Chengb1df8f22007-04-27 08:15:43 +0000108 // Conversions between floating types.
109 setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp");
110 setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp");
111
112 // Integer to floating-point conversions.
113 // i64 conversions are done via library routines even when generating VFP
114 // instructions, so use the same ones.
115 // FIXME: There appears to be some naming inconsistency in ARM libgcc: e.g.
116 // __floatunsidf vs. __floatunssidfvfp.
117 setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp");
118 setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp");
119 setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp");
120 setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp");
121 }
Evan Chenga8e29892007-01-19 07:51:42 +0000122 }
123
124 addRegisterClass(MVT::i32, ARM::GPRRegisterClass);
Evan Chengb6ab2542007-01-31 08:40:13 +0000125 if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb()) {
Evan Chenga8e29892007-01-19 07:51:42 +0000126 addRegisterClass(MVT::f32, ARM::SPRRegisterClass);
127 addRegisterClass(MVT::f64, ARM::DPRRegisterClass);
Chris Lattnerddf89562008-01-17 19:59:44 +0000128
129 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000130 }
Evan Cheng9f8cbd12007-05-18 00:19:34 +0000131 computeRegisterProperties();
Evan Chenga8e29892007-01-19 07:51:42 +0000132
133 // ARM does not have f32 extending load.
134 setLoadXAction(ISD::EXTLOAD, MVT::f32, Expand);
135
Duncan Sandsf9c98e62008-01-23 20:39:46 +0000136 // ARM does not have i1 sign extending load.
137 setLoadXAction(ISD::SEXTLOAD, MVT::i1, Promote);
138
Evan Chenga8e29892007-01-19 07:51:42 +0000139 // ARM supports all 4 flavors of integer indexed load / store.
140 for (unsigned im = (unsigned)ISD::PRE_INC;
141 im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) {
142 setIndexedLoadAction(im, MVT::i1, Legal);
143 setIndexedLoadAction(im, MVT::i8, Legal);
144 setIndexedLoadAction(im, MVT::i16, Legal);
145 setIndexedLoadAction(im, MVT::i32, Legal);
146 setIndexedStoreAction(im, MVT::i1, Legal);
147 setIndexedStoreAction(im, MVT::i8, Legal);
148 setIndexedStoreAction(im, MVT::i16, Legal);
149 setIndexedStoreAction(im, MVT::i32, Legal);
150 }
151
152 // i64 operation support.
153 if (Subtarget->isThumb()) {
154 setOperationAction(ISD::MUL, MVT::i64, Expand);
155 setOperationAction(ISD::MULHU, MVT::i32, Expand);
156 setOperationAction(ISD::MULHS, MVT::i32, Expand);
Dan Gohman525178c2007-10-08 18:33:35 +0000157 setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand);
158 setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000159 } else {
Dan Gohman525178c2007-10-08 18:33:35 +0000160 setOperationAction(ISD::MUL, MVT::i64, Expand);
161 setOperationAction(ISD::MULHU, MVT::i32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000162 if (!Subtarget->hasV6Ops())
Dan Gohman525178c2007-10-08 18:33:35 +0000163 setOperationAction(ISD::MULHS, MVT::i32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000164 }
165 setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
166 setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand);
167 setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand);
168 setOperationAction(ISD::SRL, MVT::i64, Custom);
169 setOperationAction(ISD::SRA, MVT::i64, Custom);
170
171 // ARM does not have ROTL.
172 setOperationAction(ISD::ROTL, MVT::i32, Expand);
173 setOperationAction(ISD::CTTZ , MVT::i32, Expand);
174 setOperationAction(ISD::CTPOP, MVT::i32, Expand);
Evan Chengb0636152007-02-01 23:34:03 +0000175 if (!Subtarget->hasV5TOps() || Subtarget->isThumb())
Evan Chenga8e29892007-01-19 07:51:42 +0000176 setOperationAction(ISD::CTLZ, MVT::i32, Expand);
177
Lauro Ramos Venancio368f20f2007-03-16 22:54:16 +0000178 // Only ARMv6 has BSWAP.
179 if (!Subtarget->hasV6Ops())
Chris Lattner1719e132007-03-20 02:25:53 +0000180 setOperationAction(ISD::BSWAP, MVT::i32, Expand);
Lauro Ramos Venancio368f20f2007-03-16 22:54:16 +0000181
Evan Chenga8e29892007-01-19 07:51:42 +0000182 // These are expanded into libcalls.
183 setOperationAction(ISD::SDIV, MVT::i32, Expand);
184 setOperationAction(ISD::UDIV, MVT::i32, Expand);
185 setOperationAction(ISD::SREM, MVT::i32, Expand);
186 setOperationAction(ISD::UREM, MVT::i32, Expand);
Dan Gohman525178c2007-10-08 18:33:35 +0000187 setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
188 setOperationAction(ISD::UDIVREM, MVT::i32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000189
190 // Support label based line numbers.
Dan Gohman7f460202008-06-30 20:59:49 +0000191 setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000192 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000193
194 setOperationAction(ISD::RET, MVT::Other, Custom);
195 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
196 setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +0000197 setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000198 setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom);
Evan Chenga8e29892007-01-19 07:51:42 +0000199
Evan Chenga8e29892007-01-19 07:51:42 +0000200 // Use the default implementation.
Nate Begeman48a65512008-02-04 21:44:06 +0000201 setOperationAction(ISD::VASTART , MVT::Other, Custom);
Evan Chenga8e29892007-01-19 07:51:42 +0000202 setOperationAction(ISD::VAARG , MVT::Other, Expand);
203 setOperationAction(ISD::VACOPY , MVT::Other, Expand);
204 setOperationAction(ISD::VAEND , MVT::Other, Expand);
205 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
206 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
207 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand);
Andrew Lenharthd497d9f2008-02-16 14:46:26 +0000208 setOperationAction(ISD::MEMBARRIER , MVT::Other, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000209
210 if (!Subtarget->hasV6Ops()) {
211 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
212 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand);
213 }
214 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
215
Evan Chengb6ab2542007-01-31 08:40:13 +0000216 if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb())
Evan Chenga8e29892007-01-19 07:51:42 +0000217 // Turn f64->i64 into FMRRD iff target supports vfp2.
218 setOperationAction(ISD::BIT_CONVERT, MVT::i64, Custom);
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +0000219
220 // We want to custom lower some of our intrinsics.
221 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
222
Evan Chenga8e29892007-01-19 07:51:42 +0000223 setOperationAction(ISD::SETCC , MVT::i32, Expand);
224 setOperationAction(ISD::SETCC , MVT::f32, Expand);
225 setOperationAction(ISD::SETCC , MVT::f64, Expand);
226 setOperationAction(ISD::SELECT , MVT::i32, Expand);
227 setOperationAction(ISD::SELECT , MVT::f32, Expand);
228 setOperationAction(ISD::SELECT , MVT::f64, Expand);
229 setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
230 setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
231 setOperationAction(ISD::SELECT_CC, MVT::f64, Custom);
232
233 setOperationAction(ISD::BRCOND , MVT::Other, Expand);
234 setOperationAction(ISD::BR_CC , MVT::i32, Custom);
235 setOperationAction(ISD::BR_CC , MVT::f32, Custom);
236 setOperationAction(ISD::BR_CC , MVT::f64, Custom);
237 setOperationAction(ISD::BR_JT , MVT::Other, Custom);
238
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000239 // We don't support sin/cos/fmod/copysign/pow
Evan Chenga8e29892007-01-19 07:51:42 +0000240 setOperationAction(ISD::FSIN , MVT::f64, Expand);
241 setOperationAction(ISD::FSIN , MVT::f32, Expand);
242 setOperationAction(ISD::FCOS , MVT::f32, Expand);
243 setOperationAction(ISD::FCOS , MVT::f64, Expand);
244 setOperationAction(ISD::FREM , MVT::f64, Expand);
245 setOperationAction(ISD::FREM , MVT::f32, Expand);
Evan Cheng110cf482008-04-01 01:50:16 +0000246 if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb()) {
247 setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom);
248 setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom);
249 }
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000250 setOperationAction(ISD::FPOW , MVT::f64, Expand);
251 setOperationAction(ISD::FPOW , MVT::f32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000252
253 // int <-> fp are custom expanded into bit_convert + ARMISD ops.
Evan Cheng110cf482008-04-01 01:50:16 +0000254 if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb()) {
255 setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
256 setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom);
257 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
258 setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
259 }
Evan Chenga8e29892007-01-19 07:51:42 +0000260
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +0000261 // We have target-specific dag combine patterns for the following nodes:
262 // ARMISD::FMRRD - No need to call setTargetDAGCombine
263
Evan Chenga8e29892007-01-19 07:51:42 +0000264 setStackPointerRegisterToSaveRestore(ARM::SP);
Evan Chenga8e29892007-01-19 07:51:42 +0000265 setSchedulingPreference(SchedulingForRegPressure);
Evan Cheng9f8cbd12007-05-18 00:19:34 +0000266 setIfCvtBlockSizeLimit(Subtarget->isThumb() ? 0 : 10);
Evan Cheng97e604e2007-06-19 23:55:02 +0000267 setIfCvtDupBlockSizeLimit(Subtarget->isThumb() ? 0 : 2);
Dale Johannesen8dd86c12007-05-17 21:31:21 +0000268
269 maxStoresPerMemcpy = 1; //// temporary - rewrite interface to use type
Evan Chenga8e29892007-01-19 07:51:42 +0000270}
271
272
273const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const {
274 switch (Opcode) {
275 default: return 0;
276 case ARMISD::Wrapper: return "ARMISD::Wrapper";
Evan Chenga8e29892007-01-19 07:51:42 +0000277 case ARMISD::WrapperJT: return "ARMISD::WrapperJT";
278 case ARMISD::CALL: return "ARMISD::CALL";
Evan Cheng277f0742007-06-19 21:05:09 +0000279 case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED";
Evan Chenga8e29892007-01-19 07:51:42 +0000280 case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK";
281 case ARMISD::tCALL: return "ARMISD::tCALL";
282 case ARMISD::BRCOND: return "ARMISD::BRCOND";
283 case ARMISD::BR_JT: return "ARMISD::BR_JT";
284 case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG";
285 case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD";
286 case ARMISD::CMP: return "ARMISD::CMP";
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000287 case ARMISD::CMPNZ: return "ARMISD::CMPNZ";
Evan Chenga8e29892007-01-19 07:51:42 +0000288 case ARMISD::CMPFP: return "ARMISD::CMPFP";
289 case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0";
290 case ARMISD::FMSTAT: return "ARMISD::FMSTAT";
291 case ARMISD::CMOV: return "ARMISD::CMOV";
292 case ARMISD::CNEG: return "ARMISD::CNEG";
293
294 case ARMISD::FTOSI: return "ARMISD::FTOSI";
295 case ARMISD::FTOUI: return "ARMISD::FTOUI";
296 case ARMISD::SITOF: return "ARMISD::SITOF";
297 case ARMISD::UITOF: return "ARMISD::UITOF";
Evan Chenga8e29892007-01-19 07:51:42 +0000298
299 case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG";
300 case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG";
301 case ARMISD::RRX: return "ARMISD::RRX";
302
303 case ARMISD::FMRRD: return "ARMISD::FMRRD";
304 case ARMISD::FMDRR: return "ARMISD::FMDRR";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000305
306 case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER";
Evan Chenga8e29892007-01-19 07:51:42 +0000307 }
308}
309
310//===----------------------------------------------------------------------===//
311// Lowering Code
312//===----------------------------------------------------------------------===//
313
314
315/// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC
316static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) {
317 switch (CC) {
318 default: assert(0 && "Unknown condition code!");
319 case ISD::SETNE: return ARMCC::NE;
320 case ISD::SETEQ: return ARMCC::EQ;
321 case ISD::SETGT: return ARMCC::GT;
322 case ISD::SETGE: return ARMCC::GE;
323 case ISD::SETLT: return ARMCC::LT;
324 case ISD::SETLE: return ARMCC::LE;
325 case ISD::SETUGT: return ARMCC::HI;
326 case ISD::SETUGE: return ARMCC::HS;
327 case ISD::SETULT: return ARMCC::LO;
328 case ISD::SETULE: return ARMCC::LS;
329 }
330}
331
332/// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. It
333/// returns true if the operands should be inverted to form the proper
334/// comparison.
335static bool FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode,
336 ARMCC::CondCodes &CondCode2) {
337 bool Invert = false;
338 CondCode2 = ARMCC::AL;
339 switch (CC) {
340 default: assert(0 && "Unknown FP condition!");
341 case ISD::SETEQ:
342 case ISD::SETOEQ: CondCode = ARMCC::EQ; break;
343 case ISD::SETGT:
344 case ISD::SETOGT: CondCode = ARMCC::GT; break;
345 case ISD::SETGE:
346 case ISD::SETOGE: CondCode = ARMCC::GE; break;
347 case ISD::SETOLT: CondCode = ARMCC::MI; break;
348 case ISD::SETOLE: CondCode = ARMCC::GT; Invert = true; break;
349 case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break;
350 case ISD::SETO: CondCode = ARMCC::VC; break;
351 case ISD::SETUO: CondCode = ARMCC::VS; break;
352 case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break;
353 case ISD::SETUGT: CondCode = ARMCC::HI; break;
354 case ISD::SETUGE: CondCode = ARMCC::PL; break;
355 case ISD::SETLT:
356 case ISD::SETULT: CondCode = ARMCC::LT; break;
357 case ISD::SETLE:
358 case ISD::SETULE: CondCode = ARMCC::LE; break;
359 case ISD::SETNE:
360 case ISD::SETUNE: CondCode = ARMCC::NE; break;
361 }
362 return Invert;
363}
364
365static void
Duncan Sands83ec4b62008-06-06 12:08:01 +0000366HowToPassArgument(MVT ObjectVT, unsigned NumGPRs,
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000367 unsigned StackOffset, unsigned &NeededGPRs,
368 unsigned &NeededStackSize, unsigned &GPRPad,
Duncan Sands276dcbd2008-03-21 09:14:45 +0000369 unsigned &StackPad, ISD::ArgFlagsTy Flags) {
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000370 NeededStackSize = 0;
371 NeededGPRs = 0;
372 StackPad = 0;
373 GPRPad = 0;
Duncan Sands276dcbd2008-03-21 09:14:45 +0000374 unsigned align = Flags.getOrigAlign();
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000375 GPRPad = NumGPRs % ((align + 3)/4);
376 StackPad = StackOffset % align;
377 unsigned firstGPR = NumGPRs + GPRPad;
Duncan Sands83ec4b62008-06-06 12:08:01 +0000378 switch (ObjectVT.getSimpleVT()) {
Evan Chenga8e29892007-01-19 07:51:42 +0000379 default: assert(0 && "Unhandled argument type!");
380 case MVT::i32:
381 case MVT::f32:
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000382 if (firstGPR < 4)
383 NeededGPRs = 1;
Evan Chenga8e29892007-01-19 07:51:42 +0000384 else
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000385 NeededStackSize = 4;
Evan Chenga8e29892007-01-19 07:51:42 +0000386 break;
387 case MVT::i64:
388 case MVT::f64:
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000389 if (firstGPR < 3)
390 NeededGPRs = 2;
391 else if (firstGPR == 3) {
392 NeededGPRs = 1;
393 NeededStackSize = 4;
Evan Chenga8e29892007-01-19 07:51:42 +0000394 } else
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000395 NeededStackSize = 8;
Evan Chenga8e29892007-01-19 07:51:42 +0000396 }
397}
398
Evan Chengfc403422007-02-03 08:53:01 +0000399/// LowerCALL - Lowering a ISD::CALL node into a callseq_start <-
400/// ARMISD:CALL <- callseq_end chain. Also add input and output parameter
401/// nodes.
Evan Chenga8e29892007-01-19 07:51:42 +0000402SDOperand ARMTargetLowering::LowerCALL(SDOperand Op, SelectionDAG &DAG) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000403 MVT RetVT= Op.Val->getValueType(0);
Evan Chenga8e29892007-01-19 07:51:42 +0000404 SDOperand Chain = Op.getOperand(0);
405 unsigned CallConv = cast<ConstantSDNode>(Op.getOperand(1))->getValue();
406 assert((CallConv == CallingConv::C ||
Evan Chenga8e29892007-01-19 07:51:42 +0000407 CallConv == CallingConv::Fast) && "unknown calling convention");
408 SDOperand Callee = Op.getOperand(4);
409 unsigned NumOps = (Op.getNumOperands() - 5) / 2;
410 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
411 unsigned NumGPRs = 0; // GPRs used for parameter passing.
412
413 // Count how many bytes are to be pushed on the stack.
414 unsigned NumBytes = 0;
415
416 // Add up all the space actually used.
417 for (unsigned i = 0; i < NumOps; ++i) {
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000418 unsigned ObjSize;
419 unsigned ObjGPRs;
420 unsigned StackPad;
421 unsigned GPRPad;
Duncan Sands83ec4b62008-06-06 12:08:01 +0000422 MVT ObjectVT = Op.getOperand(5+2*i).getValueType();
Duncan Sands276dcbd2008-03-21 09:14:45 +0000423 ISD::ArgFlagsTy Flags =
424 cast<ARG_FLAGSSDNode>(Op.getOperand(5+2*i+1))->getArgFlags();
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000425 HowToPassArgument(ObjectVT, NumGPRs, NumBytes, ObjGPRs, ObjSize,
426 GPRPad, StackPad, Flags);
427 NumBytes += ObjSize + StackPad;
428 NumGPRs += ObjGPRs + GPRPad;
Evan Chenga8e29892007-01-19 07:51:42 +0000429 }
430
431 // Adjust the stack pointer for the new arguments...
432 // These operations are automatically eliminated by the prolog/epilog pass
433 Chain = DAG.getCALLSEQ_START(Chain,
434 DAG.getConstant(NumBytes, MVT::i32));
435
436 SDOperand StackPtr = DAG.getRegister(ARM::SP, MVT::i32);
437
438 static const unsigned GPRArgRegs[] = {
439 ARM::R0, ARM::R1, ARM::R2, ARM::R3
440 };
441
442 NumGPRs = 0;
443 std::vector<std::pair<unsigned, SDOperand> > RegsToPass;
444 std::vector<SDOperand> MemOpChains;
445 for (unsigned i = 0; i != NumOps; ++i) {
446 SDOperand Arg = Op.getOperand(5+2*i);
Duncan Sands276dcbd2008-03-21 09:14:45 +0000447 ISD::ArgFlagsTy Flags =
448 cast<ARG_FLAGSSDNode>(Op.getOperand(5+2*i+1))->getArgFlags();
Duncan Sands83ec4b62008-06-06 12:08:01 +0000449 MVT ArgVT = Arg.getValueType();
Evan Chenga8e29892007-01-19 07:51:42 +0000450
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000451 unsigned ObjSize;
452 unsigned ObjGPRs;
453 unsigned GPRPad;
454 unsigned StackPad;
455 HowToPassArgument(ArgVT, NumGPRs, ArgOffset, ObjGPRs,
456 ObjSize, GPRPad, StackPad, Flags);
457 NumGPRs += GPRPad;
458 ArgOffset += StackPad;
Evan Chenga8e29892007-01-19 07:51:42 +0000459 if (ObjGPRs > 0) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000460 switch (ArgVT.getSimpleVT()) {
Evan Chenga8e29892007-01-19 07:51:42 +0000461 default: assert(0 && "Unexpected ValueType for argument!");
462 case MVT::i32:
463 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs], Arg));
464 break;
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000465 case MVT::f32:
Evan Chenga8e29892007-01-19 07:51:42 +0000466 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs],
467 DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Arg)));
468 break;
469 case MVT::i64: {
470 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Arg,
471 DAG.getConstant(0, getPointerTy()));
472 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Arg,
473 DAG.getConstant(1, getPointerTy()));
474 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs], Lo));
475 if (ObjGPRs == 2)
476 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs+1], Hi));
477 else {
478 SDOperand PtrOff= DAG.getConstant(ArgOffset, StackPtr.getValueType());
479 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
480 MemOpChains.push_back(DAG.getStore(Chain, Hi, PtrOff, NULL, 0));
481 }
482 break;
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000483 }
Evan Chenga8e29892007-01-19 07:51:42 +0000484 case MVT::f64: {
485 SDOperand Cvt = DAG.getNode(ARMISD::FMRRD,
486 DAG.getVTList(MVT::i32, MVT::i32),
487 &Arg, 1);
488 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs], Cvt));
489 if (ObjGPRs == 2)
490 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs+1],
491 Cvt.getValue(1)));
492 else {
493 SDOperand PtrOff= DAG.getConstant(ArgOffset, StackPtr.getValueType());
494 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
495 MemOpChains.push_back(DAG.getStore(Chain, Cvt.getValue(1), PtrOff,
496 NULL, 0));
497 }
498 break;
499 }
500 }
501 } else {
502 assert(ObjSize != 0);
503 SDOperand PtrOff = DAG.getConstant(ArgOffset, StackPtr.getValueType());
504 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
505 MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0));
506 }
507
508 NumGPRs += ObjGPRs;
509 ArgOffset += ObjSize;
510 }
511
512 if (!MemOpChains.empty())
513 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other,
514 &MemOpChains[0], MemOpChains.size());
515
516 // Build a sequence of copy-to-reg nodes chained together with token chain
517 // and flag operands which copy the outgoing args into the appropriate regs.
518 SDOperand InFlag;
519 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
520 Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first, RegsToPass[i].second,
521 InFlag);
522 InFlag = Chain.getValue(1);
523 }
524
525 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
526 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
527 // node so that legalize doesn't hack it.
528 bool isDirect = false;
529 bool isARMFunc = false;
Evan Cheng277f0742007-06-19 21:05:09 +0000530 bool isLocalARMFunc = false;
Evan Chenga8e29892007-01-19 07:51:42 +0000531 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
532 GlobalValue *GV = G->getGlobal();
Evan Chenga8e29892007-01-19 07:51:42 +0000533 isDirect = true;
Reid Spencer5cbf9852007-01-30 20:08:39 +0000534 bool isExt = (GV->isDeclaration() || GV->hasWeakLinkage() ||
Evan Chenga8e29892007-01-19 07:51:42 +0000535 GV->hasLinkOnceLinkage());
Evan Cheng970a4192007-01-19 19:28:01 +0000536 bool isStub = (isExt && Subtarget->isTargetDarwin()) &&
Evan Chenga8e29892007-01-19 07:51:42 +0000537 getTargetMachine().getRelocationModel() != Reloc::Static;
538 isARMFunc = !Subtarget->isThumb() || isStub;
Evan Cheng277f0742007-06-19 21:05:09 +0000539 // ARM call to a local ARM function is predicable.
540 isLocalARMFunc = !Subtarget->isThumb() && !isExt;
Evan Chengc60e76d2007-01-30 20:37:08 +0000541 // tBX takes a register source operand.
542 if (isARMFunc && Subtarget->isThumb() && !Subtarget->hasV5TOps()) {
543 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex,
544 ARMCP::CPStub, 4);
545 SDOperand CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 2);
546 CPAddr = DAG.getNode(ARMISD::Wrapper, MVT::i32, CPAddr);
547 Callee = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), CPAddr, NULL, 0);
548 SDOperand PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
549 Callee = DAG.getNode(ARMISD::PIC_ADD, getPointerTy(), Callee, PICLabel);
550 } else
551 Callee = DAG.getTargetGlobalAddress(GV, getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000552 } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000553 isDirect = true;
Evan Cheng970a4192007-01-19 19:28:01 +0000554 bool isStub = Subtarget->isTargetDarwin() &&
Evan Chenga8e29892007-01-19 07:51:42 +0000555 getTargetMachine().getRelocationModel() != Reloc::Static;
556 isARMFunc = !Subtarget->isThumb() || isStub;
Evan Chengc60e76d2007-01-30 20:37:08 +0000557 // tBX takes a register source operand.
558 const char *Sym = S->getSymbol();
559 if (isARMFunc && Subtarget->isThumb() && !Subtarget->hasV5TOps()) {
560 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(Sym, ARMPCLabelIndex,
561 ARMCP::CPStub, 4);
562 SDOperand CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 2);
563 CPAddr = DAG.getNode(ARMISD::Wrapper, MVT::i32, CPAddr);
564 Callee = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), CPAddr, NULL, 0);
565 SDOperand PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
566 Callee = DAG.getNode(ARMISD::PIC_ADD, getPointerTy(), Callee, PICLabel);
567 } else
568 Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000569 }
570
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +0000571 // FIXME: handle tail calls differently.
572 unsigned CallOpc;
573 if (Subtarget->isThumb()) {
574 if (!Subtarget->hasV5TOps() && (!isDirect || isARMFunc))
575 CallOpc = ARMISD::CALL_NOLINK;
576 else
577 CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL;
578 } else {
579 CallOpc = (isDirect || Subtarget->hasV5TOps())
Evan Cheng277f0742007-06-19 21:05:09 +0000580 ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL)
581 : ARMISD::CALL_NOLINK;
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +0000582 }
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000583 if (CallOpc == ARMISD::CALL_NOLINK && !Subtarget->isThumb()) {
584 // implicit def LR - LR mustn't be allocated as GRP:$dst of CALL_NOLINK
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +0000585 Chain = DAG.getCopyToReg(Chain, ARM::LR,
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000586 DAG.getNode(ISD::UNDEF, MVT::i32), InFlag);
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +0000587 InFlag = Chain.getValue(1);
588 }
589
Evan Chenga8e29892007-01-19 07:51:42 +0000590 std::vector<SDOperand> Ops;
591 Ops.push_back(Chain);
592 Ops.push_back(Callee);
593
594 // Add argument registers to the end of the list so that they are known live
595 // into the call.
596 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
597 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
598 RegsToPass[i].second.getValueType()));
599
Evan Chenga8e29892007-01-19 07:51:42 +0000600 if (InFlag.Val)
601 Ops.push_back(InFlag);
Duncan Sands4bdcb612008-07-02 17:40:58 +0000602 // Returns a chain and a flag for retval copy to use.
603 Chain = DAG.getNode(CallOpc, DAG.getVTList(MVT::Other, MVT::Flag),
604 &Ops[0], Ops.size());
Evan Chenga8e29892007-01-19 07:51:42 +0000605 InFlag = Chain.getValue(1);
606
Bill Wendling0f8d9c02007-11-13 00:44:25 +0000607 Chain = DAG.getCALLSEQ_END(Chain,
608 DAG.getConstant(NumBytes, MVT::i32),
609 DAG.getConstant(0, MVT::i32),
610 InFlag);
Evan Chenga8e29892007-01-19 07:51:42 +0000611 if (RetVT != MVT::Other)
612 InFlag = Chain.getValue(1);
613
614 std::vector<SDOperand> ResultVals;
Evan Chenga8e29892007-01-19 07:51:42 +0000615
616 // If the call has results, copy the values out of the ret val registers.
Duncan Sands83ec4b62008-06-06 12:08:01 +0000617 switch (RetVT.getSimpleVT()) {
Evan Chenga8e29892007-01-19 07:51:42 +0000618 default: assert(0 && "Unexpected ret value!");
619 case MVT::Other:
620 break;
621 case MVT::i32:
622 Chain = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag).getValue(1);
623 ResultVals.push_back(Chain.getValue(0));
624 if (Op.Val->getValueType(1) == MVT::i32) {
625 // Returns a i64 value.
626 Chain = DAG.getCopyFromReg(Chain, ARM::R1, MVT::i32,
627 Chain.getValue(2)).getValue(1);
628 ResultVals.push_back(Chain.getValue(0));
Evan Chenga8e29892007-01-19 07:51:42 +0000629 }
Evan Chenga8e29892007-01-19 07:51:42 +0000630 break;
631 case MVT::f32:
632 Chain = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag).getValue(1);
633 ResultVals.push_back(DAG.getNode(ISD::BIT_CONVERT, MVT::f32,
634 Chain.getValue(0)));
Evan Chenga8e29892007-01-19 07:51:42 +0000635 break;
636 case MVT::f64: {
637 SDOperand Lo = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag);
638 SDOperand Hi = DAG.getCopyFromReg(Lo, ARM::R1, MVT::i32, Lo.getValue(2));
639 ResultVals.push_back(DAG.getNode(ARMISD::FMDRR, MVT::f64, Lo, Hi));
Evan Chenga8e29892007-01-19 07:51:42 +0000640 break;
641 }
642 }
643
Evan Chenga8e29892007-01-19 07:51:42 +0000644 if (ResultVals.empty())
645 return Chain;
646
647 ResultVals.push_back(Chain);
Duncan Sands4bdcb612008-07-02 17:40:58 +0000648 SDOperand Res = DAG.getMergeValues(&ResultVals[0], ResultVals.size());
Evan Chenga8e29892007-01-19 07:51:42 +0000649 return Res.getValue(Op.ResNo);
650}
651
652static SDOperand LowerRET(SDOperand Op, SelectionDAG &DAG) {
653 SDOperand Copy;
654 SDOperand Chain = Op.getOperand(0);
655 switch(Op.getNumOperands()) {
656 default:
657 assert(0 && "Do not know how to return this many arguments!");
658 abort();
659 case 1: {
660 SDOperand LR = DAG.getRegister(ARM::LR, MVT::i32);
661 return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Chain);
662 }
663 case 3:
664 Op = Op.getOperand(1);
665 if (Op.getValueType() == MVT::f32) {
666 Op = DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Op);
667 } else if (Op.getValueType() == MVT::f64) {
Chris Lattner65a33232007-10-18 06:17:07 +0000668 // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is
669 // available.
670 Op = DAG.getNode(ARMISD::FMRRD, DAG.getVTList(MVT::i32, MVT::i32), &Op,1);
671 SDOperand Sign = DAG.getConstant(0, MVT::i32);
672 return DAG.getNode(ISD::RET, MVT::Other, Chain, Op, Sign,
673 Op.getValue(1), Sign);
Evan Chenga8e29892007-01-19 07:51:42 +0000674 }
675 Copy = DAG.getCopyToReg(Chain, ARM::R0, Op, SDOperand());
Chris Lattner84bc5422007-12-31 04:13:23 +0000676 if (DAG.getMachineFunction().getRegInfo().liveout_empty())
677 DAG.getMachineFunction().getRegInfo().addLiveOut(ARM::R0);
Evan Chenga8e29892007-01-19 07:51:42 +0000678 break;
679 case 5:
680 Copy = DAG.getCopyToReg(Chain, ARM::R1, Op.getOperand(3), SDOperand());
681 Copy = DAG.getCopyToReg(Copy, ARM::R0, Op.getOperand(1), Copy.getValue(1));
682 // If we haven't noted the R0+R1 are live out, do so now.
Chris Lattner84bc5422007-12-31 04:13:23 +0000683 if (DAG.getMachineFunction().getRegInfo().liveout_empty()) {
684 DAG.getMachineFunction().getRegInfo().addLiveOut(ARM::R0);
685 DAG.getMachineFunction().getRegInfo().addLiveOut(ARM::R1);
Evan Chenga8e29892007-01-19 07:51:42 +0000686 }
687 break;
688 }
689
690 //We must use RET_FLAG instead of BRIND because BRIND doesn't have a flag
691 return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1));
692}
693
694// ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as
695// their target countpart wrapped in the ARMISD::Wrapper node. Suppose N is
696// one of the above mentioned nodes. It has to be wrapped because otherwise
697// Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only
698// be used to form addressing mode. These wrapped nodes will be selected
Evan Cheng9f6636f2007-03-19 07:48:02 +0000699// into MOVi.
Evan Chenga8e29892007-01-19 07:51:42 +0000700static SDOperand LowerConstantPool(SDOperand Op, SelectionDAG &DAG) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000701 MVT PtrVT = Op.getValueType();
Evan Chenga8e29892007-01-19 07:51:42 +0000702 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
703 SDOperand Res;
704 if (CP->isMachineConstantPoolEntry())
705 Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT,
706 CP->getAlignment());
707 else
708 Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT,
709 CP->getAlignment());
710 return DAG.getNode(ARMISD::Wrapper, MVT::i32, Res);
711}
712
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000713// Lower ISD::GlobalTLSAddress using the "general dynamic" model
714SDOperand
715ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
716 SelectionDAG &DAG) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000717 MVT PtrVT = getPointerTy();
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000718 unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8;
719 ARMConstantPoolValue *CPV =
720 new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue,
721 PCAdj, "tlsgd", true);
722 SDOperand Argument = DAG.getTargetConstantPool(CPV, PtrVT, 2);
723 Argument = DAG.getNode(ARMISD::Wrapper, MVT::i32, Argument);
724 Argument = DAG.getLoad(PtrVT, DAG.getEntryNode(), Argument, NULL, 0);
725 SDOperand Chain = Argument.getValue(1);
726
727 SDOperand PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
728 Argument = DAG.getNode(ARMISD::PIC_ADD, PtrVT, Argument, PICLabel);
729
730 // call __tls_get_addr.
731 ArgListTy Args;
732 ArgListEntry Entry;
733 Entry.Node = Argument;
734 Entry.Ty = (const Type *) Type::Int32Ty;
735 Args.push_back(Entry);
736 std::pair<SDOperand, SDOperand> CallResult =
Duncan Sands00fee652008-02-14 17:28:50 +0000737 LowerCallTo(Chain, (const Type *) Type::Int32Ty, false, false, false,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000738 CallingConv::C, false,
739 DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG);
740 return CallResult.first;
741}
742
743// Lower ISD::GlobalTLSAddress using the "initial exec" or
744// "local exec" model.
745SDOperand
746ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA,
747 SelectionDAG &DAG) {
748 GlobalValue *GV = GA->getGlobal();
749 SDOperand Offset;
750 SDOperand Chain = DAG.getEntryNode();
Duncan Sands83ec4b62008-06-06 12:08:01 +0000751 MVT PtrVT = getPointerTy();
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000752 // Get the Thread Pointer
753 SDOperand ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, PtrVT);
754
755 if (GV->isDeclaration()){
756 // initial exec model
757 unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8;
758 ARMConstantPoolValue *CPV =
759 new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue,
760 PCAdj, "gottpoff", true);
761 Offset = DAG.getTargetConstantPool(CPV, PtrVT, 2);
762 Offset = DAG.getNode(ARMISD::Wrapper, MVT::i32, Offset);
763 Offset = DAG.getLoad(PtrVT, Chain, Offset, NULL, 0);
764 Chain = Offset.getValue(1);
765
766 SDOperand PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
767 Offset = DAG.getNode(ARMISD::PIC_ADD, PtrVT, Offset, PICLabel);
768
769 Offset = DAG.getLoad(PtrVT, Chain, Offset, NULL, 0);
770 } else {
771 // local exec model
772 ARMConstantPoolValue *CPV =
773 new ARMConstantPoolValue(GV, ARMCP::CPValue, "tpoff");
774 Offset = DAG.getTargetConstantPool(CPV, PtrVT, 2);
775 Offset = DAG.getNode(ARMISD::Wrapper, MVT::i32, Offset);
776 Offset = DAG.getLoad(PtrVT, Chain, Offset, NULL, 0);
777 }
778
779 // The address of the thread local variable is the add of the thread
780 // pointer with the offset of the variable.
781 return DAG.getNode(ISD::ADD, PtrVT, ThreadPointer, Offset);
782}
783
784SDOperand
785ARMTargetLowering::LowerGlobalTLSAddress(SDOperand Op, SelectionDAG &DAG) {
786 // TODO: implement the "local dynamic" model
787 assert(Subtarget->isTargetELF() &&
788 "TLS not implemented for non-ELF targets");
789 GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
790 // If the relocation model is PIC, use the "General Dynamic" TLS Model,
791 // otherwise use the "Local Exec" TLS Model
792 if (getTargetMachine().getRelocationModel() == Reloc::PIC_)
793 return LowerToTLSGeneralDynamicModel(GA, DAG);
794 else
795 return LowerToTLSExecModels(GA, DAG);
796}
797
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +0000798SDOperand ARMTargetLowering::LowerGlobalAddressELF(SDOperand Op,
799 SelectionDAG &DAG) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000800 MVT PtrVT = getPointerTy();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +0000801 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
802 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
803 if (RelocM == Reloc::PIC_) {
Lauro Ramos Venancio5d3d44a2007-05-14 23:20:21 +0000804 bool UseGOTOFF = GV->hasInternalLinkage() || GV->hasHiddenVisibility();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +0000805 ARMConstantPoolValue *CPV =
806 new ARMConstantPoolValue(GV, ARMCP::CPValue, UseGOTOFF ? "GOTOFF":"GOT");
807 SDOperand CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2);
808 CPAddr = DAG.getNode(ARMISD::Wrapper, MVT::i32, CPAddr);
809 SDOperand Result = DAG.getLoad(PtrVT, DAG.getEntryNode(), CPAddr, NULL, 0);
810 SDOperand Chain = Result.getValue(1);
811 SDOperand GOT = DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, PtrVT);
812 Result = DAG.getNode(ISD::ADD, PtrVT, Result, GOT);
813 if (!UseGOTOFF)
814 Result = DAG.getLoad(PtrVT, Chain, Result, NULL, 0);
815 return Result;
816 } else {
817 SDOperand CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 2);
818 CPAddr = DAG.getNode(ARMISD::Wrapper, MVT::i32, CPAddr);
819 return DAG.getLoad(PtrVT, DAG.getEntryNode(), CPAddr, NULL, 0);
820 }
821}
822
Evan Chenga8e29892007-01-19 07:51:42 +0000823/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol
Evan Cheng97c9bb52007-05-04 00:26:58 +0000824/// even in non-static mode.
825static bool GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) {
826 return RelocM != Reloc::Static &&
827 (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
Gabor Greifa99be512007-07-05 17:07:56 +0000828 (GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode()));
Evan Chenga8e29892007-01-19 07:51:42 +0000829}
830
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +0000831SDOperand ARMTargetLowering::LowerGlobalAddressDarwin(SDOperand Op,
832 SelectionDAG &DAG) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000833 MVT PtrVT = getPointerTy();
Evan Chenga8e29892007-01-19 07:51:42 +0000834 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
835 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
Evan Cheng97c9bb52007-05-04 00:26:58 +0000836 bool IsIndirect = GVIsIndirectSymbol(GV, RelocM);
Evan Chenga8e29892007-01-19 07:51:42 +0000837 SDOperand CPAddr;
838 if (RelocM == Reloc::Static)
839 CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 2);
840 else {
841 unsigned PCAdj = (RelocM != Reloc::PIC_)
842 ? 0 : (Subtarget->isThumb() ? 4 : 8);
Evan Chengc60e76d2007-01-30 20:37:08 +0000843 ARMCP::ARMCPKind Kind = IsIndirect ? ARMCP::CPNonLazyPtr
844 : ARMCP::CPValue;
Evan Chenga8e29892007-01-19 07:51:42 +0000845 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex,
Evan Chengc60e76d2007-01-30 20:37:08 +0000846 Kind, PCAdj);
Evan Chenga8e29892007-01-19 07:51:42 +0000847 CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2);
848 }
849 CPAddr = DAG.getNode(ARMISD::Wrapper, MVT::i32, CPAddr);
850
851 SDOperand Result = DAG.getLoad(PtrVT, DAG.getEntryNode(), CPAddr, NULL, 0);
852 SDOperand Chain = Result.getValue(1);
853
854 if (RelocM == Reloc::PIC_) {
855 SDOperand PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
856 Result = DAG.getNode(ARMISD::PIC_ADD, PtrVT, Result, PICLabel);
857 }
858 if (IsIndirect)
859 Result = DAG.getLoad(PtrVT, Chain, Result, NULL, 0);
860
861 return Result;
862}
863
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +0000864SDOperand ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDOperand Op,
865 SelectionDAG &DAG){
866 assert(Subtarget->isTargetELF() &&
867 "GLOBAL OFFSET TABLE not implemented for non-ELF targets");
Duncan Sands83ec4b62008-06-06 12:08:01 +0000868 MVT PtrVT = getPointerTy();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +0000869 unsigned PCAdj = Subtarget->isThumb() ? 4 : 8;
870 ARMConstantPoolValue *CPV = new ARMConstantPoolValue("_GLOBAL_OFFSET_TABLE_",
871 ARMPCLabelIndex,
872 ARMCP::CPValue, PCAdj);
873 SDOperand CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2);
874 CPAddr = DAG.getNode(ARMISD::Wrapper, MVT::i32, CPAddr);
875 SDOperand Result = DAG.getLoad(PtrVT, DAG.getEntryNode(), CPAddr, NULL, 0);
876 SDOperand PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
877 return DAG.getNode(ARMISD::PIC_ADD, PtrVT, Result, PICLabel);
878}
879
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +0000880static SDOperand LowerINTRINSIC_WO_CHAIN(SDOperand Op, SelectionDAG &DAG) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000881 MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +0000882 unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getValue();
883 switch (IntNo) {
884 default: return SDOperand(); // Don't custom lower most intrinsics.
885 case Intrinsic::arm_thread_pointer:
886 return DAG.getNode(ARMISD::THREAD_POINTER, PtrVT);
887 }
888}
889
Evan Chenga8e29892007-01-19 07:51:42 +0000890static SDOperand LowerVASTART(SDOperand Op, SelectionDAG &DAG,
891 unsigned VarArgsFrameIndex) {
892 // vastart just stores the address of the VarArgsFrameIndex slot into the
893 // memory location argument.
Duncan Sands83ec4b62008-06-06 12:08:01 +0000894 MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
Evan Chenga8e29892007-01-19 07:51:42 +0000895 SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT);
Dan Gohman69de1932008-02-06 22:27:42 +0000896 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
897 return DAG.getStore(Op.getOperand(0), FR, Op.getOperand(1), SV, 0);
Evan Chenga8e29892007-01-19 07:51:42 +0000898}
899
900static SDOperand LowerFORMAL_ARGUMENT(SDOperand Op, SelectionDAG &DAG,
Nate Begemanbf1caa92008-02-12 22:54:40 +0000901 unsigned ArgNo, unsigned &NumGPRs,
902 unsigned &ArgOffset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000903 MachineFunction &MF = DAG.getMachineFunction();
Duncan Sands83ec4b62008-06-06 12:08:01 +0000904 MVT ObjectVT = Op.getValue(ArgNo).getValueType();
Evan Chenga8e29892007-01-19 07:51:42 +0000905 SDOperand Root = Op.getOperand(0);
906 std::vector<SDOperand> ArgValues;
Chris Lattner84bc5422007-12-31 04:13:23 +0000907 MachineRegisterInfo &RegInfo = MF.getRegInfo();
Evan Chenga8e29892007-01-19 07:51:42 +0000908
909 static const unsigned GPRArgRegs[] = {
910 ARM::R0, ARM::R1, ARM::R2, ARM::R3
911 };
912
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000913 unsigned ObjSize;
914 unsigned ObjGPRs;
915 unsigned GPRPad;
916 unsigned StackPad;
Duncan Sands276dcbd2008-03-21 09:14:45 +0000917 ISD::ArgFlagsTy Flags =
918 cast<ARG_FLAGSSDNode>(Op.getOperand(ArgNo + 3))->getArgFlags();
Lauro Ramos Venancio876eaf12007-02-13 14:07:13 +0000919 HowToPassArgument(ObjectVT, NumGPRs, ArgOffset, ObjGPRs,
920 ObjSize, GPRPad, StackPad, Flags);
921 NumGPRs += GPRPad;
922 ArgOffset += StackPad;
Evan Chenga8e29892007-01-19 07:51:42 +0000923
924 SDOperand ArgValue;
925 if (ObjGPRs == 1) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000926 unsigned VReg = RegInfo.createVirtualRegister(&ARM::GPRRegClass);
927 RegInfo.addLiveIn(GPRArgRegs[NumGPRs], VReg);
Evan Chenga8e29892007-01-19 07:51:42 +0000928 ArgValue = DAG.getCopyFromReg(Root, VReg, MVT::i32);
929 if (ObjectVT == MVT::f32)
930 ArgValue = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, ArgValue);
931 } else if (ObjGPRs == 2) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000932 unsigned VReg = RegInfo.createVirtualRegister(&ARM::GPRRegClass);
933 RegInfo.addLiveIn(GPRArgRegs[NumGPRs], VReg);
Evan Chenga8e29892007-01-19 07:51:42 +0000934 ArgValue = DAG.getCopyFromReg(Root, VReg, MVT::i32);
935
Chris Lattner84bc5422007-12-31 04:13:23 +0000936 VReg = RegInfo.createVirtualRegister(&ARM::GPRRegClass);
937 RegInfo.addLiveIn(GPRArgRegs[NumGPRs+1], VReg);
Evan Chenga8e29892007-01-19 07:51:42 +0000938 SDOperand ArgValue2 = DAG.getCopyFromReg(Root, VReg, MVT::i32);
939
Chris Lattner27a6c732007-11-24 07:07:01 +0000940 assert(ObjectVT != MVT::i64 && "i64 should already be lowered");
941 ArgValue = DAG.getNode(ARMISD::FMDRR, MVT::f64, ArgValue, ArgValue2);
Evan Chenga8e29892007-01-19 07:51:42 +0000942 }
943 NumGPRs += ObjGPRs;
944
945 if (ObjSize) {
Chris Lattner9f72d1a2008-02-13 07:35:30 +0000946 MachineFrameInfo *MFI = MF.getFrameInfo();
947 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
948 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
949 if (ObjGPRs == 0)
950 ArgValue = DAG.getLoad(ObjectVT, Root, FIN, NULL, 0);
951 else {
952 SDOperand ArgValue2 = DAG.getLoad(MVT::i32, Root, FIN, NULL, 0);
953 assert(ObjectVT != MVT::i64 && "i64 should already be lowered");
954 ArgValue = DAG.getNode(ARMISD::FMDRR, MVT::f64, ArgValue, ArgValue2);
Evan Chenga8e29892007-01-19 07:51:42 +0000955 }
956
957 ArgOffset += ObjSize; // Move on to the next argument.
958 }
959
960 return ArgValue;
961}
962
963SDOperand
964ARMTargetLowering::LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) {
965 std::vector<SDOperand> ArgValues;
966 SDOperand Root = Op.getOperand(0);
967 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
968 unsigned NumGPRs = 0; // GPRs used for parameter passing.
Evan Chenga8e29892007-01-19 07:51:42 +0000969
970 unsigned NumArgs = Op.Val->getNumValues()-1;
971 for (unsigned ArgNo = 0; ArgNo < NumArgs; ++ArgNo)
Nate Begemanbf1caa92008-02-12 22:54:40 +0000972 ArgValues.push_back(LowerFORMAL_ARGUMENT(Op, DAG, ArgNo,
Evan Chenga8e29892007-01-19 07:51:42 +0000973 NumGPRs, ArgOffset));
974
975 bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
976 if (isVarArg) {
977 static const unsigned GPRArgRegs[] = {
978 ARM::R0, ARM::R1, ARM::R2, ARM::R3
979 };
980
981 MachineFunction &MF = DAG.getMachineFunction();
Chris Lattner84bc5422007-12-31 04:13:23 +0000982 MachineRegisterInfo &RegInfo = MF.getRegInfo();
Evan Chenga8e29892007-01-19 07:51:42 +0000983 MachineFrameInfo *MFI = MF.getFrameInfo();
984 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
Lauro Ramos Venancio600c3832007-02-23 20:32:57 +0000985 unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
986 unsigned VARegSize = (4 - NumGPRs) * 4;
987 unsigned VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1);
Evan Chenga8e29892007-01-19 07:51:42 +0000988 if (VARegSaveSize) {
989 // If this function is vararg, store any remaining integer argument regs
990 // to their spots on the stack so that they may be loaded by deferencing
991 // the result of va_next.
992 AFI->setVarArgsRegSaveSize(VARegSaveSize);
Lauro Ramos Venancio600c3832007-02-23 20:32:57 +0000993 VarArgsFrameIndex = MFI->CreateFixedObject(VARegSaveSize, ArgOffset +
994 VARegSaveSize - VARegSize);
Evan Chenga8e29892007-01-19 07:51:42 +0000995 SDOperand FIN = DAG.getFrameIndex(VarArgsFrameIndex, getPointerTy());
996
997 SmallVector<SDOperand, 4> MemOps;
998 for (; NumGPRs < 4; ++NumGPRs) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000999 unsigned VReg = RegInfo.createVirtualRegister(&ARM::GPRRegClass);
1000 RegInfo.addLiveIn(GPRArgRegs[NumGPRs], VReg);
Evan Chenga8e29892007-01-19 07:51:42 +00001001 SDOperand Val = DAG.getCopyFromReg(Root, VReg, MVT::i32);
1002 SDOperand Store = DAG.getStore(Val.getValue(1), Val, FIN, NULL, 0);
1003 MemOps.push_back(Store);
1004 FIN = DAG.getNode(ISD::ADD, getPointerTy(), FIN,
1005 DAG.getConstant(4, getPointerTy()));
1006 }
1007 if (!MemOps.empty())
1008 Root = DAG.getNode(ISD::TokenFactor, MVT::Other,
1009 &MemOps[0], MemOps.size());
1010 } else
1011 // This will point to the next argument passed via stack.
1012 VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset);
1013 }
1014
1015 ArgValues.push_back(Root);
1016
1017 // Return the new list of results.
Duncan Sandsf9516202008-06-30 10:19:09 +00001018 return DAG.getMergeValues(Op.Val->getVTList(), &ArgValues[0],
1019 ArgValues.size());
Evan Chenga8e29892007-01-19 07:51:42 +00001020}
1021
1022/// isFloatingPointZero - Return true if this is +0.0.
1023static bool isFloatingPointZero(SDOperand Op) {
1024 if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op))
Dale Johanneseneaf08942007-08-31 04:03:46 +00001025 return CFP->getValueAPF().isPosZero();
Evan Chenga8e29892007-01-19 07:51:42 +00001026 else if (ISD::isEXTLoad(Op.Val) || ISD::isNON_EXTLoad(Op.Val)) {
1027 // Maybe this has already been legalized into the constant pool?
1028 if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) {
1029 SDOperand WrapperOp = Op.getOperand(1).getOperand(0);
1030 if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp))
1031 if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal()))
Dale Johanneseneaf08942007-08-31 04:03:46 +00001032 return CFP->getValueAPF().isPosZero();
Evan Chenga8e29892007-01-19 07:51:42 +00001033 }
1034 }
1035 return false;
1036}
1037
Evan Cheng9a2ef952007-02-02 01:53:26 +00001038static bool isLegalCmpImmediate(unsigned C, bool isThumb) {
Evan Chenga8e29892007-01-19 07:51:42 +00001039 return ( isThumb && (C & ~255U) == 0) ||
1040 (!isThumb && ARM_AM::getSOImmVal(C) != -1);
1041}
1042
1043/// Returns appropriate ARM CMP (cmp) and corresponding condition code for
1044/// the given operands.
1045static SDOperand getARMCmp(SDOperand LHS, SDOperand RHS, ISD::CondCode CC,
1046 SDOperand &ARMCC, SelectionDAG &DAG, bool isThumb) {
1047 if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.Val)) {
Evan Cheng9a2ef952007-02-02 01:53:26 +00001048 unsigned C = RHSC->getValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001049 if (!isLegalCmpImmediate(C, isThumb)) {
1050 // Constant does not fit, try adjusting it by one?
1051 switch (CC) {
1052 default: break;
1053 case ISD::SETLT:
Evan Chenga8e29892007-01-19 07:51:42 +00001054 case ISD::SETGE:
Evan Chenga8e29892007-01-19 07:51:42 +00001055 if (isLegalCmpImmediate(C-1, isThumb)) {
Evan Cheng9a2ef952007-02-02 01:53:26 +00001056 CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT;
1057 RHS = DAG.getConstant(C-1, MVT::i32);
1058 }
1059 break;
1060 case ISD::SETULT:
1061 case ISD::SETUGE:
1062 if (C > 0 && isLegalCmpImmediate(C-1, isThumb)) {
1063 CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT;
Evan Chenga8e29892007-01-19 07:51:42 +00001064 RHS = DAG.getConstant(C-1, MVT::i32);
1065 }
1066 break;
1067 case ISD::SETLE:
Evan Chenga8e29892007-01-19 07:51:42 +00001068 case ISD::SETGT:
Evan Chenga8e29892007-01-19 07:51:42 +00001069 if (isLegalCmpImmediate(C+1, isThumb)) {
Evan Cheng9a2ef952007-02-02 01:53:26 +00001070 CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE;
1071 RHS = DAG.getConstant(C+1, MVT::i32);
1072 }
1073 break;
1074 case ISD::SETULE:
1075 case ISD::SETUGT:
1076 if (C < 0xffffffff && isLegalCmpImmediate(C+1, isThumb)) {
1077 CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE;
Evan Chenga8e29892007-01-19 07:51:42 +00001078 RHS = DAG.getConstant(C+1, MVT::i32);
1079 }
1080 break;
1081 }
1082 }
1083 }
1084
1085 ARMCC::CondCodes CondCode = IntCCToARMCC(CC);
Lauro Ramos Venancio99966632007-04-02 01:30:03 +00001086 ARMISD::NodeType CompareType;
1087 switch (CondCode) {
1088 default:
1089 CompareType = ARMISD::CMP;
1090 break;
1091 case ARMCC::EQ:
1092 case ARMCC::NE:
1093 case ARMCC::MI:
1094 case ARMCC::PL:
1095 // Uses only N and Z Flags
1096 CompareType = ARMISD::CMPNZ;
1097 break;
1098 }
Evan Chenga8e29892007-01-19 07:51:42 +00001099 ARMCC = DAG.getConstant(CondCode, MVT::i32);
Lauro Ramos Venancio99966632007-04-02 01:30:03 +00001100 return DAG.getNode(CompareType, MVT::Flag, LHS, RHS);
Evan Chenga8e29892007-01-19 07:51:42 +00001101}
1102
1103/// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands.
1104static SDOperand getVFPCmp(SDOperand LHS, SDOperand RHS, SelectionDAG &DAG) {
1105 SDOperand Cmp;
1106 if (!isFloatingPointZero(RHS))
1107 Cmp = DAG.getNode(ARMISD::CMPFP, MVT::Flag, LHS, RHS);
1108 else
1109 Cmp = DAG.getNode(ARMISD::CMPFPw0, MVT::Flag, LHS);
1110 return DAG.getNode(ARMISD::FMSTAT, MVT::Flag, Cmp);
1111}
1112
1113static SDOperand LowerSELECT_CC(SDOperand Op, SelectionDAG &DAG,
1114 const ARMSubtarget *ST) {
Duncan Sands83ec4b62008-06-06 12:08:01 +00001115 MVT VT = Op.getValueType();
Evan Chenga8e29892007-01-19 07:51:42 +00001116 SDOperand LHS = Op.getOperand(0);
1117 SDOperand RHS = Op.getOperand(1);
1118 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
1119 SDOperand TrueVal = Op.getOperand(2);
1120 SDOperand FalseVal = Op.getOperand(3);
1121
1122 if (LHS.getValueType() == MVT::i32) {
1123 SDOperand ARMCC;
Evan Cheng0e1d3792007-07-05 07:18:20 +00001124 SDOperand CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001125 SDOperand Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, ST->isThumb());
Evan Cheng0e1d3792007-07-05 07:18:20 +00001126 return DAG.getNode(ARMISD::CMOV, VT, FalseVal, TrueVal, ARMCC, CCR, Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001127 }
1128
1129 ARMCC::CondCodes CondCode, CondCode2;
1130 if (FPCCToARMCC(CC, CondCode, CondCode2))
1131 std::swap(TrueVal, FalseVal);
1132
1133 SDOperand ARMCC = DAG.getConstant(CondCode, MVT::i32);
Evan Cheng0e1d3792007-07-05 07:18:20 +00001134 SDOperand CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001135 SDOperand Cmp = getVFPCmp(LHS, RHS, DAG);
1136 SDOperand Result = DAG.getNode(ARMISD::CMOV, VT, FalseVal, TrueVal,
Evan Cheng0e1d3792007-07-05 07:18:20 +00001137 ARMCC, CCR, Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001138 if (CondCode2 != ARMCC::AL) {
1139 SDOperand ARMCC2 = DAG.getConstant(CondCode2, MVT::i32);
1140 // FIXME: Needs another CMP because flag can have but one use.
1141 SDOperand Cmp2 = getVFPCmp(LHS, RHS, DAG);
Evan Cheng0e1d3792007-07-05 07:18:20 +00001142 Result = DAG.getNode(ARMISD::CMOV, VT, Result, TrueVal, ARMCC2, CCR, Cmp2);
Evan Chenga8e29892007-01-19 07:51:42 +00001143 }
1144 return Result;
1145}
1146
1147static SDOperand LowerBR_CC(SDOperand Op, SelectionDAG &DAG,
1148 const ARMSubtarget *ST) {
1149 SDOperand Chain = Op.getOperand(0);
1150 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
1151 SDOperand LHS = Op.getOperand(2);
1152 SDOperand RHS = Op.getOperand(3);
1153 SDOperand Dest = Op.getOperand(4);
1154
1155 if (LHS.getValueType() == MVT::i32) {
1156 SDOperand ARMCC;
Evan Cheng0e1d3792007-07-05 07:18:20 +00001157 SDOperand CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001158 SDOperand Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, ST->isThumb());
Evan Cheng0e1d3792007-07-05 07:18:20 +00001159 return DAG.getNode(ARMISD::BRCOND, MVT::Other, Chain, Dest, ARMCC, CCR,Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001160 }
1161
1162 assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64);
1163 ARMCC::CondCodes CondCode, CondCode2;
1164 if (FPCCToARMCC(CC, CondCode, CondCode2))
1165 // Swap the LHS/RHS of the comparison if needed.
1166 std::swap(LHS, RHS);
1167
1168 SDOperand Cmp = getVFPCmp(LHS, RHS, DAG);
1169 SDOperand ARMCC = DAG.getConstant(CondCode, MVT::i32);
Evan Cheng0e1d3792007-07-05 07:18:20 +00001170 SDOperand CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001171 SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Flag);
Evan Cheng0e1d3792007-07-05 07:18:20 +00001172 SDOperand Ops[] = { Chain, Dest, ARMCC, CCR, Cmp };
1173 SDOperand Res = DAG.getNode(ARMISD::BRCOND, VTList, Ops, 5);
Evan Chenga8e29892007-01-19 07:51:42 +00001174 if (CondCode2 != ARMCC::AL) {
1175 ARMCC = DAG.getConstant(CondCode2, MVT::i32);
Evan Cheng0e1d3792007-07-05 07:18:20 +00001176 SDOperand Ops[] = { Res, Dest, ARMCC, CCR, Res.getValue(1) };
1177 Res = DAG.getNode(ARMISD::BRCOND, VTList, Ops, 5);
Evan Chenga8e29892007-01-19 07:51:42 +00001178 }
1179 return Res;
1180}
1181
1182SDOperand ARMTargetLowering::LowerBR_JT(SDOperand Op, SelectionDAG &DAG) {
1183 SDOperand Chain = Op.getOperand(0);
1184 SDOperand Table = Op.getOperand(1);
1185 SDOperand Index = Op.getOperand(2);
1186
Duncan Sands83ec4b62008-06-06 12:08:01 +00001187 MVT PTy = getPointerTy();
Evan Chenga8e29892007-01-19 07:51:42 +00001188 JumpTableSDNode *JT = cast<JumpTableSDNode>(Table);
1189 ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>();
1190 SDOperand UId = DAG.getConstant(AFI->createJumpTableUId(), PTy);
1191 SDOperand JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy);
1192 Table = DAG.getNode(ARMISD::WrapperJT, MVT::i32, JTI, UId);
1193 Index = DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(4, PTy));
1194 SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table);
1195 bool isPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_;
Duncan Sands83ec4b62008-06-06 12:08:01 +00001196 Addr = DAG.getLoad(isPIC ? (MVT)MVT::i32 : PTy,
Evan Chenge2446c62007-06-26 18:31:22 +00001197 Chain, Addr, NULL, 0);
Evan Chenga8e29892007-01-19 07:51:42 +00001198 Chain = Addr.getValue(1);
1199 if (isPIC)
1200 Addr = DAG.getNode(ISD::ADD, PTy, Addr, Table);
1201 return DAG.getNode(ARMISD::BR_JT, MVT::Other, Chain, Addr, JTI, UId);
1202}
1203
1204static SDOperand LowerFP_TO_INT(SDOperand Op, SelectionDAG &DAG) {
1205 unsigned Opc =
1206 Op.getOpcode() == ISD::FP_TO_SINT ? ARMISD::FTOSI : ARMISD::FTOUI;
1207 Op = DAG.getNode(Opc, MVT::f32, Op.getOperand(0));
1208 return DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Op);
1209}
1210
1211static SDOperand LowerINT_TO_FP(SDOperand Op, SelectionDAG &DAG) {
Duncan Sands83ec4b62008-06-06 12:08:01 +00001212 MVT VT = Op.getValueType();
Evan Chenga8e29892007-01-19 07:51:42 +00001213 unsigned Opc =
1214 Op.getOpcode() == ISD::SINT_TO_FP ? ARMISD::SITOF : ARMISD::UITOF;
1215
1216 Op = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, Op.getOperand(0));
1217 return DAG.getNode(Opc, VT, Op);
1218}
1219
1220static SDOperand LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) {
1221 // Implement fcopysign with a fabs and a conditional fneg.
1222 SDOperand Tmp0 = Op.getOperand(0);
1223 SDOperand Tmp1 = Op.getOperand(1);
Duncan Sands83ec4b62008-06-06 12:08:01 +00001224 MVT VT = Op.getValueType();
1225 MVT SrcVT = Tmp1.getValueType();
Evan Chenga8e29892007-01-19 07:51:42 +00001226 SDOperand AbsVal = DAG.getNode(ISD::FABS, VT, Tmp0);
1227 SDOperand Cmp = getVFPCmp(Tmp1, DAG.getConstantFP(0.0, SrcVT), DAG);
1228 SDOperand ARMCC = DAG.getConstant(ARMCC::LT, MVT::i32);
Evan Cheng0e1d3792007-07-05 07:18:20 +00001229 SDOperand CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
1230 return DAG.getNode(ARMISD::CNEG, VT, AbsVal, AbsVal, ARMCC, CCR, Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001231}
1232
Dan Gohman707e0182008-04-12 04:36:06 +00001233SDOperand
1234ARMTargetLowering::EmitTargetCodeForMemcpy(SelectionDAG &DAG,
1235 SDOperand Chain,
1236 SDOperand Dst, SDOperand Src,
1237 SDOperand Size, unsigned Align,
1238 bool AlwaysInline,
Dan Gohman1f13c682008-04-28 17:15:20 +00001239 const Value *DstSV, uint64_t DstSVOff,
1240 const Value *SrcSV, uint64_t SrcSVOff){
Evan Cheng4102eb52007-10-22 22:11:27 +00001241 // Do repeated 4-byte loads and stores. To be improved.
Dan Gohman707e0182008-04-12 04:36:06 +00001242 // This requires 4-byte alignment.
1243 if ((Align & 3) != 0)
1244 return SDOperand();
1245 // This requires the copy size to be a constant, preferrably
1246 // within a subtarget-specific limit.
1247 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
1248 if (!ConstantSize)
1249 return SDOperand();
1250 uint64_t SizeVal = ConstantSize->getValue();
1251 if (!AlwaysInline && SizeVal > getSubtarget()->getMaxInlineSizeThreshold())
1252 return SDOperand();
1253
1254 unsigned BytesLeft = SizeVal & 3;
1255 unsigned NumMemOps = SizeVal >> 2;
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001256 unsigned EmittedNumMemOps = 0;
Duncan Sands83ec4b62008-06-06 12:08:01 +00001257 MVT VT = MVT::i32;
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001258 unsigned VTSize = 4;
Evan Cheng4102eb52007-10-22 22:11:27 +00001259 unsigned i = 0;
Evan Chenge5e7ce42007-05-18 01:19:57 +00001260 const unsigned MAX_LOADS_IN_LDM = 6;
Evan Cheng4102eb52007-10-22 22:11:27 +00001261 SDOperand TFOps[MAX_LOADS_IN_LDM];
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001262 SDOperand Loads[MAX_LOADS_IN_LDM];
Dan Gohman1f13c682008-04-28 17:15:20 +00001263 uint64_t SrcOff = 0, DstOff = 0;
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001264
Evan Cheng4102eb52007-10-22 22:11:27 +00001265 // Emit up to MAX_LOADS_IN_LDM loads, then a TokenFactor barrier, then the
1266 // same number of stores. The loads and stores will get combined into
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001267 // ldm/stm later on.
Evan Cheng4102eb52007-10-22 22:11:27 +00001268 while (EmittedNumMemOps < NumMemOps) {
1269 for (i = 0;
1270 i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) {
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001271 Loads[i] = DAG.getLoad(VT, Chain,
Dan Gohman707e0182008-04-12 04:36:06 +00001272 DAG.getNode(ISD::ADD, MVT::i32, Src,
Evan Cheng4102eb52007-10-22 22:11:27 +00001273 DAG.getConstant(SrcOff, MVT::i32)),
Dan Gohman1f13c682008-04-28 17:15:20 +00001274 SrcSV, SrcSVOff + SrcOff);
Evan Cheng4102eb52007-10-22 22:11:27 +00001275 TFOps[i] = Loads[i].getValue(1);
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001276 SrcOff += VTSize;
1277 }
Evan Cheng4102eb52007-10-22 22:11:27 +00001278 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, &TFOps[0], i);
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001279
Evan Cheng4102eb52007-10-22 22:11:27 +00001280 for (i = 0;
1281 i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) {
1282 TFOps[i] = DAG.getStore(Chain, Loads[i],
Dan Gohman707e0182008-04-12 04:36:06 +00001283 DAG.getNode(ISD::ADD, MVT::i32, Dst,
Evan Cheng4102eb52007-10-22 22:11:27 +00001284 DAG.getConstant(DstOff, MVT::i32)),
Dan Gohman1f13c682008-04-28 17:15:20 +00001285 DstSV, DstSVOff + DstOff);
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001286 DstOff += VTSize;
1287 }
Evan Cheng4102eb52007-10-22 22:11:27 +00001288 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, &TFOps[0], i);
1289
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001290 EmittedNumMemOps += i;
1291 }
1292
Evan Cheng4102eb52007-10-22 22:11:27 +00001293 if (BytesLeft == 0)
1294 return Chain;
1295
1296 // Issue loads / stores for the trailing (1 - 3) bytes.
1297 unsigned BytesLeftSave = BytesLeft;
1298 i = 0;
1299 while (BytesLeft) {
1300 if (BytesLeft >= 2) {
1301 VT = MVT::i16;
1302 VTSize = 2;
1303 } else {
1304 VT = MVT::i8;
1305 VTSize = 1;
1306 }
1307
1308 Loads[i] = DAG.getLoad(VT, Chain,
Dan Gohman707e0182008-04-12 04:36:06 +00001309 DAG.getNode(ISD::ADD, MVT::i32, Src,
Evan Cheng4102eb52007-10-22 22:11:27 +00001310 DAG.getConstant(SrcOff, MVT::i32)),
Dan Gohman1f13c682008-04-28 17:15:20 +00001311 SrcSV, SrcSVOff + SrcOff);
Evan Cheng4102eb52007-10-22 22:11:27 +00001312 TFOps[i] = Loads[i].getValue(1);
1313 ++i;
1314 SrcOff += VTSize;
1315 BytesLeft -= VTSize;
1316 }
1317 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, &TFOps[0], i);
1318
1319 i = 0;
1320 BytesLeft = BytesLeftSave;
1321 while (BytesLeft) {
1322 if (BytesLeft >= 2) {
1323 VT = MVT::i16;
1324 VTSize = 2;
1325 } else {
1326 VT = MVT::i8;
1327 VTSize = 1;
1328 }
1329
1330 TFOps[i] = DAG.getStore(Chain, Loads[i],
Dan Gohman707e0182008-04-12 04:36:06 +00001331 DAG.getNode(ISD::ADD, MVT::i32, Dst,
Evan Cheng4102eb52007-10-22 22:11:27 +00001332 DAG.getConstant(DstOff, MVT::i32)),
Dan Gohman1f13c682008-04-28 17:15:20 +00001333 DstSV, DstSVOff + DstOff);
Evan Cheng4102eb52007-10-22 22:11:27 +00001334 ++i;
1335 DstOff += VTSize;
1336 BytesLeft -= VTSize;
1337 }
1338 return DAG.getNode(ISD::TokenFactor, MVT::Other, &TFOps[0], i);
Dale Johannesen8dd86c12007-05-17 21:31:21 +00001339}
1340
Chris Lattner27a6c732007-11-24 07:07:01 +00001341static SDNode *ExpandBIT_CONVERT(SDNode *N, SelectionDAG &DAG) {
1342 // Turn f64->i64 into FMRRD.
1343 assert(N->getValueType(0) == MVT::i64 &&
1344 N->getOperand(0).getValueType() == MVT::f64);
1345
1346 SDOperand Op = N->getOperand(0);
1347 SDOperand Cvt = DAG.getNode(ARMISD::FMRRD, DAG.getVTList(MVT::i32, MVT::i32),
1348 &Op, 1);
1349
1350 // Merge the pieces into a single i64 value.
1351 return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Cvt, Cvt.getValue(1)).Val;
1352}
1353
1354static SDNode *ExpandSRx(SDNode *N, SelectionDAG &DAG, const ARMSubtarget *ST) {
1355 assert(N->getValueType(0) == MVT::i64 &&
1356 (N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) &&
1357 "Unknown shift to lower!");
1358
1359 // We only lower SRA, SRL of 1 here, all others use generic lowering.
1360 if (!isa<ConstantSDNode>(N->getOperand(1)) ||
1361 cast<ConstantSDNode>(N->getOperand(1))->getValue() != 1)
1362 return 0;
1363
1364 // If we are in thumb mode, we don't have RRX.
1365 if (ST->isThumb()) return 0;
1366
1367 // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr.
1368 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, N->getOperand(0),
1369 DAG.getConstant(0, MVT::i32));
1370 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, N->getOperand(0),
1371 DAG.getConstant(1, MVT::i32));
1372
1373 // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and
1374 // captures the result into a carry flag.
1375 unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG;
1376 Hi = DAG.getNode(Opc, DAG.getVTList(MVT::i32, MVT::Flag), &Hi, 1);
1377
1378 // The low part is an ARMISD::RRX operand, which shifts the carry in.
1379 Lo = DAG.getNode(ARMISD::RRX, MVT::i32, Lo, Hi.getValue(1));
1380
1381 // Merge the pieces into a single i64 value.
1382 return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi).Val;
1383}
1384
1385
Evan Chenga8e29892007-01-19 07:51:42 +00001386SDOperand ARMTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
1387 switch (Op.getOpcode()) {
1388 default: assert(0 && "Don't know how to custom lower this!"); abort();
1389 case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001390 case ISD::GlobalAddress:
1391 return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) :
1392 LowerGlobalAddressELF(Op, DAG);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001393 case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
Evan Chenga8e29892007-01-19 07:51:42 +00001394 case ISD::CALL: return LowerCALL(Op, DAG);
1395 case ISD::RET: return LowerRET(Op, DAG);
1396 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG, Subtarget);
1397 case ISD::BR_CC: return LowerBR_CC(Op, DAG, Subtarget);
1398 case ISD::BR_JT: return LowerBR_JT(Op, DAG);
1399 case ISD::VASTART: return LowerVASTART(Op, DAG, VarArgsFrameIndex);
1400 case ISD::SINT_TO_FP:
1401 case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG);
1402 case ISD::FP_TO_SINT:
1403 case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG);
1404 case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG);
Chris Lattner27a6c732007-11-24 07:07:01 +00001405 case ISD::FORMAL_ARGUMENTS: return LowerFORMAL_ARGUMENTS(Op, DAG);
Nate Begemanbcc5f362007-01-29 22:58:52 +00001406 case ISD::RETURNADDR: break;
1407 case ISD::FRAMEADDR: break;
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001408 case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG);
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +00001409 case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG);
Chris Lattner27a6c732007-11-24 07:07:01 +00001410
1411
1412 // FIXME: Remove these when LegalizeDAGTypes lands.
1413 case ISD::BIT_CONVERT: return SDOperand(ExpandBIT_CONVERT(Op.Val, DAG), 0);
1414 case ISD::SRL:
1415 case ISD::SRA: return SDOperand(ExpandSRx(Op.Val, DAG,Subtarget),0);
Evan Chenga8e29892007-01-19 07:51:42 +00001416 }
Nate Begemanbcc5f362007-01-29 22:58:52 +00001417 return SDOperand();
Evan Chenga8e29892007-01-19 07:51:42 +00001418}
1419
Chris Lattner27a6c732007-11-24 07:07:01 +00001420
1421/// ExpandOperationResult - Provide custom lowering hooks for expanding
1422/// operations.
1423SDNode *ARMTargetLowering::ExpandOperationResult(SDNode *N, SelectionDAG &DAG) {
1424 switch (N->getOpcode()) {
1425 default: assert(0 && "Don't know how to custom expand this!"); abort();
1426 case ISD::BIT_CONVERT: return ExpandBIT_CONVERT(N, DAG);
1427 case ISD::SRL:
1428 case ISD::SRA: return ExpandSRx(N, DAG, Subtarget);
1429 }
1430}
1431
1432
Evan Chenga8e29892007-01-19 07:51:42 +00001433//===----------------------------------------------------------------------===//
1434// ARM Scheduler Hooks
1435//===----------------------------------------------------------------------===//
1436
1437MachineBasicBlock *
Evan Chengff9b3732008-01-30 18:18:23 +00001438ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Evan Chenga8e29892007-01-19 07:51:42 +00001439 MachineBasicBlock *BB) {
1440 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
1441 switch (MI->getOpcode()) {
1442 default: assert(false && "Unexpected instr type to insert");
1443 case ARM::tMOVCCr: {
1444 // To "insert" a SELECT_CC instruction, we actually have to insert the
1445 // diamond control-flow pattern. The incoming instruction knows the
1446 // destination vreg to set, the condition code register to branch on, the
1447 // true/false values to select between, and a branch opcode to use.
1448 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1449 ilist<MachineBasicBlock>::iterator It = BB;
1450 ++It;
1451
1452 // thisMBB:
1453 // ...
1454 // TrueVal = ...
1455 // cmpTY ccX, r1, r2
1456 // bCC copy1MBB
1457 // fallthrough --> copy0MBB
1458 MachineBasicBlock *thisMBB = BB;
1459 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1460 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1461 BuildMI(BB, TII->get(ARM::tBcc)).addMBB(sinkMBB)
Evan Cheng0e1d3792007-07-05 07:18:20 +00001462 .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg());
Evan Chenga8e29892007-01-19 07:51:42 +00001463 MachineFunction *F = BB->getParent();
1464 F->getBasicBlockList().insert(It, copy0MBB);
1465 F->getBasicBlockList().insert(It, sinkMBB);
1466 // Update machine-CFG edges by first adding all successors of the current
1467 // block to the new block which will contain the Phi node for the select.
1468 for(MachineBasicBlock::succ_iterator i = BB->succ_begin(),
1469 e = BB->succ_end(); i != e; ++i)
1470 sinkMBB->addSuccessor(*i);
1471 // Next, remove all successors of the current block, and add the true
1472 // and fallthrough blocks as its successors.
1473 while(!BB->succ_empty())
1474 BB->removeSuccessor(BB->succ_begin());
1475 BB->addSuccessor(copy0MBB);
1476 BB->addSuccessor(sinkMBB);
1477
1478 // copy0MBB:
1479 // %FalseValue = ...
1480 // # fallthrough to sinkMBB
1481 BB = copy0MBB;
1482
1483 // Update machine-CFG edges
1484 BB->addSuccessor(sinkMBB);
1485
1486 // sinkMBB:
1487 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1488 // ...
1489 BB = sinkMBB;
1490 BuildMI(BB, TII->get(ARM::PHI), MI->getOperand(0).getReg())
1491 .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
1492 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
1493
1494 delete MI; // The pseudo instruction is gone now.
1495 return BB;
1496 }
1497 }
1498}
1499
1500//===----------------------------------------------------------------------===//
1501// ARM Optimization Hooks
1502//===----------------------------------------------------------------------===//
1503
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +00001504/// PerformFMRRDCombine - Target-specific dag combine xforms for ARMISD::FMRRD.
1505static SDOperand PerformFMRRDCombine(SDNode *N,
1506 TargetLowering::DAGCombinerInfo &DCI) {
1507 // fmrrd(fmdrr x, y) -> x,y
1508 SDOperand InDouble = N->getOperand(0);
1509 if (InDouble.getOpcode() == ARMISD::FMDRR)
1510 return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1));
1511 return SDOperand();
1512}
1513
1514SDOperand ARMTargetLowering::PerformDAGCombine(SDNode *N,
1515 DAGCombinerInfo &DCI) const {
1516 switch (N->getOpcode()) {
1517 default: break;
1518 case ARMISD::FMRRD: return PerformFMRRDCombine(N, DCI);
1519 }
1520
1521 return SDOperand();
1522}
1523
1524
Evan Chengb01fad62007-03-12 23:30:29 +00001525/// isLegalAddressImmediate - Return true if the integer value can be used
1526/// as the offset of the target addressing mode for load / store of the
1527/// given type.
Duncan Sands83ec4b62008-06-06 12:08:01 +00001528static bool isLegalAddressImmediate(int64_t V, MVT VT,
Chris Lattner37caf8c2007-04-09 23:33:39 +00001529 const ARMSubtarget *Subtarget) {
Evan Cheng961f8792007-03-13 20:37:59 +00001530 if (V == 0)
1531 return true;
1532
Evan Chengb01fad62007-03-12 23:30:29 +00001533 if (Subtarget->isThumb()) {
1534 if (V < 0)
1535 return false;
1536
1537 unsigned Scale = 1;
Duncan Sands83ec4b62008-06-06 12:08:01 +00001538 switch (VT.getSimpleVT()) {
Evan Chengb01fad62007-03-12 23:30:29 +00001539 default: return false;
1540 case MVT::i1:
1541 case MVT::i8:
1542 // Scale == 1;
1543 break;
1544 case MVT::i16:
1545 // Scale == 2;
1546 Scale = 2;
1547 break;
1548 case MVT::i32:
1549 // Scale == 4;
1550 Scale = 4;
1551 break;
1552 }
1553
1554 if ((V & (Scale - 1)) != 0)
1555 return false;
1556 V /= Scale;
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +00001557 return V == (V & ((1LL << 5) - 1));
Evan Chengb01fad62007-03-12 23:30:29 +00001558 }
1559
1560 if (V < 0)
1561 V = - V;
Duncan Sands83ec4b62008-06-06 12:08:01 +00001562 switch (VT.getSimpleVT()) {
Evan Chengb01fad62007-03-12 23:30:29 +00001563 default: return false;
1564 case MVT::i1:
1565 case MVT::i8:
1566 case MVT::i32:
1567 // +- imm12
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +00001568 return V == (V & ((1LL << 12) - 1));
Evan Chengb01fad62007-03-12 23:30:29 +00001569 case MVT::i16:
1570 // +- imm8
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +00001571 return V == (V & ((1LL << 8) - 1));
Evan Chengb01fad62007-03-12 23:30:29 +00001572 case MVT::f32:
1573 case MVT::f64:
1574 if (!Subtarget->hasVFP2())
1575 return false;
Evan Cheng0b0a9a92007-05-03 02:00:18 +00001576 if ((V & 3) != 0)
Evan Chengb01fad62007-03-12 23:30:29 +00001577 return false;
1578 V >>= 2;
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +00001579 return V == (V & ((1LL << 8) - 1));
Evan Chengb01fad62007-03-12 23:30:29 +00001580 }
Evan Chenga8e29892007-01-19 07:51:42 +00001581}
1582
Chris Lattner37caf8c2007-04-09 23:33:39 +00001583/// isLegalAddressingMode - Return true if the addressing mode represented
1584/// by AM is legal for this target, for a load/store of the specified type.
1585bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM,
1586 const Type *Ty) const {
1587 if (!isLegalAddressImmediate(AM.BaseOffs, getValueType(Ty), Subtarget))
Evan Chengb01fad62007-03-12 23:30:29 +00001588 return false;
Chris Lattner37caf8c2007-04-09 23:33:39 +00001589
1590 // Can never fold addr of global into load/store.
1591 if (AM.BaseGV)
1592 return false;
1593
1594 switch (AM.Scale) {
1595 case 0: // no scale reg, must be "r+i" or "r", or "i".
1596 break;
1597 case 1:
1598 if (Subtarget->isThumb())
1599 return false;
Chris Lattner5a3d40d2007-04-13 06:50:55 +00001600 // FALL THROUGH.
Chris Lattner37caf8c2007-04-09 23:33:39 +00001601 default:
Chris Lattner5a3d40d2007-04-13 06:50:55 +00001602 // ARM doesn't support any R+R*scale+imm addr modes.
1603 if (AM.BaseOffs)
1604 return false;
1605
Chris Lattnereb13d1b2007-04-10 03:48:29 +00001606 int Scale = AM.Scale;
Duncan Sands83ec4b62008-06-06 12:08:01 +00001607 switch (getValueType(Ty).getSimpleVT()) {
Chris Lattner37caf8c2007-04-09 23:33:39 +00001608 default: return false;
1609 case MVT::i1:
1610 case MVT::i8:
1611 case MVT::i32:
1612 case MVT::i64:
1613 // This assumes i64 is legalized to a pair of i32. If not (i.e.
1614 // ldrd / strd are used, then its address mode is same as i16.
1615 // r + r
Chris Lattnereb13d1b2007-04-10 03:48:29 +00001616 if (Scale < 0) Scale = -Scale;
1617 if (Scale == 1)
Chris Lattner37caf8c2007-04-09 23:33:39 +00001618 return true;
1619 // r + r << imm
Chris Lattnere1152942007-04-11 16:17:12 +00001620 return isPowerOf2_32(Scale & ~1);
Chris Lattner37caf8c2007-04-09 23:33:39 +00001621 case MVT::i16:
1622 // r + r
Chris Lattnereb13d1b2007-04-10 03:48:29 +00001623 if (((unsigned)AM.HasBaseReg + Scale) <= 2)
Chris Lattner37caf8c2007-04-09 23:33:39 +00001624 return true;
Chris Lattnere1152942007-04-11 16:17:12 +00001625 return false;
1626
Chris Lattner37caf8c2007-04-09 23:33:39 +00001627 case MVT::isVoid:
1628 // Note, we allow "void" uses (basically, uses that aren't loads or
1629 // stores), because arm allows folding a scale into many arithmetic
1630 // operations. This should be made more precise and revisited later.
Chris Lattnerb2c594f2007-04-03 00:13:57 +00001631
Chris Lattner37caf8c2007-04-09 23:33:39 +00001632 // Allow r << imm, but the imm has to be a multiple of two.
1633 if (AM.Scale & 1) return false;
1634 return isPowerOf2_32(AM.Scale);
1635 }
1636 break;
Evan Chengb01fad62007-03-12 23:30:29 +00001637 }
Chris Lattner37caf8c2007-04-09 23:33:39 +00001638 return true;
Evan Chengb01fad62007-03-12 23:30:29 +00001639}
1640
Chris Lattner37caf8c2007-04-09 23:33:39 +00001641
Duncan Sands83ec4b62008-06-06 12:08:01 +00001642static bool getIndexedAddressParts(SDNode *Ptr, MVT VT,
Evan Chenga8e29892007-01-19 07:51:42 +00001643 bool isSEXTLoad, SDOperand &Base,
1644 SDOperand &Offset, bool &isInc,
1645 SelectionDAG &DAG) {
1646 if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB)
1647 return false;
1648
1649 if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) {
1650 // AddressingMode 3
1651 Base = Ptr->getOperand(0);
1652 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) {
1653 int RHSC = (int)RHS->getValue();
1654 if (RHSC < 0 && RHSC > -256) {
1655 isInc = false;
1656 Offset = DAG.getConstant(-RHSC, RHS->getValueType(0));
1657 return true;
1658 }
1659 }
1660 isInc = (Ptr->getOpcode() == ISD::ADD);
1661 Offset = Ptr->getOperand(1);
1662 return true;
1663 } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) {
1664 // AddressingMode 2
1665 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) {
1666 int RHSC = (int)RHS->getValue();
1667 if (RHSC < 0 && RHSC > -0x1000) {
1668 isInc = false;
1669 Offset = DAG.getConstant(-RHSC, RHS->getValueType(0));
1670 Base = Ptr->getOperand(0);
1671 return true;
1672 }
1673 }
1674
1675 if (Ptr->getOpcode() == ISD::ADD) {
1676 isInc = true;
1677 ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0));
1678 if (ShOpcVal != ARM_AM::no_shift) {
1679 Base = Ptr->getOperand(1);
1680 Offset = Ptr->getOperand(0);
1681 } else {
1682 Base = Ptr->getOperand(0);
1683 Offset = Ptr->getOperand(1);
1684 }
1685 return true;
1686 }
1687
1688 isInc = (Ptr->getOpcode() == ISD::ADD);
1689 Base = Ptr->getOperand(0);
1690 Offset = Ptr->getOperand(1);
1691 return true;
1692 }
1693
1694 // FIXME: Use FLDM / FSTM to emulate indexed FP load / store.
1695 return false;
1696}
1697
1698/// getPreIndexedAddressParts - returns true by value, base pointer and
1699/// offset pointer and addressing mode by reference if the node's address
1700/// can be legally represented as pre-indexed load / store address.
1701bool
1702ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDOperand &Base,
1703 SDOperand &Offset,
1704 ISD::MemIndexedMode &AM,
1705 SelectionDAG &DAG) {
1706 if (Subtarget->isThumb())
1707 return false;
1708
Duncan Sands83ec4b62008-06-06 12:08:01 +00001709 MVT VT;
Evan Chenga8e29892007-01-19 07:51:42 +00001710 SDOperand Ptr;
1711 bool isSEXTLoad = false;
1712 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
1713 Ptr = LD->getBasePtr();
Dan Gohmanb625f2f2008-01-30 00:15:11 +00001714 VT = LD->getMemoryVT();
Evan Chenga8e29892007-01-19 07:51:42 +00001715 isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD;
1716 } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
1717 Ptr = ST->getBasePtr();
Dan Gohmanb625f2f2008-01-30 00:15:11 +00001718 VT = ST->getMemoryVT();
Evan Chenga8e29892007-01-19 07:51:42 +00001719 } else
1720 return false;
1721
1722 bool isInc;
1723 bool isLegal = getIndexedAddressParts(Ptr.Val, VT, isSEXTLoad, Base, Offset,
1724 isInc, DAG);
1725 if (isLegal) {
1726 AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC;
1727 return true;
1728 }
1729 return false;
1730}
1731
1732/// getPostIndexedAddressParts - returns true by value, base pointer and
1733/// offset pointer and addressing mode by reference if this node can be
1734/// combined with a load / store to form a post-indexed load / store.
1735bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
1736 SDOperand &Base,
1737 SDOperand &Offset,
1738 ISD::MemIndexedMode &AM,
1739 SelectionDAG &DAG) {
1740 if (Subtarget->isThumb())
1741 return false;
1742
Duncan Sands83ec4b62008-06-06 12:08:01 +00001743 MVT VT;
Evan Chenga8e29892007-01-19 07:51:42 +00001744 SDOperand Ptr;
1745 bool isSEXTLoad = false;
1746 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
Dan Gohmanb625f2f2008-01-30 00:15:11 +00001747 VT = LD->getMemoryVT();
Evan Chenga8e29892007-01-19 07:51:42 +00001748 isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD;
1749 } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Dan Gohmanb625f2f2008-01-30 00:15:11 +00001750 VT = ST->getMemoryVT();
Evan Chenga8e29892007-01-19 07:51:42 +00001751 } else
1752 return false;
1753
1754 bool isInc;
1755 bool isLegal = getIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset,
1756 isInc, DAG);
1757 if (isLegal) {
1758 AM = isInc ? ISD::POST_INC : ISD::POST_DEC;
1759 return true;
1760 }
1761 return false;
1762}
1763
1764void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
Dan Gohman977a76f2008-02-13 22:28:48 +00001765 const APInt &Mask,
Dan Gohmanfd29e0e2008-02-13 00:35:47 +00001766 APInt &KnownZero,
1767 APInt &KnownOne,
Dan Gohmanea859be2007-06-22 14:59:07 +00001768 const SelectionDAG &DAG,
Evan Chenga8e29892007-01-19 07:51:42 +00001769 unsigned Depth) const {
Dan Gohmanfd29e0e2008-02-13 00:35:47 +00001770 KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0);
Evan Chenga8e29892007-01-19 07:51:42 +00001771 switch (Op.getOpcode()) {
1772 default: break;
1773 case ARMISD::CMOV: {
1774 // Bits are known zero/one if known on the LHS and RHS.
Dan Gohmanea859be2007-06-22 14:59:07 +00001775 DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1);
Evan Chenga8e29892007-01-19 07:51:42 +00001776 if (KnownZero == 0 && KnownOne == 0) return;
1777
Dan Gohmanfd29e0e2008-02-13 00:35:47 +00001778 APInt KnownZeroRHS, KnownOneRHS;
Dan Gohmanea859be2007-06-22 14:59:07 +00001779 DAG.ComputeMaskedBits(Op.getOperand(1), Mask,
1780 KnownZeroRHS, KnownOneRHS, Depth+1);
Evan Chenga8e29892007-01-19 07:51:42 +00001781 KnownZero &= KnownZeroRHS;
1782 KnownOne &= KnownOneRHS;
1783 return;
1784 }
1785 }
1786}
1787
1788//===----------------------------------------------------------------------===//
1789// ARM Inline Assembly Support
1790//===----------------------------------------------------------------------===//
1791
1792/// getConstraintType - Given a constraint letter, return the type of
1793/// constraint it is for this target.
1794ARMTargetLowering::ConstraintType
Chris Lattner4234f572007-03-25 02:14:49 +00001795ARMTargetLowering::getConstraintType(const std::string &Constraint) const {
1796 if (Constraint.size() == 1) {
1797 switch (Constraint[0]) {
1798 default: break;
1799 case 'l': return C_RegisterClass;
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00001800 case 'w': return C_RegisterClass;
Chris Lattner4234f572007-03-25 02:14:49 +00001801 }
Evan Chenga8e29892007-01-19 07:51:42 +00001802 }
Chris Lattner4234f572007-03-25 02:14:49 +00001803 return TargetLowering::getConstraintType(Constraint);
Evan Chenga8e29892007-01-19 07:51:42 +00001804}
1805
1806std::pair<unsigned, const TargetRegisterClass*>
1807ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
Duncan Sands83ec4b62008-06-06 12:08:01 +00001808 MVT VT) const {
Evan Chenga8e29892007-01-19 07:51:42 +00001809 if (Constraint.size() == 1) {
1810 // GCC RS6000 Constraint Letters
1811 switch (Constraint[0]) {
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00001812 case 'l':
1813 // FIXME: in thumb mode, 'l' is only low-regs.
1814 // FALL THROUGH.
1815 case 'r':
1816 return std::make_pair(0U, ARM::GPRRegisterClass);
1817 case 'w':
1818 if (VT == MVT::f32)
1819 return std::make_pair(0U, ARM::SPRRegisterClass);
Evan Cheng0a7baa22007-04-04 00:06:07 +00001820 if (VT == MVT::f64)
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00001821 return std::make_pair(0U, ARM::DPRRegisterClass);
1822 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001823 }
1824 }
1825 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
1826}
1827
1828std::vector<unsigned> ARMTargetLowering::
1829getRegClassForInlineAsmConstraint(const std::string &Constraint,
Duncan Sands83ec4b62008-06-06 12:08:01 +00001830 MVT VT) const {
Evan Chenga8e29892007-01-19 07:51:42 +00001831 if (Constraint.size() != 1)
1832 return std::vector<unsigned>();
1833
1834 switch (Constraint[0]) { // GCC ARM Constraint Letters
1835 default: break;
1836 case 'l':
1837 case 'r':
1838 return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3,
1839 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
1840 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
1841 ARM::R12, ARM::LR, 0);
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00001842 case 'w':
1843 if (VT == MVT::f32)
1844 return make_vector<unsigned>(ARM::S0, ARM::S1, ARM::S2, ARM::S3,
1845 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
1846 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
1847 ARM::S12,ARM::S13,ARM::S14,ARM::S15,
1848 ARM::S16,ARM::S17,ARM::S18,ARM::S19,
1849 ARM::S20,ARM::S21,ARM::S22,ARM::S23,
1850 ARM::S24,ARM::S25,ARM::S26,ARM::S27,
1851 ARM::S28,ARM::S29,ARM::S30,ARM::S31, 0);
1852 if (VT == MVT::f64)
1853 return make_vector<unsigned>(ARM::D0, ARM::D1, ARM::D2, ARM::D3,
1854 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
1855 ARM::D8, ARM::D9, ARM::D10,ARM::D11,
1856 ARM::D12,ARM::D13,ARM::D14,ARM::D15, 0);
1857 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001858 }
1859
1860 return std::vector<unsigned>();
1861}