[llvm] b54ccab - [Attributor] Add an option to increase the max number of iterations
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 22 11:38:35 PDT 2021
Author: Joseph Huber
Date: 2021-06-22T14:38:25-04:00
New Revision: b54ccab5096dc186fbc8343e1af75b5ccb09821b
URL: https://github.com/llvm/llvm-project/commit/b54ccab5096dc186fbc8343e1af75b5ccb09821b
DIFF: https://github.com/llvm/llvm-project/commit/b54ccab5096dc186fbc8343e1af75b5ccb09821b.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 182a794b7ddf..3109dad526e9 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/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<Function *> &Functions, InformationCache &InfoCache,
CallGraphUpdater &CGUpdater,
DenseSet<const char *> *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<Function *> &Functions, InformationCache &InfoCache,
CallGraphUpdater &CGUpdater, DenseSet<const char *> *Allowed,
bool DeleteFns, bool RewriteSignatures,
+ Optional<unsigned> 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<OptimizationRemarkGetter>(OREGetter)),
PassName(PassName) {}
@@ -1859,6 +1865,9 @@ struct Attributor {
/// Whether to rewrite signatures.
const bool RewriteSignatures;
+ /// Maximum number of fixedpoint iterations.
+ Optional<unsigned> MaxFixpointIterations;
+
/// A set to remember the functions we already assume to be live and visited.
DenseSet<const Function *> VisitedFunctions;
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index b4d66b352c53..47d1bbc607fb 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/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<unsigned>
- 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<AbstractAttribute *, 32> ChangedAAs;
SetVector<AbstractAttribute *> 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/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index b6b8219324af..3e8460a340ff 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/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);
More information about the llvm-commits
mailing list