[PATCH] D103694: [AMDGPU] Simplify handleAddressTakenFunctions. NFC.

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 7 02:54:57 PDT 2021


foad updated this revision to Diff 350212.
foad added a comment.

Change removeAttributes to take a reference. Reinstate an assert.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103694/new/

https://reviews.llvm.org/D103694

Files:
  llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp


Index: llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
@@ -29,6 +29,7 @@
 #include "AMDGPU.h"
 #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
 #include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
@@ -157,12 +158,12 @@
 
   // Remove attributes from F.
   // This is used in presence of address taken functions.
-  bool removeAttributes(Function *F);
+  bool removeAttributes(Function &F);
 
   // Handle call graph rooted at address taken functions.
   // This function will erase all attributes present
   // on all functions called from address taken functions transitively.
-  bool handleAddressTakenFunctions(CallGraph *CG);
+  bool handleAddressTakenFunctions();
 };
 
 // Allows to propagate attributes early, but no clonning is allowed as it must
@@ -216,46 +217,36 @@
                 "Late propagate attributes from kernels to functions",
                 false, false)
 
-bool AMDGPUPropagateAttributes::removeAttributes(Function *F) {
+bool AMDGPUPropagateAttributes::removeAttributes(Function &F) {
   bool Changed = false;
-  if (!F)
-    return Changed;
-  LLVM_DEBUG(dbgs() << "Removing attributes from " << F->getName() << '\n');
-  for (unsigned I = 0; I < NumAttr; ++I) {
-    if (F->hasFnAttribute(AttributeNames[I])) {
-      F->removeFnAttr(AttributeNames[I]);
+  LLVM_DEBUG(dbgs() << "Removing attributes from " << F.getName() << '\n');
+  for (const char *AttrName : AttributeNames) {
+    if (F.hasFnAttribute(AttrName)) {
+      F.removeFnAttr(AttrName);
       Changed = true;
     }
   }
   return Changed;
 }
 
-bool AMDGPUPropagateAttributes::handleAddressTakenFunctions(CallGraph *CG) {
+bool AMDGPUPropagateAttributes::handleAddressTakenFunctions() {
   assert(ModuleCG && "Call graph not present");
 
   bool Changed = false;
-  SmallSet<CallGraphNode *, 32> Visited;
+  df_iterator_default_set<CallGraphNode *> Reachable;
 
+  // Find all functions reachable from address-taken functions.
   for (Function *F : AddressTakenFunctions) {
-    CallGraphNode *CGN = (*CG)[F];
-    if (!Visited.count(CGN)) {
-      Changed |= removeAttributes(F);
-      Visited.insert(CGN);
-    }
+    for (auto *I : depth_first_ext((*ModuleCG)[F], Reachable))
+      (void)I;
+  }
 
-    std::queue<CallGraphNode *> SubGraph;
-    SubGraph.push(CGN);
-    while (!SubGraph.empty()) {
-      CallGraphNode *CGN = SubGraph.front();
-      SubGraph.pop();
-      if (!Visited.count(CGN)) {
-        Changed |= removeAttributes(CGN->getFunction());
-        Visited.insert(CGN);
-      }
-      for (auto N : *CGN)
-        SubGraph.push(N.second);
-    }
+  // Remove attributes from all reachable functions.
+  for (CallGraphNode *CGN : Reachable) {
+    if (Function *F = CGN->getFunction())
+      Changed |= removeAttributes(*F);
   }
+
   return Changed;
 }
 
@@ -378,7 +369,7 @@
   // calls separate to handle them gracefully.
   // The core traversal need not be affected by this.
   if (AllowClone)
-    Changed |= handleAddressTakenFunctions(ModuleCG);
+    Changed |= handleAddressTakenFunctions();
 
   return Changed;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103694.350212.patch
Type: text/x-patch
Size: 3367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210607/6e732670/attachment.bin>


More information about the llvm-commits mailing list