blob: dd84c3c936dbfb776c13f6ca7594e9df1a98377f [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"
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +000020#include "ARMPerfectShuffle.h"
Evan Chenga8e29892007-01-19 07:51:42 +000021#include "ARMRegisterInfo.h"
22#include "ARMSubtarget.h"
23#include "ARMTargetMachine.h"
Chris Lattner80ec2792009-08-02 00:34:36 +000024#include "ARMTargetObjectFile.h"
Evan Chenga8e29892007-01-19 07:51:42 +000025#include "llvm/CallingConv.h"
26#include "llvm/Constants.h"
Bob Wilson1f595bb2009-04-17 19:07:39 +000027#include "llvm/Function.h"
Benjamin Kramer174101e2009-10-20 11:44:38 +000028#include "llvm/GlobalValue.h"
Evan Cheng27707472007-03-16 08:43:56 +000029#include "llvm/Instruction.h"
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +000030#include "llvm/Intrinsics.h"
Benjamin Kramer174101e2009-10-20 11:44:38 +000031#include "llvm/Type.h"
Bob Wilson1f595bb2009-04-17 19:07:39 +000032#include "llvm/CodeGen/CallingConvLower.h"
Evan Chenga8e29892007-01-19 07:51:42 +000033#include "llvm/CodeGen/MachineBasicBlock.h"
34#include "llvm/CodeGen/MachineFrameInfo.h"
35#include "llvm/CodeGen/MachineFunction.h"
36#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000037#include "llvm/CodeGen/MachineRegisterInfo.h"
Bob Wilson1f595bb2009-04-17 19:07:39 +000038#include "llvm/CodeGen/PseudoSourceValue.h"
Evan Chenga8e29892007-01-19 07:51:42 +000039#include "llvm/CodeGen/SelectionDAG.h"
Evan Chengb6ab2542007-01-31 08:40:13 +000040#include "llvm/Target/TargetOptions.h"
Evan Chenga8e29892007-01-19 07:51:42 +000041#include "llvm/ADT/VectorExtras.h"
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +000042#include "llvm/Support/CommandLine.h"
Torok Edwinab7c09b2009-07-08 18:01:40 +000043#include "llvm/Support/ErrorHandling.h"
Evan Chengb01fad62007-03-12 23:30:29 +000044#include "llvm/Support/MathExtras.h"
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000045#include <sstream>
Evan Chenga8e29892007-01-19 07:51:42 +000046using namespace llvm;
47
Owen Andersone50ed302009-08-10 22:56:29 +000048static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson1f595bb2009-04-17 19:07:39 +000049 CCValAssign::LocInfo &LocInfo,
50 ISD::ArgFlagsTy &ArgFlags,
51 CCState &State);
Owen Andersone50ed302009-08-10 22:56:29 +000052static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson1f595bb2009-04-17 19:07:39 +000053 CCValAssign::LocInfo &LocInfo,
54 ISD::ArgFlagsTy &ArgFlags,
55 CCState &State);
Owen Andersone50ed302009-08-10 22:56:29 +000056static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson1f595bb2009-04-17 19:07:39 +000057 CCValAssign::LocInfo &LocInfo,
58 ISD::ArgFlagsTy &ArgFlags,
59 CCState &State);
Owen Andersone50ed302009-08-10 22:56:29 +000060static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson1f595bb2009-04-17 19:07:39 +000061 CCValAssign::LocInfo &LocInfo,
62 ISD::ArgFlagsTy &ArgFlags,
63 CCState &State);
64
Owen Andersone50ed302009-08-10 22:56:29 +000065void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT,
66 EVT PromotedBitwiseVT) {
Bob Wilson5bafff32009-06-22 23:27:02 +000067 if (VT != PromotedLdStVT) {
Owen Anderson70671842009-08-10 20:18:46 +000068 setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote);
Owen Andersond6662ad2009-08-10 20:46:15 +000069 AddPromotedToType (ISD::LOAD, VT.getSimpleVT(),
70 PromotedLdStVT.getSimpleVT());
Bob Wilson5bafff32009-06-22 23:27:02 +000071
Owen Anderson70671842009-08-10 20:18:46 +000072 setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote);
Jim Grosbach764ab522009-08-11 15:33:49 +000073 AddPromotedToType (ISD::STORE, VT.getSimpleVT(),
Owen Andersond6662ad2009-08-10 20:46:15 +000074 PromotedLdStVT.getSimpleVT());
Bob Wilson5bafff32009-06-22 23:27:02 +000075 }
76
Owen Andersone50ed302009-08-10 22:56:29 +000077 EVT ElemTy = VT.getVectorElementType();
Owen Anderson825b72b2009-08-11 20:47:22 +000078 if (ElemTy != MVT::i64 && ElemTy != MVT::f64)
Owen Anderson70671842009-08-10 20:18:46 +000079 setOperationAction(ISD::VSETCC, VT.getSimpleVT(), Custom);
Owen Anderson825b72b2009-08-11 20:47:22 +000080 if (ElemTy == MVT::i8 || ElemTy == MVT::i16)
Owen Anderson70671842009-08-10 20:18:46 +000081 setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom);
Bob Wilson0696fdf2009-09-16 20:20:44 +000082 if (ElemTy != MVT::i32) {
83 setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand);
84 setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand);
85 setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand);
86 setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand);
87 }
Owen Anderson70671842009-08-10 20:18:46 +000088 setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom);
89 setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom);
Owen Anderson70671842009-08-10 20:18:46 +000090 setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Custom);
Anton Korobeynikov8e6c2b92009-08-21 12:40:35 +000091 setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Expand);
Bob Wilson5bafff32009-06-22 23:27:02 +000092 if (VT.isInteger()) {
Owen Anderson70671842009-08-10 20:18:46 +000093 setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom);
94 setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom);
95 setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom);
Bob Wilson5bafff32009-06-22 23:27:02 +000096 }
97
98 // Promote all bit-wise operations.
99 if (VT.isInteger() && VT != PromotedBitwiseVT) {
Owen Anderson70671842009-08-10 20:18:46 +0000100 setOperationAction(ISD::AND, VT.getSimpleVT(), Promote);
Owen Andersond6662ad2009-08-10 20:46:15 +0000101 AddPromotedToType (ISD::AND, VT.getSimpleVT(),
102 PromotedBitwiseVT.getSimpleVT());
Owen Anderson70671842009-08-10 20:18:46 +0000103 setOperationAction(ISD::OR, VT.getSimpleVT(), Promote);
Jim Grosbach764ab522009-08-11 15:33:49 +0000104 AddPromotedToType (ISD::OR, VT.getSimpleVT(),
Owen Andersond6662ad2009-08-10 20:46:15 +0000105 PromotedBitwiseVT.getSimpleVT());
Owen Anderson70671842009-08-10 20:18:46 +0000106 setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote);
Jim Grosbach764ab522009-08-11 15:33:49 +0000107 AddPromotedToType (ISD::XOR, VT.getSimpleVT(),
Owen Andersond6662ad2009-08-10 20:46:15 +0000108 PromotedBitwiseVT.getSimpleVT());
Bob Wilson5bafff32009-06-22 23:27:02 +0000109 }
Bob Wilson16330762009-09-16 00:17:28 +0000110
111 // Neon does not support vector divide/remainder operations.
112 setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand);
113 setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand);
114 setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand);
115 setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand);
116 setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand);
117 setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand);
Bob Wilson5bafff32009-06-22 23:27:02 +0000118}
119
Owen Andersone50ed302009-08-10 22:56:29 +0000120void ARMTargetLowering::addDRTypeForNEON(EVT VT) {
Bob Wilson5bafff32009-06-22 23:27:02 +0000121 addRegisterClass(VT, ARM::DPRRegisterClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000122 addTypeForNEON(VT, MVT::f64, MVT::v2i32);
Bob Wilson5bafff32009-06-22 23:27:02 +0000123}
124
Owen Andersone50ed302009-08-10 22:56:29 +0000125void ARMTargetLowering::addQRTypeForNEON(EVT VT) {
Bob Wilson5bafff32009-06-22 23:27:02 +0000126 addRegisterClass(VT, ARM::QPRRegisterClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000127 addTypeForNEON(VT, MVT::v2f64, MVT::v4i32);
Bob Wilson5bafff32009-06-22 23:27:02 +0000128}
129
Chris Lattnerf0144122009-07-28 03:13:23 +0000130static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) {
131 if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin())
Chris Lattnerf26e03b2009-07-31 17:42:42 +0000132 return new TargetLoweringObjectFileMachO();
Chris Lattner80ec2792009-08-02 00:34:36 +0000133 return new ARMElfTargetObjectFile();
Chris Lattnerf0144122009-07-28 03:13:23 +0000134}
135
Evan Chenga8e29892007-01-19 07:51:42 +0000136ARMTargetLowering::ARMTargetLowering(TargetMachine &TM)
Evan Chenge7e0d622009-11-06 22:24:13 +0000137 : TargetLowering(TM, createTLOF(TM)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000138 Subtarget = &TM.getSubtarget<ARMSubtarget>();
139
Evan Chengb1df8f22007-04-27 08:15:43 +0000140 if (Subtarget->isTargetDarwin()) {
Evan Chengb1df8f22007-04-27 08:15:43 +0000141 // Uses VFP for Thumb libfuncs if available.
142 if (Subtarget->isThumb() && Subtarget->hasVFP2()) {
143 // Single-precision floating-point arithmetic.
144 setLibcallName(RTLIB::ADD_F32, "__addsf3vfp");
145 setLibcallName(RTLIB::SUB_F32, "__subsf3vfp");
146 setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp");
147 setLibcallName(RTLIB::DIV_F32, "__divsf3vfp");
Evan Chenga8e29892007-01-19 07:51:42 +0000148
Evan Chengb1df8f22007-04-27 08:15:43 +0000149 // Double-precision floating-point arithmetic.
150 setLibcallName(RTLIB::ADD_F64, "__adddf3vfp");
151 setLibcallName(RTLIB::SUB_F64, "__subdf3vfp");
152 setLibcallName(RTLIB::MUL_F64, "__muldf3vfp");
153 setLibcallName(RTLIB::DIV_F64, "__divdf3vfp");
Evan Cheng193f8502007-01-31 09:30:58 +0000154
Evan Chengb1df8f22007-04-27 08:15:43 +0000155 // Single-precision comparisons.
156 setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp");
157 setLibcallName(RTLIB::UNE_F32, "__nesf2vfp");
158 setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp");
159 setLibcallName(RTLIB::OLE_F32, "__lesf2vfp");
160 setLibcallName(RTLIB::OGE_F32, "__gesf2vfp");
161 setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp");
162 setLibcallName(RTLIB::UO_F32, "__unordsf2vfp");
163 setLibcallName(RTLIB::O_F32, "__unordsf2vfp");
Evan Chenga8e29892007-01-19 07:51:42 +0000164
Evan Chengb1df8f22007-04-27 08:15:43 +0000165 setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE);
166 setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE);
167 setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE);
168 setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE);
169 setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE);
170 setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE);
171 setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE);
172 setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ);
Evan Cheng193f8502007-01-31 09:30:58 +0000173
Evan Chengb1df8f22007-04-27 08:15:43 +0000174 // Double-precision comparisons.
175 setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp");
176 setLibcallName(RTLIB::UNE_F64, "__nedf2vfp");
177 setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp");
178 setLibcallName(RTLIB::OLE_F64, "__ledf2vfp");
179 setLibcallName(RTLIB::OGE_F64, "__gedf2vfp");
180 setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp");
181 setLibcallName(RTLIB::UO_F64, "__unorddf2vfp");
182 setLibcallName(RTLIB::O_F64, "__unorddf2vfp");
Evan Chenga8e29892007-01-19 07:51:42 +0000183
Evan Chengb1df8f22007-04-27 08:15:43 +0000184 setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE);
185 setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE);
186 setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE);
187 setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE);
188 setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE);
189 setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE);
190 setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE);
191 setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ);
Evan Chenga8e29892007-01-19 07:51:42 +0000192
Evan Chengb1df8f22007-04-27 08:15:43 +0000193 // Floating-point to integer conversions.
194 // i64 conversions are done via library routines even when generating VFP
195 // instructions, so use the same ones.
196 setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp");
197 setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp");
198 setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp");
199 setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp");
Evan Chenga8e29892007-01-19 07:51:42 +0000200
Evan Chengb1df8f22007-04-27 08:15:43 +0000201 // Conversions between floating types.
202 setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp");
203 setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp");
204
205 // Integer to floating-point conversions.
206 // i64 conversions are done via library routines even when generating VFP
207 // instructions, so use the same ones.
Bob Wilson2a14c522009-03-20 23:16:43 +0000208 // FIXME: There appears to be some naming inconsistency in ARM libgcc:
209 // e.g., __floatunsidf vs. __floatunssidfvfp.
Evan Chengb1df8f22007-04-27 08:15:43 +0000210 setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp");
211 setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp");
212 setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp");
213 setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp");
214 }
Evan Chenga8e29892007-01-19 07:51:42 +0000215 }
216
Bob Wilson2f954612009-05-22 17:38:41 +0000217 // These libcalls are not available in 32-bit.
218 setLibcallName(RTLIB::SHL_I128, 0);
219 setLibcallName(RTLIB::SRL_I128, 0);
220 setLibcallName(RTLIB::SRA_I128, 0);
221
Anton Korobeynikov72977a42009-08-14 20:10:52 +0000222 // Libcalls should use the AAPCS base standard ABI, even if hard float
223 // is in effect, as per the ARM RTABI specification, section 4.1.2.
224 if (Subtarget->isAAPCS_ABI()) {
225 for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) {
226 setLibcallCallingConv(static_cast<RTLIB::Libcall>(i),
227 CallingConv::ARM_AAPCS);
228 }
229 }
230
David Goodwinf1daf7d2009-07-08 23:10:31 +0000231 if (Subtarget->isThumb1Only())
Owen Anderson825b72b2009-08-11 20:47:22 +0000232 addRegisterClass(MVT::i32, ARM::tGPRRegisterClass);
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000233 else
Owen Anderson825b72b2009-08-11 20:47:22 +0000234 addRegisterClass(MVT::i32, ARM::GPRRegisterClass);
David Goodwinf1daf7d2009-07-08 23:10:31 +0000235 if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000236 addRegisterClass(MVT::f32, ARM::SPRRegisterClass);
237 addRegisterClass(MVT::f64, ARM::DPRRegisterClass);
Bob Wilson2dc4f542009-03-20 22:42:55 +0000238
Owen Anderson825b72b2009-08-11 20:47:22 +0000239 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000240 }
Bob Wilson5bafff32009-06-22 23:27:02 +0000241
242 if (Subtarget->hasNEON()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000243 addDRTypeForNEON(MVT::v2f32);
244 addDRTypeForNEON(MVT::v8i8);
245 addDRTypeForNEON(MVT::v4i16);
246 addDRTypeForNEON(MVT::v2i32);
247 addDRTypeForNEON(MVT::v1i64);
Bob Wilson5bafff32009-06-22 23:27:02 +0000248
Owen Anderson825b72b2009-08-11 20:47:22 +0000249 addQRTypeForNEON(MVT::v4f32);
250 addQRTypeForNEON(MVT::v2f64);
251 addQRTypeForNEON(MVT::v16i8);
252 addQRTypeForNEON(MVT::v8i16);
253 addQRTypeForNEON(MVT::v4i32);
254 addQRTypeForNEON(MVT::v2i64);
Bob Wilson5bafff32009-06-22 23:27:02 +0000255
Bob Wilson74dc72e2009-09-15 23:55:57 +0000256 // v2f64 is legal so that QR subregs can be extracted as f64 elements, but
257 // neither Neon nor VFP support any arithmetic operations on it.
258 setOperationAction(ISD::FADD, MVT::v2f64, Expand);
259 setOperationAction(ISD::FSUB, MVT::v2f64, Expand);
260 setOperationAction(ISD::FMUL, MVT::v2f64, Expand);
261 setOperationAction(ISD::FDIV, MVT::v2f64, Expand);
262 setOperationAction(ISD::FREM, MVT::v2f64, Expand);
263 setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand);
264 setOperationAction(ISD::VSETCC, MVT::v2f64, Expand);
265 setOperationAction(ISD::FNEG, MVT::v2f64, Expand);
266 setOperationAction(ISD::FABS, MVT::v2f64, Expand);
267 setOperationAction(ISD::FSQRT, MVT::v2f64, Expand);
268 setOperationAction(ISD::FSIN, MVT::v2f64, Expand);
269 setOperationAction(ISD::FCOS, MVT::v2f64, Expand);
270 setOperationAction(ISD::FPOWI, MVT::v2f64, Expand);
271 setOperationAction(ISD::FPOW, MVT::v2f64, Expand);
272 setOperationAction(ISD::FLOG, MVT::v2f64, Expand);
273 setOperationAction(ISD::FLOG2, MVT::v2f64, Expand);
274 setOperationAction(ISD::FLOG10, MVT::v2f64, Expand);
275 setOperationAction(ISD::FEXP, MVT::v2f64, Expand);
276 setOperationAction(ISD::FEXP2, MVT::v2f64, Expand);
277 setOperationAction(ISD::FCEIL, MVT::v2f64, Expand);
278 setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand);
279 setOperationAction(ISD::FRINT, MVT::v2f64, Expand);
280 setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand);
281 setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand);
282
Bob Wilson642b3292009-09-16 00:32:15 +0000283 // Neon does not support some operations on v1i64 and v2i64 types.
284 setOperationAction(ISD::MUL, MVT::v1i64, Expand);
285 setOperationAction(ISD::MUL, MVT::v2i64, Expand);
286 setOperationAction(ISD::VSETCC, MVT::v1i64, Expand);
287 setOperationAction(ISD::VSETCC, MVT::v2i64, Expand);
288
Bob Wilson5bafff32009-06-22 23:27:02 +0000289 setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN);
290 setTargetDAGCombine(ISD::SHL);
291 setTargetDAGCombine(ISD::SRL);
292 setTargetDAGCombine(ISD::SRA);
293 setTargetDAGCombine(ISD::SIGN_EXTEND);
294 setTargetDAGCombine(ISD::ZERO_EXTEND);
295 setTargetDAGCombine(ISD::ANY_EXTEND);
296 }
297
Evan Cheng9f8cbd12007-05-18 00:19:34 +0000298 computeRegisterProperties();
Evan Chenga8e29892007-01-19 07:51:42 +0000299
300 // ARM does not have f32 extending load.
Owen Anderson825b72b2009-08-11 20:47:22 +0000301 setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000302
Duncan Sandsf9c98e62008-01-23 20:39:46 +0000303 // ARM does not have i1 sign extending load.
Owen Anderson825b72b2009-08-11 20:47:22 +0000304 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
Duncan Sandsf9c98e62008-01-23 20:39:46 +0000305
Evan Chenga8e29892007-01-19 07:51:42 +0000306 // ARM supports all 4 flavors of integer indexed load / store.
Evan Chenge88d5ce2009-07-02 07:28:31 +0000307 if (!Subtarget->isThumb1Only()) {
308 for (unsigned im = (unsigned)ISD::PRE_INC;
309 im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000310 setIndexedLoadAction(im, MVT::i1, Legal);
311 setIndexedLoadAction(im, MVT::i8, Legal);
312 setIndexedLoadAction(im, MVT::i16, Legal);
313 setIndexedLoadAction(im, MVT::i32, Legal);
314 setIndexedStoreAction(im, MVT::i1, Legal);
315 setIndexedStoreAction(im, MVT::i8, Legal);
316 setIndexedStoreAction(im, MVT::i16, Legal);
317 setIndexedStoreAction(im, MVT::i32, Legal);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000318 }
Evan Chenga8e29892007-01-19 07:51:42 +0000319 }
320
321 // i64 operation support.
Evan Cheng5b9fcd12009-07-07 01:17:28 +0000322 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000323 setOperationAction(ISD::MUL, MVT::i64, Expand);
324 setOperationAction(ISD::MULHU, MVT::i32, Expand);
325 setOperationAction(ISD::MULHS, MVT::i32, Expand);
326 setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand);
327 setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000328 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +0000329 setOperationAction(ISD::MUL, MVT::i64, Expand);
330 setOperationAction(ISD::MULHU, MVT::i32, Expand);
Evan Chengb6207242009-08-01 00:16:10 +0000331 if (!Subtarget->hasV6Ops())
Owen Anderson825b72b2009-08-11 20:47:22 +0000332 setOperationAction(ISD::MULHS, MVT::i32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000333 }
Jim Grosbachc2b879f2009-10-31 19:38:01 +0000334 setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom);
Jim Grosbachb4a976c2009-10-31 21:00:56 +0000335 setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom);
Jim Grosbachbcf2f2c2009-10-31 21:42:19 +0000336 setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom);
Owen Anderson825b72b2009-08-11 20:47:22 +0000337 setOperationAction(ISD::SRL, MVT::i64, Custom);
338 setOperationAction(ISD::SRA, MVT::i64, Custom);
Evan Chenga8e29892007-01-19 07:51:42 +0000339
340 // ARM does not have ROTL.
Owen Anderson825b72b2009-08-11 20:47:22 +0000341 setOperationAction(ISD::ROTL, MVT::i32, Expand);
342 setOperationAction(ISD::CTTZ, MVT::i32, Expand);
343 setOperationAction(ISD::CTPOP, MVT::i32, Expand);
David Goodwin24062ac2009-06-26 20:47:43 +0000344 if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only())
Owen Anderson825b72b2009-08-11 20:47:22 +0000345 setOperationAction(ISD::CTLZ, MVT::i32, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000346
Lauro Ramos Venancio368f20f2007-03-16 22:54:16 +0000347 // Only ARMv6 has BSWAP.
348 if (!Subtarget->hasV6Ops())
Owen Anderson825b72b2009-08-11 20:47:22 +0000349 setOperationAction(ISD::BSWAP, MVT::i32, Expand);
Lauro Ramos Venancio368f20f2007-03-16 22:54:16 +0000350
Evan Chenga8e29892007-01-19 07:51:42 +0000351 // These are expanded into libcalls.
Owen Anderson825b72b2009-08-11 20:47:22 +0000352 setOperationAction(ISD::SDIV, MVT::i32, Expand);
353 setOperationAction(ISD::UDIV, MVT::i32, Expand);
354 setOperationAction(ISD::SREM, MVT::i32, Expand);
355 setOperationAction(ISD::UREM, MVT::i32, Expand);
356 setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
357 setOperationAction(ISD::UDIVREM, MVT::i32, Expand);
Bob Wilson2dc4f542009-03-20 22:42:55 +0000358
Owen Anderson825b72b2009-08-11 20:47:22 +0000359 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
360 setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
361 setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom);
362 setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom);
Bob Wilsonddb16df2009-10-30 05:45:42 +0000363 setOperationAction(ISD::BlockAddress, MVT::i32, Custom);
Evan Chenga8e29892007-01-19 07:51:42 +0000364
Evan Chenga8e29892007-01-19 07:51:42 +0000365 // Use the default implementation.
Owen Anderson825b72b2009-08-11 20:47:22 +0000366 setOperationAction(ISD::VASTART, MVT::Other, Custom);
367 setOperationAction(ISD::VAARG, MVT::Other, Expand);
368 setOperationAction(ISD::VACOPY, MVT::Other, Expand);
369 setOperationAction(ISD::VAEND, MVT::Other, Expand);
370 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
371 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
Jim Grosbachbff39232009-08-12 17:38:44 +0000372 setOperationAction(ISD::EHSELECTION, MVT::i32, Expand);
373 // FIXME: Shouldn't need this, since no register is used, but the legalizer
374 // doesn't yet know how to not do that for SjLj.
375 setExceptionSelectorRegister(ARM::R0);
Evan Cheng86198642009-08-07 00:34:42 +0000376 if (Subtarget->isThumb())
Owen Anderson825b72b2009-08-11 20:47:22 +0000377 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom);
Evan Cheng86198642009-08-07 00:34:42 +0000378 else
Owen Anderson825b72b2009-08-11 20:47:22 +0000379 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand);
Jim Grosbach3728e962009-12-10 00:11:09 +0000380 setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom);
Evan Chenga8e29892007-01-19 07:51:42 +0000381
Evan Chengd27c9fc2009-07-03 01:43:10 +0000382 if (!Subtarget->hasV6Ops() && !Subtarget->isThumb2()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000383 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
384 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000385 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000386 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
Evan Chenga8e29892007-01-19 07:51:42 +0000387
David Goodwinf1daf7d2009-07-08 23:10:31 +0000388 if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only())
Jim Grosbache5165492009-11-09 00:11:35 +0000389 // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR iff target supports vfp2.
Owen Anderson825b72b2009-08-11 20:47:22 +0000390 setOperationAction(ISD::BIT_CONVERT, MVT::i64, Custom);
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +0000391
392 // We want to custom lower some of our intrinsics.
Owen Anderson825b72b2009-08-11 20:47:22 +0000393 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +0000394
Owen Anderson825b72b2009-08-11 20:47:22 +0000395 setOperationAction(ISD::SETCC, MVT::i32, Expand);
396 setOperationAction(ISD::SETCC, MVT::f32, Expand);
397 setOperationAction(ISD::SETCC, MVT::f64, Expand);
398 setOperationAction(ISD::SELECT, MVT::i32, Expand);
399 setOperationAction(ISD::SELECT, MVT::f32, Expand);
400 setOperationAction(ISD::SELECT, MVT::f64, Expand);
401 setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
402 setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
403 setOperationAction(ISD::SELECT_CC, MVT::f64, Custom);
Evan Chenga8e29892007-01-19 07:51:42 +0000404
Owen Anderson825b72b2009-08-11 20:47:22 +0000405 setOperationAction(ISD::BRCOND, MVT::Other, Expand);
406 setOperationAction(ISD::BR_CC, MVT::i32, Custom);
407 setOperationAction(ISD::BR_CC, MVT::f32, Custom);
408 setOperationAction(ISD::BR_CC, MVT::f64, Custom);
409 setOperationAction(ISD::BR_JT, MVT::Other, Custom);
Evan Chenga8e29892007-01-19 07:51:42 +0000410
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000411 // We don't support sin/cos/fmod/copysign/pow
Owen Anderson825b72b2009-08-11 20:47:22 +0000412 setOperationAction(ISD::FSIN, MVT::f64, Expand);
413 setOperationAction(ISD::FSIN, MVT::f32, Expand);
414 setOperationAction(ISD::FCOS, MVT::f32, Expand);
415 setOperationAction(ISD::FCOS, MVT::f64, Expand);
416 setOperationAction(ISD::FREM, MVT::f64, Expand);
417 setOperationAction(ISD::FREM, MVT::f32, Expand);
David Goodwinf1daf7d2009-07-08 23:10:31 +0000418 if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000419 setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom);
420 setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom);
Evan Cheng110cf482008-04-01 01:50:16 +0000421 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000422 setOperationAction(ISD::FPOW, MVT::f64, Expand);
423 setOperationAction(ISD::FPOW, MVT::f32, Expand);
Bob Wilson2dc4f542009-03-20 22:42:55 +0000424
Evan Chenga8e29892007-01-19 07:51:42 +0000425 // int <-> fp are custom expanded into bit_convert + ARMISD ops.
David Goodwinf1daf7d2009-07-08 23:10:31 +0000426 if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000427 setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
428 setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom);
429 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
430 setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
Evan Cheng110cf482008-04-01 01:50:16 +0000431 }
Evan Chenga8e29892007-01-19 07:51:42 +0000432
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +0000433 // We have target-specific dag combine patterns for the following nodes:
Jim Grosbache5165492009-11-09 00:11:35 +0000434 // ARMISD::VMOVRRD - No need to call setTargetDAGCombine
Chris Lattnerd1980a52009-03-12 06:52:53 +0000435 setTargetDAGCombine(ISD::ADD);
436 setTargetDAGCombine(ISD::SUB);
Bob Wilson2dc4f542009-03-20 22:42:55 +0000437
Evan Chenga8e29892007-01-19 07:51:42 +0000438 setStackPointerRegisterToSaveRestore(ARM::SP);
Evan Chenga8e29892007-01-19 07:51:42 +0000439 setSchedulingPreference(SchedulingForRegPressure);
Dale Johannesen8dd86c12007-05-17 21:31:21 +0000440
Evan Chengbc9b7542009-08-15 07:59:10 +0000441 // FIXME: If-converter should use instruction latency to determine
442 // profitability rather than relying on fixed limits.
443 if (Subtarget->getCPUString() == "generic") {
444 // Generic (and overly aggressive) if-conversion limits.
445 setIfCvtBlockSizeLimit(10);
446 setIfCvtDupBlockSizeLimit(2);
447 } else if (Subtarget->hasV6Ops()) {
448 setIfCvtBlockSizeLimit(2);
449 setIfCvtDupBlockSizeLimit(1);
450 } else {
451 setIfCvtBlockSizeLimit(3);
452 setIfCvtDupBlockSizeLimit(2);
Evan Cheng8557c2b2009-06-19 01:51:50 +0000453 }
454
Dale Johannesen8dd86c12007-05-17 21:31:21 +0000455 maxStoresPerMemcpy = 1; //// temporary - rewrite interface to use type
Bob Wilsone6abdff2009-05-18 20:55:32 +0000456 // Do not enable CodePlacementOpt for now: it currently runs after the
457 // ARMConstantIslandPass and messes up branch relaxation and placement
458 // of constant islands.
459 // benefitFromCodePlacementOpt = true;
Evan Chenga8e29892007-01-19 07:51:42 +0000460}
461
Evan Chenga8e29892007-01-19 07:51:42 +0000462const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const {
463 switch (Opcode) {
464 default: return 0;
465 case ARMISD::Wrapper: return "ARMISD::Wrapper";
Evan Chenga8e29892007-01-19 07:51:42 +0000466 case ARMISD::WrapperJT: return "ARMISD::WrapperJT";
467 case ARMISD::CALL: return "ARMISD::CALL";
Evan Cheng277f0742007-06-19 21:05:09 +0000468 case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED";
Evan Chenga8e29892007-01-19 07:51:42 +0000469 case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK";
470 case ARMISD::tCALL: return "ARMISD::tCALL";
471 case ARMISD::BRCOND: return "ARMISD::BRCOND";
472 case ARMISD::BR_JT: return "ARMISD::BR_JT";
Evan Cheng5657c012009-07-29 02:18:14 +0000473 case ARMISD::BR2_JT: return "ARMISD::BR2_JT";
Evan Chenga8e29892007-01-19 07:51:42 +0000474 case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG";
475 case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD";
476 case ARMISD::CMP: return "ARMISD::CMP";
David Goodwinc0309b42009-06-29 15:33:01 +0000477 case ARMISD::CMPZ: return "ARMISD::CMPZ";
Evan Chenga8e29892007-01-19 07:51:42 +0000478 case ARMISD::CMPFP: return "ARMISD::CMPFP";
479 case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0";
480 case ARMISD::FMSTAT: return "ARMISD::FMSTAT";
481 case ARMISD::CMOV: return "ARMISD::CMOV";
482 case ARMISD::CNEG: return "ARMISD::CNEG";
Bob Wilson2dc4f542009-03-20 22:42:55 +0000483
Evan Chenga8e29892007-01-19 07:51:42 +0000484 case ARMISD::FTOSI: return "ARMISD::FTOSI";
485 case ARMISD::FTOUI: return "ARMISD::FTOUI";
486 case ARMISD::SITOF: return "ARMISD::SITOF";
487 case ARMISD::UITOF: return "ARMISD::UITOF";
Evan Chenga8e29892007-01-19 07:51:42 +0000488
489 case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG";
490 case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG";
491 case ARMISD::RRX: return "ARMISD::RRX";
Bob Wilson2dc4f542009-03-20 22:42:55 +0000492
Jim Grosbache5165492009-11-09 00:11:35 +0000493 case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD";
494 case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000495
Evan Chengc5942082009-10-28 06:55:03 +0000496 case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP";
497 case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP";
498
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000499 case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER";
Bob Wilson5bafff32009-06-22 23:27:02 +0000500
Evan Cheng86198642009-08-07 00:34:42 +0000501 case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC";
502
Jim Grosbach3728e962009-12-10 00:11:09 +0000503 case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER";
504 case ARMISD::SYNCBARRIER: return "ARMISD::SYNCBARRIER";
505
Bob Wilson5bafff32009-06-22 23:27:02 +0000506 case ARMISD::VCEQ: return "ARMISD::VCEQ";
507 case ARMISD::VCGE: return "ARMISD::VCGE";
508 case ARMISD::VCGEU: return "ARMISD::VCGEU";
509 case ARMISD::VCGT: return "ARMISD::VCGT";
510 case ARMISD::VCGTU: return "ARMISD::VCGTU";
511 case ARMISD::VTST: return "ARMISD::VTST";
512
513 case ARMISD::VSHL: return "ARMISD::VSHL";
514 case ARMISD::VSHRs: return "ARMISD::VSHRs";
515 case ARMISD::VSHRu: return "ARMISD::VSHRu";
516 case ARMISD::VSHLLs: return "ARMISD::VSHLLs";
517 case ARMISD::VSHLLu: return "ARMISD::VSHLLu";
518 case ARMISD::VSHLLi: return "ARMISD::VSHLLi";
519 case ARMISD::VSHRN: return "ARMISD::VSHRN";
520 case ARMISD::VRSHRs: return "ARMISD::VRSHRs";
521 case ARMISD::VRSHRu: return "ARMISD::VRSHRu";
522 case ARMISD::VRSHRN: return "ARMISD::VRSHRN";
523 case ARMISD::VQSHLs: return "ARMISD::VQSHLs";
524 case ARMISD::VQSHLu: return "ARMISD::VQSHLu";
525 case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu";
526 case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs";
527 case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu";
528 case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu";
529 case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs";
530 case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu";
531 case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu";
532 case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu";
533 case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs";
Bob Wilsonc1d287b2009-08-14 05:13:08 +0000534 case ARMISD::VDUP: return "ARMISD::VDUP";
Bob Wilson0ce37102009-08-14 05:08:32 +0000535 case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE";
Bob Wilsonde95c1b82009-08-19 17:03:43 +0000536 case ARMISD::VEXT: return "ARMISD::VEXT";
Bob Wilsond8e17572009-08-12 22:31:50 +0000537 case ARMISD::VREV64: return "ARMISD::VREV64";
538 case ARMISD::VREV32: return "ARMISD::VREV32";
539 case ARMISD::VREV16: return "ARMISD::VREV16";
Anton Korobeynikov051cfd62009-08-21 12:41:42 +0000540 case ARMISD::VZIP: return "ARMISD::VZIP";
541 case ARMISD::VUZP: return "ARMISD::VUZP";
542 case ARMISD::VTRN: return "ARMISD::VTRN";
Evan Chenga8e29892007-01-19 07:51:42 +0000543 }
544}
545
Bill Wendlingb4202b82009-07-01 18:50:55 +0000546/// getFunctionAlignment - Return the Log2 alignment of this function.
Bill Wendling20c568f2009-06-30 22:38:32 +0000547unsigned ARMTargetLowering::getFunctionAlignment(const Function *F) const {
Evan Cheng048e36f2009-10-02 06:57:25 +0000548 return getTargetMachine().getSubtarget<ARMSubtarget>().isThumb() ? 0 : 1;
Bill Wendling20c568f2009-06-30 22:38:32 +0000549}
550
Evan Chenga8e29892007-01-19 07:51:42 +0000551//===----------------------------------------------------------------------===//
552// Lowering Code
553//===----------------------------------------------------------------------===//
554
Evan Chenga8e29892007-01-19 07:51:42 +0000555/// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC
556static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) {
557 switch (CC) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000558 default: llvm_unreachable("Unknown condition code!");
Evan Chenga8e29892007-01-19 07:51:42 +0000559 case ISD::SETNE: return ARMCC::NE;
560 case ISD::SETEQ: return ARMCC::EQ;
561 case ISD::SETGT: return ARMCC::GT;
562 case ISD::SETGE: return ARMCC::GE;
563 case ISD::SETLT: return ARMCC::LT;
564 case ISD::SETLE: return ARMCC::LE;
565 case ISD::SETUGT: return ARMCC::HI;
566 case ISD::SETUGE: return ARMCC::HS;
567 case ISD::SETULT: return ARMCC::LO;
568 case ISD::SETULE: return ARMCC::LS;
569 }
570}
571
Bob Wilsoncd3b9a42009-09-09 23:14:54 +0000572/// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC.
573static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode,
Evan Chenga8e29892007-01-19 07:51:42 +0000574 ARMCC::CondCodes &CondCode2) {
Evan Chenga8e29892007-01-19 07:51:42 +0000575 CondCode2 = ARMCC::AL;
576 switch (CC) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000577 default: llvm_unreachable("Unknown FP condition!");
Evan Chenga8e29892007-01-19 07:51:42 +0000578 case ISD::SETEQ:
579 case ISD::SETOEQ: CondCode = ARMCC::EQ; break;
580 case ISD::SETGT:
581 case ISD::SETOGT: CondCode = ARMCC::GT; break;
582 case ISD::SETGE:
583 case ISD::SETOGE: CondCode = ARMCC::GE; break;
584 case ISD::SETOLT: CondCode = ARMCC::MI; break;
Bob Wilsoncd3b9a42009-09-09 23:14:54 +0000585 case ISD::SETOLE: CondCode = ARMCC::LS; break;
Evan Chenga8e29892007-01-19 07:51:42 +0000586 case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break;
587 case ISD::SETO: CondCode = ARMCC::VC; break;
588 case ISD::SETUO: CondCode = ARMCC::VS; break;
589 case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break;
590 case ISD::SETUGT: CondCode = ARMCC::HI; break;
591 case ISD::SETUGE: CondCode = ARMCC::PL; break;
592 case ISD::SETLT:
593 case ISD::SETULT: CondCode = ARMCC::LT; break;
594 case ISD::SETLE:
595 case ISD::SETULE: CondCode = ARMCC::LE; break;
596 case ISD::SETNE:
597 case ISD::SETUNE: CondCode = ARMCC::NE; break;
598 }
Evan Chenga8e29892007-01-19 07:51:42 +0000599}
600
Bob Wilson1f595bb2009-04-17 19:07:39 +0000601//===----------------------------------------------------------------------===//
602// Calling Convention Implementation
Bob Wilson1f595bb2009-04-17 19:07:39 +0000603//===----------------------------------------------------------------------===//
604
605#include "ARMGenCallingConv.inc"
606
607// APCS f64 is in register pairs, possibly split to stack
Owen Andersone50ed302009-08-10 22:56:29 +0000608static bool f64AssignAPCS(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson5bafff32009-06-22 23:27:02 +0000609 CCValAssign::LocInfo &LocInfo,
610 CCState &State, bool CanFail) {
611 static const unsigned RegList[] = { ARM::R0, ARM::R1, ARM::R2, ARM::R3 };
612
613 // Try to get the first register.
614 if (unsigned Reg = State.AllocateReg(RegList, 4))
615 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
616 else {
617 // For the 2nd half of a v2f64, do not fail.
618 if (CanFail)
619 return false;
620
621 // Put the whole thing on the stack.
622 State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
623 State.AllocateStack(8, 4),
624 LocVT, LocInfo));
625 return true;
626 }
627
628 // Try to get the second register.
629 if (unsigned Reg = State.AllocateReg(RegList, 4))
630 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
631 else
632 State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
633 State.AllocateStack(4, 4),
634 LocVT, LocInfo));
635 return true;
636}
637
Owen Andersone50ed302009-08-10 22:56:29 +0000638static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000639 CCValAssign::LocInfo &LocInfo,
640 ISD::ArgFlagsTy &ArgFlags,
641 CCState &State) {
Bob Wilson5bafff32009-06-22 23:27:02 +0000642 if (!f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, true))
643 return false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000644 if (LocVT == MVT::v2f64 &&
Bob Wilson5bafff32009-06-22 23:27:02 +0000645 !f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, false))
646 return false;
Bob Wilsone65586b2009-04-17 20:40:45 +0000647 return true; // we handled it
Bob Wilson1f595bb2009-04-17 19:07:39 +0000648}
649
650// AAPCS f64 is in aligned register pairs
Owen Andersone50ed302009-08-10 22:56:29 +0000651static bool f64AssignAAPCS(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson5bafff32009-06-22 23:27:02 +0000652 CCValAssign::LocInfo &LocInfo,
653 CCState &State, bool CanFail) {
654 static const unsigned HiRegList[] = { ARM::R0, ARM::R2 };
655 static const unsigned LoRegList[] = { ARM::R1, ARM::R3 };
656
657 unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2);
658 if (Reg == 0) {
659 // For the 2nd half of a v2f64, do not just fail.
660 if (CanFail)
661 return false;
662
663 // Put the whole thing on the stack.
664 State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
665 State.AllocateStack(8, 8),
666 LocVT, LocInfo));
667 return true;
668 }
669
670 unsigned i;
671 for (i = 0; i < 2; ++i)
672 if (HiRegList[i] == Reg)
673 break;
674
675 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
676 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i],
677 LocVT, LocInfo));
678 return true;
679}
680
Owen Andersone50ed302009-08-10 22:56:29 +0000681static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000682 CCValAssign::LocInfo &LocInfo,
683 ISD::ArgFlagsTy &ArgFlags,
684 CCState &State) {
Bob Wilson5bafff32009-06-22 23:27:02 +0000685 if (!f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, true))
686 return false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000687 if (LocVT == MVT::v2f64 &&
Bob Wilson5bafff32009-06-22 23:27:02 +0000688 !f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, false))
689 return false;
690 return true; // we handled it
691}
692
Owen Andersone50ed302009-08-10 22:56:29 +0000693static bool f64RetAssign(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson5bafff32009-06-22 23:27:02 +0000694 CCValAssign::LocInfo &LocInfo, CCState &State) {
Bob Wilson1f595bb2009-04-17 19:07:39 +0000695 static const unsigned HiRegList[] = { ARM::R0, ARM::R2 };
696 static const unsigned LoRegList[] = { ARM::R1, ARM::R3 };
697
Bob Wilsone65586b2009-04-17 20:40:45 +0000698 unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2);
699 if (Reg == 0)
700 return false; // we didn't handle it
Bob Wilson1f595bb2009-04-17 19:07:39 +0000701
Bob Wilsone65586b2009-04-17 20:40:45 +0000702 unsigned i;
703 for (i = 0; i < 2; ++i)
704 if (HiRegList[i] == Reg)
705 break;
Bob Wilson1f595bb2009-04-17 19:07:39 +0000706
Bob Wilson5bafff32009-06-22 23:27:02 +0000707 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
Bob Wilsone65586b2009-04-17 20:40:45 +0000708 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i],
Bob Wilson5bafff32009-06-22 23:27:02 +0000709 LocVT, LocInfo));
710 return true;
Bob Wilson1f595bb2009-04-17 19:07:39 +0000711}
712
Owen Andersone50ed302009-08-10 22:56:29 +0000713static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000714 CCValAssign::LocInfo &LocInfo,
715 ISD::ArgFlagsTy &ArgFlags,
716 CCState &State) {
Bob Wilson5bafff32009-06-22 23:27:02 +0000717 if (!f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State))
718 return false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000719 if (LocVT == MVT::v2f64 && !f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State))
Bob Wilson5bafff32009-06-22 23:27:02 +0000720 return false;
Bob Wilsone65586b2009-04-17 20:40:45 +0000721 return true; // we handled it
Bob Wilson1f595bb2009-04-17 19:07:39 +0000722}
723
Owen Andersone50ed302009-08-10 22:56:29 +0000724static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, EVT &ValVT, EVT &LocVT,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000725 CCValAssign::LocInfo &LocInfo,
726 ISD::ArgFlagsTy &ArgFlags,
727 CCState &State) {
728 return RetCC_ARM_APCS_Custom_f64(ValNo, ValVT, LocVT, LocInfo, ArgFlags,
729 State);
730}
731
Anton Korobeynikov385f5a92009-06-16 18:50:49 +0000732/// CCAssignFnForNode - Selects the correct CCAssignFn for a the
733/// given CallingConvention value.
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000734CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC,
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000735 bool Return,
736 bool isVarArg) const {
Anton Korobeynikov385f5a92009-06-16 18:50:49 +0000737 switch (CC) {
738 default:
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000739 llvm_unreachable("Unsupported calling convention");
Anton Korobeynikov385f5a92009-06-16 18:50:49 +0000740 case CallingConv::C:
741 case CallingConv::Fast:
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000742 // Use target triple & subtarget features to do actual dispatch.
743 if (Subtarget->isAAPCS_ABI()) {
744 if (Subtarget->hasVFP2() &&
745 FloatABIType == FloatABI::Hard && !isVarArg)
746 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
747 else
748 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
749 } else
750 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
Anton Korobeynikov385f5a92009-06-16 18:50:49 +0000751 case CallingConv::ARM_AAPCS_VFP:
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000752 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
Anton Korobeynikov385f5a92009-06-16 18:50:49 +0000753 case CallingConv::ARM_AAPCS:
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000754 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
Anton Korobeynikov385f5a92009-06-16 18:50:49 +0000755 case CallingConv::ARM_APCS:
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000756 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
Anton Korobeynikov385f5a92009-06-16 18:50:49 +0000757 }
758}
759
Dan Gohman98ca4f22009-08-05 01:29:28 +0000760/// LowerCallResult - Lower the result values of a call into the
761/// appropriate copies out of appropriate physical registers.
762SDValue
763ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000764 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000765 const SmallVectorImpl<ISD::InputArg> &Ins,
766 DebugLoc dl, SelectionDAG &DAG,
767 SmallVectorImpl<SDValue> &InVals) {
Bob Wilson1f595bb2009-04-17 19:07:39 +0000768
Bob Wilson1f595bb2009-04-17 19:07:39 +0000769 // Assign locations to each value returned by this call.
770 SmallVector<CCValAssign, 16> RVLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000771 CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
Owen Andersone922c022009-07-22 00:24:57 +0000772 RVLocs, *DAG.getContext());
Dan Gohman98ca4f22009-08-05 01:29:28 +0000773 CCInfo.AnalyzeCallResult(Ins,
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000774 CCAssignFnForNode(CallConv, /* Return*/ true,
775 isVarArg));
Bob Wilson1f595bb2009-04-17 19:07:39 +0000776
777 // Copy all of the result registers out of their specified physreg.
778 for (unsigned i = 0; i != RVLocs.size(); ++i) {
779 CCValAssign VA = RVLocs[i];
780
Bob Wilson80915242009-04-25 00:33:20 +0000781 SDValue Val;
Bob Wilson1f595bb2009-04-17 19:07:39 +0000782 if (VA.needsCustom()) {
Bob Wilson5bafff32009-06-22 23:27:02 +0000783 // Handle f64 or half of a v2f64.
Owen Anderson825b72b2009-08-11 20:47:22 +0000784 SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000785 InFlag);
Bob Wilson4d59e1d2009-04-24 17:00:36 +0000786 Chain = Lo.getValue(1);
787 InFlag = Lo.getValue(2);
Bob Wilson1f595bb2009-04-17 19:07:39 +0000788 VA = RVLocs[++i]; // skip ahead to next loc
Owen Anderson825b72b2009-08-11 20:47:22 +0000789 SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32,
Bob Wilson4d59e1d2009-04-24 17:00:36 +0000790 InFlag);
791 Chain = Hi.getValue(1);
792 InFlag = Hi.getValue(2);
Jim Grosbache5165492009-11-09 00:11:35 +0000793 Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi);
Bob Wilson5bafff32009-06-22 23:27:02 +0000794
Owen Anderson825b72b2009-08-11 20:47:22 +0000795 if (VA.getLocVT() == MVT::v2f64) {
796 SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64);
797 Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val,
798 DAG.getConstant(0, MVT::i32));
Bob Wilson5bafff32009-06-22 23:27:02 +0000799
800 VA = RVLocs[++i]; // skip ahead to next loc
Owen Anderson825b72b2009-08-11 20:47:22 +0000801 Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag);
Bob Wilson5bafff32009-06-22 23:27:02 +0000802 Chain = Lo.getValue(1);
803 InFlag = Lo.getValue(2);
804 VA = RVLocs[++i]; // skip ahead to next loc
Owen Anderson825b72b2009-08-11 20:47:22 +0000805 Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag);
Bob Wilson5bafff32009-06-22 23:27:02 +0000806 Chain = Hi.getValue(1);
807 InFlag = Hi.getValue(2);
Jim Grosbache5165492009-11-09 00:11:35 +0000808 Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi);
Owen Anderson825b72b2009-08-11 20:47:22 +0000809 Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val,
810 DAG.getConstant(1, MVT::i32));
Bob Wilson5bafff32009-06-22 23:27:02 +0000811 }
Bob Wilson1f595bb2009-04-17 19:07:39 +0000812 } else {
Bob Wilson80915242009-04-25 00:33:20 +0000813 Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(),
814 InFlag);
Bob Wilson4d59e1d2009-04-24 17:00:36 +0000815 Chain = Val.getValue(1);
816 InFlag = Val.getValue(2);
Bob Wilson1f595bb2009-04-17 19:07:39 +0000817 }
Bob Wilson80915242009-04-25 00:33:20 +0000818
819 switch (VA.getLocInfo()) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000820 default: llvm_unreachable("Unknown loc info!");
Bob Wilson80915242009-04-25 00:33:20 +0000821 case CCValAssign::Full: break;
822 case CCValAssign::BCvt:
823 Val = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getValVT(), Val);
824 break;
825 }
826
Dan Gohman98ca4f22009-08-05 01:29:28 +0000827 InVals.push_back(Val);
Bob Wilson1f595bb2009-04-17 19:07:39 +0000828 }
829
Dan Gohman98ca4f22009-08-05 01:29:28 +0000830 return Chain;
Bob Wilson1f595bb2009-04-17 19:07:39 +0000831}
832
833/// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified
834/// by "Src" to address "Dst" of size "Size". Alignment information is
Bob Wilsondee46d72009-04-17 20:35:10 +0000835/// specified by the specific parameter attribute. The copy will be passed as
Bob Wilson1f595bb2009-04-17 19:07:39 +0000836/// a byval function parameter.
837/// Sometimes what we are copying is the end of a larger object, the part that
838/// does not fit in registers.
839static SDValue
840CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain,
841 ISD::ArgFlagsTy Flags, SelectionDAG &DAG,
842 DebugLoc dl) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000843 SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32);
Bob Wilson1f595bb2009-04-17 19:07:39 +0000844 return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(),
845 /*AlwaysInline=*/false, NULL, 0, NULL, 0);
846}
847
Bob Wilsondee46d72009-04-17 20:35:10 +0000848/// LowerMemOpCallTo - Store the argument to the stack.
Bob Wilson1f595bb2009-04-17 19:07:39 +0000849SDValue
Dan Gohman98ca4f22009-08-05 01:29:28 +0000850ARMTargetLowering::LowerMemOpCallTo(SDValue Chain,
851 SDValue StackPtr, SDValue Arg,
852 DebugLoc dl, SelectionDAG &DAG,
853 const CCValAssign &VA,
854 ISD::ArgFlagsTy Flags) {
Bob Wilson1f595bb2009-04-17 19:07:39 +0000855 unsigned LocMemOffset = VA.getLocMemOffset();
856 SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset);
857 PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff);
858 if (Flags.isByVal()) {
859 return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG, dl);
860 }
861 return DAG.getStore(Chain, dl, Arg, PtrOff,
862 PseudoSourceValue::getStack(), LocMemOffset);
Evan Chenga8e29892007-01-19 07:51:42 +0000863}
864
Dan Gohman98ca4f22009-08-05 01:29:28 +0000865void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG,
Bob Wilson5bafff32009-06-22 23:27:02 +0000866 SDValue Chain, SDValue &Arg,
867 RegsToPassVector &RegsToPass,
868 CCValAssign &VA, CCValAssign &NextVA,
869 SDValue &StackPtr,
870 SmallVector<SDValue, 8> &MemOpChains,
871 ISD::ArgFlagsTy Flags) {
Bob Wilson5bafff32009-06-22 23:27:02 +0000872
Jim Grosbache5165492009-11-09 00:11:35 +0000873 SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000874 DAG.getVTList(MVT::i32, MVT::i32), Arg);
Bob Wilson5bafff32009-06-22 23:27:02 +0000875 RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd));
876
877 if (NextVA.isRegLoc())
878 RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1)));
879 else {
880 assert(NextVA.isMemLoc());
881 if (StackPtr.getNode() == 0)
882 StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy());
883
Dan Gohman98ca4f22009-08-05 01:29:28 +0000884 MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1),
885 dl, DAG, NextVA,
886 Flags));
Bob Wilson5bafff32009-06-22 23:27:02 +0000887 }
888}
889
Dan Gohman98ca4f22009-08-05 01:29:28 +0000890/// LowerCall - Lowering a call into a callseq_start <-
Evan Chengfc403422007-02-03 08:53:01 +0000891/// ARMISD:CALL <- callseq_end chain. Also add input and output parameter
892/// nodes.
Dan Gohman98ca4f22009-08-05 01:29:28 +0000893SDValue
894ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000895 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000896 bool isTailCall,
897 const SmallVectorImpl<ISD::OutputArg> &Outs,
898 const SmallVectorImpl<ISD::InputArg> &Ins,
899 DebugLoc dl, SelectionDAG &DAG,
900 SmallVectorImpl<SDValue> &InVals) {
Evan Chenga8e29892007-01-19 07:51:42 +0000901
Bob Wilson1f595bb2009-04-17 19:07:39 +0000902 // Analyze operands of the call, assigning locations to each operand.
903 SmallVector<CCValAssign, 16> ArgLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000904 CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs,
905 *DAG.getContext());
906 CCInfo.AnalyzeCallOperands(Outs,
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000907 CCAssignFnForNode(CallConv, /* Return*/ false,
908 isVarArg));
Evan Chenga8e29892007-01-19 07:51:42 +0000909
Bob Wilson1f595bb2009-04-17 19:07:39 +0000910 // Get a count of how many bytes are to be pushed on the stack.
911 unsigned NumBytes = CCInfo.getNextStackOffset();
Evan Chenga8e29892007-01-19 07:51:42 +0000912
913 // Adjust the stack pointer for the new arguments...
914 // These operations are automatically eliminated by the prolog/epilog pass
Chris Lattnere563bbc2008-10-11 22:08:30 +0000915 Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true));
Evan Chenga8e29892007-01-19 07:51:42 +0000916
Owen Anderson825b72b2009-08-11 20:47:22 +0000917 SDValue StackPtr = DAG.getRegister(ARM::SP, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000918
Bob Wilson5bafff32009-06-22 23:27:02 +0000919 RegsToPassVector RegsToPass;
Bob Wilson1f595bb2009-04-17 19:07:39 +0000920 SmallVector<SDValue, 8> MemOpChains;
Evan Chenga8e29892007-01-19 07:51:42 +0000921
Bob Wilson1f595bb2009-04-17 19:07:39 +0000922 // Walk the register/memloc assignments, inserting copies/loads. In the case
Bob Wilsondee46d72009-04-17 20:35:10 +0000923 // of tail call optimization, arguments are handled later.
Bob Wilson1f595bb2009-04-17 19:07:39 +0000924 for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size();
925 i != e;
926 ++i, ++realArgIdx) {
927 CCValAssign &VA = ArgLocs[i];
Dan Gohman98ca4f22009-08-05 01:29:28 +0000928 SDValue Arg = Outs[realArgIdx].Val;
929 ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags;
Evan Chenga8e29892007-01-19 07:51:42 +0000930
Bob Wilson1f595bb2009-04-17 19:07:39 +0000931 // Promote the value if needed.
932 switch (VA.getLocInfo()) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000933 default: llvm_unreachable("Unknown loc info!");
Bob Wilson1f595bb2009-04-17 19:07:39 +0000934 case CCValAssign::Full: break;
935 case CCValAssign::SExt:
936 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
937 break;
938 case CCValAssign::ZExt:
939 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
940 break;
941 case CCValAssign::AExt:
942 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
943 break;
944 case CCValAssign::BCvt:
945 Arg = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), Arg);
946 break;
Evan Chenga8e29892007-01-19 07:51:42 +0000947 }
948
Anton Korobeynikov567d14f2009-08-05 19:04:42 +0000949 // f64 and v2f64 might be passed in i32 pairs and must be split into pieces
Bob Wilson1f595bb2009-04-17 19:07:39 +0000950 if (VA.needsCustom()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000951 if (VA.getLocVT() == MVT::v2f64) {
952 SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg,
953 DAG.getConstant(0, MVT::i32));
954 SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg,
955 DAG.getConstant(1, MVT::i32));
Bob Wilson1f595bb2009-04-17 19:07:39 +0000956
Dan Gohman98ca4f22009-08-05 01:29:28 +0000957 PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass,
Bob Wilson5bafff32009-06-22 23:27:02 +0000958 VA, ArgLocs[++i], StackPtr, MemOpChains, Flags);
959
960 VA = ArgLocs[++i]; // skip ahead to next loc
961 if (VA.isRegLoc()) {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000962 PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass,
Bob Wilson5bafff32009-06-22 23:27:02 +0000963 VA, ArgLocs[++i], StackPtr, MemOpChains, Flags);
964 } else {
965 assert(VA.isMemLoc());
966 if (StackPtr.getNode() == 0)
967 StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy());
968
Dan Gohman98ca4f22009-08-05 01:29:28 +0000969 MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1,
970 dl, DAG, VA, Flags));
Bob Wilson5bafff32009-06-22 23:27:02 +0000971 }
972 } else {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000973 PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i],
Bob Wilson5bafff32009-06-22 23:27:02 +0000974 StackPtr, MemOpChains, Flags);
Bob Wilson1f595bb2009-04-17 19:07:39 +0000975 }
976 } else if (VA.isRegLoc()) {
977 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
978 } else {
979 assert(VA.isMemLoc());
980 if (StackPtr.getNode() == 0)
981 StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy());
982
Dan Gohman98ca4f22009-08-05 01:29:28 +0000983 MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg,
984 dl, DAG, VA, Flags));
Bob Wilson1f595bb2009-04-17 19:07:39 +0000985 }
Evan Chenga8e29892007-01-19 07:51:42 +0000986 }
987
988 if (!MemOpChains.empty())
Owen Anderson825b72b2009-08-11 20:47:22 +0000989 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
Evan Chenga8e29892007-01-19 07:51:42 +0000990 &MemOpChains[0], MemOpChains.size());
991
992 // Build a sequence of copy-to-reg nodes chained together with token chain
993 // and flag operands which copy the outgoing args into the appropriate regs.
Dan Gohman475871a2008-07-27 21:46:04 +0000994 SDValue InFlag;
Evan Chenga8e29892007-01-19 07:51:42 +0000995 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
Bob Wilson2dc4f542009-03-20 22:42:55 +0000996 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
Dale Johannesen33c960f2009-02-04 20:06:27 +0000997 RegsToPass[i].second, InFlag);
Evan Chenga8e29892007-01-19 07:51:42 +0000998 InFlag = Chain.getValue(1);
999 }
1000
Bill Wendling056292f2008-09-16 21:48:12 +00001001 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
1002 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
1003 // node so that legalize doesn't hack it.
Evan Chenga8e29892007-01-19 07:51:42 +00001004 bool isDirect = false;
1005 bool isARMFunc = false;
Evan Cheng277f0742007-06-19 21:05:09 +00001006 bool isLocalARMFunc = false;
Evan Chenge7e0d622009-11-06 22:24:13 +00001007 MachineFunction &MF = DAG.getMachineFunction();
1008 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
Evan Chenga8e29892007-01-19 07:51:42 +00001009 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
1010 GlobalValue *GV = G->getGlobal();
Evan Chenga8e29892007-01-19 07:51:42 +00001011 isDirect = true;
Chris Lattner4fb63d02009-07-15 04:12:33 +00001012 bool isExt = GV->isDeclaration() || GV->isWeakForLinker();
Evan Cheng970a4192007-01-19 19:28:01 +00001013 bool isStub = (isExt && Subtarget->isTargetDarwin()) &&
Evan Chenga8e29892007-01-19 07:51:42 +00001014 getTargetMachine().getRelocationModel() != Reloc::Static;
1015 isARMFunc = !Subtarget->isThumb() || isStub;
Evan Cheng277f0742007-06-19 21:05:09 +00001016 // ARM call to a local ARM function is predicable.
1017 isLocalARMFunc = !Subtarget->isThumb() && !isExt;
Evan Chengc60e76d2007-01-30 20:37:08 +00001018 // tBX takes a register source operand.
David Goodwinf1daf7d2009-07-08 23:10:31 +00001019 if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) {
Evan Chenge7e0d622009-11-06 22:24:13 +00001020 unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId();
Evan Chenge4e4ed32009-08-28 23:18:09 +00001021 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +00001022 ARMPCLabelIndex,
1023 ARMCP::CPValue, 4);
Evan Cheng1606e8e2009-03-13 07:51:59 +00001024 SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4);
Owen Anderson825b72b2009-08-11 20:47:22 +00001025 CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
Bob Wilson2dc4f542009-03-20 22:42:55 +00001026 Callee = DAG.getLoad(getPointerTy(), dl,
Evan Cheng9eda6892009-10-31 03:39:36 +00001027 DAG.getEntryNode(), CPAddr,
1028 PseudoSourceValue::getConstantPool(), 0);
Evan Chenge7e0d622009-11-06 22:24:13 +00001029 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
Bob Wilson2dc4f542009-03-20 22:42:55 +00001030 Callee = DAG.getNode(ARMISD::PIC_ADD, dl,
Dale Johannesen33c960f2009-02-04 20:06:27 +00001031 getPointerTy(), Callee, PICLabel);
Evan Chengc60e76d2007-01-30 20:37:08 +00001032 } else
1033 Callee = DAG.getTargetGlobalAddress(GV, getPointerTy());
Bill Wendling056292f2008-09-16 21:48:12 +00001034 } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
Evan Chenga8e29892007-01-19 07:51:42 +00001035 isDirect = true;
Evan Cheng970a4192007-01-19 19:28:01 +00001036 bool isStub = Subtarget->isTargetDarwin() &&
Evan Chenga8e29892007-01-19 07:51:42 +00001037 getTargetMachine().getRelocationModel() != Reloc::Static;
1038 isARMFunc = !Subtarget->isThumb() || isStub;
Evan Chengc60e76d2007-01-30 20:37:08 +00001039 // tBX takes a register source operand.
1040 const char *Sym = S->getSymbol();
David Goodwinf1daf7d2009-07-08 23:10:31 +00001041 if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) {
Evan Chenge7e0d622009-11-06 22:24:13 +00001042 unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId();
Owen Anderson1d0be152009-08-13 21:58:54 +00001043 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(),
Evan Chenge4e4ed32009-08-28 23:18:09 +00001044 Sym, ARMPCLabelIndex, 4);
Evan Cheng1606e8e2009-03-13 07:51:59 +00001045 SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4);
Owen Anderson825b72b2009-08-11 20:47:22 +00001046 CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001047 Callee = DAG.getLoad(getPointerTy(), dl,
Evan Cheng9eda6892009-10-31 03:39:36 +00001048 DAG.getEntryNode(), CPAddr,
1049 PseudoSourceValue::getConstantPool(), 0);
Evan Chenge7e0d622009-11-06 22:24:13 +00001050 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
Bob Wilson2dc4f542009-03-20 22:42:55 +00001051 Callee = DAG.getNode(ARMISD::PIC_ADD, dl,
Dale Johannesen33c960f2009-02-04 20:06:27 +00001052 getPointerTy(), Callee, PICLabel);
Evan Chengc60e76d2007-01-30 20:37:08 +00001053 } else
Bill Wendling056292f2008-09-16 21:48:12 +00001054 Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +00001055 }
1056
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +00001057 // FIXME: handle tail calls differently.
1058 unsigned CallOpc;
Evan Chengb6207242009-08-01 00:16:10 +00001059 if (Subtarget->isThumb()) {
1060 if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps())
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +00001061 CallOpc = ARMISD::CALL_NOLINK;
1062 else
1063 CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL;
1064 } else {
1065 CallOpc = (isDirect || Subtarget->hasV5TOps())
Evan Cheng277f0742007-06-19 21:05:09 +00001066 ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL)
1067 : ARMISD::CALL_NOLINK;
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +00001068 }
David Goodwinf1daf7d2009-07-08 23:10:31 +00001069 if (CallOpc == ARMISD::CALL_NOLINK && !Subtarget->isThumb1Only()) {
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +00001070 // implicit def LR - LR mustn't be allocated as GRP:$dst of CALL_NOLINK
Owen Anderson825b72b2009-08-11 20:47:22 +00001071 Chain = DAG.getCopyToReg(Chain, dl, ARM::LR, DAG.getUNDEF(MVT::i32),InFlag);
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +00001072 InFlag = Chain.getValue(1);
1073 }
1074
Dan Gohman475871a2008-07-27 21:46:04 +00001075 std::vector<SDValue> Ops;
Evan Chenga8e29892007-01-19 07:51:42 +00001076 Ops.push_back(Chain);
1077 Ops.push_back(Callee);
1078
1079 // Add argument registers to the end of the list so that they are known live
1080 // into the call.
1081 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
1082 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
1083 RegsToPass[i].second.getValueType()));
1084
Gabor Greifba36cb52008-08-28 21:40:38 +00001085 if (InFlag.getNode())
Evan Chenga8e29892007-01-19 07:51:42 +00001086 Ops.push_back(InFlag);
Duncan Sands4bdcb612008-07-02 17:40:58 +00001087 // Returns a chain and a flag for retval copy to use.
Owen Anderson825b72b2009-08-11 20:47:22 +00001088 Chain = DAG.getNode(CallOpc, dl, DAG.getVTList(MVT::Other, MVT::Flag),
Duncan Sands4bdcb612008-07-02 17:40:58 +00001089 &Ops[0], Ops.size());
Evan Chenga8e29892007-01-19 07:51:42 +00001090 InFlag = Chain.getValue(1);
1091
Chris Lattnere563bbc2008-10-11 22:08:30 +00001092 Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true),
1093 DAG.getIntPtrConstant(0, true), InFlag);
Dan Gohman98ca4f22009-08-05 01:29:28 +00001094 if (!Ins.empty())
Evan Chenga8e29892007-01-19 07:51:42 +00001095 InFlag = Chain.getValue(1);
1096
Bob Wilson1f595bb2009-04-17 19:07:39 +00001097 // Handle result values, copying them out of physregs into vregs that we
1098 // return.
Dan Gohman98ca4f22009-08-05 01:29:28 +00001099 return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins,
1100 dl, DAG, InVals);
Evan Chenga8e29892007-01-19 07:51:42 +00001101}
1102
Dan Gohman98ca4f22009-08-05 01:29:28 +00001103SDValue
1104ARMTargetLowering::LowerReturn(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +00001105 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +00001106 const SmallVectorImpl<ISD::OutputArg> &Outs,
1107 DebugLoc dl, SelectionDAG &DAG) {
Bob Wilson2dc4f542009-03-20 22:42:55 +00001108
Bob Wilsondee46d72009-04-17 20:35:10 +00001109 // CCValAssign - represent the assignment of the return value to a location.
Bob Wilson1f595bb2009-04-17 19:07:39 +00001110 SmallVector<CCValAssign, 16> RVLocs;
Bob Wilson1f595bb2009-04-17 19:07:39 +00001111
Bob Wilsondee46d72009-04-17 20:35:10 +00001112 // CCState - Info about the registers and stack slots.
Dan Gohman98ca4f22009-08-05 01:29:28 +00001113 CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs,
1114 *DAG.getContext());
Bob Wilson1f595bb2009-04-17 19:07:39 +00001115
Dan Gohman98ca4f22009-08-05 01:29:28 +00001116 // Analyze outgoing return values.
Anton Korobeynikov567d14f2009-08-05 19:04:42 +00001117 CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true,
1118 isVarArg));
Bob Wilson1f595bb2009-04-17 19:07:39 +00001119
1120 // If this is the first return lowered for this function, add
1121 // the regs to the liveout set for the function.
1122 if (DAG.getMachineFunction().getRegInfo().liveout_empty()) {
1123 for (unsigned i = 0; i != RVLocs.size(); ++i)
1124 if (RVLocs[i].isRegLoc())
1125 DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg());
Evan Chenga8e29892007-01-19 07:51:42 +00001126 }
1127
Bob Wilson1f595bb2009-04-17 19:07:39 +00001128 SDValue Flag;
1129
1130 // Copy the result values into the output registers.
1131 for (unsigned i = 0, realRVLocIdx = 0;
1132 i != RVLocs.size();
1133 ++i, ++realRVLocIdx) {
1134 CCValAssign &VA = RVLocs[i];
1135 assert(VA.isRegLoc() && "Can only return in registers!");
1136
Dan Gohman98ca4f22009-08-05 01:29:28 +00001137 SDValue Arg = Outs[realRVLocIdx].Val;
Bob Wilson1f595bb2009-04-17 19:07:39 +00001138
1139 switch (VA.getLocInfo()) {
Torok Edwinc23197a2009-07-14 16:55:14 +00001140 default: llvm_unreachable("Unknown loc info!");
Bob Wilson1f595bb2009-04-17 19:07:39 +00001141 case CCValAssign::Full: break;
1142 case CCValAssign::BCvt:
1143 Arg = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), Arg);
1144 break;
1145 }
1146
Bob Wilson1f595bb2009-04-17 19:07:39 +00001147 if (VA.needsCustom()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001148 if (VA.getLocVT() == MVT::v2f64) {
Bob Wilson5bafff32009-06-22 23:27:02 +00001149 // Extract the first half and return it in two registers.
Owen Anderson825b72b2009-08-11 20:47:22 +00001150 SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg,
1151 DAG.getConstant(0, MVT::i32));
Jim Grosbache5165492009-11-09 00:11:35 +00001152 SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +00001153 DAG.getVTList(MVT::i32, MVT::i32), Half);
Bob Wilson5bafff32009-06-22 23:27:02 +00001154
1155 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag);
1156 Flag = Chain.getValue(1);
1157 VA = RVLocs[++i]; // skip ahead to next loc
1158 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(),
1159 HalfGPRs.getValue(1), Flag);
1160 Flag = Chain.getValue(1);
1161 VA = RVLocs[++i]; // skip ahead to next loc
1162
1163 // Extract the 2nd half and fall through to handle it as an f64 value.
Owen Anderson825b72b2009-08-11 20:47:22 +00001164 Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg,
1165 DAG.getConstant(1, MVT::i32));
Bob Wilson5bafff32009-06-22 23:27:02 +00001166 }
1167 // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is
1168 // available.
Jim Grosbache5165492009-11-09 00:11:35 +00001169 SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +00001170 DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1);
Bob Wilson1f595bb2009-04-17 19:07:39 +00001171 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag);
Bob Wilson4d59e1d2009-04-24 17:00:36 +00001172 Flag = Chain.getValue(1);
Bob Wilson1f595bb2009-04-17 19:07:39 +00001173 VA = RVLocs[++i]; // skip ahead to next loc
1174 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1),
1175 Flag);
1176 } else
1177 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag);
1178
Bob Wilsondee46d72009-04-17 20:35:10 +00001179 // Guarantee that all emitted copies are
1180 // stuck together, avoiding something bad.
Bob Wilson1f595bb2009-04-17 19:07:39 +00001181 Flag = Chain.getValue(1);
1182 }
1183
1184 SDValue result;
1185 if (Flag.getNode())
Owen Anderson825b72b2009-08-11 20:47:22 +00001186 result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag);
Bob Wilson1f595bb2009-04-17 19:07:39 +00001187 else // Return Void
Owen Anderson825b72b2009-08-11 20:47:22 +00001188 result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain);
Bob Wilson1f595bb2009-04-17 19:07:39 +00001189
1190 return result;
Evan Chenga8e29892007-01-19 07:51:42 +00001191}
1192
Bob Wilsonb62d2572009-11-03 00:02:05 +00001193// ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as
1194// their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is
1195// one of the above mentioned nodes. It has to be wrapped because otherwise
1196// Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only
1197// be used to form addressing mode. These wrapped nodes will be selected
1198// into MOVi.
Dan Gohman475871a2008-07-27 21:46:04 +00001199static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +00001200 EVT PtrVT = Op.getValueType();
Dale Johannesenb300d2a2009-02-07 00:55:49 +00001201 // FIXME there is no actual debug info here
1202 DebugLoc dl = Op.getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001203 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
Dan Gohman475871a2008-07-27 21:46:04 +00001204 SDValue Res;
Evan Chenga8e29892007-01-19 07:51:42 +00001205 if (CP->isMachineConstantPoolEntry())
1206 Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT,
1207 CP->getAlignment());
1208 else
1209 Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT,
1210 CP->getAlignment());
Owen Anderson825b72b2009-08-11 20:47:22 +00001211 return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res);
Evan Chenga8e29892007-01-19 07:51:42 +00001212}
1213
Bob Wilsonddb16df2009-10-30 05:45:42 +00001214SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) {
Evan Chenge7e0d622009-11-06 22:24:13 +00001215 MachineFunction &MF = DAG.getMachineFunction();
1216 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1217 unsigned ARMPCLabelIndex = 0;
Bob Wilsonddb16df2009-10-30 05:45:42 +00001218 DebugLoc DL = Op.getDebugLoc();
Bob Wilson907eebd2009-11-02 20:59:23 +00001219 EVT PtrVT = getPointerTy();
Bob Wilsonddb16df2009-10-30 05:45:42 +00001220 BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
Bob Wilson907eebd2009-11-02 20:59:23 +00001221 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
1222 SDValue CPAddr;
1223 if (RelocM == Reloc::Static) {
1224 CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4);
1225 } else {
1226 unsigned PCAdj = Subtarget->isThumb() ? 4 : 8;
Evan Chenge7e0d622009-11-06 22:24:13 +00001227 ARMPCLabelIndex = AFI->createConstPoolEntryUId();
Bob Wilson907eebd2009-11-02 20:59:23 +00001228 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(BA, ARMPCLabelIndex,
1229 ARMCP::CPBlockAddress,
1230 PCAdj);
1231 CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
1232 }
1233 CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr);
1234 SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr,
1235 PseudoSourceValue::getConstantPool(), 0);
1236 if (RelocM == Reloc::Static)
1237 return Result;
Evan Chenge7e0d622009-11-06 22:24:13 +00001238 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
Bob Wilson907eebd2009-11-02 20:59:23 +00001239 return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel);
Bob Wilsonddb16df2009-10-30 05:45:42 +00001240}
1241
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001242// Lower ISD::GlobalTLSAddress using the "general dynamic" model
Dan Gohman475871a2008-07-27 21:46:04 +00001243SDValue
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001244ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
1245 SelectionDAG &DAG) {
Dale Johannesen33c960f2009-02-04 20:06:27 +00001246 DebugLoc dl = GA->getDebugLoc();
Owen Andersone50ed302009-08-10 22:56:29 +00001247 EVT PtrVT = getPointerTy();
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001248 unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8;
Evan Chenge7e0d622009-11-06 22:24:13 +00001249 MachineFunction &MF = DAG.getMachineFunction();
1250 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1251 unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId();
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001252 ARMConstantPoolValue *CPV =
Evan Chenge4e4ed32009-08-28 23:18:09 +00001253 new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +00001254 ARMCP::CPValue, PCAdj, "tlsgd", true);
Evan Cheng1606e8e2009-03-13 07:51:59 +00001255 SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4);
Owen Anderson825b72b2009-08-11 20:47:22 +00001256 Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument);
Evan Cheng9eda6892009-10-31 03:39:36 +00001257 Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument,
1258 PseudoSourceValue::getConstantPool(), 0);
Dan Gohman475871a2008-07-27 21:46:04 +00001259 SDValue Chain = Argument.getValue(1);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001260
Evan Chenge7e0d622009-11-06 22:24:13 +00001261 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001262 Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001263
1264 // call __tls_get_addr.
1265 ArgListTy Args;
1266 ArgListEntry Entry;
1267 Entry.Node = Argument;
Owen Anderson1d0be152009-08-13 21:58:54 +00001268 Entry.Ty = (const Type *) Type::getInt32Ty(*DAG.getContext());
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001269 Args.push_back(Entry);
Dale Johannesen7d2ad622009-01-30 23:10:59 +00001270 // FIXME: is there useful debug info available here?
Dan Gohman475871a2008-07-27 21:46:04 +00001271 std::pair<SDValue, SDValue> CallResult =
Evan Cheng59bc0602009-08-14 19:11:20 +00001272 LowerCallTo(Chain, (const Type *) Type::getInt32Ty(*DAG.getContext()),
1273 false, false, false, false,
Dan Gohman98ca4f22009-08-05 01:29:28 +00001274 0, CallingConv::C, false, /*isReturnValueUsed=*/true,
Dale Johannesen33c960f2009-02-04 20:06:27 +00001275 DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001276 return CallResult.first;
1277}
1278
1279// Lower ISD::GlobalTLSAddress using the "initial exec" or
1280// "local exec" model.
Dan Gohman475871a2008-07-27 21:46:04 +00001281SDValue
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001282ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA,
Bob Wilson2dc4f542009-03-20 22:42:55 +00001283 SelectionDAG &DAG) {
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001284 GlobalValue *GV = GA->getGlobal();
Dale Johannesen33c960f2009-02-04 20:06:27 +00001285 DebugLoc dl = GA->getDebugLoc();
Dan Gohman475871a2008-07-27 21:46:04 +00001286 SDValue Offset;
1287 SDValue Chain = DAG.getEntryNode();
Owen Andersone50ed302009-08-10 22:56:29 +00001288 EVT PtrVT = getPointerTy();
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001289 // Get the Thread Pointer
Dale Johannesen33c960f2009-02-04 20:06:27 +00001290 SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001291
Chris Lattner4fb63d02009-07-15 04:12:33 +00001292 if (GV->isDeclaration()) {
Evan Chenge7e0d622009-11-06 22:24:13 +00001293 MachineFunction &MF = DAG.getMachineFunction();
1294 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1295 unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId();
1296 // Initial exec model.
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001297 unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8;
1298 ARMConstantPoolValue *CPV =
Evan Chenge4e4ed32009-08-28 23:18:09 +00001299 new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +00001300 ARMCP::CPValue, PCAdj, "gottpoff", true);
Evan Cheng1606e8e2009-03-13 07:51:59 +00001301 Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4);
Owen Anderson825b72b2009-08-11 20:47:22 +00001302 Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset);
Evan Cheng9eda6892009-10-31 03:39:36 +00001303 Offset = DAG.getLoad(PtrVT, dl, Chain, Offset,
1304 PseudoSourceValue::getConstantPool(), 0);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001305 Chain = Offset.getValue(1);
1306
Evan Chenge7e0d622009-11-06 22:24:13 +00001307 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001308 Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001309
Evan Cheng9eda6892009-10-31 03:39:36 +00001310 Offset = DAG.getLoad(PtrVT, dl, Chain, Offset,
1311 PseudoSourceValue::getConstantPool(), 0);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001312 } else {
1313 // local exec model
Evan Chenge4e4ed32009-08-28 23:18:09 +00001314 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, "tpoff");
Evan Cheng1606e8e2009-03-13 07:51:59 +00001315 Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4);
Owen Anderson825b72b2009-08-11 20:47:22 +00001316 Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset);
Evan Cheng9eda6892009-10-31 03:39:36 +00001317 Offset = DAG.getLoad(PtrVT, dl, Chain, Offset,
1318 PseudoSourceValue::getConstantPool(), 0);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001319 }
1320
1321 // The address of the thread local variable is the add of the thread
1322 // pointer with the offset of the variable.
Dale Johannesen33c960f2009-02-04 20:06:27 +00001323 return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001324}
1325
Dan Gohman475871a2008-07-27 21:46:04 +00001326SDValue
1327ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) {
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001328 // TODO: implement the "local dynamic" model
1329 assert(Subtarget->isTargetELF() &&
1330 "TLS not implemented for non-ELF targets");
1331 GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
1332 // If the relocation model is PIC, use the "General Dynamic" TLS Model,
1333 // otherwise use the "Local Exec" TLS Model
1334 if (getTargetMachine().getRelocationModel() == Reloc::PIC_)
1335 return LowerToTLSGeneralDynamicModel(GA, DAG);
1336 else
1337 return LowerToTLSExecModels(GA, DAG);
1338}
1339
Dan Gohman475871a2008-07-27 21:46:04 +00001340SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
Bob Wilson2dc4f542009-03-20 22:42:55 +00001341 SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +00001342 EVT PtrVT = getPointerTy();
Dale Johannesen33c960f2009-02-04 20:06:27 +00001343 DebugLoc dl = Op.getDebugLoc();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001344 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
1345 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
1346 if (RelocM == Reloc::PIC_) {
Rafael Espindolabb46f522009-01-15 20:18:42 +00001347 bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001348 ARMConstantPoolValue *CPV =
Evan Chenge4e4ed32009-08-28 23:18:09 +00001349 new ARMConstantPoolValue(GV, UseGOTOFF ? "GOTOFF" : "GOT");
Evan Cheng1606e8e2009-03-13 07:51:59 +00001350 SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
Owen Anderson825b72b2009-08-11 20:47:22 +00001351 CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
Bob Wilson2dc4f542009-03-20 22:42:55 +00001352 SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(),
Anton Korobeynikov249fb332009-10-07 00:06:35 +00001353 CPAddr,
1354 PseudoSourceValue::getConstantPool(), 0);
Dan Gohman475871a2008-07-27 21:46:04 +00001355 SDValue Chain = Result.getValue(1);
Dale Johannesenb300d2a2009-02-07 00:55:49 +00001356 SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001357 Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001358 if (!UseGOTOFF)
Anton Korobeynikov249fb332009-10-07 00:06:35 +00001359 Result = DAG.getLoad(PtrVT, dl, Chain, Result,
1360 PseudoSourceValue::getGOT(), 0);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001361 return Result;
1362 } else {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001363 // If we have T2 ops, we can materialize the address directly via movt/movw
1364 // pair. This is always cheaper.
1365 if (Subtarget->useMovt()) {
1366 return DAG.getNode(ARMISD::Wrapper, dl, PtrVT,
1367 DAG.getTargetGlobalAddress(GV, PtrVT));
1368 } else {
1369 SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4);
1370 CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
1371 return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr,
1372 PseudoSourceValue::getConstantPool(), 0);
1373 }
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001374 }
1375}
1376
Dan Gohman475871a2008-07-27 21:46:04 +00001377SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op,
Bob Wilson2dc4f542009-03-20 22:42:55 +00001378 SelectionDAG &DAG) {
Evan Chenge7e0d622009-11-06 22:24:13 +00001379 MachineFunction &MF = DAG.getMachineFunction();
1380 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1381 unsigned ARMPCLabelIndex = 0;
Owen Andersone50ed302009-08-10 22:56:29 +00001382 EVT PtrVT = getPointerTy();
Dale Johannesen33c960f2009-02-04 20:06:27 +00001383 DebugLoc dl = Op.getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001384 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
1385 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
Dan Gohman475871a2008-07-27 21:46:04 +00001386 SDValue CPAddr;
Evan Chenga8e29892007-01-19 07:51:42 +00001387 if (RelocM == Reloc::Static)
Evan Cheng1606e8e2009-03-13 07:51:59 +00001388 CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4);
Evan Chenga8e29892007-01-19 07:51:42 +00001389 else {
Evan Chenge7e0d622009-11-06 22:24:13 +00001390 ARMPCLabelIndex = AFI->createConstPoolEntryUId();
Evan Chenge4e4ed32009-08-28 23:18:09 +00001391 unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8);
1392 ARMConstantPoolValue *CPV =
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +00001393 new ARMConstantPoolValue(GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj);
Evan Cheng1606e8e2009-03-13 07:51:59 +00001394 CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
Evan Chenga8e29892007-01-19 07:51:42 +00001395 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001396 CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
Evan Chenga8e29892007-01-19 07:51:42 +00001397
Evan Cheng9eda6892009-10-31 03:39:36 +00001398 SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr,
1399 PseudoSourceValue::getConstantPool(), 0);
Dan Gohman475871a2008-07-27 21:46:04 +00001400 SDValue Chain = Result.getValue(1);
Evan Chenga8e29892007-01-19 07:51:42 +00001401
1402 if (RelocM == Reloc::PIC_) {
Evan Chenge7e0d622009-11-06 22:24:13 +00001403 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001404 Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel);
Evan Chenga8e29892007-01-19 07:51:42 +00001405 }
Evan Chenge4e4ed32009-08-28 23:18:09 +00001406
Evan Cheng63476a82009-09-03 07:04:02 +00001407 if (Subtarget->GVIsIndirectSymbol(GV, RelocM))
Evan Cheng9eda6892009-10-31 03:39:36 +00001408 Result = DAG.getLoad(PtrVT, dl, Chain, Result,
1409 PseudoSourceValue::getGOT(), 0);
Evan Chenga8e29892007-01-19 07:51:42 +00001410
1411 return Result;
1412}
1413
Dan Gohman475871a2008-07-27 21:46:04 +00001414SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op,
Bob Wilson2dc4f542009-03-20 22:42:55 +00001415 SelectionDAG &DAG){
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001416 assert(Subtarget->isTargetELF() &&
1417 "GLOBAL OFFSET TABLE not implemented for non-ELF targets");
Evan Chenge7e0d622009-11-06 22:24:13 +00001418 MachineFunction &MF = DAG.getMachineFunction();
1419 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1420 unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId();
Owen Andersone50ed302009-08-10 22:56:29 +00001421 EVT PtrVT = getPointerTy();
Dale Johannesen33c960f2009-02-04 20:06:27 +00001422 DebugLoc dl = Op.getDebugLoc();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001423 unsigned PCAdj = Subtarget->isThumb() ? 4 : 8;
Owen Anderson1d0be152009-08-13 21:58:54 +00001424 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(),
1425 "_GLOBAL_OFFSET_TABLE_",
Evan Chenge4e4ed32009-08-28 23:18:09 +00001426 ARMPCLabelIndex, PCAdj);
Evan Cheng1606e8e2009-03-13 07:51:59 +00001427 SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
Owen Anderson825b72b2009-08-11 20:47:22 +00001428 CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
Anton Korobeynikov249fb332009-10-07 00:06:35 +00001429 SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr,
1430 PseudoSourceValue::getConstantPool(), 0);
Evan Chenge7e0d622009-11-06 22:24:13 +00001431 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001432 return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00001433}
1434
Jim Grosbach0e0da732009-05-12 23:59:14 +00001435SDValue
1436ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001437 unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
Jim Grosbach0e0da732009-05-12 23:59:14 +00001438 DebugLoc dl = Op.getDebugLoc();
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +00001439 switch (IntNo) {
Dan Gohman475871a2008-07-27 21:46:04 +00001440 default: return SDValue(); // Don't custom lower most intrinsics.
Bob Wilson916afdb2009-08-04 00:25:01 +00001441 case Intrinsic::arm_thread_pointer: {
Owen Andersone50ed302009-08-10 22:56:29 +00001442 EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
Bob Wilson916afdb2009-08-04 00:25:01 +00001443 return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT);
1444 }
Jim Grosbach1b747ad2009-08-11 00:09:57 +00001445 case Intrinsic::eh_sjlj_lsda: {
Jim Grosbach1b747ad2009-08-11 00:09:57 +00001446 MachineFunction &MF = DAG.getMachineFunction();
Evan Chenge7e0d622009-11-06 22:24:13 +00001447 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1448 unsigned ARMPCLabelIndex = AFI->createConstPoolEntryUId();
Jim Grosbach1b747ad2009-08-11 00:09:57 +00001449 EVT PtrVT = getPointerTy();
1450 DebugLoc dl = Op.getDebugLoc();
1451 Reloc::Model RelocM = getTargetMachine().getRelocationModel();
1452 SDValue CPAddr;
1453 unsigned PCAdj = (RelocM != Reloc::PIC_)
1454 ? 0 : (Subtarget->isThumb() ? 4 : 8);
Jim Grosbach1b747ad2009-08-11 00:09:57 +00001455 ARMConstantPoolValue *CPV =
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +00001456 new ARMConstantPoolValue(MF.getFunction(), ARMPCLabelIndex,
1457 ARMCP::CPLSDA, PCAdj);
Jim Grosbach1b747ad2009-08-11 00:09:57 +00001458 CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
Owen Anderson825b72b2009-08-11 20:47:22 +00001459 CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
Jim Grosbach1b747ad2009-08-11 00:09:57 +00001460 SDValue Result =
Evan Cheng9eda6892009-10-31 03:39:36 +00001461 DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr,
1462 PseudoSourceValue::getConstantPool(), 0);
Jim Grosbach1b747ad2009-08-11 00:09:57 +00001463 SDValue Chain = Result.getValue(1);
1464
1465 if (RelocM == Reloc::PIC_) {
Evan Chenge7e0d622009-11-06 22:24:13 +00001466 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
Jim Grosbach1b747ad2009-08-11 00:09:57 +00001467 Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel);
1468 }
1469 return Result;
1470 }
Jim Grosbachf9570122009-05-14 00:46:35 +00001471 case Intrinsic::eh_sjlj_setjmp:
Owen Anderson825b72b2009-08-11 20:47:22 +00001472 return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, MVT::i32, Op.getOperand(1));
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +00001473 }
1474}
1475
Jim Grosbach3728e962009-12-10 00:11:09 +00001476static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG) {
1477 DebugLoc dl = Op.getDebugLoc();
1478 SDValue Op5 = Op.getOperand(5);
1479 SDValue Res;
1480 unsigned isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue();
1481 if (isDeviceBarrier) {
1482 Res = DAG.getNode(ARMISD::SYNCBARRIER, dl, MVT::Other,
1483 Op.getOperand(0));
1484 } else {
1485 Res = DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other,
1486 Op.getOperand(0));
1487 }
1488 return Res;
1489}
1490
Dan Gohman475871a2008-07-27 21:46:04 +00001491static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG,
Bob Wilson2dc4f542009-03-20 22:42:55 +00001492 unsigned VarArgsFrameIndex) {
Evan Chenga8e29892007-01-19 07:51:42 +00001493 // vastart just stores the address of the VarArgsFrameIndex slot into the
1494 // memory location argument.
Dale Johannesen33c960f2009-02-04 20:06:27 +00001495 DebugLoc dl = Op.getDebugLoc();
Owen Andersone50ed302009-08-10 22:56:29 +00001496 EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
Dan Gohman475871a2008-07-27 21:46:04 +00001497 SDValue FR = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT);
Dan Gohman69de1932008-02-06 22:27:42 +00001498 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
Dale Johannesen33c960f2009-02-04 20:06:27 +00001499 return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), SV, 0);
Evan Chenga8e29892007-01-19 07:51:42 +00001500}
1501
Dan Gohman475871a2008-07-27 21:46:04 +00001502SDValue
Evan Cheng86198642009-08-07 00:34:42 +00001503ARMTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) {
1504 SDNode *Node = Op.getNode();
1505 DebugLoc dl = Node->getDebugLoc();
Owen Andersone50ed302009-08-10 22:56:29 +00001506 EVT VT = Node->getValueType(0);
Evan Cheng86198642009-08-07 00:34:42 +00001507 SDValue Chain = Op.getOperand(0);
1508 SDValue Size = Op.getOperand(1);
1509 SDValue Align = Op.getOperand(2);
1510
1511 // Chain the dynamic stack allocation so that it doesn't modify the stack
1512 // pointer when other instructions are using the stack.
1513 Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, true));
1514
1515 unsigned AlignVal = cast<ConstantSDNode>(Align)->getZExtValue();
1516 unsigned StackAlign = getTargetMachine().getFrameInfo()->getStackAlignment();
1517 if (AlignVal > StackAlign)
1518 // Do this now since selection pass cannot introduce new target
1519 // independent node.
1520 Align = DAG.getConstant(-(uint64_t)AlignVal, VT);
1521
1522 // In Thumb1 mode, there isn't a "sub r, sp, r" instruction, we will end up
1523 // using a "add r, sp, r" instead. Negate the size now so we don't have to
1524 // do even more horrible hack later.
1525 MachineFunction &MF = DAG.getMachineFunction();
1526 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1527 if (AFI->isThumb1OnlyFunction()) {
1528 bool Negate = true;
1529 ConstantSDNode *C = dyn_cast<ConstantSDNode>(Size);
1530 if (C) {
1531 uint32_t Val = C->getZExtValue();
1532 if (Val <= 508 && ((Val & 3) == 0))
1533 Negate = false;
1534 }
1535 if (Negate)
1536 Size = DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(0, VT), Size);
1537 }
1538
Owen Anderson825b72b2009-08-11 20:47:22 +00001539 SDVTList VTList = DAG.getVTList(VT, MVT::Other);
Evan Cheng86198642009-08-07 00:34:42 +00001540 SDValue Ops1[] = { Chain, Size, Align };
1541 SDValue Res = DAG.getNode(ARMISD::DYN_ALLOC, dl, VTList, Ops1, 3);
1542 Chain = Res.getValue(1);
1543 Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, true),
1544 DAG.getIntPtrConstant(0, true), SDValue());
1545 SDValue Ops2[] = { Res, Chain };
1546 return DAG.getMergeValues(Ops2, 2, dl);
1547}
1548
1549SDValue
Bob Wilson5bafff32009-06-22 23:27:02 +00001550ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA,
1551 SDValue &Root, SelectionDAG &DAG,
1552 DebugLoc dl) {
1553 MachineFunction &MF = DAG.getMachineFunction();
1554 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1555
1556 TargetRegisterClass *RC;
David Goodwinf1daf7d2009-07-08 23:10:31 +00001557 if (AFI->isThumb1OnlyFunction())
Bob Wilson5bafff32009-06-22 23:27:02 +00001558 RC = ARM::tGPRRegisterClass;
1559 else
1560 RC = ARM::GPRRegisterClass;
1561
1562 // Transform the arguments stored in physical registers into virtual ones.
1563 unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC);
Owen Anderson825b72b2009-08-11 20:47:22 +00001564 SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32);
Bob Wilson5bafff32009-06-22 23:27:02 +00001565
1566 SDValue ArgValue2;
1567 if (NextVA.isMemLoc()) {
1568 unsigned ArgSize = NextVA.getLocVT().getSizeInBits()/8;
1569 MachineFrameInfo *MFI = MF.getFrameInfo();
David Greene3f2bf852009-11-12 20:49:22 +00001570 int FI = MFI->CreateFixedObject(ArgSize, NextVA.getLocMemOffset(),
1571 true, false);
Bob Wilson5bafff32009-06-22 23:27:02 +00001572
1573 // Create load node to retrieve arguments from the stack.
1574 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy());
Evan Cheng9eda6892009-10-31 03:39:36 +00001575 ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN,
1576 PseudoSourceValue::getFixedStack(FI), 0);
Bob Wilson5bafff32009-06-22 23:27:02 +00001577 } else {
1578 Reg = MF.addLiveIn(NextVA.getLocReg(), RC);
Owen Anderson825b72b2009-08-11 20:47:22 +00001579 ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32);
Bob Wilson5bafff32009-06-22 23:27:02 +00001580 }
1581
Jim Grosbache5165492009-11-09 00:11:35 +00001582 return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2);
Bob Wilson5bafff32009-06-22 23:27:02 +00001583}
1584
1585SDValue
Dan Gohman98ca4f22009-08-05 01:29:28 +00001586ARMTargetLowering::LowerFormalArguments(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +00001587 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +00001588 const SmallVectorImpl<ISD::InputArg>
1589 &Ins,
1590 DebugLoc dl, SelectionDAG &DAG,
1591 SmallVectorImpl<SDValue> &InVals) {
1592
Bob Wilson1f595bb2009-04-17 19:07:39 +00001593 MachineFunction &MF = DAG.getMachineFunction();
1594 MachineFrameInfo *MFI = MF.getFrameInfo();
1595
Bob Wilson1f595bb2009-04-17 19:07:39 +00001596 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1597
1598 // Assign locations to all of the incoming arguments.
1599 SmallVector<CCValAssign, 16> ArgLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +00001600 CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs,
1601 *DAG.getContext());
1602 CCInfo.AnalyzeFormalArguments(Ins,
Anton Korobeynikov567d14f2009-08-05 19:04:42 +00001603 CCAssignFnForNode(CallConv, /* Return*/ false,
1604 isVarArg));
Bob Wilson1f595bb2009-04-17 19:07:39 +00001605
1606 SmallVector<SDValue, 16> ArgValues;
1607
1608 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1609 CCValAssign &VA = ArgLocs[i];
1610
Bob Wilsondee46d72009-04-17 20:35:10 +00001611 // Arguments stored in registers.
Bob Wilson1f595bb2009-04-17 19:07:39 +00001612 if (VA.isRegLoc()) {
Owen Andersone50ed302009-08-10 22:56:29 +00001613 EVT RegVT = VA.getLocVT();
Bob Wilson1f595bb2009-04-17 19:07:39 +00001614
Bob Wilson5bafff32009-06-22 23:27:02 +00001615 SDValue ArgValue;
Bob Wilson1f595bb2009-04-17 19:07:39 +00001616 if (VA.needsCustom()) {
Bob Wilson5bafff32009-06-22 23:27:02 +00001617 // f64 and vector types are split up into multiple registers or
1618 // combinations of registers and stack slots.
Owen Anderson825b72b2009-08-11 20:47:22 +00001619 RegVT = MVT::i32;
Bob Wilson1f595bb2009-04-17 19:07:39 +00001620
Owen Anderson825b72b2009-08-11 20:47:22 +00001621 if (VA.getLocVT() == MVT::v2f64) {
Bob Wilson5bafff32009-06-22 23:27:02 +00001622 SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i],
Dan Gohman98ca4f22009-08-05 01:29:28 +00001623 Chain, DAG, dl);
Bob Wilson5bafff32009-06-22 23:27:02 +00001624 VA = ArgLocs[++i]; // skip ahead to next loc
1625 SDValue ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i],
Dan Gohman98ca4f22009-08-05 01:29:28 +00001626 Chain, DAG, dl);
Owen Anderson825b72b2009-08-11 20:47:22 +00001627 ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64);
1628 ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64,
Bob Wilson5bafff32009-06-22 23:27:02 +00001629 ArgValue, ArgValue1, DAG.getIntPtrConstant(0));
Owen Anderson825b72b2009-08-11 20:47:22 +00001630 ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64,
Bob Wilson5bafff32009-06-22 23:27:02 +00001631 ArgValue, ArgValue2, DAG.getIntPtrConstant(1));
1632 } else
Dan Gohman98ca4f22009-08-05 01:29:28 +00001633 ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl);
Bob Wilson1f595bb2009-04-17 19:07:39 +00001634
Bob Wilson5bafff32009-06-22 23:27:02 +00001635 } else {
1636 TargetRegisterClass *RC;
Anton Korobeynikov567d14f2009-08-05 19:04:42 +00001637
Owen Anderson825b72b2009-08-11 20:47:22 +00001638 if (RegVT == MVT::f32)
Bob Wilson5bafff32009-06-22 23:27:02 +00001639 RC = ARM::SPRRegisterClass;
Owen Anderson825b72b2009-08-11 20:47:22 +00001640 else if (RegVT == MVT::f64)
Bob Wilson5bafff32009-06-22 23:27:02 +00001641 RC = ARM::DPRRegisterClass;
Owen Anderson825b72b2009-08-11 20:47:22 +00001642 else if (RegVT == MVT::v2f64)
Anton Korobeynikov567d14f2009-08-05 19:04:42 +00001643 RC = ARM::QPRRegisterClass;
Owen Anderson825b72b2009-08-11 20:47:22 +00001644 else if (RegVT == MVT::i32)
Anton Korobeynikov058c2512009-08-05 20:15:19 +00001645 RC = (AFI->isThumb1OnlyFunction() ?
1646 ARM::tGPRRegisterClass : ARM::GPRRegisterClass);
Bob Wilson5bafff32009-06-22 23:27:02 +00001647 else
Anton Korobeynikov058c2512009-08-05 20:15:19 +00001648 llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering");
Bob Wilson5bafff32009-06-22 23:27:02 +00001649
1650 // Transform the arguments in physical registers into virtual ones.
1651 unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC);
Dan Gohman98ca4f22009-08-05 01:29:28 +00001652 ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT);
Bob Wilson1f595bb2009-04-17 19:07:39 +00001653 }
1654
1655 // If this is an 8 or 16-bit value, it is really passed promoted
1656 // to 32 bits. Insert an assert[sz]ext to capture this, then
1657 // truncate to the right size.
1658 switch (VA.getLocInfo()) {
Torok Edwinc23197a2009-07-14 16:55:14 +00001659 default: llvm_unreachable("Unknown loc info!");
Bob Wilson1f595bb2009-04-17 19:07:39 +00001660 case CCValAssign::Full: break;
1661 case CCValAssign::BCvt:
1662 ArgValue = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getValVT(), ArgValue);
1663 break;
1664 case CCValAssign::SExt:
1665 ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue,
1666 DAG.getValueType(VA.getValVT()));
1667 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
1668 break;
1669 case CCValAssign::ZExt:
1670 ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue,
1671 DAG.getValueType(VA.getValVT()));
1672 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
1673 break;
1674 }
1675
Dan Gohman98ca4f22009-08-05 01:29:28 +00001676 InVals.push_back(ArgValue);
Bob Wilson1f595bb2009-04-17 19:07:39 +00001677
1678 } else { // VA.isRegLoc()
1679
1680 // sanity check
1681 assert(VA.isMemLoc());
Owen Anderson825b72b2009-08-11 20:47:22 +00001682 assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered");
Bob Wilson1f595bb2009-04-17 19:07:39 +00001683
1684 unsigned ArgSize = VA.getLocVT().getSizeInBits()/8;
David Greene3f2bf852009-11-12 20:49:22 +00001685 int FI = MFI->CreateFixedObject(ArgSize, VA.getLocMemOffset(),
1686 true, false);
Bob Wilson1f595bb2009-04-17 19:07:39 +00001687
Bob Wilsondee46d72009-04-17 20:35:10 +00001688 // Create load nodes to retrieve arguments from the stack.
Bob Wilson1f595bb2009-04-17 19:07:39 +00001689 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy());
Evan Cheng9eda6892009-10-31 03:39:36 +00001690 InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN,
1691 PseudoSourceValue::getFixedStack(FI), 0));
Bob Wilson1f595bb2009-04-17 19:07:39 +00001692 }
1693 }
1694
1695 // varargs
Evan Chenga8e29892007-01-19 07:51:42 +00001696 if (isVarArg) {
1697 static const unsigned GPRArgRegs[] = {
1698 ARM::R0, ARM::R1, ARM::R2, ARM::R3
1699 };
1700
Bob Wilsondee46d72009-04-17 20:35:10 +00001701 unsigned NumGPRs = CCInfo.getFirstUnallocated
1702 (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0]));
Bob Wilson1f595bb2009-04-17 19:07:39 +00001703
Lauro Ramos Venancio600c3832007-02-23 20:32:57 +00001704 unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
1705 unsigned VARegSize = (4 - NumGPRs) * 4;
1706 unsigned VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1);
Rafael Espindolac1382b72009-10-30 14:33:14 +00001707 unsigned ArgOffset = CCInfo.getNextStackOffset();
Evan Chenga8e29892007-01-19 07:51:42 +00001708 if (VARegSaveSize) {
1709 // If this function is vararg, store any remaining integer argument regs
1710 // to their spots on the stack so that they may be loaded by deferencing
1711 // the result of va_next.
1712 AFI->setVarArgsRegSaveSize(VARegSaveSize);
Lauro Ramos Venancio600c3832007-02-23 20:32:57 +00001713 VarArgsFrameIndex = MFI->CreateFixedObject(VARegSaveSize, ArgOffset +
David Greene3f2bf852009-11-12 20:49:22 +00001714 VARegSaveSize - VARegSize,
1715 true, false);
Dan Gohman475871a2008-07-27 21:46:04 +00001716 SDValue FIN = DAG.getFrameIndex(VarArgsFrameIndex, getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +00001717
Dan Gohman475871a2008-07-27 21:46:04 +00001718 SmallVector<SDValue, 4> MemOps;
Evan Chenga8e29892007-01-19 07:51:42 +00001719 for (; NumGPRs < 4; ++NumGPRs) {
Bob Wilson1f595bb2009-04-17 19:07:39 +00001720 TargetRegisterClass *RC;
David Goodwinf1daf7d2009-07-08 23:10:31 +00001721 if (AFI->isThumb1OnlyFunction())
Bob Wilson1f595bb2009-04-17 19:07:39 +00001722 RC = ARM::tGPRRegisterClass;
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001723 else
Bob Wilson1f595bb2009-04-17 19:07:39 +00001724 RC = ARM::GPRRegisterClass;
1725
Bob Wilson998e1252009-04-20 18:36:57 +00001726 unsigned VReg = MF.addLiveIn(GPRArgRegs[NumGPRs], RC);
Owen Anderson825b72b2009-08-11 20:47:22 +00001727 SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32);
Evan Cheng9eda6892009-10-31 03:39:36 +00001728 SDValue Store = DAG.getStore(Val.getValue(1), dl, Val, FIN,
1729 PseudoSourceValue::getFixedStack(VarArgsFrameIndex), 0);
Evan Chenga8e29892007-01-19 07:51:42 +00001730 MemOps.push_back(Store);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001731 FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN,
Evan Chenga8e29892007-01-19 07:51:42 +00001732 DAG.getConstant(4, getPointerTy()));
1733 }
1734 if (!MemOps.empty())
Owen Anderson825b72b2009-08-11 20:47:22 +00001735 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
Dan Gohman98ca4f22009-08-05 01:29:28 +00001736 &MemOps[0], MemOps.size());
Evan Chenga8e29892007-01-19 07:51:42 +00001737 } else
1738 // This will point to the next argument passed via stack.
David Greene3f2bf852009-11-12 20:49:22 +00001739 VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset, true, false);
Evan Chenga8e29892007-01-19 07:51:42 +00001740 }
1741
Dan Gohman98ca4f22009-08-05 01:29:28 +00001742 return Chain;
Evan Chenga8e29892007-01-19 07:51:42 +00001743}
1744
1745/// isFloatingPointZero - Return true if this is +0.0.
Dan Gohman475871a2008-07-27 21:46:04 +00001746static bool isFloatingPointZero(SDValue Op) {
Evan Chenga8e29892007-01-19 07:51:42 +00001747 if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op))
Dale Johanneseneaf08942007-08-31 04:03:46 +00001748 return CFP->getValueAPF().isPosZero();
Gabor Greifba36cb52008-08-28 21:40:38 +00001749 else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) {
Evan Chenga8e29892007-01-19 07:51:42 +00001750 // Maybe this has already been legalized into the constant pool?
1751 if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) {
Dan Gohman475871a2008-07-27 21:46:04 +00001752 SDValue WrapperOp = Op.getOperand(1).getOperand(0);
Evan Chenga8e29892007-01-19 07:51:42 +00001753 if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp))
1754 if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal()))
Dale Johanneseneaf08942007-08-31 04:03:46 +00001755 return CFP->getValueAPF().isPosZero();
Evan Chenga8e29892007-01-19 07:51:42 +00001756 }
1757 }
1758 return false;
1759}
1760
Evan Chenga8e29892007-01-19 07:51:42 +00001761/// Returns appropriate ARM CMP (cmp) and corresponding condition code for
1762/// the given operands.
Evan Cheng06b53c02009-11-12 07:13:11 +00001763SDValue
1764ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
1765 SDValue &ARMCC, SelectionDAG &DAG, DebugLoc dl) {
Gabor Greifba36cb52008-08-28 21:40:38 +00001766 if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001767 unsigned C = RHSC->getZExtValue();
Evan Cheng06b53c02009-11-12 07:13:11 +00001768 if (!isLegalICmpImmediate(C)) {
Evan Chenga8e29892007-01-19 07:51:42 +00001769 // Constant does not fit, try adjusting it by one?
1770 switch (CC) {
1771 default: break;
1772 case ISD::SETLT:
Evan Chenga8e29892007-01-19 07:51:42 +00001773 case ISD::SETGE:
Evan Cheng06b53c02009-11-12 07:13:11 +00001774 if (isLegalICmpImmediate(C-1)) {
Evan Cheng9a2ef952007-02-02 01:53:26 +00001775 CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT;
Owen Anderson825b72b2009-08-11 20:47:22 +00001776 RHS = DAG.getConstant(C-1, MVT::i32);
Evan Cheng9a2ef952007-02-02 01:53:26 +00001777 }
1778 break;
1779 case ISD::SETULT:
1780 case ISD::SETUGE:
Evan Cheng06b53c02009-11-12 07:13:11 +00001781 if (C > 0 && isLegalICmpImmediate(C-1)) {
Evan Cheng9a2ef952007-02-02 01:53:26 +00001782 CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT;
Owen Anderson825b72b2009-08-11 20:47:22 +00001783 RHS = DAG.getConstant(C-1, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001784 }
1785 break;
1786 case ISD::SETLE:
Evan Chenga8e29892007-01-19 07:51:42 +00001787 case ISD::SETGT:
Evan Cheng06b53c02009-11-12 07:13:11 +00001788 if (isLegalICmpImmediate(C+1)) {
Evan Cheng9a2ef952007-02-02 01:53:26 +00001789 CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE;
Owen Anderson825b72b2009-08-11 20:47:22 +00001790 RHS = DAG.getConstant(C+1, MVT::i32);
Evan Cheng9a2ef952007-02-02 01:53:26 +00001791 }
1792 break;
1793 case ISD::SETULE:
1794 case ISD::SETUGT:
Evan Cheng06b53c02009-11-12 07:13:11 +00001795 if (C < 0xffffffff && isLegalICmpImmediate(C+1)) {
Evan Cheng9a2ef952007-02-02 01:53:26 +00001796 CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE;
Owen Anderson825b72b2009-08-11 20:47:22 +00001797 RHS = DAG.getConstant(C+1, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001798 }
1799 break;
1800 }
1801 }
1802 }
1803
1804 ARMCC::CondCodes CondCode = IntCCToARMCC(CC);
Lauro Ramos Venancio99966632007-04-02 01:30:03 +00001805 ARMISD::NodeType CompareType;
1806 switch (CondCode) {
1807 default:
1808 CompareType = ARMISD::CMP;
1809 break;
1810 case ARMCC::EQ:
1811 case ARMCC::NE:
David Goodwinc0309b42009-06-29 15:33:01 +00001812 // Uses only Z Flag
1813 CompareType = ARMISD::CMPZ;
Lauro Ramos Venancio99966632007-04-02 01:30:03 +00001814 break;
1815 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001816 ARMCC = DAG.getConstant(CondCode, MVT::i32);
1817 return DAG.getNode(CompareType, dl, MVT::Flag, LHS, RHS);
Evan Chenga8e29892007-01-19 07:51:42 +00001818}
1819
1820/// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands.
Bob Wilson2dc4f542009-03-20 22:42:55 +00001821static SDValue getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG,
Dale Johannesende064702009-02-06 21:50:26 +00001822 DebugLoc dl) {
Dan Gohman475871a2008-07-27 21:46:04 +00001823 SDValue Cmp;
Evan Chenga8e29892007-01-19 07:51:42 +00001824 if (!isFloatingPointZero(RHS))
Owen Anderson825b72b2009-08-11 20:47:22 +00001825 Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Flag, LHS, RHS);
Evan Chenga8e29892007-01-19 07:51:42 +00001826 else
Owen Anderson825b72b2009-08-11 20:47:22 +00001827 Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Flag, LHS);
1828 return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Flag, Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001829}
1830
Evan Cheng06b53c02009-11-12 07:13:11 +00001831SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +00001832 EVT VT = Op.getValueType();
Dan Gohman475871a2008-07-27 21:46:04 +00001833 SDValue LHS = Op.getOperand(0);
1834 SDValue RHS = Op.getOperand(1);
Evan Chenga8e29892007-01-19 07:51:42 +00001835 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
Dan Gohman475871a2008-07-27 21:46:04 +00001836 SDValue TrueVal = Op.getOperand(2);
1837 SDValue FalseVal = Op.getOperand(3);
Dale Johannesende064702009-02-06 21:50:26 +00001838 DebugLoc dl = Op.getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001839
Owen Anderson825b72b2009-08-11 20:47:22 +00001840 if (LHS.getValueType() == MVT::i32) {
Dan Gohman475871a2008-07-27 21:46:04 +00001841 SDValue ARMCC;
Owen Anderson825b72b2009-08-11 20:47:22 +00001842 SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
Evan Cheng06b53c02009-11-12 07:13:11 +00001843 SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, dl);
Dale Johannesende064702009-02-06 21:50:26 +00001844 return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMCC, CCR,Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001845 }
1846
1847 ARMCC::CondCodes CondCode, CondCode2;
Bob Wilsoncd3b9a42009-09-09 23:14:54 +00001848 FPCCToARMCC(CC, CondCode, CondCode2);
Evan Chenga8e29892007-01-19 07:51:42 +00001849
Owen Anderson825b72b2009-08-11 20:47:22 +00001850 SDValue ARMCC = DAG.getConstant(CondCode, MVT::i32);
1851 SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
Dale Johannesende064702009-02-06 21:50:26 +00001852 SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl);
1853 SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal,
Evan Cheng0e1d3792007-07-05 07:18:20 +00001854 ARMCC, CCR, Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001855 if (CondCode2 != ARMCC::AL) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001856 SDValue ARMCC2 = DAG.getConstant(CondCode2, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001857 // FIXME: Needs another CMP because flag can have but one use.
Dale Johannesende064702009-02-06 21:50:26 +00001858 SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl);
Bob Wilson2dc4f542009-03-20 22:42:55 +00001859 Result = DAG.getNode(ARMISD::CMOV, dl, VT,
Dale Johannesende064702009-02-06 21:50:26 +00001860 Result, TrueVal, ARMCC2, CCR, Cmp2);
Evan Chenga8e29892007-01-19 07:51:42 +00001861 }
1862 return Result;
1863}
1864
Evan Cheng06b53c02009-11-12 07:13:11 +00001865SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) {
Dan Gohman475871a2008-07-27 21:46:04 +00001866 SDValue Chain = Op.getOperand(0);
Evan Chenga8e29892007-01-19 07:51:42 +00001867 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
Dan Gohman475871a2008-07-27 21:46:04 +00001868 SDValue LHS = Op.getOperand(2);
1869 SDValue RHS = Op.getOperand(3);
1870 SDValue Dest = Op.getOperand(4);
Dale Johannesende064702009-02-06 21:50:26 +00001871 DebugLoc dl = Op.getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001872
Owen Anderson825b72b2009-08-11 20:47:22 +00001873 if (LHS.getValueType() == MVT::i32) {
Dan Gohman475871a2008-07-27 21:46:04 +00001874 SDValue ARMCC;
Owen Anderson825b72b2009-08-11 20:47:22 +00001875 SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
Evan Cheng06b53c02009-11-12 07:13:11 +00001876 SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMCC, DAG, dl);
Owen Anderson825b72b2009-08-11 20:47:22 +00001877 return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other,
Dale Johannesende064702009-02-06 21:50:26 +00001878 Chain, Dest, ARMCC, CCR,Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001879 }
1880
Owen Anderson825b72b2009-08-11 20:47:22 +00001881 assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64);
Evan Chenga8e29892007-01-19 07:51:42 +00001882 ARMCC::CondCodes CondCode, CondCode2;
Bob Wilsoncd3b9a42009-09-09 23:14:54 +00001883 FPCCToARMCC(CC, CondCode, CondCode2);
Bob Wilson2dc4f542009-03-20 22:42:55 +00001884
Dale Johannesende064702009-02-06 21:50:26 +00001885 SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl);
Owen Anderson825b72b2009-08-11 20:47:22 +00001886 SDValue ARMCC = DAG.getConstant(CondCode, MVT::i32);
1887 SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
1888 SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Flag);
Dan Gohman475871a2008-07-27 21:46:04 +00001889 SDValue Ops[] = { Chain, Dest, ARMCC, CCR, Cmp };
Dale Johannesende064702009-02-06 21:50:26 +00001890 SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5);
Evan Chenga8e29892007-01-19 07:51:42 +00001891 if (CondCode2 != ARMCC::AL) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001892 ARMCC = DAG.getConstant(CondCode2, MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001893 SDValue Ops[] = { Res, Dest, ARMCC, CCR, Res.getValue(1) };
Dale Johannesende064702009-02-06 21:50:26 +00001894 Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5);
Evan Chenga8e29892007-01-19 07:51:42 +00001895 }
1896 return Res;
1897}
1898
Dan Gohman475871a2008-07-27 21:46:04 +00001899SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) {
1900 SDValue Chain = Op.getOperand(0);
1901 SDValue Table = Op.getOperand(1);
1902 SDValue Index = Op.getOperand(2);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001903 DebugLoc dl = Op.getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001904
Owen Andersone50ed302009-08-10 22:56:29 +00001905 EVT PTy = getPointerTy();
Evan Chenga8e29892007-01-19 07:51:42 +00001906 JumpTableSDNode *JT = cast<JumpTableSDNode>(Table);
1907 ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>();
Bob Wilson3eadf002009-07-14 18:44:34 +00001908 SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy);
Dan Gohman475871a2008-07-27 21:46:04 +00001909 SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy);
Owen Anderson825b72b2009-08-11 20:47:22 +00001910 Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId);
Evan Chenge7c329b2009-07-28 20:53:24 +00001911 Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy));
1912 SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table);
Evan Cheng66ac5312009-07-25 00:33:29 +00001913 if (Subtarget->isThumb2()) {
1914 // Thumb2 uses a two-level jump. That is, it jumps into the jump table
1915 // which does another jump to the destination. This also makes it easier
1916 // to translate it to TBB / TBH later.
1917 // FIXME: This might not work if the function is extremely large.
Owen Anderson825b72b2009-08-11 20:47:22 +00001918 return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain,
Evan Cheng5657c012009-07-29 02:18:14 +00001919 Addr, Op.getOperand(2), JTI, UId);
Evan Cheng66ac5312009-07-25 00:33:29 +00001920 }
Evan Cheng66ac5312009-07-25 00:33:29 +00001921 if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
Evan Cheng9eda6892009-10-31 03:39:36 +00001922 Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr,
1923 PseudoSourceValue::getJumpTable(), 0);
Evan Cheng66ac5312009-07-25 00:33:29 +00001924 Chain = Addr.getValue(1);
Dale Johannesen33c960f2009-02-04 20:06:27 +00001925 Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table);
Owen Anderson825b72b2009-08-11 20:47:22 +00001926 return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId);
Evan Cheng66ac5312009-07-25 00:33:29 +00001927 } else {
Evan Cheng9eda6892009-10-31 03:39:36 +00001928 Addr = DAG.getLoad(PTy, dl, Chain, Addr,
1929 PseudoSourceValue::getJumpTable(), 0);
Evan Cheng66ac5312009-07-25 00:33:29 +00001930 Chain = Addr.getValue(1);
Owen Anderson825b72b2009-08-11 20:47:22 +00001931 return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId);
Evan Cheng66ac5312009-07-25 00:33:29 +00001932 }
Evan Chenga8e29892007-01-19 07:51:42 +00001933}
1934
Dan Gohman475871a2008-07-27 21:46:04 +00001935static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) {
Dale Johannesende064702009-02-06 21:50:26 +00001936 DebugLoc dl = Op.getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001937 unsigned Opc =
1938 Op.getOpcode() == ISD::FP_TO_SINT ? ARMISD::FTOSI : ARMISD::FTOUI;
Owen Anderson825b72b2009-08-11 20:47:22 +00001939 Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0));
1940 return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Op);
Evan Chenga8e29892007-01-19 07:51:42 +00001941}
1942
Dan Gohman475871a2008-07-27 21:46:04 +00001943static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +00001944 EVT VT = Op.getValueType();
Dale Johannesende064702009-02-06 21:50:26 +00001945 DebugLoc dl = Op.getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001946 unsigned Opc =
1947 Op.getOpcode() == ISD::SINT_TO_FP ? ARMISD::SITOF : ARMISD::UITOF;
1948
Owen Anderson825b72b2009-08-11 20:47:22 +00001949 Op = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, Op.getOperand(0));
Dale Johannesende064702009-02-06 21:50:26 +00001950 return DAG.getNode(Opc, dl, VT, Op);
Evan Chenga8e29892007-01-19 07:51:42 +00001951}
1952
Dan Gohman475871a2008-07-27 21:46:04 +00001953static SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) {
Evan Chenga8e29892007-01-19 07:51:42 +00001954 // Implement fcopysign with a fabs and a conditional fneg.
Dan Gohman475871a2008-07-27 21:46:04 +00001955 SDValue Tmp0 = Op.getOperand(0);
1956 SDValue Tmp1 = Op.getOperand(1);
Dale Johannesende064702009-02-06 21:50:26 +00001957 DebugLoc dl = Op.getDebugLoc();
Owen Andersone50ed302009-08-10 22:56:29 +00001958 EVT VT = Op.getValueType();
1959 EVT SrcVT = Tmp1.getValueType();
Dale Johannesende064702009-02-06 21:50:26 +00001960 SDValue AbsVal = DAG.getNode(ISD::FABS, dl, VT, Tmp0);
1961 SDValue Cmp = getVFPCmp(Tmp1, DAG.getConstantFP(0.0, SrcVT), DAG, dl);
Owen Anderson825b72b2009-08-11 20:47:22 +00001962 SDValue ARMCC = DAG.getConstant(ARMCC::LT, MVT::i32);
1963 SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
Dale Johannesende064702009-02-06 21:50:26 +00001964 return DAG.getNode(ARMISD::CNEG, dl, VT, AbsVal, AbsVal, ARMCC, CCR, Cmp);
Evan Chenga8e29892007-01-19 07:51:42 +00001965}
1966
Jim Grosbach0e0da732009-05-12 23:59:14 +00001967SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) {
1968 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
1969 MFI->setFrameAddressIsTaken(true);
Owen Andersone50ed302009-08-10 22:56:29 +00001970 EVT VT = Op.getValueType();
Jim Grosbach0e0da732009-05-12 23:59:14 +00001971 DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful
1972 unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
Evan Chengcd828612009-06-18 23:14:30 +00001973 unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin())
Jim Grosbach0e0da732009-05-12 23:59:14 +00001974 ? ARM::R7 : ARM::R11;
1975 SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT);
1976 while (Depth--)
1977 FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, NULL, 0);
1978 return FrameAddr;
1979}
1980
Dan Gohman475871a2008-07-27 21:46:04 +00001981SDValue
Dale Johannesen0f502f62009-02-03 22:26:09 +00001982ARMTargetLowering::EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl,
Dan Gohman475871a2008-07-27 21:46:04 +00001983 SDValue Chain,
1984 SDValue Dst, SDValue Src,
1985 SDValue Size, unsigned Align,
Dan Gohman707e0182008-04-12 04:36:06 +00001986 bool AlwaysInline,
Dan Gohman1f13c682008-04-28 17:15:20 +00001987 const Value *DstSV, uint64_t DstSVOff,
1988 const Value *SrcSV, uint64_t SrcSVOff){
Evan Cheng4102eb52007-10-22 22:11:27 +00001989 // Do repeated 4-byte loads and stores. To be improved.
Dan Gohman707e0182008-04-12 04:36:06 +00001990 // This requires 4-byte alignment.
1991 if ((Align & 3) != 0)
Dan Gohman475871a2008-07-27 21:46:04 +00001992 return SDValue();
Dan Gohman707e0182008-04-12 04:36:06 +00001993 // This requires the copy size to be a constant, preferrably
1994 // within a subtarget-specific limit.
1995 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
1996 if (!ConstantSize)
Dan Gohman475871a2008-07-27 21:46:04 +00001997 return SDValue();
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001998 uint64_t SizeVal = ConstantSize->getZExtValue();
Dan Gohman707e0182008-04-12 04:36:06 +00001999 if (!AlwaysInline && SizeVal > getSubtarget()->getMaxInlineSizeThreshold())
Dan Gohman475871a2008-07-27 21:46:04 +00002000 return SDValue();
Dan Gohman707e0182008-04-12 04:36:06 +00002001
2002 unsigned BytesLeft = SizeVal & 3;
2003 unsigned NumMemOps = SizeVal >> 2;
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002004 unsigned EmittedNumMemOps = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002005 EVT VT = MVT::i32;
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002006 unsigned VTSize = 4;
Evan Cheng4102eb52007-10-22 22:11:27 +00002007 unsigned i = 0;
Evan Chenge5e7ce42007-05-18 01:19:57 +00002008 const unsigned MAX_LOADS_IN_LDM = 6;
Dan Gohman475871a2008-07-27 21:46:04 +00002009 SDValue TFOps[MAX_LOADS_IN_LDM];
2010 SDValue Loads[MAX_LOADS_IN_LDM];
Dan Gohman1f13c682008-04-28 17:15:20 +00002011 uint64_t SrcOff = 0, DstOff = 0;
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002012
Evan Cheng4102eb52007-10-22 22:11:27 +00002013 // Emit up to MAX_LOADS_IN_LDM loads, then a TokenFactor barrier, then the
2014 // same number of stores. The loads and stores will get combined into
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002015 // ldm/stm later on.
Evan Cheng4102eb52007-10-22 22:11:27 +00002016 while (EmittedNumMemOps < NumMemOps) {
2017 for (i = 0;
2018 i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) {
Dale Johannesen0f502f62009-02-03 22:26:09 +00002019 Loads[i] = DAG.getLoad(VT, dl, Chain,
Owen Anderson825b72b2009-08-11 20:47:22 +00002020 DAG.getNode(ISD::ADD, dl, MVT::i32, Src,
2021 DAG.getConstant(SrcOff, MVT::i32)),
Dan Gohman1f13c682008-04-28 17:15:20 +00002022 SrcSV, SrcSVOff + SrcOff);
Evan Cheng4102eb52007-10-22 22:11:27 +00002023 TFOps[i] = Loads[i].getValue(1);
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002024 SrcOff += VTSize;
2025 }
Owen Anderson825b72b2009-08-11 20:47:22 +00002026 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002027
Evan Cheng4102eb52007-10-22 22:11:27 +00002028 for (i = 0;
2029 i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) {
Dale Johannesen0f502f62009-02-03 22:26:09 +00002030 TFOps[i] = DAG.getStore(Chain, dl, Loads[i],
Owen Anderson825b72b2009-08-11 20:47:22 +00002031 DAG.getNode(ISD::ADD, dl, MVT::i32, Dst,
2032 DAG.getConstant(DstOff, MVT::i32)),
Dan Gohman1f13c682008-04-28 17:15:20 +00002033 DstSV, DstSVOff + DstOff);
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002034 DstOff += VTSize;
2035 }
Owen Anderson825b72b2009-08-11 20:47:22 +00002036 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
Evan Cheng4102eb52007-10-22 22:11:27 +00002037
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002038 EmittedNumMemOps += i;
2039 }
2040
Bob Wilson2dc4f542009-03-20 22:42:55 +00002041 if (BytesLeft == 0)
Evan Cheng4102eb52007-10-22 22:11:27 +00002042 return Chain;
2043
2044 // Issue loads / stores for the trailing (1 - 3) bytes.
2045 unsigned BytesLeftSave = BytesLeft;
2046 i = 0;
2047 while (BytesLeft) {
2048 if (BytesLeft >= 2) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002049 VT = MVT::i16;
Evan Cheng4102eb52007-10-22 22:11:27 +00002050 VTSize = 2;
2051 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +00002052 VT = MVT::i8;
Evan Cheng4102eb52007-10-22 22:11:27 +00002053 VTSize = 1;
2054 }
2055
Dale Johannesen0f502f62009-02-03 22:26:09 +00002056 Loads[i] = DAG.getLoad(VT, dl, Chain,
Owen Anderson825b72b2009-08-11 20:47:22 +00002057 DAG.getNode(ISD::ADD, dl, MVT::i32, Src,
2058 DAG.getConstant(SrcOff, MVT::i32)),
Dan Gohman1f13c682008-04-28 17:15:20 +00002059 SrcSV, SrcSVOff + SrcOff);
Evan Cheng4102eb52007-10-22 22:11:27 +00002060 TFOps[i] = Loads[i].getValue(1);
2061 ++i;
2062 SrcOff += VTSize;
2063 BytesLeft -= VTSize;
2064 }
Owen Anderson825b72b2009-08-11 20:47:22 +00002065 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
Evan Cheng4102eb52007-10-22 22:11:27 +00002066
2067 i = 0;
2068 BytesLeft = BytesLeftSave;
2069 while (BytesLeft) {
2070 if (BytesLeft >= 2) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002071 VT = MVT::i16;
Evan Cheng4102eb52007-10-22 22:11:27 +00002072 VTSize = 2;
2073 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +00002074 VT = MVT::i8;
Evan Cheng4102eb52007-10-22 22:11:27 +00002075 VTSize = 1;
2076 }
2077
Dale Johannesen0f502f62009-02-03 22:26:09 +00002078 TFOps[i] = DAG.getStore(Chain, dl, Loads[i],
Owen Anderson825b72b2009-08-11 20:47:22 +00002079 DAG.getNode(ISD::ADD, dl, MVT::i32, Dst,
2080 DAG.getConstant(DstOff, MVT::i32)),
Dan Gohman1f13c682008-04-28 17:15:20 +00002081 DstSV, DstSVOff + DstOff);
Evan Cheng4102eb52007-10-22 22:11:27 +00002082 ++i;
2083 DstOff += VTSize;
2084 BytesLeft -= VTSize;
2085 }
Owen Anderson825b72b2009-08-11 20:47:22 +00002086 return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
Dale Johannesen8dd86c12007-05-17 21:31:21 +00002087}
2088
Duncan Sands1607f052008-12-01 11:39:25 +00002089static SDValue ExpandBIT_CONVERT(SDNode *N, SelectionDAG &DAG) {
Dan Gohman475871a2008-07-27 21:46:04 +00002090 SDValue Op = N->getOperand(0);
Dale Johannesende064702009-02-06 21:50:26 +00002091 DebugLoc dl = N->getDebugLoc();
Owen Anderson825b72b2009-08-11 20:47:22 +00002092 if (N->getValueType(0) == MVT::f64) {
Jim Grosbache5165492009-11-09 00:11:35 +00002093 // Turn i64->f64 into VMOVDRR.
Owen Anderson825b72b2009-08-11 20:47:22 +00002094 SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op,
2095 DAG.getConstant(0, MVT::i32));
2096 SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op,
2097 DAG.getConstant(1, MVT::i32));
Jim Grosbache5165492009-11-09 00:11:35 +00002098 return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi);
Evan Chengc7c77292008-11-04 19:57:48 +00002099 }
Bob Wilson2dc4f542009-03-20 22:42:55 +00002100
Jim Grosbache5165492009-11-09 00:11:35 +00002101 // Turn f64->i64 into VMOVRRD.
2102 SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +00002103 DAG.getVTList(MVT::i32, MVT::i32), &Op, 1);
Bob Wilson2dc4f542009-03-20 22:42:55 +00002104
Chris Lattner27a6c732007-11-24 07:07:01 +00002105 // Merge the pieces into a single i64 value.
Owen Anderson825b72b2009-08-11 20:47:22 +00002106 return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1));
Chris Lattner27a6c732007-11-24 07:07:01 +00002107}
2108
Bob Wilson5bafff32009-06-22 23:27:02 +00002109/// getZeroVector - Returns a vector of specified type with all zero elements.
2110///
Owen Andersone50ed302009-08-10 22:56:29 +00002111static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) {
Bob Wilson5bafff32009-06-22 23:27:02 +00002112 assert(VT.isVector() && "Expected a vector type");
2113
2114 // Zero vectors are used to represent vector negation and in those cases
2115 // will be implemented with the NEON VNEG instruction. However, VNEG does
2116 // not support i64 elements, so sometimes the zero vectors will need to be
2117 // explicitly constructed. For those cases, and potentially other uses in
Anton Korobeynikov2ba62ef2009-09-08 22:51:43 +00002118 // the future, always build zero vectors as <16 x i8> or <8 x i8> bitcasted
Bob Wilson5bafff32009-06-22 23:27:02 +00002119 // to their dest type. This ensures they get CSE'd.
2120 SDValue Vec;
Anton Korobeynikov2ba62ef2009-09-08 22:51:43 +00002121 SDValue Cst = DAG.getTargetConstant(0, MVT::i8);
2122 SmallVector<SDValue, 8> Ops;
2123 MVT TVT;
2124
2125 if (VT.getSizeInBits() == 64) {
2126 Ops.assign(8, Cst); TVT = MVT::v8i8;
2127 } else {
2128 Ops.assign(16, Cst); TVT = MVT::v16i8;
2129 }
2130 Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, TVT, &Ops[0], Ops.size());
Bob Wilson5bafff32009-06-22 23:27:02 +00002131
2132 return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Vec);
2133}
2134
2135/// getOnesVector - Returns a vector of specified type with all bits set.
2136///
Owen Andersone50ed302009-08-10 22:56:29 +00002137static SDValue getOnesVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) {
Bob Wilson5bafff32009-06-22 23:27:02 +00002138 assert(VT.isVector() && "Expected a vector type");
2139
Bob Wilson929ffa22009-10-30 20:13:25 +00002140 // Always build ones vectors as <16 x i8> or <8 x i8> bitcasted to their
Anton Korobeynikov2ba62ef2009-09-08 22:51:43 +00002141 // dest type. This ensures they get CSE'd.
Bob Wilson5bafff32009-06-22 23:27:02 +00002142 SDValue Vec;
Anton Korobeynikov2ba62ef2009-09-08 22:51:43 +00002143 SDValue Cst = DAG.getTargetConstant(0xFF, MVT::i8);
2144 SmallVector<SDValue, 8> Ops;
2145 MVT TVT;
2146
2147 if (VT.getSizeInBits() == 64) {
2148 Ops.assign(8, Cst); TVT = MVT::v8i8;
2149 } else {
2150 Ops.assign(16, Cst); TVT = MVT::v16i8;
2151 }
2152 Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, TVT, &Ops[0], Ops.size());
Bob Wilson5bafff32009-06-22 23:27:02 +00002153
2154 return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Vec);
2155}
2156
Jim Grosbachb4a976c2009-10-31 21:00:56 +00002157/// LowerShiftRightParts - Lower SRA_PARTS, which returns two
2158/// i32 values and take a 2 x i32 value to shift plus a shift amount.
Evan Cheng06b53c02009-11-12 07:13:11 +00002159SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) {
Jim Grosbachb4a976c2009-10-31 21:00:56 +00002160 assert(Op.getNumOperands() == 3 && "Not a double-shift!");
2161 EVT VT = Op.getValueType();
2162 unsigned VTBits = VT.getSizeInBits();
2163 DebugLoc dl = Op.getDebugLoc();
2164 SDValue ShOpLo = Op.getOperand(0);
2165 SDValue ShOpHi = Op.getOperand(1);
2166 SDValue ShAmt = Op.getOperand(2);
2167 SDValue ARMCC;
Jim Grosbachbcf2f2c2009-10-31 21:42:19 +00002168 unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL;
Jim Grosbachb4a976c2009-10-31 21:00:56 +00002169
Jim Grosbachbcf2f2c2009-10-31 21:42:19 +00002170 assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS);
2171
Jim Grosbachb4a976c2009-10-31 21:00:56 +00002172 SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32,
2173 DAG.getConstant(VTBits, MVT::i32), ShAmt);
2174 SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt);
2175 SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt,
2176 DAG.getConstant(VTBits, MVT::i32));
2177 SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt);
2178 SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
Jim Grosbachbcf2f2c2009-10-31 21:42:19 +00002179 SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt);
Jim Grosbachb4a976c2009-10-31 21:00:56 +00002180
2181 SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
2182 SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE,
Evan Cheng06b53c02009-11-12 07:13:11 +00002183 ARMCC, DAG, dl);
Jim Grosbachbcf2f2c2009-10-31 21:42:19 +00002184 SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt);
Jim Grosbachb4a976c2009-10-31 21:00:56 +00002185 SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMCC,
2186 CCR, Cmp);
2187
2188 SDValue Ops[2] = { Lo, Hi };
2189 return DAG.getMergeValues(Ops, 2, dl);
2190}
2191
Jim Grosbachc2b879f2009-10-31 19:38:01 +00002192/// LowerShiftLeftParts - Lower SHL_PARTS, which returns two
2193/// i32 values and take a 2 x i32 value to shift plus a shift amount.
Evan Cheng06b53c02009-11-12 07:13:11 +00002194SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) {
Jim Grosbachc2b879f2009-10-31 19:38:01 +00002195 assert(Op.getNumOperands() == 3 && "Not a double-shift!");
2196 EVT VT = Op.getValueType();
2197 unsigned VTBits = VT.getSizeInBits();
2198 DebugLoc dl = Op.getDebugLoc();
2199 SDValue ShOpLo = Op.getOperand(0);
2200 SDValue ShOpHi = Op.getOperand(1);
2201 SDValue ShAmt = Op.getOperand(2);
2202 SDValue ARMCC;
2203
2204 assert(Op.getOpcode() == ISD::SHL_PARTS);
2205 SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32,
2206 DAG.getConstant(VTBits, MVT::i32), ShAmt);
2207 SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt);
2208 SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt,
2209 DAG.getConstant(VTBits, MVT::i32));
2210 SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt);
2211 SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt);
2212
2213 SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
2214 SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32);
2215 SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE,
Evan Cheng06b53c02009-11-12 07:13:11 +00002216 ARMCC, DAG, dl);
Jim Grosbachc2b879f2009-10-31 19:38:01 +00002217 SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt);
2218 SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMCC,
2219 CCR, Cmp);
2220
2221 SDValue Ops[2] = { Lo, Hi };
2222 return DAG.getMergeValues(Ops, 2, dl);
2223}
2224
Bob Wilson5bafff32009-06-22 23:27:02 +00002225static SDValue LowerShift(SDNode *N, SelectionDAG &DAG,
2226 const ARMSubtarget *ST) {
Owen Andersone50ed302009-08-10 22:56:29 +00002227 EVT VT = N->getValueType(0);
Bob Wilson5bafff32009-06-22 23:27:02 +00002228 DebugLoc dl = N->getDebugLoc();
2229
2230 // Lower vector shifts on NEON to use VSHL.
2231 if (VT.isVector()) {
2232 assert(ST->hasNEON() && "unexpected vector shift");
2233
2234 // Left shifts translate directly to the vshiftu intrinsic.
2235 if (N->getOpcode() == ISD::SHL)
2236 return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT,
Owen Anderson825b72b2009-08-11 20:47:22 +00002237 DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32),
Bob Wilson5bafff32009-06-22 23:27:02 +00002238 N->getOperand(0), N->getOperand(1));
2239
2240 assert((N->getOpcode() == ISD::SRA ||
2241 N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode");
2242
2243 // NEON uses the same intrinsics for both left and right shifts. For
2244 // right shifts, the shift amounts are negative, so negate the vector of
2245 // shift amounts.
Owen Andersone50ed302009-08-10 22:56:29 +00002246 EVT ShiftVT = N->getOperand(1).getValueType();
Bob Wilson5bafff32009-06-22 23:27:02 +00002247 SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT,
2248 getZeroVector(ShiftVT, DAG, dl),
2249 N->getOperand(1));
2250 Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ?
2251 Intrinsic::arm_neon_vshifts :
2252 Intrinsic::arm_neon_vshiftu);
2253 return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT,
Owen Anderson825b72b2009-08-11 20:47:22 +00002254 DAG.getConstant(vshiftInt, MVT::i32),
Bob Wilson5bafff32009-06-22 23:27:02 +00002255 N->getOperand(0), NegatedCount);
2256 }
2257
Eli Friedmance392eb2009-08-22 03:13:10 +00002258 // We can get here for a node like i32 = ISD::SHL i32, i64
2259 if (VT != MVT::i64)
2260 return SDValue();
2261
2262 assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) &&
Chris Lattner27a6c732007-11-24 07:07:01 +00002263 "Unknown shift to lower!");
Duncan Sands1607f052008-12-01 11:39:25 +00002264
Chris Lattner27a6c732007-11-24 07:07:01 +00002265 // We only lower SRA, SRL of 1 here, all others use generic lowering.
2266 if (!isa<ConstantSDNode>(N->getOperand(1)) ||
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002267 cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1)
Duncan Sands1607f052008-12-01 11:39:25 +00002268 return SDValue();
Bob Wilson2dc4f542009-03-20 22:42:55 +00002269
Chris Lattner27a6c732007-11-24 07:07:01 +00002270 // If we are in thumb mode, we don't have RRX.
David Goodwinf1daf7d2009-07-08 23:10:31 +00002271 if (ST->isThumb1Only()) return SDValue();
Bob Wilson2dc4f542009-03-20 22:42:55 +00002272
Chris Lattner27a6c732007-11-24 07:07:01 +00002273 // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr.
Owen Anderson825b72b2009-08-11 20:47:22 +00002274 SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0),
2275 DAG.getConstant(0, MVT::i32));
2276 SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0),
2277 DAG.getConstant(1, MVT::i32));
Bob Wilson2dc4f542009-03-20 22:42:55 +00002278
Chris Lattner27a6c732007-11-24 07:07:01 +00002279 // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and
2280 // captures the result into a carry flag.
2281 unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG;
Owen Anderson825b72b2009-08-11 20:47:22 +00002282 Hi = DAG.getNode(Opc, dl, DAG.getVTList(MVT::i32, MVT::Flag), &Hi, 1);
Bob Wilson2dc4f542009-03-20 22:42:55 +00002283
Chris Lattner27a6c732007-11-24 07:07:01 +00002284 // The low part is an ARMISD::RRX operand, which shifts the carry in.
Owen Anderson825b72b2009-08-11 20:47:22 +00002285 Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1));
Bob Wilson2dc4f542009-03-20 22:42:55 +00002286
Chris Lattner27a6c732007-11-24 07:07:01 +00002287 // Merge the pieces into a single i64 value.
Owen Anderson825b72b2009-08-11 20:47:22 +00002288 return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi);
Chris Lattner27a6c732007-11-24 07:07:01 +00002289}
2290
Bob Wilson5bafff32009-06-22 23:27:02 +00002291static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) {
2292 SDValue TmpOp0, TmpOp1;
2293 bool Invert = false;
2294 bool Swap = false;
2295 unsigned Opc = 0;
2296
2297 SDValue Op0 = Op.getOperand(0);
2298 SDValue Op1 = Op.getOperand(1);
2299 SDValue CC = Op.getOperand(2);
Owen Andersone50ed302009-08-10 22:56:29 +00002300 EVT VT = Op.getValueType();
Bob Wilson5bafff32009-06-22 23:27:02 +00002301 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
2302 DebugLoc dl = Op.getDebugLoc();
2303
2304 if (Op.getOperand(1).getValueType().isFloatingPoint()) {
2305 switch (SetCCOpcode) {
Torok Edwinc23197a2009-07-14 16:55:14 +00002306 default: llvm_unreachable("Illegal FP comparison"); break;
Bob Wilson5bafff32009-06-22 23:27:02 +00002307 case ISD::SETUNE:
2308 case ISD::SETNE: Invert = true; // Fallthrough
2309 case ISD::SETOEQ:
2310 case ISD::SETEQ: Opc = ARMISD::VCEQ; break;
2311 case ISD::SETOLT:
2312 case ISD::SETLT: Swap = true; // Fallthrough
2313 case ISD::SETOGT:
2314 case ISD::SETGT: Opc = ARMISD::VCGT; break;
2315 case ISD::SETOLE:
2316 case ISD::SETLE: Swap = true; // Fallthrough
2317 case ISD::SETOGE:
2318 case ISD::SETGE: Opc = ARMISD::VCGE; break;
2319 case ISD::SETUGE: Swap = true; // Fallthrough
2320 case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break;
2321 case ISD::SETUGT: Swap = true; // Fallthrough
2322 case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break;
2323 case ISD::SETUEQ: Invert = true; // Fallthrough
2324 case ISD::SETONE:
2325 // Expand this to (OLT | OGT).
2326 TmpOp0 = Op0;
2327 TmpOp1 = Op1;
2328 Opc = ISD::OR;
2329 Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0);
2330 Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1);
2331 break;
2332 case ISD::SETUO: Invert = true; // Fallthrough
2333 case ISD::SETO:
2334 // Expand this to (OLT | OGE).
2335 TmpOp0 = Op0;
2336 TmpOp1 = Op1;
2337 Opc = ISD::OR;
2338 Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0);
2339 Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1);
2340 break;
2341 }
2342 } else {
2343 // Integer comparisons.
2344 switch (SetCCOpcode) {
Torok Edwinc23197a2009-07-14 16:55:14 +00002345 default: llvm_unreachable("Illegal integer comparison"); break;
Bob Wilson5bafff32009-06-22 23:27:02 +00002346 case ISD::SETNE: Invert = true;
2347 case ISD::SETEQ: Opc = ARMISD::VCEQ; break;
2348 case ISD::SETLT: Swap = true;
2349 case ISD::SETGT: Opc = ARMISD::VCGT; break;
2350 case ISD::SETLE: Swap = true;
2351 case ISD::SETGE: Opc = ARMISD::VCGE; break;
2352 case ISD::SETULT: Swap = true;
2353 case ISD::SETUGT: Opc = ARMISD::VCGTU; break;
2354 case ISD::SETULE: Swap = true;
2355 case ISD::SETUGE: Opc = ARMISD::VCGEU; break;
2356 }
2357
Nick Lewycky7f6aa2b2009-07-08 03:04:38 +00002358 // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero).
Bob Wilson5bafff32009-06-22 23:27:02 +00002359 if (Opc == ARMISD::VCEQ) {
2360
2361 SDValue AndOp;
2362 if (ISD::isBuildVectorAllZeros(Op1.getNode()))
2363 AndOp = Op0;
2364 else if (ISD::isBuildVectorAllZeros(Op0.getNode()))
2365 AndOp = Op1;
2366
2367 // Ignore bitconvert.
2368 if (AndOp.getNode() && AndOp.getOpcode() == ISD::BIT_CONVERT)
2369 AndOp = AndOp.getOperand(0);
2370
2371 if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) {
2372 Opc = ARMISD::VTST;
2373 Op0 = DAG.getNode(ISD::BIT_CONVERT, dl, VT, AndOp.getOperand(0));
2374 Op1 = DAG.getNode(ISD::BIT_CONVERT, dl, VT, AndOp.getOperand(1));
2375 Invert = !Invert;
2376 }
2377 }
2378 }
2379
2380 if (Swap)
2381 std::swap(Op0, Op1);
2382
2383 SDValue Result = DAG.getNode(Opc, dl, VT, Op0, Op1);
2384
2385 if (Invert)
2386 Result = DAG.getNOT(dl, Result, VT);
2387
2388 return Result;
2389}
2390
2391/// isVMOVSplat - Check if the specified splat value corresponds to an immediate
2392/// VMOV instruction, and if so, return the constant being splatted.
2393static SDValue isVMOVSplat(uint64_t SplatBits, uint64_t SplatUndef,
2394 unsigned SplatBitSize, SelectionDAG &DAG) {
2395 switch (SplatBitSize) {
2396 case 8:
2397 // Any 1-byte value is OK.
2398 assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big");
Owen Anderson825b72b2009-08-11 20:47:22 +00002399 return DAG.getTargetConstant(SplatBits, MVT::i8);
Bob Wilson5bafff32009-06-22 23:27:02 +00002400
2401 case 16:
2402 // NEON's 16-bit VMOV supports splat values where only one byte is nonzero.
2403 if ((SplatBits & ~0xff) == 0 ||
2404 (SplatBits & ~0xff00) == 0)
Owen Anderson825b72b2009-08-11 20:47:22 +00002405 return DAG.getTargetConstant(SplatBits, MVT::i16);
Bob Wilson5bafff32009-06-22 23:27:02 +00002406 break;
2407
2408 case 32:
2409 // NEON's 32-bit VMOV supports splat values where:
2410 // * only one byte is nonzero, or
2411 // * the least significant byte is 0xff and the second byte is nonzero, or
2412 // * the least significant 2 bytes are 0xff and the third is nonzero.
2413 if ((SplatBits & ~0xff) == 0 ||
2414 (SplatBits & ~0xff00) == 0 ||
2415 (SplatBits & ~0xff0000) == 0 ||
2416 (SplatBits & ~0xff000000) == 0)
Owen Anderson825b72b2009-08-11 20:47:22 +00002417 return DAG.getTargetConstant(SplatBits, MVT::i32);
Bob Wilson5bafff32009-06-22 23:27:02 +00002418
2419 if ((SplatBits & ~0xffff) == 0 &&
2420 ((SplatBits | SplatUndef) & 0xff) == 0xff)
Owen Anderson825b72b2009-08-11 20:47:22 +00002421 return DAG.getTargetConstant(SplatBits | 0xff, MVT::i32);
Bob Wilson5bafff32009-06-22 23:27:02 +00002422
2423 if ((SplatBits & ~0xffffff) == 0 &&
2424 ((SplatBits | SplatUndef) & 0xffff) == 0xffff)
Owen Anderson825b72b2009-08-11 20:47:22 +00002425 return DAG.getTargetConstant(SplatBits | 0xffff, MVT::i32);
Bob Wilson5bafff32009-06-22 23:27:02 +00002426
2427 // Note: there are a few 32-bit splat values (specifically: 00ffff00,
2428 // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not
2429 // VMOV.I32. A (very) minor optimization would be to replicate the value
2430 // and fall through here to test for a valid 64-bit splat. But, then the
2431 // caller would also need to check and handle the change in size.
2432 break;
2433
2434 case 64: {
2435 // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff.
2436 uint64_t BitMask = 0xff;
2437 uint64_t Val = 0;
2438 for (int ByteNum = 0; ByteNum < 8; ++ByteNum) {
2439 if (((SplatBits | SplatUndef) & BitMask) == BitMask)
2440 Val |= BitMask;
2441 else if ((SplatBits & BitMask) != 0)
2442 return SDValue();
2443 BitMask <<= 8;
2444 }
Owen Anderson825b72b2009-08-11 20:47:22 +00002445 return DAG.getTargetConstant(Val, MVT::i64);
Bob Wilson5bafff32009-06-22 23:27:02 +00002446 }
2447
2448 default:
Torok Edwinc23197a2009-07-14 16:55:14 +00002449 llvm_unreachable("unexpected size for isVMOVSplat");
Bob Wilson5bafff32009-06-22 23:27:02 +00002450 break;
2451 }
2452
2453 return SDValue();
2454}
2455
2456/// getVMOVImm - If this is a build_vector of constants which can be
2457/// formed by using a VMOV instruction of the specified element size,
2458/// return the constant being splatted. The ByteSize field indicates the
2459/// number of bytes of each element [1248].
2460SDValue ARM::getVMOVImm(SDNode *N, unsigned ByteSize, SelectionDAG &DAG) {
2461 BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N);
2462 APInt SplatBits, SplatUndef;
2463 unsigned SplatBitSize;
2464 bool HasAnyUndefs;
2465 if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize,
2466 HasAnyUndefs, ByteSize * 8))
2467 return SDValue();
2468
2469 if (SplatBitSize > ByteSize * 8)
2470 return SDValue();
2471
2472 return isVMOVSplat(SplatBits.getZExtValue(), SplatUndef.getZExtValue(),
2473 SplatBitSize, DAG);
2474}
2475
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002476static bool isVEXTMask(const SmallVectorImpl<int> &M, EVT VT,
2477 bool &ReverseVEXT, unsigned &Imm) {
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002478 unsigned NumElts = VT.getVectorNumElements();
2479 ReverseVEXT = false;
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002480 Imm = M[0];
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002481
2482 // If this is a VEXT shuffle, the immediate value is the index of the first
2483 // element. The other shuffle indices must be the successive elements after
2484 // the first one.
2485 unsigned ExpectedElt = Imm;
2486 for (unsigned i = 1; i < NumElts; ++i) {
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002487 // Increment the expected index. If it wraps around, it may still be
2488 // a VEXT but the source vectors must be swapped.
2489 ExpectedElt += 1;
2490 if (ExpectedElt == NumElts * 2) {
2491 ExpectedElt = 0;
2492 ReverseVEXT = true;
2493 }
2494
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002495 if (ExpectedElt != static_cast<unsigned>(M[i]))
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002496 return false;
2497 }
2498
2499 // Adjust the index value if the source operands will be swapped.
2500 if (ReverseVEXT)
2501 Imm -= NumElts;
2502
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002503 return true;
2504}
2505
Bob Wilson8bb9e482009-07-26 00:39:34 +00002506/// isVREVMask - Check if a vector shuffle corresponds to a VREV
2507/// instruction with the specified blocksize. (The order of the elements
2508/// within each block of the vector is reversed.)
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002509static bool isVREVMask(const SmallVectorImpl<int> &M, EVT VT,
2510 unsigned BlockSize) {
Bob Wilson8bb9e482009-07-26 00:39:34 +00002511 assert((BlockSize==16 || BlockSize==32 || BlockSize==64) &&
2512 "Only possible block sizes for VREV are: 16, 32, 64");
2513
Bob Wilson8bb9e482009-07-26 00:39:34 +00002514 unsigned EltSz = VT.getVectorElementType().getSizeInBits();
Bob Wilson20d10812009-10-21 21:36:27 +00002515 if (EltSz == 64)
2516 return false;
2517
2518 unsigned NumElts = VT.getVectorNumElements();
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002519 unsigned BlockElts = M[0] + 1;
Bob Wilson8bb9e482009-07-26 00:39:34 +00002520
2521 if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz)
2522 return false;
2523
2524 for (unsigned i = 0; i < NumElts; ++i) {
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002525 if ((unsigned) M[i] !=
Bob Wilson8bb9e482009-07-26 00:39:34 +00002526 (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts))
2527 return false;
2528 }
2529
2530 return true;
2531}
2532
Bob Wilsonc692cb72009-08-21 20:54:19 +00002533static bool isVTRNMask(const SmallVectorImpl<int> &M, EVT VT,
2534 unsigned &WhichResult) {
Bob Wilson20d10812009-10-21 21:36:27 +00002535 unsigned EltSz = VT.getVectorElementType().getSizeInBits();
2536 if (EltSz == 64)
2537 return false;
2538
Bob Wilsonc692cb72009-08-21 20:54:19 +00002539 unsigned NumElts = VT.getVectorNumElements();
2540 WhichResult = (M[0] == 0 ? 0 : 1);
2541 for (unsigned i = 0; i < NumElts; i += 2) {
2542 if ((unsigned) M[i] != i + WhichResult ||
2543 (unsigned) M[i+1] != i + NumElts + WhichResult)
2544 return false;
2545 }
2546 return true;
2547}
2548
Bob Wilson324f4f12009-12-03 06:40:55 +00002549/// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of
2550/// "vector_shuffle v, v", i.e., "vector_shuffle v, undef".
2551/// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>.
2552static bool isVTRN_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT,
2553 unsigned &WhichResult) {
2554 unsigned EltSz = VT.getVectorElementType().getSizeInBits();
2555 if (EltSz == 64)
2556 return false;
2557
2558 unsigned NumElts = VT.getVectorNumElements();
2559 WhichResult = (M[0] == 0 ? 0 : 1);
2560 for (unsigned i = 0; i < NumElts; i += 2) {
2561 if ((unsigned) M[i] != i + WhichResult ||
2562 (unsigned) M[i+1] != i + WhichResult)
2563 return false;
2564 }
2565 return true;
2566}
2567
Bob Wilsonc692cb72009-08-21 20:54:19 +00002568static bool isVUZPMask(const SmallVectorImpl<int> &M, EVT VT,
2569 unsigned &WhichResult) {
Bob Wilson20d10812009-10-21 21:36:27 +00002570 unsigned EltSz = VT.getVectorElementType().getSizeInBits();
2571 if (EltSz == 64)
2572 return false;
2573
Bob Wilsonc692cb72009-08-21 20:54:19 +00002574 unsigned NumElts = VT.getVectorNumElements();
2575 WhichResult = (M[0] == 0 ? 0 : 1);
2576 for (unsigned i = 0; i != NumElts; ++i) {
2577 if ((unsigned) M[i] != 2 * i + WhichResult)
2578 return false;
2579 }
2580
2581 // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32.
Bob Wilson20d10812009-10-21 21:36:27 +00002582 if (VT.is64BitVector() && EltSz == 32)
Bob Wilsonc692cb72009-08-21 20:54:19 +00002583 return false;
2584
2585 return true;
2586}
2587
Bob Wilson324f4f12009-12-03 06:40:55 +00002588/// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of
2589/// "vector_shuffle v, v", i.e., "vector_shuffle v, undef".
2590/// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>,
2591static bool isVUZP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT,
2592 unsigned &WhichResult) {
2593 unsigned EltSz = VT.getVectorElementType().getSizeInBits();
2594 if (EltSz == 64)
2595 return false;
2596
2597 unsigned Half = VT.getVectorNumElements() / 2;
2598 WhichResult = (M[0] == 0 ? 0 : 1);
2599 for (unsigned j = 0; j != 2; ++j) {
2600 unsigned Idx = WhichResult;
2601 for (unsigned i = 0; i != Half; ++i) {
2602 if ((unsigned) M[i + j * Half] != Idx)
2603 return false;
2604 Idx += 2;
2605 }
2606 }
2607
2608 // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32.
2609 if (VT.is64BitVector() && EltSz == 32)
2610 return false;
2611
2612 return true;
2613}
2614
Bob Wilsonc692cb72009-08-21 20:54:19 +00002615static bool isVZIPMask(const SmallVectorImpl<int> &M, EVT VT,
2616 unsigned &WhichResult) {
Bob Wilson20d10812009-10-21 21:36:27 +00002617 unsigned EltSz = VT.getVectorElementType().getSizeInBits();
2618 if (EltSz == 64)
2619 return false;
2620
Bob Wilsonc692cb72009-08-21 20:54:19 +00002621 unsigned NumElts = VT.getVectorNumElements();
2622 WhichResult = (M[0] == 0 ? 0 : 1);
2623 unsigned Idx = WhichResult * NumElts / 2;
2624 for (unsigned i = 0; i != NumElts; i += 2) {
2625 if ((unsigned) M[i] != Idx ||
2626 (unsigned) M[i+1] != Idx + NumElts)
2627 return false;
2628 Idx += 1;
2629 }
2630
2631 // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32.
Bob Wilson20d10812009-10-21 21:36:27 +00002632 if (VT.is64BitVector() && EltSz == 32)
Bob Wilsonc692cb72009-08-21 20:54:19 +00002633 return false;
2634
2635 return true;
2636}
2637
Bob Wilson324f4f12009-12-03 06:40:55 +00002638/// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of
2639/// "vector_shuffle v, v", i.e., "vector_shuffle v, undef".
2640/// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>.
2641static bool isVZIP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT,
2642 unsigned &WhichResult) {
2643 unsigned EltSz = VT.getVectorElementType().getSizeInBits();
2644 if (EltSz == 64)
2645 return false;
2646
2647 unsigned NumElts = VT.getVectorNumElements();
2648 WhichResult = (M[0] == 0 ? 0 : 1);
2649 unsigned Idx = WhichResult * NumElts / 2;
2650 for (unsigned i = 0; i != NumElts; i += 2) {
2651 if ((unsigned) M[i] != Idx ||
2652 (unsigned) M[i+1] != Idx)
2653 return false;
2654 Idx += 1;
2655 }
2656
2657 // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32.
2658 if (VT.is64BitVector() && EltSz == 32)
2659 return false;
2660
2661 return true;
2662}
2663
2664
Owen Andersone50ed302009-08-10 22:56:29 +00002665static SDValue BuildSplat(SDValue Val, EVT VT, SelectionDAG &DAG, DebugLoc dl) {
Bob Wilson5bafff32009-06-22 23:27:02 +00002666 // Canonicalize all-zeros and all-ones vectors.
Bob Wilsond06791f2009-08-13 01:57:47 +00002667 ConstantSDNode *ConstVal = cast<ConstantSDNode>(Val.getNode());
Bob Wilson5bafff32009-06-22 23:27:02 +00002668 if (ConstVal->isNullValue())
2669 return getZeroVector(VT, DAG, dl);
2670 if (ConstVal->isAllOnesValue())
2671 return getOnesVector(VT, DAG, dl);
2672
Owen Andersone50ed302009-08-10 22:56:29 +00002673 EVT CanonicalVT;
Bob Wilson5bafff32009-06-22 23:27:02 +00002674 if (VT.is64BitVector()) {
2675 switch (Val.getValueType().getSizeInBits()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002676 case 8: CanonicalVT = MVT::v8i8; break;
2677 case 16: CanonicalVT = MVT::v4i16; break;
2678 case 32: CanonicalVT = MVT::v2i32; break;
2679 case 64: CanonicalVT = MVT::v1i64; break;
Torok Edwinc23197a2009-07-14 16:55:14 +00002680 default: llvm_unreachable("unexpected splat element type"); break;
Bob Wilson5bafff32009-06-22 23:27:02 +00002681 }
2682 } else {
2683 assert(VT.is128BitVector() && "unknown splat vector size");
2684 switch (Val.getValueType().getSizeInBits()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002685 case 8: CanonicalVT = MVT::v16i8; break;
2686 case 16: CanonicalVT = MVT::v8i16; break;
2687 case 32: CanonicalVT = MVT::v4i32; break;
2688 case 64: CanonicalVT = MVT::v2i64; break;
Torok Edwinc23197a2009-07-14 16:55:14 +00002689 default: llvm_unreachable("unexpected splat element type"); break;
Bob Wilson5bafff32009-06-22 23:27:02 +00002690 }
2691 }
2692
2693 // Build a canonical splat for this value.
2694 SmallVector<SDValue, 8> Ops;
2695 Ops.assign(CanonicalVT.getVectorNumElements(), Val);
2696 SDValue Res = DAG.getNode(ISD::BUILD_VECTOR, dl, CanonicalVT, &Ops[0],
2697 Ops.size());
2698 return DAG.getNode(ISD::BIT_CONVERT, dl, VT, Res);
2699}
2700
2701// If this is a case we can't handle, return null and let the default
2702// expansion code take care of it.
2703static SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) {
Bob Wilsond06791f2009-08-13 01:57:47 +00002704 BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode());
Bob Wilson5bafff32009-06-22 23:27:02 +00002705 DebugLoc dl = Op.getDebugLoc();
Owen Andersone50ed302009-08-10 22:56:29 +00002706 EVT VT = Op.getValueType();
Bob Wilson5bafff32009-06-22 23:27:02 +00002707
2708 APInt SplatBits, SplatUndef;
2709 unsigned SplatBitSize;
2710 bool HasAnyUndefs;
2711 if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) {
Anton Korobeynikov71624cc2009-08-29 00:08:18 +00002712 if (SplatBitSize <= 64) {
2713 SDValue Val = isVMOVSplat(SplatBits.getZExtValue(),
2714 SplatUndef.getZExtValue(), SplatBitSize, DAG);
2715 if (Val.getNode())
2716 return BuildSplat(Val, VT, DAG, dl);
2717 }
Bob Wilsoncf661e22009-07-30 00:31:25 +00002718 }
2719
2720 // If there are only 2 elements in a 128-bit vector, insert them into an
2721 // undef vector. This handles the common case for 128-bit vector argument
2722 // passing, where the insertions should be translated to subreg accesses
2723 // with no real instructions.
2724 if (VT.is128BitVector() && Op.getNumOperands() == 2) {
2725 SDValue Val = DAG.getUNDEF(VT);
2726 SDValue Op0 = Op.getOperand(0);
2727 SDValue Op1 = Op.getOperand(1);
2728 if (Op0.getOpcode() != ISD::UNDEF)
2729 Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Val, Op0,
2730 DAG.getIntPtrConstant(0));
2731 if (Op1.getOpcode() != ISD::UNDEF)
2732 Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Val, Op1,
2733 DAG.getIntPtrConstant(1));
2734 return Val;
Bob Wilson5bafff32009-06-22 23:27:02 +00002735 }
2736
2737 return SDValue();
2738}
2739
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002740/// isShuffleMaskLegal - Targets can use this to indicate that they only
2741/// support *some* VECTOR_SHUFFLE operations, those with specific masks.
2742/// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
2743/// are assumed to be legal.
2744bool
2745ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M,
2746 EVT VT) const {
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002747 if (VT.getVectorNumElements() == 4 &&
2748 (VT.is128BitVector() || VT.is64BitVector())) {
2749 unsigned PFIndexes[4];
2750 for (unsigned i = 0; i != 4; ++i) {
2751 if (M[i] < 0)
2752 PFIndexes[i] = 8;
2753 else
2754 PFIndexes[i] = M[i];
2755 }
2756
2757 // Compute the index in the perfect shuffle table.
2758 unsigned PFTableIndex =
2759 PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3];
2760 unsigned PFEntry = PerfectShuffleTable[PFTableIndex];
2761 unsigned Cost = (PFEntry >> 30);
2762
2763 if (Cost <= 4)
2764 return true;
2765 }
2766
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002767 bool ReverseVEXT;
Bob Wilsonc692cb72009-08-21 20:54:19 +00002768 unsigned Imm, WhichResult;
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002769
2770 return (ShuffleVectorSDNode::isSplatMask(&M[0], VT) ||
2771 isVREVMask(M, VT, 64) ||
2772 isVREVMask(M, VT, 32) ||
2773 isVREVMask(M, VT, 16) ||
Bob Wilsonc692cb72009-08-21 20:54:19 +00002774 isVEXTMask(M, VT, ReverseVEXT, Imm) ||
2775 isVTRNMask(M, VT, WhichResult) ||
2776 isVUZPMask(M, VT, WhichResult) ||
Bob Wilson324f4f12009-12-03 06:40:55 +00002777 isVZIPMask(M, VT, WhichResult) ||
2778 isVTRN_v_undef_Mask(M, VT, WhichResult) ||
2779 isVUZP_v_undef_Mask(M, VT, WhichResult) ||
2780 isVZIP_v_undef_Mask(M, VT, WhichResult));
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002781}
2782
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002783/// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit
2784/// the specified operations to build the shuffle.
2785static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS,
2786 SDValue RHS, SelectionDAG &DAG,
2787 DebugLoc dl) {
2788 unsigned OpNum = (PFEntry >> 26) & 0x0F;
2789 unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1);
2790 unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1);
2791
2792 enum {
2793 OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3>
2794 OP_VREV,
2795 OP_VDUP0,
2796 OP_VDUP1,
2797 OP_VDUP2,
2798 OP_VDUP3,
2799 OP_VEXT1,
2800 OP_VEXT2,
2801 OP_VEXT3,
2802 OP_VUZPL, // VUZP, left result
2803 OP_VUZPR, // VUZP, right result
2804 OP_VZIPL, // VZIP, left result
2805 OP_VZIPR, // VZIP, right result
2806 OP_VTRNL, // VTRN, left result
2807 OP_VTRNR // VTRN, right result
2808 };
2809
2810 if (OpNum == OP_COPY) {
2811 if (LHSID == (1*9+2)*9+3) return LHS;
2812 assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!");
2813 return RHS;
2814 }
2815
2816 SDValue OpLHS, OpRHS;
2817 OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl);
2818 OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl);
2819 EVT VT = OpLHS.getValueType();
2820
2821 switch (OpNum) {
2822 default: llvm_unreachable("Unknown shuffle opcode!");
2823 case OP_VREV:
2824 return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS);
2825 case OP_VDUP0:
2826 case OP_VDUP1:
2827 case OP_VDUP2:
2828 case OP_VDUP3:
2829 return DAG.getNode(ARMISD::VDUPLANE, dl, VT,
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002830 OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32));
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002831 case OP_VEXT1:
2832 case OP_VEXT2:
2833 case OP_VEXT3:
2834 return DAG.getNode(ARMISD::VEXT, dl, VT,
2835 OpLHS, OpRHS,
2836 DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32));
2837 case OP_VUZPL:
2838 case OP_VUZPR:
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002839 return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT),
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002840 OpLHS, OpRHS).getValue(OpNum-OP_VUZPL);
2841 case OP_VZIPL:
2842 case OP_VZIPR:
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002843 return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT),
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002844 OpLHS, OpRHS).getValue(OpNum-OP_VZIPL);
2845 case OP_VTRNL:
2846 case OP_VTRNR:
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002847 return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT),
2848 OpLHS, OpRHS).getValue(OpNum-OP_VTRNL);
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002849 }
2850}
2851
Bob Wilson5bafff32009-06-22 23:27:02 +00002852static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) {
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002853 SDValue V1 = Op.getOperand(0);
2854 SDValue V2 = Op.getOperand(1);
Bob Wilsond8e17572009-08-12 22:31:50 +00002855 DebugLoc dl = Op.getDebugLoc();
2856 EVT VT = Op.getValueType();
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002857 ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode());
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002858 SmallVector<int, 8> ShuffleMask;
Bob Wilsond8e17572009-08-12 22:31:50 +00002859
Bob Wilson28865062009-08-13 02:13:04 +00002860 // Convert shuffles that are directly supported on NEON to target-specific
2861 // DAG nodes, instead of keeping them as shuffles and matching them again
2862 // during code selection. This is more efficient and avoids the possibility
2863 // of inconsistencies between legalization and selection.
Bob Wilsonbfcbb502009-08-13 06:01:30 +00002864 // FIXME: floating-point vectors should be canonicalized to integer vectors
2865 // of the same time so that they get CSEd properly.
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002866 SVN->getMask(ShuffleMask);
2867
2868 if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) {
Bob Wilson0ce37102009-08-14 05:08:32 +00002869 int Lane = SVN->getSplatIndex();
Anton Korobeynikov2ae0eec2009-11-02 00:12:06 +00002870 // If this is undef splat, generate it via "just" vdup, if possible.
2871 if (Lane == -1) Lane = 0;
2872
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002873 if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) {
2874 return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0));
Bob Wilsonc1d287b2009-08-14 05:13:08 +00002875 }
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002876 return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1,
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002877 DAG.getConstant(Lane, MVT::i32));
Bob Wilson0ce37102009-08-14 05:08:32 +00002878 }
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002879
2880 bool ReverseVEXT;
2881 unsigned Imm;
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002882 if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) {
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002883 if (ReverseVEXT)
Bob Wilsonc692cb72009-08-21 20:54:19 +00002884 std::swap(V1, V2);
2885 return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2,
Bob Wilsonde95c1b82009-08-19 17:03:43 +00002886 DAG.getConstant(Imm, MVT::i32));
2887 }
2888
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002889 if (isVREVMask(ShuffleMask, VT, 64))
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002890 return DAG.getNode(ARMISD::VREV64, dl, VT, V1);
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002891 if (isVREVMask(ShuffleMask, VT, 32))
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002892 return DAG.getNode(ARMISD::VREV32, dl, VT, V1);
Anton Korobeynikovd0ac2342009-08-21 12:40:07 +00002893 if (isVREVMask(ShuffleMask, VT, 16))
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002894 return DAG.getNode(ARMISD::VREV16, dl, VT, V1);
2895
Bob Wilsonc692cb72009-08-21 20:54:19 +00002896 // Check for Neon shuffles that modify both input vectors in place.
2897 // If both results are used, i.e., if there are two shuffles with the same
2898 // source operands and with masks corresponding to both results of one of
2899 // these operations, DAG memoization will ensure that a single node is
2900 // used for both shuffles.
2901 unsigned WhichResult;
2902 if (isVTRNMask(ShuffleMask, VT, WhichResult))
2903 return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT),
2904 V1, V2).getValue(WhichResult);
2905 if (isVUZPMask(ShuffleMask, VT, WhichResult))
2906 return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT),
2907 V1, V2).getValue(WhichResult);
2908 if (isVZIPMask(ShuffleMask, VT, WhichResult))
2909 return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT),
2910 V1, V2).getValue(WhichResult);
2911
Bob Wilson324f4f12009-12-03 06:40:55 +00002912 if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult))
2913 return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT),
2914 V1, V1).getValue(WhichResult);
2915 if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult))
2916 return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT),
2917 V1, V1).getValue(WhichResult);
2918 if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult))
2919 return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT),
2920 V1, V1).getValue(WhichResult);
2921
Bob Wilsonc692cb72009-08-21 20:54:19 +00002922 // If the shuffle is not directly supported and it has 4 elements, use
2923 // the PerfectShuffle-generated table to synthesize it from other shuffles.
Anton Korobeynikov1c8e5812009-08-21 12:41:24 +00002924 if (VT.getVectorNumElements() == 4 &&
2925 (VT.is128BitVector() || VT.is64BitVector())) {
2926 unsigned PFIndexes[4];
2927 for (unsigned i = 0; i != 4; ++i) {
2928 if (ShuffleMask[i] < 0)
2929 PFIndexes[i] = 8;
2930 else
2931 PFIndexes[i] = ShuffleMask[i];
2932 }
2933
2934 // Compute the index in the perfect shuffle table.
2935 unsigned PFTableIndex =
2936 PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3];
2937
2938 unsigned PFEntry = PerfectShuffleTable[PFTableIndex];
2939 unsigned Cost = (PFEntry >> 30);
2940
2941 if (Cost <= 4)
2942 return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl);
2943 }
Bob Wilsond8e17572009-08-12 22:31:50 +00002944
Bob Wilson22cac0d2009-08-14 05:16:33 +00002945 return SDValue();
Bob Wilson5bafff32009-06-22 23:27:02 +00002946}
2947
Bob Wilson5bafff32009-06-22 23:27:02 +00002948static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +00002949 EVT VT = Op.getValueType();
Bob Wilson5bafff32009-06-22 23:27:02 +00002950 DebugLoc dl = Op.getDebugLoc();
Bob Wilson5bafff32009-06-22 23:27:02 +00002951 SDValue Vec = Op.getOperand(0);
2952 SDValue Lane = Op.getOperand(1);
Bob Wilson934f98b2009-10-15 23:12:05 +00002953 assert(VT == MVT::i32 &&
2954 Vec.getValueType().getVectorElementType().getSizeInBits() < 32 &&
2955 "unexpected type for custom-lowering vector extract");
2956 return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane);
Bob Wilson5bafff32009-06-22 23:27:02 +00002957}
2958
Bob Wilsona6d65862009-08-03 20:36:38 +00002959static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) {
2960 // The only time a CONCAT_VECTORS operation can have legal types is when
2961 // two 64-bit vectors are concatenated to a 128-bit vector.
2962 assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 &&
2963 "unexpected CONCAT_VECTORS");
2964 DebugLoc dl = Op.getDebugLoc();
Owen Anderson825b72b2009-08-11 20:47:22 +00002965 SDValue Val = DAG.getUNDEF(MVT::v2f64);
Bob Wilsona6d65862009-08-03 20:36:38 +00002966 SDValue Op0 = Op.getOperand(0);
2967 SDValue Op1 = Op.getOperand(1);
2968 if (Op0.getOpcode() != ISD::UNDEF)
Owen Anderson825b72b2009-08-11 20:47:22 +00002969 Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val,
2970 DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op0),
Bob Wilsona6d65862009-08-03 20:36:38 +00002971 DAG.getIntPtrConstant(0));
2972 if (Op1.getOpcode() != ISD::UNDEF)
Owen Anderson825b72b2009-08-11 20:47:22 +00002973 Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val,
2974 DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op1),
Bob Wilsona6d65862009-08-03 20:36:38 +00002975 DAG.getIntPtrConstant(1));
2976 return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Val);
Bob Wilson5bafff32009-06-22 23:27:02 +00002977}
2978
Dan Gohman475871a2008-07-27 21:46:04 +00002979SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
Evan Chenga8e29892007-01-19 07:51:42 +00002980 switch (Op.getOpcode()) {
Torok Edwinc23197a2009-07-14 16:55:14 +00002981 default: llvm_unreachable("Don't know how to custom lower this!");
Evan Chenga8e29892007-01-19 07:51:42 +00002982 case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
Bob Wilsonddb16df2009-10-30 05:45:42 +00002983 case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00002984 case ISD::GlobalAddress:
2985 return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) :
2986 LowerGlobalAddressELF(Op, DAG);
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00002987 case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
Evan Cheng06b53c02009-11-12 07:13:11 +00002988 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
2989 case ISD::BR_CC: return LowerBR_CC(Op, DAG);
Evan Chenga8e29892007-01-19 07:51:42 +00002990 case ISD::BR_JT: return LowerBR_JT(Op, DAG);
Evan Cheng86198642009-08-07 00:34:42 +00002991 case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG);
Evan Chenga8e29892007-01-19 07:51:42 +00002992 case ISD::VASTART: return LowerVASTART(Op, DAG, VarArgsFrameIndex);
Jim Grosbach3728e962009-12-10 00:11:09 +00002993 case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG);
Evan Chenga8e29892007-01-19 07:51:42 +00002994 case ISD::SINT_TO_FP:
2995 case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG);
2996 case ISD::FP_TO_SINT:
2997 case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG);
2998 case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG);
Nate Begemanbcc5f362007-01-29 22:58:52 +00002999 case ISD::RETURNADDR: break;
Jim Grosbach0e0da732009-05-12 23:59:14 +00003000 case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +00003001 case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG);
Lauro Ramos Venancioe0cb36b2007-11-08 17:20:05 +00003002 case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG);
Duncan Sands1607f052008-12-01 11:39:25 +00003003 case ISD::BIT_CONVERT: return ExpandBIT_CONVERT(Op.getNode(), DAG);
Bob Wilson5bafff32009-06-22 23:27:02 +00003004 case ISD::SHL:
Chris Lattner27a6c732007-11-24 07:07:01 +00003005 case ISD::SRL:
Bob Wilson5bafff32009-06-22 23:27:02 +00003006 case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget);
Evan Cheng06b53c02009-11-12 07:13:11 +00003007 case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG);
Jim Grosbachbcf2f2c2009-10-31 21:42:19 +00003008 case ISD::SRL_PARTS:
Evan Cheng06b53c02009-11-12 07:13:11 +00003009 case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG);
Bob Wilson5bafff32009-06-22 23:27:02 +00003010 case ISD::VSETCC: return LowerVSETCC(Op, DAG);
3011 case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG);
3012 case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG);
Bob Wilson5bafff32009-06-22 23:27:02 +00003013 case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG);
Bob Wilsona6d65862009-08-03 20:36:38 +00003014 case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG);
Evan Chenga8e29892007-01-19 07:51:42 +00003015 }
Dan Gohman475871a2008-07-27 21:46:04 +00003016 return SDValue();
Evan Chenga8e29892007-01-19 07:51:42 +00003017}
3018
Duncan Sands1607f052008-12-01 11:39:25 +00003019/// ReplaceNodeResults - Replace the results of node with an illegal result
3020/// type with new values built out of custom code.
Duncan Sands1607f052008-12-01 11:39:25 +00003021void ARMTargetLowering::ReplaceNodeResults(SDNode *N,
3022 SmallVectorImpl<SDValue>&Results,
3023 SelectionDAG &DAG) {
Chris Lattner27a6c732007-11-24 07:07:01 +00003024 switch (N->getOpcode()) {
Duncan Sands1607f052008-12-01 11:39:25 +00003025 default:
Torok Edwinc23197a2009-07-14 16:55:14 +00003026 llvm_unreachable("Don't know how to custom expand this!");
Duncan Sands1607f052008-12-01 11:39:25 +00003027 return;
3028 case ISD::BIT_CONVERT:
3029 Results.push_back(ExpandBIT_CONVERT(N, DAG));
3030 return;
Chris Lattner27a6c732007-11-24 07:07:01 +00003031 case ISD::SRL:
Duncan Sands1607f052008-12-01 11:39:25 +00003032 case ISD::SRA: {
Bob Wilson5bafff32009-06-22 23:27:02 +00003033 SDValue Res = LowerShift(N, DAG, Subtarget);
Duncan Sands1607f052008-12-01 11:39:25 +00003034 if (Res.getNode())
3035 Results.push_back(Res);
3036 return;
3037 }
Chris Lattner27a6c732007-11-24 07:07:01 +00003038 }
3039}
Chris Lattner27a6c732007-11-24 07:07:01 +00003040
Evan Chenga8e29892007-01-19 07:51:42 +00003041//===----------------------------------------------------------------------===//
3042// ARM Scheduler Hooks
3043//===----------------------------------------------------------------------===//
3044
3045MachineBasicBlock *
Evan Chengff9b3732008-01-30 18:18:23 +00003046ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Evan Chengfb2e7522009-09-18 21:02:19 +00003047 MachineBasicBlock *BB,
3048 DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) const {
Evan Chenga8e29892007-01-19 07:51:42 +00003049 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
Dale Johannesenb6728402009-02-13 02:25:56 +00003050 DebugLoc dl = MI->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00003051 switch (MI->getOpcode()) {
Evan Cheng86198642009-08-07 00:34:42 +00003052 default:
3053 llvm_unreachable("Unexpected instr type to insert");
Evan Cheng007ea272009-08-12 05:17:19 +00003054 case ARM::tMOVCCr_pseudo: {
Evan Chenga8e29892007-01-19 07:51:42 +00003055 // To "insert" a SELECT_CC instruction, we actually have to insert the
3056 // diamond control-flow pattern. The incoming instruction knows the
3057 // destination vreg to set, the condition code register to branch on, the
3058 // true/false values to select between, and a branch opcode to use.
3059 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Dan Gohman8e5f2c62008-07-07 23:14:23 +00003060 MachineFunction::iterator It = BB;
Evan Chenga8e29892007-01-19 07:51:42 +00003061 ++It;
3062
3063 // thisMBB:
3064 // ...
3065 // TrueVal = ...
3066 // cmpTY ccX, r1, r2
3067 // bCC copy1MBB
3068 // fallthrough --> copy0MBB
3069 MachineBasicBlock *thisMBB = BB;
Dan Gohman8e5f2c62008-07-07 23:14:23 +00003070 MachineFunction *F = BB->getParent();
3071 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
3072 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
Dale Johannesenb6728402009-02-13 02:25:56 +00003073 BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB)
Evan Cheng0e1d3792007-07-05 07:18:20 +00003074 .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg());
Dan Gohman8e5f2c62008-07-07 23:14:23 +00003075 F->insert(It, copy0MBB);
3076 F->insert(It, sinkMBB);
Evan Chenga8e29892007-01-19 07:51:42 +00003077 // Update machine-CFG edges by first adding all successors of the current
3078 // block to the new block which will contain the Phi node for the select.
Evan Chengce319102009-09-19 09:51:03 +00003079 // Also inform sdisel of the edge changes.
3080 for (MachineBasicBlock::succ_iterator I = BB->succ_begin(),
3081 E = BB->succ_end(); I != E; ++I) {
3082 EM->insert(std::make_pair(*I, sinkMBB));
3083 sinkMBB->addSuccessor(*I);
3084 }
Evan Chenga8e29892007-01-19 07:51:42 +00003085 // Next, remove all successors of the current block, and add the true
3086 // and fallthrough blocks as its successors.
Evan Chengce319102009-09-19 09:51:03 +00003087 while (!BB->succ_empty())
Evan Chenga8e29892007-01-19 07:51:42 +00003088 BB->removeSuccessor(BB->succ_begin());
3089 BB->addSuccessor(copy0MBB);
3090 BB->addSuccessor(sinkMBB);
3091
3092 // copy0MBB:
3093 // %FalseValue = ...
3094 // # fallthrough to sinkMBB
3095 BB = copy0MBB;
3096
3097 // Update machine-CFG edges
3098 BB->addSuccessor(sinkMBB);
3099
3100 // sinkMBB:
3101 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
3102 // ...
3103 BB = sinkMBB;
Dale Johannesenb6728402009-02-13 02:25:56 +00003104 BuildMI(BB, dl, TII->get(ARM::PHI), MI->getOperand(0).getReg())
Evan Chenga8e29892007-01-19 07:51:42 +00003105 .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
3106 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
3107
Dan Gohman8e5f2c62008-07-07 23:14:23 +00003108 F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
Evan Chenga8e29892007-01-19 07:51:42 +00003109 return BB;
3110 }
Evan Cheng86198642009-08-07 00:34:42 +00003111
3112 case ARM::tANDsp:
3113 case ARM::tADDspr_:
3114 case ARM::tSUBspi_:
3115 case ARM::t2SUBrSPi_:
3116 case ARM::t2SUBrSPi12_:
3117 case ARM::t2SUBrSPs_: {
3118 MachineFunction *MF = BB->getParent();
3119 unsigned DstReg = MI->getOperand(0).getReg();
3120 unsigned SrcReg = MI->getOperand(1).getReg();
3121 bool DstIsDead = MI->getOperand(0).isDead();
3122 bool SrcIsKill = MI->getOperand(1).isKill();
3123
3124 if (SrcReg != ARM::SP) {
3125 // Copy the source to SP from virtual register.
3126 const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(SrcReg);
3127 unsigned CopyOpc = (RC == ARM::tGPRRegisterClass)
3128 ? ARM::tMOVtgpr2gpr : ARM::tMOVgpr2gpr;
3129 BuildMI(BB, dl, TII->get(CopyOpc), ARM::SP)
3130 .addReg(SrcReg, getKillRegState(SrcIsKill));
3131 }
3132
3133 unsigned OpOpc = 0;
3134 bool NeedPred = false, NeedCC = false, NeedOp3 = false;
3135 switch (MI->getOpcode()) {
3136 default:
3137 llvm_unreachable("Unexpected pseudo instruction!");
3138 case ARM::tANDsp:
3139 OpOpc = ARM::tAND;
3140 NeedPred = true;
3141 break;
3142 case ARM::tADDspr_:
3143 OpOpc = ARM::tADDspr;
3144 break;
3145 case ARM::tSUBspi_:
3146 OpOpc = ARM::tSUBspi;
3147 break;
3148 case ARM::t2SUBrSPi_:
3149 OpOpc = ARM::t2SUBrSPi;
3150 NeedPred = true; NeedCC = true;
3151 break;
3152 case ARM::t2SUBrSPi12_:
3153 OpOpc = ARM::t2SUBrSPi12;
3154 NeedPred = true;
3155 break;
3156 case ARM::t2SUBrSPs_:
3157 OpOpc = ARM::t2SUBrSPs;
3158 NeedPred = true; NeedCC = true; NeedOp3 = true;
3159 break;
3160 }
3161 MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(OpOpc), ARM::SP);
3162 if (OpOpc == ARM::tAND)
3163 AddDefaultT1CC(MIB);
3164 MIB.addReg(ARM::SP);
3165 MIB.addOperand(MI->getOperand(2));
3166 if (NeedOp3)
3167 MIB.addOperand(MI->getOperand(3));
3168 if (NeedPred)
3169 AddDefaultPred(MIB);
3170 if (NeedCC)
3171 AddDefaultCC(MIB);
3172
3173 // Copy the result from SP to virtual register.
3174 const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(DstReg);
3175 unsigned CopyOpc = (RC == ARM::tGPRRegisterClass)
3176 ? ARM::tMOVgpr2tgpr : ARM::tMOVgpr2gpr;
3177 BuildMI(BB, dl, TII->get(CopyOpc))
3178 .addReg(DstReg, getDefRegState(true) | getDeadRegState(DstIsDead))
3179 .addReg(ARM::SP);
3180 MF->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
3181 return BB;
3182 }
Evan Chenga8e29892007-01-19 07:51:42 +00003183 }
3184}
3185
3186//===----------------------------------------------------------------------===//
3187// ARM Optimization Hooks
3188//===----------------------------------------------------------------------===//
3189
Chris Lattnerd1980a52009-03-12 06:52:53 +00003190static
3191SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp,
3192 TargetLowering::DAGCombinerInfo &DCI) {
Chris Lattnerd1980a52009-03-12 06:52:53 +00003193 SelectionDAG &DAG = DCI.DAG;
3194 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
Owen Andersone50ed302009-08-10 22:56:29 +00003195 EVT VT = N->getValueType(0);
Chris Lattnerd1980a52009-03-12 06:52:53 +00003196 unsigned Opc = N->getOpcode();
3197 bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC;
3198 SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1);
3199 SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2);
3200 ISD::CondCode CC = ISD::SETCC_INVALID;
3201
3202 if (isSlctCC) {
3203 CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get();
3204 } else {
3205 SDValue CCOp = Slct.getOperand(0);
3206 if (CCOp.getOpcode() == ISD::SETCC)
3207 CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get();
3208 }
3209
3210 bool DoXform = false;
3211 bool InvCC = false;
3212 assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) &&
3213 "Bad input!");
3214
3215 if (LHS.getOpcode() == ISD::Constant &&
3216 cast<ConstantSDNode>(LHS)->isNullValue()) {
3217 DoXform = true;
3218 } else if (CC != ISD::SETCC_INVALID &&
3219 RHS.getOpcode() == ISD::Constant &&
3220 cast<ConstantSDNode>(RHS)->isNullValue()) {
3221 std::swap(LHS, RHS);
3222 SDValue Op0 = Slct.getOperand(0);
Owen Andersone50ed302009-08-10 22:56:29 +00003223 EVT OpVT = isSlctCC ? Op0.getValueType() :
Chris Lattnerd1980a52009-03-12 06:52:53 +00003224 Op0.getOperand(0).getValueType();
3225 bool isInt = OpVT.isInteger();
3226 CC = ISD::getSetCCInverse(CC, isInt);
3227
3228 if (!TLI.isCondCodeLegal(CC, OpVT))
3229 return SDValue(); // Inverse operator isn't legal.
3230
3231 DoXform = true;
3232 InvCC = true;
3233 }
3234
3235 if (DoXform) {
3236 SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS);
3237 if (isSlctCC)
3238 return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result,
3239 Slct.getOperand(0), Slct.getOperand(1), CC);
3240 SDValue CCOp = Slct.getOperand(0);
3241 if (InvCC)
3242 CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(),
3243 CCOp.getOperand(0), CCOp.getOperand(1), CC);
3244 return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT,
3245 CCOp, OtherOp, Result);
3246 }
3247 return SDValue();
3248}
3249
3250/// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD.
3251static SDValue PerformADDCombine(SDNode *N,
3252 TargetLowering::DAGCombinerInfo &DCI) {
3253 // added by evan in r37685 with no testcase.
3254 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Bob Wilson2dc4f542009-03-20 22:42:55 +00003255
Chris Lattnerd1980a52009-03-12 06:52:53 +00003256 // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c))
3257 if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) {
3258 SDValue Result = combineSelectAndUse(N, N0, N1, DCI);
3259 if (Result.getNode()) return Result;
3260 }
3261 if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) {
3262 SDValue Result = combineSelectAndUse(N, N1, N0, DCI);
3263 if (Result.getNode()) return Result;
3264 }
Bob Wilson2dc4f542009-03-20 22:42:55 +00003265
Chris Lattnerd1980a52009-03-12 06:52:53 +00003266 return SDValue();
3267}
3268
3269/// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB.
3270static SDValue PerformSUBCombine(SDNode *N,
3271 TargetLowering::DAGCombinerInfo &DCI) {
3272 // added by evan in r37685 with no testcase.
3273 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Bob Wilson2dc4f542009-03-20 22:42:55 +00003274
Chris Lattnerd1980a52009-03-12 06:52:53 +00003275 // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c))
3276 if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) {
3277 SDValue Result = combineSelectAndUse(N, N1, N0, DCI);
3278 if (Result.getNode()) return Result;
3279 }
Bob Wilson2dc4f542009-03-20 22:42:55 +00003280
Chris Lattnerd1980a52009-03-12 06:52:53 +00003281 return SDValue();
3282}
3283
Jim Grosbache5165492009-11-09 00:11:35 +00003284/// PerformVMOVRRDCombine - Target-specific dag combine xforms for ARMISD::VMOVRRD.
3285static SDValue PerformVMOVRRDCombine(SDNode *N,
Bob Wilson2dc4f542009-03-20 22:42:55 +00003286 TargetLowering::DAGCombinerInfo &DCI) {
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +00003287 // fmrrd(fmdrr x, y) -> x,y
Dan Gohman475871a2008-07-27 21:46:04 +00003288 SDValue InDouble = N->getOperand(0);
Jim Grosbache5165492009-11-09 00:11:35 +00003289 if (InDouble.getOpcode() == ARMISD::VMOVDRR)
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +00003290 return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1));
Dan Gohman475871a2008-07-27 21:46:04 +00003291 return SDValue();
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +00003292}
3293
Bob Wilson5bafff32009-06-22 23:27:02 +00003294/// getVShiftImm - Check if this is a valid build_vector for the immediate
3295/// operand of a vector shift operation, where all the elements of the
3296/// build_vector must have the same constant integer value.
3297static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) {
3298 // Ignore bit_converts.
3299 while (Op.getOpcode() == ISD::BIT_CONVERT)
3300 Op = Op.getOperand(0);
3301 BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode());
3302 APInt SplatBits, SplatUndef;
3303 unsigned SplatBitSize;
3304 bool HasAnyUndefs;
3305 if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize,
3306 HasAnyUndefs, ElementBits) ||
3307 SplatBitSize > ElementBits)
3308 return false;
3309 Cnt = SplatBits.getSExtValue();
3310 return true;
3311}
3312
3313/// isVShiftLImm - Check if this is a valid build_vector for the immediate
3314/// operand of a vector shift left operation. That value must be in the range:
3315/// 0 <= Value < ElementBits for a left shift; or
3316/// 0 <= Value <= ElementBits for a long left shift.
Owen Andersone50ed302009-08-10 22:56:29 +00003317static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) {
Bob Wilson5bafff32009-06-22 23:27:02 +00003318 assert(VT.isVector() && "vector shift count is not a vector type");
3319 unsigned ElementBits = VT.getVectorElementType().getSizeInBits();
3320 if (! getVShiftImm(Op, ElementBits, Cnt))
3321 return false;
3322 return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits);
3323}
3324
3325/// isVShiftRImm - Check if this is a valid build_vector for the immediate
3326/// operand of a vector shift right operation. For a shift opcode, the value
3327/// is positive, but for an intrinsic the value count must be negative. The
3328/// absolute value must be in the range:
3329/// 1 <= |Value| <= ElementBits for a right shift; or
3330/// 1 <= |Value| <= ElementBits/2 for a narrow right shift.
Owen Andersone50ed302009-08-10 22:56:29 +00003331static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic,
Bob Wilson5bafff32009-06-22 23:27:02 +00003332 int64_t &Cnt) {
3333 assert(VT.isVector() && "vector shift count is not a vector type");
3334 unsigned ElementBits = VT.getVectorElementType().getSizeInBits();
3335 if (! getVShiftImm(Op, ElementBits, Cnt))
3336 return false;
3337 if (isIntrinsic)
3338 Cnt = -Cnt;
3339 return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits));
3340}
3341
3342/// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics.
3343static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) {
3344 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3345 switch (IntNo) {
3346 default:
3347 // Don't do anything for most intrinsics.
3348 break;
3349
3350 // Vector shifts: check for immediate versions and lower them.
3351 // Note: This is done during DAG combining instead of DAG legalizing because
3352 // the build_vectors for 64-bit vector element shift counts are generally
3353 // not legal, and it is hard to see their values after they get legalized to
3354 // loads from a constant pool.
3355 case Intrinsic::arm_neon_vshifts:
3356 case Intrinsic::arm_neon_vshiftu:
3357 case Intrinsic::arm_neon_vshiftls:
3358 case Intrinsic::arm_neon_vshiftlu:
3359 case Intrinsic::arm_neon_vshiftn:
3360 case Intrinsic::arm_neon_vrshifts:
3361 case Intrinsic::arm_neon_vrshiftu:
3362 case Intrinsic::arm_neon_vrshiftn:
3363 case Intrinsic::arm_neon_vqshifts:
3364 case Intrinsic::arm_neon_vqshiftu:
3365 case Intrinsic::arm_neon_vqshiftsu:
3366 case Intrinsic::arm_neon_vqshiftns:
3367 case Intrinsic::arm_neon_vqshiftnu:
3368 case Intrinsic::arm_neon_vqshiftnsu:
3369 case Intrinsic::arm_neon_vqrshiftns:
3370 case Intrinsic::arm_neon_vqrshiftnu:
3371 case Intrinsic::arm_neon_vqrshiftnsu: {
Owen Andersone50ed302009-08-10 22:56:29 +00003372 EVT VT = N->getOperand(1).getValueType();
Bob Wilson5bafff32009-06-22 23:27:02 +00003373 int64_t Cnt;
3374 unsigned VShiftOpc = 0;
3375
3376 switch (IntNo) {
3377 case Intrinsic::arm_neon_vshifts:
3378 case Intrinsic::arm_neon_vshiftu:
3379 if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) {
3380 VShiftOpc = ARMISD::VSHL;
3381 break;
3382 }
3383 if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) {
3384 VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ?
3385 ARMISD::VSHRs : ARMISD::VSHRu);
3386 break;
3387 }
3388 return SDValue();
3389
3390 case Intrinsic::arm_neon_vshiftls:
3391 case Intrinsic::arm_neon_vshiftlu:
3392 if (isVShiftLImm(N->getOperand(2), VT, true, Cnt))
3393 break;
Torok Edwinc23197a2009-07-14 16:55:14 +00003394 llvm_unreachable("invalid shift count for vshll intrinsic");
Bob Wilson5bafff32009-06-22 23:27:02 +00003395
3396 case Intrinsic::arm_neon_vrshifts:
3397 case Intrinsic::arm_neon_vrshiftu:
3398 if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt))
3399 break;
3400 return SDValue();
3401
3402 case Intrinsic::arm_neon_vqshifts:
3403 case Intrinsic::arm_neon_vqshiftu:
3404 if (isVShiftLImm(N->getOperand(2), VT, false, Cnt))
3405 break;
3406 return SDValue();
3407
3408 case Intrinsic::arm_neon_vqshiftsu:
3409 if (isVShiftLImm(N->getOperand(2), VT, false, Cnt))
3410 break;
Torok Edwinc23197a2009-07-14 16:55:14 +00003411 llvm_unreachable("invalid shift count for vqshlu intrinsic");
Bob Wilson5bafff32009-06-22 23:27:02 +00003412
3413 case Intrinsic::arm_neon_vshiftn:
3414 case Intrinsic::arm_neon_vrshiftn:
3415 case Intrinsic::arm_neon_vqshiftns:
3416 case Intrinsic::arm_neon_vqshiftnu:
3417 case Intrinsic::arm_neon_vqshiftnsu:
3418 case Intrinsic::arm_neon_vqrshiftns:
3419 case Intrinsic::arm_neon_vqrshiftnu:
3420 case Intrinsic::arm_neon_vqrshiftnsu:
3421 // Narrowing shifts require an immediate right shift.
3422 if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt))
3423 break;
Torok Edwinc23197a2009-07-14 16:55:14 +00003424 llvm_unreachable("invalid shift count for narrowing vector shift intrinsic");
Bob Wilson5bafff32009-06-22 23:27:02 +00003425
3426 default:
Torok Edwinc23197a2009-07-14 16:55:14 +00003427 llvm_unreachable("unhandled vector shift");
Bob Wilson5bafff32009-06-22 23:27:02 +00003428 }
3429
3430 switch (IntNo) {
3431 case Intrinsic::arm_neon_vshifts:
3432 case Intrinsic::arm_neon_vshiftu:
3433 // Opcode already set above.
3434 break;
3435 case Intrinsic::arm_neon_vshiftls:
3436 case Intrinsic::arm_neon_vshiftlu:
3437 if (Cnt == VT.getVectorElementType().getSizeInBits())
3438 VShiftOpc = ARMISD::VSHLLi;
3439 else
3440 VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ?
3441 ARMISD::VSHLLs : ARMISD::VSHLLu);
3442 break;
3443 case Intrinsic::arm_neon_vshiftn:
3444 VShiftOpc = ARMISD::VSHRN; break;
3445 case Intrinsic::arm_neon_vrshifts:
3446 VShiftOpc = ARMISD::VRSHRs; break;
3447 case Intrinsic::arm_neon_vrshiftu:
3448 VShiftOpc = ARMISD::VRSHRu; break;
3449 case Intrinsic::arm_neon_vrshiftn:
3450 VShiftOpc = ARMISD::VRSHRN; break;
3451 case Intrinsic::arm_neon_vqshifts:
3452 VShiftOpc = ARMISD::VQSHLs; break;
3453 case Intrinsic::arm_neon_vqshiftu:
3454 VShiftOpc = ARMISD::VQSHLu; break;
3455 case Intrinsic::arm_neon_vqshiftsu:
3456 VShiftOpc = ARMISD::VQSHLsu; break;
3457 case Intrinsic::arm_neon_vqshiftns:
3458 VShiftOpc = ARMISD::VQSHRNs; break;
3459 case Intrinsic::arm_neon_vqshiftnu:
3460 VShiftOpc = ARMISD::VQSHRNu; break;
3461 case Intrinsic::arm_neon_vqshiftnsu:
3462 VShiftOpc = ARMISD::VQSHRNsu; break;
3463 case Intrinsic::arm_neon_vqrshiftns:
3464 VShiftOpc = ARMISD::VQRSHRNs; break;
3465 case Intrinsic::arm_neon_vqrshiftnu:
3466 VShiftOpc = ARMISD::VQRSHRNu; break;
3467 case Intrinsic::arm_neon_vqrshiftnsu:
3468 VShiftOpc = ARMISD::VQRSHRNsu; break;
3469 }
3470
3471 return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0),
Owen Anderson825b72b2009-08-11 20:47:22 +00003472 N->getOperand(1), DAG.getConstant(Cnt, MVT::i32));
Bob Wilson5bafff32009-06-22 23:27:02 +00003473 }
3474
3475 case Intrinsic::arm_neon_vshiftins: {
Owen Andersone50ed302009-08-10 22:56:29 +00003476 EVT VT = N->getOperand(1).getValueType();
Bob Wilson5bafff32009-06-22 23:27:02 +00003477 int64_t Cnt;
3478 unsigned VShiftOpc = 0;
3479
3480 if (isVShiftLImm(N->getOperand(3), VT, false, Cnt))
3481 VShiftOpc = ARMISD::VSLI;
3482 else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt))
3483 VShiftOpc = ARMISD::VSRI;
3484 else {
Torok Edwinc23197a2009-07-14 16:55:14 +00003485 llvm_unreachable("invalid shift count for vsli/vsri intrinsic");
Bob Wilson5bafff32009-06-22 23:27:02 +00003486 }
3487
3488 return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0),
3489 N->getOperand(1), N->getOperand(2),
Owen Anderson825b72b2009-08-11 20:47:22 +00003490 DAG.getConstant(Cnt, MVT::i32));
Bob Wilson5bafff32009-06-22 23:27:02 +00003491 }
3492
3493 case Intrinsic::arm_neon_vqrshifts:
3494 case Intrinsic::arm_neon_vqrshiftu:
3495 // No immediate versions of these to check for.
3496 break;
3497 }
3498
3499 return SDValue();
3500}
3501
3502/// PerformShiftCombine - Checks for immediate versions of vector shifts and
3503/// lowers them. As with the vector shift intrinsics, this is done during DAG
3504/// combining instead of DAG legalizing because the build_vectors for 64-bit
3505/// vector element shift counts are generally not legal, and it is hard to see
3506/// their values after they get legalized to loads from a constant pool.
3507static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG,
3508 const ARMSubtarget *ST) {
Owen Andersone50ed302009-08-10 22:56:29 +00003509 EVT VT = N->getValueType(0);
Bob Wilson5bafff32009-06-22 23:27:02 +00003510
3511 // Nothing to be done for scalar shifts.
3512 if (! VT.isVector())
3513 return SDValue();
3514
3515 assert(ST->hasNEON() && "unexpected vector shift");
3516 int64_t Cnt;
3517
3518 switch (N->getOpcode()) {
Torok Edwinc23197a2009-07-14 16:55:14 +00003519 default: llvm_unreachable("unexpected shift opcode");
Bob Wilson5bafff32009-06-22 23:27:02 +00003520
3521 case ISD::SHL:
3522 if (isVShiftLImm(N->getOperand(1), VT, false, Cnt))
3523 return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0),
Owen Anderson825b72b2009-08-11 20:47:22 +00003524 DAG.getConstant(Cnt, MVT::i32));
Bob Wilson5bafff32009-06-22 23:27:02 +00003525 break;
3526
3527 case ISD::SRA:
3528 case ISD::SRL:
3529 if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) {
3530 unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ?
3531 ARMISD::VSHRs : ARMISD::VSHRu);
3532 return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0),
Owen Anderson825b72b2009-08-11 20:47:22 +00003533 DAG.getConstant(Cnt, MVT::i32));
Bob Wilson5bafff32009-06-22 23:27:02 +00003534 }
3535 }
3536 return SDValue();
3537}
3538
3539/// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND,
3540/// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND.
3541static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG,
3542 const ARMSubtarget *ST) {
3543 SDValue N0 = N->getOperand(0);
3544
3545 // Check for sign- and zero-extensions of vector extract operations of 8-
3546 // and 16-bit vector elements. NEON supports these directly. They are
3547 // handled during DAG combining because type legalization will promote them
3548 // to 32-bit types and it is messy to recognize the operations after that.
3549 if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
3550 SDValue Vec = N0.getOperand(0);
3551 SDValue Lane = N0.getOperand(1);
Owen Andersone50ed302009-08-10 22:56:29 +00003552 EVT VT = N->getValueType(0);
3553 EVT EltVT = N0.getValueType();
Bob Wilson5bafff32009-06-22 23:27:02 +00003554 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
3555
Owen Anderson825b72b2009-08-11 20:47:22 +00003556 if (VT == MVT::i32 &&
3557 (EltVT == MVT::i8 || EltVT == MVT::i16) &&
Bob Wilson5bafff32009-06-22 23:27:02 +00003558 TLI.isTypeLegal(Vec.getValueType())) {
3559
3560 unsigned Opc = 0;
3561 switch (N->getOpcode()) {
Torok Edwinc23197a2009-07-14 16:55:14 +00003562 default: llvm_unreachable("unexpected opcode");
Bob Wilson5bafff32009-06-22 23:27:02 +00003563 case ISD::SIGN_EXTEND:
3564 Opc = ARMISD::VGETLANEs;
3565 break;
3566 case ISD::ZERO_EXTEND:
3567 case ISD::ANY_EXTEND:
3568 Opc = ARMISD::VGETLANEu;
3569 break;
3570 }
3571 return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane);
3572 }
3573 }
3574
3575 return SDValue();
3576}
3577
Dan Gohman475871a2008-07-27 21:46:04 +00003578SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N,
Bob Wilson2dc4f542009-03-20 22:42:55 +00003579 DAGCombinerInfo &DCI) const {
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +00003580 switch (N->getOpcode()) {
3581 default: break;
Chris Lattnerd1980a52009-03-12 06:52:53 +00003582 case ISD::ADD: return PerformADDCombine(N, DCI);
3583 case ISD::SUB: return PerformSUBCombine(N, DCI);
Jim Grosbache5165492009-11-09 00:11:35 +00003584 case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI);
Bob Wilson5bafff32009-06-22 23:27:02 +00003585 case ISD::INTRINSIC_WO_CHAIN:
3586 return PerformIntrinsicCombine(N, DCI.DAG);
3587 case ISD::SHL:
3588 case ISD::SRA:
3589 case ISD::SRL:
3590 return PerformShiftCombine(N, DCI.DAG, Subtarget);
3591 case ISD::SIGN_EXTEND:
3592 case ISD::ZERO_EXTEND:
3593 case ISD::ANY_EXTEND:
3594 return PerformExtendCombine(N, DCI.DAG, Subtarget);
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +00003595 }
Dan Gohman475871a2008-07-27 21:46:04 +00003596 return SDValue();
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +00003597}
3598
Bill Wendlingaf566342009-08-15 21:21:19 +00003599bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const {
3600 if (!Subtarget->hasV6Ops())
3601 // Pre-v6 does not support unaligned mem access.
3602 return false;
3603 else if (!Subtarget->hasV6Ops()) {
3604 // v6 may or may not support unaligned mem access.
3605 if (!Subtarget->isTargetDarwin())
3606 return false;
3607 }
3608
3609 switch (VT.getSimpleVT().SimpleTy) {
3610 default:
3611 return false;
3612 case MVT::i8:
3613 case MVT::i16:
3614 case MVT::i32:
3615 return true;
3616 // FIXME: VLD1 etc with standard alignment is legal.
3617 }
3618}
3619
Evan Chenge6c835f2009-08-14 20:09:37 +00003620static bool isLegalT1AddressImmediate(int64_t V, EVT VT) {
3621 if (V < 0)
3622 return false;
3623
3624 unsigned Scale = 1;
3625 switch (VT.getSimpleVT().SimpleTy) {
3626 default: return false;
3627 case MVT::i1:
3628 case MVT::i8:
3629 // Scale == 1;
3630 break;
3631 case MVT::i16:
3632 // Scale == 2;
3633 Scale = 2;
3634 break;
3635 case MVT::i32:
3636 // Scale == 4;
3637 Scale = 4;
3638 break;
3639 }
3640
3641 if ((V & (Scale - 1)) != 0)
3642 return false;
3643 V /= Scale;
3644 return V == (V & ((1LL << 5) - 1));
3645}
3646
3647static bool isLegalT2AddressImmediate(int64_t V, EVT VT,
3648 const ARMSubtarget *Subtarget) {
3649 bool isNeg = false;
3650 if (V < 0) {
3651 isNeg = true;
3652 V = - V;
3653 }
3654
3655 switch (VT.getSimpleVT().SimpleTy) {
3656 default: return false;
3657 case MVT::i1:
3658 case MVT::i8:
3659 case MVT::i16:
3660 case MVT::i32:
3661 // + imm12 or - imm8
3662 if (isNeg)
3663 return V == (V & ((1LL << 8) - 1));
3664 return V == (V & ((1LL << 12) - 1));
3665 case MVT::f32:
3666 case MVT::f64:
3667 // Same as ARM mode. FIXME: NEON?
3668 if (!Subtarget->hasVFP2())
3669 return false;
3670 if ((V & 3) != 0)
3671 return false;
3672 V >>= 2;
3673 return V == (V & ((1LL << 8) - 1));
3674 }
3675}
3676
Evan Chengb01fad62007-03-12 23:30:29 +00003677/// isLegalAddressImmediate - Return true if the integer value can be used
3678/// as the offset of the target addressing mode for load / store of the
3679/// given type.
Owen Andersone50ed302009-08-10 22:56:29 +00003680static bool isLegalAddressImmediate(int64_t V, EVT VT,
Chris Lattner37caf8c2007-04-09 23:33:39 +00003681 const ARMSubtarget *Subtarget) {
Evan Cheng961f8792007-03-13 20:37:59 +00003682 if (V == 0)
3683 return true;
3684
Evan Cheng65011532009-03-09 19:15:00 +00003685 if (!VT.isSimple())
3686 return false;
3687
Evan Chenge6c835f2009-08-14 20:09:37 +00003688 if (Subtarget->isThumb1Only())
3689 return isLegalT1AddressImmediate(V, VT);
3690 else if (Subtarget->isThumb2())
3691 return isLegalT2AddressImmediate(V, VT, Subtarget);
Evan Chengb01fad62007-03-12 23:30:29 +00003692
Evan Chenge6c835f2009-08-14 20:09:37 +00003693 // ARM mode.
Evan Chengb01fad62007-03-12 23:30:29 +00003694 if (V < 0)
3695 V = - V;
Owen Anderson825b72b2009-08-11 20:47:22 +00003696 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengb01fad62007-03-12 23:30:29 +00003697 default: return false;
Owen Anderson825b72b2009-08-11 20:47:22 +00003698 case MVT::i1:
3699 case MVT::i8:
3700 case MVT::i32:
Evan Chengb01fad62007-03-12 23:30:29 +00003701 // +- imm12
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +00003702 return V == (V & ((1LL << 12) - 1));
Owen Anderson825b72b2009-08-11 20:47:22 +00003703 case MVT::i16:
Evan Chengb01fad62007-03-12 23:30:29 +00003704 // +- imm8
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +00003705 return V == (V & ((1LL << 8) - 1));
Owen Anderson825b72b2009-08-11 20:47:22 +00003706 case MVT::f32:
3707 case MVT::f64:
Evan Chenge6c835f2009-08-14 20:09:37 +00003708 if (!Subtarget->hasVFP2()) // FIXME: NEON?
Evan Chengb01fad62007-03-12 23:30:29 +00003709 return false;
Evan Cheng0b0a9a92007-05-03 02:00:18 +00003710 if ((V & 3) != 0)
Evan Chengb01fad62007-03-12 23:30:29 +00003711 return false;
3712 V >>= 2;
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +00003713 return V == (V & ((1LL << 8) - 1));
Evan Chengb01fad62007-03-12 23:30:29 +00003714 }
Evan Chenga8e29892007-01-19 07:51:42 +00003715}
3716
Evan Chenge6c835f2009-08-14 20:09:37 +00003717bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM,
3718 EVT VT) const {
3719 int Scale = AM.Scale;
3720 if (Scale < 0)
3721 return false;
3722
3723 switch (VT.getSimpleVT().SimpleTy) {
3724 default: return false;
3725 case MVT::i1:
3726 case MVT::i8:
3727 case MVT::i16:
3728 case MVT::i32:
3729 if (Scale == 1)
3730 return true;
3731 // r + r << imm
3732 Scale = Scale & ~1;
3733 return Scale == 2 || Scale == 4 || Scale == 8;
3734 case MVT::i64:
3735 // r + r
3736 if (((unsigned)AM.HasBaseReg + Scale) <= 2)
3737 return true;
3738 return false;
3739 case MVT::isVoid:
3740 // Note, we allow "void" uses (basically, uses that aren't loads or
3741 // stores), because arm allows folding a scale into many arithmetic
3742 // operations. This should be made more precise and revisited later.
3743
3744 // Allow r << imm, but the imm has to be a multiple of two.
3745 if (Scale & 1) return false;
3746 return isPowerOf2_32(Scale);
3747 }
3748}
3749
Chris Lattner37caf8c2007-04-09 23:33:39 +00003750/// isLegalAddressingMode - Return true if the addressing mode represented
3751/// by AM is legal for this target, for a load/store of the specified type.
Bob Wilson2dc4f542009-03-20 22:42:55 +00003752bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM,
Chris Lattner37caf8c2007-04-09 23:33:39 +00003753 const Type *Ty) const {
Owen Andersone50ed302009-08-10 22:56:29 +00003754 EVT VT = getValueType(Ty, true);
Bob Wilson2c7dab12009-04-08 17:55:28 +00003755 if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget))
Evan Chengb01fad62007-03-12 23:30:29 +00003756 return false;
Bob Wilson2dc4f542009-03-20 22:42:55 +00003757
Chris Lattner37caf8c2007-04-09 23:33:39 +00003758 // Can never fold addr of global into load/store.
Bob Wilson2dc4f542009-03-20 22:42:55 +00003759 if (AM.BaseGV)
Chris Lattner37caf8c2007-04-09 23:33:39 +00003760 return false;
Bob Wilson2dc4f542009-03-20 22:42:55 +00003761
Chris Lattner37caf8c2007-04-09 23:33:39 +00003762 switch (AM.Scale) {
3763 case 0: // no scale reg, must be "r+i" or "r", or "i".
3764 break;
3765 case 1:
Evan Chenge6c835f2009-08-14 20:09:37 +00003766 if (Subtarget->isThumb1Only())
Chris Lattner37caf8c2007-04-09 23:33:39 +00003767 return false;
Chris Lattner5a3d40d2007-04-13 06:50:55 +00003768 // FALL THROUGH.
Chris Lattner37caf8c2007-04-09 23:33:39 +00003769 default:
Chris Lattner5a3d40d2007-04-13 06:50:55 +00003770 // ARM doesn't support any R+R*scale+imm addr modes.
3771 if (AM.BaseOffs)
3772 return false;
Bob Wilson2dc4f542009-03-20 22:42:55 +00003773
Bob Wilson2c7dab12009-04-08 17:55:28 +00003774 if (!VT.isSimple())
3775 return false;
3776
Evan Chenge6c835f2009-08-14 20:09:37 +00003777 if (Subtarget->isThumb2())
3778 return isLegalT2ScaledAddressingMode(AM, VT);
3779
Chris Lattnereb13d1b2007-04-10 03:48:29 +00003780 int Scale = AM.Scale;
Owen Anderson825b72b2009-08-11 20:47:22 +00003781 switch (VT.getSimpleVT().SimpleTy) {
Chris Lattner37caf8c2007-04-09 23:33:39 +00003782 default: return false;
Owen Anderson825b72b2009-08-11 20:47:22 +00003783 case MVT::i1:
3784 case MVT::i8:
3785 case MVT::i32:
Chris Lattnereb13d1b2007-04-10 03:48:29 +00003786 if (Scale < 0) Scale = -Scale;
3787 if (Scale == 1)
Chris Lattner37caf8c2007-04-09 23:33:39 +00003788 return true;
3789 // r + r << imm
Chris Lattnere1152942007-04-11 16:17:12 +00003790 return isPowerOf2_32(Scale & ~1);
Owen Anderson825b72b2009-08-11 20:47:22 +00003791 case MVT::i16:
Evan Chenge6c835f2009-08-14 20:09:37 +00003792 case MVT::i64:
Chris Lattner37caf8c2007-04-09 23:33:39 +00003793 // r + r
Chris Lattnereb13d1b2007-04-10 03:48:29 +00003794 if (((unsigned)AM.HasBaseReg + Scale) <= 2)
Chris Lattner37caf8c2007-04-09 23:33:39 +00003795 return true;
Chris Lattnere1152942007-04-11 16:17:12 +00003796 return false;
Bob Wilson2dc4f542009-03-20 22:42:55 +00003797
Owen Anderson825b72b2009-08-11 20:47:22 +00003798 case MVT::isVoid:
Chris Lattner37caf8c2007-04-09 23:33:39 +00003799 // Note, we allow "void" uses (basically, uses that aren't loads or
3800 // stores), because arm allows folding a scale into many arithmetic
3801 // operations. This should be made more precise and revisited later.
Bob Wilson2dc4f542009-03-20 22:42:55 +00003802
Chris Lattner37caf8c2007-04-09 23:33:39 +00003803 // Allow r << imm, but the imm has to be a multiple of two.
Evan Chenge6c835f2009-08-14 20:09:37 +00003804 if (Scale & 1) return false;
3805 return isPowerOf2_32(Scale);
Chris Lattner37caf8c2007-04-09 23:33:39 +00003806 }
3807 break;
Evan Chengb01fad62007-03-12 23:30:29 +00003808 }
Chris Lattner37caf8c2007-04-09 23:33:39 +00003809 return true;
Evan Chengb01fad62007-03-12 23:30:29 +00003810}
3811
Evan Cheng77e47512009-11-11 19:05:52 +00003812/// isLegalICmpImmediate - Return true if the specified immediate is legal
3813/// icmp immediate, that is the target has icmp instructions which can compare
3814/// a register against the immediate without having to materialize the
3815/// immediate into a register.
Evan Cheng06b53c02009-11-12 07:13:11 +00003816bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const {
Evan Cheng77e47512009-11-11 19:05:52 +00003817 if (!Subtarget->isThumb())
3818 return ARM_AM::getSOImmVal(Imm) != -1;
3819 if (Subtarget->isThumb2())
3820 return ARM_AM::getT2SOImmVal(Imm) != -1;
Evan Cheng06b53c02009-11-12 07:13:11 +00003821 return Imm >= 0 && Imm <= 255;
Evan Cheng77e47512009-11-11 19:05:52 +00003822}
3823
Owen Andersone50ed302009-08-10 22:56:29 +00003824static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT,
Evan Chenge88d5ce2009-07-02 07:28:31 +00003825 bool isSEXTLoad, SDValue &Base,
3826 SDValue &Offset, bool &isInc,
3827 SelectionDAG &DAG) {
Evan Chenga8e29892007-01-19 07:51:42 +00003828 if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB)
3829 return false;
3830
Owen Anderson825b72b2009-08-11 20:47:22 +00003831 if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) {
Evan Chenga8e29892007-01-19 07:51:42 +00003832 // AddressingMode 3
3833 Base = Ptr->getOperand(0);
3834 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00003835 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00003836 if (RHSC < 0 && RHSC > -256) {
Evan Chenge88d5ce2009-07-02 07:28:31 +00003837 assert(Ptr->getOpcode() == ISD::ADD);
Evan Chenga8e29892007-01-19 07:51:42 +00003838 isInc = false;
3839 Offset = DAG.getConstant(-RHSC, RHS->getValueType(0));
3840 return true;
3841 }
3842 }
3843 isInc = (Ptr->getOpcode() == ISD::ADD);
3844 Offset = Ptr->getOperand(1);
3845 return true;
Owen Anderson825b72b2009-08-11 20:47:22 +00003846 } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) {
Evan Chenga8e29892007-01-19 07:51:42 +00003847 // AddressingMode 2
3848 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00003849 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00003850 if (RHSC < 0 && RHSC > -0x1000) {
Evan Chenge88d5ce2009-07-02 07:28:31 +00003851 assert(Ptr->getOpcode() == ISD::ADD);
Evan Chenga8e29892007-01-19 07:51:42 +00003852 isInc = false;
3853 Offset = DAG.getConstant(-RHSC, RHS->getValueType(0));
3854 Base = Ptr->getOperand(0);
3855 return true;
3856 }
3857 }
3858
3859 if (Ptr->getOpcode() == ISD::ADD) {
3860 isInc = true;
3861 ARM_AM::ShiftOpc ShOpcVal= ARM_AM::getShiftOpcForNode(Ptr->getOperand(0));
3862 if (ShOpcVal != ARM_AM::no_shift) {
3863 Base = Ptr->getOperand(1);
3864 Offset = Ptr->getOperand(0);
3865 } else {
3866 Base = Ptr->getOperand(0);
3867 Offset = Ptr->getOperand(1);
3868 }
3869 return true;
3870 }
3871
3872 isInc = (Ptr->getOpcode() == ISD::ADD);
3873 Base = Ptr->getOperand(0);
3874 Offset = Ptr->getOperand(1);
3875 return true;
3876 }
3877
Jim Grosbache5165492009-11-09 00:11:35 +00003878 // FIXME: Use VLDM / VSTM to emulate indexed FP load / store.
Evan Chenga8e29892007-01-19 07:51:42 +00003879 return false;
3880}
3881
Owen Andersone50ed302009-08-10 22:56:29 +00003882static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT,
Evan Chenge88d5ce2009-07-02 07:28:31 +00003883 bool isSEXTLoad, SDValue &Base,
3884 SDValue &Offset, bool &isInc,
3885 SelectionDAG &DAG) {
3886 if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB)
3887 return false;
3888
3889 Base = Ptr->getOperand(0);
3890 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) {
3891 int RHSC = (int)RHS->getZExtValue();
3892 if (RHSC < 0 && RHSC > -0x100) { // 8 bits.
3893 assert(Ptr->getOpcode() == ISD::ADD);
3894 isInc = false;
3895 Offset = DAG.getConstant(-RHSC, RHS->getValueType(0));
3896 return true;
3897 } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero.
3898 isInc = Ptr->getOpcode() == ISD::ADD;
3899 Offset = DAG.getConstant(RHSC, RHS->getValueType(0));
3900 return true;
3901 }
3902 }
3903
3904 return false;
3905}
3906
Evan Chenga8e29892007-01-19 07:51:42 +00003907/// getPreIndexedAddressParts - returns true by value, base pointer and
3908/// offset pointer and addressing mode by reference if the node's address
3909/// can be legally represented as pre-indexed load / store address.
3910bool
Dan Gohman475871a2008-07-27 21:46:04 +00003911ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base,
3912 SDValue &Offset,
Evan Chenga8e29892007-01-19 07:51:42 +00003913 ISD::MemIndexedMode &AM,
Dan Gohman73e09142009-01-15 16:29:45 +00003914 SelectionDAG &DAG) const {
Evan Chenge88d5ce2009-07-02 07:28:31 +00003915 if (Subtarget->isThumb1Only())
Evan Chenga8e29892007-01-19 07:51:42 +00003916 return false;
3917
Owen Andersone50ed302009-08-10 22:56:29 +00003918 EVT VT;
Dan Gohman475871a2008-07-27 21:46:04 +00003919 SDValue Ptr;
Evan Chenga8e29892007-01-19 07:51:42 +00003920 bool isSEXTLoad = false;
3921 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
3922 Ptr = LD->getBasePtr();
Dan Gohmanb625f2f2008-01-30 00:15:11 +00003923 VT = LD->getMemoryVT();
Evan Chenga8e29892007-01-19 07:51:42 +00003924 isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD;
3925 } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
3926 Ptr = ST->getBasePtr();
Dan Gohmanb625f2f2008-01-30 00:15:11 +00003927 VT = ST->getMemoryVT();
Evan Chenga8e29892007-01-19 07:51:42 +00003928 } else
3929 return false;
3930
3931 bool isInc;
Evan Chenge88d5ce2009-07-02 07:28:31 +00003932 bool isLegal = false;
Evan Chenge6c835f2009-08-14 20:09:37 +00003933 if (Subtarget->isThumb2())
Evan Chenge88d5ce2009-07-02 07:28:31 +00003934 isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base,
3935 Offset, isInc, DAG);
Jim Grosbach764ab522009-08-11 15:33:49 +00003936 else
Evan Chenge88d5ce2009-07-02 07:28:31 +00003937 isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base,
Evan Cheng04129572009-07-02 06:44:30 +00003938 Offset, isInc, DAG);
Evan Chenge88d5ce2009-07-02 07:28:31 +00003939 if (!isLegal)
3940 return false;
3941
3942 AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC;
3943 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00003944}
3945
3946/// getPostIndexedAddressParts - returns true by value, base pointer and
3947/// offset pointer and addressing mode by reference if this node can be
3948/// combined with a load / store to form a post-indexed load / store.
3949bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
Dan Gohman475871a2008-07-27 21:46:04 +00003950 SDValue &Base,
3951 SDValue &Offset,
Evan Chenga8e29892007-01-19 07:51:42 +00003952 ISD::MemIndexedMode &AM,
Dan Gohman73e09142009-01-15 16:29:45 +00003953 SelectionDAG &DAG) const {
Evan Chenge88d5ce2009-07-02 07:28:31 +00003954 if (Subtarget->isThumb1Only())
Evan Chenga8e29892007-01-19 07:51:42 +00003955 return false;
3956
Owen Andersone50ed302009-08-10 22:56:29 +00003957 EVT VT;
Dan Gohman475871a2008-07-27 21:46:04 +00003958 SDValue Ptr;
Evan Chenga8e29892007-01-19 07:51:42 +00003959 bool isSEXTLoad = false;
3960 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
Dan Gohmanb625f2f2008-01-30 00:15:11 +00003961 VT = LD->getMemoryVT();
Evan Chenga8e29892007-01-19 07:51:42 +00003962 isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD;
3963 } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Dan Gohmanb625f2f2008-01-30 00:15:11 +00003964 VT = ST->getMemoryVT();
Evan Chenga8e29892007-01-19 07:51:42 +00003965 } else
3966 return false;
3967
3968 bool isInc;
Evan Chenge88d5ce2009-07-02 07:28:31 +00003969 bool isLegal = false;
Evan Chenge6c835f2009-08-14 20:09:37 +00003970 if (Subtarget->isThumb2())
Evan Chenge88d5ce2009-07-02 07:28:31 +00003971 isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset,
Evan Chenga8e29892007-01-19 07:51:42 +00003972 isInc, DAG);
Jim Grosbach764ab522009-08-11 15:33:49 +00003973 else
Evan Chenge88d5ce2009-07-02 07:28:31 +00003974 isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset,
3975 isInc, DAG);
3976 if (!isLegal)
3977 return false;
3978
3979 AM = isInc ? ISD::POST_INC : ISD::POST_DEC;
3980 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00003981}
3982
Dan Gohman475871a2008-07-27 21:46:04 +00003983void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op,
Dan Gohman977a76f2008-02-13 22:28:48 +00003984 const APInt &Mask,
Bob Wilson2dc4f542009-03-20 22:42:55 +00003985 APInt &KnownZero,
Dan Gohmanfd29e0e2008-02-13 00:35:47 +00003986 APInt &KnownOne,
Dan Gohmanea859be2007-06-22 14:59:07 +00003987 const SelectionDAG &DAG,
Evan Chenga8e29892007-01-19 07:51:42 +00003988 unsigned Depth) const {
Dan Gohmanfd29e0e2008-02-13 00:35:47 +00003989 KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0);
Evan Chenga8e29892007-01-19 07:51:42 +00003990 switch (Op.getOpcode()) {
3991 default: break;
3992 case ARMISD::CMOV: {
3993 // Bits are known zero/one if known on the LHS and RHS.
Dan Gohmanea859be2007-06-22 14:59:07 +00003994 DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1);
Evan Chenga8e29892007-01-19 07:51:42 +00003995 if (KnownZero == 0 && KnownOne == 0) return;
3996
Dan Gohmanfd29e0e2008-02-13 00:35:47 +00003997 APInt KnownZeroRHS, KnownOneRHS;
Dan Gohmanea859be2007-06-22 14:59:07 +00003998 DAG.ComputeMaskedBits(Op.getOperand(1), Mask,
3999 KnownZeroRHS, KnownOneRHS, Depth+1);
Evan Chenga8e29892007-01-19 07:51:42 +00004000 KnownZero &= KnownZeroRHS;
4001 KnownOne &= KnownOneRHS;
4002 return;
4003 }
4004 }
4005}
4006
4007//===----------------------------------------------------------------------===//
4008// ARM Inline Assembly Support
4009//===----------------------------------------------------------------------===//
4010
4011/// getConstraintType - Given a constraint letter, return the type of
4012/// constraint it is for this target.
4013ARMTargetLowering::ConstraintType
Chris Lattner4234f572007-03-25 02:14:49 +00004014ARMTargetLowering::getConstraintType(const std::string &Constraint) const {
4015 if (Constraint.size() == 1) {
4016 switch (Constraint[0]) {
4017 default: break;
4018 case 'l': return C_RegisterClass;
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004019 case 'w': return C_RegisterClass;
Chris Lattner4234f572007-03-25 02:14:49 +00004020 }
Evan Chenga8e29892007-01-19 07:51:42 +00004021 }
Chris Lattner4234f572007-03-25 02:14:49 +00004022 return TargetLowering::getConstraintType(Constraint);
Evan Chenga8e29892007-01-19 07:51:42 +00004023}
4024
Bob Wilson2dc4f542009-03-20 22:42:55 +00004025std::pair<unsigned, const TargetRegisterClass*>
Evan Chenga8e29892007-01-19 07:51:42 +00004026ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
Owen Andersone50ed302009-08-10 22:56:29 +00004027 EVT VT) const {
Evan Chenga8e29892007-01-19 07:51:42 +00004028 if (Constraint.size() == 1) {
4029 // GCC RS6000 Constraint Letters
4030 switch (Constraint[0]) {
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004031 case 'l':
David Goodwinf1daf7d2009-07-08 23:10:31 +00004032 if (Subtarget->isThumb1Only())
Jim Grosbach30eae3c2009-04-07 20:34:09 +00004033 return std::make_pair(0U, ARM::tGPRRegisterClass);
4034 else
4035 return std::make_pair(0U, ARM::GPRRegisterClass);
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004036 case 'r':
4037 return std::make_pair(0U, ARM::GPRRegisterClass);
4038 case 'w':
Owen Anderson825b72b2009-08-11 20:47:22 +00004039 if (VT == MVT::f32)
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004040 return std::make_pair(0U, ARM::SPRRegisterClass);
Owen Anderson825b72b2009-08-11 20:47:22 +00004041 if (VT == MVT::f64)
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004042 return std::make_pair(0U, ARM::DPRRegisterClass);
Evan Chengd831cda2009-12-08 23:06:22 +00004043 if (VT.getSizeInBits() == 128)
4044 return std::make_pair(0U, ARM::QPRRegisterClass);
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004045 break;
Evan Chenga8e29892007-01-19 07:51:42 +00004046 }
4047 }
4048 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
4049}
4050
4051std::vector<unsigned> ARMTargetLowering::
4052getRegClassForInlineAsmConstraint(const std::string &Constraint,
Owen Andersone50ed302009-08-10 22:56:29 +00004053 EVT VT) const {
Evan Chenga8e29892007-01-19 07:51:42 +00004054 if (Constraint.size() != 1)
4055 return std::vector<unsigned>();
4056
4057 switch (Constraint[0]) { // GCC ARM Constraint Letters
4058 default: break;
4059 case 'l':
Jim Grosbach30eae3c2009-04-07 20:34:09 +00004060 return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3,
4061 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
4062 0);
Evan Chenga8e29892007-01-19 07:51:42 +00004063 case 'r':
4064 return make_vector<unsigned>(ARM::R0, ARM::R1, ARM::R2, ARM::R3,
4065 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
4066 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
4067 ARM::R12, ARM::LR, 0);
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004068 case 'w':
Owen Anderson825b72b2009-08-11 20:47:22 +00004069 if (VT == MVT::f32)
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004070 return make_vector<unsigned>(ARM::S0, ARM::S1, ARM::S2, ARM::S3,
4071 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
4072 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
4073 ARM::S12,ARM::S13,ARM::S14,ARM::S15,
4074 ARM::S16,ARM::S17,ARM::S18,ARM::S19,
4075 ARM::S20,ARM::S21,ARM::S22,ARM::S23,
4076 ARM::S24,ARM::S25,ARM::S26,ARM::S27,
4077 ARM::S28,ARM::S29,ARM::S30,ARM::S31, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +00004078 if (VT == MVT::f64)
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004079 return make_vector<unsigned>(ARM::D0, ARM::D1, ARM::D2, ARM::D3,
4080 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
4081 ARM::D8, ARM::D9, ARM::D10,ARM::D11,
4082 ARM::D12,ARM::D13,ARM::D14,ARM::D15, 0);
Evan Chengd831cda2009-12-08 23:06:22 +00004083 if (VT.getSizeInBits() == 128)
4084 return make_vector<unsigned>(ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
4085 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7, 0);
Chris Lattnerc4e3f8e2007-04-02 17:24:08 +00004086 break;
Evan Chenga8e29892007-01-19 07:51:42 +00004087 }
4088
4089 return std::vector<unsigned>();
4090}
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004091
4092/// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
4093/// vector. If it is invalid, don't add anything to Ops.
4094void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
4095 char Constraint,
4096 bool hasMemory,
4097 std::vector<SDValue>&Ops,
4098 SelectionDAG &DAG) const {
4099 SDValue Result(0, 0);
4100
4101 switch (Constraint) {
4102 default: break;
4103 case 'I': case 'J': case 'K': case 'L':
4104 case 'M': case 'N': case 'O':
4105 ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op);
4106 if (!C)
4107 return;
4108
4109 int64_t CVal64 = C->getSExtValue();
4110 int CVal = (int) CVal64;
4111 // None of these constraints allow values larger than 32 bits. Check
4112 // that the value fits in an int.
4113 if (CVal != CVal64)
4114 return;
4115
4116 switch (Constraint) {
4117 case 'I':
David Goodwinf1daf7d2009-07-08 23:10:31 +00004118 if (Subtarget->isThumb1Only()) {
4119 // This must be a constant between 0 and 255, for ADD
4120 // immediates.
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004121 if (CVal >= 0 && CVal <= 255)
4122 break;
David Goodwinf1daf7d2009-07-08 23:10:31 +00004123 } else if (Subtarget->isThumb2()) {
4124 // A constant that can be used as an immediate value in a
4125 // data-processing instruction.
4126 if (ARM_AM::getT2SOImmVal(CVal) != -1)
4127 break;
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004128 } else {
4129 // A constant that can be used as an immediate value in a
4130 // data-processing instruction.
4131 if (ARM_AM::getSOImmVal(CVal) != -1)
4132 break;
4133 }
4134 return;
4135
4136 case 'J':
David Goodwinf1daf7d2009-07-08 23:10:31 +00004137 if (Subtarget->isThumb()) { // FIXME thumb2
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004138 // This must be a constant between -255 and -1, for negated ADD
4139 // immediates. This can be used in GCC with an "n" modifier that
4140 // prints the negated value, for use with SUB instructions. It is
4141 // not useful otherwise but is implemented for compatibility.
4142 if (CVal >= -255 && CVal <= -1)
4143 break;
4144 } else {
4145 // This must be a constant between -4095 and 4095. It is not clear
4146 // what this constraint is intended for. Implemented for
4147 // compatibility with GCC.
4148 if (CVal >= -4095 && CVal <= 4095)
4149 break;
4150 }
4151 return;
4152
4153 case 'K':
David Goodwinf1daf7d2009-07-08 23:10:31 +00004154 if (Subtarget->isThumb1Only()) {
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004155 // A 32-bit value where only one byte has a nonzero value. Exclude
4156 // zero to match GCC. This constraint is used by GCC internally for
4157 // constants that can be loaded with a move/shift combination.
4158 // It is not useful otherwise but is implemented for compatibility.
4159 if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal))
4160 break;
David Goodwinf1daf7d2009-07-08 23:10:31 +00004161 } else if (Subtarget->isThumb2()) {
4162 // A constant whose bitwise inverse can be used as an immediate
4163 // value in a data-processing instruction. This can be used in GCC
4164 // with a "B" modifier that prints the inverted value, for use with
4165 // BIC and MVN instructions. It is not useful otherwise but is
4166 // implemented for compatibility.
4167 if (ARM_AM::getT2SOImmVal(~CVal) != -1)
4168 break;
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004169 } else {
4170 // A constant whose bitwise inverse can be used as an immediate
4171 // value in a data-processing instruction. This can be used in GCC
4172 // with a "B" modifier that prints the inverted value, for use with
4173 // BIC and MVN instructions. It is not useful otherwise but is
4174 // implemented for compatibility.
4175 if (ARM_AM::getSOImmVal(~CVal) != -1)
4176 break;
4177 }
4178 return;
4179
4180 case 'L':
David Goodwinf1daf7d2009-07-08 23:10:31 +00004181 if (Subtarget->isThumb1Only()) {
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004182 // This must be a constant between -7 and 7,
4183 // for 3-operand ADD/SUB immediate instructions.
4184 if (CVal >= -7 && CVal < 7)
4185 break;
David Goodwinf1daf7d2009-07-08 23:10:31 +00004186 } else if (Subtarget->isThumb2()) {
4187 // A constant whose negation can be used as an immediate value in a
4188 // data-processing instruction. This can be used in GCC with an "n"
4189 // modifier that prints the negated value, for use with SUB
4190 // instructions. It is not useful otherwise but is implemented for
4191 // compatibility.
4192 if (ARM_AM::getT2SOImmVal(-CVal) != -1)
4193 break;
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004194 } else {
4195 // A constant whose negation can be used as an immediate value in a
4196 // data-processing instruction. This can be used in GCC with an "n"
4197 // modifier that prints the negated value, for use with SUB
4198 // instructions. It is not useful otherwise but is implemented for
4199 // compatibility.
4200 if (ARM_AM::getSOImmVal(-CVal) != -1)
4201 break;
4202 }
4203 return;
4204
4205 case 'M':
David Goodwinf1daf7d2009-07-08 23:10:31 +00004206 if (Subtarget->isThumb()) { // FIXME thumb2
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004207 // This must be a multiple of 4 between 0 and 1020, for
4208 // ADD sp + immediate.
4209 if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0))
4210 break;
4211 } else {
4212 // A power of two or a constant between 0 and 32. This is used in
4213 // GCC for the shift amount on shifted register operands, but it is
4214 // useful in general for any shift amounts.
4215 if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0))
4216 break;
4217 }
4218 return;
4219
4220 case 'N':
David Goodwinf1daf7d2009-07-08 23:10:31 +00004221 if (Subtarget->isThumb()) { // FIXME thumb2
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004222 // This must be a constant between 0 and 31, for shift amounts.
4223 if (CVal >= 0 && CVal <= 31)
4224 break;
4225 }
4226 return;
4227
4228 case 'O':
David Goodwinf1daf7d2009-07-08 23:10:31 +00004229 if (Subtarget->isThumb()) { // FIXME thumb2
Bob Wilsonbf6396b2009-04-01 17:58:54 +00004230 // This must be a multiple of 4 between -508 and 508, for
4231 // ADD/SUB sp = sp + immediate.
4232 if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0))
4233 break;
4234 }
4235 return;
4236 }
4237 Result = DAG.getTargetConstant(CVal, Op.getValueType());
4238 break;
4239 }
4240
4241 if (Result.getNode()) {
4242 Ops.push_back(Result);
4243 return;
4244 }
4245 return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, hasMemory,
4246 Ops, DAG);
4247}
Anton Korobeynikov48e19352009-09-23 19:04:09 +00004248
4249bool
4250ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
4251 // The ARM target isn't yet aware of offsets.
4252 return false;
4253}
Evan Cheng39382422009-10-28 01:44:26 +00004254
4255int ARM::getVFPf32Imm(const APFloat &FPImm) {
4256 APInt Imm = FPImm.bitcastToAPInt();
4257 uint32_t Sign = Imm.lshr(31).getZExtValue() & 1;
4258 int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127
4259 int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits
4260
4261 // We can handle 4 bits of mantissa.
4262 // mantissa = (16+UInt(e:f:g:h))/16.
4263 if (Mantissa & 0x7ffff)
4264 return -1;
4265 Mantissa >>= 19;
4266 if ((Mantissa & 0xf) != Mantissa)
4267 return -1;
4268
4269 // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3
4270 if (Exp < -3 || Exp > 4)
4271 return -1;
4272 Exp = ((Exp+3) & 0x7) ^ 4;
4273
4274 return ((int)Sign << 7) | (Exp << 4) | Mantissa;
4275}
4276
4277int ARM::getVFPf64Imm(const APFloat &FPImm) {
4278 APInt Imm = FPImm.bitcastToAPInt();
4279 uint64_t Sign = Imm.lshr(63).getZExtValue() & 1;
4280 int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023
4281 uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffLL;
4282
4283 // We can handle 4 bits of mantissa.
4284 // mantissa = (16+UInt(e:f:g:h))/16.
4285 if (Mantissa & 0xffffffffffffLL)
4286 return -1;
4287 Mantissa >>= 48;
4288 if ((Mantissa & 0xf) != Mantissa)
4289 return -1;
4290
4291 // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3
4292 if (Exp < -3 || Exp > 4)
4293 return -1;
4294 Exp = ((Exp+3) & 0x7) ^ 4;
4295
4296 return ((int)Sign << 7) | (Exp << 4) | Mantissa;
4297}
4298
4299/// isFPImmLegal - Returns true if the target can instruction select the
4300/// specified FP immediate natively. If false, the legalizer will
4301/// materialize the FP immediate as a load from a constant pool.
4302bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
4303 if (!Subtarget->hasVFP3())
4304 return false;
4305 if (VT == MVT::f32)
4306 return ARM::getVFPf32Imm(Imm) != -1;
4307 if (VT == MVT::f64)
4308 return ARM::getVFPf64Imm(Imm) != -1;
4309 return false;
4310}