Skip to content

[TTI] Make all interface methods const (NFCI) #136598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/TargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2367,7 +2367,7 @@ class TargetTransformInfo::Concept {

template <typename T>
class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
T Impl;
const T Impl;

public:
Model(T Impl) : Impl(std::move(Impl)) {}
Expand Down
28 changes: 14 additions & 14 deletions llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class TargetTransformInfoImplBase {
}

bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
Align Alignment, unsigned AddrSpace) {
Align Alignment, unsigned AddrSpace) const {
return false;
}

Expand Down Expand Up @@ -440,7 +440,7 @@ class TargetTransformInfoImplBase {

bool enableSelectOptimize() const { return true; }

bool shouldTreatInstructionLikeSelect(const Instruction *I) {
bool shouldTreatInstructionLikeSelect(const Instruction *I) const {
// A select with two constant operands will usually be better left as a
// select.
using namespace llvm::PatternMatch;
Expand Down Expand Up @@ -747,7 +747,7 @@ class TargetTransformInfoImplBase {

unsigned getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
const APInt &DemandedDstElts,
TTI::TargetCostKind CostKind) {
TTI::TargetCostKind CostKind) const {
return 1;
}

Expand Down Expand Up @@ -1170,7 +1170,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {

InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr,
ArrayRef<const Value *> Operands, Type *AccessType,
TTI::TargetCostKind CostKind) {
TTI::TargetCostKind CostKind) const {
assert(PointeeType && Ptr && "can't get GEPCost of nullptr");
auto *BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
bool HasBaseReg = (BaseGV == nullptr);
Expand Down Expand Up @@ -1234,7 +1234,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {

// If the final address of the GEP is a legal addressing mode for the given
// access type, then we can fold it into its users.
if (static_cast<T *>(this)->isLegalAddressingMode(
if (static_cast<const T *>(this)->isLegalAddressingMode(
AccessType, const_cast<GlobalValue *>(BaseGV),
BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale,
Ptr->getType()->getPointerAddressSpace()))
Expand All @@ -1250,7 +1250,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
const Value *Base,
const TTI::PointersChainInfo &Info,
Type *AccessTy,
TTI::TargetCostKind CostKind) {
TTI::TargetCostKind CostKind) const {
InstructionCost Cost = TTI::TCC_Free;
// In the basic model we take into account GEP instructions only
// (although here can come alloca instruction, a value, constants and/or
Expand All @@ -1269,26 +1269,26 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
if (Info.isSameBase() && V != Base) {
if (GEP->hasAllConstantIndices())
continue;
Cost += static_cast<T *>(this)->getArithmeticInstrCost(
Cost += static_cast<const T *>(this)->getArithmeticInstrCost(
Instruction::Add, GEP->getType(), CostKind,
{TTI::OK_AnyValue, TTI::OP_None}, {TTI::OK_AnyValue, TTI::OP_None},
{});
} else {
SmallVector<const Value *> Indices(GEP->indices());
Cost += static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
GEP->getPointerOperand(),
Indices, AccessTy, CostKind);
Cost += static_cast<const T *>(this)->getGEPCost(
GEP->getSourceElementType(), GEP->getPointerOperand(), Indices,
AccessTy, CostKind);
}
}
return Cost;
}

InstructionCost getInstructionCost(const User *U,
ArrayRef<const Value *> Operands,
TTI::TargetCostKind CostKind) {
TTI::TargetCostKind CostKind) const {
using namespace llvm::PatternMatch;

auto *TargetTTI = static_cast<T *>(this);
auto *TargetTTI = static_cast<const T *>(this);
// Handle non-intrinsic calls, invokes, and callbr.
// FIXME: Unlikely to be true for anything but CodeSize.
auto *CB = dyn_cast<CallBase>(U);
Expand Down Expand Up @@ -1585,8 +1585,8 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
return CostKind == TTI::TCK_RecipThroughput ? -1 : TTI::TCC_Basic;
}

bool isExpensiveToSpeculativelyExecute(const Instruction *I) {
auto *TargetTTI = static_cast<T *>(this);
bool isExpensiveToSpeculativelyExecute(const Instruction *I) const {
auto *TargetTTI = static_cast<const T *>(this);
SmallVector<const Value *, 4> Ops(I->operand_values());
InstructionCost Cost = TargetTTI->getInstructionCost(
I, Ops, TargetTransformInfo::TCK_SizeAndLatency);
Expand Down
Loading
Loading