[llvm] 2f56e1c - NFC: Change getTypeBasedIntrinsicCost to return InstructionCost
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 31 06:05:45 PDT 2021
Author: Sander de Smalen
Date: 2021-03-31T14:04:41+01:00
New Revision: 2f56e1c6b1370f48877acbd774638e451685f6db
URL: https://github.com/llvm/llvm-project/commit/2f56e1c6b1370f48877acbd774638e451685f6db
DIFF: https://github.com/llvm/llvm-project/commit/2f56e1c6b1370f48877acbd774638e451685f6db.diff
LOG: NFC: Change getTypeBasedIntrinsicCost to return InstructionCost
This patch migrates the TTI cost interfaces to return an InstructionCost.
See this patch for the introduction of the type: https://reviews.llvm.org/D91174
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html
Depends on D97466
Reviewed By: dmgreen
Differential Revision: https://reviews.llvm.org/D97468
Added:
Modified:
llvm/include/llvm/CodeGen/BasicTTIImpl.h
llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
llvm/lib/Target/X86/X86TargetTransformInfo.cpp
llvm/lib/Target/X86/X86TargetTransformInfo.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 8aabb597f025..cb6ddb7ae9c2 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -1207,7 +1207,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
return TargetTransformInfo::TCC_Basic;
if (ICA.isTypeBasedOnly())
- return getTypeBasedIntrinsicInstrCost(ICA, CostKind);
+ return *getTypeBasedIntrinsicInstrCost(ICA, CostKind).getValue();
Type *RetTy = ICA.getReturnType();
@@ -1294,13 +1294,13 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
case Intrinsic::vector_reduce_umax:
case Intrinsic::vector_reduce_umin: {
IntrinsicCostAttributes Attrs(IID, RetTy, Args[0]->getType(), FMF, I, 1);
- return getTypeBasedIntrinsicInstrCost(Attrs, CostKind);
+ return *getTypeBasedIntrinsicInstrCost(Attrs, CostKind).getValue();
}
case Intrinsic::vector_reduce_fadd:
case Intrinsic::vector_reduce_fmul: {
IntrinsicCostAttributes Attrs(
IID, RetTy, {Args[0]->getType(), Args[1]->getType()}, FMF, I, 1);
- return getTypeBasedIntrinsicInstrCost(Attrs, CostKind);
+ return *getTypeBasedIntrinsicInstrCost(Attrs, CostKind).getValue();
}
case Intrinsic::fshl:
case Intrinsic::fshr: {
@@ -1365,15 +1365,16 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
IntrinsicCostAttributes Attrs(IID, RetTy, ICA.getArgTypes(), FMF, I,
ScalarizationCost);
- return thisT()->getTypeBasedIntrinsicInstrCost(Attrs, CostKind);
+ return *thisT()->getTypeBasedIntrinsicInstrCost(Attrs, CostKind).getValue();
}
/// Get intrinsic cost based on argument types.
/// If ScalarizationCostPassed is std::numeric_limits<unsigned>::max(), the
/// cost of scalarizing the arguments and the return value will be computed
/// based on types.
- unsigned getTypeBasedIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
- TTI::TargetCostKind CostKind) {
+ InstructionCost
+ getTypeBasedIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
+ TTI::TargetCostKind CostKind) {
Intrinsic::ID IID = ICA.getID();
Type *RetTy = ICA.getReturnType();
const SmallVectorImpl<Type *> &Tys = ICA.getArgTypes();
@@ -1399,7 +1400,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
switch (IID) {
default: {
// Assume that we need to scalarize this intrinsic.
- unsigned ScalarizationCost = ScalarizationCostPassed;
+ InstructionCost ScalarizationCost = ScalarizationCostPassed;
unsigned ScalarCalls = 1;
Type *ScalarRetTy = RetTy;
if (auto *RetVTy = dyn_cast<VectorType>(RetTy)) {
@@ -1425,7 +1426,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
return 1; // Return cost of a scalar intrinsic. Assume it to be cheap.
IntrinsicCostAttributes ScalarAttrs(IID, ScalarRetTy, ScalarTys, FMF);
- unsigned ScalarCost =
+ InstructionCost ScalarCost =
thisT()->getIntrinsicInstrCost(ScalarAttrs, CostKind);
return ScalarCalls * ScalarCost + ScalarizationCost;
@@ -1605,7 +1606,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
// SatMax -> Overflow && SumDiff < 0
// SatMin -> Overflow && SumDiff >= 0
- unsigned Cost = 0;
+ InstructionCost Cost = 0;
IntrinsicCostAttributes Attrs(OverflowOp, OpTy, {RetTy, RetTy}, FMF,
nullptr, ScalarizationCostPassed);
Cost += thisT()->getIntrinsicInstrCost(Attrs, CostKind);
@@ -1626,7 +1627,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
? Intrinsic::uadd_with_overflow
: Intrinsic::usub_with_overflow;
- unsigned Cost = 0;
+ InstructionCost Cost = 0;
IntrinsicCostAttributes Attrs(OverflowOp, OpTy, {RetTy, RetTy}, FMF,
nullptr, ScalarizationCostPassed);
Cost += thisT()->getIntrinsicInstrCost(Attrs, CostKind);
@@ -1644,7 +1645,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
IID == Intrinsic::smul_fix ? Instruction::SExt : Instruction::ZExt;
TTI::CastContextHint CCH = TTI::CastContextHint::None;
- unsigned Cost = 0;
+ InstructionCost Cost = 0;
Cost += 2 * thisT()->getCastInstrCost(ExtOp, ExtTy, RetTy, CCH, CostKind);
Cost +=
thisT()->getArithmeticInstrCost(Instruction::Mul, ExtTy, CostKind);
@@ -1713,7 +1714,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
IID == Intrinsic::smul_fix ? Instruction::SExt : Instruction::ZExt;
TTI::CastContextHint CCH = TTI::CastContextHint::None;
- unsigned Cost = 0;
+ InstructionCost Cost = 0;
Cost += 2 * thisT()->getCastInstrCost(ExtOp, ExtTy, MulTy, CCH, CostKind);
Cost +=
thisT()->getArithmeticInstrCost(Instruction::Mul, ExtTy, CostKind);
@@ -1821,7 +1822,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
ScalarTys.push_back(Ty);
}
IntrinsicCostAttributes Attrs(IID, RetTy->getScalarType(), ScalarTys, FMF);
- unsigned ScalarCost = thisT()->getIntrinsicInstrCost(Attrs, CostKind);
+ InstructionCost ScalarCost =
+ thisT()->getIntrinsicInstrCost(Attrs, CostKind);
for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
if (auto *VTy = dyn_cast<VectorType>(Tys[i])) {
if (!ICA.skipScalarizationCost())
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
index ebc685207fe1..6a2cff3186f7 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
@@ -743,7 +743,7 @@ int GCNTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
// TODO: Combine these two logic paths.
if (ICA.isTypeBasedOnly())
- return getTypeBasedIntrinsicInstrCost(ICA, CostKind);
+ return *getTypeBasedIntrinsicInstrCost(ICA, CostKind).getValue();
unsigned RetVF =
(RetTy->isVectorTy() ? cast<FixedVectorType>(RetTy)->getNumElements()
diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
index 0a9582edd211..03a71fc2d4a1 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -2284,8 +2284,9 @@ int X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
unsigned X86TTIImpl::getAtomicMemIntrinsicMaxElementSize() const { return 16; }
-int X86TTIImpl::getTypeBasedIntrinsicInstrCost(
- const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) {
+InstructionCost
+X86TTIImpl::getTypeBasedIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
+ TTI::TargetCostKind CostKind) {
// Costs should match the codegen from:
// BITREVERSE: llvm\test\CodeGen\X86\vector-bitreverse.ll
@@ -2914,7 +2915,7 @@ int X86TTIImpl::getTypeBasedIntrinsicInstrCost(
int X86TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
TTI::TargetCostKind CostKind) {
if (ICA.isTypeBasedOnly())
- return getTypeBasedIntrinsicInstrCost(ICA, CostKind);
+ return *getTypeBasedIntrinsicInstrCost(ICA, CostKind).getValue();
static const CostTblEntry AVX512CostTbl[] = {
{ ISD::ROTL, MVT::v8i64, 1 },
diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.h b/llvm/lib/Target/X86/X86TargetTransformInfo.h
index 8b2f919347c7..eab4654b2f95 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.h
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.h
@@ -167,8 +167,9 @@ class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
unsigned getAtomicMemIntrinsicMaxElementSize() const;
- int getTypeBasedIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
- TTI::TargetCostKind CostKind);
+ InstructionCost
+ getTypeBasedIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
+ TTI::TargetCostKind CostKind);
int getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
TTI::TargetCostKind CostKind);
More information about the llvm-commits
mailing list