diff options
author | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2018-05-22 08:33:02 +0000 |
---|---|---|
committer | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2018-05-22 08:33:02 +0000 |
commit | fecef6be9ef257198e42f8acb4cf5d7051ba5f0a (patch) | |
tree | 3838f36b38138ec6e12daf07293a3da193049bb0 /llvm/lib/Transforms/Utils | |
parent | 844663353d34c43e99d920042820a8a33f5ab1de (diff) | |
download | bcm5719-llvm-fecef6be9ef257198e42f8acb4cf5d7051ba5f0a.tar.gz bcm5719-llvm-fecef6be9ef257198e42f8acb4cf5d7051ba5f0a.zip |
[LoopVersioning] Don't modify the list that we iterate over in addPHINodes
Summary:
In LoopVersioning::addPHINodes we need to iterate over all
users for a value "Inst", and if the user is outside of the
VersionedLoop we should replace the use of "Inst" by using
the value "PN" instead.
Replacing the use of "Inst" for a user of "Inst" also means
that Inst->users() is modified. So it is not safe to do the
replace while iterating over Inst->users() as we used to do.
This patch splits the task into two steps. First we iterate
over Inst->users() to find all users that should be updated.
Those users are saved into a local data structure on the stack.
And then, in the second step, we do the actual updates. This
time iterating over the local data structure.
Reviewers: mzolotukhin, anemet
Reviewed By: mzolotukhin
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D47134
llvm-svn: 332958
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopVersioning.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopVersioning.cpp b/llvm/lib/Transforms/Utils/LoopVersioning.cpp index 95e9a186c10..abbcd5f9e3b 100644 --- a/llvm/lib/Transforms/Utils/LoopVersioning.cpp +++ b/llvm/lib/Transforms/Utils/LoopVersioning.cpp @@ -140,9 +140,12 @@ void LoopVersioning::addPHINodes( if (!PN) { PN = PHINode::Create(Inst->getType(), 2, Inst->getName() + ".lver", &PHIBlock->front()); - for (auto *User : Inst->users()) - if (!VersionedLoop->contains(cast<Instruction>(User)->getParent())) - User->replaceUsesOfWith(Inst, PN); + SmallVector<User*, 8> UsersToUpdate; + for (User *U : Inst->users()) + if (!VersionedLoop->contains(cast<Instruction>(U)->getParent())) + UsersToUpdate.push_back(U); + for (User *U : UsersToUpdate) + U->replaceUsesOfWith(Inst, PN); PN->addIncoming(Inst, VersionedLoop->getExitingBlock()); } } |