38 #define DEBUG_TYPE "armtti" 42 cl::desc(
"Enable the generation of masked loads and stores"));
46 cl::desc(
"Disable the generation of low-overhead loops"));
61 bool MatchExact = (CallerBits & ~InlineFeatureWhitelist) ==
62 (CalleeBits & ~InlineFeatureWhitelist);
65 bool MatchSubset = ((CallerBits & CalleeBits) & InlineFeatureWhitelist) ==
66 (CalleeBits & InlineFeatureWhitelist);
67 return MatchExact && MatchSubset;
80 if ((SImmVal >= 0 && SImmVal < 65536) ||
87 if ((SImmVal >= 0 && SImmVal < 65536) ||
94 if (Bits == 8 || (SImmVal >= 0 && SImmVal < 256))
118 if ((Opcode == Instruction::SDiv || Opcode == Instruction::UDiv ||
119 Opcode == Instruction::SRem || Opcode == Instruction::URem) &&
123 if (Opcode == Instruction::And) {
125 if (Imm == 255 || Imm == 65535)
135 if (Opcode == Instruction::ICmp && Imm.
isNegative() &&
138 if (ST->
isThumb2() && NegImm < 1<<12)
141 if (ST->
isThumb() && NegImm < 1<<8)
156 assert(ISD &&
"Invalid opcode");
170 return LT.first *
Entry->Cost;
208 if (
const auto *
Entry =
419 if (ST->
hasNEON() && (Opcode == Instruction::InsertElement ||
420 Opcode == Instruction::ExtractElement)) {
434 Opcode == Instruction::ExtractElement)) {
484 unsigned NumVectorInstToHideOverhead = 10;
485 int MaxMergeDistance = 64;
490 return NumVectorInstToHideOverhead;
503 if (
auto *VecTy = dyn_cast<VectorType>(DataTy)) {
505 if (VecTy->getNumElements() == 2)
510 if (VecWidth != 128 && VecTy->getElementType()->isFloatingPointTy())
515 return (EltWidth == 32 && (!Alignment || Alignment >= 4)) ||
516 (EltWidth == 16 && (!Alignment || Alignment >= 2)) ||
533 if (isa<VectorType>(Ty))
537 return ((EltWidth == 32 && (!Alignment || Alignment >= 4)) ||
538 (EltWidth == 16 && (!Alignment || Alignment >= 2)) || EltWidth == 8);
543 assert(MI &&
"MemcpyInst expected");
548 const unsigned LibCallCost = 4;
559 std::vector<EVT> MemOps;
565 MemOps, Limit, Size, DstAlign, SrcAlign,
false ,
566 false ,
false ,
false ,
569 return MemOps.size() * 2;
595 if (
const auto *
Entry =
597 return LT.first *
Entry->Cost;
617 if (
const auto *
Entry =
619 return LT.first *
Entry->Cost;
643 return LT.first *
Entry->Cost;
680 const unsigned FunctionCallDivCost = 20;
681 const unsigned ReciprocalDivCost = 10;
724 return LT.first *
Entry->Cost;
727 Opd1PropInfo, Opd2PropInfo);
745 auto LooksLikeAFreeShift = [&]() {
757 case Instruction::Sub:
758 case Instruction::And:
759 case Instruction::Xor:
760 case Instruction::Or:
761 case Instruction::ICmp:
767 if (LooksLikeAFreeShift())
779 return LT.first * BaseCost;
799 (Alignment && *Alignment !=
Align(16)) &&
808 return BaseCost * LT.first;
813 unsigned Alignment,
unsigned AddressSpace,
bool UseMaskForCond,
814 bool UseMaskForGaps) {
815 assert(Factor >= 2 &&
"Invalid interleave factor");
816 assert(isa<VectorType>(VecTy) &&
"Expect a vector type");
821 if (Factor <= TLI->getMaxSupportedInterleaveFactor() && !EltIs64Bits &&
822 !UseMaskForCond && !UseMaskForGaps) {
830 if (NumElts % Factor == 0 &&
845 Alignment, AddressSpace,
846 UseMaskForCond, UseMaskForGaps);
859 case Intrinsic::powi:
864 case Intrinsic::log10:
867 case Intrinsic::exp2:
869 case Intrinsic::sqrt:
870 case Intrinsic::fabs:
871 case Intrinsic::copysign:
872 case Intrinsic::floor:
873 case Intrinsic::ceil:
874 case Intrinsic::trunc:
875 case Intrinsic::rint:
876 case Intrinsic::nearbyint:
878 case Intrinsic::canonicalize:
879 case Intrinsic::lround:
880 case Intrinsic::llround:
881 case Intrinsic::lrint:
882 case Intrinsic::llrint:
891 case Intrinsic::masked_store:
892 case Intrinsic::masked_load:
893 case Intrinsic::masked_gather:
894 case Intrinsic::masked_scatter:
896 case Intrinsic::sadd_with_overflow:
897 case Intrinsic::uadd_with_overflow:
898 case Intrinsic::ssub_with_overflow:
899 case Intrinsic::usub_with_overflow:
900 case Intrinsic::sadd_sat:
901 case Intrinsic::uadd_sat:
902 case Intrinsic::ssub_sat:
903 case Intrinsic::usub_sat:
923 if (isa<SCEVCouldNotCompute>(BackedgeTakenCount))
926 const SCEV *TripCountSCEV =
945 if (
auto *Call = dyn_cast<CallInst>(&
I)) {
946 if (isa<IntrinsicInst>(Call)) {
947 if (
const Function *
F = Call->getCalledFunction())
955 switch (
I.getOpcode()) {
958 case Instruction::FPToSI:
959 case Instruction::FPToUI:
960 case Instruction::SIToFP:
961 case Instruction::UIToFP:
962 case Instruction::FPTrunc:
963 case Instruction::FPExt:
993 switch (
I.getOpcode()) {
996 case Instruction::Alloca:
1000 case Instruction::PHI:
1007 if (
I.getType()->isDoubleTy() && !ST->
hasFP64())
1018 if (
auto *Call = dyn_cast<IntrinsicInst>(&
I)) {
1019 switch (Call->getIntrinsicID()) {
1022 case Intrinsic::set_loop_iterations:
1023 case Intrinsic::test_set_loop_iterations:
1024 case Intrinsic::loop_decrement:
1025 case Intrinsic::loop_decrement_reg:
1034 auto ScanLoop = [&](
Loop *L) {
1036 for (
auto &
I : *BB) {
1037 if (MaybeCall(
I) || IsHardwareLoopIntrinsic(
I))
1045 for (
auto Inner : *L)
1046 if (!ScanLoop(Inner))
1068 if (isa<ICmpInst>(&I) && ++ICmpCount > 1)
1071 if (isa<FCmpInst>(&I))
1076 if (isa<FPExtInst>(&I) || isa<FPTruncInst>(&I))
1080 if (isa<SExtInst>(&I) || isa<ZExtInst>(&I) )
1085 if (isa<TruncInst>(&I) )
1109 LLVM_DEBUG(
dbgs() <<
"tail-predication: checking allowed instructions\n");
1112 for (
Instruction &
I : BB->instructionsWithoutDebug()) {
1113 if (isa<PHINode>(&
I))
1129 if (isa<StoreInst>(
I) || isa<LoadInst>(
I)) {
1130 Value *Ptr = isa<LoadInst>(
I) ?
I.getOperand(0) :
I.getOperand(1);
1135 if (Stride == 0 && NextStride == 1) {
1136 Stride = NextStride;
1139 if (Stride != NextStride) {
1141 "tail-predicate\n.");
1148 LLVM_DEBUG(
dbgs() <<
"tail-predication: all instructions allowed!\n");
1158 if (DisableTailPredication)
1169 LLVM_DEBUG(
dbgs() <<
"preferPredicateOverEpilogue: not a single block " 1174 assert(L->
empty() &&
"preferPredicateOverEpilogue: inner-loop expected");
1177 if (!HWLoopInfo.canAnalyze(*LI)) {
1178 LLVM_DEBUG(
dbgs() <<
"preferPredicateOverEpilogue: hardware-loop is not " 1186 LLVM_DEBUG(
dbgs() <<
"preferPredicateOverEpilogue: hardware-loop is not " 1191 if (!HWLoopInfo.isHardwareLoopCandidate(SE, *LI, *DT)) {
1192 LLVM_DEBUG(
dbgs() <<
"preferPredicateOverEpilogue: hardware-loop is not " 1221 <<
"Exit blocks: " << ExitingBlocks.
size() <<
"\n");
1225 if (ExitingBlocks.
size() > 2)
1237 for (
auto &
I : *BB) {
1240 if (
I.getType()->isVectorTy())
1243 if (isa<CallInst>(
I) || isa<InvokeInst>(
I)) {
1276 assert(isa<VectorType>(Ty) &&
"Expected Ty to be a vector type");
1282 case Instruction::FAdd:
1283 case Instruction::FMul:
1284 case Instruction::And:
1285 case Instruction::Or:
1286 case Instruction::Xor:
1287 case Instruction::Mul:
1288 case Instruction::FCmp:
1290 case Instruction::ICmp:
Type * getVectorElementType() const
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I=nullptr)
uint64_t getZExtValue() const
Get zero extended value.
This class represents lattice values for constants.
Cost tables and simple lookup functions.
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
unsigned getNumInterleavedAccesses(VectorType *VecTy, const DataLayout &DL) const
Returns the number of interleaved accesses that will be generated when lowering accesses of the given...
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract)
Estimate the overhead of scalarizing an instruction.
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool hasBranchPredictor() const
The main scalar evolution driver.
int64_t getPtrStride(PredicatedScalarEvolution &PSE, Value *Ptr, const Loop *Lp, const ValueToValueMap &StridesMap=ValueToValueMap(), bool Assume=false, bool ShouldCheckWrap=true)
If the pointer has a constant stride return it in units of its element size.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
unsigned getSourceAlignment() const
FIXME: Remove this function once transition to Align is over.
static uint64_t round(uint64_t Acc, uint64_t Input)
A cache of @llvm.assume calls within a function.
unsigned getSourceAddressSpace() const
LLVMContext & getContext() const
All values hold a context through their type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
Type Conversion Cost Table.
bool isThumb1Only() const
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
bool isVectorTy() const
True if this is an instance of VectorType.
Value * getLength() const
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
unsigned getBitWidth() const
Return the number of bits in the APInt.
int getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty)
bool findOptimalMemOpLowering(std::vector< EVT > &MemOps, unsigned Limit, uint64_t Size, unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc, bool AllowOverlap, unsigned DstAS, unsigned SrcAS, const AttributeList &FuncAttributes) const
Determines the optimal series of memory ops to replace the memset / memcpy.
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
bool isLoweredToCall(const Function *F)
unsigned getAddressComputationCost(Type *Ty, ScalarEvolution *, const SCEV *)
Type * getPointerElementType() const
const FeatureBitset & getFeatureBits() const
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
bool preferPredicateOverEpilogue(Loop *L, LoopInfo *LI, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *TLI, DominatorTree *DT, const LoopAccessInfo *LAI)
APInt getUnsignedRangeMax(const SCEV *S)
Determine the max of the unsigned range for a particular SCEV.
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
bool isIntegerTy() const
True if this is an instance of IntegerType.
unsigned getDestAlignment() const
FIXME: Remove this function once transition to Align is over.
const TypeConversionCostTblEntry * ConvertCostTableLookup(ArrayRef< TypeConversionCostTblEntry > Tbl, int ISD, MVT Dst, MVT Src)
Find in type conversion cost table, TypeTy must be comparable to CompareTy by ==. ...
mir Rename Register Operands
This file implements a class to represent arbitrary precision integral constant values and operations...
BlockT * getHeader() const
unsigned getActiveBits() const
Compute the number of active bits in the value.
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I)
int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
int64_t getSExtValue() const
Get sign extended value.
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
bool useReductionIntrinsic(unsigned Opcode, Type *Ty, TTI::ReductionFlags Flags) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const APInt & getValue() const
Return the constant as an APInt value reference.
AttributeList getAttributes() const
Return the attribute list for this Function.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Value * getOperand(unsigned i) const
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isNegative() const
Determine sign of this APInt.
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
initializer< Ty > init(const Ty &Val)
Type * getReturnType() const
Returns the type of the ret val.
bool isAllOnesValue() const
Determine if all bits are set.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
bool useSoftFloat() const override
Container class for subtarget features.
LLVM Basic Block Representation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
bool isThumbImmShiftedVal(unsigned V)
isThumbImmShiftedVal - Return true if the specified value can be obtained by left shifting a 8-bit im...
bool isPointerTy() const
True if this is an instance of PointerType.
const SCEV * getAddExpr(SmallVectorImpl< const SCEV *> &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool hasSlowLoadDSubregister() const
int getT2SOImmVal(unsigned Arg)
getT2SOImmVal - Given a 32-bit immediate, if it is something that can fit into a Thumb-2 shifter_oper...
bool isOperationLegalOrCustomOrPromote(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
const PredicatedScalarEvolution & getPSE() const
Used to add runtime SCEV checks.
Attributes of a target dependent hardware loop.
static double log2(double V)
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
void getExitingBlocks(SmallVectorImpl< BlockT *> &ExitingBlocks) const
Return all blocks inside the loop that have successors outside of the loop.
unsigned getMVEVectorCostFactor() const
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
const TargetMachine & getTargetMachine() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
bool isLegalInterleavedAccessType(unsigned Factor, VectorType *VecTy, const DataLayout &DL) const
Returns true if VecTy is a legal interleaved access type.
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo)
int getSOImmVal(unsigned Arg)
getSOImmVal - Given a 32-bit immediate, if it is something that can fit into an shifter_operand immed...
This is the shared class of boolean and integer constants.
Type * getType() const
Return the LLVM type of this SCEV expression.
Align max(MaybeAlign Lhs, Align Rhs)
bool hasFPARMv8Base() const
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
Provides information about what library functions are available for the current target.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
int getAddressComputationCost(Type *Val, ScalarEvolution *SE, const SCEV *Ptr)
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
Drive the analysis of memory accesses in the loop.
This class wraps the llvm.memcpy intrinsic.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getVectorNumElements() const
Class for arbitrary precision integers.
Select(COND, TRUEVAL, FALSEVAL).
ZERO_EXTEND - Used for integer types, zeroing the new bits.
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
const SCEV * getBackedgeTakenCount(const Loop *L, ExitCountKind Kind=Exact)
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCould...
int getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Op1Info=TTI::OK_AnyValue, TTI::OperandValueKind Op2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr)
bool isLegalMaskedGather(Type *Ty, MaybeAlign Alignment)
const CostTblEntry * CostTableLookup(ArrayRef< CostTblEntry > Tbl, int ISD, MVT Ty)
Find in cost table, TypeTy must be comparable to CompareTy by ==.
int getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
unsigned getNumBlocks() const
Get the number of blocks in this loop in constant time.
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
bool isVector() const
Return true if this is a vector value type.
int getMemcpyCost(const Instruction *I)
unsigned getDestAddressSpace() const
This class represents an analyzed expression in the program.
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getIntegerBitWidth() const
Represents a single loop in the control flow graph.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
StringRef getName() const
Return a constant reference to the value's name.
Establish a view to a call site for examination.
const Function * getParent() const
Return the enclosing method, or null if none.
int getIntImmCost(const APInt &Imm, Type *Ty)
bool isLegalMaskedLoad(Type *DataTy, MaybeAlign Alignment)
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
unsigned getMaxStoresPerMemmove(bool OptSize) const
Get maximum # of store operations permitted for llvm.memmove.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
LLVM Value Representation.
int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty)
bool hasMVEIntegerOps() const
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Primary interface to the complete machine description for the target machine.
bool hasOneUse() const
Return true if there is exactly one user of this value.
TRUNCATE - Completely drop the high bits.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
iterator_range< block_iterator > blocks() const
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
Return true if the specified loop has an analyzable loop-invariant backedge-taken count...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::pair< int, MVT > getTypeLegalizationCost(const DataLayout &DL, Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
const BasicBlock * getParent() const