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

Commit dc21a6f

Browse files
author
Johannes Doerfert
committed
[NFC][FunctionAttrs] Remove duplication in old/new PM pipeline
This patch just extract code into a separate function to remove some duplication between the old and new pass manager pipeline. Due to the different CGSCC iterators used, not all code duplication was eliminated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338585 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4619b05 commit dc21a6f

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,31 @@ static bool addNoRecurseAttrs(const SCCNodeSet &SCCNodes) {
12861286
return setDoesNotRecurse(*F);
12871287
}
12881288

1289+
template <typename AARGetterT>
1290+
static bool deriveAttrsInPostOrder(SCCNodeSet &SCCNodes, AARGetterT &&AARGetter,
1291+
bool HasUnknownCall) {
1292+
bool Changed = false;
1293+
1294+
// Bail if the SCC only contains optnone functions.
1295+
if (SCCNodes.empty())
1296+
return Changed;
1297+
1298+
Changed |= addArgumentReturnedAttrs(SCCNodes);
1299+
Changed |= addReadAttrs(SCCNodes, AARGetter);
1300+
Changed |= addArgumentAttrs(SCCNodes);
1301+
1302+
// If we have no external nodes participating in the SCC, we can deduce some
1303+
// more precise attributes as well.
1304+
if (!HasUnknownCall) {
1305+
Changed |= addNoAliasAttrs(SCCNodes);
1306+
Changed |= addNonNullAttrs(SCCNodes);
1307+
Changed |= inferAttrsFromFunctionBodies(SCCNodes);
1308+
Changed |= addNoRecurseAttrs(SCCNodes);
1309+
}
1310+
1311+
return Changed;
1312+
}
1313+
12891314
PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
12901315
CGSCCAnalysisManager &AM,
12911316
LazyCallGraph &CG,
@@ -1328,21 +1353,10 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
13281353
SCCNodes.insert(&F);
13291354
}
13301355

1331-
bool Changed = false;
1332-
Changed |= addArgumentReturnedAttrs(SCCNodes);
1333-
Changed |= addReadAttrs(SCCNodes, AARGetter);
1334-
Changed |= addArgumentAttrs(SCCNodes);
1335-
1336-
// If we have no external nodes participating in the SCC, we can deduce some
1337-
// more precise attributes as well.
1338-
if (!HasUnknownCall) {
1339-
Changed |= addNoAliasAttrs(SCCNodes);
1340-
Changed |= addNonNullAttrs(SCCNodes);
1341-
Changed |= inferAttrsFromFunctionBodies(SCCNodes);
1342-
Changed |= addNoRecurseAttrs(SCCNodes);
1343-
}
1356+
if (deriveAttrsInPostOrder(SCCNodes, AARGetter, HasUnknownCall))
1357+
return PreservedAnalyses::none();
13441358

1345-
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
1359+
return PreservedAnalyses::all();
13461360
}
13471361

13481362
namespace {
@@ -1382,7 +1396,6 @@ Pass *llvm::createPostOrderFunctionAttrsLegacyPass() {
13821396

13831397
template <typename AARGetterT>
13841398
static bool runImpl(CallGraphSCC &SCC, AARGetterT AARGetter) {
1385-
bool Changed = false;
13861399

13871400
// Fill SCCNodes with the elements of the SCC. Used for quickly looking up
13881401
// whether a given CallGraphNode is in this SCC. Also track whether there are
@@ -1403,24 +1416,7 @@ static bool runImpl(CallGraphSCC &SCC, AARGetterT AARGetter) {
14031416
SCCNodes.insert(F);
14041417
}
14051418

1406-
// Skip it if the SCC only contains optnone functions.
1407-
if (SCCNodes.empty())
1408-
return Changed;
1409-
1410-
Changed |= addArgumentReturnedAttrs(SCCNodes);
1411-
Changed |= addReadAttrs(SCCNodes, AARGetter);
1412-
Changed |= addArgumentAttrs(SCCNodes);
1413-
1414-
// If we have no external nodes participating in the SCC, we can deduce some
1415-
// more precise attributes as well.
1416-
if (!ExternalNode) {
1417-
Changed |= addNoAliasAttrs(SCCNodes);
1418-
Changed |= addNonNullAttrs(SCCNodes);
1419-
Changed |= inferAttrsFromFunctionBodies(SCCNodes);
1420-
Changed |= addNoRecurseAttrs(SCCNodes);
1421-
}
1422-
1423-
return Changed;
1419+
return deriveAttrsInPostOrder(SCCNodes, AARGetter, ExternalNode);
14241420
}
14251421

14261422
bool PostOrderFunctionAttrsLegacyPass::runOnSCC(CallGraphSCC &SCC) {

0 commit comments

Comments
 (0)