[PATCH] D12071: Exposing findDefsUsedOutsideOfLoop as a Loop utility

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 11:18:09 PDT 2015


anemet added a comment.

Hi Ashutosh,

Thanks for improving this.


================
Comment at: include/llvm/Transforms/Utils/LoopUtils.h:285-286
@@ +284,4 @@
+
+/// \brief Returns the instructions that use values defined in the loop.
+/// Iterates over loop instruction and get its outsider users.
+SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L);
----------------
Nit: I don't think this second line is necessary to describe the API, I would drop it.

================
Comment at: lib/Transforms/Scalar/LoopDistribute.cpp:60-78
@@ -58,2 +59,21 @@
 
+/// \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;
+}
+
 namespace {
----------------
You also need to move this to LoopUtils.cpp.


Repository:
  rL LLVM

http://reviews.llvm.org/D12071





More information about the llvm-commits mailing list