-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC][LoopVectorize] Dont pass LLVMContext to VPTypeAnalysis constructor #108540
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
Conversation
We already pass a Type object into the VPTypeAnalysis constructor, which can be used to obtain the context. While in the same area it also made sense to avoid passing the context into the VPTransformState and VPCostContext constructors.
@llvm/pr-subscribers-llvm-transforms Author: David Sherwood (david-arm) ChangesWe already pass a Type object into the VPTypeAnalysis constructor, which can be used to obtain the context. While in the same area it also made sense to avoid passing the context into the VPTransformState and VPCostContext constructors. Full diff: https://github.com/llvm/llvm-project/pull/108540.diff 5 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f726b171969a30..275ee18d36f9ff 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4344,12 +4344,11 @@ bool LoopVectorizationPlanner::isMoreProfitable(
void LoopVectorizationPlanner::emitInvalidCostRemarks(
OptimizationRemarkEmitter *ORE) {
using RecipeVFPair = std::pair<VPRecipeBase *, ElementCount>;
- LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext();
SmallVector<RecipeVFPair> InvalidCosts;
for (const auto &Plan : VPlans) {
for (ElementCount VF : Plan->vectorFactors()) {
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
- LLVMCtx, CM);
+ CM);
auto Iter = vp_depth_first_deep(Plan->getVectorLoopRegion()->getEntry());
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
for (auto &R : *VPBB) {
@@ -4452,8 +4451,7 @@ void LoopVectorizationPlanner::emitInvalidCostRemarks(
static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
const TargetTransformInfo &TTI) {
assert(VF.isVector() && "Checking a scalar VF?");
- VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(),
- Plan.getCanonicalIV()->getScalarType()->getContext());
+ VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType());
DenseSet<VPRecipeBase *> EphemeralRecipes;
collectEphemeralRecipesForVPlan(Plan, EphemeralRecipes);
// Set of already visited types.
@@ -7270,9 +7268,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
ElementCount VF) const {
- LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext();
- VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
- LLVMCtx, CM);
+ VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(), CM);
InstructionCost Cost = precomputeCosts(Plan, VF, CostCtx);
// Now compute and add the VPlan-based cost.
@@ -7391,9 +7387,7 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
// simplifications not accounted for in the legacy cost model. If that's the
// case, don't trigger the assertion, as the extra simplifications may cause a
// different VF to be picked by the VPlan-based cost model.
- LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext();
- VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
- LLVMCtx, CM);
+ VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(), CM);
precomputeCosts(BestPlan, BestFactor.Width, CostCtx);
assert((BestFactor.Width == LegacyVF.Width ||
planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width),
@@ -7530,8 +7524,7 @@ LoopVectorizationPlanner::executePlan(
LLVM_DEBUG(BestVPlan.dump());
// Perform the actual loop transformation.
- VPTransformState State(BestVF, BestUF, LI, DT, ILV.Builder, &ILV, &BestVPlan,
- OrigLoop->getHeader()->getContext());
+ VPTransformState State(BestVF, BestUF, LI, DT, ILV.Builder, &ILV, &BestVPlan);
// 0. Generate SCEV-dependent code into the preheader, including TripCount,
// before making any changes to the CFG.
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 316468651df1ab..1e4ba4c8041d40 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -223,11 +223,9 @@ VPBasicBlock::iterator VPBasicBlock::getFirstNonPhi() {
VPTransformState::VPTransformState(ElementCount VF, unsigned UF, LoopInfo *LI,
DominatorTree *DT, IRBuilderBase &Builder,
- InnerLoopVectorizer *ILV, VPlan *Plan,
- LLVMContext &Ctx)
+ InnerLoopVectorizer *ILV, VPlan *Plan)
: VF(VF), UF(UF), CFG(DT), LI(LI), Builder(Builder), ILV(ILV), Plan(Plan),
- LVer(nullptr),
- TypeAnalysis(Plan->getCanonicalIV()->getScalarType(), Ctx) {}
+ LVer(nullptr), TypeAnalysis(Plan->getCanonicalIV()->getScalarType()) {}
Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) {
if (Def->isLiveIn())
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 64242e43c56bc8..1fc4ac5e9ba1c3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -255,7 +255,7 @@ struct VPIteration {
struct VPTransformState {
VPTransformState(ElementCount VF, unsigned UF, LoopInfo *LI,
DominatorTree *DT, IRBuilderBase &Builder,
- InnerLoopVectorizer *ILV, VPlan *Plan, LLVMContext &Ctx);
+ InnerLoopVectorizer *ILV, VPlan *Plan);
/// The chosen Vectorization and Unroll Factors of the loop being vectorized.
ElementCount VF;
@@ -743,9 +743,9 @@ struct VPCostContext {
SmallPtrSet<Instruction *, 8> SkipCostComputation;
VPCostContext(const TargetTransformInfo &TTI, const TargetLibraryInfo &TLI,
- Type *CanIVTy, LLVMContext &LLVMCtx,
- LoopVectorizationCostModel &CM)
- : TTI(TTI), TLI(TLI), Types(CanIVTy, LLVMCtx), LLVMCtx(LLVMCtx), CM(CM) {}
+ Type *CanIVTy, LoopVectorizationCostModel &CM)
+ : TTI(TTI), TLI(TLI), Types(CanIVTy), LLVMCtx(CanIVTy->getContext()),
+ CM(CM) {}
/// Return the cost for \p UI with \p VF using the legacy cost model as
/// fallback until computing the cost of all recipes migrates to VPlan.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h
index 438364efc62942..cc21870bee2e3b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h
@@ -11,6 +11,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/IR/Type.h"
namespace llvm {
@@ -54,8 +55,8 @@ class VPTypeAnalysis {
Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R);
public:
- VPTypeAnalysis(Type *CanonicalIVTy, LLVMContext &Ctx)
- : CanonicalIVTy(CanonicalIVTy), Ctx(Ctx) {}
+ VPTypeAnalysis(Type *CanonicalIVTy)
+ : CanonicalIVTy(CanonicalIVTy), Ctx(CanonicalIVTy->getContext()) {}
/// Infer the type of \p V. Returns the scalar type of \p V.
Type *inferScalarType(const VPValue *V);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index dd67430394807c..dffdc4a295c436 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -538,7 +538,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
// Truncate base induction if needed.
Type *CanonicalIVType = CanonicalIV->getScalarType();
- VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext());
+ VPTypeAnalysis TypeInfo(CanonicalIVType);
Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
if (TruncI) {
Type *TruncTy = TruncI->getType();
@@ -946,8 +946,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
// Verify that the cached type info is for both A and its users is still
// accurate by comparing it to freshly computed types.
VPTypeAnalysis TypeInfo2(
- R.getParent()->getPlan()->getCanonicalIV()->getScalarType(),
- TypeInfo.getContext());
+ R.getParent()->getPlan()->getCanonicalIV()->getScalarType());
assert(TypeInfo.inferScalarType(A) == TypeInfo2.inferScalarType(A));
for (VPUser *U : A->users()) {
auto *R = dyn_cast<VPRecipeBase>(U);
@@ -982,7 +981,7 @@ static void simplifyRecipes(VPlan &Plan) {
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
Plan.getEntry());
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
- VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext());
+ VPTypeAnalysis TypeInfo(CanonicalIVType);
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
simplifyRecipe(R, TypeInfo);
@@ -1003,8 +1002,7 @@ void VPlanTransforms::truncateToMinimalBitwidths(
// typed.
DenseMap<VPValue *, VPWidenCastRecipe *> ProcessedTruncs;
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
- LLVMContext &Ctx = CanonicalIVType->getContext();
- VPTypeAnalysis TypeInfo(CanonicalIVType, Ctx);
+ VPTypeAnalysis TypeInfo(CanonicalIVType);
VPBasicBlock *PH = Plan.getEntry();
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
vp_depth_first_deep(Plan.getVectorLoopRegion()))) {
@@ -1058,6 +1056,7 @@ void VPlanTransforms::truncateToMinimalBitwidths(
assert(OldResTy->isIntegerTy() && "only integer types supported");
(void)OldResSizeInBits;
+ LLVMContext &Ctx = CanonicalIVType->getContext();
auto *NewResTy = IntegerType::get(Ctx, NewResSizeInBits);
// Any wrapping introduced by shrinking this operation shouldn't be
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the cleanup!
We already pass a Type object into the VPTypeAnalysis constructor, which can be used to obtain the context. While in the same area it also made sense to avoid passing the context into the VPTransformState and VPCostContext constructors.