Path: blob/main/contrib/llvm-project/llvm/lib/Target/ARM/ARMISelLowering.h
35268 views
//===- ARMISelLowering.h - ARM DAG Lowering Interface -----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the interfaces that ARM uses to lower LLVM code into a9// selection DAG.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_ARM_ARMISELLOWERING_H14#define LLVM_LIB_TARGET_ARM_ARMISELLOWERING_H1516#include "MCTargetDesc/ARMBaseInfo.h"17#include "llvm/ADT/SmallVector.h"18#include "llvm/ADT/StringRef.h"19#include "llvm/CodeGen/CallingConvLower.h"20#include "llvm/CodeGen/ISDOpcodes.h"21#include "llvm/CodeGen/MachineFunction.h"22#include "llvm/CodeGen/SelectionDAGNodes.h"23#include "llvm/CodeGen/TargetLowering.h"24#include "llvm/CodeGen/ValueTypes.h"25#include "llvm/CodeGenTypes/MachineValueType.h"26#include "llvm/IR/Attributes.h"27#include "llvm/IR/CallingConv.h"28#include "llvm/IR/Function.h"29#include "llvm/IR/InlineAsm.h"30#include "llvm/Support/CodeGen.h"31#include <optional>32#include <utility>3334namespace llvm {3536class ARMSubtarget;37class DataLayout;38class FastISel;39class FunctionLoweringInfo;40class GlobalValue;41class InstrItineraryData;42class Instruction;43class IRBuilderBase;44class MachineBasicBlock;45class MachineInstr;46class SelectionDAG;47class TargetLibraryInfo;48class TargetMachine;49class TargetRegisterInfo;50class VectorType;5152namespace ARMISD {5354// ARM Specific DAG Nodes55enum NodeType : unsigned {56// Start the numbering where the builtin ops and target ops leave off.57FIRST_NUMBER = ISD::BUILTIN_OP_END,5859Wrapper, // Wrapper - A wrapper node for TargetConstantPool,60// TargetExternalSymbol, and TargetGlobalAddress.61WrapperPIC, // WrapperPIC - A wrapper node for TargetGlobalAddress in62// PIC mode.63WrapperJT, // WrapperJT - A wrapper node for TargetJumpTable6465// Add pseudo op to model memcpy for struct byval.66COPY_STRUCT_BYVAL,6768CALL, // Function call.69CALL_PRED, // Function call that's predicable.70CALL_NOLINK, // Function call with branch not branch-and-link.71tSECALL, // CMSE non-secure function call.72t2CALL_BTI, // Thumb function call followed by BTI instruction.73BRCOND, // Conditional branch.74BR_JT, // Jumptable branch.75BR2_JT, // Jumptable branch (2 level - jumptable entry is a jump).76RET_GLUE, // Return with a flag operand.77SERET_GLUE, // CMSE Entry function return with a flag operand.78INTRET_GLUE, // Interrupt return with an LR-offset and a flag operand.7980PIC_ADD, // Add with a PC operand and a PIC label.8182ASRL, // MVE long arithmetic shift right.83LSRL, // MVE long shift right.84LSLL, // MVE long shift left.8586CMP, // ARM compare instructions.87CMN, // ARM CMN instructions.88CMPZ, // ARM compare that sets only Z flag.89CMPFP, // ARM VFP compare instruction, sets FPSCR.90CMPFPE, // ARM VFP signalling compare instruction, sets FPSCR.91CMPFPw0, // ARM VFP compare against zero instruction, sets FPSCR.92CMPFPEw0, // ARM VFP signalling compare against zero instruction, sets93// FPSCR.94FMSTAT, // ARM fmstat instruction.9596CMOV, // ARM conditional move instructions.9798SSAT, // Signed saturation99USAT, // Unsigned saturation100101BCC_i64,102103SRL_GLUE, // V,Flag = srl_flag X -> srl X, 1 + save carry out.104SRA_GLUE, // V,Flag = sra_flag X -> sra X, 1 + save carry out.105RRX, // V = RRX X, Flag -> srl X, 1 + shift in carry flag.106107ADDC, // Add with carry108ADDE, // Add using carry109SUBC, // Sub with carry110SUBE, // Sub using carry111LSLS, // Shift left producing carry112113VMOVRRD, // double to two gprs.114VMOVDRR, // Two gprs to double.115VMOVSR, // move gpr to single, used for f32 literal constructed in a gpr116117EH_SJLJ_SETJMP, // SjLj exception handling setjmp.118EH_SJLJ_LONGJMP, // SjLj exception handling longjmp.119EH_SJLJ_SETUP_DISPATCH, // SjLj exception handling setup_dispatch.120121TC_RETURN, // Tail call return pseudo.122123THREAD_POINTER,124125DYN_ALLOC, // Dynamic allocation on the stack.126127MEMBARRIER_MCR, // Memory barrier (MCR)128129PRELOAD, // Preload130131WIN__CHKSTK, // Windows' __chkstk call to do stack probing.132WIN__DBZCHK, // Windows' divide by zero check133134WLS, // Low-overhead loops, While Loop Start branch. See t2WhileLoopStart135WLSSETUP, // Setup for the iteration count of a WLS. See t2WhileLoopSetup.136LOOP_DEC, // Really a part of LE, performs the sub137LE, // Low-overhead loops, Loop End138139PREDICATE_CAST, // Predicate cast for MVE i1 types140VECTOR_REG_CAST, // Reinterpret the current contents of a vector register141142MVESEXT, // Legalization aids for extending a vector into two/four vectors.143MVEZEXT, // or truncating two/four vectors into one. Eventually becomes144MVETRUNC, // stack store/load sequence, if not optimized to anything else.145146VCMP, // Vector compare.147VCMPZ, // Vector compare to zero.148VTST, // Vector test bits.149150// Vector shift by vector151VSHLs, // ...left/right by signed152VSHLu, // ...left/right by unsigned153154// Vector shift by immediate:155VSHLIMM, // ...left156VSHRsIMM, // ...right (signed)157VSHRuIMM, // ...right (unsigned)158159// Vector rounding shift by immediate:160VRSHRsIMM, // ...right (signed)161VRSHRuIMM, // ...right (unsigned)162VRSHRNIMM, // ...right narrow163164// Vector saturating shift by immediate:165VQSHLsIMM, // ...left (signed)166VQSHLuIMM, // ...left (unsigned)167VQSHLsuIMM, // ...left (signed to unsigned)168VQSHRNsIMM, // ...right narrow (signed)169VQSHRNuIMM, // ...right narrow (unsigned)170VQSHRNsuIMM, // ...right narrow (signed to unsigned)171172// Vector saturating rounding shift by immediate:173VQRSHRNsIMM, // ...right narrow (signed)174VQRSHRNuIMM, // ...right narrow (unsigned)175VQRSHRNsuIMM, // ...right narrow (signed to unsigned)176177// Vector shift and insert:178VSLIIMM, // ...left179VSRIIMM, // ...right180181// Vector get lane (VMOV scalar to ARM core register)182// (These are used for 8- and 16-bit element types only.)183VGETLANEu, // zero-extend vector extract element184VGETLANEs, // sign-extend vector extract element185186// Vector move immediate and move negated immediate:187VMOVIMM,188VMVNIMM,189190// Vector move f32 immediate:191VMOVFPIMM,192193// Move H <-> R, clearing top 16 bits194VMOVrh,195VMOVhr,196197// Vector duplicate:198VDUP,199VDUPLANE,200201// Vector shuffles:202VEXT, // extract203VREV64, // reverse elements within 64-bit doublewords204VREV32, // reverse elements within 32-bit words205VREV16, // reverse elements within 16-bit halfwords206VZIP, // zip (interleave)207VUZP, // unzip (deinterleave)208VTRN, // transpose209VTBL1, // 1-register shuffle with mask210VTBL2, // 2-register shuffle with mask211VMOVN, // MVE vmovn212213// MVE Saturating truncates214VQMOVNs, // Vector (V) Saturating (Q) Move and Narrow (N), signed (s)215VQMOVNu, // Vector (V) Saturating (Q) Move and Narrow (N), unsigned (u)216217// MVE float <> half converts218VCVTN, // MVE vcvt f32 -> f16, truncating into either the bottom or top219// lanes220VCVTL, // MVE vcvt f16 -> f32, extending from either the bottom or top lanes221222// MVE VIDUP instruction, taking a start value and increment.223VIDUP,224225// Vector multiply long:226VMULLs, // ...signed227VMULLu, // ...unsigned228229VQDMULH, // MVE vqdmulh instruction230231// MVE reductions232VADDVs, // sign- or zero-extend the elements of a vector to i32,233VADDVu, // add them all together, and return an i32 of their sum234VADDVps, // Same as VADDV[su] but with a v4i1 predicate mask235VADDVpu,236VADDLVs, // sign- or zero-extend elements to i64 and sum, returning237VADDLVu, // the low and high 32-bit halves of the sum238VADDLVAs, // Same as VADDLV[su] but also add an input accumulator239VADDLVAu, // provided as low and high halves240VADDLVps, // Same as VADDLV[su] but with a v4i1 predicate mask241VADDLVpu,242VADDLVAps, // Same as VADDLVp[su] but with a v4i1 predicate mask243VADDLVApu,244VMLAVs, // sign- or zero-extend the elements of two vectors to i32, multiply245VMLAVu, // them and add the results together, returning an i32 of the sum246VMLAVps, // Same as VMLAV[su] with a v4i1 predicate mask247VMLAVpu,248VMLALVs, // Same as VMLAV but with i64, returning the low and249VMLALVu, // high 32-bit halves of the sum250VMLALVps, // Same as VMLALV[su] with a v4i1 predicate mask251VMLALVpu,252VMLALVAs, // Same as VMLALV but also add an input accumulator253VMLALVAu, // provided as low and high halves254VMLALVAps, // Same as VMLALVA[su] with a v4i1 predicate mask255VMLALVApu,256VMINVu, // Find minimum unsigned value of a vector and register257VMINVs, // Find minimum signed value of a vector and register258VMAXVu, // Find maximum unsigned value of a vector and register259VMAXVs, // Find maximum signed value of a vector and register260261SMULWB, // Signed multiply word by half word, bottom262SMULWT, // Signed multiply word by half word, top263UMLAL, // 64bit Unsigned Accumulate Multiply264SMLAL, // 64bit Signed Accumulate Multiply265UMAAL, // 64-bit Unsigned Accumulate Accumulate Multiply266SMLALBB, // 64-bit signed accumulate multiply bottom, bottom 16267SMLALBT, // 64-bit signed accumulate multiply bottom, top 16268SMLALTB, // 64-bit signed accumulate multiply top, bottom 16269SMLALTT, // 64-bit signed accumulate multiply top, top 16270SMLALD, // Signed multiply accumulate long dual271SMLALDX, // Signed multiply accumulate long dual exchange272SMLSLD, // Signed multiply subtract long dual273SMLSLDX, // Signed multiply subtract long dual exchange274SMMLAR, // Signed multiply long, round and add275SMMLSR, // Signed multiply long, subtract and round276277// Single Lane QADD8 and QADD16. Only the bottom lane. That's what the b278// stands for.279QADD8b,280QSUB8b,281QADD16b,282QSUB16b,283UQADD8b,284UQSUB8b,285UQADD16b,286UQSUB16b,287288// Operands of the standard BUILD_VECTOR node are not legalized, which289// is fine if BUILD_VECTORs are always lowered to shuffles or other290// operations, but for ARM some BUILD_VECTORs are legal as-is and their291// operands need to be legalized. Define an ARM-specific version of292// BUILD_VECTOR for this purpose.293BUILD_VECTOR,294295// Bit-field insert296BFI,297298// Vector OR with immediate299VORRIMM,300// Vector AND with NOT of immediate301VBICIMM,302303// Pseudo vector bitwise select304VBSP,305306// Pseudo-instruction representing a memory copy using ldm/stm307// instructions.308MEMCPY,309310// Pseudo-instruction representing a memory copy using a tail predicated311// loop312MEMCPYLOOP,313// Pseudo-instruction representing a memset using a tail predicated314// loop315MEMSETLOOP,316317// V8.1MMainline condition select318CSINV, // Conditional select invert.319CSNEG, // Conditional select negate.320CSINC, // Conditional select increment.321322// Vector load N-element structure to all lanes:323VLD1DUP = ISD::FIRST_TARGET_MEMORY_OPCODE,324VLD2DUP,325VLD3DUP,326VLD4DUP,327328// NEON loads with post-increment base updates:329VLD1_UPD,330VLD2_UPD,331VLD3_UPD,332VLD4_UPD,333VLD2LN_UPD,334VLD3LN_UPD,335VLD4LN_UPD,336VLD1DUP_UPD,337VLD2DUP_UPD,338VLD3DUP_UPD,339VLD4DUP_UPD,340VLD1x2_UPD,341VLD1x3_UPD,342VLD1x4_UPD,343344// NEON stores with post-increment base updates:345VST1_UPD,346VST2_UPD,347VST3_UPD,348VST4_UPD,349VST2LN_UPD,350VST3LN_UPD,351VST4LN_UPD,352VST1x2_UPD,353VST1x3_UPD,354VST1x4_UPD,355356// Load/Store of dual registers357LDRD,358STRD359};360361} // end namespace ARMISD362363namespace ARM {364/// Possible values of current rounding mode, which is specified in bits365/// 23:22 of FPSCR.366enum Rounding {367RN = 0, // Round to Nearest368RP = 1, // Round towards Plus infinity369RM = 2, // Round towards Minus infinity370RZ = 3, // Round towards Zero371rmMask = 3 // Bit mask selecting rounding mode372};373374// Bit position of rounding mode bits in FPSCR.375const unsigned RoundingBitsPos = 22;376377// Bits of floating-point status. These are NZCV flags, QC bit and cumulative378// FP exception bits.379const unsigned FPStatusBits = 0xf800009f;380381// Some bits in the FPSCR are not yet defined. They must be preserved when382// modifying the contents.383const unsigned FPReservedBits = 0x00006060;384} // namespace ARM385386/// Define some predicates that are used for node matching.387namespace ARM {388389bool isBitFieldInvertedMask(unsigned v);390391} // end namespace ARM392393//===--------------------------------------------------------------------===//394// ARMTargetLowering - ARM Implementation of the TargetLowering interface395396class ARMTargetLowering : public TargetLowering {397public:398explicit ARMTargetLowering(const TargetMachine &TM,399const ARMSubtarget &STI);400401unsigned getJumpTableEncoding() const override;402bool useSoftFloat() const override;403404SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;405406/// ReplaceNodeResults - Replace the results of node with an illegal result407/// type with new values built out of custom code.408void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,409SelectionDAG &DAG) const override;410411const char *getTargetNodeName(unsigned Opcode) const override;412413bool isSelectSupported(SelectSupportKind Kind) const override {414// ARM does not support scalar condition selects on vectors.415return (Kind != ScalarCondVectorVal);416}417418bool isReadOnly(const GlobalValue *GV) const;419420/// getSetCCResultType - Return the value type to use for ISD::SETCC.421EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,422EVT VT) const override;423424MachineBasicBlock *425EmitInstrWithCustomInserter(MachineInstr &MI,426MachineBasicBlock *MBB) const override;427428void AdjustInstrPostInstrSelection(MachineInstr &MI,429SDNode *Node) const override;430431SDValue PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const;432SDValue PerformBRCONDCombine(SDNode *N, SelectionDAG &DAG) const;433SDValue PerformCMOVToBFICombine(SDNode *N, SelectionDAG &DAG) const;434SDValue PerformIntrinsicCombine(SDNode *N, DAGCombinerInfo &DCI) const;435SDValue PerformMVEExtCombine(SDNode *N, DAGCombinerInfo &DCI) const;436SDValue PerformMVETruncCombine(SDNode *N, DAGCombinerInfo &DCI) const;437SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;438439bool SimplifyDemandedBitsForTargetNode(SDValue Op,440const APInt &OriginalDemandedBits,441const APInt &OriginalDemandedElts,442KnownBits &Known,443TargetLoweringOpt &TLO,444unsigned Depth) const override;445446bool isDesirableToTransformToIntegerOp(unsigned Opc, EVT VT) const override;447448/// allowsMisalignedMemoryAccesses - Returns true if the target allows449/// unaligned memory accesses of the specified type. Returns whether it450/// is "fast" by reference in the second argument.451bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace,452Align Alignment,453MachineMemOperand::Flags Flags,454unsigned *Fast) const override;455456EVT getOptimalMemOpType(const MemOp &Op,457const AttributeList &FuncAttributes) const override;458459bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;460bool isTruncateFree(EVT SrcVT, EVT DstVT) const override;461bool isZExtFree(SDValue Val, EVT VT2) const override;462bool shouldSinkOperands(Instruction *I,463SmallVectorImpl<Use *> &Ops) const override;464Type* shouldConvertSplatType(ShuffleVectorInst* SVI) const override;465466bool isFNegFree(EVT VT) const override;467468bool isVectorLoadExtDesirable(SDValue ExtVal) const override;469470bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;471472473/// isLegalAddressingMode - Return true if the addressing mode represented474/// by AM is legal for this target, for a load/store of the specified type.475bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,476Type *Ty, unsigned AS,477Instruction *I = nullptr) const override;478479bool isLegalT2ScaledAddressingMode(const AddrMode &AM, EVT VT) const;480481/// Returns true if the addressing mode representing by AM is legal482/// for the Thumb1 target, for a load/store of the specified type.483bool isLegalT1ScaledAddressingMode(const AddrMode &AM, EVT VT) const;484485/// isLegalICmpImmediate - Return true if the specified immediate is legal486/// icmp immediate, that is the target has icmp instructions which can487/// compare a register against the immediate without having to materialize488/// the immediate into a register.489bool isLegalICmpImmediate(int64_t Imm) const override;490491/// isLegalAddImmediate - Return true if the specified immediate is legal492/// add immediate, that is the target has add instructions which can493/// add a register and the immediate without having to materialize494/// the immediate into a register.495bool isLegalAddImmediate(int64_t Imm) const override;496497/// getPreIndexedAddressParts - returns true by value, base pointer and498/// offset pointer and addressing mode by reference if the node's address499/// can be legally represented as pre-indexed load / store address.500bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, SDValue &Offset,501ISD::MemIndexedMode &AM,502SelectionDAG &DAG) const override;503504/// getPostIndexedAddressParts - returns true by value, base pointer and505/// offset pointer and addressing mode by reference if this node can be506/// combined with a load / store to form a post-indexed load / store.507bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base,508SDValue &Offset, ISD::MemIndexedMode &AM,509SelectionDAG &DAG) const override;510511void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known,512const APInt &DemandedElts,513const SelectionDAG &DAG,514unsigned Depth) const override;515516bool targetShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits,517const APInt &DemandedElts,518TargetLoweringOpt &TLO) const override;519520bool ExpandInlineAsm(CallInst *CI) const override;521522ConstraintType getConstraintType(StringRef Constraint) const override;523524/// Examine constraint string and operand type and determine a weight value.525/// The operand object must already have been set up with the operand type.526ConstraintWeight getSingleConstraintMatchWeight(527AsmOperandInfo &info, const char *constraint) const override;528529std::pair<unsigned, const TargetRegisterClass *>530getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,531StringRef Constraint, MVT VT) const override;532533const char *LowerXConstraint(EVT ConstraintVT) const override;534535/// LowerAsmOperandForConstraint - Lower the specified operand into the Ops536/// vector. If it is invalid, don't add anything to Ops. If hasMemory is537/// true it means one of the asm constraint of the inline asm instruction538/// being processed is 'm'.539void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint,540std::vector<SDValue> &Ops,541SelectionDAG &DAG) const override;542543InlineAsm::ConstraintCode544getInlineAsmMemConstraint(StringRef ConstraintCode) const override {545if (ConstraintCode == "Q")546return InlineAsm::ConstraintCode::Q;547if (ConstraintCode.size() == 2) {548if (ConstraintCode[0] == 'U') {549switch(ConstraintCode[1]) {550default:551break;552case 'm':553return InlineAsm::ConstraintCode::Um;554case 'n':555return InlineAsm::ConstraintCode::Un;556case 'q':557return InlineAsm::ConstraintCode::Uq;558case 's':559return InlineAsm::ConstraintCode::Us;560case 't':561return InlineAsm::ConstraintCode::Ut;562case 'v':563return InlineAsm::ConstraintCode::Uv;564case 'y':565return InlineAsm::ConstraintCode::Uy;566}567}568}569return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);570}571572const ARMSubtarget* getSubtarget() const {573return Subtarget;574}575576/// getRegClassFor - Return the register class that should be used for the577/// specified value type.578const TargetRegisterClass *579getRegClassFor(MVT VT, bool isDivergent = false) const override;580581bool shouldAlignPointerArgs(CallInst *CI, unsigned &MinSize,582Align &PrefAlign) const override;583584/// createFastISel - This method returns a target specific FastISel object,585/// or null if the target does not support "fast" ISel.586FastISel *createFastISel(FunctionLoweringInfo &funcInfo,587const TargetLibraryInfo *libInfo) const override;588589Sched::Preference getSchedulingPreference(SDNode *N) const override;590591bool preferZeroCompareBranch() const override { return true; }592593bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override;594595bool596isShuffleMaskLegal(ArrayRef<int> M, EVT VT) const override;597bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;598599/// isFPImmLegal - Returns true if the target can instruction select the600/// specified FP immediate natively. If false, the legalizer will601/// materialize the FP immediate as a load from a constant pool.602bool isFPImmLegal(const APFloat &Imm, EVT VT,603bool ForCodeSize = false) const override;604605bool getTgtMemIntrinsic(IntrinsicInfo &Info,606const CallInst &I,607MachineFunction &MF,608unsigned Intrinsic) const override;609610/// Returns true if it is beneficial to convert a load of a constant611/// to just the constant itself.612bool shouldConvertConstantLoadToIntImm(const APInt &Imm,613Type *Ty) const override;614615/// Return true if EXTRACT_SUBVECTOR is cheap for this result type616/// with this index.617bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,618unsigned Index) const override;619620bool shouldFormOverflowOp(unsigned Opcode, EVT VT,621bool MathUsed) const override {622// Using overflow ops for overflow checks only should beneficial on ARM.623return TargetLowering::shouldFormOverflowOp(Opcode, VT, true);624}625626bool shouldReassociateReduction(unsigned Opc, EVT VT) const override {627return Opc != ISD::VECREDUCE_ADD;628}629630/// Returns true if an argument of type Ty needs to be passed in a631/// contiguous block of registers in calling convention CallConv.632bool functionArgumentNeedsConsecutiveRegisters(633Type *Ty, CallingConv::ID CallConv, bool isVarArg,634const DataLayout &DL) const override;635636/// If a physical register, this returns the register that receives the637/// exception address on entry to an EH pad.638Register639getExceptionPointerRegister(const Constant *PersonalityFn) const override;640641/// If a physical register, this returns the register that receives the642/// exception typeid on entry to a landing pad.643Register644getExceptionSelectorRegister(const Constant *PersonalityFn) const override;645646Instruction *makeDMB(IRBuilderBase &Builder, ARM_MB::MemBOpt Domain) const;647Value *emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy, Value *Addr,648AtomicOrdering Ord) const override;649Value *emitStoreConditional(IRBuilderBase &Builder, Value *Val, Value *Addr,650AtomicOrdering Ord) const override;651652void653emitAtomicCmpXchgNoStoreLLBalance(IRBuilderBase &Builder) const override;654655Instruction *emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst,656AtomicOrdering Ord) const override;657Instruction *emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst,658AtomicOrdering Ord) const override;659660unsigned getMaxSupportedInterleaveFactor() const override;661662bool lowerInterleavedLoad(LoadInst *LI,663ArrayRef<ShuffleVectorInst *> Shuffles,664ArrayRef<unsigned> Indices,665unsigned Factor) const override;666bool lowerInterleavedStore(StoreInst *SI, ShuffleVectorInst *SVI,667unsigned Factor) const override;668669bool shouldInsertFencesForAtomic(const Instruction *I) const override;670TargetLoweringBase::AtomicExpansionKind671shouldExpandAtomicLoadInIR(LoadInst *LI) const override;672TargetLoweringBase::AtomicExpansionKind673shouldExpandAtomicStoreInIR(StoreInst *SI) const override;674TargetLoweringBase::AtomicExpansionKind675shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;676TargetLoweringBase::AtomicExpansionKind677shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const override;678679bool useLoadStackGuardNode() const override;680681void insertSSPDeclarations(Module &M) const override;682Value *getSDagStackGuard(const Module &M) const override;683Function *getSSPStackGuardCheck(const Module &M) const override;684685bool canCombineStoreAndExtract(Type *VectorTy, Value *Idx,686unsigned &Cost) const override;687688bool canMergeStoresTo(unsigned AddressSpace, EVT MemVT,689const MachineFunction &MF) const override {690// Do not merge to larger than i32.691return (MemVT.getSizeInBits() <= 32);692}693694bool isCheapToSpeculateCttz(Type *Ty) const override;695bool isCheapToSpeculateCtlz(Type *Ty) const override;696697bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {698return VT.isScalarInteger();699}700701bool supportSwiftError() const override {702return true;703}704705bool hasStandaloneRem(EVT VT) const override {706return HasStandaloneRem;707}708709ShiftLegalizationStrategy710preferredShiftLegalizationStrategy(SelectionDAG &DAG, SDNode *N,711unsigned ExpansionFactor) const override;712713CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool isVarArg) const;714CCAssignFn *CCAssignFnForReturn(CallingConv::ID CC, bool isVarArg) const;715716/// Returns true if \p VecTy is a legal interleaved access type. This717/// function checks the vector element type and the overall width of the718/// vector.719bool isLegalInterleavedAccessType(unsigned Factor, FixedVectorType *VecTy,720Align Alignment,721const DataLayout &DL) const;722723bool isMulAddWithConstProfitable(SDValue AddNode,724SDValue ConstNode) const override;725726bool alignLoopsWithOptSize() const override;727728/// Returns the number of interleaved accesses that will be generated when729/// lowering accesses of the given type.730unsigned getNumInterleavedAccesses(VectorType *VecTy,731const DataLayout &DL) const;732733void finalizeLowering(MachineFunction &MF) const override;734735/// Return the correct alignment for the current calling convention.736Align getABIAlignmentForCallingConv(Type *ArgTy,737const DataLayout &DL) const override;738739bool isDesirableToCommuteWithShift(const SDNode *N,740CombineLevel Level) const override;741742bool isDesirableToCommuteXorWithShift(const SDNode *N) const override;743744bool shouldFoldConstantShiftPairToMask(const SDNode *N,745CombineLevel Level) const override;746747bool shouldFoldSelectWithIdentityConstant(unsigned BinOpcode,748EVT VT) const override;749750bool preferIncOfAddToSubOfNot(EVT VT) const override;751752bool shouldConvertFpToSat(unsigned Op, EVT FPVT, EVT VT) const override;753754bool isComplexDeinterleavingSupported() const override;755bool isComplexDeinterleavingOperationSupported(756ComplexDeinterleavingOperation Operation, Type *Ty) const override;757758Value *createComplexDeinterleavingIR(759IRBuilderBase &B, ComplexDeinterleavingOperation OperationType,760ComplexDeinterleavingRotation Rotation, Value *InputA, Value *InputB,761Value *Accumulator = nullptr) const override;762763bool softPromoteHalfType() const override { return true; }764765bool useFPRegsForHalfType() const override { return true; }766767protected:768std::pair<const TargetRegisterClass *, uint8_t>769findRepresentativeClass(const TargetRegisterInfo *TRI,770MVT VT) const override;771772private:773/// Subtarget - Keep a pointer to the ARMSubtarget around so that we can774/// make the right decision when generating code for different targets.775const ARMSubtarget *Subtarget;776777const TargetRegisterInfo *RegInfo;778779const InstrItineraryData *Itins;780781// TODO: remove this, and have shouldInsertFencesForAtomic do the proper782// check.783bool InsertFencesForAtomic;784785bool HasStandaloneRem = true;786787void addTypeForNEON(MVT VT, MVT PromotedLdStVT);788void addDRTypeForNEON(MVT VT);789void addQRTypeForNEON(MVT VT);790std::pair<SDValue, SDValue> getARMXALUOOp(SDValue Op, SelectionDAG &DAG, SDValue &ARMcc) const;791792using RegsToPassVector = SmallVector<std::pair<unsigned, SDValue>, 8>;793794void PassF64ArgInRegs(const SDLoc &dl, SelectionDAG &DAG, SDValue Chain,795SDValue &Arg, RegsToPassVector &RegsToPass,796CCValAssign &VA, CCValAssign &NextVA,797SDValue &StackPtr,798SmallVectorImpl<SDValue> &MemOpChains,799bool IsTailCall,800int SPDiff) const;801SDValue GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA,802SDValue &Root, SelectionDAG &DAG,803const SDLoc &dl) const;804805CallingConv::ID getEffectiveCallingConv(CallingConv::ID CC,806bool isVarArg) const;807CCAssignFn *CCAssignFnForNode(CallingConv::ID CC, bool Return,808bool isVarArg) const;809std::pair<SDValue, MachinePointerInfo>810computeAddrForCallArg(const SDLoc &dl, SelectionDAG &DAG,811const CCValAssign &VA, SDValue StackPtr,812bool IsTailCall, int SPDiff) const;813SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;814SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;815SDValue LowerEH_SJLJ_SETUP_DISPATCH(SDValue Op, SelectionDAG &DAG) const;816SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG,817const ARMSubtarget *Subtarget) const;818SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG,819const ARMSubtarget *Subtarget) const;820SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;821SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;822SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;823SDValue LowerGlobalAddressDarwin(SDValue Op, SelectionDAG &DAG) const;824SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG) const;825SDValue LowerGlobalAddressWindows(SDValue Op, SelectionDAG &DAG) const;826SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;827SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,828SelectionDAG &DAG) const;829SDValue LowerToTLSExecModels(GlobalAddressSDNode *GA,830SelectionDAG &DAG,831TLSModel::Model model) const;832SDValue LowerGlobalTLSAddressDarwin(SDValue Op, SelectionDAG &DAG) const;833SDValue LowerGlobalTLSAddressWindows(SDValue Op, SelectionDAG &DAG) const;834SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;835SDValue LowerSignedALUO(SDValue Op, SelectionDAG &DAG) const;836SDValue LowerUnsignedALUO(SDValue Op, SelectionDAG &DAG) const;837SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;838SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;839SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;840SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;841SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;842SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;843SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;844SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;845SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;846SDValue LowerGET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;847SDValue LowerSET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;848SDValue LowerSET_FPMODE(SDValue Op, SelectionDAG &DAG) const;849SDValue LowerRESET_FPMODE(SDValue Op, SelectionDAG &DAG) const;850SDValue LowerConstantFP(SDValue Op, SelectionDAG &DAG,851const ARMSubtarget *ST) const;852SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG,853const ARMSubtarget *ST) const;854SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;855SDValue LowerFSINCOS(SDValue Op, SelectionDAG &DAG) const;856SDValue LowerDivRem(SDValue Op, SelectionDAG &DAG) const;857SDValue LowerDIV_Windows(SDValue Op, SelectionDAG &DAG, bool Signed) const;858void ExpandDIV_Windows(SDValue Op, SelectionDAG &DAG, bool Signed,859SmallVectorImpl<SDValue> &Results) const;860SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG,861const ARMSubtarget *Subtarget) const;862SDValue LowerWindowsDIVLibCall(SDValue Op, SelectionDAG &DAG, bool Signed,863SDValue &Chain) const;864SDValue LowerREM(SDNode *N, SelectionDAG &DAG) const;865SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;866SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;867SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;868SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const;869SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;870SDValue LowerFSETCC(SDValue Op, SelectionDAG &DAG) const;871SDValue LowerSPONENTRY(SDValue Op, SelectionDAG &DAG) const;872void LowerLOAD(SDNode *N, SmallVectorImpl<SDValue> &Results,873SelectionDAG &DAG) const;874875Register getRegisterByName(const char* RegName, LLT VT,876const MachineFunction &MF) const override;877878SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,879SmallVectorImpl<SDNode *> &Created) const override;880881bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,882EVT VT) const override;883884SDValue MoveToHPR(const SDLoc &dl, SelectionDAG &DAG, MVT LocVT, MVT ValVT,885SDValue Val) const;886SDValue MoveFromHPR(const SDLoc &dl, SelectionDAG &DAG, MVT LocVT,887MVT ValVT, SDValue Val) const;888889SDValue ReconstructShuffle(SDValue Op, SelectionDAG &DAG) const;890891SDValue LowerCallResult(SDValue Chain, SDValue InGlue,892CallingConv::ID CallConv, bool isVarArg,893const SmallVectorImpl<ISD::InputArg> &Ins,894const SDLoc &dl, SelectionDAG &DAG,895SmallVectorImpl<SDValue> &InVals, bool isThisReturn,896SDValue ThisVal, bool isCmseNSCall) const;897898bool supportSplitCSR(MachineFunction *MF) const override {899return MF->getFunction().getCallingConv() == CallingConv::CXX_FAST_TLS &&900MF->getFunction().hasFnAttribute(Attribute::NoUnwind);901}902903void initializeSplitCSR(MachineBasicBlock *Entry) const override;904void insertCopiesSplitCSR(905MachineBasicBlock *Entry,906const SmallVectorImpl<MachineBasicBlock *> &Exits) const override;907908bool splitValueIntoRegisterParts(909SelectionDAG & DAG, const SDLoc &DL, SDValue Val, SDValue *Parts,910unsigned NumParts, MVT PartVT, std::optional<CallingConv::ID> CC)911const override;912913SDValue joinRegisterPartsIntoValue(914SelectionDAG & DAG, const SDLoc &DL, const SDValue *Parts,915unsigned NumParts, MVT PartVT, EVT ValueVT,916std::optional<CallingConv::ID> CC) const override;917918SDValue919LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,920const SmallVectorImpl<ISD::InputArg> &Ins,921const SDLoc &dl, SelectionDAG &DAG,922SmallVectorImpl<SDValue> &InVals) const override;923924int StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG, const SDLoc &dl,925SDValue &Chain, const Value *OrigArg,926unsigned InRegsParamRecordIdx, int ArgOffset,927unsigned ArgSize) const;928929void VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,930const SDLoc &dl, SDValue &Chain,931unsigned ArgOffset, unsigned TotalArgRegsSaveSize,932bool ForceMutable = false) const;933934SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,935SmallVectorImpl<SDValue> &InVals) const override;936937/// HandleByVal - Target-specific cleanup for ByVal support.938void HandleByVal(CCState *, unsigned &, Align) const override;939940/// IsEligibleForTailCallOptimization - Check whether the call is eligible941/// for tail call optimization. Targets which want to do tail call942/// optimization should implement this function.943bool IsEligibleForTailCallOptimization(944TargetLowering::CallLoweringInfo &CLI, CCState &CCInfo,945SmallVectorImpl<CCValAssign> &ArgLocs, const bool isIndirect) const;946947bool CanLowerReturn(CallingConv::ID CallConv,948MachineFunction &MF, bool isVarArg,949const SmallVectorImpl<ISD::OutputArg> &Outs,950LLVMContext &Context) const override;951952SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,953const SmallVectorImpl<ISD::OutputArg> &Outs,954const SmallVectorImpl<SDValue> &OutVals,955const SDLoc &dl, SelectionDAG &DAG) const override;956957bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const override;958959bool mayBeEmittedAsTailCall(const CallInst *CI) const override;960961bool shouldConsiderGEPOffsetSplit() const override { return true; }962963bool isUnsupportedFloatingType(EVT VT) const;964965SDValue getCMOV(const SDLoc &dl, EVT VT, SDValue FalseVal, SDValue TrueVal,966SDValue ARMcc, SDValue CCR, SDValue Cmp,967SelectionDAG &DAG) const;968SDValue getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,969SDValue &ARMcc, SelectionDAG &DAG, const SDLoc &dl) const;970SDValue getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG,971const SDLoc &dl, bool Signaling = false) const;972SDValue duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const;973974SDValue OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const;975976void SetupEntryBlockForSjLj(MachineInstr &MI, MachineBasicBlock *MBB,977MachineBasicBlock *DispatchBB, int FI) const;978979void EmitSjLjDispatchBlock(MachineInstr &MI, MachineBasicBlock *MBB) const;980981MachineBasicBlock *EmitStructByval(MachineInstr &MI,982MachineBasicBlock *MBB) const;983984MachineBasicBlock *EmitLowered__chkstk(MachineInstr &MI,985MachineBasicBlock *MBB) const;986MachineBasicBlock *EmitLowered__dbzchk(MachineInstr &MI,987MachineBasicBlock *MBB) const;988void addMVEVectorTypes(bool HasMVEFP);989void addAllExtLoads(const MVT From, const MVT To, LegalizeAction Action);990void setAllExpand(MVT VT);991};992993enum VMOVModImmType {994VMOVModImm,995VMVNModImm,996MVEVMVNModImm,997OtherModImm998};9991000namespace ARM {10011002FastISel *createFastISel(FunctionLoweringInfo &funcInfo,1003const TargetLibraryInfo *libInfo);10041005} // end namespace ARM10061007} // end namespace llvm10081009#endif // LLVM_LIB_TARGET_ARM_ARMISELLOWERING_H101010111012