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/optional.h" | 10 #include "src/base/optional.h" |
(...skipping 3926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3937 DCHECK(name_len > 0 && name_len < name_vector.length()); | 3937 DCHECK(name_len > 0 && name_len < name_vector.length()); |
3938 | 3938 |
3939 char* index_name = zone->NewArray<char>(name_len); | 3939 char* index_name = zone->NewArray<char>(name_len); |
3940 memcpy(index_name, name_vector.start(), name_len); | 3940 memcpy(index_name, name_vector.start(), name_len); |
3941 return Vector<const char>(index_name, name_len); | 3941 return Vector<const char>(index_name, name_len); |
3942 } | 3942 } |
3943 } // namespace | 3943 } // namespace |
3944 | 3944 |
3945 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, | 3945 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, |
3946 wasm::ModuleBytesEnv* module_env, | 3946 wasm::ModuleBytesEnv* module_env, |
3947 const wasm::WasmFunction* function, | 3947 const wasm::WasmFunction* function) |
3948 bool is_sync) | |
3949 : WasmCompilationUnit( | 3948 : WasmCompilationUnit( |
3950 isolate, &module_env->module_env, | 3949 isolate, &module_env->module_env, |
3951 wasm::FunctionBody{ | 3950 wasm::FunctionBody{ |
3952 function->sig, module_env->wire_bytes.start(), | 3951 function->sig, module_env->wire_bytes.start(), |
3953 module_env->wire_bytes.start() + function->code.offset(), | 3952 module_env->wire_bytes.start() + function->code.offset(), |
3954 module_env->wire_bytes.start() + function->code.end_offset()}, | 3953 module_env->wire_bytes.start() + function->code.end_offset()}, |
3955 module_env->wire_bytes.GetNameOrNull(function), function->func_index, | 3954 module_env->wire_bytes.GetNameOrNull(function), |
3956 is_sync) {} | 3955 function->func_index) {} |
3957 | 3956 |
3958 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, | 3957 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, |
3959 wasm::ModuleEnv* module_env, | 3958 wasm::ModuleEnv* module_env, |
3960 wasm::FunctionBody body, | 3959 wasm::FunctionBody body, |
3961 wasm::WasmName name, int index, | 3960 wasm::WasmName name, int index) |
3962 bool is_sync) | |
3963 : isolate_(isolate), | 3961 : isolate_(isolate), |
3964 module_env_(module_env), | 3962 module_env_(module_env), |
3965 func_body_(body), | 3963 func_body_(body), |
3966 func_name_(name), | 3964 func_name_(name), |
3967 is_sync_(is_sync), | |
3968 centry_stub_(CEntryStub(isolate, 1).GetCode()), | 3965 centry_stub_(CEntryStub(isolate, 1).GetCode()), |
3969 func_index_(index) {} | 3966 func_index_(index) {} |
3970 | 3967 |
3971 void WasmCompilationUnit::ExecuteCompilation() { | 3968 void WasmCompilationUnit::ExecuteCompilation() { |
3972 // TODO(karlschimpf): Make this work when asynchronous. | 3969 HistogramTimerScope wasm_compile_function_time_scope( |
3973 // https://bugs.chromium.org/p/v8/issues/detail?id=6361 | 3970 isolate_->counters()->wasm_compile_function_time()); |
3974 base::Optional<HistogramTimerScope> wasm_compile_function_time_scope; | |
3975 if (is_sync_) { | |
3976 wasm_compile_function_time_scope.emplace( | |
3977 isolate_->counters()->wasm_compile_function_time()); | |
3978 } | |
3979 | 3971 |
3980 if (FLAG_trace_wasm_compiler) { | 3972 if (FLAG_trace_wasm_compiler) { |
3981 if (func_name_.start() != nullptr) { | 3973 if (func_name_.start() != nullptr) { |
3982 PrintF("Compiling wasm function %d:'%.*s'\n\n", func_index(), | 3974 PrintF("Compiling wasm function %d:'%.*s'\n\n", func_index(), |
3983 func_name_.length(), func_name_.start()); | 3975 func_name_.length(), func_name_.start()); |
3984 } else { | 3976 } else { |
3985 PrintF("Compiling wasm function %d:<unnamed>\n\n", func_index()); | 3977 PrintF("Compiling wasm function %d:<unnamed>\n\n", func_index()); |
3986 } | 3978 } |
3987 } | 3979 } |
3988 | 3980 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4027 isolate_, compilation_zone_.get(), | 4019 isolate_, compilation_zone_.get(), |
4028 Code::ComputeFlags(Code::WASM_FUNCTION))); | 4020 Code::ComputeFlags(Code::WASM_FUNCTION))); |
4029 ZoneVector<trap_handler::ProtectedInstructionData> protected_instructions( | 4021 ZoneVector<trap_handler::ProtectedInstructionData> protected_instructions( |
4030 compilation_zone_.get()); | 4022 compilation_zone_.get()); |
4031 | 4023 |
4032 job_.reset(Pipeline::NewWasmCompilationJob( | 4024 job_.reset(Pipeline::NewWasmCompilationJob( |
4033 info_.get(), jsgraph_, descriptor, source_positions, | 4025 info_.get(), jsgraph_, descriptor, source_positions, |
4034 &protected_instructions, !module_env_->module->is_wasm())); | 4026 &protected_instructions, !module_env_->module->is_wasm())); |
4035 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; | 4027 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; |
4036 // TODO(bradnelson): Improve histogram handling of size_t. | 4028 // TODO(bradnelson): Improve histogram handling of size_t. |
4037 if (is_sync_) | 4029 isolate_->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( |
4038 // TODO(karlschimpf): Make this work when asynchronous. | 4030 static_cast<int>(jsgraph_->graph()->zone()->allocation_size())); |
4039 // https://bugs.chromium.org/p/v8/issues/detail?id=6361 | |
4040 isolate_->counters() | |
4041 ->wasm_compile_function_peak_memory_bytes() | |
4042 ->AddSample( | |
4043 static_cast<int>(jsgraph_->graph()->zone()->allocation_size())); | |
4044 | 4031 |
4045 if (FLAG_trace_wasm_decode_time) { | 4032 if (FLAG_trace_wasm_decode_time) { |
4046 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); | 4033 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); |
4047 PrintF( | 4034 PrintF( |
4048 "wasm-compilation phase 1 ok: %u bytes, %0.3f ms decode, %zu nodes, " | 4035 "wasm-compilation phase 1 ok: %u bytes, %0.3f ms decode, %zu nodes, " |
4049 "%0.3f ms pipeline\n", | 4036 "%0.3f ms pipeline\n", |
4050 static_cast<unsigned>(func_body_.end - func_body_.start), decode_ms, | 4037 static_cast<unsigned>(func_body_.end - func_body_.start), decode_ms, |
4051 node_count, pipeline_ms); | 4038 node_count, pipeline_ms); |
4052 } | 4039 } |
4053 // The graph zone is about to get out of scope. Avoid invalid references. | 4040 // The graph zone is about to get out of scope. Avoid invalid references. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4110 wasm::ErrorThrower* thrower, Isolate* isolate, | 4097 wasm::ErrorThrower* thrower, Isolate* isolate, |
4111 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { | 4098 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { |
4112 WasmCompilationUnit unit(isolate, module_env, function); | 4099 WasmCompilationUnit unit(isolate, module_env, function); |
4113 unit.ExecuteCompilation(); | 4100 unit.ExecuteCompilation(); |
4114 return unit.FinishCompilation(thrower); | 4101 return unit.FinishCompilation(thrower); |
4115 } | 4102 } |
4116 | 4103 |
4117 } // namespace compiler | 4104 } // namespace compiler |
4118 } // namespace internal | 4105 } // namespace internal |
4119 } // namespace v8 | 4106 } // namespace v8 |
OLD | NEW |