Skip to content

Commit 4c1d453

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm/compiler] Cleanup outdated CompilationPipeline
TEST=ci Change-Id: Ia817aab0d607b1259ab2d3398a0a2cb97267753c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398586 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 76c2573 commit 4c1d453

File tree

4 files changed

+63
-131
lines changed

4 files changed

+63
-131
lines changed

runtime/vm/compiler/aot/precompiler.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class PrecompileParsedFunctionHelper : public ValueObject {
345345
optimized_(optimized),
346346
thread_(Thread::Current()) {}
347347

348-
bool Compile(CompilationPipeline* pipeline);
348+
bool Compile();
349349

350350
private:
351351
ParsedFunction* parsed_function() const { return parsed_function_; }
@@ -3493,7 +3493,7 @@ static void GenerateNecessaryAllocationStubs(FlowGraph* flow_graph) {
34933493
}
34943494

34953495
// Return false if bailed out.
3496-
bool PrecompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
3496+
bool PrecompileParsedFunctionHelper::Compile() {
34973497
ASSERT(CompilerState::Current().is_aot());
34983498
if (optimized() && !parsed_function()->function().IsOptimizable()) {
34993499
// All functions compiled by precompiler must be optimizable.
@@ -3522,6 +3522,7 @@ bool PrecompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
35223522
FlowGraph* flow_graph = nullptr;
35233523
ZoneGrowableArray<const ICData*>* ic_data_array = nullptr;
35243524
const Function& function = parsed_function()->function();
3525+
ASSERT(!function.IsIrregexpFunction());
35253526

35263527
CompilerState compiler_state(thread(), /*is_aot=*/true, optimized(),
35273528
CompilerState::ShouldTrace(function));
@@ -3532,9 +3533,12 @@ bool PrecompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
35323533

35333534
TIMELINE_DURATION(thread(), CompilerVerbose, "BuildFlowGraph");
35343535
COMPILER_TIMINGS_TIMER_SCOPE(thread(), BuildGraph);
3535-
flow_graph =
3536-
pipeline->BuildFlowGraph(zone, parsed_function(), ic_data_array,
3537-
Compiler::kNoOSRDeoptId, optimized());
3536+
kernel::FlowGraphBuilder builder(parsed_function(), ic_data_array,
3537+
/* not building var desc */ nullptr,
3538+
/* not inlining */ nullptr,
3539+
optimized(), Compiler::kNoOSRDeoptId);
3540+
flow_graph = builder.BuildGraph();
3541+
ASSERT(flow_graph != nullptr);
35383542
}
35393543

35403544
if (optimized()) {
@@ -3704,7 +3708,6 @@ bool PrecompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
37043708
}
37053709

37063710
static ErrorPtr PrecompileFunctionHelper(Precompiler* precompiler,
3707-
CompilationPipeline* pipeline,
37083711
const Function& function,
37093712
bool optimized) {
37103713
// Check that we optimize, except if the function is not optimizable.
@@ -3729,14 +3732,10 @@ static ErrorPtr PrecompileFunctionHelper(Precompiler* precompiler,
37293732
function.ToFullyQualifiedCString(), function.token_pos().Pos(),
37303733
(function.end_token_pos().Pos() - function.token_pos().Pos()));
37313734
}
3732-
{
3733-
HANDLESCOPE(thread);
3734-
pipeline->ParseFunction(parsed_function);
3735-
}
37363735

37373736
PrecompileParsedFunctionHelper helper(precompiler, parsed_function,
37383737
optimized);
3739-
const bool success = helper.Compile(pipeline);
3738+
const bool success = helper.Compile();
37403739
if (!success) {
37413740
// We got an error during compilation.
37423741
const Error& error = Error::Handle(thread->StealStickyError());
@@ -3790,12 +3789,11 @@ ErrorPtr Precompiler::CompileFunction(Precompiler* precompiler,
37903789

37913790
ASSERT(CompilerState::Current().is_aot());
37923791
const bool optimized = function.IsOptimizable(); // False for natives.
3793-
DartCompilationPipeline pipeline;
37943792
if (precompiler->is_tracing()) {
37953793
precompiler->tracer_->WriteCompileFunctionEvent(function);
37963794
}
37973795

3798-
return PrecompileFunctionHelper(precompiler, &pipeline, function, optimized);
3796+
return PrecompileFunctionHelper(precompiler, function, optimized);
37993797
}
38003798

38013799
Obfuscator::Obfuscator(Thread* thread, const String& private_key)

runtime/vm/compiler/backend/il_test_helper.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,8 @@ FlowGraph* TestPipeline::RunPasses(
124124
// avoid running ComputeSSA on it (it will just crash).
125125
const bool is_ssa = (flow_graph_ != nullptr);
126126
if (flow_graph_ == nullptr) {
127-
auto pipeline = CompilationPipeline::New(zone, function_);
128-
129127
parsed_function_ = new (zone)
130128
ParsedFunction(thread, Function::ZoneHandle(zone, function_.ptr()));
131-
pipeline->ParseFunction(parsed_function_);
132129

133130
// Extract type feedback before the graph is built, as the graph
134131
// builder uses it to attach it to nodes.
@@ -137,7 +134,7 @@ FlowGraph* TestPipeline::RunPasses(
137134
function_.RestoreICDataMap(ic_data_array_, /*clone_ic_data=*/false);
138135
}
139136

140-
flow_graph_ = pipeline->BuildFlowGraph(zone, parsed_function_,
137+
flow_graph_ = Compiler::BuildFlowGraph(zone, parsed_function_,
141138
ic_data_array_, osr_id, optimized);
142139
}
143140

runtime/vm/compiler/jit/compiler.cc

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -121,57 +121,36 @@ DEFINE_FLAG_HANDLER(PrecompilationModeHandler,
121121

122122
#ifndef DART_PRECOMPILED_RUNTIME
123123

124-
void DartCompilationPipeline::ParseFunction(ParsedFunction* parsed_function) {
125-
// Nothing to do here.
126-
}
127-
128-
FlowGraph* DartCompilationPipeline::BuildFlowGraph(
124+
static FlowGraph* BuildIrregexpFunctionFlowGraph(
129125
Zone* zone,
130126
ParsedFunction* parsed_function,
131127
ZoneGrowableArray<const ICData*>* ic_data_array,
132128
intptr_t osr_id,
133129
bool optimized) {
134-
kernel::FlowGraphBuilder builder(parsed_function, ic_data_array,
135-
/* not building var desc */ nullptr,
136-
/* not inlining */ nullptr, optimized,
137-
osr_id);
138-
FlowGraph* graph = builder.BuildGraph();
139-
ASSERT(graph != nullptr);
140-
return graph;
141-
}
142-
143-
void IrregexpCompilationPipeline::ParseFunction(
144-
ParsedFunction* parsed_function) {
145-
VMTagScope tagScope(parsed_function->thread(),
146-
VMTag::kCompileParseRegExpTagId);
147-
Zone* zone = parsed_function->zone();
148-
RegExp& regexp = RegExp::Handle(parsed_function->function().regexp());
130+
if (parsed_function->regexp_compile_data() == nullptr) {
131+
VMTagScope tagScope(parsed_function->thread(),
132+
VMTag::kCompileParseRegExpTagId);
133+
RegExp& regexp = RegExp::Handle(parsed_function->function().regexp());
149134

150-
const String& pattern = String::Handle(regexp.pattern());
135+
const String& pattern = String::Handle(regexp.pattern());
151136

152-
RegExpCompileData* compile_data = new (zone) RegExpCompileData();
153-
// Parsing failures are handled in the RegExp factory constructor.
154-
RegExpParser::ParseRegExp(pattern, regexp.flags(), compile_data);
137+
RegExpCompileData* compile_data = new (zone) RegExpCompileData();
138+
// Parsing failures are handled in the RegExp factory constructor.
139+
RegExpParser::ParseRegExp(pattern, regexp.flags(), compile_data);
155140

156-
regexp.set_num_bracket_expressions(compile_data->capture_count);
157-
regexp.set_capture_name_map(compile_data->capture_name_map);
158-
if (compile_data->simple) {
159-
regexp.set_is_simple();
160-
} else {
161-
regexp.set_is_complex();
162-
}
141+
regexp.set_num_bracket_expressions(compile_data->capture_count);
142+
regexp.set_capture_name_map(compile_data->capture_name_map);
143+
if (compile_data->simple) {
144+
regexp.set_is_simple();
145+
} else {
146+
regexp.set_is_complex();
147+
}
163148

164-
parsed_function->SetRegExpCompileData(compile_data);
149+
parsed_function->SetRegExpCompileData(compile_data);
165150

166-
// Variables are allocated after compilation.
167-
}
151+
// Variables are allocated after compilation.
152+
}
168153

169-
FlowGraph* IrregexpCompilationPipeline::BuildFlowGraph(
170-
Zone* zone,
171-
ParsedFunction* parsed_function,
172-
ZoneGrowableArray<const ICData*>* ic_data_array,
173-
intptr_t osr_id,
174-
bool optimized) {
175154
// Compile to the dart IR.
176155
RegExpEngine::CompilationResult result =
177156
RegExpEngine::CompileIR(parsed_function->regexp_compile_data(),
@@ -180,7 +159,6 @@ FlowGraph* IrregexpCompilationPipeline::BuildFlowGraph(
180159
Report::LongJump(LanguageError::Handle(
181160
LanguageError::New(String::Handle(String::New(result.error_message)))));
182161
}
183-
backtrack_goto_ = result.backtrack_goto;
184162

185163
// Allocate variables now that we know the number of locals.
186164
parsed_function->AllocateIrregexpVariables(result.num_stack_locals);
@@ -198,13 +176,23 @@ FlowGraph* IrregexpCompilationPipeline::BuildFlowGraph(
198176
prologue_info, FlowGraph::CompilationModeFrom(optimized));
199177
}
200178

201-
CompilationPipeline* CompilationPipeline::New(Zone* zone,
202-
const Function& function) {
203-
if (function.IsIrregexpFunction()) {
204-
return new (zone) IrregexpCompilationPipeline();
205-
} else {
206-
return new (zone) DartCompilationPipeline();
179+
FlowGraph* Compiler::BuildFlowGraph(
180+
Zone* zone,
181+
ParsedFunction* parsed_function,
182+
ZoneGrowableArray<const ICData*>* ic_data_array,
183+
intptr_t osr_id,
184+
bool optimized) {
185+
if (parsed_function->function().IsIrregexpFunction()) {
186+
return BuildIrregexpFunctionFlowGraph(zone, parsed_function, ic_data_array,
187+
osr_id, optimized);
207188
}
189+
kernel::FlowGraphBuilder builder(parsed_function, ic_data_array,
190+
/* not building var desc */ nullptr,
191+
/* not inlining */ nullptr, optimized,
192+
osr_id);
193+
FlowGraph* graph = builder.BuildGraph();
194+
ASSERT(graph != nullptr);
195+
return graph;
208196
}
209197

210198
// Compile a function. Should call only if the function has not been compiled.
@@ -310,7 +298,7 @@ class CompileParsedFunctionHelper : public ValueObject {
310298
osr_id_(osr_id),
311299
thread_(Thread::Current()) {}
312300

313-
CodePtr Compile(CompilationPipeline* pipeline);
301+
CodePtr Compile();
314302

315303
private:
316304
ParsedFunction* parsed_function() const { return parsed_function_; }
@@ -484,7 +472,7 @@ CodePtr CompileParsedFunctionHelper::FinalizeCompilation(
484472
}
485473

486474
// Return null if bailed out.
487-
CodePtr CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
475+
CodePtr CompileParsedFunctionHelper::Compile() {
488476
ASSERT(!FLAG_precompiled_mode);
489477
const Function& function = parsed_function()->function();
490478
if (optimized() && !function.IsOptimizable()) {
@@ -544,7 +532,7 @@ CodePtr CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
544532
}
545533

546534
TIMELINE_DURATION(thread(), CompilerVerbose, "BuildFlowGraph");
547-
flow_graph = pipeline->BuildFlowGraph(
535+
flow_graph = Compiler::BuildFlowGraph(
548536
zone, parsed_function(), ic_data_array, osr_id(), optimized());
549537
}
550538

@@ -679,8 +667,7 @@ CodePtr CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
679667
return result->ptr();
680668
}
681669

682-
static ObjectPtr CompileFunctionHelper(CompilationPipeline* pipeline,
683-
const Function& function,
670+
static ObjectPtr CompileFunctionHelper(const Function& function,
684671
bool optimized,
685672
intptr_t osr_id) {
686673
Thread* const thread = Thread::Current();
@@ -708,15 +695,10 @@ static ObjectPtr CompileFunctionHelper(CompilationPipeline* pipeline,
708695
function.ToFullyQualifiedCString(),
709696
function.token_pos().ToCString(), token_size);
710697
}
711-
// Makes sure no classes are loaded during parsing in background.
712-
{
713-
HANDLESCOPE(thread);
714-
pipeline->ParseFunction(parsed_function);
715-
}
716698

717699
CompileParsedFunctionHelper helper(parsed_function, optimized, osr_id);
718700

719-
const Code& result = Code::Handle(helper.Compile(pipeline));
701+
const Code& result = Code::Handle(helper.Compile());
720702

721703
if (result.IsNull()) {
722704
const Error& error = Error::Handle(thread->StealStickyError());
@@ -843,11 +825,8 @@ ObjectPtr Compiler::CompileFunction(Thread* thread, const Function& function) {
843825
TIMELINE_FUNCTION_COMPILATION_DURATION(thread, event_name, function);
844826
#endif // defined(SUPPORT_TIMELINE)
845827

846-
CompilationPipeline* pipeline =
847-
CompilationPipeline::New(thread->zone(), function);
848-
849828
const bool optimized = function.ForceOptimize();
850-
return CompileFunctionHelper(pipeline, function, optimized, kNoOSRDeoptId);
829+
return CompileFunctionHelper(function, optimized, kNoOSRDeoptId);
851830
}
852831

853832
ErrorPtr Compiler::EnsureUnoptimizedCode(Thread* thread,
@@ -860,11 +839,9 @@ ErrorPtr Compiler::EnsureUnoptimizedCode(Thread* thread,
860839
if (function.HasCode()) {
861840
original_code = function.CurrentCode();
862841
}
863-
CompilationPipeline* pipeline =
864-
CompilationPipeline::New(thread->zone(), function);
865842
const bool optimized = function.ForceOptimize();
866-
const Object& result = Object::Handle(
867-
CompileFunctionHelper(pipeline, function, optimized, kNoOSRDeoptId));
843+
const Object& result =
844+
Object::Handle(CompileFunctionHelper(function, optimized, kNoOSRDeoptId));
868845
if (result.IsError()) {
869846
return Error::Cast(result).ptr();
870847
}
@@ -899,10 +876,7 @@ ObjectPtr Compiler::CompileOptimizedFunction(Thread* thread,
899876
TIMELINE_FUNCTION_COMPILATION_DURATION(thread, event_name, function);
900877
#endif // defined(SUPPORT_TIMELINE)
901878

902-
CompilationPipeline* pipeline =
903-
CompilationPipeline::New(thread->zone(), function);
904-
return CompileFunctionHelper(pipeline, function, /* optimized = */ true,
905-
osr_id);
879+
return CompileFunctionHelper(function, /* optimized = */ true, osr_id);
906880
}
907881

908882
void Compiler::ComputeLocalVarDescriptors(const Code& code) {
@@ -1253,12 +1227,6 @@ void BackgroundCompiler::Disable() {
12531227

12541228
#else // DART_PRECOMPILED_RUNTIME
12551229

1256-
CompilationPipeline* CompilationPipeline::New(Zone* zone,
1257-
const Function& function) {
1258-
UNREACHABLE();
1259-
return nullptr;
1260-
}
1261-
12621230
DEFINE_RUNTIME_ENTRY(CompileFunction, 1) {
12631231
const Function& function = Function::CheckedHandle(zone, arguments.ArgAt(0));
12641232
FATAL("Precompilation missed function %s (%s, %s)\n",

runtime/vm/compiler/jit/compiler.h

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,50 +27,19 @@ class QueueElement;
2727
class Script;
2828
class SequenceNode;
2929

30-
class CompilationPipeline : public ZoneAllocated {
30+
class Compiler : public AllStatic {
3131
public:
32-
static CompilationPipeline* New(Zone* zone, const Function& function);
32+
static constexpr intptr_t kNoOSRDeoptId = DeoptId::kNone;
3333

34-
virtual void ParseFunction(ParsedFunction* parsed_function) = 0;
35-
virtual FlowGraph* BuildFlowGraph(
34+
#if !defined(DART_PRECOMPILED_RUNTIME)
35+
// Build flow graph for the given function.
36+
static FlowGraph* BuildFlowGraph(
3637
Zone* zone,
3738
ParsedFunction* parsed_function,
3839
ZoneGrowableArray<const ICData*>* ic_data_array,
3940
intptr_t osr_id,
40-
bool optimized) = 0;
41-
virtual ~CompilationPipeline() {}
42-
};
43-
44-
class DartCompilationPipeline : public CompilationPipeline {
45-
public:
46-
void ParseFunction(ParsedFunction* parsed_function) override;
47-
48-
FlowGraph* BuildFlowGraph(Zone* zone,
49-
ParsedFunction* parsed_function,
50-
ZoneGrowableArray<const ICData*>* ic_data_array,
51-
intptr_t osr_id,
52-
bool optimized) override;
53-
};
54-
55-
class IrregexpCompilationPipeline : public CompilationPipeline {
56-
public:
57-
IrregexpCompilationPipeline() : backtrack_goto_(nullptr) {}
58-
59-
void ParseFunction(ParsedFunction* parsed_function) override;
60-
61-
FlowGraph* BuildFlowGraph(Zone* zone,
62-
ParsedFunction* parsed_function,
63-
ZoneGrowableArray<const ICData*>* ic_data_array,
64-
intptr_t osr_id,
65-
bool optimized) override;
66-
67-
private:
68-
IndirectGotoInstr* backtrack_goto_;
69-
};
70-
71-
class Compiler : public AllStatic {
72-
public:
73-
static constexpr intptr_t kNoOSRDeoptId = DeoptId::kNone;
41+
bool optimized);
42+
#endif
7443

7544
static bool IsBackgroundCompilation();
7645
// The result for a function may change if debugging gets turned on/off.

0 commit comments

Comments
 (0)