[PATCH] D104704: [AMDGPU] Simplify collectReachableCallees. NFCI.

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 22 05:22:51 PDT 2021


foad created this revision.
foad added reviewers: hsmhsm, rampitec.
Herald added subscribers: kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl, arsenm.
foad requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

Don't use SCC iterators when we're only interested in reachability.
Use df_begin/df_end inline to find reachable nodes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104704

Files:
  llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp


Index: llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
+++ 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 @@
     }
   }
 
-  // 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,11 +51,8 @@
     // 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
+    // Go through all call graph nodes reachable from the node representing this
+    // kernel, 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
@@ -77,7 +60,7 @@
     //
     // 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 @@
             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));
             }
           }
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104704.353614.patch
Type: text/x-patch
Size: 2740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210622/4a547423/attachment.bin>


More information about the llvm-commits mailing list