[llvm] 00500d5 - [NFC] De-template LazyCallGraph::visitReferences() and move into .cpp file
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 20 10:51:53 PDT 2021
Author: Arthur Eubanks
Date: 2021-10-20T10:50:00-07:00
New Revision: 00500d5bad2270ea244adfdc6a48171968f88901
URL: https://github.com/llvm/llvm-project/commit/00500d5bad2270ea244adfdc6a48171968f88901
DIFF: https://github.com/llvm/llvm-project/commit/00500d5bad2270ea244adfdc6a48171968f88901.diff
LOG: [NFC] De-template LazyCallGraph::visitReferences() and move into .cpp file
This makes changing it and recompiling it much faster.
Added:
Modified:
llvm/include/llvm/Analysis/LazyCallGraph.h
llvm/lib/Analysis/LazyCallGraph.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/LazyCallGraph.h b/llvm/include/llvm/Analysis/LazyCallGraph.h
index 81500905c0f50..d07642c4d7683 100644
--- a/llvm/include/llvm/Analysis/LazyCallGraph.h
+++ b/llvm/include/llvm/Analysis/LazyCallGraph.h
@@ -1085,47 +1085,9 @@ class LazyCallGraph {
/// updates that set with every constant visited.
///
/// For each defined function, calls \p Callback with that function.
- template <typename CallbackT>
static void visitReferences(SmallVectorImpl<Constant *> &Worklist,
SmallPtrSetImpl<Constant *> &Visited,
- CallbackT Callback) {
- while (!Worklist.empty()) {
- Constant *C = Worklist.pop_back_val();
-
- if (Function *F = dyn_cast<Function>(C)) {
- if (!F->isDeclaration())
- Callback(*F);
- continue;
- }
-
- // The blockaddress constant expression is a weird special case, we can't
- // generically walk its operands the way we do for all other constants.
- if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
- // If we've already visited the function referred to by the block
- // address, we don't need to revisit it.
- if (Visited.count(BA->getFunction()))
- continue;
-
- // If all of the blockaddress' users are instructions within the
- // referred to function, we don't need to insert a cycle.
- if (llvm::all_of(BA->users(), [&](User *U) {
- if (Instruction *I = dyn_cast<Instruction>(U))
- return I->getFunction() == BA->getFunction();
- return false;
- }))
- continue;
-
- // Otherwise we should go visit the referred to function.
- Visited.insert(BA->getFunction());
- Worklist.push_back(BA->getFunction());
- continue;
- }
-
- for (Value *Op : C->operand_values())
- if (Visited.insert(cast<Constant>(Op)).second)
- Worklist.push_back(cast<Constant>(Op));
- }
- }
+ function_ref<void(Function &)> Callback);
///@}
diff --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp
index 8170c32a2d157..672a2c6eba582 100644
--- a/llvm/lib/Analysis/LazyCallGraph.cpp
+++ b/llvm/lib/Analysis/LazyCallGraph.cpp
@@ -1961,6 +1961,47 @@ void LazyCallGraph::buildRefSCCs() {
});
}
+void LazyCallGraph::visitReferences(SmallVectorImpl<Constant *> &Worklist,
+ SmallPtrSetImpl<Constant *> &Visited,
+ function_ref<void(Function &)> Callback) {
+ while (!Worklist.empty()) {
+ Constant *C = Worklist.pop_back_val();
+
+ if (Function *F = dyn_cast<Function>(C)) {
+ if (!F->isDeclaration())
+ Callback(*F);
+ continue;
+ }
+
+ // The blockaddress constant expression is a weird special case, we can't
+ // generically walk its operands the way we do for all other constants.
+ if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
+ // If we've already visited the function referred to by the block
+ // address, we don't need to revisit it.
+ if (Visited.count(BA->getFunction()))
+ continue;
+
+ // If all of the blockaddress' users are instructions within the
+ // referred to function, we don't need to insert a cycle.
+ if (llvm::all_of(BA->users(), [&](User *U) {
+ if (Instruction *I = dyn_cast<Instruction>(U))
+ return I->getFunction() == BA->getFunction();
+ return false;
+ }))
+ continue;
+
+ // Otherwise we should go visit the referred to function.
+ Visited.insert(BA->getFunction());
+ Worklist.push_back(BA->getFunction());
+ continue;
+ }
+
+ for (Value *Op : C->operand_values())
+ if (Visited.insert(cast<Constant>(Op)).second)
+ Worklist.push_back(cast<Constant>(Op));
+ }
+}
+
AnalysisKey LazyCallGraphAnalysis::Key;
LazyCallGraphPrinterPass::LazyCallGraphPrinterPass(raw_ostream &OS) : OS(OS) {}
More information about the llvm-commits
mailing list