Skip to content

Commit b29c5b6

Browse files
authored
[NFC][LoopVectorize] Dont pass LLVMContext to VPTypeAnalysis constructor (#108540)
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.
1 parent 6d3f6c2 commit b29c5b6

File tree

5 files changed

+19
-28
lines changed

5 files changed

+19
-28
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4344,12 +4344,11 @@ bool LoopVectorizationPlanner::isMoreProfitable(
43444344
void LoopVectorizationPlanner::emitInvalidCostRemarks(
43454345
OptimizationRemarkEmitter *ORE) {
43464346
using RecipeVFPair = std::pair<VPRecipeBase *, ElementCount>;
4347-
LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext();
43484347
SmallVector<RecipeVFPair> InvalidCosts;
43494348
for (const auto &Plan : VPlans) {
43504349
for (ElementCount VF : Plan->vectorFactors()) {
43514350
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
4352-
LLVMCtx, CM);
4351+
CM);
43534352
auto Iter = vp_depth_first_deep(Plan->getVectorLoopRegion()->getEntry());
43544353
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
43554354
for (auto &R : *VPBB) {
@@ -4452,8 +4451,7 @@ void LoopVectorizationPlanner::emitInvalidCostRemarks(
44524451
static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
44534452
const TargetTransformInfo &TTI) {
44544453
assert(VF.isVector() && "Checking a scalar VF?");
4455-
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(),
4456-
Plan.getCanonicalIV()->getScalarType()->getContext());
4454+
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType());
44574455
DenseSet<VPRecipeBase *> EphemeralRecipes;
44584456
collectEphemeralRecipesForVPlan(Plan, EphemeralRecipes);
44594457
// Set of already visited types.
@@ -7267,9 +7265,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
72677265

72687266
InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
72697267
ElementCount VF) const {
7270-
LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext();
7271-
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
7272-
LLVMCtx, CM);
7268+
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(), CM);
72737269
InstructionCost Cost = precomputeCosts(Plan, VF, CostCtx);
72747270

72757271
// Now compute and add the VPlan-based cost.
@@ -7388,9 +7384,7 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
73887384
// simplifications not accounted for in the legacy cost model. If that's the
73897385
// case, don't trigger the assertion, as the extra simplifications may cause a
73907386
// different VF to be picked by the VPlan-based cost model.
7391-
LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext();
7392-
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
7393-
LLVMCtx, CM);
7387+
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(), CM);
73947388
precomputeCosts(BestPlan, BestFactor.Width, CostCtx);
73957389
assert((BestFactor.Width == LegacyVF.Width ||
73967390
planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width),
@@ -7527,8 +7521,7 @@ LoopVectorizationPlanner::executePlan(
75277521
LLVM_DEBUG(BestVPlan.dump());
75287522

75297523
// Perform the actual loop transformation.
7530-
VPTransformState State(BestVF, BestUF, LI, DT, ILV.Builder, &ILV, &BestVPlan,
7531-
OrigLoop->getHeader()->getContext());
7524+
VPTransformState State(BestVF, BestUF, LI, DT, ILV.Builder, &ILV, &BestVPlan);
75327525

75337526
// 0. Generate SCEV-dependent code into the preheader, including TripCount,
75347527
// before making any changes to the CFG.

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,9 @@ VPBasicBlock::iterator VPBasicBlock::getFirstNonPhi() {
224224

225225
VPTransformState::VPTransformState(ElementCount VF, unsigned UF, LoopInfo *LI,
226226
DominatorTree *DT, IRBuilderBase &Builder,
227-
InnerLoopVectorizer *ILV, VPlan *Plan,
228-
LLVMContext &Ctx)
227+
InnerLoopVectorizer *ILV, VPlan *Plan)
229228
: VF(VF), UF(UF), CFG(DT), LI(LI), Builder(Builder), ILV(ILV), Plan(Plan),
230-
LVer(nullptr),
231-
TypeAnalysis(Plan->getCanonicalIV()->getScalarType(), Ctx) {}
229+
LVer(nullptr), TypeAnalysis(Plan->getCanonicalIV()->getScalarType()) {}
232230

233231
Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) {
234232
if (Def->isLiveIn())

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ struct VPIteration {
255255
struct VPTransformState {
256256
VPTransformState(ElementCount VF, unsigned UF, LoopInfo *LI,
257257
DominatorTree *DT, IRBuilderBase &Builder,
258-
InnerLoopVectorizer *ILV, VPlan *Plan, LLVMContext &Ctx);
258+
InnerLoopVectorizer *ILV, VPlan *Plan);
259259

260260
/// The chosen Vectorization and Unroll Factors of the loop being vectorized.
261261
ElementCount VF;
@@ -743,9 +743,9 @@ struct VPCostContext {
743743
SmallPtrSet<Instruction *, 8> SkipCostComputation;
744744

745745
VPCostContext(const TargetTransformInfo &TTI, const TargetLibraryInfo &TLI,
746-
Type *CanIVTy, LLVMContext &LLVMCtx,
747-
LoopVectorizationCostModel &CM)
748-
: TTI(TTI), TLI(TLI), Types(CanIVTy, LLVMCtx), LLVMCtx(LLVMCtx), CM(CM) {}
746+
Type *CanIVTy, LoopVectorizationCostModel &CM)
747+
: TTI(TTI), TLI(TLI), Types(CanIVTy), LLVMCtx(CanIVTy->getContext()),
748+
CM(CM) {}
749749

750750
/// Return the cost for \p UI with \p VF using the legacy cost model as
751751
/// fallback until computing the cost of all recipes migrates to VPlan.

llvm/lib/Transforms/Vectorize/VPlanAnalysis.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "llvm/ADT/DenseMap.h"
1313
#include "llvm/ADT/DenseSet.h"
14+
#include "llvm/IR/Type.h"
1415

1516
namespace llvm {
1617

@@ -54,8 +55,8 @@ class VPTypeAnalysis {
5455
Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R);
5556

5657
public:
57-
VPTypeAnalysis(Type *CanonicalIVTy, LLVMContext &Ctx)
58-
: CanonicalIVTy(CanonicalIVTy), Ctx(Ctx) {}
58+
VPTypeAnalysis(Type *CanonicalIVTy)
59+
: CanonicalIVTy(CanonicalIVTy), Ctx(CanonicalIVTy->getContext()) {}
5960

6061
/// Infer the type of \p V. Returns the scalar type of \p V.
6162
Type *inferScalarType(const VPValue *V);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
537537

538538
// Truncate base induction if needed.
539539
Type *CanonicalIVType = CanonicalIV->getScalarType();
540-
VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext());
540+
VPTypeAnalysis TypeInfo(CanonicalIVType);
541541
Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
542542
if (TruncI) {
543543
Type *TruncTy = TruncI->getType();
@@ -940,8 +940,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
940940
// Verify that the cached type info is for both A and its users is still
941941
// accurate by comparing it to freshly computed types.
942942
VPTypeAnalysis TypeInfo2(
943-
R.getParent()->getPlan()->getCanonicalIV()->getScalarType(),
944-
TypeInfo.getContext());
943+
R.getParent()->getPlan()->getCanonicalIV()->getScalarType());
945944
assert(TypeInfo.inferScalarType(A) == TypeInfo2.inferScalarType(A));
946945
for (VPUser *U : A->users()) {
947946
auto *R = dyn_cast<VPRecipeBase>(U);
@@ -976,7 +975,7 @@ static void simplifyRecipes(VPlan &Plan) {
976975
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
977976
Plan.getEntry());
978977
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
979-
VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext());
978+
VPTypeAnalysis TypeInfo(CanonicalIVType);
980979
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
981980
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
982981
simplifyRecipe(R, TypeInfo);
@@ -997,8 +996,7 @@ void VPlanTransforms::truncateToMinimalBitwidths(
997996
// typed.
998997
DenseMap<VPValue *, VPWidenCastRecipe *> ProcessedTruncs;
999998
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
1000-
LLVMContext &Ctx = CanonicalIVType->getContext();
1001-
VPTypeAnalysis TypeInfo(CanonicalIVType, Ctx);
999+
VPTypeAnalysis TypeInfo(CanonicalIVType);
10021000
VPBasicBlock *PH = Plan.getEntry();
10031001
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
10041002
vp_depth_first_deep(Plan.getVectorLoopRegion()))) {
@@ -1052,6 +1050,7 @@ void VPlanTransforms::truncateToMinimalBitwidths(
10521050
assert(OldResTy->isIntegerTy() && "only integer types supported");
10531051
(void)OldResSizeInBits;
10541052

1053+
LLVMContext &Ctx = CanonicalIVType->getContext();
10551054
auto *NewResTy = IntegerType::get(Ctx, NewResSizeInBits);
10561055

10571056
// Any wrapping introduced by shrinking this operation shouldn't be

0 commit comments

Comments
 (0)