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
19 #include "ARMSubtarget.h"
20 #include "llvm/CodeGen/CallingConvLower.h"
21 #include "llvm/CodeGen/FastISel.h"
22 #include "llvm/CodeGen/SelectionDAG.h"
23 #include "llvm/Target/TargetLowering.h"
24 #include "llvm/Target/TargetRegisterInfo.h"
25 #include "llvm/Target/TargetTransformImpl.h"
29 class ARMConstantPoolValue;
32 // ARM Specific DAG Nodes
34 // Start the numbering where the builtin ops and target ops leave off.
35 FIRST_NUMBER = ISD::BUILTIN_OP_END,
37 Wrapper, // Wrapper - A wrapper node for TargetConstantPool,
38 // TargetExternalSymbol, and TargetGlobalAddress.
39 WrapperDYN, // WrapperDYN - A wrapper node for TargetGlobalAddress in
41 WrapperPIC, // WrapperPIC - A wrapper node for TargetGlobalAddress in
43 WrapperJT, // WrapperJT - A wrapper node for TargetJumpTable
45 // Add pseudo op to model memcpy for struct byval.
48 CALL, // Function call.
49 CALL_PRED, // Function call that's predicable.
50 CALL_NOLINK, // Function call with branch not branch-and-link.
51 tCALL, // Thumb function call.
52 BRCOND, // Conditional branch.
53 BR_JT, // Jumptable branch.
54 BR2_JT, // Jumptable branch (2 level - jumptable entry is a jump).
55 RET_FLAG, // Return with a flag operand.
57 PIC_ADD, // Add with a PC operand and a PIC label.
59 CMP, // ARM compare instructions.
60 CMN, // ARM CMN instructions.
61 CMPZ, // ARM compare that sets only Z flag.
62 CMPFP, // ARM VFP compare instruction, sets FPSCR.
63 CMPFPw0, // ARM VFP compare against zero instruction, sets FPSCR.
64 FMSTAT, // ARM fmstat instruction.
66 CMOV, // ARM conditional move instructions.
70 RBIT, // ARM bitreverse instruction
72 FTOSI, // FP to sint within a FP register.
73 FTOUI, // FP to uint within a FP register.
74 SITOF, // sint to FP within a FP register.
75 UITOF, // uint to FP within a FP register.
77 SRL_FLAG, // V,Flag = srl_flag X -> srl X, 1 + save carry out.
78 SRA_FLAG, // V,Flag = sra_flag X -> sra X, 1 + save carry out.
79 RRX, // V = RRX X, Flag -> srl X, 1 + shift in carry flag.
81 ADDC, // Add with carry
82 ADDE, // Add using carry
83 SUBC, // Sub with carry
84 SUBE, // Sub using carry
86 VMOVRRD, // double to two gprs.
87 VMOVDRR, // Two gprs to double.
89 EH_SJLJ_SETJMP, // SjLj exception handling setjmp.
90 EH_SJLJ_LONGJMP, // SjLj exception handling longjmp.
92 TC_RETURN, // Tail call return pseudo.
96 DYN_ALLOC, // Dynamic allocation on the stack.
98 MEMBARRIER, // Memory barrier (DMB)
99 MEMBARRIER_MCR, // Memory barrier (MCR)
103 VCEQ, // Vector compare equal.
104 VCEQZ, // Vector compare equal to zero.
105 VCGE, // Vector compare greater than or equal.
106 VCGEZ, // Vector compare greater than or equal to zero.
107 VCLEZ, // Vector compare less than or equal to zero.
108 VCGEU, // Vector compare unsigned greater than or equal.
109 VCGT, // Vector compare greater than.
110 VCGTZ, // Vector compare greater than zero.
111 VCLTZ, // Vector compare less than zero.
112 VCGTU, // Vector compare unsigned greater than.
113 VTST, // Vector test bits.
115 // Vector shift by immediate:
117 VSHRs, // ...right (signed)
118 VSHRu, // ...right (unsigned)
119 VSHLLs, // ...left long (signed)
120 VSHLLu, // ...left long (unsigned)
121 VSHLLi, // ...left long (with maximum shift count)
122 VSHRN, // ...right narrow
124 // Vector rounding shift by immediate:
125 VRSHRs, // ...right (signed)
126 VRSHRu, // ...right (unsigned)
127 VRSHRN, // ...right narrow
129 // Vector saturating shift by immediate:
130 VQSHLs, // ...left (signed)
131 VQSHLu, // ...left (unsigned)
132 VQSHLsu, // ...left (signed to unsigned)
133 VQSHRNs, // ...right narrow (signed)
134 VQSHRNu, // ...right narrow (unsigned)
135 VQSHRNsu, // ...right narrow (signed to unsigned)
137 // Vector saturating rounding shift by immediate:
138 VQRSHRNs, // ...right narrow (signed)
139 VQRSHRNu, // ...right narrow (unsigned)
140 VQRSHRNsu, // ...right narrow (signed to unsigned)
142 // Vector shift and insert:
146 // Vector get lane (VMOV scalar to ARM core register)
147 // (These are used for 8- and 16-bit element types only.)
148 VGETLANEu, // zero-extend vector extract element
149 VGETLANEs, // sign-extend vector extract element
151 // Vector move immediate and move negated immediate:
155 // Vector move f32 immediate:
164 VREV64, // reverse elements within 64-bit doublewords
165 VREV32, // reverse elements within 32-bit words
166 VREV16, // reverse elements within 16-bit halfwords
167 VZIP, // zip (interleave)
168 VUZP, // unzip (deinterleave)
170 VTBL1, // 1-register shuffle with mask
171 VTBL2, // 2-register shuffle with mask
173 // Vector multiply long:
175 VMULLu, // ...unsigned
179 VADDLu, // ...unsigned
181 // Vector subtract long:
183 VSUBLu, // ...unsigned
185 UMLAL, // 64bit Unsigned Accumulate Multiply
186 SMLAL, // 64bit Signed Accumulate Multiply
188 // Operands of the standard BUILD_VECTOR node are not legalized, which
189 // is fine if BUILD_VECTORs are always lowered to shuffles or other
190 // operations, but for ARM some BUILD_VECTORs are legal as-is and their
191 // operands need to be legalized. Define an ARM-specific version of
192 // BUILD_VECTOR for this purpose.
195 // Floating-point max and min:
202 // Vector OR with immediate
204 // Vector AND with NOT of immediate
207 // Vector bitwise select
210 // Vector load N-element structure to all lanes:
211 VLD2DUP = ISD::FIRST_TARGET_MEMORY_OPCODE,
215 // NEON loads with post-increment base updates:
227 // NEON stores with post-increment base updates:
236 // 64-bit atomic ops (value split into two registers)
252 /// Define some predicates that are used for node matching.
254 bool isBitFieldInvertedMask(unsigned v);
257 //===--------------------------------------------------------------------===//
258 // ARMTargetLowering - ARM Implementation of the TargetLowering interface
260 class ARMTargetLowering : public TargetLowering {
262 explicit ARMTargetLowering(TargetMachine &TM);
264 virtual unsigned getJumpTableEncoding() const;
266 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
268 /// ReplaceNodeResults - Replace the results of node with an illegal result
269 /// type with new values built out of custom code.
271 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
272 SelectionDAG &DAG) const;
274 virtual const char *getTargetNodeName(unsigned Opcode) const;
276 virtual bool isSelectSupported(SelectSupportKind Kind) const {
277 // ARM does not support scalar condition selects on vectors.
278 return (Kind != ScalarCondVectorVal);
281 /// getSetCCResultType - Return the value type to use for ISD::SETCC.
282 virtual EVT getSetCCResultType(EVT VT) const;
284 virtual MachineBasicBlock *
285 EmitInstrWithCustomInserter(MachineInstr *MI,
286 MachineBasicBlock *MBB) const;
289 AdjustInstrPostInstrSelection(MachineInstr *MI, SDNode *Node) const;
291 SDValue PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const;
292 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
294 bool isDesirableToTransformToIntegerOp(unsigned Opc, EVT VT) const;
296 /// allowsUnalignedMemoryAccesses - Returns true if the target allows
297 /// unaligned memory accesses of the specified type. Returns whether it
298 /// is "fast" by reference in the second argument.
299 virtual bool allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const;
301 virtual EVT getOptimalMemOpType(uint64_t Size,
302 unsigned DstAlign, unsigned SrcAlign,
303 bool IsMemset, bool ZeroMemset,
305 MachineFunction &MF) const;
307 using TargetLowering::isZExtFree;
308 virtual bool isZExtFree(SDValue Val, EVT VT2) const;
310 /// isLegalAddressingMode - Return true if the addressing mode represented
311 /// by AM is legal for this target, for a load/store of the specified type.
312 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty)const;
313 bool isLegalT2ScaledAddressingMode(const AddrMode &AM, EVT VT) const;
315 /// isLegalICmpImmediate - Return true if the specified immediate is legal
316 /// icmp immediate, that is the target has icmp instructions which can
317 /// compare a register against the immediate without having to materialize
318 /// the immediate into a register.
319 virtual bool isLegalICmpImmediate(int64_t Imm) const;
321 /// isLegalAddImmediate - Return true if the specified immediate is legal
322 /// add immediate, that is the target has add instructions which can
323 /// add a register and the immediate without having to materialize
324 /// the immediate into a register.
325 virtual bool isLegalAddImmediate(int64_t Imm) const;
327 /// getPreIndexedAddressParts - returns true by value, base pointer and
328 /// offset pointer and addressing mode by reference if the node's address
329 /// can be legally represented as pre-indexed load / store address.
330 virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
332 ISD::MemIndexedMode &AM,
333 SelectionDAG &DAG) const;
335 /// getPostIndexedAddressParts - returns true by value, base pointer and
336 /// offset pointer and addressing mode by reference if this node can be
337 /// combined with a load / store to form a post-indexed load / store.
338 virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
339 SDValue &Base, SDValue &Offset,
340 ISD::MemIndexedMode &AM,
341 SelectionDAG &DAG) const;
343 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
346 const SelectionDAG &DAG,
347 unsigned Depth) const;
350 virtual bool ExpandInlineAsm(CallInst *CI) const;
352 ConstraintType getConstraintType(const std::string &Constraint) const;
354 /// Examine constraint string and operand type and determine a weight value.
355 /// The operand object must already have been set up with the operand type.
356 ConstraintWeight getSingleConstraintMatchWeight(
357 AsmOperandInfo &info, const char *constraint) const;
359 std::pair<unsigned, const TargetRegisterClass*>
360 getRegForInlineAsmConstraint(const std::string &Constraint,
363 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
364 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is
365 /// true it means one of the asm constraint of the inline asm instruction
366 /// being processed is 'm'.
367 virtual void LowerAsmOperandForConstraint(SDValue Op,
368 std::string &Constraint,
369 std::vector<SDValue> &Ops,
370 SelectionDAG &DAG) const;
372 const ARMSubtarget* getSubtarget() const {
376 /// getRegClassFor - Return the register class that should be used for the
377 /// specified value type.
378 virtual const TargetRegisterClass *getRegClassFor(MVT VT) const;
380 /// getMaximalGlobalOffset - Returns the maximal possible offset which can
381 /// be used for loads / stores from the global.
382 virtual unsigned getMaximalGlobalOffset() const;
384 /// createFastISel - This method returns a target specific FastISel object,
385 /// or null if the target does not support "fast" ISel.
386 virtual FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
387 const TargetLibraryInfo *libInfo) const;
389 Sched::Preference getSchedulingPreference(SDNode *N) const;
391 bool isShuffleMaskLegal(const SmallVectorImpl<int> &M, EVT VT) const;
392 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
394 /// isFPImmLegal - Returns true if the target can instruction select the
395 /// specified FP immediate natively. If false, the legalizer will
396 /// materialize the FP immediate as a load from a constant pool.
397 virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
399 virtual bool getTgtMemIntrinsic(IntrinsicInfo &Info,
401 unsigned Intrinsic) const;
403 std::pair<const TargetRegisterClass*, uint8_t>
404 findRepresentativeClass(MVT VT) const;
407 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
408 /// make the right decision when generating code for different targets.
409 const ARMSubtarget *Subtarget;
411 const TargetRegisterInfo *RegInfo;
413 const InstrItineraryData *Itins;
415 /// ARMPCLabelIndex - Keep track of the number of ARM PC labels created.
417 unsigned ARMPCLabelIndex;
419 void addTypeForNEON(MVT VT, MVT PromotedLdStVT, MVT PromotedBitwiseVT);
420 void addDRTypeForNEON(MVT VT);
421 void addQRTypeForNEON(MVT VT);
423 typedef SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPassVector;
424 void PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG,
425 SDValue Chain, SDValue &Arg,
426 RegsToPassVector &RegsToPass,
427 CCValAssign &VA, CCValAssign &NextVA,
429 SmallVector<SDValue, 8> &MemOpChains,
430 ISD::ArgFlagsTy Flags) const;
431 SDValue GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA,
432 SDValue &Root, SelectionDAG &DAG,
435 CCAssignFn *CCAssignFnForNode(CallingConv::ID CC, bool Return,
436 bool isVarArg) const;
437 SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg,
438 DebugLoc dl, SelectionDAG &DAG,
439 const CCValAssign &VA,
440 ISD::ArgFlagsTy Flags) const;
441 SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
442 SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
443 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG,
444 const ARMSubtarget *Subtarget) const;
445 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
446 SDValue LowerGlobalAddressDarwin(SDValue Op, SelectionDAG &DAG) const;
447 SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG) const;
448 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
449 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
450 SelectionDAG &DAG) const;
451 SDValue LowerToTLSExecModels(GlobalAddressSDNode *GA,
453 TLSModel::Model model) const;
454 SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) const;
455 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
456 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
457 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
458 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
459 SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
460 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
461 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
462 SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;
463 SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
464 SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
465 SDValue LowerConstantFP(SDValue Op, SelectionDAG &DAG,
466 const ARMSubtarget *ST) const;
467 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG,
468 const ARMSubtarget *ST) const;
470 SDValue ReconstructShuffle(SDValue Op, SelectionDAG &DAG) const;
472 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
473 CallingConv::ID CallConv, bool isVarArg,
474 const SmallVectorImpl<ISD::InputArg> &Ins,
475 DebugLoc dl, SelectionDAG &DAG,
476 SmallVectorImpl<SDValue> &InVals) const;
479 LowerFormalArguments(SDValue Chain,
480 CallingConv::ID CallConv, bool isVarArg,
481 const SmallVectorImpl<ISD::InputArg> &Ins,
482 DebugLoc dl, SelectionDAG &DAG,
483 SmallVectorImpl<SDValue> &InVals) const;
485 void VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,
486 DebugLoc dl, SDValue &Chain,
487 const Value *OrigArg,
488 unsigned OffsetFromOrigArg,
490 bool ForceMutable = false)
493 void computeRegArea(CCState &CCInfo, MachineFunction &MF,
494 unsigned &VARegSize, unsigned &VARegSaveSize) const;
497 LowerCall(TargetLowering::CallLoweringInfo &CLI,
498 SmallVectorImpl<SDValue> &InVals) const;
500 /// HandleByVal - Target-specific cleanup for ByVal support.
501 virtual void HandleByVal(CCState *, unsigned &, unsigned) const;
503 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
504 /// for tail call optimization. Targets which want to do tail call
505 /// optimization should implement this function.
506 bool IsEligibleForTailCallOptimization(SDValue Callee,
507 CallingConv::ID CalleeCC,
509 bool isCalleeStructRet,
510 bool isCallerStructRet,
511 const SmallVectorImpl<ISD::OutputArg> &Outs,
512 const SmallVectorImpl<SDValue> &OutVals,
513 const SmallVectorImpl<ISD::InputArg> &Ins,
514 SelectionDAG& DAG) const;
516 virtual bool CanLowerReturn(CallingConv::ID CallConv,
517 MachineFunction &MF, bool isVarArg,
518 const SmallVectorImpl<ISD::OutputArg> &Outs,
519 LLVMContext &Context) const;
522 LowerReturn(SDValue Chain,
523 CallingConv::ID CallConv, bool isVarArg,
524 const SmallVectorImpl<ISD::OutputArg> &Outs,
525 const SmallVectorImpl<SDValue> &OutVals,
526 DebugLoc dl, SelectionDAG &DAG) const;
528 virtual bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const;
530 virtual bool mayBeEmittedAsTailCall(CallInst *CI) const;
532 SDValue getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
533 SDValue &ARMcc, SelectionDAG &DAG, DebugLoc dl) const;
534 SDValue getVFPCmp(SDValue LHS, SDValue RHS,
535 SelectionDAG &DAG, DebugLoc dl) const;
536 SDValue duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const;
538 SDValue OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const;
540 MachineBasicBlock *EmitAtomicCmpSwap(MachineInstr *MI,
541 MachineBasicBlock *BB,
542 unsigned Size) const;
543 MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI,
544 MachineBasicBlock *BB,
546 unsigned BinOpcode) const;
547 MachineBasicBlock *EmitAtomicBinary64(MachineInstr *MI,
548 MachineBasicBlock *BB,
551 bool NeedsCarry = false,
552 bool IsCmpxchg = false,
553 bool IsMinMax = false,
554 ARMCC::CondCodes CC = ARMCC::AL) const;
555 MachineBasicBlock * EmitAtomicBinaryMinMax(MachineInstr *MI,
556 MachineBasicBlock *BB,
559 ARMCC::CondCodes Cond) const;
561 void SetupEntryBlockForSjLj(MachineInstr *MI,
562 MachineBasicBlock *MBB,
563 MachineBasicBlock *DispatchBB, int FI) const;
565 MachineBasicBlock *EmitSjLjDispatchBlock(MachineInstr *MI,
566 MachineBasicBlock *MBB) const;
568 bool RemapAddSubWithFlags(MachineInstr *MI, MachineBasicBlock *BB) const;
570 MachineBasicBlock *EmitStructByval(MachineInstr *MI,
571 MachineBasicBlock *MBB) const;
574 enum NEONModImmType {
582 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
583 const TargetLibraryInfo *libInfo);
586 class ARMScalarTargetTransformImpl : public ScalarTargetTransformImpl {
587 const ARMSubtarget *Subtarget;
589 explicit ARMScalarTargetTransformImpl(const TargetLowering *TL) :
590 ScalarTargetTransformImpl(TL),
591 Subtarget(&TL->getTargetMachine().getSubtarget<ARMSubtarget>()) {};
593 virtual unsigned getIntImmCost(const APInt &Imm, Type *Ty) const;
597 #endif // ARMISELLOWERING_H