blob: 305d23cf58a75d0be1768343c2c910a2af726da1 [file] [log] [blame]
Evan Cheng10043e22007-01-19 07:51:42 +00001//===-- ARMISelLowering.h - ARM DAG Lowering Interface ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Cheng10043e22007-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#ifndef ARMISELLOWERING_H
16#define ARMISELLOWERING_H
17
Craig Toppera9253262014-03-22 23:51:00 +000018#include "MCTargetDesc/ARMBaseInfo.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000019#include "llvm/CodeGen/CallingConvLower.h"
Evan Cheng10043e22007-01-19 07:51:42 +000020#include "llvm/CodeGen/SelectionDAG.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000021#include "llvm/Target/TargetLowering.h"
Evan Cheng10043e22007-01-19 07:51:42 +000022#include <vector>
23
24namespace llvm {
25 class ARMConstantPoolValue;
Craig Toppera9253262014-03-22 23:51:00 +000026 class ARMSubtarget;
Evan Cheng10043e22007-01-19 07:51:42 +000027
28 namespace ARMISD {
29 // ARM Specific DAG Nodes
30 enum NodeType {
Jim Grosbach91fa7812009-05-13 22:32:43 +000031 // Start the numbering where the builtin ops and target ops leave off.
Dan Gohmaned1cf1a2008-09-23 18:42:32 +000032 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Evan Cheng10043e22007-01-19 07:51:42 +000033
34 Wrapper, // Wrapper - A wrapper node for TargetConstantPool,
35 // TargetExternalSymbol, and TargetGlobalAddress.
Evan Chengdfce83c2011-01-17 08:03:18 +000036 WrapperPIC, // WrapperPIC - A wrapper node for TargetGlobalAddress in
37 // PIC mode.
Evan Cheng10043e22007-01-19 07:51:42 +000038 WrapperJT, // WrapperJT - A wrapper node for TargetJumpTable
Jim Grosbach91fa7812009-05-13 22:32:43 +000039
Manman Ren9f911162012-06-01 02:44:42 +000040 // Add pseudo op to model memcpy for struct byval.
41 COPY_STRUCT_BYVAL,
42
Evan Cheng10043e22007-01-19 07:51:42 +000043 CALL, // Function call.
Evan Chengc3c949b42007-06-19 21:05:09 +000044 CALL_PRED, // Function call that's predicable.
Evan Cheng10043e22007-01-19 07:51:42 +000045 CALL_NOLINK, // Function call with branch not branch-and-link.
46 tCALL, // Thumb function call.
47 BRCOND, // Conditional branch.
48 BR_JT, // Jumptable branch.
Evan Chengc6d70ae2009-07-29 02:18:14 +000049 BR2_JT, // Jumptable branch (2 level - jumptable entry is a jump).
Evan Cheng10043e22007-01-19 07:51:42 +000050 RET_FLAG, // Return with a flag operand.
Tim Northoverd8407452013-10-01 14:33:28 +000051 INTRET_FLAG, // Interrupt return with an LR-offset and a flag operand.
Evan Cheng10043e22007-01-19 07:51:42 +000052
53 PIC_ADD, // Add with a PC operand and a PIC label.
54
55 CMP, // ARM compare instructions.
Bill Wendling4b796472012-06-11 08:07:26 +000056 CMN, // ARM CMN instructions.
David Goodwindbf11ba2009-06-29 15:33:01 +000057 CMPZ, // ARM compare that sets only Z flag.
Evan Cheng10043e22007-01-19 07:51:42 +000058 CMPFP, // ARM VFP compare instruction, sets FPSCR.
59 CMPFPw0, // ARM VFP compare against zero instruction, sets FPSCR.
60 FMSTAT, // ARM fmstat instruction.
Evan Chenge87681c2012-02-23 01:19:06 +000061
Evan Cheng10043e22007-01-19 07:51:42 +000062 CMOV, // ARM conditional move instructions.
Jim Grosbach91fa7812009-05-13 22:32:43 +000063
Evan Cheng0cc4ad92010-07-13 19:27:42 +000064 BCC_i64,
65
Jim Grosbach8546ec92010-01-18 19:58:49 +000066 RBIT, // ARM bitreverse instruction
67
Bob Wilsone4191e72010-03-19 22:51:32 +000068 FTOSI, // FP to sint within a FP register.
69 FTOUI, // FP to uint within a FP register.
70 SITOF, // sint to FP within a FP register.
71 UITOF, // uint to FP within a FP register.
72
Evan Cheng10043e22007-01-19 07:51:42 +000073 SRL_FLAG, // V,Flag = srl_flag X -> srl X, 1 + save carry out.
74 SRA_FLAG, // V,Flag = sra_flag X -> sra X, 1 + save carry out.
75 RRX, // V = RRX X, Flag -> srl X, 1 + shift in carry flag.
Jim Grosbach91fa7812009-05-13 22:32:43 +000076
Evan Chenge8916542011-08-30 01:34:54 +000077 ADDC, // Add with carry
78 ADDE, // Add using carry
79 SUBC, // Sub with carry
80 SUBE, // Sub using carry
81
Jim Grosbachd7cf55c2009-11-09 00:11:35 +000082 VMOVRRD, // double to two gprs.
83 VMOVDRR, // Two gprs to double.
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000084
Jim Grosbachbbdc5d22010-10-19 23:27:08 +000085 EH_SJLJ_SETJMP, // SjLj exception handling setjmp.
86 EH_SJLJ_LONGJMP, // SjLj exception handling longjmp.
Jim Grosbachaeca45d2009-05-12 23:59:14 +000087
Dale Johannesend679ff72010-06-03 21:09:53 +000088 TC_RETURN, // Tail call return pseudo.
89
Bob Wilson2e076c42009-06-22 23:27:02 +000090 THREAD_POINTER,
91
Evan Chengb972e562009-08-07 00:34:42 +000092 DYN_ALLOC, // Dynamic allocation on the stack.
93
Bob Wilson7ed59712010-10-30 00:54:37 +000094 MEMBARRIER_MCR, // Memory barrier (MCR)
Evan Cheng8740ee32010-11-03 06:34:55 +000095
96 PRELOAD, // Preload
Andrew Trick1a1f8d42011-04-23 03:24:11 +000097
Bob Wilson2e076c42009-06-22 23:27:02 +000098 VCEQ, // Vector compare equal.
Owen Andersonc7baee32010-11-08 23:21:22 +000099 VCEQZ, // Vector compare equal to zero.
Bob Wilson2e076c42009-06-22 23:27:02 +0000100 VCGE, // Vector compare greater than or equal.
Owen Andersonc7baee32010-11-08 23:21:22 +0000101 VCGEZ, // Vector compare greater than or equal to zero.
102 VCLEZ, // Vector compare less than or equal to zero.
Bob Wilson2e076c42009-06-22 23:27:02 +0000103 VCGEU, // Vector compare unsigned greater than or equal.
104 VCGT, // Vector compare greater than.
Owen Andersonc7baee32010-11-08 23:21:22 +0000105 VCGTZ, // Vector compare greater than zero.
106 VCLTZ, // Vector compare less than zero.
Bob Wilson2e076c42009-06-22 23:27:02 +0000107 VCGTU, // Vector compare unsigned greater than.
108 VTST, // Vector test bits.
109
110 // Vector shift by immediate:
111 VSHL, // ...left
112 VSHRs, // ...right (signed)
113 VSHRu, // ...right (unsigned)
Bob Wilson2e076c42009-06-22 23:27:02 +0000114
115 // Vector rounding shift by immediate:
116 VRSHRs, // ...right (signed)
117 VRSHRu, // ...right (unsigned)
118 VRSHRN, // ...right narrow
119
120 // Vector saturating shift by immediate:
121 VQSHLs, // ...left (signed)
122 VQSHLu, // ...left (unsigned)
123 VQSHLsu, // ...left (signed to unsigned)
124 VQSHRNs, // ...right narrow (signed)
125 VQSHRNu, // ...right narrow (unsigned)
126 VQSHRNsu, // ...right narrow (signed to unsigned)
127
128 // Vector saturating rounding shift by immediate:
129 VQRSHRNs, // ...right narrow (signed)
130 VQRSHRNu, // ...right narrow (unsigned)
131 VQRSHRNsu, // ...right narrow (signed to unsigned)
132
133 // Vector shift and insert:
134 VSLI, // ...left
135 VSRI, // ...right
136
137 // Vector get lane (VMOV scalar to ARM core register)
138 // (These are used for 8- and 16-bit element types only.)
139 VGETLANEu, // zero-extend vector extract element
140 VGETLANEs, // sign-extend vector extract element
141
Bob Wilsonbad47f62010-07-14 06:31:50 +0000142 // Vector move immediate and move negated immediate:
Bob Wilsona3f19012010-07-13 21:16:48 +0000143 VMOVIMM,
Bob Wilsonbad47f62010-07-14 06:31:50 +0000144 VMVNIMM,
145
Evan Cheng7ca4b6e2011-11-15 02:12:34 +0000146 // Vector move f32 immediate:
147 VMOVFPIMM,
148
Bob Wilsonbad47f62010-07-14 06:31:50 +0000149 // Vector duplicate:
Bob Wilsoneb54d512009-08-14 05:13:08 +0000150 VDUP,
Bob Wilsoncce31f62009-08-14 05:08:32 +0000151 VDUPLANE,
Bob Wilsonf45dee32009-08-04 00:36:16 +0000152
Bob Wilsonea3a4022009-08-12 22:31:50 +0000153 // Vector shuffles:
Bob Wilson32cd8552009-08-19 17:03:43 +0000154 VEXT, // extract
Bob Wilsonea3a4022009-08-12 22:31:50 +0000155 VREV64, // reverse elements within 64-bit doublewords
156 VREV32, // reverse elements within 32-bit words
Anton Korobeynikov9a232f42009-08-21 12:41:24 +0000157 VREV16, // reverse elements within 16-bit halfwords
Bob Wilsona7062312009-08-21 20:54:19 +0000158 VZIP, // zip (interleave)
159 VUZP, // unzip (deinterleave)
Bob Wilsonc6c13a32010-02-18 06:05:53 +0000160 VTRN, // transpose
Bill Wendlinge1fd78f2011-03-14 23:02:38 +0000161 VTBL1, // 1-register shuffle with mask
162 VTBL2, // 2-register shuffle with mask
Bob Wilsonc6c13a32010-02-18 06:05:53 +0000163
Bob Wilson38ab35a2010-09-01 23:50:19 +0000164 // Vector multiply long:
165 VMULLs, // ...signed
166 VMULLu, // ...unsigned
167
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +0000168 UMLAL, // 64bit Unsigned Accumulate Multiply
169 SMLAL, // 64bit Signed Accumulate Multiply
170
Bob Wilsond8a9a042010-06-04 00:04:02 +0000171 // Operands of the standard BUILD_VECTOR node are not legalized, which
172 // is fine if BUILD_VECTORs are always lowered to shuffles or other
173 // operations, but for ARM some BUILD_VECTORs are legal as-is and their
174 // operands need to be legalized. Define an ARM-specific version of
175 // BUILD_VECTOR for this purpose.
176 BUILD_VECTOR,
177
Bob Wilsonc6c13a32010-02-18 06:05:53 +0000178 // Floating-point max and min:
179 FMAX,
Jim Grosbach11013ed2010-07-16 23:05:05 +0000180 FMIN,
Joey Goulye3dd6842013-08-23 12:01:13 +0000181 VMAXNM,
182 VMINNM,
Jim Grosbach11013ed2010-07-16 23:05:05 +0000183
184 // Bit-field insert
Owen Anderson07473072010-11-03 22:44:51 +0000185 BFI,
Andrew Trick1a1f8d42011-04-23 03:24:11 +0000186
Owen Anderson07473072010-11-03 22:44:51 +0000187 // Vector OR with immediate
Owen Anderson30c48922010-11-05 19:27:46 +0000188 VORRIMM,
189 // Vector AND with NOT of immediate
Bob Wilson2d790df2010-11-28 06:51:26 +0000190 VBICIMM,
191
Cameron Zwarich53dd03d2011-03-30 23:01:21 +0000192 // Vector bitwise select
193 VBSL,
194
Bob Wilson2d790df2010-11-28 06:51:26 +0000195 // Vector load N-element structure to all lanes:
196 VLD2DUP = ISD::FIRST_TARGET_MEMORY_OPCODE,
197 VLD3DUP,
Bob Wilson06fce872011-02-07 17:43:21 +0000198 VLD4DUP,
199
200 // NEON loads with post-increment base updates:
201 VLD1_UPD,
202 VLD2_UPD,
203 VLD3_UPD,
204 VLD4_UPD,
205 VLD2LN_UPD,
206 VLD3LN_UPD,
207 VLD4LN_UPD,
208 VLD2DUP_UPD,
209 VLD3DUP_UPD,
210 VLD4DUP_UPD,
211
212 // NEON stores with post-increment base updates:
213 VST1_UPD,
214 VST2_UPD,
215 VST3_UPD,
216 VST4_UPD,
217 VST2LN_UPD,
218 VST3LN_UPD,
Amara Emersonb4ad2f32013-09-26 12:22:36 +0000219 VST4LN_UPD
Evan Cheng10043e22007-01-19 07:51:42 +0000220 };
221 }
222
Bob Wilson2e076c42009-06-22 23:27:02 +0000223 /// Define some predicates that are used for node matching.
224 namespace ARM {
Jim Grosbach11013ed2010-07-16 23:05:05 +0000225 bool isBitFieldInvertedMask(unsigned v);
Bob Wilson2e076c42009-06-22 23:27:02 +0000226 }
227
Bob Wilsondd0e2362009-05-20 16:30:25 +0000228 //===--------------------------------------------------------------------===//
Dale Johannesen8447d342007-03-20 00:30:56 +0000229 // ARMTargetLowering - ARM Implementation of the TargetLowering interface
Jim Grosbach91fa7812009-05-13 22:32:43 +0000230
Evan Cheng10043e22007-01-19 07:51:42 +0000231 class ARMTargetLowering : public TargetLowering {
Evan Cheng10043e22007-01-19 07:51:42 +0000232 public:
Dan Gohman5f6a9da52007-08-02 21:21:54 +0000233 explicit ARMTargetLowering(TargetMachine &TM);
Evan Cheng10043e22007-01-19 07:51:42 +0000234
Craig Topper6bc27bf2014-03-10 02:09:33 +0000235 unsigned getJumpTableEncoding() const override;
Jim Grosbach8d3ba732010-07-19 17:20:38 +0000236
Craig Topper6bc27bf2014-03-10 02:09:33 +0000237 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Duncan Sands6ed40142008-12-01 11:39:25 +0000238
239 /// ReplaceNodeResults - Replace the results of node with an illegal result
240 /// type with new values built out of custom code.
241 ///
Craig Topper6bc27bf2014-03-10 02:09:33 +0000242 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
243 SelectionDAG &DAG) const override;
Duncan Sands6ed40142008-12-01 11:39:25 +0000244
Craig Topper6bc27bf2014-03-10 02:09:33 +0000245 const char *getTargetNodeName(unsigned Opcode) const override;
Evan Cheng10043e22007-01-19 07:51:42 +0000246
Craig Topper6bc27bf2014-03-10 02:09:33 +0000247 bool isSelectSupported(SelectSupportKind Kind) const override {
Nadav Rotem9d832022012-09-02 12:10:19 +0000248 // ARM does not support scalar condition selects on vectors.
249 return (Kind != ScalarCondVectorVal);
250 }
251
Duncan Sandsf2641e12011-09-06 19:07:46 +0000252 /// getSetCCResultType - Return the value type to use for ISD::SETCC.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000253 EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override;
Duncan Sandsf2641e12011-09-06 19:07:46 +0000254
Craig Topper6bc27bf2014-03-10 02:09:33 +0000255 MachineBasicBlock *
Dan Gohman25c16532010-05-01 00:01:06 +0000256 EmitInstrWithCustomInserter(MachineInstr *MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000257 MachineBasicBlock *MBB) const override;
Evan Cheng10043e22007-01-19 07:51:42 +0000258
Craig Topper6bc27bf2014-03-10 02:09:33 +0000259 void AdjustInstrPostInstrSelection(MachineInstr *MI,
260 SDNode *Node) const override;
Evan Chenge6fba772011-08-30 19:09:48 +0000261
Evan Chengf863e3f2011-07-13 00:42:17 +0000262 SDValue PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const;
Craig Topper6bc27bf2014-03-10 02:09:33 +0000263 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
Evan Chengd42641c2011-02-02 01:06:55 +0000264
Craig Topper6bc27bf2014-03-10 02:09:33 +0000265 bool isDesirableToTransformToIntegerOp(unsigned Opc, EVT VT) const override;
Evan Chengd42641c2011-02-02 01:06:55 +0000266
Bill Wendlingbae6b2c2009-08-15 21:21:19 +0000267 /// allowsUnalignedMemoryAccesses - Returns true if the target allows
Evan Cheng79e2ca92012-12-10 23:21:26 +0000268 /// unaligned memory accesses of the specified type. Returns whether it
269 /// is "fast" by reference in the second argument.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000270 bool allowsUnalignedMemoryAccesses(EVT VT, unsigned AddrSpace,
271 bool *Fast) const override;
Bill Wendlingbae6b2c2009-08-15 21:21:19 +0000272
Craig Topper6bc27bf2014-03-10 02:09:33 +0000273 EVT getOptimalMemOpType(uint64_t Size,
274 unsigned DstAlign, unsigned SrcAlign,
275 bool IsMemset, bool ZeroMemset,
276 bool MemcpyStrSrc,
277 MachineFunction &MF) const override;
Lang Hames9929c422011-11-02 22:52:45 +0000278
Matt Beaumont-Gay4a04c922012-12-06 23:15:36 +0000279 using TargetLowering::isZExtFree;
Craig Topper6bc27bf2014-03-10 02:09:33 +0000280 bool isZExtFree(SDValue Val, EVT VT2) const override;
Evan Cheng9ec512d2012-12-06 19:13:27 +0000281
Craig Topper6bc27bf2014-03-10 02:09:33 +0000282 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
Tim Northovercc2e9032013-08-06 13:58:03 +0000283
284
Chris Lattner1eb94d92007-03-30 23:15:24 +0000285 /// isLegalAddressingMode - Return true if the addressing mode represented
286 /// by AM is legal for this target, for a load/store of the specified type.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000287 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
Evan Chengdc49a8d2009-08-14 20:09:37 +0000288 bool isLegalT2ScaledAddressingMode(const AddrMode &AM, EVT VT) const;
Jim Grosbach91fa7812009-05-13 22:32:43 +0000289
Evan Cheng3d3c24a2009-11-11 19:05:52 +0000290 /// isLegalICmpImmediate - Return true if the specified immediate is legal
Jim Grosbach84511e12010-06-02 21:53:11 +0000291 /// icmp immediate, that is the target has icmp instructions which can
292 /// compare a register against the immediate without having to materialize
293 /// the immediate into a register.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000294 bool isLegalICmpImmediate(int64_t Imm) const override;
Evan Cheng3d3c24a2009-11-11 19:05:52 +0000295
Dan Gohman6136e942011-05-03 00:46:49 +0000296 /// isLegalAddImmediate - Return true if the specified immediate is legal
297 /// add immediate, that is the target has add instructions which can
298 /// add a register and the immediate without having to materialize
299 /// the immediate into a register.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000300 bool isLegalAddImmediate(int64_t Imm) const override;
Dan Gohman6136e942011-05-03 00:46:49 +0000301
Evan Cheng10043e22007-01-19 07:51:42 +0000302 /// getPreIndexedAddressParts - returns true by value, base pointer and
303 /// offset pointer and addressing mode by reference if the node's address
304 /// can be legally represented as pre-indexed load / store address.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000305 bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, SDValue &Offset,
306 ISD::MemIndexedMode &AM,
307 SelectionDAG &DAG) const override;
Evan Cheng10043e22007-01-19 07:51:42 +0000308
309 /// getPostIndexedAddressParts - returns true by value, base pointer and
310 /// offset pointer and addressing mode by reference if this node can be
311 /// combined with a load / store to form a post-indexed load / store.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000312 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base,
313 SDValue &Offset, ISD::MemIndexedMode &AM,
314 SelectionDAG &DAG) const override;
Evan Cheng10043e22007-01-19 07:51:42 +0000315
Craig Topper6bc27bf2014-03-10 02:09:33 +0000316 void computeMaskedBitsForTargetNode(const SDValue Op, APInt &KnownZero,
317 APInt &KnownOne,
318 const SelectionDAG &DAG,
319 unsigned Depth) const override;
Bill Wendlingbae6b2c2009-08-15 21:21:19 +0000320
321
Craig Topper6bc27bf2014-03-10 02:09:33 +0000322 bool ExpandInlineAsm(CallInst *CI) const override;
Evan Cheng078b0b02011-01-08 01:24:27 +0000323
Craig Topper6bc27bf2014-03-10 02:09:33 +0000324 ConstraintType
325 getConstraintType(const std::string &Constraint) const override;
John Thompsone8360b72010-10-29 17:29:13 +0000326
327 /// Examine constraint string and operand type and determine a weight value.
328 /// The operand object must already have been set up with the operand type.
329 ConstraintWeight getSingleConstraintMatchWeight(
Craig Topper6bc27bf2014-03-10 02:09:33 +0000330 AsmOperandInfo &info, const char *constraint) const override;
John Thompsone8360b72010-10-29 17:29:13 +0000331
Jim Grosbach91fa7812009-05-13 22:32:43 +0000332 std::pair<unsigned, const TargetRegisterClass*>
Evan Cheng10043e22007-01-19 07:51:42 +0000333 getRegForInlineAsmConstraint(const std::string &Constraint,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000334 MVT VT) const override;
Rafael Espindolafa0df552007-11-05 23:12:20 +0000335
Bob Wilsoncf1ec2c2009-04-01 17:58:54 +0000336 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
337 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is
338 /// true it means one of the asm constraint of the inline asm instruction
339 /// being processed is 'm'.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000340 void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
341 std::vector<SDValue> &Ops,
342 SelectionDAG &DAG) const override;
Jim Grosbach91fa7812009-05-13 22:32:43 +0000343
Dan Gohman4df9d9c2010-05-11 16:21:03 +0000344 const ARMSubtarget* getSubtarget() const {
Dan Gohman544ab2c2008-04-12 04:36:06 +0000345 return Subtarget;
Rafael Espindolafa0df552007-11-05 23:12:20 +0000346 }
347
Evan Cheng4cad68e2010-05-15 02:18:07 +0000348 /// getRegClassFor - Return the register class that should be used for the
349 /// specified value type.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000350 const TargetRegisterClass *getRegClassFor(MVT VT) const override;
Evan Cheng4cad68e2010-05-15 02:18:07 +0000351
Anton Korobeynikov19edda02010-07-24 21:52:08 +0000352 /// getMaximalGlobalOffset - Returns the maximal possible offset which can
353 /// be used for loads / stores from the global.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000354 unsigned getMaximalGlobalOffset() const override;
Anton Korobeynikov19edda02010-07-24 21:52:08 +0000355
James Molloy8a259922013-12-03 11:23:11 +0000356 /// Returns true if a cast between SrcAS and DestAS is a noop.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000357 bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
James Molloy8a259922013-12-03 11:23:11 +0000358 // Addrspacecasts are always noops.
359 return true;
360 }
361
Eric Christopher84bdfd82010-07-21 22:26:11 +0000362 /// createFastISel - This method returns a target specific FastISel object,
363 /// or null if the target does not support "fast" ISel.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000364 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
365 const TargetLibraryInfo *libInfo) const override;
Eric Christopher84bdfd82010-07-21 22:26:11 +0000366
Craig Topper6bc27bf2014-03-10 02:09:33 +0000367 Sched::Preference getSchedulingPreference(SDNode *N) const override;
Evan Cheng4401f882010-05-20 23:26:43 +0000368
Craig Topper6bc27bf2014-03-10 02:09:33 +0000369 bool
370 isShuffleMaskLegal(const SmallVectorImpl<int> &M, EVT VT) const override;
371 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
Evan Cheng4a609f3c2009-10-28 01:44:26 +0000372
373 /// isFPImmLegal - Returns true if the target can instruction select the
374 /// specified FP immediate natively. If false, the legalizer will
375 /// materialize the FP immediate as a load from a constant pool.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000376 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
Evan Cheng4a609f3c2009-10-28 01:44:26 +0000377
Craig Topper6bc27bf2014-03-10 02:09:33 +0000378 bool getTgtMemIntrinsic(IntrinsicInfo &Info,
379 const CallInst &I,
380 unsigned Intrinsic) const override;
Juergen Ributzka659ce002014-01-28 01:20:14 +0000381
382 /// \brief Returns true if it is beneficial to convert a load of a constant
383 /// to just the constant itself.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000384 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
385 Type *Ty) const override;
Juergen Ributzka659ce002014-01-28 01:20:14 +0000386
Oliver Stannardc24f2172014-05-09 14:01:47 +0000387 /// \brief Returns true if an argument of type Ty needs to be passed in a
388 /// contiguous block of registers in calling convention CallConv.
389 bool functionArgumentNeedsConsecutiveRegisters(
390 Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override;
391
Tim Northover037f26f22014-04-17 18:22:47 +0000392 Value *emitLoadLinked(IRBuilder<> &Builder, Value *Addr,
393 AtomicOrdering Ord) const override;
394 Value *emitStoreConditional(IRBuilder<> &Builder, Value *Val,
395 Value *Addr, AtomicOrdering Ord) const override;
396
397 bool shouldExpandAtomicInIR(Instruction *Inst) const override;
398
Evan Cheng10f99a32010-07-19 22:15:08 +0000399 protected:
Evan Chenga77f3d32010-07-21 06:09:07 +0000400 std::pair<const TargetRegisterClass*, uint8_t>
Craig Topper6bc27bf2014-03-10 02:09:33 +0000401 findRepresentativeClass(MVT VT) const override;
Evan Cheng10f99a32010-07-19 22:15:08 +0000402
Evan Cheng10043e22007-01-19 07:51:42 +0000403 private:
404 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
405 /// make the right decision when generating code for different targets.
406 const ARMSubtarget *Subtarget;
407
Evan Chengdf907f42010-07-23 22:39:59 +0000408 const TargetRegisterInfo *RegInfo;
409
Evan Chengbf407072010-09-10 01:29:16 +0000410 const InstrItineraryData *Itins;
411
Bob Wilson844d6c82009-07-13 18:11:36 +0000412 /// ARMPCLabelIndex - Keep track of the number of ARM PC labels created.
Evan Cheng10043e22007-01-19 07:51:42 +0000413 ///
414 unsigned ARMPCLabelIndex;
415
Craig Topper4fa625f2012-08-12 03:16:37 +0000416 void addTypeForNEON(MVT VT, MVT PromotedLdStVT, MVT PromotedBitwiseVT);
417 void addDRTypeForNEON(MVT VT);
418 void addQRTypeForNEON(MVT VT);
Bob Wilson2e076c42009-06-22 23:27:02 +0000419
420 typedef SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPassVector;
Andrew Trickef9de2a2013-05-25 02:42:55 +0000421 void PassF64ArgInRegs(SDLoc dl, SelectionDAG &DAG,
Bob Wilson2e076c42009-06-22 23:27:02 +0000422 SDValue Chain, SDValue &Arg,
423 RegsToPassVector &RegsToPass,
424 CCValAssign &VA, CCValAssign &NextVA,
425 SDValue &StackPtr,
Craig Topperb94011f2013-07-14 04:42:23 +0000426 SmallVectorImpl<SDValue> &MemOpChains,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000427 ISD::ArgFlagsTy Flags) const;
Bob Wilson2e076c42009-06-22 23:27:02 +0000428 SDValue GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000429 SDValue &Root, SelectionDAG &DAG,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000430 SDLoc dl) const;
Bob Wilson2e076c42009-06-22 23:27:02 +0000431
Oliver Stannardc24f2172014-05-09 14:01:47 +0000432 CallingConv::ID getEffectiveCallingConv(CallingConv::ID CC,
433 bool isVarArg) const;
Jim Grosbach84511e12010-06-02 21:53:11 +0000434 CCAssignFn *CCAssignFnForNode(CallingConv::ID CC, bool Return,
435 bool isVarArg) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000436 SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000437 SDLoc dl, SelectionDAG &DAG,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000438 const CCValAssign &VA,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000439 ISD::ArgFlagsTy Flags) const;
Jim Grosbachc98892f2010-05-26 20:22:18 +0000440 SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
Jim Grosbachbd9485d2010-05-22 01:06:18 +0000441 SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
Jim Grosbacha570d052010-02-08 23:22:00 +0000442 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000443 const ARMSubtarget *Subtarget) const;
444 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
445 SDValue LowerGlobalAddressDarwin(SDValue Op, SelectionDAG &DAG) const;
446 SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG) const;
Saleem Abdulrasool40bca0a2014-05-09 00:58:32 +0000447 SDValue LowerGlobalAddressWindows(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman21cea8a2010-04-17 15:26:15 +0000448 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000449 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000450 SelectionDAG &DAG) const;
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000451 SDValue LowerToTLSExecModels(GlobalAddressSDNode *GA,
Hans Wennborgaea41202012-05-04 09:40:39 +0000452 SelectionDAG &DAG,
453 TLSModel::Model model) const;
Dan Gohman21cea8a2010-04-17 15:26:15 +0000454 SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) const;
455 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
Bill Wendling6a981312010-08-11 08:43:16 +0000456 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman21cea8a2010-04-17 15:26:15 +0000457 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
458 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
Evan Cheng25f93642010-07-08 02:08:50 +0000459 SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
Evan Cheng168ced92010-05-22 01:47:14 +0000460 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman21cea8a2010-04-17 15:26:15 +0000461 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman21cea8a2010-04-17 15:26:15 +0000462 SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;
463 SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
Nate Begemanb69b1822010-08-03 21:31:55 +0000464 SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
Lang Hamesc35ee8b2012-03-15 18:49:02 +0000465 SDValue LowerConstantFP(SDValue Op, SelectionDAG &DAG,
466 const ARMSubtarget *ST) const;
Andrew Trick1a1f8d42011-04-23 03:24:11 +0000467 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG,
Bob Wilson6f2b8962011-01-07 21:37:30 +0000468 const ARMSubtarget *ST) const;
Bob Wilsone7dde0c2013-11-03 06:14:38 +0000469 SDValue LowerFSINCOS(SDValue Op, SelectionDAG &DAG) const;
Renato Golin87610692013-07-16 09:32:17 +0000470 SDValue LowerDivRem(SDValue Op, SelectionDAG &DAG) const;
Bob Wilson6f2b8962011-01-07 21:37:30 +0000471
Renato Golinc7aea402014-05-06 16:51:25 +0000472 unsigned getRegisterByName(const char* RegName) const;
473
Stephen Lindd502022013-07-10 01:54:24 +0000474 /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
475 /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
476 /// expanded to FMAs when this method returns true, otherwise fmuladd is
477 /// expanded to fmul + fadd.
478 ///
479 /// ARM supports both fused and unfused multiply-add operations; we already
Stephen Lin2a644732013-07-10 01:57:39 +0000480 /// lower a pair of fmul and fadd to the latter so it's not clear that there
Stephen Lindd502022013-07-10 01:54:24 +0000481 /// would be a gain or that the gain would be worthwhile enough to risk
482 /// correctness bugs.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000483 bool isFMAFasterThanFMulAndFAdd(EVT VT) const override { return false; }
Stephen Lindd502022013-07-10 01:54:24 +0000484
Bob Wilson6f2b8962011-01-07 21:37:30 +0000485 SDValue ReconstructShuffle(SDValue Op, SelectionDAG &DAG) const;
Rafael Espindola18a831d2007-10-19 14:35:17 +0000486
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000487 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000488 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000489 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000490 SDLoc dl, SelectionDAG &DAG,
Stephen Linb8bd2322013-04-20 05:14:40 +0000491 SmallVectorImpl<SDValue> &InVals,
492 bool isThisReturn, SDValue ThisVal) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000493
Craig Topper6bc27bf2014-03-10 02:09:33 +0000494 SDValue
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000495 LowerFormalArguments(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000496 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000497 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000498 SDLoc dl, SelectionDAG &DAG,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000499 SmallVectorImpl<SDValue> &InVals) const override;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000500
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000501 int StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000502 SDLoc dl, SDValue &Chain,
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000503 const Value *OrigArg,
Stepan Dyatkovskiy8c02c982013-05-05 07:48:36 +0000504 unsigned InRegsParamRecordIdx,
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000505 unsigned OffsetFromOrigArg,
506 unsigned ArgOffset,
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +0000507 unsigned ArgSize,
Oliver Stannardd55e1152014-03-05 15:25:27 +0000508 bool ForceMutable,
509 unsigned ByValStoreOffset,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000510 unsigned TotalArgRegsSaveSize) const;
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000511
Stuart Hastings45fe3c32011-04-20 16:47:52 +0000512 void VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000513 SDLoc dl, SDValue &Chain,
Stepan Dyatkovskiydab80432012-10-19 08:23:06 +0000514 unsigned ArgOffset,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000515 unsigned TotalArgRegsSaveSize,
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000516 bool ForceMutable = false) const;
Stuart Hastings45fe3c32011-04-20 16:47:52 +0000517
518 void computeRegArea(CCState &CCInfo, MachineFunction &MF,
Stepan Dyatkovskiy8c02c982013-05-05 07:48:36 +0000519 unsigned InRegsParamRecordIdx,
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +0000520 unsigned ArgSize,
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000521 unsigned &ArgRegsSize,
522 unsigned &ArgRegsSaveSize) const;
Stuart Hastings45fe3c32011-04-20 16:47:52 +0000523
Craig Topper6bc27bf2014-03-10 02:09:33 +0000524 SDValue
Justin Holewinskiaa583972012-05-25 16:35:28 +0000525 LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000526 SmallVectorImpl<SDValue> &InVals) const override;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000527
Stuart Hastings67c5c3e2011-02-28 17:17:53 +0000528 /// HandleByVal - Target-specific cleanup for ByVal support.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000529 void HandleByVal(CCState *, unsigned &, unsigned) const override;
Stuart Hastings67c5c3e2011-02-28 17:17:53 +0000530
Dale Johannesend679ff72010-06-03 21:09:53 +0000531 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
532 /// for tail call optimization. Targets which want to do tail call
533 /// optimization should implement this function.
534 bool IsEligibleForTailCallOptimization(SDValue Callee,
535 CallingConv::ID CalleeCC,
536 bool isVarArg,
537 bool isCalleeStructRet,
538 bool isCallerStructRet,
539 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000540 const SmallVectorImpl<SDValue> &OutVals,
Dale Johannesend679ff72010-06-03 21:09:53 +0000541 const SmallVectorImpl<ISD::InputArg> &Ins,
542 SelectionDAG& DAG) const;
Benjamin Kramerb1996da2012-11-28 20:55:10 +0000543
Craig Topper6bc27bf2014-03-10 02:09:33 +0000544 bool CanLowerReturn(CallingConv::ID CallConv,
545 MachineFunction &MF, bool isVarArg,
546 const SmallVectorImpl<ISD::OutputArg> &Outs,
547 LLVMContext &Context) const override;
Benjamin Kramerb1996da2012-11-28 20:55:10 +0000548
Craig Topper6bc27bf2014-03-10 02:09:33 +0000549 SDValue
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000550 LowerReturn(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000551 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000552 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000553 const SmallVectorImpl<SDValue> &OutVals,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000554 SDLoc dl, SelectionDAG &DAG) const override;
Evan Cheng15b80e42009-11-12 07:13:11 +0000555
Craig Topper6bc27bf2014-03-10 02:09:33 +0000556 bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const override;
Evan Chengd4b08732010-11-30 23:55:39 +0000557
Craig Topper6bc27bf2014-03-10 02:09:33 +0000558 bool mayBeEmittedAsTailCall(CallInst *CI) const override;
Evan Cheng0663f232011-03-21 01:19:09 +0000559
Evan Cheng15b80e42009-11-12 07:13:11 +0000560 SDValue getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000561 SDValue &ARMcc, SelectionDAG &DAG, SDLoc dl) const;
Evan Cheng0cc4ad92010-07-13 19:27:42 +0000562 SDValue getVFPCmp(SDValue LHS, SDValue RHS,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000563 SelectionDAG &DAG, SDLoc dl) const;
Bob Wilson45acbd02011-03-08 01:17:20 +0000564 SDValue duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const;
Evan Cheng0cc4ad92010-07-13 19:27:42 +0000565
566 SDValue OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const;
Jim Grosbach5c4e99f2009-12-11 01:42:04 +0000567
Bill Wendling030b58e2011-10-06 22:18:16 +0000568 void SetupEntryBlockForSjLj(MachineInstr *MI,
569 MachineBasicBlock *MBB,
570 MachineBasicBlock *DispatchBB, int FI) const;
571
Bill Wendling374ee192011-10-03 21:25:38 +0000572 MachineBasicBlock *EmitSjLjDispatchBlock(MachineInstr *MI,
573 MachineBasicBlock *MBB) const;
574
Andrew Trick0ed57782011-04-23 03:55:32 +0000575 bool RemapAddSubWithFlags(MachineInstr *MI, MachineBasicBlock *BB) const;
Manman Rene8735522012-06-01 19:33:18 +0000576
577 MachineBasicBlock *EmitStructByval(MachineInstr *MI,
578 MachineBasicBlock *MBB) const;
Evan Cheng10043e22007-01-19 07:51:42 +0000579 };
Andrew Trick1a1f8d42011-04-23 03:24:11 +0000580
Owen Andersona4076922010-11-05 21:57:54 +0000581 enum NEONModImmType {
582 VMOVModImm,
583 VMVNModImm,
584 OtherModImm
585 };
Andrew Trick1a1f8d42011-04-23 03:24:11 +0000586
Eric Christopher84bdfd82010-07-21 22:26:11 +0000587 namespace ARM {
Bob Wilson3e6fa462012-08-03 04:06:28 +0000588 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
589 const TargetLibraryInfo *libInfo);
Eric Christopher84bdfd82010-07-21 22:26:11 +0000590 }
Evan Cheng10043e22007-01-19 07:51:42 +0000591}
592
593#endif // ARMISELLOWERING_H