Skip to content

Commit 3f4bd77

Browse files
committed
[TTI] Constify BasicTTImplBase::thisT()
And fix lots of compilation errors.
1 parent 788b50a commit 3f4bd77

25 files changed

+380
-355
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 50 additions & 44 deletions
Large diffs are not rendered by default.

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static InstructionCost getHistogramCost(const IntrinsicCostAttributes &ICA) {
577577

578578
InstructionCost
579579
AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
580-
TTI::TargetCostKind CostKind) {
580+
TTI::TargetCostKind CostKind) const {
581581
// The code-generator is currently not able to handle scalable vectors
582582
// of <vscale x 1 x eltty> yet, so return an invalid cost to avoid selecting
583583
// it. This change will be removed when code-generation for these types is
@@ -2806,7 +2806,7 @@ AArch64TTIImpl::getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const {
28062806

28072807
bool AArch64TTIImpl::isWideningInstruction(Type *DstTy, unsigned Opcode,
28082808
ArrayRef<const Value *> Args,
2809-
Type *SrcOverrideTy) {
2809+
Type *SrcOverrideTy) const {
28102810
// A helper that returns a vector type from the given type. The number of
28112811
// elements in type Ty determines the vector width.
28122812
auto toVectorTy = [&](Type *ArgTy) {
@@ -2903,7 +2903,7 @@ bool AArch64TTIImpl::isWideningInstruction(Type *DstTy, unsigned Opcode,
29032903
// trunc i16 (lshr (add %x, %y), 1) -> i8
29042904
//
29052905
bool AArch64TTIImpl::isExtPartOfAvgExpr(const Instruction *ExtUser, Type *Dst,
2906-
Type *Src) {
2906+
Type *Src) const {
29072907
// The source should be a legal vector type.
29082908
if (!Src->isVectorTy() || !TLI->isTypeLegal(TLI->getValueType(DL, Src)) ||
29092909
(Src->isScalableTy() && !ST->hasSVE2()))
@@ -2948,7 +2948,7 @@ InstructionCost AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
29482948
Type *Src,
29492949
TTI::CastContextHint CCH,
29502950
TTI::TargetCostKind CostKind,
2951-
const Instruction *I) {
2951+
const Instruction *I) const {
29522952
int ISD = TLI->InstructionOpcodeToISD(Opcode);
29532953
assert(ISD && "Invalid opcode");
29542954
// If the cast is observable, and it is used by a widening instruction (e.g.,
@@ -3619,7 +3619,7 @@ InstructionCost AArch64TTIImpl::getExtractWithExtendCost(unsigned Opcode,
36193619

36203620
InstructionCost AArch64TTIImpl::getCFInstrCost(unsigned Opcode,
36213621
TTI::TargetCostKind CostKind,
3622-
const Instruction *I) {
3622+
const Instruction *I) const {
36233623
if (CostKind != TTI::TCK_RecipThroughput)
36243624
return Opcode == Instruction::PHI ? 0 : 1;
36253625
assert(CostKind == TTI::TCK_RecipThroughput && "unexpected CostKind");
@@ -3630,7 +3630,7 @@ InstructionCost AArch64TTIImpl::getCFInstrCost(unsigned Opcode,
36303630
InstructionCost AArch64TTIImpl::getVectorInstrCostHelper(
36313631
unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
36323632
bool HasRealUse, const Instruction *I, Value *Scalar,
3633-
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) {
3633+
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) const {
36343634
assert(Val->isVectorTy() && "This must be a vector type");
36353635

36363636
if (Index != -1U) {
@@ -3802,7 +3802,7 @@ InstructionCost AArch64TTIImpl::getVectorInstrCostHelper(
38023802
InstructionCost AArch64TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
38033803
TTI::TargetCostKind CostKind,
38043804
unsigned Index, Value *Op0,
3805-
Value *Op1) {
3805+
Value *Op1) const {
38063806
bool HasRealUse =
38073807
Opcode == Instruction::InsertElement && Op0 && !isa<UndefValue>(Op0);
38083808
return getVectorInstrCostHelper(Opcode, Val, CostKind, Index, HasRealUse);
@@ -3826,7 +3826,7 @@ InstructionCost AArch64TTIImpl::getVectorInstrCost(const Instruction &I,
38263826

38273827
InstructionCost AArch64TTIImpl::getScalarizationOverhead(
38283828
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
3829-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL) {
3829+
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL) const {
38303830
if (isa<ScalableVectorType>(Ty))
38313831
return InstructionCost::getInvalid();
38323832
if (Ty->getElementType()->isFloatingPointTy())
@@ -3840,8 +3840,7 @@ InstructionCost AArch64TTIImpl::getScalarizationOverhead(
38403840
InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
38413841
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
38423842
TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
3843-
ArrayRef<const Value *> Args,
3844-
const Instruction *CxtI) {
3843+
ArrayRef<const Value *> Args, const Instruction *CxtI) const {
38453844

38463845
// The code-generator is currently not able to handle scalable vectors
38473846
// of <vscale x 1 x eltty> yet, so return an invalid cost to avoid selecting
@@ -4171,7 +4170,7 @@ InstructionCost AArch64TTIImpl::getAddressComputationCost(Type *Ty,
41714170
InstructionCost AArch64TTIImpl::getCmpSelInstrCost(
41724171
unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
41734172
TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info,
4174-
TTI::OperandValueInfo Op2Info, const Instruction *I) {
4173+
TTI::OperandValueInfo Op2Info, const Instruction *I) const {
41754174
// TODO: Handle other cost kinds.
41764175
if (CostKind != TTI::TCK_RecipThroughput)
41774176
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
@@ -4284,7 +4283,7 @@ bool AArch64TTIImpl::prefersVectorizedAddressing() const {
42844283
InstructionCost
42854284
AArch64TTIImpl::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
42864285
Align Alignment, unsigned AddressSpace,
4287-
TTI::TargetCostKind CostKind) {
4286+
TTI::TargetCostKind CostKind) const {
42884287
if (useNeonVector(Src))
42894288
return BaseT::getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
42904289
CostKind);
@@ -4331,7 +4330,7 @@ static unsigned getSVEGatherScatterOverhead(unsigned Opcode,
43314330

43324331
InstructionCost AArch64TTIImpl::getGatherScatterOpCost(
43334332
unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask,
4334-
Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I) {
4333+
Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I) const {
43354334
if (useNeonVector(DataTy) || !isLegalMaskedGatherScatter(DataTy))
43364335
return BaseT::getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
43374336
Alignment, CostKind, I);
@@ -4371,7 +4370,7 @@ InstructionCost AArch64TTIImpl::getMemoryOpCost(unsigned Opcode, Type *Ty,
43714370
unsigned AddressSpace,
43724371
TTI::TargetCostKind CostKind,
43734372
TTI::OperandValueInfo OpInfo,
4374-
const Instruction *I) {
4373+
const Instruction *I) const {
43754374
EVT VT = TLI->getValueType(DL, Ty, true);
43764375
// Type legalization can't handle structs
43774376
if (VT == MVT::Other)
@@ -4980,7 +4979,7 @@ bool AArch64TTIImpl::isLegalToVectorizeReduction(
49804979
InstructionCost
49814980
AArch64TTIImpl::getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty,
49824981
FastMathFlags FMF,
4983-
TTI::TargetCostKind CostKind) {
4982+
TTI::TargetCostKind CostKind) const {
49844983
// The code-generator is currently not able to handle scalable vectors
49854984
// of <vscale x 1 x eltty> yet, so return an invalid cost to avoid selecting
49864985
// it. This change will be removed when code-generation for these types is
@@ -5005,7 +5004,7 @@ AArch64TTIImpl::getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty,
50055004
}
50065005

50075006
InstructionCost AArch64TTIImpl::getArithmeticReductionCostSVE(
5008-
unsigned Opcode, VectorType *ValTy, TTI::TargetCostKind CostKind) {
5007+
unsigned Opcode, VectorType *ValTy, TTI::TargetCostKind CostKind) const {
50095008
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
50105009
InstructionCost LegalizationCost = 0;
50115010
if (LT.first > 1) {
@@ -5032,7 +5031,7 @@ InstructionCost AArch64TTIImpl::getArithmeticReductionCostSVE(
50325031
InstructionCost
50335032
AArch64TTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *ValTy,
50345033
std::optional<FastMathFlags> FMF,
5035-
TTI::TargetCostKind CostKind) {
5034+
TTI::TargetCostKind CostKind) const {
50365035
// The code-generator is currently not able to handle scalable vectors
50375036
// of <vscale x 1 x eltty> yet, so return an invalid cost to avoid selecting
50385037
// it. This change will be removed when code-generation for these types is
@@ -5207,8 +5206,9 @@ AArch64TTIImpl::getMulAccReductionCost(bool IsUnsigned, Type *ResTy,
52075206
return BaseT::getMulAccReductionCost(IsUnsigned, ResTy, VecTy, CostKind);
52085207
}
52095208

5210-
InstructionCost AArch64TTIImpl::getSpliceCost(VectorType *Tp, int Index,
5211-
TTI::TargetCostKind CostKind) {
5209+
InstructionCost
5210+
AArch64TTIImpl::getSpliceCost(VectorType *Tp, int Index,
5211+
TTI::TargetCostKind CostKind) const {
52125212
static const CostTblEntry ShuffleTbl[] = {
52135213
{ TTI::SK_Splice, MVT::nxv16i8, 1 },
52145214
{ TTI::SK_Splice, MVT::nxv8i16, 1 },
@@ -5340,7 +5340,7 @@ InstructionCost AArch64TTIImpl::getPartialReductionCost(
53405340
InstructionCost AArch64TTIImpl::getShuffleCost(
53415341
TTI::ShuffleKind Kind, VectorType *Tp, ArrayRef<int> Mask,
53425342
TTI::TargetCostKind CostKind, int Index, VectorType *SubTp,
5343-
ArrayRef<const Value *> Args, const Instruction *CxtI) {
5343+
ArrayRef<const Value *> Args, const Instruction *CxtI) const {
53445344
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Tp);
53455345

53465346
// If we have a Mask, and the LT is being legalized somehow, split the Mask

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
6161

6262
bool isWideningInstruction(Type *DstTy, unsigned Opcode,
6363
ArrayRef<const Value *> Args,
64-
Type *SrcOverrideTy = nullptr);
64+
Type *SrcOverrideTy = nullptr) const;
6565

6666
// A helper function called by 'getVectorInstrCost'.
6767
//
@@ -75,7 +75,7 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
7575
InstructionCost getVectorInstrCostHelper(
7676
unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
7777
bool HasRealUse, const Instruction *I = nullptr, Value *Scalar = nullptr,
78-
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx = {});
78+
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx = {}) const;
7979

8080
public:
8181
explicit AArch64TTIImpl(const AArch64TargetMachine *TM, const Function &F)
@@ -131,7 +131,7 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
131131
}
132132

133133
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
134-
TTI::TargetCostKind CostKind);
134+
TTI::TargetCostKind CostKind) const;
135135

136136
std::optional<Instruction *> instCombineIntrinsic(InstCombiner &IC,
137137
IntrinsicInst &II) const;
@@ -173,30 +173,32 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
173173

174174
InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
175175
Align Alignment, unsigned AddressSpace,
176-
TTI::TargetCostKind CostKind);
176+
TTI::TargetCostKind CostKind) const;
177177

178178
InstructionCost getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
179179
const Value *Ptr, bool VariableMask,
180180
Align Alignment,
181181
TTI::TargetCostKind CostKind,
182-
const Instruction *I = nullptr);
182+
const Instruction *I = nullptr) const;
183183

184-
bool isExtPartOfAvgExpr(const Instruction *ExtUser, Type *Dst, Type *Src);
184+
bool isExtPartOfAvgExpr(const Instruction *ExtUser, Type *Dst,
185+
Type *Src) const;
185186

186187
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
187188
TTI::CastContextHint CCH,
188189
TTI::TargetCostKind CostKind,
189-
const Instruction *I = nullptr);
190+
const Instruction *I = nullptr) const;
190191

191192
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
192193
VectorType *VecTy, unsigned Index);
193194

194195
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
195-
const Instruction *I = nullptr);
196+
const Instruction *I = nullptr) const;
196197

197198
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
198199
TTI::TargetCostKind CostKind,
199-
unsigned Index, Value *Op0, Value *Op1);
200+
unsigned Index, Value *Op0,
201+
Value *Op1) const;
200202

201203
/// \param ScalarUserAndIdx encodes the information about extracts from a
202204
/// vector with 'Scalar' being the value being extracted,'User' being the user
@@ -213,20 +215,21 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
213215

214216
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty,
215217
FastMathFlags FMF,
216-
TTI::TargetCostKind CostKind);
218+
TTI::TargetCostKind CostKind) const;
217219

218-
InstructionCost getArithmeticReductionCostSVE(unsigned Opcode,
219-
VectorType *ValTy,
220-
TTI::TargetCostKind CostKind);
220+
InstructionCost
221+
getArithmeticReductionCostSVE(unsigned Opcode, VectorType *ValTy,
222+
TTI::TargetCostKind CostKind) const;
221223

222224
InstructionCost getSpliceCost(VectorType *Tp, int Index,
223-
TTI::TargetCostKind CostKind);
225+
TTI::TargetCostKind CostKind) const;
224226

225227
InstructionCost getArithmeticInstrCost(
226228
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
227229
TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
228230
TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
229-
ArrayRef<const Value *> Args = {}, const Instruction *CxtI = nullptr);
231+
ArrayRef<const Value *> Args = {},
232+
const Instruction *CxtI = nullptr) const;
230233

231234
InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *SE,
232235
const SCEV *Ptr);
@@ -236,17 +239,17 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
236239
TTI::TargetCostKind CostKind,
237240
TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
238241
TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
239-
const Instruction *I = nullptr);
242+
const Instruction *I = nullptr) const;
240243

241244
TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,
242245
bool IsZeroCmp) const;
243246
bool useNeonVector(const Type *Ty) const;
244247

245-
InstructionCost
246-
getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment,
247-
unsigned AddressSpace, TTI::TargetCostKind CostKind,
248-
TTI::OperandValueInfo OpInfo = {TTI::OK_AnyValue, TTI::OP_None},
249-
const Instruction *I = nullptr);
248+
InstructionCost getMemoryOpCost(
249+
unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace,
250+
TTI::TargetCostKind CostKind,
251+
TTI::OperandValueInfo OpInfo = {TTI::OK_AnyValue, TTI::OP_None},
252+
const Instruction *I = nullptr) const;
250253

251254
InstructionCost getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys);
252255

@@ -423,9 +426,10 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
423426
return ST->hasSVE();
424427
}
425428

426-
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
427-
std::optional<FastMathFlags> FMF,
428-
TTI::TargetCostKind CostKind);
429+
InstructionCost
430+
getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
431+
std::optional<FastMathFlags> FMF,
432+
TTI::TargetCostKind CostKind) const;
429433

430434
InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned,
431435
Type *ResTy, VectorType *ValTy,
@@ -441,13 +445,13 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
441445
TTI::TargetCostKind CostKind, int Index,
442446
VectorType *SubTp,
443447
ArrayRef<const Value *> Args = {},
444-
const Instruction *CxtI = nullptr);
448+
const Instruction *CxtI = nullptr) const;
445449

446450
InstructionCost getScalarizationOverhead(VectorType *Ty,
447451
const APInt &DemandedElts,
448452
bool Insert, bool Extract,
449453
TTI::TargetCostKind CostKind,
450-
ArrayRef<Value *> VL = {});
454+
ArrayRef<Value *> VL = {}) const;
451455

452456
/// Return the cost of the scaling factor used in the addressing
453457
/// mode represented by AM for this target, for a load/store

0 commit comments

Comments
 (0)