diff options
| author | Hideto Ueno <uenoku.tokotoko@gmail.com> | 2019-09-21 15:13:19 +0000 |
|---|---|---|
| committer | Hideto Ueno <uenoku.tokotoko@gmail.com> | 2019-09-21 15:13:19 +0000 |
| commit | 63f6066b53d5094945fc47f382480290520b1605 (patch) | |
| tree | 3aa771e6bff2a80b1a3906157ccc900bce209626 /llvm/lib/Transforms | |
| parent | 9ec7117506355771a8410b6c92c94bc6f6754ffb (diff) | |
| download | bcm5719-llvm-63f6066b53d5094945fc47f382480290520b1605.tar.gz bcm5719-llvm-63f6066b53d5094945fc47f382480290520b1605.zip | |
[Attributor] Implement "norecurse" function attribute deduction
Summary:
This patch introduces `norecurse` function attribute deduction.
`norecurse` will be deduced if the following conditions hold:
* The size of SCC in which the function belongs equals to 1.
* The function doesn't have self-recursion.
* We have `norecurse` for all call site.
To avoid a large change, SCC is calculated using scc_iterator in InfoCache initialization for now.
Reviewers: jdoerfert, sstefan1
Reviewed By: jdoerfert
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67751
llvm-svn: 372475
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 0f5d2aa8e17..ef16ed04b5f 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -1530,10 +1530,38 @@ struct AANoRecurseImpl : public AANoRecurse { struct AANoRecurseFunction final : AANoRecurseImpl { AANoRecurseFunction(const IRPosition &IRP) : AANoRecurseImpl(IRP) {} + /// See AbstractAttribute::initialize(...). + void initialize(Attributor &A) override { + AANoRecurseImpl::initialize(A); + if (const Function *F = getAnchorScope()) + if (A.getInfoCache().getSccSize(*F) == 1) + return; + indicatePessimisticFixpoint(); + } + /// See AbstractAttribute::updateImpl(...). ChangeStatus updateImpl(Attributor &A) override { - // TODO: Implement this. - return indicatePessimisticFixpoint(); + + auto CheckForNoRecurse = [&](Instruction &I) { + ImmutableCallSite ICS(&I); + if (ICS.hasFnAttr(Attribute::NoRecurse)) + return true; + + const auto &NoRecurseAA = + A.getAAFor<AANoRecurse>(*this, IRPosition::callsite_function(ICS)); + if (!NoRecurseAA.isAssumedNoRecurse()) + return false; + + // Recursion to the same function + if (ICS.getCalledFunction() == getAnchorScope()) + return false; + + return true; + }; + + if (!A.checkForAllCallLikeInstructions(CheckForNoRecurse, *this)) + return indicatePessimisticFixpoint(); + return ChangeStatus::UNCHANGED; } void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(norecurse) } @@ -3934,6 +3962,9 @@ void Attributor::identifyDefaultAbstractAttributes(Function &F) { // Every function might be "no-return". getOrCreateAAFor<AANoReturn>(FPos); + // Every function might be "no-recurse". + getOrCreateAAFor<AANoRecurse>(FPos); + // Every function might be applicable for Heap-To-Stack conversion. if (EnableHeapToStack) getOrCreateAAFor<AAHeapToStack>(FPos); @@ -4113,7 +4144,7 @@ static bool runAttributorOnModule(Module &M, AnalysisGetter &AG) { // Create an Attributor and initially empty information cache that is filled // while we identify default attribute opportunities. - InformationCache InfoCache(M.getDataLayout(), AG); + InformationCache InfoCache(M, AG); Attributor A(InfoCache, DepRecInterval); for (Function &F : M) @@ -4149,9 +4180,7 @@ static bool runAttributorOnModule(Module &M, AnalysisGetter &AG) { } PreservedAnalyses AttributorPass::run(Module &M, ModuleAnalysisManager &AM) { - auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); - - AnalysisGetter AG(FAM); + AnalysisGetter AG(AM); if (runAttributorOnModule(M, AG)) { // FIXME: Think about passes we will preserve and add them here. return PreservedAnalyses::none(); |

