OLD | NEW |
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/assembler-inl.h" | 9 #include "src/assembler-inl.h" |
10 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
(...skipping 3892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3903 DCHECK(name_len > 0 && name_len < name_vector.length()); | 3903 DCHECK(name_len > 0 && name_len < name_vector.length()); |
3904 | 3904 |
3905 char* index_name = zone->NewArray<char>(name_len); | 3905 char* index_name = zone->NewArray<char>(name_len); |
3906 memcpy(index_name, name_vector.start(), name_len); | 3906 memcpy(index_name, name_vector.start(), name_len); |
3907 return Vector<const char>(index_name, name_len); | 3907 return Vector<const char>(index_name, name_len); |
3908 } | 3908 } |
3909 } // namespace | 3909 } // namespace |
3910 | 3910 |
3911 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, | 3911 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, |
3912 wasm::ModuleBytesEnv* module_env, | 3912 wasm::ModuleBytesEnv* module_env, |
3913 const wasm::WasmFunction* function, | 3913 const wasm::WasmFunction* function) |
3914 bool is_sync) | |
3915 : WasmCompilationUnit( | 3914 : WasmCompilationUnit( |
3916 isolate, &module_env->module_env, | 3915 isolate, &module_env->module_env, |
3917 wasm::FunctionBody{ | 3916 wasm::FunctionBody{ |
3918 function->sig, module_env->wire_bytes.start(), | 3917 function->sig, module_env->wire_bytes.start(), |
3919 module_env->wire_bytes.start() + function->code_start_offset, | 3918 module_env->wire_bytes.start() + function->code_start_offset, |
3920 module_env->wire_bytes.start() + function->code_end_offset}, | 3919 module_env->wire_bytes.start() + function->code_end_offset}, |
3921 module_env->wire_bytes.GetNameOrNull(function), function->func_index, | 3920 module_env->wire_bytes.GetNameOrNull(function), |
3922 is_sync) {} | 3921 function->func_index) {} |
3923 | 3922 |
3924 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, | 3923 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, |
3925 wasm::ModuleEnv* module_env, | 3924 wasm::ModuleEnv* module_env, |
3926 wasm::FunctionBody body, | 3925 wasm::FunctionBody body, |
3927 wasm::WasmName name, int index, | 3926 wasm::WasmName name, int index) |
3928 bool is_sync) | |
3929 : isolate_(isolate), | 3927 : isolate_(isolate), |
3930 module_env_(module_env), | 3928 module_env_(module_env), |
3931 func_body_(body), | 3929 func_body_(body), |
3932 func_name_(name), | 3930 func_name_(name), |
3933 is_sync_(is_sync), | |
3934 graph_zone_(new Zone(isolate->allocator(), ZONE_NAME)), | 3931 graph_zone_(new Zone(isolate->allocator(), ZONE_NAME)), |
3935 jsgraph_(new (graph_zone()) JSGraph( | 3932 jsgraph_(new (graph_zone()) JSGraph( |
3936 isolate, new (graph_zone()) Graph(graph_zone()), | 3933 isolate, new (graph_zone()) Graph(graph_zone()), |
3937 new (graph_zone()) CommonOperatorBuilder(graph_zone()), nullptr, | 3934 new (graph_zone()) CommonOperatorBuilder(graph_zone()), nullptr, |
3938 nullptr, | 3935 nullptr, |
3939 new (graph_zone()) MachineOperatorBuilder( | 3936 new (graph_zone()) MachineOperatorBuilder( |
3940 graph_zone(), MachineType::PointerRepresentation(), | 3937 graph_zone(), MachineType::PointerRepresentation(), |
3941 InstructionSelector::SupportedMachineOperatorFlags(), | 3938 InstructionSelector::SupportedMachineOperatorFlags(), |
3942 InstructionSelector::AlignmentRequirements()))), | 3939 InstructionSelector::AlignmentRequirements()))), |
3943 compilation_zone_(isolate->allocator(), ZONE_NAME), | 3940 compilation_zone_(isolate->allocator(), ZONE_NAME), |
3944 info_(GetDebugName(&compilation_zone_, name, index), isolate, | 3941 info_(GetDebugName(&compilation_zone_, name, index), isolate, |
3945 &compilation_zone_, Code::ComputeFlags(Code::WASM_FUNCTION)), | 3942 &compilation_zone_, Code::ComputeFlags(Code::WASM_FUNCTION)), |
3946 func_index_(index), | 3943 func_index_(index), |
3947 protected_instructions_(&compilation_zone_) {} | 3944 protected_instructions_(&compilation_zone_) {} |
3948 | 3945 |
3949 void WasmCompilationUnit::InitializeHandles() { | 3946 void WasmCompilationUnit::InitializeHandles() { |
3950 // Create and cache this node in the main thread, which contains a handle to | 3947 // Create and cache this node in the main thread, which contains a handle to |
3951 // the code object of the c-entry stub. | 3948 // the code object of the c-entry stub. |
3952 jsgraph_->CEntryStubConstant(1); | 3949 jsgraph_->CEntryStubConstant(1); |
3953 DCHECK(!handles_initialized_); | 3950 DCHECK(!handles_initialized_); |
3954 #if DEBUG | 3951 #if DEBUG |
3955 handles_initialized_ = true; | 3952 handles_initialized_ = true; |
3956 #endif // DEBUG | 3953 #endif // DEBUG |
3957 } | 3954 } |
3958 | 3955 |
3959 void WasmCompilationUnit::ExecuteCompilation() { | 3956 void WasmCompilationUnit::ExecuteCompilation() { |
3960 DCHECK(handles_initialized_); | 3957 DCHECK(handles_initialized_); |
3961 if (is_sync_) { | 3958 HistogramTimerScope wasm_compile_function_time_scope( |
3962 // TODO(karlschimpf): Make this work when asynchronous. | 3959 isolate_->counters()->wasm_compile_function_time()); |
3963 // https://bugs.chromium.org/p/v8/issues/detail?id=6361 | |
3964 HistogramTimerScope wasm_compile_function_time_scope( | |
3965 isolate_->counters()->wasm_compile_function_time()); | |
3966 ExecuteCompilationInternal(); | |
3967 return; | |
3968 } | |
3969 ExecuteCompilationInternal(); | |
3970 } | |
3971 | |
3972 void WasmCompilationUnit::ExecuteCompilationInternal() { | |
3973 if (FLAG_trace_wasm_compiler) { | 3960 if (FLAG_trace_wasm_compiler) { |
3974 if (func_name_.start() != nullptr) { | 3961 if (func_name_.start() != nullptr) { |
3975 PrintF("Compiling WASM function %d:'%.*s'\n\n", func_index(), | 3962 PrintF("Compiling WASM function %d:'%.*s'\n\n", func_index(), |
3976 func_name_.length(), func_name_.start()); | 3963 func_name_.length(), func_name_.start()); |
3977 } else { | 3964 } else { |
3978 PrintF("Compiling WASM function %d:<unnamed>\n\n", func_index()); | 3965 PrintF("Compiling WASM function %d:<unnamed>\n\n", func_index()); |
3979 } | 3966 } |
3980 } | 3967 } |
3981 | 3968 |
3982 double decode_ms = 0; | 3969 double decode_ms = 0; |
(...skipping 18 matching lines...) Expand all Loading... |
4001 &compilation_zone_, func_body_.sig); | 3988 &compilation_zone_, func_body_.sig); |
4002 if (jsgraph_->machine()->Is32()) { | 3989 if (jsgraph_->machine()->Is32()) { |
4003 descriptor = | 3990 descriptor = |
4004 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); | 3991 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); |
4005 } | 3992 } |
4006 job_.reset(Pipeline::NewWasmCompilationJob( | 3993 job_.reset(Pipeline::NewWasmCompilationJob( |
4007 &info_, jsgraph_, descriptor, source_positions, &protected_instructions_, | 3994 &info_, jsgraph_, descriptor, source_positions, &protected_instructions_, |
4008 !module_env_->module->is_wasm())); | 3995 !module_env_->module->is_wasm())); |
4009 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; | 3996 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; |
4010 // TODO(bradnelson): Improve histogram handling of size_t. | 3997 // TODO(bradnelson): Improve histogram handling of size_t. |
4011 if (is_sync_) | 3998 isolate_->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( |
4012 // TODO(karlschimpf): Make this work when asynchronous. | 3999 static_cast<int>(jsgraph_->graph()->zone()->allocation_size())); |
4013 // https://bugs.chromium.org/p/v8/issues/detail?id=6361 | |
4014 isolate_->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( | |
4015 static_cast<int>(jsgraph_->graph()->zone()->allocation_size())); | |
4016 | 4000 |
4017 if (FLAG_trace_wasm_decode_time) { | 4001 if (FLAG_trace_wasm_decode_time) { |
4018 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); | 4002 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); |
4019 PrintF( | 4003 PrintF( |
4020 "wasm-compilation phase 1 ok: %u bytes, %0.3f ms decode, %zu nodes, " | 4004 "wasm-compilation phase 1 ok: %u bytes, %0.3f ms decode, %zu nodes, " |
4021 "%0.3f ms pipeline\n", | 4005 "%0.3f ms pipeline\n", |
4022 static_cast<unsigned>(func_body_.end - func_body_.start), decode_ms, | 4006 static_cast<unsigned>(func_body_.end - func_body_.start), decode_ms, |
4023 node_count, pipeline_ms); | 4007 node_count, pipeline_ms); |
4024 } | 4008 } |
4025 } | 4009 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4075 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { | 4059 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { |
4076 WasmCompilationUnit unit(isolate, module_env, function); | 4060 WasmCompilationUnit unit(isolate, module_env, function); |
4077 unit.InitializeHandles(); | 4061 unit.InitializeHandles(); |
4078 unit.ExecuteCompilation(); | 4062 unit.ExecuteCompilation(); |
4079 return unit.FinishCompilation(thrower); | 4063 return unit.FinishCompilation(thrower); |
4080 } | 4064 } |
4081 | 4065 |
4082 } // namespace compiler | 4066 } // namespace compiler |
4083 } // namespace internal | 4067 } // namespace internal |
4084 } // namespace v8 | 4068 } // namespace v8 |
OLD | NEW |