From 53f301ea10800231fce9c839ec0dc6bc87785dd5 Mon Sep 17 00:00:00 2001 From: Daniil Fukalov Date: Sat, 15 May 2021 02:44:05 +0300 Subject: [PATCH] [TTI] NFC: Change getRegUsageForType 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 Reviewed By: sdesmalen Differential Revision: https://reviews.llvm.org/D102541 --- include/llvm/Analysis/TargetTransformInfo.h | 6 +++--- include/llvm/Analysis/TargetTransformInfoImpl.h | 2 +- include/llvm/CodeGen/BasicTTIImpl.h | 5 ++--- lib/Analysis/TargetTransformInfo.cpp | 2 +- lib/Transforms/Vectorize/LoopVectorize.cpp | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/llvm/Analysis/TargetTransformInfo.h b/include/llvm/Analysis/TargetTransformInfo.h index 1f508a45b7b..c67c02bf12e 100644 --- a/include/llvm/Analysis/TargetTransformInfo.h +++ b/include/llvm/Analysis/TargetTransformInfo.h @@ -709,7 +709,7 @@ public: bool isTypeLegal(Type *Ty) const; /// Returns the estimated number of registers required to represent \p Ty. - unsigned getRegUsageForType(Type *Ty) const; + InstructionCost getRegUsageForType(Type *Ty) const; /// Return true if switches should be turned into lookup tables for the /// target. @@ -1528,7 +1528,7 @@ public: virtual bool isProfitableToHoist(Instruction *I) = 0; virtual bool useAA() = 0; virtual bool isTypeLegal(Type *Ty) = 0; - virtual unsigned getRegUsageForType(Type *Ty) = 0; + virtual InstructionCost getRegUsageForType(Type *Ty) = 0; virtual bool shouldBuildLookupTables() = 0; virtual bool shouldBuildLookupTablesForConstant(Constant *C) = 0; virtual bool shouldBuildRelLookupTables() = 0; @@ -1921,7 +1921,7 @@ public: } bool useAA() override { return Impl.useAA(); } bool isTypeLegal(Type *Ty) override { return Impl.isTypeLegal(Ty); } - unsigned getRegUsageForType(Type *Ty) override { + InstructionCost getRegUsageForType(Type *Ty) override { return Impl.getRegUsageForType(Ty); } bool shouldBuildLookupTables() override { diff --git a/include/llvm/Analysis/TargetTransformInfoImpl.h b/include/llvm/Analysis/TargetTransformInfoImpl.h index e0a12d75e0b..e9c20b7ba8e 100644 --- a/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -291,7 +291,7 @@ public: bool isTypeLegal(Type *Ty) const { return false; } - unsigned getRegUsageForType(Type *Ty) const { return 1; } + InstructionCost getRegUsageForType(Type *Ty) const { return 1; } bool shouldBuildLookupTables() const { return true; } diff --git a/include/llvm/CodeGen/BasicTTIImpl.h b/include/llvm/CodeGen/BasicTTIImpl.h index 6dc82a87a43..e46df8d7132 100644 --- a/include/llvm/CodeGen/BasicTTIImpl.h +++ b/include/llvm/CodeGen/BasicTTIImpl.h @@ -356,9 +356,8 @@ public: return getTLI()->isTypeLegal(VT); } - unsigned getRegUsageForType(Type *Ty) { - InstructionCost::CostType Val = - *getTLI()->getTypeLegalizationCost(DL, Ty).first.getValue(); + InstructionCost getRegUsageForType(Type *Ty) { + InstructionCost Val = getTLI()->getTypeLegalizationCost(DL, Ty).first; assert(Val >= 0 && "Negative cost!"); return Val; } diff --git a/lib/Analysis/TargetTransformInfo.cpp b/lib/Analysis/TargetTransformInfo.cpp index 5084aaa4e76..e7cc915cd0d 100644 --- a/lib/Analysis/TargetTransformInfo.cpp +++ b/lib/Analysis/TargetTransformInfo.cpp @@ -449,7 +449,7 @@ bool TargetTransformInfo::isTypeLegal(Type *Ty) const { return TTIImpl->isTypeLegal(Ty); } -unsigned TargetTransformInfo::getRegUsageForType(Type *Ty) const { +InstructionCost TargetTransformInfo::getRegUsageForType(Type *Ty) const { return TTIImpl->getRegUsageForType(Ty); } diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index d5f71c7496c..45acffabc17 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6568,8 +6568,8 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef VFs) { const auto &TTICapture = TTI; auto GetRegUsage = [&TTICapture](Type *Ty, ElementCount VF) { if (Ty->isTokenTy() || !VectorType::isValidElementType(Ty)) - return 0U; - return TTICapture.getRegUsageForType(VectorType::get(Ty, VF)); + return 0; + return *TTICapture.getRegUsageForType(VectorType::get(Ty, VF)).getValue(); }; for (unsigned int i = 0, s = IdxToInstr.size(); i < s; ++i) {