Skip to content

Commit c6c4748

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/bytecode] Bytecode compilation
Change-Id: I09192e4e929a397920c217b605580f8c4880e7c2 Reviewed-on: https://dart-review.googlesource.com/74002 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Régis Crelier <regis@google.com>
1 parent 78d9a28 commit c6c4748

34 files changed

+1890
-186
lines changed

runtime/vm/compiler/aot/precompiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,7 +2774,7 @@ bool PrecompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
27742774
"BuildFlowGraph");
27752775
#endif // !PRODUCT
27762776
flow_graph =
2777-
pipeline->BuildFlowGraph(zone, parsed_function(), *ic_data_array,
2777+
pipeline->BuildFlowGraph(zone, parsed_function(), ic_data_array,
27782778
Compiler::kNoOSRDeoptId, optimized());
27792779
}
27802780

runtime/vm/compiler/backend/flow_graph.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ class FlowGraph : public ZoneAllocated {
128128
}
129129

130130
intptr_t CurrentContextEnvIndex() const {
131-
return EnvIndex(parsed_function().current_context_var());
131+
return FLAG_use_bytecode_compiler
132+
? -1
133+
: EnvIndex(parsed_function().current_context_var());
132134
}
133135

134136
intptr_t RawTypeArgumentEnvIndex() const {

runtime/vm/compiler/backend/flow_graph_compiler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,8 @@ void FlowGraphCompiler::FinalizeStackMaps(const Code& code) {
10371037
}
10381038

10391039
void FlowGraphCompiler::FinalizeVarDescriptors(const Code& code) {
1040-
if (code.is_optimized()) {
1040+
// TODO(alexmarkov): revise local vars descriptors when compiling bytecode
1041+
if (code.is_optimized() || FLAG_use_bytecode_compiler) {
10411042
// Optimized code does not need variable descriptors. They are
10421043
// only stored in the unoptimized version.
10431044
code.set_var_descriptors(Object::empty_var_descriptors());

runtime/vm/compiler/backend/il.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,17 +779,21 @@ const NativeFieldDesc* NativeFieldDesc::GetLengthFieldForArrayCid(
779779
}
780780
}
781781

782-
const NativeFieldDesc* NativeFieldDesc::GetTypeArgumentsFieldFor(
783-
Zone* zone,
784-
const Class& cls) {
782+
const NativeFieldDesc* NativeFieldDesc::GetTypeArgumentsField(Zone* zone,
783+
intptr_t offset) {
785784
// TODO(vegorov) consider caching type arguments fields for specific classes
786785
// in some sort of a flow-graph specific cache.
787-
const intptr_t offset = cls.type_arguments_field_offset();
788786
ASSERT(offset != Class::kNoTypeArguments);
789787
return new (zone) NativeFieldDesc(kTypeArguments, offset, kDynamicCid,
790788
/*immutable=*/true);
791789
}
792790

791+
const NativeFieldDesc* NativeFieldDesc::GetTypeArgumentsFieldFor(
792+
Zone* zone,
793+
const Class& cls) {
794+
return GetTypeArgumentsField(zone, cls.type_arguments_field_offset());
795+
}
796+
793797
RawAbstractType* NativeFieldDesc::type() const {
794798
if (cid() == kSmiCid) {
795799
return Type::SmiType();
@@ -1233,7 +1237,10 @@ intptr_t JoinEntryInstr::IndexOfPredecessor(BlockEntryInstr* pred) const {
12331237
}
12341238

12351239
void Value::AddToList(Value* value, Value** list) {
1240+
ASSERT(value->next_use() == nullptr);
1241+
ASSERT(value->previous_use() == nullptr);
12361242
Value* next = *list;
1243+
ASSERT(value != next);
12371244
*list = value;
12381245
value->set_next_use(next);
12391246
value->set_previous_use(NULL);
@@ -3965,7 +3972,8 @@ void InstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
39653972
}
39663973

39673974
#if !defined(TARGET_ARCH_DBC)
3968-
if (compiler->is_optimizing() && HasICData()) {
3975+
if ((compiler->is_optimizing() || FLAG_use_bytecode_compiler) &&
3976+
HasICData()) {
39693977
ASSERT(HasICData());
39703978
if (ic_data()->NumberOfUsedChecks() > 0) {
39713979
const ICData& unary_ic_data =

runtime/vm/compiler/backend/il.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,10 +1708,10 @@ class CatchBlockEntryInstr : public BlockEntryInstr {
17081708
GraphEntryInstr* graph_entry,
17091709
const Array& handler_types,
17101710
intptr_t catch_try_index,
1711-
const LocalVariable& exception_var,
1712-
const LocalVariable& stacktrace_var,
17131711
bool needs_stacktrace,
17141712
intptr_t deopt_id,
1713+
const LocalVariable* exception_var,
1714+
const LocalVariable* stacktrace_var,
17151715
const LocalVariable* raw_exception_var,
17161716
const LocalVariable* raw_stacktrace_var)
17171717
: BlockEntryInstr(block_id, try_index, deopt_id),
@@ -1739,8 +1739,8 @@ class CatchBlockEntryInstr : public BlockEntryInstr {
17391739

17401740
GraphEntryInstr* graph_entry() const { return graph_entry_; }
17411741

1742-
const LocalVariable& exception_var() const { return exception_var_; }
1743-
const LocalVariable& stacktrace_var() const { return stacktrace_var_; }
1742+
const LocalVariable* exception_var() const { return exception_var_; }
1743+
const LocalVariable* stacktrace_var() const { return stacktrace_var_; }
17441744

17451745
const LocalVariable* raw_exception_var() const { return raw_exception_var_; }
17461746
const LocalVariable* raw_stacktrace_var() const {
@@ -1775,8 +1775,8 @@ class CatchBlockEntryInstr : public BlockEntryInstr {
17751775
const Array& catch_handler_types_;
17761776
const intptr_t catch_try_index_;
17771777
GrowableArray<Definition*> initial_definitions_;
1778-
const LocalVariable& exception_var_;
1779-
const LocalVariable& stacktrace_var_;
1778+
const LocalVariable* exception_var_;
1779+
const LocalVariable* stacktrace_var_;
17801780
const LocalVariable* raw_exception_var_;
17811781
const LocalVariable* raw_stacktrace_var_;
17821782
const bool needs_stacktrace_;
@@ -2993,6 +2993,7 @@ class AssertAssignableInstr : public TemplateDefinition<3, Throws, Pure> {
29932993
ASSERT(!dst_type.IsNull());
29942994
ASSERT(!dst_type.IsTypeRef());
29952995
ASSERT(!dst_name.IsNull());
2996+
ASSERT(!dst_type.IsDynamicType());
29962997
SetInputAt(0, value);
29972998
SetInputAt(1, instantiator_type_arguments);
29982999
SetInputAt(2, function_type_arguments);
@@ -5131,6 +5132,8 @@ class NativeFieldDesc : public ZoneAllocated {
51315132

51325133
static const NativeFieldDesc* Get(Kind kind);
51335134
static const NativeFieldDesc* GetLengthFieldForArrayCid(intptr_t array_cid);
5135+
static const NativeFieldDesc* GetTypeArgumentsField(Zone* zone,
5136+
intptr_t offset);
51345137
static const NativeFieldDesc* GetTypeArgumentsFieldFor(Zone* zone,
51355138
const Class& cls);
51365139

runtime/vm/compiler/backend/il_printer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ void InstantiateTypeArgumentsInstr::PrintOperandsTo(BufferFormatter* f) const {
707707
instantiator_type_arguments()->PrintTo(f);
708708
f->Print("), function_type_args(");
709709
function_type_arguments()->PrintTo(f);
710-
f->Print(")");
710+
f->Print("), instantiator_class(%s)", instantiator_class().ToCString());
711711
}
712712

713713
void AllocateContextInstr::PrintOperandsTo(BufferFormatter* f) const {

runtime/vm/compiler/backend/inliner.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ class CallSiteInliner : public ValueObject {
973973
entry_kind = instr->entry_kind();
974974
}
975975
kernel::FlowGraphBuilder builder(
976-
parsed_function, *ic_data_array, /* not building var desc */ NULL,
976+
parsed_function, ic_data_array, /* not building var desc */ NULL,
977977
exit_collector,
978978
/* optimized = */ true, Compiler::kNoOSRDeoptId,
979979
caller_graph_->max_block_id() + 1,

runtime/vm/compiler/backend/type_propagator.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,12 @@ CompileType ParameterInstr::ComputeType() const {
938938
return CompileType::Dynamic();
939939
}
940940

941+
if (FLAG_use_bytecode_compiler &&
942+
graph_entry->parsed_function().node_sequence() == nullptr) {
943+
// TODO(alexmarkov): Consider adding node_sequence() and scope.
944+
return CompileType::Dynamic();
945+
}
946+
941947
// Parameter is the receiver.
942948
if ((index() == 0) &&
943949
(function.IsDynamicFunction() || function.IsGenerativeConstructor())) {

runtime/vm/compiler/call_specializer.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,8 @@ bool CallSpecializer::TryInlineInstanceSetter(InstanceCallInstr* instr,
998998
}
999999

10001000
// Build an AssertAssignable if necessary.
1001-
if (I->argument_type_checks()) {
1002-
const AbstractType& dst_type =
1003-
AbstractType::ZoneHandle(zone(), field.type());
1004-
1001+
const AbstractType& dst_type = AbstractType::ZoneHandle(zone(), field.type());
1002+
if (I->argument_type_checks() && !dst_type.IsTopType()) {
10051003
// Compute if we need to type check the value. Always type check if
10061004
// not in strong mode or if at a dynamic invocation.
10071005
bool needs_check = true;

runtime/vm/compiler/compiler_sources.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ compiler_sources = [
7878
"compiler_state.h",
7979
"frontend/base_flow_graph_builder.cc",
8080
"frontend/base_flow_graph_builder.h",
81+
"frontend/bytecode_flow_graph_builder.cc",
82+
"frontend/bytecode_flow_graph_builder.h",
8183
"frontend/bytecode_reader.cc",
8284
"frontend/bytecode_reader.h",
8385
"frontend/constant_evaluator.cc",

0 commit comments

Comments
 (0)