|
LLVM 24.0.0git
|
#include "llvm/CodeGen/TargetLowering.h"#include "llvm/ADT/STLExtras.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/Analysis/VectorUtils.h"#include "llvm/CodeGen/Analysis.h"#include "llvm/CodeGen/CallingConvLower.h"#include "llvm/CodeGen/CodeGenCommonISel.h"#include "llvm/CodeGen/MachineFrameInfo.h"#include "llvm/CodeGen/MachineFunction.h"#include "llvm/CodeGen/MachineJumpTableInfo.h"#include "llvm/CodeGen/MachineRegisterInfo.h"#include "llvm/CodeGen/SDPatternMatch.h"#include "llvm/CodeGen/SelectionDAG.h"#include "llvm/CodeGen/TargetRegisterInfo.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/DerivedTypes.h"#include "llvm/IR/GlobalVariable.h"#include "llvm/IR/LLVMContext.h"#include "llvm/MC/MCAsmInfo.h"#include "llvm/MC/MCExpr.h"#include "llvm/Support/DivisionByConstantInfo.h"#include "llvm/Support/ErrorHandling.h"#include "llvm/Support/KnownBits.h"#include "llvm/Support/MathExtras.h"#include "llvm/Target/TargetMachine.h"#include <cctype>#include <deque>Go to the source code of this file.
Macros | |
| #define | FP_CMP_LIBCALL(BASE) |
Functions | |
| static bool | paramHasAttr (const CallBase &Call, unsigned ArgIdx, Attribute::AttrKind Kind) |
| static bool | paramHasAttr (const AttributeList &Attrs, unsigned ArgIdx, Attribute::AttrKind Kind) |
| static MaybeAlign | getParamStackAlign (const CallBase &Call, unsigned ArgIdx) |
| static MaybeAlign | getParamStackAlign (const AttributeList &Attrs, unsigned ArgIdx) |
| static MaybeAlign | getParamAlign (const CallBase &Call, unsigned ArgIdx) |
| static MaybeAlign | getParamAlign (const AttributeList &Attrs, unsigned ArgIdx) |
| template<typename SourceT> | |
| static void | setArgListEntryAttributes (TargetLoweringBase::ArgListEntry &Entry, const SourceT &Src, unsigned ArgIdx) |
| Set CallLoweringInfo attribute flags based on a call instruction and called function attributes. | |
| static std::pair< RTLIB::Libcall, ISD::CondCode > | selectFPCmpLibcall (const LibcallLoweringInfo &Libcalls, RTLIB::Libcall BoolLC, RTLIB::Libcall TriStateLC, RTLIB::Libcall GenericLC, ISD::CondCode TriStateCC) |
| Select the libcall and the condition code to test its result against 0 for an ordered floating-point compare. | |
| static SDValue | combineShiftToAVG (SDValue Op, TargetLowering::TargetLoweringOpt &TLO, const TargetLowering &TLI, const APInt &DemandedBits, const APInt &DemandedElts, unsigned Depth) |
| static APInt | getKnownUndefForVectorBinop (SDValue BO, SelectionDAG &DAG, const APInt &UndefOp0, const APInt &UndefOp1) |
| Given a vector binary operation and known undefined elements for each input operand, compute whether each element of the output is undefined. | |
| static SDValue | simplifySetCCWithCTPOP (const TargetLowering &TLI, EVT VT, SDValue N0, const APInt &C1, ISD::CondCode Cond, const SDLoc &dl, SelectionDAG &DAG) |
| static SDValue | foldSetCCWithRotate (EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, const SDLoc &dl, SelectionDAG &DAG) |
| static SDValue | foldSetCCWithFunnelShift (EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, const SDLoc &dl, SelectionDAG &DAG) |
| static unsigned | getConstraintPiority (TargetLowering::ConstraintType CT) |
| Return a number indicating our preference for chosing a type of constraint over another, for the purpose of sorting them. | |
| static bool | lowerImmediateIfPossible (TargetLowering::ConstraintPair &P, SDValue Op, SelectionDAG *DAG, const TargetLowering &TLI) |
| If we have an immediate, see if we can lower it. | |
| static SDValue | BuildExactSDIV (const TargetLowering &TLI, SDNode *N, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDNode * > &Created) |
| Given an exact SDIV by a constant, create a multiplication with the multiplicative inverse of the constant. | |
| static SDValue | BuildExactUDIV (const TargetLowering &TLI, SDNode *N, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDNode * > &Created) |
| Given an exact UDIV by a constant, create a multiplication with the multiplicative inverse of the constant. | |
| static void | turnVectorIntoSplatVector (MutableArrayRef< SDValue > Values, std::function< bool(SDValue)> Predicate, SDValue AlternativeReplacement=SDValue()) |
| If all values in Values that don't match the predicate are same 'splat' value, then replace all values with that splat value. | |
| static bool | isNonZeroModBitWidthOrUndef (SDValue Z, unsigned BW) |
| static bool | canNarrowCLMULToLegal (const TargetLowering &TLI, LLVMContext &Ctx, EVT VT, unsigned HalveDepth=0, unsigned TotalDepth=0) |
| Check if CLMUL on VT can eventually reach a type with legal CLMUL through a chain of halving decompositions (halving element width) and/or vector widening (doubling element count). | |
| static SDValue | isSpecificZeroAfterMaybeRounding (SelectionDAG &DAG, const TargetLowering &TLI, const SDLoc &DL, SDValue Val, FPClassTest FPClass) |
| static std::optional< bool > | isFCmpEqualZero (FPClassTest Test, const fltSemantics &Semantics, const MachineFunction &MF) |
| Returns a true value if if this FPClassTest can be performed with an ordered fcmp to 0, and a false value if it's an unordered fcmp to 0. | |
| static bool | canExpandVectorCTPOP (const TargetLowering &TLI, EVT VT) |
| static std::pair< SDValue, SDValue > | getLegalMaskAndStepVector (SDValue Mask, bool ZeroIsPoison, SDLoc DL, SelectionDAG &DAG) |
Returns a type-legalized version of Mask as the first item in the pair. | |
| static SDValue | clampDynamicVectorIndex (SelectionDAG &DAG, SDValue Idx, EVT VecVT, const SDLoc &dl, ElementCount SubEC) |
| static bool | canFoldStoreIntoLibCallOutputPointers (StoreSDNode *StoreNode, SDNode *FPNode) |
Given a store node StoreNode, return true if it is safe to fold that node into FPNode, which expands to a library call with output pointers. | |
| #define FP_CMP_LIBCALL | ( | BASE | ) |
Referenced by llvm::TargetLowering::softenSetCCOperands().
|
static |
Given an exact SDIV by a constant, create a multiplication with the multiplicative inverse of the constant.
Ref: "Hacker's Delight" by Henry Warren, 2nd Edition, p. 242
Definition at line 6637 of file TargetLowering.cpp.
References llvm::APInt::ashrInPlace(), assert(), llvm::ISD::BUILD_VECTOR, C(), llvm::APInt::countr_zero(), llvm::SDNodeFlags::Exact, llvm::SelectionDAG::getBuildVector(), llvm::SelectionDAG::getConstant(), llvm::SelectionDAG::getDataLayout(), llvm::SDValue::getNode(), llvm::SelectionDAG::getNode(), llvm::SDValue::getOpcode(), llvm::EVT::getScalarType(), llvm::TargetLoweringBase::getShiftAmountTy(), llvm::SelectionDAG::getSplatVector(), llvm::isa(), llvm::ISD::matchUnaryPredicate(), llvm::ISD::MUL, llvm::APInt::multiplicativeInverse(), N, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::ISD::SPLAT_VECTOR, and llvm::ISD::SRA.
Referenced by llvm::TargetLowering::BuildSDIV().
|
static |
Given an exact UDIV by a constant, create a multiplication with the multiplicative inverse of the constant.
Ref: "Hacker's Delight" by Henry Warren, 2nd Edition, p. 242
Definition at line 6698 of file TargetLowering.cpp.
References assert(), llvm::ISD::BUILD_VECTOR, C(), llvm::APInt::countr_zero(), llvm::SDNodeFlags::Exact, llvm::SelectionDAG::getBuildVector(), llvm::SelectionDAG::getConstant(), llvm::SelectionDAG::getDataLayout(), llvm::SDValue::getNode(), llvm::SelectionDAG::getNode(), llvm::SDValue::getOpcode(), llvm::EVT::getScalarType(), llvm::TargetLoweringBase::getShiftAmountTy(), llvm::SelectionDAG::getSplatVector(), llvm::isa(), llvm::APInt::lshrInPlace(), llvm::ISD::matchUnaryPredicate(), llvm::ISD::MUL, llvm::APInt::multiplicativeInverse(), N, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::ISD::SPLAT_VECTOR, and llvm::ISD::SRL.
Referenced by llvm::TargetLowering::BuildUDIV().
|
static |
Definition at line 10972 of file TargetLowering.cpp.
References llvm::ISD::ADD, llvm::ISD::AND, assert(), llvm::EVT::getScalarSizeInBits(), llvm::TargetLoweringBase::isOperationLegalOrCustom(), llvm::TargetLoweringBase::isOperationLegalOrCustomOrPromote(), llvm::EVT::isVector(), llvm::ISD::MUL, llvm::ISD::SRL, and llvm::ISD::SUB.
Referenced by llvm::TargetLowering::expandCTLZ(), llvm::TargetLowering::expandCTPOP(), and llvm::TargetLowering::expandCTTZ().
|
static |
Given a store node StoreNode, return true if it is safe to fold that node into FPNode, which expands to a library call with output pointers.
Definition at line 14046 of file TargetLowering.cpp.
References _, llvm::ISD::CALLSEQ_END, llvm::ISD::CALLSEQ_START, llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::SelectionDAG::getHasPredecessorMaxSteps(), llvm::SDNode::hasPredecessorHelper(), llvm::SmallPtrSetImpl< PtrType >::insert(), MaxSteps, llvm::SDNode::ops(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::SmallPtrSetImplBase::size().
Referenced by llvm::TargetLowering::expandMultipleResultFPLibCall().
|
static |
Check if CLMUL on VT can eventually reach a type with legal CLMUL through a chain of halving decompositions (halving element width) and/or vector widening (doubling element count).
This guides expansion strategy selection: if true, the halving/widening path produces better code than bit-by-bit.
HalveDepth tracks halving steps only (each creates ~4x more operations). Widening steps are cheap (O(1) pad/extract) and don't count. Limiting halvings to 2 prevents exponential blowup: 1 halving: ~4 sub-CLMULs (good, e.g. v8i16 -> v8i8) 2 halvings: ~16 sub-CLMULs (acceptable, e.g. v4i32 -> v4i16 -> v8i8) 3 halvings: ~64 sub-CLMULs (worse than bit-by-bit expansion)
Definition at line 8922 of file TargetLowering.cpp.
References canNarrowCLMULToLegal(), llvm::EVT::changeVectorElementType(), llvm::ISD::CLMUL, llvm::EVT::getDoubleNumVectorElementsVT(), llvm::EVT::getIntegerVT(), llvm::EVT::getScalarSizeInBits(), llvm::EVT::isFixedLengthVector(), llvm::TargetLoweringBase::isOperationLegalOrCustom(), and llvm::TargetLoweringBase::isTypeLegal().
Referenced by canNarrowCLMULToLegal(), and llvm::TargetLowering::expandCLMUL().
|
static |
Definition at line 12302 of file TargetLowering.cpp.
References llvm::ISD::AND, assert(), llvm::dyn_cast(), llvm::SelectionDAG::getConstant(), llvm::EVT::getFixedSizeInBits(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getKnownMinValue(), llvm::APInt::getLowBitsSet(), llvm::SelectionDAG::getNode(), llvm::EVT::getSizeInBits(), llvm::SDValue::getValueType(), llvm::EVT::getVectorMinNumElements(), llvm::SelectionDAG::getVScale(), Imm, llvm::EVT::isFixedLengthVector(), llvm::isPowerOf2_32(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable(), llvm::EVT::isScalableVector(), llvm::Log2_32(), llvm::ISD::SUB, llvm::Sub, llvm::ISD::UMIN, and llvm::ISD::USUBSAT.
Referenced by llvm::TargetLowering::getVectorSubVecPointer().
|
static |
Definition at line 1117 of file TargetLowering.cpp.
References A(), llvm::ISD::ADD, llvm::Add, assert(), llvm::ISD::AVGCEILS, llvm::ISD::AVGCEILU, llvm::ISD::AVGFLOORS, llvm::ISD::AVGFLOORU, llvm::bit_ceil(), llvm::SelectionDAG::computeKnownBits(), llvm::SelectionDAG::ComputeNumSignBits(), llvm::KnownBits::countMinLeadingZeros(), llvm::TargetLowering::TargetLoweringOpt::DAG, llvm::Depth, DL, llvm::SelectionDAG::getContext(), llvm::SelectionDAG::getExtOrTrunc(), llvm::EVT::getIntegerVT(), llvm::SelectionDAG::getNode(), llvm::SDValue::getOpcode(), llvm::SDValue::getOperand(), llvm::EVT::getScalarSizeInBits(), llvm::EVT::getVectorElementCount(), llvm::EVT::getVectorVT(), llvm::isa(), llvm::isConstOrConstSplat(), llvm::ConstantSDNode::isOne(), llvm::TargetLoweringBase::isOperationLegal(), llvm::EVT::isVector(), llvm::TargetLowering::TargetLoweringOpt::LegalOperations(), llvm::TargetLowering::TargetLoweringOpt::LegalTypes(), llvm_unreachable, llvm::ISD::SRA, llvm::ISD::SRL, and llvm::SelectionDAG::willNotOverflowAdd().
Referenced by llvm::TargetLowering::SimplifyDemandedBits().
|
static |
Definition at line 4823 of file TargetLowering.cpp.
References llvm::BitWidth, Cond, llvm::ISD::FSHL, llvm::ISD::FSHR, llvm::SelectionDAG::getConstant(), llvm::SelectionDAG::getNode(), llvm::SDValue::getOpcode(), llvm::SDValue::getOperand(), llvm::SDValue::getScalarValueSizeInBits(), llvm::SelectionDAG::getSetCC(), llvm::SDValue::getValueType(), llvm::SDValue::hasOneUse(), llvm::isConstOrConstSplat(), llvm::ConstantSDNode::isZero(), llvm::ISD::OR, llvm::Other, llvm::ISD::SETEQ, llvm::ISD::SETNE, llvm::ISD::SHL, llvm::ISD::SRL, uint64_t, X, and Y.
Referenced by llvm::TargetLowering::SimplifySetCC().
|
static |
Definition at line 4780 of file TargetLowering.cpp.
References Cond, llvm::SelectionDAG::getNode(), llvm::SDValue::getOpcode(), llvm::SDValue::getOperand(), llvm::SelectionDAG::getSetCC(), llvm::SDValue::getValueType(), llvm::SDValue::hasOneUse(), llvm::ConstantSDNode::isAllOnes(), llvm::isConstOrConstSplat(), llvm::ConstantSDNode::isZero(), llvm::ISD::OR, llvm::ISD::ROTL, llvm::ISD::ROTR, llvm::ISD::SETEQ, llvm::ISD::SETNE, and X.
Referenced by llvm::TargetLowering::SimplifySetCC().
|
static |
Return a number indicating our preference for chosing a type of constraint over another, for the purpose of sorting them.
Immediates are almost always preferrable (when they can be emitted). A higher return value means a stronger preference for one constraint type relative to another. FIXME: We should prefer registers over memory but doing so may lead to unrecoverable register exhaustion later. https://github.com/llvm/llvm-project/issues/20571
Definition at line 6414 of file TargetLowering.cpp.
References llvm::TargetLowering::C_Address, llvm::TargetLowering::C_Immediate, llvm::TargetLowering::C_Memory, llvm::TargetLowering::C_Other, llvm::TargetLowering::C_Register, llvm::TargetLowering::C_RegisterClass, llvm::TargetLowering::C_Unknown, and llvm_unreachable.
Referenced by llvm::TargetLowering::getConstraintPreferences().
|
static |
Given a vector binary operation and known undefined elements for each input operand, compute whether each element of the output is undefined.
Definition at line 3281 of file TargetLowering.cpp.
References assert(), C(), llvm::dyn_cast(), llvm::APInt::getBitWidth(), llvm::SelectionDAG::getNode(), llvm::SDValue::getOpcode(), llvm::SDNode::getOperand(), llvm::SDValue::getOperand(), llvm::SelectionDAG::getTargetLoweringInfo(), llvm::SelectionDAG::getUNDEF(), llvm::SDValue::getValueType(), llvm::EVT::getVectorElementType(), llvm::EVT::getVectorNumElements(), llvm::APInt::getZero(), llvm::isa(), llvm::TargetLoweringBase::isBinOp(), llvm::EVT::isFixedLengthVector(), isUndef(), llvm::SDValue::isUndef(), llvm::EVT::isVector(), and llvm::APInt::setBit().
Referenced by llvm::TargetLowering::SimplifyDemandedVectorElts().
|
static |
Returns a type-legalized version of Mask as the first item in the pair.
The second item contains a type-legalized step vector that's guaranteed to fit the number of elements in Mask. If the stepvector would require splitting, returns an empty SDValue as the second item to signal that the operation should be split instead.
Definition at line 11301 of file TargetLowering.cpp.
References llvm::EVT::changeVectorElementType(), DL, llvm::TargetLoweringBase::getBitWidthForCttzElements(), llvm::SelectionDAG::getConstant(), llvm::SelectionDAG::getContext(), llvm::SelectionDAG::getDataLayout(), llvm::EVT::getFixedSizeInBits(), llvm::MachineFunction::getFunction(), llvm::SelectionDAG::getInsertSubvector(), llvm::MVT::getIntegerVT(), llvm::SelectionDAG::getMachineFunction(), llvm::SelectionDAG::getPOISON(), llvm::EVT::getScalarType(), llvm::SelectionDAG::getStepVector(), llvm::SelectionDAG::getTargetLoweringInfo(), llvm::TargetLoweringBase::getTypeAction(), llvm::TargetLoweringBase::getTypeToTransformTo(), llvm::EVT::getVectorElementCount(), llvm::TargetLoweringBase::getVectorIdxTy(), llvm::EVT::getVectorNumElements(), llvm::EVT::getVectorVT(), llvm::getVScaleRange(), llvm::EVT::isScalableVector(), llvm::TargetLoweringBase::TypePromoteInteger, llvm::TargetLoweringBase::TypeSplitVector, llvm::TargetLoweringBase::TypeWidenVector, and uint64_t.
Referenced by llvm::TargetLowering::expandCttzElts(), and llvm::TargetLowering::expandVectorFindLastActive().
|
static |
Definition at line 141 of file TargetLowering.cpp.
|
static |
Definition at line 137 of file TargetLowering.cpp.
References Call.
Referenced by setArgListEntryAttributes().
|
static |
Definition at line 132 of file TargetLowering.cpp.
|
static |
Definition at line 128 of file TargetLowering.cpp.
References Call.
Referenced by setArgListEntryAttributes().
|
static |
Returns a true value if if this FPClassTest can be performed with an ordered fcmp to 0, and a false value if it's an unordered fcmp to 0.
Returns std::nullopt if it cannot be performed as a compare with 0.
Definition at line 10593 of file TargetLowering.cpp.
References llvm::fcNan, llvm::fcNone, llvm::fcSubnormal, llvm::fcZero, llvm::MachineFunction::getDenormalMode(), llvm::DenormalMode::IEEE, llvm::DenormalMode::Input, llvm::DenormalMode::inputsAreZero(), and llvm::Test.
Referenced by llvm::TargetLowering::expandIS_FPCLASS().
Definition at line 8764 of file TargetLowering.cpp.
References C(), and llvm::ISD::matchUnaryPredicate().
|
static |
Definition at line 10429 of file TargetLowering.cpp.
References llvm::EVT::changeElementType(), llvm::EVT::changeTypeToInteger(), DL, llvm::ISD::FP_ROUND, llvm::SelectionDAG::getContext(), llvm::SelectionDAG::getDataLayout(), llvm::SelectionDAG::getIntPtrConstant(), llvm::SelectionDAG::getNode(), llvm::TargetLoweringBase::getSetCCResultType(), llvm::SelectionDAG::getTargetConstant(), llvm::SDValue::getValueType(), llvm::ISD::IS_FPCLASS, llvm::TargetLoweringBase::isOperationLegalOrCustom(), and llvm::TargetLoweringBase::isTypeLegal().
Referenced by llvm::TargetLowering::expandFMINIMUM_FMAXIMUM(), and llvm::TargetLowering::expandFMINIMUMNUM_FMAXIMUMNUM().
|
static |
If we have an immediate, see if we can lower it.
Return true if we can, false otherwise.
Definition at line 6560 of file TargetLowering.cpp.
References assert(), llvm::TargetLowering::C_Immediate, llvm::TargetLowering::C_Other, llvm::TargetLowering::LowerAsmOperandForConstraint(), and P.
Referenced by llvm::TargetLowering::ComputeConstraintToUse().
|
static |
Definition at line 123 of file TargetLowering.cpp.
Definition at line 118 of file TargetLowering.cpp.
References Call.
Referenced by setArgListEntryAttributes().
|
static |
Select the libcall and the condition code to test its result against 0 for an ordered floating-point compare.
BoolLC is the boolean helper (result is 0/1). TriStateLC is the per-predicate three-way helper and GenericLC the generic single-symbol three-way helper (both return -1/0/1, tested against 0 with TriStateCC). The boolean form is preferred, then the per-predicate three-way, then the generic three-way.
Definition at line 390 of file TargetLowering.cpp.
References llvm::LibcallLoweringInfo::getLibcallImpl(), and llvm::ISD::SETNE.
Referenced by llvm::TargetLowering::softenSetCCOperands().
|
static |
Set CallLoweringInfo attribute flags based on a call instruction and called function attributes.
Definition at line 148 of file TargetLowering.cpp.
References assert(), getParamAlign(), getParamStackAlign(), and paramHasAttr().
Referenced by llvm::TargetLoweringBase::ArgListEntry::setAttributes(), and llvm::TargetLoweringBase::ArgListEntry::setAttributes().
|
static |
Definition at line 4706 of file TargetLowering.cpp.
References llvm::ISD::ADD, llvm::Add, llvm::ISD::AND, assert(), Cond, llvm::ISD::CTPOP, llvm::SelectionDAG::getAllOnesConstant(), llvm::SelectionDAG::getConstant(), llvm::TargetLoweringBase::getCustomCtpopCost(), llvm::APInt::getLimitedValue(), llvm::SelectionDAG::getNode(), llvm::SDValue::getOpcode(), llvm::SDValue::getOperand(), llvm::SDValue::getScalarValueSizeInBits(), llvm::SelectionDAG::getSetCC(), llvm::SDValue::hasOneUse(), llvm::TargetLoweringBase::isCtpopFast(), llvm::EVT::isInteger(), llvm::SelectionDAG::isKnownNeverZero(), llvm::EVT::isVector(), llvm::Log2_32(), Passes, RHS, llvm::ISD::SETEQ, llvm::ISD::SETNE, llvm::ISD::SETUGT, llvm::ISD::SETULE, llvm::ISD::SETULT, llvm::ISD::TRUNCATE, llvm::APInt::ugt(), llvm::ISD::XOR, and llvm::Xor.
Referenced by llvm::TargetLowering::SimplifySetCC().
|
static |
If all values in Values that don't match the predicate are same 'splat' value, then replace all values with that splat value.
Else, if AlternativeReplacement was provided, then replace all values that do match predicate with AlternativeReplacement value.
Definition at line 7280 of file TargetLowering.cpp.
References llvm::all_of(), llvm::find_if_not(), and llvm::Values.