[llvm] e099c7b - [NFC][OpenMPOpt] Provide function-specific foreachUse.

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 16 03:34:24 PDT 2020


Author: sstefan1
Date: 2020-06-16T12:33:15+02:00
New Revision: e099c7b64a06caa6ee404066be507c7fc3efe10a

URL: https://github.com/llvm/llvm-project/commit/e099c7b64a06caa6ee404066be507c7fc3efe10a
DIFF: https://github.com/llvm/llvm-project/commit/e099c7b64a06caa6ee404066be507c7fc3efe10a.diff

LOG: [NFC][OpenMPOpt] Provide function-specific foreachUse.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 03be412cd24b..c05a9c6f3e28 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -118,24 +118,32 @@ struct OpenMPOpt {
     /// true. The callback will be fed the function in which the use was
     /// encountered as second argument.
     void foreachUse(function_ref<bool(Use &, Function &)> CB) {
+      for (auto &It : UsesMap)
+        foreachUse(CB, It.first, It.second.get());
+    }
+
+    /// Run the callback \p CB on each use within the function \p F and forget
+    /// the use if the result is true.
+    void foreachUse(function_ref<bool(Use &, Function &)> CB, Function *F,
+                    UseVector *Uses = nullptr) {
       SmallVector<unsigned, 8> ToBeDeleted;
-      for (auto &It : UsesMap) {
-        ToBeDeleted.clear();
-        unsigned Idx = 0;
-        UseVector &UV = *It.second;
-        for (Use *U : UV) {
-          if (CB(*U, *It.first))
-            ToBeDeleted.push_back(Idx);
-          ++Idx;
-        }
+      ToBeDeleted.clear();
 
-        // Remove the to-be-deleted indices in reverse order as prior
-        // modifcations will not modify the smaller indices.
-        while (!ToBeDeleted.empty()) {
-          unsigned Idx = ToBeDeleted.pop_back_val();
-          UV[Idx] = UV.back();
-          UV.pop_back();
-        }
+      unsigned Idx = 0;
+      UseVector &UV = Uses ? *Uses : getOrCreateUseVector(F);
+
+      for (Use *U : UV) {
+        if (CB(*U, *F))
+          ToBeDeleted.push_back(Idx);
+        ++Idx;
+      }
+
+      // Remove the to-be-deleted indices in reverse order as prior
+      // modifcations will not modify the smaller indices.
+      while (!ToBeDeleted.empty()) {
+        unsigned Idx = ToBeDeleted.pop_back_val();
+        UV[Idx] = UV.back();
+        UV.pop_back();
       }
     }
 


        


More information about the llvm-commits mailing list