Skip to content

Commit 83f5f48

Browse files
committed
[VPlan] Add getContext helper to VPlan (NFC).
(cherry picked from commit f8b1c73)
1 parent 88d1b05 commit 83f5f48

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4068,6 +4068,10 @@ class VPlan {
40684068
/// Returns VF * UF of the vector loop region.
40694069
VPValue &getVFxUF() { return VFxUF; }
40704070

4071+
LLVMContext &getContext() const {
4072+
return getScalarHeader()->getIRBasicBlock()->getContext();
4073+
}
4074+
40714075
void addVF(ElementCount VF) { VFs.insert(VF); }
40724076

40734077
void setVF(ElementCount VF) {

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,11 @@ void VPlanTransforms::prepareForVectorization(
568568
VPBuilder Builder(MiddleVPBB);
569569
VPValue *Cmp;
570570
if (!RequiresScalarEpilogueCheck)
571-
Cmp = Plan.getOrAddLiveIn(ConstantInt::getFalse(
572-
IntegerType::getInt1Ty(TripCount->getType()->getContext())));
571+
Cmp = Plan.getOrAddLiveIn(
572+
ConstantInt::getFalse(IntegerType::getInt1Ty(Plan.getContext())));
573573
else if (TailFolded)
574-
Cmp = Plan.getOrAddLiveIn(ConstantInt::getTrue(
575-
IntegerType::getInt1Ty(TripCount->getType()->getContext())));
574+
Cmp = Plan.getOrAddLiveIn(
575+
ConstantInt::getTrue(IntegerType::getInt1Ty(Plan.getContext())));
576576
else
577577
Cmp = Builder.createICmp(CmpInst::ICMP_EQ, Plan.getTripCount(),
578578
&Plan.getVectorTripCount(), LatchDL, "cmp.n");
@@ -622,7 +622,7 @@ void VPlanTransforms::attachCheckBlock(VPlan &Plan, Value *Cond,
622622
.createNaryOp(VPInstruction::BranchOnCond, {CondVPV},
623623
Plan.getCanonicalIV()->getDebugLoc());
624624
if (AddBranchWeights) {
625-
MDBuilder MDB(Plan.getScalarHeader()->getIRBasicBlock()->getContext());
625+
MDBuilder MDB(Plan.getContext());
626626
MDNode *BranchWeights =
627627
MDB.createBranchWeights(CheckBypassWeights, /*IsExpected=*/false);
628628
Term->addMetadata(LLVMContext::MD_prof, BranchWeights);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ static bool optimizeVectorInductionWidthForTCAndVFUF(VPlan &Plan,
13701370
unsigned NewBitWidth =
13711371
ComputeBitWidth(TC->getValue(), BestVF.getKnownMinValue() * BestUF);
13721372

1373-
LLVMContext &Ctx = Plan.getCanonicalIV()->getScalarType()->getContext();
1373+
LLVMContext &Ctx = Plan.getContext();
13741374
auto *NewIVTy = IntegerType::get(Ctx, NewBitWidth);
13751375

13761376
bool MadeChange = false;
@@ -2534,8 +2534,8 @@ void VPlanTransforms::createInterleaveGroups(
25342534
DL.getTypeAllocSize(getLoadStoreType(IRInsertPos)) *
25352535
IG->getIndex(IRInsertPos),
25362536
/*IsSigned=*/true);
2537-
VPValue *OffsetVPV = Plan.getOrAddLiveIn(
2538-
ConstantInt::get(IRInsertPos->getParent()->getContext(), -Offset));
2537+
VPValue *OffsetVPV =
2538+
Plan.getOrAddLiveIn(ConstantInt::get(Plan.getContext(), -Offset));
25392539
VPBuilder B(InsertPos);
25402540
Addr = InBounds ? B.createInBoundsPtrAdd(InsertPos->getAddr(), OffsetVPV)
25412541
: B.createPtrAdd(InsertPos->getAddr(), OffsetVPV);
@@ -3409,7 +3409,7 @@ void VPlanTransforms::addBranchWeightToMiddleTerminator(
34093409
if (VF.isScalable() && VScaleForTuning.has_value())
34103410
VectorStep *= *VScaleForTuning;
34113411
assert(VectorStep > 0 && "trip count should not be zero");
3412-
MDBuilder MDB(Plan.getScalarHeader()->getIRBasicBlock()->getContext());
3412+
MDBuilder MDB(Plan.getContext());
34133413
MDNode *BranchWeights =
34143414
MDB.createBranchWeights({1, VectorStep - 1}, /*IsExpected=*/false);
34153415
MiddleTerm->addMetadata(LLVMContext::MD_prof, BranchWeights);

0 commit comments

Comments
 (0)