1 //===-- ARMISelLowering.h - ARM DAG Lowering Interface ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interfaces that ARM uses to lower LLVM code into a
13 //===----------------------------------------------------------------------===//
15 #ifndef ARMISELLOWERING_H
16 #define ARMISELLOWERING_H
18 #include "ARMSubtarget.h"
19 #include "llvm/Target/TargetLowering.h"
20 #include "llvm/Target/TargetRegisterInfo.h"
21 #include "llvm/CodeGen/FastISel.h"
22 #include "llvm/CodeGen/SelectionDAG.h"
23 #include "llvm/CodeGen/CallingConvLower.h"
27 class ARMConstantPoolValue;
30 // ARM Specific DAG Nodes
32 // Start the numbering where the builtin ops and target ops leave off.
33 FIRST_NUMBER = ISD::BUILTIN_OP_END,
35 Wrapper, // Wrapper - A wrapper node for TargetConstantPool,
36 // TargetExternalSymbol, and TargetGlobalAddress.
37 WrapperJT, // WrapperJT - A wrapper node for TargetJumpTable
39 CALL, // Function call.
40 CALL_PRED, // Function call that's predicable.
41 CALL_NOLINK, // Function call with branch not branch-and-link.
42 tCALL, // Thumb function call.
43 BRCOND, // Conditional branch.
44 BR_JT, // Jumptable branch.
45 BR2_JT, // Jumptable branch (2 level - jumptable entry is a jump).
46 RET_FLAG, // Return with a flag operand.
48 PIC_ADD, // Add with a PC operand and a PIC label.
50 AND, // ARM "and" instruction that sets the 's' flag in CPSR.
52 CMP, // ARM compare instructions.
53 CMPZ, // ARM compare that sets only Z flag.
54 CMPFP, // ARM VFP compare instruction, sets FPSCR.
55 CMPFPw0, // ARM VFP compare against zero instruction, sets FPSCR.
56 FMSTAT, // ARM fmstat instruction.
57 CMOV, // ARM conditional move instructions.
58 CNEG, // ARM conditional negate instructions.
62 RBIT, // ARM bitreverse instruction
64 FTOSI, // FP to sint within a FP register.
65 FTOUI, // FP to uint within a FP register.
66 SITOF, // sint to FP within a FP register.
67 UITOF, // uint to FP within a FP register.
69 SRL_FLAG, // V,Flag = srl_flag X -> srl X, 1 + save carry out.
70 SRA_FLAG, // V,Flag = sra_flag X -> sra X, 1 + save carry out.
71 RRX, // V = RRX X, Flag -> srl X, 1 + shift in carry flag.
73 VMOVRRD, // double to two gprs.
74 VMOVDRR, // Two gprs to double.
76 EH_SJLJ_SETJMP, // SjLj exception handling setjmp.
77 EH_SJLJ_LONGJMP, // SjLj exception handling longjmp.
79 TC_RETURN, // Tail call return pseudo.
83 DYN_ALLOC, // Dynamic allocation on the stack.
85 MEMBARRIER, // Memory barrier
86 SYNCBARRIER, // Memory sync barrier
88 VCEQ, // Vector compare equal.
89 VCGE, // Vector compare greater than or equal.
90 VCGEU, // Vector compare unsigned greater than or equal.
91 VCGT, // Vector compare greater than.
92 VCGTU, // Vector compare unsigned greater than.
93 VTST, // Vector test bits.
95 // Vector shift by immediate:
97 VSHRs, // ...right (signed)
98 VSHRu, // ...right (unsigned)
99 VSHLLs, // ...left long (signed)
100 VSHLLu, // ...left long (unsigned)
101 VSHLLi, // ...left long (with maximum shift count)
102 VSHRN, // ...right narrow
104 // Vector rounding shift by immediate:
105 VRSHRs, // ...right (signed)
106 VRSHRu, // ...right (unsigned)
107 VRSHRN, // ...right narrow
109 // Vector saturating shift by immediate:
110 VQSHLs, // ...left (signed)
111 VQSHLu, // ...left (unsigned)
112 VQSHLsu, // ...left (signed to unsigned)
113 VQSHRNs, // ...right narrow (signed)
114 VQSHRNu, // ...right narrow (unsigned)
115 VQSHRNsu, // ...right narrow (signed to unsigned)
117 // Vector saturating rounding shift by immediate:
118 VQRSHRNs, // ...right narrow (signed)
119 VQRSHRNu, // ...right narrow (unsigned)
120 VQRSHRNsu, // ...right narrow (signed to unsigned)
122 // Vector shift and insert:
126 // Vector get lane (VMOV scalar to ARM core register)
127 // (These are used for 8- and 16-bit element types only.)
128 VGETLANEu, // zero-extend vector extract element
129 VGETLANEs, // sign-extend vector extract element
131 // Vector move immediate and move negated immediate:
141 VREV64, // reverse elements within 64-bit doublewords
142 VREV32, // reverse elements within 32-bit words
143 VREV16, // reverse elements within 16-bit halfwords
144 VZIP, // zip (interleave)
145 VUZP, // unzip (deinterleave)
148 // Vector multiply long:
150 VMULLu, // ...unsigned
152 // Operands of the standard BUILD_VECTOR node are not legalized, which
153 // is fine if BUILD_VECTORs are always lowered to shuffles or other
154 // operations, but for ARM some BUILD_VECTORs are legal as-is and their
155 // operands need to be legalized. Define an ARM-specific version of
156 // BUILD_VECTOR for this purpose.
159 // Floating-point max and min:
168 /// Define some predicates that are used for node matching.
170 /// getVFPf32Imm / getVFPf64Imm - If the given fp immediate can be
171 /// materialized with a VMOV.f32 / VMOV.f64 (i.e. fconsts / fconstd)
172 /// instruction, returns its 8-bit integer representation. Otherwise,
174 int getVFPf32Imm(const APFloat &FPImm);
175 int getVFPf64Imm(const APFloat &FPImm);
176 bool isBitFieldInvertedMask(unsigned v);
179 //===--------------------------------------------------------------------===//
180 // ARMTargetLowering - ARM Implementation of the TargetLowering interface
182 class ARMTargetLowering : public TargetLowering {
184 explicit ARMTargetLowering(TargetMachine &TM);
186 virtual unsigned getJumpTableEncoding(void) const;
188 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
190 /// ReplaceNodeResults - Replace the results of node with an illegal result
191 /// type with new values built out of custom code.
193 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
194 SelectionDAG &DAG) const;
196 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
198 virtual const char *getTargetNodeName(unsigned Opcode) const;
200 virtual MachineBasicBlock *
201 EmitInstrWithCustomInserter(MachineInstr *MI,
202 MachineBasicBlock *MBB) const;
204 /// allowsUnalignedMemoryAccesses - Returns true if the target allows
205 /// unaligned memory accesses. of the specified type.
206 /// FIXME: Add getOptimalMemOpType to implement memcpy with NEON?
207 virtual bool allowsUnalignedMemoryAccesses(EVT VT) const;
209 /// isLegalAddressingMode - Return true if the addressing mode represented
210 /// by AM is legal for this target, for a load/store of the specified type.
211 virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty)const;
212 bool isLegalT2ScaledAddressingMode(const AddrMode &AM, EVT VT) const;
214 /// isLegalICmpImmediate - Return true if the specified immediate is legal
215 /// icmp immediate, that is the target has icmp instructions which can
216 /// compare a register against the immediate without having to materialize
217 /// the immediate into a register.
218 virtual bool isLegalICmpImmediate(int64_t Imm) const;
220 /// getPreIndexedAddressParts - returns true by value, base pointer and
221 /// offset pointer and addressing mode by reference if the node's address
222 /// can be legally represented as pre-indexed load / store address.
223 virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
225 ISD::MemIndexedMode &AM,
226 SelectionDAG &DAG) const;
228 /// getPostIndexedAddressParts - returns true by value, base pointer and
229 /// offset pointer and addressing mode by reference if this node can be
230 /// combined with a load / store to form a post-indexed load / store.
231 virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
232 SDValue &Base, SDValue &Offset,
233 ISD::MemIndexedMode &AM,
234 SelectionDAG &DAG) const;
236 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
240 const SelectionDAG &DAG,
241 unsigned Depth) const;
244 ConstraintType getConstraintType(const std::string &Constraint) const;
245 std::pair<unsigned, const TargetRegisterClass*>
246 getRegForInlineAsmConstraint(const std::string &Constraint,
248 std::vector<unsigned>
249 getRegClassForInlineAsmConstraint(const std::string &Constraint,
252 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
253 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is
254 /// true it means one of the asm constraint of the inline asm instruction
255 /// being processed is 'm'.
256 virtual void LowerAsmOperandForConstraint(SDValue Op,
257 char ConstraintLetter,
258 std::vector<SDValue> &Ops,
259 SelectionDAG &DAG) const;
261 const ARMSubtarget* getSubtarget() const {
265 /// getRegClassFor - Return the register class that should be used for the
266 /// specified value type.
267 virtual TargetRegisterClass *getRegClassFor(EVT VT) const;
269 /// getFunctionAlignment - Return the Log2 alignment of this function.
270 virtual unsigned getFunctionAlignment(const Function *F) const;
272 /// getMaximalGlobalOffset - Returns the maximal possible offset which can
273 /// be used for loads / stores from the global.
274 virtual unsigned getMaximalGlobalOffset() const;
276 /// createFastISel - This method returns a target specific FastISel object,
277 /// or null if the target does not support "fast" ISel.
278 virtual FastISel *createFastISel(FunctionLoweringInfo &funcInfo) const;
280 Sched::Preference getSchedulingPreference(SDNode *N) const;
282 unsigned getRegPressureLimit(const TargetRegisterClass *RC,
283 MachineFunction &MF) const;
285 bool isShuffleMaskLegal(const SmallVectorImpl<int> &M, EVT VT) const;
286 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
288 /// isFPImmLegal - Returns true if the target can instruction select the
289 /// specified FP immediate natively. If false, the legalizer will
290 /// materialize the FP immediate as a load from a constant pool.
291 virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
293 virtual bool getTgtMemIntrinsic(IntrinsicInfo &Info,
295 unsigned Intrinsic) const;
297 std::pair<const TargetRegisterClass*, uint8_t>
298 findRepresentativeClass(EVT VT) const;
301 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
302 /// make the right decision when generating code for different targets.
303 const ARMSubtarget *Subtarget;
305 const TargetRegisterInfo *RegInfo;
307 const InstrItineraryData *Itins;
309 /// ARMPCLabelIndex - Keep track of the number of ARM PC labels created.
311 unsigned ARMPCLabelIndex;
313 void addTypeForNEON(EVT VT, EVT PromotedLdStVT, EVT PromotedBitwiseVT);
314 void addDRTypeForNEON(EVT VT);
315 void addQRTypeForNEON(EVT VT);
317 typedef SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPassVector;
318 void PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG,
319 SDValue Chain, SDValue &Arg,
320 RegsToPassVector &RegsToPass,
321 CCValAssign &VA, CCValAssign &NextVA,
323 SmallVector<SDValue, 8> &MemOpChains,
324 ISD::ArgFlagsTy Flags) const;
325 SDValue GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA,
326 SDValue &Root, SelectionDAG &DAG,
329 CCAssignFn *CCAssignFnForNode(CallingConv::ID CC, bool Return,
330 bool isVarArg) const;
331 SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg,
332 DebugLoc dl, SelectionDAG &DAG,
333 const CCValAssign &VA,
334 ISD::ArgFlagsTy Flags) const;
335 SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
336 SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
337 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG,
338 const ARMSubtarget *Subtarget) const;
339 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
340 SDValue LowerGlobalAddressDarwin(SDValue Op, SelectionDAG &DAG) const;
341 SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG) const;
342 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
343 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
344 SelectionDAG &DAG) const;
345 SDValue LowerToTLSExecModels(GlobalAddressSDNode *GA,
346 SelectionDAG &DAG) const;
347 SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) const;
348 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
349 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
350 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
351 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
352 SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
353 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
354 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
355 SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;
356 SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
357 SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
359 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
360 CallingConv::ID CallConv, bool isVarArg,
361 const SmallVectorImpl<ISD::InputArg> &Ins,
362 DebugLoc dl, SelectionDAG &DAG,
363 SmallVectorImpl<SDValue> &InVals) const;
366 LowerFormalArguments(SDValue Chain,
367 CallingConv::ID CallConv, bool isVarArg,
368 const SmallVectorImpl<ISD::InputArg> &Ins,
369 DebugLoc dl, SelectionDAG &DAG,
370 SmallVectorImpl<SDValue> &InVals) const;
373 LowerCall(SDValue Chain, SDValue Callee,
374 CallingConv::ID CallConv, bool isVarArg,
376 const SmallVectorImpl<ISD::OutputArg> &Outs,
377 const SmallVectorImpl<SDValue> &OutVals,
378 const SmallVectorImpl<ISD::InputArg> &Ins,
379 DebugLoc dl, SelectionDAG &DAG,
380 SmallVectorImpl<SDValue> &InVals) const;
382 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
383 /// for tail call optimization. Targets which want to do tail call
384 /// optimization should implement this function.
385 bool IsEligibleForTailCallOptimization(SDValue Callee,
386 CallingConv::ID CalleeCC,
388 bool isCalleeStructRet,
389 bool isCallerStructRet,
390 const SmallVectorImpl<ISD::OutputArg> &Outs,
391 const SmallVectorImpl<SDValue> &OutVals,
392 const SmallVectorImpl<ISD::InputArg> &Ins,
393 SelectionDAG& DAG) const;
395 LowerReturn(SDValue Chain,
396 CallingConv::ID CallConv, bool isVarArg,
397 const SmallVectorImpl<ISD::OutputArg> &Outs,
398 const SmallVectorImpl<SDValue> &OutVals,
399 DebugLoc dl, SelectionDAG &DAG) const;
401 SDValue getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
402 SDValue &ARMcc, SelectionDAG &DAG, DebugLoc dl) const;
403 SDValue getVFPCmp(SDValue LHS, SDValue RHS,
404 SelectionDAG &DAG, DebugLoc dl) const;
406 SDValue OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const;
408 MachineBasicBlock *EmitAtomicCmpSwap(MachineInstr *MI,
409 MachineBasicBlock *BB,
410 unsigned Size) const;
411 MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI,
412 MachineBasicBlock *BB,
414 unsigned BinOpcode) const;
419 FastISel *createFastISel(FunctionLoweringInfo &funcInfo);
423 #endif // ARMISELLOWERING_H