Skip to content

Commit 9b38ca0

Browse files
fhahngithub-actions[bot]
authored andcommitted
Automerge: [VPlan] Add VPRecipeBase::getRegion helper (NFC).
Multiple places retrieve the region for a recipe. Add a helper to make the code more compact and clearer.
2 parents a65c13b + 8769119 commit 9b38ca0

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ class LLVM_ABI_FOR_TEST VPRecipeBase
407407
VPBasicBlock *getParent() { return Parent; }
408408
const VPBasicBlock *getParent() const { return Parent; }
409409

410+
/// \return the VPRegionBlock which the recipe belongs to.
411+
VPRegionBlock *getRegion();
412+
const VPRegionBlock *getRegion() const;
413+
410414
/// The method which generates the output IR instructions that correspond to
411415
/// this VPRecipe, thereby "executing" the VPlan.
412416
virtual void execute(VPTransformState &State) = 0;
@@ -4075,6 +4079,14 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
40754079
}
40764080
};
40774081

4082+
inline VPRegionBlock *VPRecipeBase::getRegion() {
4083+
return getParent()->getParent();
4084+
}
4085+
4086+
inline const VPRegionBlock *VPRecipeBase::getRegion() const {
4087+
return getParent()->getParent();
4088+
}
4089+
40784090
/// VPlan models a candidate for vectorization, encoding various decisions take
40794091
/// to produce efficient output IR, including which branches, basic-blocks and
40804092
/// output IR instructions to generate, and their cost. VPlan holds a

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ bool VPDominatorTree::properlyDominates(const VPRecipeBase *A,
377377

378378
#ifndef NDEBUG
379379
auto GetReplicateRegion = [](VPRecipeBase *R) -> VPRegionBlock * {
380-
auto *Region = dyn_cast_or_null<VPRegionBlock>(R->getParent()->getParent());
380+
VPRegionBlock *Region = R->getRegion();
381381
if (Region && Region->isReplicator()) {
382382
assert(Region->getNumSuccessors() == 1 &&
383383
Region->getNumPredecessors() == 1 && "Expected SESE region!");

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ bool VPWidenIntOrFpInductionRecipe::isCanonical() const {
23522352
return false;
23532353
auto *StepC = dyn_cast<ConstantInt>(getStepValue()->getLiveInIRValue());
23542354
auto *StartC = dyn_cast<ConstantInt>(getStartValue()->getLiveInIRValue());
2355-
auto *CanIV = getParent()->getParent()->getCanonicalIV();
2355+
auto *CanIV = getRegion()->getCanonicalIV();
23562356
return StartC && StartC->isZero() && StepC && StepC->isOne() &&
23572357
getScalarType() == CanIV->getScalarType();
23582358
}
@@ -3076,7 +3076,7 @@ static void scalarizeInstruction(const Instruction *Instr,
30763076
State.AC->registerAssumption(II);
30773077

30783078
assert(
3079-
(RepRecipe->getParent()->getParent() ||
3079+
(RepRecipe->getRegion() ||
30803080
!RepRecipe->getParent()->getPlan()->getVectorLoopRegion() ||
30813081
all_of(RepRecipe->operands(),
30823082
[](VPValue *Op) { return Op->isDefinedOutsideLoopRegions(); })) &&
@@ -3268,7 +3268,7 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
32683268
to_vector(operands()), VF);
32693269
// If the recipe is not predicated (i.e. not in a replicate region), return
32703270
// the scalar cost. Otherwise handle predicated cost.
3271-
if (!getParent()->getParent()->isReplicator())
3271+
if (!getRegion()->isReplicator())
32723272
return ScalarCost;
32733273

32743274
// Account for the phi nodes that we will create.
@@ -3284,7 +3284,7 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
32843284
case Instruction::Store: {
32853285
// TODO: See getMemInstScalarizationCost for how to handle replicating and
32863286
// predicated cases.
3287-
const VPRegionBlock *ParentRegion = getParent()->getParent();
3287+
const VPRegionBlock *ParentRegion = getRegion();
32883288
if (ParentRegion && ParentRegion->isReplicator())
32893289
break;
32903290

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,8 +1858,8 @@ static bool hoistPreviousBeforeFORUsers(VPFirstOrderRecurrencePHIRecipe *FOR,
18581858
return nullptr;
18591859
VPRegionBlock *EnclosingLoopRegion =
18601860
HoistCandidate->getParent()->getEnclosingLoopRegion();
1861-
assert((!HoistCandidate->getParent()->getParent() ||
1862-
HoistCandidate->getParent()->getParent() == EnclosingLoopRegion) &&
1861+
assert((!HoistCandidate->getRegion() ||
1862+
HoistCandidate->getRegion() == EnclosingLoopRegion) &&
18631863
"CFG in VPlan should still be flat, without replicate regions");
18641864
// Hoist candidate was already visited, no need to hoist.
18651865
if (!Visited.insert(HoistCandidate).second)
@@ -2898,7 +2898,7 @@ void VPlanTransforms::replaceSymbolicStrides(
28982898
// evolution.
28992899
auto CanUseVersionedStride = [&Plan](VPUser &U, unsigned) {
29002900
auto *R = cast<VPRecipeBase>(&U);
2901-
return R->getParent()->getParent() ||
2901+
return R->getRegion() ||
29022902
R->getParent() == Plan.getVectorLoopRegion()->getSinglePredecessor();
29032903
};
29042904
ValueToSCEVMapTy RewriteMap;
@@ -3803,8 +3803,7 @@ void VPlanTransforms::materializeBuildVectors(VPlan &Plan) {
38033803
continue;
38043804
auto *DefR = cast<VPRecipeWithIRFlags>(&R);
38053805
auto UsesVectorOrInsideReplicateRegion = [DefR, LoopRegion](VPUser *U) {
3806-
VPRegionBlock *ParentRegion =
3807-
cast<VPRecipeBase>(U)->getParent()->getParent();
3806+
VPRegionBlock *ParentRegion = cast<VPRecipeBase>(U)->getRegion();
38083807
return !U->usesScalars(DefR) || ParentRegion != LoopRegion;
38093808
};
38103809
if ((isa<VPReplicateRecipe>(DefR) &&

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ inline bool isSingleScalar(const VPValue *VPV) {
6464
return true;
6565

6666
if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
67-
const VPRegionBlock *RegionOfR = Rep->getParent()->getParent();
67+
const VPRegionBlock *RegionOfR = Rep->getRegion();
6868
// Don't consider recipes in replicate regions as uniform yet; their first
6969
// lane cannot be accessed when executing the replicate region for other
7070
// lanes.

0 commit comments

Comments
 (0)