From 141815765ce20ab5e6c6337ebf895e63c8605268 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 16 Jun 2021 15:37:22 -0400 Subject: [PATCH] [Attributor] Add an option to increase the max number of iterations Right now the Attributor defaults to 32 fixed point iterations unless it is set explicitly by a command line flag. This patch allows this to be configured when the attributor instance is created. The maximum is then increased in OpenMPOpt if the target is a kernel. This is because the globalization analysis can result in larger iteration counts due to many dependent instances running at once. Depends on D102444 Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D104416 --- include/llvm/Transforms/IPO/Attributor.h | 11 ++++++++++- lib/Transforms/IPO/Attributor.cpp | 14 ++++++++++---- lib/Transforms/IPO/OpenMPOpt.cpp | 9 ++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/llvm/Transforms/IPO/Attributor.h b/include/llvm/Transforms/IPO/Attributor.h index 182a794b7dd..3109dad526e 100644 --- a/include/llvm/Transforms/IPO/Attributor.h +++ b/include/llvm/Transforms/IPO/Attributor.h @@ -1090,6 +1090,8 @@ struct Attributor { /// \param Allowed If not null, a set limiting the attribute opportunities. /// \param DeleteFns Whether to delete functions. /// \param RewriteSignatures Whether to rewrite function signatures. + /// \param MaxFixedPointIterations Maximum number of iterations to run until + /// fixpoint. Attributor(SetVector &Functions, InformationCache &InfoCache, CallGraphUpdater &CGUpdater, DenseSet *Allowed = nullptr, bool DeleteFns = true, @@ -1097,7 +1099,7 @@ struct Attributor { : Allocator(InfoCache.Allocator), Functions(Functions), InfoCache(InfoCache), CGUpdater(CGUpdater), Allowed(Allowed), DeleteFns(DeleteFns), RewriteSignatures(RewriteSignatures), - OREGetter(None), PassName("") {} + MaxFixpointIterations(None), OREGetter(None), PassName("") {} /// Constructor /// @@ -1107,16 +1109,20 @@ struct Attributor { /// \param CGUpdater Helper to update an underlying call graph. /// \param Allowed If not null, a set limiting the attribute opportunities. /// \param DeleteFns Whether to delete functions + /// \param MaxFixedPointIterations Maximum number of iterations to run until + /// fixpoint. /// \param OREGetter A callback function that returns an ORE object from a /// Function pointer. /// \param PassName The name of the pass emitting remarks. Attributor(SetVector &Functions, InformationCache &InfoCache, CallGraphUpdater &CGUpdater, DenseSet *Allowed, bool DeleteFns, bool RewriteSignatures, + Optional MaxFixpointIterations, OptimizationRemarkGetter OREGetter, const char *PassName) : Allocator(InfoCache.Allocator), Functions(Functions), InfoCache(InfoCache), CGUpdater(CGUpdater), Allowed(Allowed), DeleteFns(DeleteFns), RewriteSignatures(RewriteSignatures), + MaxFixpointIterations(MaxFixpointIterations), OREGetter(Optional(OREGetter)), PassName(PassName) {} @@ -1859,6 +1865,9 @@ private: /// Whether to rewrite signatures. const bool RewriteSignatures; + /// Maximum number of fixedpoint iterations. + Optional MaxFixpointIterations; + /// A set to remember the functions we already assume to be live and visited. DenseSet VisitedFunctions; diff --git a/lib/Transforms/IPO/Attributor.cpp b/lib/Transforms/IPO/Attributor.cpp index b4d66b352c5..47d1bbc607f 100644 --- a/lib/Transforms/IPO/Attributor.cpp +++ b/lib/Transforms/IPO/Attributor.cpp @@ -77,7 +77,7 @@ STATISTIC(NumAttributesManifested, // This will become more evolved once we perform two interleaved fixpoint // iterations: bottom-up and top-down. static cl::opt - MaxFixpointIterations("attributor-max-iterations", cl::Hidden, + SetFixpointIterations("attributor-max-iterations", cl::Hidden, cl::desc("Maximal number of fixpoint iterations."), cl::init(32)); @@ -1069,6 +1069,12 @@ void Attributor::runTillFixpoint() { // the abstract analysis. unsigned IterationCounter = 1; + unsigned MaxFixedPointIterations; + if (MaxFixpointIterations) + MaxFixedPointIterations = MaxFixpointIterations.getValue(); + else + MaxFixedPointIterations = SetFixpointIterations; + SmallVector ChangedAAs; SetVector Worklist, InvalidAAs; @@ -1148,7 +1154,7 @@ void Attributor::runTillFixpoint() { Worklist.clear(); Worklist.insert(ChangedAAs.begin(), ChangedAAs.end()); - } while (!Worklist.empty() && (IterationCounter++ < MaxFixpointIterations || + } while (!Worklist.empty() && (IterationCounter++ < MaxFixedPointIterations || VerifyMaxFixpointIterations)); LLVM_DEBUG(dbgs() << "\n[Attributor] Fixpoint iteration done after: " @@ -1187,9 +1193,9 @@ void Attributor::runTillFixpoint() { }); if (VerifyMaxFixpointIterations && - IterationCounter != MaxFixpointIterations) { + IterationCounter != MaxFixedPointIterations) { errs() << "\n[Attributor] Fixpoint iteration done after: " - << IterationCounter << "/" << MaxFixpointIterations + << IterationCounter << "/" << MaxFixedPointIterations << " iterations\n"; llvm_unreachable("The fixpoint was not reached with exactly the number of " "specified iterations!"); diff --git a/lib/Transforms/IPO/OpenMPOpt.cpp b/lib/Transforms/IPO/OpenMPOpt.cpp index b6b8219324a..3e8460a340f 100644 --- a/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/lib/Transforms/IPO/OpenMPOpt.cpp @@ -2666,7 +2666,8 @@ PreservedAnalyses OpenMPOptPass::run(Module &M, ModuleAnalysisManager &AM) { OMPInformationCache InfoCache(M, AG, Allocator, /*CGSCC*/ Functions, OMPInModule.getKernels()); - Attributor A(Functions, InfoCache, CGUpdater, nullptr, true, false, OREGetter, + unsigned MaxFixponitIterations = (!OMPInModule.getKernels().empty()) ? 64 : 32; + Attributor A(Functions, InfoCache, CGUpdater, nullptr, true, false, MaxFixponitIterations, OREGetter, DEBUG_TYPE); OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache, A); @@ -2722,7 +2723,8 @@ PreservedAnalyses OpenMPOptCGSCCPass::run(LazyCallGraph::SCC &C, OMPInformationCache InfoCache(*(Functions.back()->getParent()), AG, Allocator, /*CGSCC*/ Functions, OMPInModule.getKernels()); - Attributor A(Functions, InfoCache, CGUpdater, nullptr, false, true, OREGetter, + unsigned MaxFixponitIterations = (!OMPInModule.getKernels().empty()) ? 64 : 32; + Attributor A(Functions, InfoCache, CGUpdater, nullptr, false, true, MaxFixponitIterations, OREGetter, DEBUG_TYPE); OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache, A); @@ -2799,8 +2801,9 @@ struct OpenMPOptCGSCCLegacyPass : public CallGraphSCCPass { *(Functions.back()->getParent()), AG, Allocator, /*CGSCC*/ Functions, OMPInModule.getKernels()); + unsigned MaxFixponitIterations = (!OMPInModule.getKernels().empty()) ? 64 : 32; Attributor A(Functions, InfoCache, CGUpdater, nullptr, false, true, - OREGetter, DEBUG_TYPE); + MaxFixponitIterations, OREGetter, DEBUG_TYPE); OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache, A); return OMPOpt.run(false);