diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -1090,6 +1090,8 @@ /// \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 @@ : 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 @@ /// \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 @@ /// 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/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -77,7 +77,7 @@ // 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 @@ // 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 @@ 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 @@ }); 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/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -2666,7 +2666,8 @@ 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 @@ 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 @@ *(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);