Skip to content

Commit c7ac27b

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
[vm/ffi] Refactor and fix pipeline for force-optimized code.
Change-Id: I18429fcfe44065c73674c9a00977e222e5abb5de Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114513 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Samir Jindel <[email protected]>
1 parent 71f1a61 commit c7ac27b

File tree

4 files changed

+53
-39
lines changed

4 files changed

+53
-39
lines changed

runtime/vm/compiler/aot/precompiler.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,12 @@ bool PrecompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
22852285
pass_state.reorder_blocks =
22862286
FlowGraph::ShouldReorderBlocks(function, optimized());
22872287

2288-
if (optimized()) {
2288+
if (function.ForceOptimize()) {
2289+
ASSERT(optimized());
2290+
TIMELINE_DURATION(thread(), CompilerVerbose, "OptimizationPasses");
2291+
flow_graph = CompilerPass::RunForceOptimizedPipeline(CompilerPass::kAOT,
2292+
&pass_state);
2293+
} else if (optimized()) {
22892294
TIMELINE_DURATION(thread(), CompilerVerbose, "OptimizationPasses");
22902295

22912296
pass_state.inline_id_to_function.Add(&function);

runtime/vm/compiler/compiler_pass.cc

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -236,42 +236,43 @@ void CompilerPass::RunInliningPipeline(PipelineMode mode,
236236
INVOKE_PASS(TryOptimizePatterns);
237237
}
238238

239-
FlowGraph* CompilerPass::RunPipeline(PipelineMode mode,
240-
CompilerPassState* pass_state) {
241-
if (mode == kForced) {
242-
INVOKE_PASS(ComputeSSA);
243-
if (FLAG_early_round_trip_serialization) {
244-
INVOKE_PASS(RoundTripSerialization);
245-
}
246-
INVOKE_PASS(TypePropagation);
247-
INVOKE_PASS(ApplyClassIds);
248-
INVOKE_PASS(Canonicalize);
249-
INVOKE_PASS(BranchSimplify);
250-
INVOKE_PASS(IfConvert);
251-
INVOKE_PASS(ConstantPropagation);
252-
INVOKE_PASS(TypePropagation);
253-
INVOKE_PASS(WidenSmiToInt32);
254-
INVOKE_PASS(SelectRepresentations);
255-
INVOKE_PASS(TypePropagation);
256-
INVOKE_PASS(TryCatchOptimization);
257-
INVOKE_PASS(EliminateEnvironments);
258-
INVOKE_PASS(EliminateDeadPhis);
259-
INVOKE_PASS(Canonicalize);
260-
INVOKE_PASS(WriteBarrierElimination);
261-
INVOKE_PASS(FinalizeGraph);
239+
FlowGraph* CompilerPass::RunForceOptimizedPipeline(
240+
PipelineMode mode,
241+
CompilerPassState* pass_state) {
242+
INVOKE_PASS(ComputeSSA);
243+
if (FLAG_early_round_trip_serialization) {
244+
INVOKE_PASS(RoundTripSerialization);
245+
}
246+
INVOKE_PASS(TypePropagation);
247+
INVOKE_PASS(Canonicalize);
248+
INVOKE_PASS(BranchSimplify);
249+
INVOKE_PASS(IfConvert);
250+
INVOKE_PASS(ConstantPropagation);
251+
INVOKE_PASS(TypePropagation);
252+
INVOKE_PASS(WidenSmiToInt32);
253+
INVOKE_PASS(SelectRepresentations);
254+
INVOKE_PASS(TypePropagation);
255+
INVOKE_PASS(TryCatchOptimization);
256+
INVOKE_PASS(EliminateEnvironments);
257+
INVOKE_PASS(EliminateDeadPhis);
258+
INVOKE_PASS(Canonicalize);
259+
INVOKE_PASS(WriteBarrierElimination);
260+
INVOKE_PASS(FinalizeGraph);
262261
#if defined(DART_PRECOMPILER)
263-
if (mode == kAOT) {
264-
INVOKE_PASS(SerializeGraph);
265-
}
262+
if (mode == kAOT) {
263+
INVOKE_PASS(SerializeGraph);
264+
}
266265
#endif
267-
if (FLAG_late_round_trip_serialization) {
268-
INVOKE_PASS(RoundTripSerialization);
269-
}
270-
INVOKE_PASS(AllocateRegisters);
271-
INVOKE_PASS(ReorderBlocks);
272-
return pass_state->flow_graph;
266+
if (FLAG_late_round_trip_serialization) {
267+
INVOKE_PASS(RoundTripSerialization);
273268
}
269+
INVOKE_PASS(AllocateRegisters);
270+
INVOKE_PASS(ReorderBlocks);
271+
return pass_state->flow_graph;
272+
}
274273

274+
FlowGraph* CompilerPass::RunPipeline(PipelineMode mode,
275+
CompilerPassState* pass_state) {
275276
INVOKE_PASS(ComputeSSA);
276277
if (FLAG_early_round_trip_serialization) {
277278
INVOKE_PASS(RoundTripSerialization);

runtime/vm/compiler/compiler_pass.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ class CompilerPass {
141141

142142
static void ParseFilters(const char* filter);
143143

144-
enum PipelineMode {
145-
kJIT, // Includes speculative and inter-procedural optimizations.
146-
kAOT, // Includes inter-procedural optimizations.
147-
kForced // Does not include speculative or inter-procedural optimizations.
148-
};
144+
enum PipelineMode { kJIT, kAOT };
149145

150146
static void RunGraphIntrinsicPipeline(CompilerPassState* state);
151147

@@ -165,6 +161,13 @@ class CompilerPass {
165161
CompilerPassState* state,
166162
std::initializer_list<CompilerPass::Id> passes);
167163

164+
// Pipeline which is used for "force-optimized" functions.
165+
//
166+
// Must not include speculative or inter-procedural optimizations.
167+
DART_WARN_UNUSED_RESULT
168+
static FlowGraph* RunForceOptimizedPipeline(PipelineMode mode,
169+
CompilerPassState* state);
170+
168171
protected:
169172
// This function executes the pass. If it returns true then
170173
// we will run Canonicalize on the graph and execute the pass

runtime/vm/compiler/jit/compiler.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,12 @@ RawCode* CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
616616
CompilerPassState pass_state(thread(), flow_graph, &speculative_policy);
617617
pass_state.reorder_blocks = reorder_blocks;
618618

619-
if (optimized()) {
619+
if (function.ForceOptimize()) {
620+
ASSERT(optimized());
621+
TIMELINE_DURATION(thread(), CompilerVerbose, "OptimizationPasses");
622+
flow_graph = CompilerPass::RunForceOptimizedPipeline(CompilerPass::kJIT,
623+
&pass_state);
624+
} else if (optimized()) {
620625
TIMELINE_DURATION(thread(), CompilerVerbose, "OptimizationPasses");
621626

622627
pass_state.inline_id_to_function.Add(&function);

0 commit comments

Comments
 (0)