Skip to content

Commit f8b1c73

Browse files
committed
[VPlan] Add getContext helper to VPlan (NFC).
1 parent 83cb8b7 commit f8b1c73

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
@@ -4065,6 +4065,10 @@ class VPlan {
40654065
/// Returns VF * UF of the vector loop region.
40664066
VPValue &getVFxUF() { return VFxUF; }
40674067

4068+
LLVMContext &getContext() const {
4069+
return getScalarHeader()->getIRBasicBlock()->getContext();
4070+
}
4071+
40684072
void addVF(ElementCount VF) { VFs.insert(VF); }
40694073

40704074
void setVF(ElementCount VF) {

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,11 @@ void VPlanTransforms::prepareForVectorization(
570570
VPBuilder Builder(MiddleVPBB);
571571
VPValue *Cmp;
572572
if (!RequiresScalarEpilogueCheck)
573-
Cmp = Plan.getOrAddLiveIn(ConstantInt::getFalse(
574-
IntegerType::getInt1Ty(TripCount->getType()->getContext())));
573+
Cmp = Plan.getOrAddLiveIn(
574+
ConstantInt::getFalse(IntegerType::getInt1Ty(Plan.getContext())));
575575
else if (TailFolded)
576-
Cmp = Plan.getOrAddLiveIn(ConstantInt::getTrue(
577-
IntegerType::getInt1Ty(TripCount->getType()->getContext())));
576+
Cmp = Plan.getOrAddLiveIn(
577+
ConstantInt::getTrue(IntegerType::getInt1Ty(Plan.getContext())));
578578
else
579579
Cmp = Builder.createICmp(CmpInst::ICMP_EQ, Plan.getTripCount(),
580580
&Plan.getVectorTripCount(), LatchDL, "cmp.n");
@@ -648,7 +648,7 @@ void VPlanTransforms::attachCheckBlock(VPlan &Plan, Value *Cond,
648648
.createNaryOp(VPInstruction::BranchOnCond, {CondVPV},
649649
Plan.getCanonicalIV()->getDebugLoc());
650650
if (AddBranchWeights) {
651-
MDBuilder MDB(Plan.getScalarHeader()->getIRBasicBlock()->getContext());
651+
MDBuilder MDB(Plan.getContext());
652652
MDNode *BranchWeights =
653653
MDB.createBranchWeights(CheckBypassWeights, /*IsExpected=*/false);
654654
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;
@@ -2519,8 +2519,8 @@ void VPlanTransforms::createInterleaveGroups(
25192519
DL.getTypeAllocSize(getLoadStoreType(IRInsertPos)) *
25202520
IG->getIndex(IRInsertPos),
25212521
/*IsSigned=*/true);
2522-
VPValue *OffsetVPV = Plan.getOrAddLiveIn(
2523-
ConstantInt::get(IRInsertPos->getParent()->getContext(), -Offset));
2522+
VPValue *OffsetVPV =
2523+
Plan.getOrAddLiveIn(ConstantInt::get(Plan.getContext(), -Offset));
25242524
VPBuilder B(InsertPos);
25252525
Addr = InBounds ? B.createInBoundsPtrAdd(InsertPos->getAddr(), OffsetVPV)
25262526
: B.createPtrAdd(InsertPos->getAddr(), OffsetVPV);
@@ -3377,7 +3377,7 @@ void VPlanTransforms::addBranchWeightToMiddleTerminator(
33773377
if (VF.isScalable() && VScaleForTuning.has_value())
33783378
VectorStep *= *VScaleForTuning;
33793379
assert(VectorStep > 0 && "trip count should not be zero");
3380-
MDBuilder MDB(Plan.getScalarHeader()->getIRBasicBlock()->getContext());
3380+
MDBuilder MDB(Plan.getContext());
33813381
MDNode *BranchWeights =
33823382
MDB.createBranchWeights({1, VectorStep - 1}, /*IsExpected=*/false);
33833383
MiddleTerm->addMetadata(LLVMContext::MD_prof, BranchWeights);

0 commit comments

Comments
 (0)