[llvm] c65f3f5 - [AMDGPU] Simplify collectReachableCallees. NFCI.
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 23 01:21:37 PDT 2021
Author: Jay Foad
Date: 2021-06-23T09:11:29+01:00
New Revision: c65f3f562b15588a444322afe3f2cd3693681730
URL: https://github.com/llvm/llvm-project/commit/c65f3f562b15588a444322afe3f2cd3693681730
DIFF: https://github.com/llvm/llvm-project/commit/c65f3f562b15588a444322afe3f2cd3693681730.diff
LOG: [AMDGPU] Simplify collectReachableCallees. NFCI.
Don't use SCC iterators when we're only interested in reachability.
Use df_begin/df_end inline to find reachable nodes.
Differential Revision: https://reviews.llvm.org/D104704
Added:
Modified:
llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
index a8a023f4b543..da8fcf3900bb 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
@@ -12,7 +12,7 @@
#include "AMDGPULDSUtils.h"
#include "Utils/AMDGPUBaseInfo.h"
-#include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/IR/Constants.h"
@@ -44,20 +44,6 @@ class CollectReachableCallees {
}
}
- // For a given caller node, collect all reachable callee nodes.
- SmallPtrSet<CallGraphNode *, 8> collectCGNodes(CallGraphNode *CGN) {
- SmallPtrSet<CallGraphNode *, 8> CGNodes;
-
- for (scc_iterator<CallGraphNode *> I = scc_begin(CGN); !I.isAtEnd(); ++I) {
- const std::vector<CallGraphNode *> &SCC = *I;
- assert(!SCC.empty() && "SCC with no functions?");
- for (auto *CGNode : SCC)
- CGNodes.insert(CGNode);
- }
-
- return CGNodes;
- }
-
// For given kernel, collect all its reachable non-kernel functions.
SmallPtrSet<Function *, 8> collectReachableCallees(Function *K) {
SmallPtrSet<Function *, 8> ReachableCallees;
@@ -65,19 +51,16 @@ class CollectReachableCallees {
// Call graph node which represents this kernel.
auto *KCGN = CG[K];
- // Collect all reachable call graph nodes from the node representing this
- // kernel.
- SmallPtrSet<CallGraphNode *, 8> CGNodes = collectCGNodes(KCGN);
-
- // Go through collected reachable nodes, visit all thier call sites, if the
- // call site is direct, add corresponding callee to reachable callee set, if
- // it is indirect, resolve the indirect call site to potential reachable
- // callees, add them to reachable callee set, and repeat the process for the
- // newly added potential callee nodes.
+ // Go through all call graph nodes reachable from the node representing this
+ // kernel, visit all their call sites, if the call site is direct, add
+ // corresponding callee to reachable callee set, if it is indirect, resolve
+ // the indirect call site to potential reachable callees, add them to
+ // reachable callee set, and repeat the process for the newly added
+ // potential callee nodes.
//
// FIXME: Need to handle bit-casted function pointers.
//
- SmallVector<CallGraphNode *, 8> CGNStack(CGNodes.begin(), CGNodes.end());
+ SmallVector<CallGraphNode *, 8> CGNStack(df_begin(KCGN), df_end(KCGN));
SmallPtrSet<CallGraphNode *, 8> VisitedCGNodes;
while (!CGNStack.empty()) {
auto *CGN = CGNStack.pop_back_val();
@@ -97,9 +80,7 @@ class CollectReachableCallees {
auto *ACallee = ACGN->getFunction();
if (ACallee->getFunctionType() == RCBFTy) {
ReachableCallees.insert(ACallee);
- SmallPtrSet<CallGraphNode *, 8> IGCNNodes = collectCGNodes(ACGN);
- for (auto *IGCN : IGCNNodes)
- CGNStack.push_back(IGCN);
+ CGNStack.append(df_begin(ACGN), df_end(ACGN));
}
}
}
More information about the llvm-commits
mailing list