diff options
author | Ashutosh Nema <ashu1212@gmail.com> | 2015-08-19 05:40:42 +0000 |
---|---|---|
committer | Ashutosh Nema <ashu1212@gmail.com> | 2015-08-19 05:40:42 +0000 |
commit | c5b7b5558907b6ee9717c584f9f53fa21fd3cf76 (patch) | |
tree | de35c6cbc9c14bbe22165035c29fe58b1a5b932f /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | 9c039962cac7f05af8ea16fb1bdedf1003b048b7 (diff) | |
download | bcm5719-llvm-c5b7b5558907b6ee9717c584f9f53fa21fd3cf76.tar.gz bcm5719-llvm-c5b7b5558907b6ee9717c584f9f53fa21fd3cf76.zip |
Exposed findDefsUsedOutsideOfLoop as a loop utility function
Exposed findDefsUsedOutsideOfLoop as a loop utility function by moving
it from LoopDistribute to LoopUtils.
Reviewed By: anemet
llvm-svn: 245416
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index dae19d23db6..2bf6be452fd 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -501,3 +501,22 @@ bool llvm::isInductionPHI(PHINode *Phi, ScalarEvolution *SE, StepValue = ConstantInt::getSigned(CV->getType(), CVSize / Size); return true; } + +/// \brief Returns the instructions that use values defined in the loop. +SmallVector<Instruction *, 8> llvm::findDefsUsedOutsideOfLoop(Loop *L) { + SmallVector<Instruction *, 8> UsedOutside; + + for (auto *Block : L->getBlocks()) + // FIXME: I believe that this could use copy_if if the Inst reference could + // be adapted into a pointer. + for (auto &Inst : *Block) { + auto Users = Inst.users(); + if (std::any_of(Users.begin(), Users.end(), [&](User *U) { + auto *Use = cast<Instruction>(U); + return !L->contains(Use->getParent()); + })) + UsedOutside.push_back(&Inst); + } + + return UsedOutside; +} |