Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2651903002: [wasm] No need to use multiple inheritance for `ModuleBytesEnv` (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/wasm/module-decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/wasm-compiler.h" 5 #include "src/compiler/wasm-compiler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 10
(...skipping 3668 matching lines...) Expand 10 before | Expand all | Expand 10 after
3679 if (FLAG_trace_wasm_decode_time) { 3679 if (FLAG_trace_wasm_decode_time) {
3680 decode_timer.Start(); 3680 decode_timer.Start();
3681 } 3681 }
3682 // Create a TF graph during decoding. 3682 // Create a TF graph during decoding.
3683 3683
3684 Graph* graph = jsgraph_->graph(); 3684 Graph* graph = jsgraph_->graph();
3685 CommonOperatorBuilder* common = jsgraph_->common(); 3685 CommonOperatorBuilder* common = jsgraph_->common();
3686 MachineOperatorBuilder* machine = jsgraph_->machine(); 3686 MachineOperatorBuilder* machine = jsgraph_->machine();
3687 SourcePositionTable* source_position_table = 3687 SourcePositionTable* source_position_table =
3688 new (jsgraph_->zone()) SourcePositionTable(graph); 3688 new (jsgraph_->zone()) SourcePositionTable(graph);
3689 WasmGraphBuilder builder(module_env_, jsgraph_->zone(), jsgraph_, 3689 WasmGraphBuilder builder(&module_env_->module_env, jsgraph_->zone(), jsgraph_,
3690 function_->sig, source_position_table); 3690 function_->sig, source_position_table);
3691 const byte* module_start = module_env_->module_bytes.start(); 3691 const byte* module_start = module_env_->wire_bytes.start();
3692 wasm::FunctionBody body = {function_->sig, module_start, 3692 wasm::FunctionBody body = {function_->sig, module_start,
3693 module_start + function_->code_start_offset, 3693 module_start + function_->code_start_offset,
3694 module_start + function_->code_end_offset}; 3694 module_start + function_->code_end_offset};
3695 graph_construction_result_ = 3695 graph_construction_result_ =
3696 wasm::BuildTFGraph(isolate_->allocator(), &builder, body); 3696 wasm::BuildTFGraph(isolate_->allocator(), &builder, body);
3697 3697
3698 if (graph_construction_result_.failed()) { 3698 if (graph_construction_result_.failed()) {
3699 if (FLAG_trace_wasm_compiler) { 3699 if (FLAG_trace_wasm_compiler) {
3700 OFStream os(stdout); 3700 OFStream os(stdout);
3701 os << "Compilation failed: " << graph_construction_result_ << std::endl; 3701 os << "Compilation failed: " << graph_construction_result_ << std::endl;
3702 } 3702 }
3703 return nullptr; 3703 return nullptr;
3704 } 3704 }
3705 3705
3706 if (machine->Is32()) { 3706 if (machine->Is32()) {
3707 Int64Lowering(graph, machine, common, jsgraph_->zone(), function_->sig) 3707 Int64Lowering(graph, machine, common, jsgraph_->zone(), function_->sig)
3708 .LowerGraph(); 3708 .LowerGraph();
3709 } 3709 }
3710 3710
3711 if (builder.has_simd() && !CpuFeatures::SupportsSimd128()) { 3711 if (builder.has_simd() && !CpuFeatures::SupportsSimd128()) {
3712 SimdScalarLowering(graph, machine, common, jsgraph_->zone(), function_->sig) 3712 SimdScalarLowering(graph, machine, common, jsgraph_->zone(), function_->sig)
3713 .LowerGraph(); 3713 .LowerGraph();
3714 } 3714 }
3715 3715
3716 int index = static_cast<int>(function_->func_index); 3716 int index = static_cast<int>(function_->func_index);
3717 3717
3718 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { 3718 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) {
3719 OFStream os(stdout); 3719 OFStream os(stdout);
3720 PrintWasmCode(isolate_->allocator(), body, module_env_->module, os, 3720 PrintWasmCode(isolate_->allocator(), body, module_env_->module_env.module,
3721 nullptr); 3721 os, nullptr);
3722 } 3722 }
3723 if (index >= FLAG_trace_wasm_text_start && index < FLAG_trace_wasm_text_end) { 3723 if (index >= FLAG_trace_wasm_text_start && index < FLAG_trace_wasm_text_end) {
3724 OFStream os(stdout); 3724 OFStream os(stdout);
3725 PrintWasmText(module_env_->module, *module_env_, function_->func_index, os, 3725 PrintWasmText(module_env_->module_env.module, module_env_->wire_bytes,
3726 nullptr); 3726 function_->func_index, os, nullptr);
3727 } 3727 }
3728 if (FLAG_trace_wasm_decode_time) { 3728 if (FLAG_trace_wasm_decode_time) {
3729 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); 3729 *decode_ms = decode_timer.Elapsed().InMillisecondsF();
3730 } 3730 }
3731 return source_position_table; 3731 return source_position_table;
3732 } 3732 }
3733 3733
3734 WasmCompilationUnit::WasmCompilationUnit(wasm::ErrorThrower* thrower, 3734 WasmCompilationUnit::WasmCompilationUnit(wasm::ErrorThrower* thrower,
3735 Isolate* isolate, 3735 Isolate* isolate,
3736 wasm::ModuleBytesEnv* module_env, 3736 wasm::ModuleBytesEnv* module_env,
3737 const wasm::WasmFunction* function, 3737 const wasm::WasmFunction* function,
3738 uint32_t index) 3738 uint32_t index)
3739 : thrower_(thrower), 3739 : thrower_(thrower),
3740 isolate_(isolate), 3740 isolate_(isolate),
3741 module_env_(module_env), 3741 module_env_(module_env),
3742 function_(&module_env->module->functions[index]), 3742 function_(&module_env->module_env.module->functions[index]),
3743 graph_zone_(new Zone(isolate->allocator(), ZONE_NAME)), 3743 graph_zone_(new Zone(isolate->allocator(), ZONE_NAME)),
3744 jsgraph_(new (graph_zone()) JSGraph( 3744 jsgraph_(new (graph_zone()) JSGraph(
3745 isolate, new (graph_zone()) Graph(graph_zone()), 3745 isolate, new (graph_zone()) Graph(graph_zone()),
3746 new (graph_zone()) CommonOperatorBuilder(graph_zone()), nullptr, 3746 new (graph_zone()) CommonOperatorBuilder(graph_zone()), nullptr,
3747 nullptr, new (graph_zone()) MachineOperatorBuilder( 3747 nullptr, new (graph_zone()) MachineOperatorBuilder(
3748 graph_zone(), MachineType::PointerRepresentation(), 3748 graph_zone(), MachineType::PointerRepresentation(),
3749 InstructionSelector::SupportedMachineOperatorFlags(), 3749 InstructionSelector::SupportedMachineOperatorFlags(),
3750 InstructionSelector::AlignmentRequirements()))), 3750 InstructionSelector::AlignmentRequirements()))),
3751 compilation_zone_(isolate->allocator(), ZONE_NAME), 3751 compilation_zone_(isolate->allocator(), ZONE_NAME),
3752 info_(function->name_length != 0 ? module_env->GetNameOrNull(function) 3752 info_(function->name_length != 0
3753 : ArrayVector("wasm"), 3753 ? module_env->wire_bytes.GetNameOrNull(function)
3754 : ArrayVector("wasm"),
3754 isolate, &compilation_zone_, 3755 isolate, &compilation_zone_,
3755 Code::ComputeFlags(Code::WASM_FUNCTION)), 3756 Code::ComputeFlags(Code::WASM_FUNCTION)),
3756 job_(), 3757 job_(),
3757 index_(index), 3758 index_(index),
3758 ok_(true), 3759 ok_(true),
3759 protected_instructions_(&compilation_zone_) { 3760 protected_instructions_(&compilation_zone_) {
3760 // Create and cache this node in the main thread. 3761 // Create and cache this node in the main thread.
3761 jsgraph_->CEntryStubConstant(1); 3762 jsgraph_->CEntryStubConstant(1);
3762 } 3763 }
3763 3764
3764 void WasmCompilationUnit::ExecuteCompilation() { 3765 void WasmCompilationUnit::ExecuteCompilation() {
3765 // TODO(ahaas): The counters are not thread-safe at the moment. 3766 // TODO(ahaas): The counters are not thread-safe at the moment.
3766 // HistogramTimerScope wasm_compile_function_time_scope( 3767 // HistogramTimerScope wasm_compile_function_time_scope(
3767 // isolate_->counters()->wasm_compile_function_time()); 3768 // isolate_->counters()->wasm_compile_function_time());
3768 if (FLAG_trace_wasm_compiler) { 3769 if (FLAG_trace_wasm_compiler) {
3769 OFStream os(stdout); 3770 OFStream os(stdout);
3770 os << "Compiling WASM function " 3771 os << "Compiling WASM function "
3771 << wasm::WasmFunctionName(function_, module_env_) << std::endl; 3772 << wasm::WasmFunctionName(
3773 function_, module_env_->wire_bytes.GetNameOrNull(function_))
3774 << std::endl;
3772 os << std::endl; 3775 os << std::endl;
3773 } 3776 }
3774 3777
3775 double decode_ms = 0; 3778 double decode_ms = 0;
3776 size_t node_count = 0; 3779 size_t node_count = 0;
3777 3780
3778 std::unique_ptr<Zone> graph_zone(graph_zone_.release()); 3781 std::unique_ptr<Zone> graph_zone(graph_zone_.release());
3779 SourcePositionTable* source_positions = BuildGraphForWasmFunction(&decode_ms); 3782 SourcePositionTable* source_positions = BuildGraphForWasmFunction(&decode_ms);
3780 3783
3781 if (graph_construction_result_.failed()) { 3784 if (graph_construction_result_.failed()) {
3782 ok_ = false; 3785 ok_ = false;
3783 return; 3786 return;
3784 } 3787 }
3785 3788
3786 base::ElapsedTimer pipeline_timer; 3789 base::ElapsedTimer pipeline_timer;
3787 if (FLAG_trace_wasm_decode_time) { 3790 if (FLAG_trace_wasm_decode_time) {
3788 node_count = jsgraph_->graph()->NodeCount(); 3791 node_count = jsgraph_->graph()->NodeCount();
3789 pipeline_timer.Start(); 3792 pipeline_timer.Start();
3790 } 3793 }
3791 3794
3792 // Run the compiler pipeline to generate machine code. 3795 // Run the compiler pipeline to generate machine code.
3793 CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor( 3796 CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor(
3794 &compilation_zone_, function_->sig); 3797 &compilation_zone_, function_->sig);
3795 if (jsgraph_->machine()->Is32()) { 3798 if (jsgraph_->machine()->Is32()) {
3796 descriptor = 3799 descriptor = module_env_->module_env.GetI32WasmCallDescriptor(
3797 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); 3800 &compilation_zone_, descriptor);
3798 } 3801 }
3799 job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_, descriptor, 3802 job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_, descriptor,
3800 source_positions, 3803 source_positions,
3801 &protected_instructions_)); 3804 &protected_instructions_));
3802 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; 3805 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED;
3803 // TODO(bradnelson): Improve histogram handling of size_t. 3806 // TODO(bradnelson): Improve histogram handling of size_t.
3804 // TODO(ahaas): The counters are not thread-safe at the moment. 3807 // TODO(ahaas): The counters are not thread-safe at the moment.
3805 // isolate_->counters()->wasm_compile_function_peak_memory_bytes() 3808 // isolate_->counters()->wasm_compile_function_peak_memory_bytes()
3806 // ->AddSample( 3809 // ->AddSample(
3807 // static_cast<int>(jsgraph->graph()->zone()->allocation_size())); 3810 // static_cast<int>(jsgraph->graph()->zone()->allocation_size()));
3808 3811
3809 if (FLAG_trace_wasm_decode_time) { 3812 if (FLAG_trace_wasm_decode_time) {
3810 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); 3813 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
3811 PrintF( 3814 PrintF(
3812 "wasm-compilation phase 1 ok: %d bytes, %0.3f ms decode, %zu nodes, " 3815 "wasm-compilation phase 1 ok: %d bytes, %0.3f ms decode, %zu nodes, "
3813 "%0.3f ms pipeline\n", 3816 "%0.3f ms pipeline\n",
3814 static_cast<int>(function_->code_end_offset - 3817 static_cast<int>(function_->code_end_offset -
3815 function_->code_start_offset), 3818 function_->code_start_offset),
3816 decode_ms, node_count, pipeline_ms); 3819 decode_ms, node_count, pipeline_ms);
3817 } 3820 }
3818 } 3821 }
3819 3822
3820 Handle<Code> WasmCompilationUnit::FinishCompilation() { 3823 Handle<Code> WasmCompilationUnit::FinishCompilation() {
3821 if (!ok_) { 3824 if (!ok_) {
3822 if (graph_construction_result_.failed()) { 3825 if (graph_construction_result_.failed()) {
3823 // Add the function as another context for the exception 3826 // Add the function as another context for the exception
3824 ScopedVector<char> buffer(128); 3827 ScopedVector<char> buffer(128);
3825 wasm::WasmName name = module_env_->GetName(function_); 3828 wasm::WasmName name = module_env_->wire_bytes.GetName(function_);
3826 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:", 3829 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:",
3827 function_->func_index, name.length(), name.start()); 3830 function_->func_index, name.length(), name.start());
3828 thrower_->CompileFailed(buffer.start(), graph_construction_result_); 3831 thrower_->CompileFailed(buffer.start(), graph_construction_result_);
3829 } 3832 }
3830 3833
3831 return Handle<Code>::null(); 3834 return Handle<Code>::null();
3832 } 3835 }
3833 if (job_->FinalizeJob() != CompilationJob::SUCCEEDED) { 3836 if (job_->FinalizeJob() != CompilationJob::SUCCEEDED) {
3834 return Handle<Code>::null(); 3837 return Handle<Code>::null();
3835 } 3838 }
3836 base::ElapsedTimer compile_timer; 3839 base::ElapsedTimer compile_timer;
3837 if (FLAG_trace_wasm_decode_time) { 3840 if (FLAG_trace_wasm_decode_time) {
3838 compile_timer.Start(); 3841 compile_timer.Start();
3839 } 3842 }
3840 Handle<Code> code = info_.code(); 3843 Handle<Code> code = info_.code();
3841 DCHECK(!code.is_null()); 3844 DCHECK(!code.is_null());
3842 3845
3843 if (isolate_->logger()->is_logging_code_events() || 3846 if (isolate_->logger()->is_logging_code_events() ||
3844 isolate_->is_profiling()) { 3847 isolate_->is_profiling()) {
3845 RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate_, code, 3848 RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate_, code,
3846 "WASM_function", function_->func_index, 3849 "WASM_function", function_->func_index,
3847 wasm::WasmName("module"), 3850 wasm::WasmName("module"),
3848 module_env_->GetName(function_)); 3851 module_env_->wire_bytes.GetName(function_));
3849 } 3852 }
3850 3853
3851 if (FLAG_trace_wasm_decode_time) { 3854 if (FLAG_trace_wasm_decode_time) {
3852 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); 3855 double compile_ms = compile_timer.Elapsed().InMillisecondsF();
3853 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n", 3856 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n",
3854 static_cast<int>(function_->code_end_offset - 3857 static_cast<int>(function_->code_end_offset -
3855 function_->code_start_offset), 3858 function_->code_start_offset),
3856 compile_ms); 3859 compile_ms);
3857 } 3860 }
3858 3861
(...skipping 14 matching lines...) Expand all
3873 Smi::FromInt(instruction.instr_offset)); 3876 Smi::FromInt(instruction.instr_offset));
3874 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, 3877 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset,
3875 Smi::FromInt(instruction.landing_offset)); 3878 Smi::FromInt(instruction.landing_offset));
3876 } 3879 }
3877 return fn_protected; 3880 return fn_protected;
3878 } 3881 }
3879 3882
3880 } // namespace compiler 3883 } // namespace compiler
3881 } // namespace internal 3884 } // namespace internal
3882 } // namespace v8 3885 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/module-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698