[PATCH] D103694: [AMDGPU] Simplify handleAddressTakenFunctions. NFC.
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 4 05:26:49 PDT 2021
foad created this revision.
foad added reviewers: madhur13490, arsenm, rampitec.
Herald added subscribers: jdoerfert, kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
foad requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Use standard depth first iterators to simplify the implementation. Also
don't bother passing in ModuleCG when it is available in the class.
Repository:
rG LLVM Github Monorepo
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"
@@ -162,7 +163,7 @@
// 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
@@ -218,44 +219,32 @@
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]);
+ for (const char *AttrName : AttributeNames) {
+ if (F->hasFnAttribute(AttrName)) {
+ F->removeFnAttr(AttrName);
Changed = true;
}
}
return Changed;
}
-bool AMDGPUPropagateAttributes::handleAddressTakenFunctions(CallGraph *CG) {
- assert(ModuleCG && "Call graph not present");
-
+bool AMDGPUPropagateAttributes::handleAddressTakenFunctions() {
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 +367,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.349836.patch
Type: text/x-patch
Size: 2948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210604/f8bdf71a/attachment.bin>
More information about the llvm-commits
mailing list