Skip to content

Commit c2e26ff

Browse files
fixup! refactor phi functions
1 parent cf71fdd commit c2e26ff

File tree

6 files changed

+50
-44
lines changed

6 files changed

+50
-44
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void VPBlockBase::deleteCFG(VPBlockBase *Entry) {
216216

217217
VPBasicBlock::iterator VPBasicBlock::getFirstNonPhi() {
218218
iterator It = begin();
219-
while (It != end() && vputils::isPhi(*It))
219+
while (It != end() && It->isPhi())
220220
It++;
221221
return It;
222222
}
@@ -1035,7 +1035,7 @@ void VPlan::execute(VPTransformState *State) {
10351035
VPBasicBlock *Header = getVectorLoopRegion()->getEntryBasicBlock();
10361036
for (VPRecipeBase &R : Header->phis()) {
10371037
// Skip phi-like recipes that generate their backedege values themselves.
1038-
if (vputils::isPhiThatGeneratesBackedge(R))
1038+
if (R.isPhiThatGeneratesBackedge())
10391039
continue;
10401040

10411041
if (isa<VPWidenPointerInductionRecipe>(&R) ||

llvm/lib/Transforms/Vectorize/VPlan.h

+30-1
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,29 @@ class VPRecipeBase : public ilist_node_with_parent<VPRecipeBase, VPBasicBlock>,
890890
bool mayHaveSideEffects() const;
891891

892892
/// Returns true for PHI-like recipes.
893-
bool isPhi() const {
893+
virtual bool isPhi() const {
894+
assert(getVPDefID() != VPInstructionSC &&
895+
"VPInstructions implement this function themselves");
894896
return getVPDefID() >= VPFirstPHISC && getVPDefID() <= VPLastPHISC;
895897
}
896898

899+
/// Returns true for PHI-like recipes that exists in vector loop header basic
900+
/// block
901+
virtual bool isHeaderPhi() const {
902+
assert(getVPDefID() != VPInstructionSC &&
903+
"VPInstructions implement this function themselves");
904+
return (getVPDefID() >= VPFirstHeaderPHISC &&
905+
getVPDefID() <= VPLastHeaderPHISC) ||
906+
getVPDefID() == VPWidenPHISC;
907+
}
908+
909+
/// Returns true for PHI-like recipes that generate their own backedge
910+
virtual bool isPhiThatGeneratesBackedge() const {
911+
assert(getVPDefID() != VPInstructionSC &&
912+
"VPInstructions implement this function themselves");
913+
return getVPDefID() == VPWidenPHISC || getVPDefID() == VPCSAHeaderPHISC;
914+
}
915+
897916
/// Returns true if the recipe may read from memory.
898917
bool mayReadFromMemory() const;
899918

@@ -1459,6 +1478,16 @@ class VPInstruction : public VPRecipeWithIRFlags {
14591478
/// Returns true if this VPInstruction's operands are single scalars and the
14601479
/// result is also a single scalar.
14611480
bool isSingleScalar() const;
1481+
1482+
/// Returns true for PHI-like recipes.
1483+
bool isPhi() const override;
1484+
1485+
/// Returns true for PHI-like recipes that exists in vector loop header basic
1486+
/// block
1487+
bool isHeaderPhi() const override;
1488+
1489+
/// Returns true for PHI-like recipes that generate their own backedge
1490+
bool isPhiThatGeneratesBackedge() const override;
14621491
};
14631492

14641493
/// VPWidenRecipe is a recipe for producing a widened instruction using the

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,21 @@ bool VPInstruction::isSingleScalar() const {
778778
getOpcode() == VPInstruction::ExplicitVectorLength;
779779
}
780780

781+
bool VPInstruction::isPhi() const {
782+
return getOpcode() == VPInstruction::CSAMaskPhi ||
783+
getOpcode() == VPInstruction::CSAVLPhi;
784+
}
785+
786+
bool VPInstruction::isHeaderPhi() const {
787+
return getOpcode() == VPInstruction::CSAMaskPhi ||
788+
getOpcode() == VPInstruction::CSAVLPhi;
789+
}
790+
791+
bool VPInstruction::isPhiThatGeneratesBackedge() const {
792+
return getOpcode() == VPInstruction::CSAMaskPhi ||
793+
getOpcode() == VPInstruction::CSAVLPhi;
794+
}
795+
781796
#if !defined(NDEBUG)
782797
bool VPInstruction::isFPMathOp() const {
783798
// Inspired by FPMathOperator::classof. Notable differences are that we don't

llvm/lib/Transforms/Vectorize/VPlanUtils.cpp

-27
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,3 @@ bool vputils::isHeaderMask(const VPValue *V, VPlan &Plan) {
6060
return match(V, m_Binary<Instruction::ICmp>(m_VPValue(A), m_VPValue(B))) &&
6161
IsWideCanonicalIV(A) && B == Plan.getOrCreateBackedgeTakenCount();
6262
}
63-
64-
bool vputils::isPhi(const VPRecipeBase &R) {
65-
if (R.isPhi())
66-
return true;
67-
if (auto *VPInst = dyn_cast<VPInstruction>(&R))
68-
return VPInst->getOpcode() == VPInstruction::CSAMaskPhi ||
69-
VPInst->getOpcode() == VPInstruction::CSAVLPhi;
70-
return false;
71-
}
72-
73-
bool vputils::isPhiThatGeneratesBackedge(const VPRecipeBase &R) {
74-
if (isa<VPWidenPHIRecipe, VPCSAHeaderPHIRecipe>(&R))
75-
return true;
76-
if (auto *VPInst = dyn_cast<VPInstruction>(&R))
77-
return VPInst->getOpcode() == VPInstruction::CSAMaskPhi ||
78-
VPInst->getOpcode() == VPInstruction::CSAVLPhi;
79-
return false;
80-
}
81-
82-
bool vputils::isHeaderPhi(const VPRecipeBase &R) {
83-
if (isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(&R))
84-
return true;
85-
if (auto *VPInst = dyn_cast<VPInstruction>(&R))
86-
return VPInst->getOpcode() == VPInstruction::CSAMaskPhi ||
87-
VPInst->getOpcode() == VPInstruction::CSAVLPhi;
88-
return false;
89-
}

llvm/lib/Transforms/Vectorize/VPlanUtils.h

-11
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ inline bool isUniformAfterVectorization(const VPValue *VPV) {
4545

4646
/// Return true if \p V is a header mask in \p Plan.
4747
bool isHeaderMask(const VPValue *V, VPlan &Plan);
48-
49-
/// Returns true for PHI-like recipes.
50-
bool isPhi(const VPRecipeBase &R);
51-
52-
/// Returns true for PHI-like recipes that generate their own backedge
53-
bool isPhiThatGeneratesBackedge(const VPRecipeBase &R);
54-
55-
/// Returns true for PHI-like recipes that exists in vector loop header basic
56-
/// block
57-
bool isHeaderPhi(const VPRecipeBase &R);
58-
5948
} // end namespace llvm::vputils
6049

6150
#endif

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
6868
const VPRegionBlock *ParentR = VPBB->getParent();
6969
bool IsHeaderVPBB = ParentR && !ParentR->isReplicator() &&
7070
ParentR->getEntryBasicBlock() == VPBB;
71-
while (RecipeI != End && vputils::isPhi(*RecipeI)) {
71+
while (RecipeI != End && RecipeI->isPhi()) {
7272
if (isa<VPActiveLaneMaskPHIRecipe>(RecipeI))
7373
NumActiveLaneMaskPhiRecipes++;
7474

75-
if (IsHeaderVPBB && !vputils::isHeaderPhi(*RecipeI)) {
75+
if (IsHeaderVPBB && !RecipeI->isHeaderPhi()) {
7676
errs() << "Found non-header PHI recipe in header VPBB";
7777
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
7878
errs() << ": ";
@@ -99,7 +99,7 @@ bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
9999
}
100100

101101
while (RecipeI != End) {
102-
if (vputils::isPhi(*RecipeI) && !isa<VPBlendRecipe>(&*RecipeI)) {
102+
if (RecipeI->isPhi() && !isa<VPBlendRecipe>(&*RecipeI)) {
103103
errs() << "Found phi-like recipe after non-phi recipe";
104104

105105
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

0 commit comments

Comments
 (0)