Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 5403bca

Browse files
committed
[attrs] Simplify the convergent removal to directly use the pre-built
node set rather than walking the SCC directly. This directly exposes the functions and has already had null entries filtered out. We also don't need need to handle optnone as it has already been handled in the caller -- we never try to remove convergent when there are optnone functions in the SCC. With this change, the code for removing convergent should work with the new pass manager and a different SCC analysis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260668 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3f89873 commit 5403bca

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -938,27 +938,18 @@ static bool addNonNullAttrs(const SCCNodeSet &SCCNodes,
938938
/// Removes convergent attributes where we can prove that none of the SCC's
939939
/// callees are themselves convergent. Returns true if successful at removing
940940
/// the attribute.
941-
static bool removeConvergentAttrs(const CallGraphSCC &SCC,
942-
const SCCNodeSet &SCCNodes) {
941+
static bool removeConvergentAttrs(const SCCNodeSet &SCCNodes) {
943942
// Determines whether a function can be made non-convergent, ignoring all
944943
// other functions in SCC. (A function can *actually* be made non-convergent
945944
// only if all functions in its SCC can be made convergent.)
946-
auto CanRemoveConvergent = [&](CallGraphNode *CGN) {
947-
Function *F = CGN->getFunction();
948-
if (!F)
949-
return false;
950-
945+
auto CanRemoveConvergent = [&](Function *F) {
951946
if (!F->isConvergent())
952947
return true;
953948

954949
// Can't remove convergent from declarations.
955950
if (F->isDeclaration())
956951
return false;
957952

958-
// Don't remove convergent from optnone functions.
959-
if (F->hasFnAttribute(Attribute::OptimizeNone))
960-
return false;
961-
962953
for (Instruction &I : instructions(*F))
963954
if (auto CS = CallSite(&I)) {
964955
// Can't remove convergent if any of F's callees -- ignoring functions
@@ -979,19 +970,16 @@ static bool removeConvergentAttrs(const CallGraphSCC &SCC,
979970
// We can remove the convergent attr from functions in the SCC if they all
980971
// can be made non-convergent (because they call only non-convergent
981972
// functions, other than each other).
982-
if (!llvm::all_of(SCC, CanRemoveConvergent))
973+
if (!llvm::all_of(SCCNodes, CanRemoveConvergent))
983974
return false;
984975

985-
// If we got here, all of the SCC's callees are non-convergent, and none of
986-
// the optnone functions in the SCC are marked as convergent. Therefore all
976+
// If we got here, all of the SCC's callees are non-convergent. Therefore all
987977
// of the SCC's functions can be marked as non-convergent.
988-
for (CallGraphNode *CGN : SCC)
989-
if (Function *F = CGN->getFunction()) {
990-
if (F->isConvergent())
991-
DEBUG(dbgs() << "Removing convergent attr from " << F->getName()
992-
<< "\n");
993-
F->setNotConvergent();
994-
}
978+
for (Function *F : SCCNodes) {
979+
if (F->isConvergent())
980+
DEBUG(dbgs() << "Removing convergent attr from " << F->getName() << "\n");
981+
F->setNotConvergent();
982+
}
995983
return true;
996984
}
997985

@@ -1071,7 +1059,7 @@ bool PostOrderFunctionAttrs::runOnSCC(CallGraphSCC &SCC) {
10711059
if (!ExternalNode) {
10721060
Changed |= addNoAliasAttrs(SCCNodes);
10731061
Changed |= addNonNullAttrs(SCCNodes, *TLI);
1074-
Changed |= removeConvergentAttrs(SCC, SCCNodes);
1062+
Changed |= removeConvergentAttrs(SCCNodes);
10751063
}
10761064

10771065
Changed |= addNoRecurseAttrs(SCC);

0 commit comments

Comments
 (0)