Skip to content

Commit

Permalink
[VPlan] Use replaceUsesWithIf in replaceAllUseswith and add comment (…
Browse files Browse the repository at this point in the history
…NFCI).

Follow-up to post-commit commens for b1bfe22.
  • Loading branch information
fhahn committed Jan 21, 2024
1 parent b0b491d commit 3683852
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions llvm/lib/Transforms/Vectorize/VPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,29 +1136,18 @@ void VPlanIngredient::print(raw_ostream &O) const {
template void DomTreeBuilder::Calculate<VPDominatorTree>(VPDominatorTree &DT);

void VPValue::replaceAllUsesWith(VPValue *New) {
if (this == New)
return;
for (unsigned J = 0; J < getNumUsers();) {
VPUser *User = Users[J];
bool RemovedUser = false;
for (unsigned I = 0, E = User->getNumOperands(); I < E; ++I)
if (User->getOperand(I) == this) {
User->setOperand(I, New);
RemovedUser = true;
}
// If a user got removed after updating the current user, the next user to
// update will be moved to the current position, so we only need to
// increment the index if the number of users did not change.
if (!RemovedUser)
J++;
}
replaceUsesWithIf(New, [](VPUser &, unsigned) { return true; });
}

void VPValue::replaceUsesWithIf(
VPValue *New,
llvm::function_ref<bool(VPUser &U, unsigned Idx)> ShouldReplace) {
// Note that this early exit is required for correctness; the implementation
// below relies on the number of users for this VPValue to decrease, which
// isn't the case if this == New.
if (this == New)
return;

for (unsigned J = 0; J < getNumUsers();) {
VPUser *User = Users[J];
bool RemovedUser = false;
Expand Down

0 comments on commit 3683852

Please sign in to comment.