Skip to content

Commit 09cebd2

Browse files
committed
[LV][NFC] Rename getNumUsers to getNumUses
The Users list in VPValue is really just a Use list because the same User can appear several times in the list, reflecting the fact the VPValue can be used for more than one operand of a recipe. In such a scenario there is really just one *user* with multiple *uses* of a given Value. See the documentation for the IR routine Value::hasOneUser(): --- /// Return true if there is exactly one user of this value. /// /// Note that this is not the same as "has one use". If a value has one use, /// then there certainly is a single user. But if value has several uses, /// it is possible that all uses are in a single user, or not. /// /// This check is potentially costly, since it requires traversing, /// in the worst case, the whole use list of a value. LLVM_ABI bool hasOneUser() const; --- I've renamed this function, along with removeUser to more accurately reflect what the code is doing.
1 parent ba707db commit 09cebd2

File tree

10 files changed

+66
-61
lines changed

10 files changed

+66
-61
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4207,7 +4207,7 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
42074207
// divisors.
42084208
case Instruction::Select: {
42094209
VPValue *VPV = VPI->getVPSingleValue();
4210-
if (VPV->getNumUsers() == 1) {
4210+
if (VPV->getNumUses() == 1) {
42114211
if (auto *WR = dyn_cast<VPWidenRecipe>(*VPV->user_begin())) {
42124212
switch (WR->getOpcode()) {
42134213
case Instruction::UDiv:

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,25 +1056,25 @@ const VPRegionBlock *VPlan::getVectorLoopRegion() const {
10561056
void VPlan::printLiveIns(raw_ostream &O) const {
10571057
VPSlotTracker SlotTracker(this);
10581058

1059-
if (VF.getNumUsers() > 0) {
1059+
if (VF.getNumUses() > 0) {
10601060
O << "\nLive-in ";
10611061
VF.printAsOperand(O, SlotTracker);
10621062
O << " = VF";
10631063
}
10641064

1065-
if (VFxUF.getNumUsers() > 0) {
1065+
if (VFxUF.getNumUses() > 0) {
10661066
O << "\nLive-in ";
10671067
VFxUF.printAsOperand(O, SlotTracker);
10681068
O << " = VF * UF";
10691069
}
10701070

1071-
if (VectorTripCount.getNumUsers() > 0) {
1071+
if (VectorTripCount.getNumUses() > 0) {
10721072
O << "\nLive-in ";
10731073
VectorTripCount.printAsOperand(O, SlotTracker);
10741074
O << " = vector-trip-count";
10751075
}
10761076

1077-
if (BackedgeTakenCount && BackedgeTakenCount->getNumUsers()) {
1077+
if (BackedgeTakenCount && BackedgeTakenCount->getNumUses()) {
10781078
O << "\nLive-in ";
10791079
BackedgeTakenCount->printAsOperand(O, SlotTracker);
10801080
O << " = backedge-taken count";
@@ -1416,7 +1416,7 @@ void VPValue::replaceUsesWithIf(
14161416
if (this == New)
14171417
return;
14181418

1419-
for (unsigned J = 0; J < getNumUsers();) {
1419+
for (unsigned J = 0; J < getNumUses();) {
14201420
VPUser *User = Users[J];
14211421
bool RemovedUser = false;
14221422
for (unsigned I = 0, E = User->getNumOperands(); I < E; ++I) {
@@ -1492,9 +1492,9 @@ void VPSlotTracker::assignName(const VPValue *V) {
14921492
}
14931493

14941494
void VPSlotTracker::assignNames(const VPlan &Plan) {
1495-
if (Plan.VF.getNumUsers() > 0)
1495+
if (Plan.VF.getNumUses() > 0)
14961496
assignName(&Plan.VF);
1497-
if (Plan.VFxUF.getNumUsers() > 0)
1497+
if (Plan.VFxUF.getNumUses() > 0)
14981498
assignName(&Plan.VFxUF);
14991499
assignName(&Plan.VectorTripCount);
15001500
if (Plan.BackedgeTakenCount)

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4204,7 +4204,7 @@ class VPlan {
42044204
/// Resets the trip count for the VPlan. The caller must make sure all uses of
42054205
/// the original trip count have been replaced.
42064206
void resetTripCount(VPValue *NewTripCount) {
4207-
assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
4207+
assert(TripCount && NewTripCount && TripCount->getNumUses() == 0 &&
42084208
"TripCount must be set when resetting");
42094209
TripCount = NewTripCount;
42104210
}

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
885885
if (VecV == RdxResult)
886886
continue;
887887
if (auto *DerivedIV = dyn_cast<VPDerivedIVRecipe>(VecV)) {
888-
if (DerivedIV->getNumUsers() == 1 &&
888+
if (DerivedIV->getNumUses() == 1 &&
889889
DerivedIV->getOperand(1) == &Plan.getVectorTripCount()) {
890890
auto *NewSel = Builder.createSelect(AnyNaN, Plan.getCanonicalIV(),
891891
&Plan.getVectorTripCount());

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF,
22492249
TTI::CastContextHint CCH = TTI::CastContextHint::None;
22502250
// For Trunc/FPTrunc, get the context from the only user.
22512251
if ((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
2252-
!hasMoreThanOneUniqueUser() && getNumUsers() > 0) {
2252+
!hasMoreThanOneUniqueUser() && getNumUses() > 0) {
22532253
if (auto *StoreRecipe = dyn_cast<VPRecipeBase>(*user_begin()))
22542254
CCH = ComputeCCH(StoreRecipe);
22552255
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan) {
316316
});
317317

318318
// Remove phi recipes that are unused after merging the regions.
319-
if (Phi1ToMove.getVPSingleValue()->getNumUsers() == 0) {
319+
if (Phi1ToMove.getVPSingleValue()->getNumUses() == 0) {
320320
Phi1ToMove.eraseFromParent();
321321
continue;
322322
}
@@ -363,7 +363,7 @@ static VPRegionBlock *createReplicateRegion(VPReplicateRecipe *PredRecipe,
363363
Plan.createVPBasicBlock(Twine(RegionName) + ".if", RecipeWithoutMask);
364364

365365
VPPredInstPHIRecipe *PHIRecipe = nullptr;
366-
if (PredRecipe->getNumUsers() != 0) {
366+
if (PredRecipe->getNumUses() != 0) {
367367
PHIRecipe = new VPPredInstPHIRecipe(RecipeWithoutMask,
368368
RecipeWithoutMask->getDebugLoc());
369369
PredRecipe->replaceAllUsesWith(PHIRecipe);
@@ -547,7 +547,7 @@ static bool isDeadRecipe(VPRecipeBase &R) {
547547

548548
// Recipe is dead if no user keeps the recipe alive.
549549
return all_of(R.definedValues(),
550-
[](VPValue *V) { return V->getNumUsers() == 0; });
550+
[](VPValue *V) { return V->getNumUses() == 0; });
551551
}
552552

553553
void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
@@ -563,11 +563,11 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
563563

564564
// Check if R is a dead VPPhi <-> update cycle and remove it.
565565
auto *PhiR = dyn_cast<VPPhi>(&R);
566-
if (!PhiR || PhiR->getNumOperands() != 2 || PhiR->getNumUsers() != 1)
566+
if (!PhiR || PhiR->getNumOperands() != 2 || PhiR->getNumUses() != 1)
567567
continue;
568568
VPValue *Incoming = PhiR->getOperand(1);
569569
if (*PhiR->user_begin() != Incoming->getDefiningRecipe() ||
570-
Incoming->getNumUsers() != 1)
570+
Incoming->getNumUses() != 1)
571571
continue;
572572
PhiR->replaceAllUsesWith(PhiR->getOperand(0));
573573
PhiR->eraseFromParent();
@@ -658,7 +658,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
658658
auto *RepR = dyn_cast<VPReplicateRecipe>(U);
659659
// Skip recipes that shouldn't be narrowed.
660660
if (!Def || !isa<VPReplicateRecipe, VPWidenRecipe>(Def) ||
661-
Def->getNumUsers() == 0 || !Def->getUnderlyingValue() ||
661+
Def->getNumUses() == 0 || !Def->getUnderlyingValue() ||
662662
(RepR && (RepR->isSingleScalar() || RepR->isPredicated())))
663663
continue;
664664

@@ -1344,7 +1344,7 @@ static void simplifyBlends(VPlan &Plan) {
13441344
// TODO: Find the most expensive mask that can be deadcoded, or a mask
13451345
// that's used by multiple blends where it can be removed from them all.
13461346
VPValue *Mask = Blend->getMask(I);
1347-
if (Mask->getNumUsers() == 1 && !match(Mask, m_False())) {
1347+
if (Mask->getNumUses() == 1 && !match(Mask, m_False())) {
13481348
StartIndex = I;
13491349
break;
13501350
}
@@ -1380,7 +1380,7 @@ static void simplifyBlends(VPlan &Plan) {
13801380
NewBlend->setOperand(0, Inc1);
13811381
NewBlend->setOperand(1, Inc0);
13821382
NewBlend->setOperand(2, NewMask);
1383-
if (OldMask->getNumUsers() == 0)
1383+
if (OldMask->getNumUses() == 0)
13841384
cast<VPInstruction>(OldMask)->eraseFromParent();
13851385
}
13861386
}
@@ -2467,7 +2467,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
24672467
ToErase.push_back(CurRecipe);
24682468
}
24692469
// Remove dead EVL mask.
2470-
if (EVLMask->getNumUsers() == 0)
2470+
if (EVLMask->getNumUses() == 0)
24712471
ToErase.push_back(EVLMask->getDefiningRecipe());
24722472

24732473
for (VPRecipeBase *R : reverse(ToErase)) {
@@ -3445,7 +3445,7 @@ void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {
34453445
#endif
34463446

34473447
SmallVector<VPValue *> VPValues;
3448-
if (Plan.getOrCreateBackedgeTakenCount()->getNumUsers() > 0)
3448+
if (Plan.getOrCreateBackedgeTakenCount()->getNumUses() > 0)
34493449
VPValues.push_back(Plan.getOrCreateBackedgeTakenCount());
34503450
append_range(VPValues, Plan.getLiveIns());
34513451
for (VPRecipeBase &R : *Plan.getEntry())
@@ -3514,7 +3514,7 @@ void VPlanTransforms::materializeConstantVectorTripCount(
35143514
void VPlanTransforms::materializeBackedgeTakenCount(VPlan &Plan,
35153515
VPBasicBlock *VectorPH) {
35163516
VPValue *BTC = Plan.getOrCreateBackedgeTakenCount();
3517-
if (BTC->getNumUsers() == 0)
3517+
if (BTC->getNumUses() == 0)
35183518
return;
35193519

35203520
VPBuilder Builder(VectorPH, VectorPH->begin());
@@ -3580,7 +3580,7 @@ void VPlanTransforms::materializeVectorTripCount(VPlan &Plan,
35803580
assert(VectorTC.isLiveIn() && "vector-trip-count must be a live-in");
35813581
// There's nothing to do if there are no users of the vector trip count or its
35823582
// IR value has already been set.
3583-
if (VectorTC.getNumUsers() == 0 || VectorTC.getLiveInIRValue())
3583+
if (VectorTC.getNumUses() == 0 || VectorTC.getLiveInIRValue())
35843584
return;
35853585

35863586
VPValue *TC = Plan.getTripCount();
@@ -3645,7 +3645,7 @@ void VPlanTransforms::materializeVFAndVFxUF(VPlan &Plan, VPBasicBlock *VectorPH,
36453645

36463646
// If there are no users of the runtime VF, compute VFxUF by constant folding
36473647
// the multiplication of VF and UF.
3648-
if (VF.getNumUsers() == 0) {
3648+
if (VF.getNumUses() == 0) {
36493649
VPValue *RuntimeVFxUF =
36503650
Builder.createElementCount(TCTy, VFEC * Plan.getUF());
36513651
VFxUF.replaceAllUsesWith(RuntimeVFxUF);

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ void VPlanTransforms::replicateByVF(VPlan &Plan, ElementCount VF) {
535535
continue;
536536

537537
VPBuilder Builder(RepR);
538-
if (RepR->getNumUsers() == 0) {
538+
if (RepR->getNumUses() == 0) {
539539
if (isa<StoreInst>(RepR->getUnderlyingInstr()) &&
540540
vputils::isSingleScalar(RepR->getOperand(1))) {
541541
// Stores to invariant addresses need to store the last lane only.

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,18 @@ class LLVM_ABI_FOR_TEST VPValue {
110110
void dump() const;
111111
#endif
112112

113-
unsigned getNumUsers() const { return Users.size(); }
113+
/// Returns the number of uses of this VPValue. The same user could appear
114+
/// more than once in the list due to this value being used for multiple
115+
/// operands in a recipe.
116+
unsigned getNumUses() const { return Users.size(); }
117+
118+
/// Adds a user of this value to the list.
114119
void addUser(VPUser &User) { Users.push_back(&User); }
115120

116-
/// Remove a single \p User from the list of users.
117-
void removeUser(VPUser &User) {
121+
/// Remove the first instance of \p User from the list of uses.
122+
void removeFirstUse(VPUser &User) {
118123
// The same user can be added multiple times, e.g. because the same VPValue
119-
// is used twice by the same VPUser. Remove a single one.
124+
// is used twice by the same VPUser. Remove the first one.
120125
auto *I = find(Users, &User);
121126
if (I != Users.end())
122127
Users.erase(I);
@@ -138,7 +143,7 @@ class LLVM_ABI_FOR_TEST VPValue {
138143

139144
/// Returns true if the value has more than one unique user.
140145
bool hasMoreThanOneUniqueUser() const {
141-
if (getNumUsers() == 0)
146+
if (getNumUses() == 0)
142147
return false;
143148

144149
// Check if all users match the first user.
@@ -203,7 +208,7 @@ class VPUser {
203208
/// Removes the operand at index \p Idx. This also removes the VPUser from the
204209
/// use-list of the operand.
205210
void removeOperand(unsigned Idx) {
206-
getOperand(Idx)->removeUser(*this);
211+
getOperand(Idx)->removeFirstUse(*this);
207212
Operands.erase(Operands.begin() + Idx);
208213
}
209214

@@ -224,7 +229,7 @@ class VPUser {
224229
VPUser &operator=(const VPUser &) = delete;
225230
virtual ~VPUser() {
226231
for (VPValue *Op : operands())
227-
Op->removeUser(*this);
232+
Op->removeFirstUse(*this);
228233
}
229234

230235
void addOperand(VPValue *Operand) {
@@ -239,7 +244,7 @@ class VPUser {
239244
}
240245

241246
void setOperand(unsigned I, VPValue *New) {
242-
Operands[I]->removeUser(*this);
247+
Operands[I]->removeFirstUse(*this);
243248
Operands[I] = New;
244249
New->addUser(*this);
245250
}
@@ -383,7 +388,7 @@ class VPDef {
383388
for (VPValue *D : make_early_inc_range(DefinedValues)) {
384389
assert(D->Def == this &&
385390
"all defined VPValues should point to the containing VPDef");
386-
assert(D->getNumUsers() == 0 &&
391+
assert(D->getNumUses() == 0 &&
387392
"all defined VPValues should have no more users");
388393
D->Def = nullptr;
389394
delete D;

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
198198
}
199199
// EVLIVIncrement is only used by EVLIV & BranchOnCount.
200200
// Having more than two users is unexpected.
201-
if ((I->getNumUsers() != 1) &&
202-
(I->getNumUsers() != 2 || none_of(I->users(), [&I](VPUser *U) {
201+
if ((I->getNumUses() != 1) &&
202+
(I->getNumUses() != 2 || none_of(I->users(), [&I](VPUser *U) {
203203
using namespace llvm::VPlanPatternMatch;
204204
return match(U, m_BranchOnCount(m_Specific(I), m_VPValue()));
205205
}))) {

0 commit comments

Comments
 (0)