[PM] Introduce a devirtualization iteration layer for the new PM.
This is an orthogonal and separated layer instead of being embedded
inside the pass manager. While it adds a small amount of complexity, it
is fairly minimal and the composability and control seems worth the
cost.
The logic for this ends up being nicely isolated and targeted. It should
be easy to experiment with different iteration strategies wrapped around
the CGSCC bottom-up walk using this kind of facility.
The mechanism used to track devirtualization is the simplest one I came
up with. I think it handles most of the cases the existing iteration
machinery handles, but I haven't done a *very* in depth analysis. It
does however match the basic intended semantics, and we can tweak or
tune its exact behavior incrementally as necessary. One thing that we
may want to revisit is freshly building the value handle set on each
iteration. While I don't think this will be a significant cost (it is
strictly fewer value handles but more churn of value handes than the old
call graph), it is conceivable that we'll want a somewhat more clever
tracking mechanism. My hope is to layer that on as a follow up patch
with data supporting any implementation complexity it adds.
This code also provides for a basic count heuristic: if the number of
indirect calls decreases and the number of direct calls increases for
a given function in the SCC, we assume devirtualization is responsible.
This matches the heuristics currently used in the legacy pass manager.
Differential Revision: https://reviews.llvm.org/D23114
llvm-svn: 290665
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 40536a9..6e0aae5 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -592,6 +592,15 @@
return Count;
}
+static Optional<int> parseDevirtPassName(StringRef Name) {
+ if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
+ return None;
+ int Count;
+ if (Name.getAsInteger(0, Count) || Count <= 0)
+ return None;
+ return Count;
+}
+
static bool isModulePassName(StringRef Name) {
// Manually handle aliases for pre-configured pipeline fragments.
if (Name.startswith("default") || Name.startswith("lto"))
@@ -630,6 +639,8 @@
// Explicitly handle custom-parsed pass names.
if (parseRepeatPassName(Name))
return true;
+ if (parseDevirtPassName(Name))
+ return true;
#define CGSCC_PASS(NAME, CREATE_PASS) \
if (Name == NAME) \
@@ -873,6 +884,15 @@
CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
return true;
}
+ if (auto MaxRepetitions = parseDevirtPassName(Name)) {
+ CGSCCPassManager NestedCGPM(DebugLogging);
+ if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
+ DebugLogging))
+ return false;
+ CGPM.addPass(createDevirtSCCRepeatedPass(std::move(NestedCGPM),
+ *MaxRepetitions, DebugLogging));
+ return true;
+ }
// Normal passes can't have pipelines.
return false;
}