[llvm] 982247d - Value::isTransitiveUsedByMetadataOnly: Don't repeatedly add an element to the worklist. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 11 13:35:28 PDT 2022
Author: Fangrui Song
Date: 2022-04-11T13:35:25-07:00
New Revision: 982247dce5b2d126e66e53d6b6c0fbe592de7ed1
URL: https://github.com/llvm/llvm-project/commit/982247dce5b2d126e66e53d6b6c0fbe592de7ed1
DIFF: https://github.com/llvm/llvm-project/commit/982247dce5b2d126e66e53d6b6c0fbe592de7ed1.diff
LOG: Value::isTransitiveUsedByMetadataOnly: Don't repeatedly add an element to the worklist. NFC
Added:
Modified:
llvm/lib/IR/Value.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 6081388038b0b..d4294af100cee 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -1020,20 +1020,16 @@ bool Value::isSwiftError() const {
}
bool Value::isTransitiveUsedByMetadataOnly() const {
- if (use_empty())
- return false;
- llvm::SmallVector<const User *, 32> WorkList;
- llvm::SmallPtrSet<const User *, 32> Visited;
- WorkList.insert(WorkList.begin(), user_begin(), user_end());
+ SmallVector<const User *, 32> WorkList(user_begin(), user_end());
+ SmallPtrSet<const User *, 32> Visited(user_begin(), user_end());
while (!WorkList.empty()) {
const User *U = WorkList.pop_back_val();
- Visited.insert(U);
// If it is transitively used by a global value or a non-constant value,
// it's obviously not only used by metadata.
if (!isa<Constant>(U) || isa<GlobalValue>(U))
return false;
for (const User *UU : U->users())
- if (!Visited.count(UU))
+ if (Visited.insert(UU).second)
WorkList.push_back(UU);
}
return true;
More information about the llvm-commits
mailing list