[llvm] [TTI] Make the rest of TTI::Concept/TTI::Model methods const (NFC) (PR #136668)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 22 01:20:51 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Sergei Barannikov (s-barannikov)
<details>
<summary>Changes</summary>
This will simplify future changes.
---
Patch is 64.93 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/136668.diff
1 Files Affected:
- (modified) llvm/include/llvm/Analysis/TargetTransformInfo.h (+313-278)
``````````diff
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index b5d766c34d09d..5a74523d37e81 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -1923,7 +1923,7 @@ class TargetTransformInfo {
/// implementation in a type erased interface.
template <typename T> class Model;
- std::unique_ptr<Concept> TTIImpl;
+ std::unique_ptr<const Concept> TTIImpl;
};
class TargetTransformInfo::Concept {
@@ -1933,37 +1933,37 @@ class TargetTransformInfo::Concept {
virtual InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr,
ArrayRef<const Value *> Operands,
Type *AccessType,
- TTI::TargetCostKind CostKind) = 0;
+ TTI::TargetCostKind CostKind) const = 0;
virtual InstructionCost
getPointersChainCost(ArrayRef<const Value *> Ptrs, const Value *Base,
const TTI::PointersChainInfo &Info, Type *AccessTy,
- TTI::TargetCostKind CostKind) = 0;
+ TTI::TargetCostKind CostKind) const = 0;
virtual unsigned getInliningThresholdMultiplier() const = 0;
virtual unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const = 0;
virtual unsigned
getInliningCostBenefitAnalysisProfitableMultiplier() const = 0;
virtual int getInliningLastCallToStaticBonus() const = 0;
- virtual unsigned adjustInliningThreshold(const CallBase *CB) = 0;
+ virtual unsigned adjustInliningThreshold(const CallBase *CB) const = 0;
virtual int getInlinerVectorBonusPercent() const = 0;
virtual unsigned getCallerAllocaCost(const CallBase *CB,
const AllocaInst *AI) const = 0;
- virtual InstructionCost getMemcpyCost(const Instruction *I) = 0;
+ virtual InstructionCost getMemcpyCost(const Instruction *I) const = 0;
virtual uint64_t getMaxMemIntrinsicInlineSizeThreshold() const = 0;
virtual unsigned
getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize,
ProfileSummaryInfo *PSI,
- BlockFrequencyInfo *BFI) = 0;
+ BlockFrequencyInfo *BFI) const = 0;
virtual InstructionCost getInstructionCost(const User *U,
ArrayRef<const Value *> Operands,
- TargetCostKind CostKind) = 0;
- virtual BranchProbability getPredictableBranchThreshold() = 0;
- virtual InstructionCost getBranchMispredictPenalty() = 0;
- virtual bool hasBranchDivergence(const Function *F = nullptr) = 0;
- virtual bool isSourceOfDivergence(const Value *V) = 0;
- virtual bool isAlwaysUniform(const Value *V) = 0;
+ TargetCostKind CostKind) const = 0;
+ virtual BranchProbability getPredictableBranchThreshold() const = 0;
+ virtual InstructionCost getBranchMispredictPenalty() const = 0;
+ virtual bool hasBranchDivergence(const Function *F = nullptr) const = 0;
+ virtual bool isSourceOfDivergence(const Value *V) const = 0;
+ virtual bool isAlwaysUniform(const Value *V) const = 0;
virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const = 0;
- virtual unsigned getFlatAddressSpace() = 0;
+ virtual unsigned getFlatAddressSpace() const = 0;
virtual bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,
Intrinsic::ID IID) const = 0;
virtual bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
@@ -1976,140 +1976,150 @@ class TargetTransformInfo::Concept {
virtual Value *rewriteIntrinsicWithAddressSpace(IntrinsicInst *II,
Value *OldV,
Value *NewV) const = 0;
- virtual bool isLoweredToCall(const Function *F) = 0;
- virtual void getUnrollingPreferences(Loop *L, ScalarEvolution &,
- UnrollingPreferences &UP,
- OptimizationRemarkEmitter *ORE) = 0;
+ virtual bool isLoweredToCall(const Function *F) const = 0;
+ virtual void
+ getUnrollingPreferences(Loop *L, ScalarEvolution &, UnrollingPreferences &UP,
+ OptimizationRemarkEmitter *ORE) const = 0;
virtual void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
- PeelingPreferences &PP) = 0;
+ PeelingPreferences &PP) const = 0;
virtual bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
AssumptionCache &AC,
TargetLibraryInfo *LibInfo,
- HardwareLoopInfo &HWLoopInfo) = 0;
- virtual unsigned getEpilogueVectorizationMinVF() = 0;
- virtual bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) = 0;
+ HardwareLoopInfo &HWLoopInfo) const = 0;
+ virtual unsigned getEpilogueVectorizationMinVF() const = 0;
+ virtual bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) const = 0;
virtual TailFoldingStyle
- getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) = 0;
- virtual std::optional<Instruction *> instCombineIntrinsic(
- InstCombiner &IC, IntrinsicInst &II) = 0;
- virtual std::optional<Value *> simplifyDemandedUseBitsIntrinsic(
- InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask,
- KnownBits & Known, bool &KnownBitsComputed) = 0;
+ getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) const = 0;
+ virtual std::optional<Instruction *>
+ instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const = 0;
+ virtual std::optional<Value *>
+ simplifyDemandedUseBitsIntrinsic(InstCombiner &IC, IntrinsicInst &II,
+ APInt DemandedMask, KnownBits &Known,
+ bool &KnownBitsComputed) const = 0;
virtual std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
- InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts,
- APInt &UndefElts, APInt &UndefElts2, APInt &UndefElts3,
+ InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
+ APInt &UndefElts2, APInt &UndefElts3,
std::function<void(Instruction *, unsigned, APInt, APInt &)>
- SimplifyAndSetOp) = 0;
- virtual bool isLegalAddImmediate(int64_t Imm) = 0;
- virtual bool isLegalAddScalableImmediate(int64_t Imm) = 0;
- virtual bool isLegalICmpImmediate(int64_t Imm) = 0;
+ SimplifyAndSetOp) const = 0;
+ virtual bool isLegalAddImmediate(int64_t Imm) const = 0;
+ virtual bool isLegalAddScalableImmediate(int64_t Imm) const = 0;
+ virtual bool isLegalICmpImmediate(int64_t Imm) const = 0;
virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
int64_t BaseOffset, bool HasBaseReg,
int64_t Scale, unsigned AddrSpace,
Instruction *I,
- int64_t ScalableOffset) = 0;
+ int64_t ScalableOffset) const = 0;
virtual bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
- const TargetTransformInfo::LSRCost &C2) = 0;
- virtual bool isNumRegsMajorCostOfLSR() = 0;
+ const TargetTransformInfo::LSRCost &C2) const = 0;
+ virtual bool isNumRegsMajorCostOfLSR() const = 0;
virtual bool shouldDropLSRSolutionIfLessProfitable() const = 0;
- virtual bool isProfitableLSRChainElement(Instruction *I) = 0;
- virtual bool canMacroFuseCmp() = 0;
+ virtual bool isProfitableLSRChainElement(Instruction *I) const = 0;
+ virtual bool canMacroFuseCmp() const = 0;
virtual bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE,
LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC,
- TargetLibraryInfo *LibInfo) = 0;
+ TargetLibraryInfo *LibInfo) const = 0;
virtual AddressingModeKind
getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const = 0;
virtual bool isLegalMaskedStore(Type *DataType, Align Alignment,
- unsigned AddressSpace) = 0;
+ unsigned AddressSpace) const = 0;
virtual bool isLegalMaskedLoad(Type *DataType, Align Alignment,
- unsigned AddressSpace) = 0;
- virtual bool isLegalNTStore(Type *DataType, Align Alignment) = 0;
- virtual bool isLegalNTLoad(Type *DataType, Align Alignment) = 0;
+ unsigned AddressSpace) const = 0;
+ virtual bool isLegalNTStore(Type *DataType, Align Alignment) const = 0;
+ virtual bool isLegalNTLoad(Type *DataType, Align Alignment) const = 0;
virtual bool isLegalBroadcastLoad(Type *ElementTy,
ElementCount NumElements) const = 0;
- virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment) = 0;
- virtual bool isLegalMaskedGather(Type *DataType, Align Alignment) = 0;
+ virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment) const = 0;
+ virtual bool isLegalMaskedGather(Type *DataType, Align Alignment) const = 0;
virtual bool forceScalarizeMaskedGather(VectorType *DataType,
- Align Alignment) = 0;
+ Align Alignment) const = 0;
virtual bool forceScalarizeMaskedScatter(VectorType *DataType,
- Align Alignment) = 0;
- virtual bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) = 0;
- virtual bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) = 0;
- virtual bool isLegalStridedLoadStore(Type *DataType, Align Alignment) = 0;
+ Align Alignment) const = 0;
+ virtual bool isLegalMaskedCompressStore(Type *DataType,
+ Align Alignment) const = 0;
+ virtual bool isLegalMaskedExpandLoad(Type *DataType,
+ Align Alignment) const = 0;
+ virtual bool isLegalStridedLoadStore(Type *DataType,
+ Align Alignment) const = 0;
virtual bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
Align Alignment,
- unsigned AddrSpace) = 0;
+ unsigned AddrSpace) const = 0;
- virtual bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) = 0;
+ virtual bool isLegalMaskedVectorHistogram(Type *AddrType,
+ Type *DataType) const = 0;
virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
unsigned Opcode1,
const SmallBitVector &OpcodeMask) const = 0;
- virtual bool enableOrderedReductions() = 0;
- virtual bool hasDivRemOp(Type *DataType, bool IsSigned) = 0;
- virtual bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) = 0;
- virtual bool prefersVectorizedAddressing() = 0;
+ virtual bool enableOrderedReductions() const = 0;
+ virtual bool hasDivRemOp(Type *DataType, bool IsSigned) const = 0;
+ virtual bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const = 0;
+ virtual bool prefersVectorizedAddressing() const = 0;
virtual InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
StackOffset BaseOffset,
bool HasBaseReg, int64_t Scale,
- unsigned AddrSpace) = 0;
- virtual bool LSRWithInstrQueries() = 0;
- virtual bool isTruncateFree(Type *Ty1, Type *Ty2) = 0;
- virtual bool isProfitableToHoist(Instruction *I) = 0;
- virtual bool useAA() = 0;
+ unsigned AddrSpace) const = 0;
+ virtual bool LSRWithInstrQueries() const = 0;
+ virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const = 0;
+ virtual bool isProfitableToHoist(Instruction *I) const = 0;
+ virtual bool useAA() const = 0;
virtual bool isTypeLegal(Type *Ty) const = 0;
virtual unsigned getRegUsageForType(Type *Ty) const = 0;
- virtual bool shouldBuildLookupTables() = 0;
- virtual bool shouldBuildLookupTablesForConstant(Constant *C) = 0;
- virtual bool shouldBuildRelLookupTables() = 0;
- virtual bool useColdCCForColdCall(Function &F) = 0;
- virtual bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) = 0;
- virtual bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
- unsigned ScalarOpdIdx) = 0;
+ virtual bool shouldBuildLookupTables() const = 0;
+ virtual bool shouldBuildLookupTablesForConstant(Constant *C) const = 0;
+ virtual bool shouldBuildRelLookupTables() const = 0;
+ virtual bool useColdCCForColdCall(Function &F) const = 0;
+ virtual bool
+ isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) const = 0;
+ virtual bool
+ isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
+ unsigned ScalarOpdIdx) const = 0;
virtual bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
- int OpdIdx) = 0;
+ int OpdIdx) const = 0;
virtual bool
isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID,
- int RetIdx) = 0;
+ int RetIdx) const = 0;
virtual InstructionCost
getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts,
bool Insert, bool Extract, TargetCostKind CostKind,
- ArrayRef<Value *> VL = {}) = 0;
+ ArrayRef<Value *> VL = {}) const = 0;
virtual InstructionCost
getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
ArrayRef<Type *> Tys,
- TargetCostKind CostKind) = 0;
- virtual bool supportsEfficientVectorElementLoadStore() = 0;
- virtual bool supportsTailCalls() = 0;
- virtual bool supportsTailCallFor(const CallBase *CB) = 0;
- virtual bool enableAggressiveInterleaving(bool LoopHasReductions) = 0;
+ TargetCostKind CostKind) const = 0;
+ virtual bool supportsEfficientVectorElementLoadStore() const = 0;
+ virtual bool supportsTailCalls() const = 0;
+ virtual bool supportsTailCallFor(const CallBase *CB) const = 0;
+ virtual bool enableAggressiveInterleaving(bool LoopHasReductions) const = 0;
virtual MemCmpExpansionOptions
enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const = 0;
- virtual bool enableSelectOptimize() = 0;
- virtual bool shouldTreatInstructionLikeSelect(const Instruction *I) = 0;
- virtual bool enableInterleavedAccessVectorization() = 0;
- virtual bool enableMaskedInterleavedAccessVectorization() = 0;
- virtual bool isFPVectorizationPotentiallyUnsafe() = 0;
+ virtual bool enableSelectOptimize() const = 0;
+ virtual bool shouldTreatInstructionLikeSelect(const Instruction *I) const = 0;
+ virtual bool enableInterleavedAccessVectorization() const = 0;
+ virtual bool enableMaskedInterleavedAccessVectorization() const = 0;
+ virtual bool isFPVectorizationPotentiallyUnsafe() const = 0;
virtual bool allowsMisalignedMemoryAccesses(LLVMContext &Context,
unsigned BitWidth,
unsigned AddressSpace,
Align Alignment,
- unsigned *Fast) = 0;
- virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) = 0;
- virtual bool haveFastSqrt(Type *Ty) = 0;
- virtual bool isExpensiveToSpeculativelyExecute(const Instruction *I) = 0;
- virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) = 0;
- virtual InstructionCost getFPOpCost(Type *Ty) = 0;
+ unsigned *Fast) const = 0;
+ virtual PopcntSupportKind
+ getPopcntSupport(unsigned IntTyWidthInBit) const = 0;
+ virtual bool haveFastSqrt(Type *Ty) const = 0;
+ virtual bool
+ isExpensiveToSpeculativelyExecute(const Instruction *I) const = 0;
+ virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const = 0;
+ virtual InstructionCost getFPOpCost(Type *Ty) const = 0;
virtual InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
- const APInt &Imm, Type *Ty) = 0;
+ const APInt &Imm,
+ Type *Ty) const = 0;
virtual InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
- TargetCostKind CostKind) = 0;
- virtual InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
- const APInt &Imm, Type *Ty,
- TargetCostKind CostKind,
- Instruction *Inst = nullptr) = 0;
- virtual InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
- const APInt &Imm, Type *Ty,
- TargetCostKind CostKind) = 0;
+ TargetCostKind CostKind) const = 0;
+ virtual InstructionCost
+ getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty,
+ TargetCostKind CostKind,
+ Instruction *Inst = nullptr) const = 0;
+ virtual InstructionCost
+ getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
+ Type *Ty, TargetCostKind CostKind) const = 0;
virtual bool preferToKeepConstantsAttached(const Instruction &Inst,
const Function &Fn) const = 0;
virtual unsigned getNumberOfRegisters(unsigned ClassID) const = 0;
@@ -2130,7 +2140,7 @@ class TargetTransformInfo::Concept {
virtual unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
Type *ScalarValTy) const = 0;
virtual bool shouldConsiderAddressTypePromotion(
- const Instruction &I, bool &AllowPromotionWithoutCommonHeader) = 0;
+ const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const = 0;
virtual unsigned getCacheLineSize() const = 0;
virtual std::optional<unsigned> getCacheSize(CacheLevel Level) const = 0;
virtual std::optional<unsigned> getCacheAssociativity(CacheLevel Level)
@@ -2178,39 +2188,43 @@ class TargetTransformInfo::Concept {
PartialReductionExtendKind OpBExtend,
std::optional<unsigned> BinOp) const = 0;
- virtual unsigned getMaxInterleaveFactor(ElementCount VF) = 0;
- virtual InstructionCost getArithmeticInstrCost(
- unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
- OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
- ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0;
+ virtual unsigned getMaxInterleaveFactor(ElementCount VF) const = 0;
+ virtual InstructionCost
+ getArithmeticInstrCost(unsigned Opcode, Type *Ty,
+ TTI::TargetCostKind CostKind,
+ OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
+ ArrayRef<const Value *> Args,
+ const Instruction *CxtI = nullptr) const = 0;
virtual InstructionCost getAltInstrCost(
VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
const SmallBitVector &OpcodeMask,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const = 0;
- virtual InstructionCost
- getShuffleCost(ShuffleKind Kind, VectorType *Tp, ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/136668
More information about the llvm-commits
mailing list