[llvm] 3273430 - Re-add getSingleUndroppableUse API

Anna Thomas via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 15 14:08:46 PDT 2021


Author: Anna Thomas
Date: 2021-09-15T17:06:20-04:00
New Revision: 3273430406c186f1f2af597adeedf21d4fa52b18

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

LOG: Re-add getSingleUndroppableUse API

The API was removed in 4ac4e52189aa in favor of
getUniqueUndroppableUser.
However, this caused a buildbot failure in AbstractCallSiteTest.cpp,
which uses the API and the AbstractCallSite class requires a "use"
rather than a user.
Retain the API so that the unittest compiles and passes.

Added: 
    

Modified: 
    llvm/include/llvm/IR/Value.h
    llvm/lib/IR/Value.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index d3224932bdfe..253c97c3b5e3 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -452,6 +452,13 @@ class Value {
   /// in the worst case, the whole use list of a value.
   bool hasOneUser() const;
 
+  /// Return true if there is exactly one use of this value that cannot be
+  /// dropped.
+  Use *getSingleUndroppableUse();
+  const Use *getSingleUndroppableUse() const {
+    return const_cast<Value *>(this)->getSingleUndroppableUse();
+  }
+
   /// Return true if there is exactly one unique user of this value that cannot be
   /// dropped (that user can have multiple uses of this value).
   User *getUniqueUndroppableUser();

diff  --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index a47ab683630c..7d2d73a17889 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -164,6 +164,18 @@ bool Value::hasOneUser() const {
 
 static bool isUnDroppableUser(const User *U) { return !U->isDroppable(); }
 
+Use *Value::getSingleUndroppableUse() {
+  Use *Result = nullptr;
+  for (Use &U : uses()) {
+    if (!U.getUser()->isDroppable()) {
+      if (Result)
+        return nullptr;
+      Result = &U;
+    }
+  }
+  return Result;
+}
+
 User *Value::getUniqueUndroppableUser() {
   User *Result = nullptr;
   for (auto *U : users()) {


        


More information about the llvm-commits mailing list