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

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

Issue 2094563002: [wasm] Complete separation of compilation and instantiation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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
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 "src/isolate-inl.h" 7 #include "src/isolate-inl.h"
8 8
9 #include "src/base/platform/elapsed-timer.h" 9 #include "src/base/platform/elapsed-timer.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 2901 matching lines...) Expand 10 before | Expand all | Expand 10 after
2912 2912
2913 void WasmGraphBuilder::SetSourcePosition(Node* node, 2913 void WasmGraphBuilder::SetSourcePosition(Node* node,
2914 wasm::WasmCodePosition position) { 2914 wasm::WasmCodePosition position) {
2915 DCHECK_NE(position, wasm::kNoCodePosition); 2915 DCHECK_NE(position, wasm::kNoCodePosition);
2916 compiler::SourcePosition pos(position); 2916 compiler::SourcePosition pos(position);
2917 if (source_position_table_) 2917 if (source_position_table_)
2918 source_position_table_->SetSourcePosition(node, pos); 2918 source_position_table_->SetSourcePosition(node, pos);
2919 } 2919 }
2920 2920
2921 static void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag, 2921 static void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
2922 CompilationInfo* info, 2922 Isolate* isolate, Handle<Code> code,
2923 const char* message, uint32_t index, 2923 const char* message, uint32_t index,
2924 wasm::WasmName func_name) { 2924 const wasm::WasmName& module_name,
2925 Isolate* isolate = info->isolate(); 2925 const wasm::WasmName& func_name) {
2926 if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) { 2926 DCHECK(isolate->logger()->is_logging_code_events() ||
2927 ScopedVector<char> buffer(128); 2927 isolate->is_profiling());
2928 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length(), 2928
2929 func_name.start()); 2929 ScopedVector<char> buffer(128);
2930 Handle<String> name_str = 2930 SNPrintF(buffer, "%s#%d:%.*s:%.*s", message, index, module_name.length(),
2931 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); 2931 module_name.start(), func_name.length(), func_name.start());
2932 Handle<String> script_str = 2932 Handle<String> name_str =
2933 isolate->factory()->NewStringFromAsciiChecked("(WASM)"); 2933 isolate->factory()->NewStringFromAsciiChecked(buffer.start());
2934 Handle<Code> code = info->code(); 2934 Handle<String> script_str =
2935 Handle<SharedFunctionInfo> shared = 2935 isolate->factory()->NewStringFromAsciiChecked("(WASM)");
2936 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); 2936 Handle<SharedFunctionInfo> shared =
2937 PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared, 2937 isolate->factory()->NewSharedFunctionInfo(name_str, code, false);
2938 *script_str, 0, 0)); 2938 PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared,
2939 } 2939 *script_str, 0, 0));
2940 } 2940 }
2941 2941
2942 Handle<JSFunction> CompileJSToWasmWrapper( 2942 Handle<JSFunction> CompileJSToWasmWrapper(Isolate* isolate,
2943 Isolate* isolate, wasm::ModuleEnv* module, Handle<String> name, 2943 wasm::ModuleEnv* module,
2944 Handle<Code> wasm_code, Handle<JSObject> module_object, uint32_t index) { 2944 Handle<String> name,
2945 Handle<Code> wasm_code,
2946 uint32_t index) {
2945 const wasm::WasmFunction* func = &module->module->functions[index]; 2947 const wasm::WasmFunction* func = &module->module->functions[index];
2946 2948
2947 //---------------------------------------------------------------------------- 2949 //----------------------------------------------------------------------------
2948 // Create the JSFunction object. 2950 // Create the JSFunction object.
2949 //---------------------------------------------------------------------------- 2951 //----------------------------------------------------------------------------
2950 Handle<SharedFunctionInfo> shared = 2952 Handle<SharedFunctionInfo> shared =
2951 isolate->factory()->NewSharedFunctionInfo(name, wasm_code, false); 2953 isolate->factory()->NewSharedFunctionInfo(name, wasm_code, false);
2952 int params = static_cast<int>(func->sig->parameter_count()); 2954 int params = static_cast<int>(func->sig->parameter_count());
2953 shared->set_length(params); 2955 shared->set_length(params);
2954 shared->set_internal_formal_parameter_count(params); 2956 shared->set_internal_formal_parameter_count(params);
2955 Handle<JSFunction> function = isolate->factory()->NewFunction( 2957 Handle<JSFunction> function = isolate->factory()->NewFunction(
2956 isolate->wasm_function_map(), name, MaybeHandle<Code>()); 2958 isolate->wasm_function_map(), name, MaybeHandle<Code>());
2957 function->SetInternalField(0, *module_object);
2958 function->set_shared(*shared); 2959 function->set_shared(*shared);
2959 2960
2960 //---------------------------------------------------------------------------- 2961 //----------------------------------------------------------------------------
2961 // Create the Graph 2962 // Create the Graph
2962 //---------------------------------------------------------------------------- 2963 //----------------------------------------------------------------------------
2963 Zone zone(isolate->allocator()); 2964 Zone zone(isolate->allocator());
2964 Graph graph(&zone); 2965 Graph graph(&zone);
2965 CommonOperatorBuilder common(&zone); 2966 CommonOperatorBuilder common(&zone);
2966 MachineOperatorBuilder machine(&zone); 2967 MachineOperatorBuilder machine(&zone);
2967 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 2968 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3013 #ifdef ENABLE_DISASSEMBLER 3014 #ifdef ENABLE_DISASSEMBLER
3014 if (FLAG_print_opt_code && !code.is_null()) { 3015 if (FLAG_print_opt_code && !code.is_null()) {
3015 OFStream os(stdout); 3016 OFStream os(stdout);
3016 code->Disassemble(buffer.start(), os); 3017 code->Disassemble(buffer.start(), os);
3017 } 3018 }
3018 #endif 3019 #endif
3019 if (debugging) { 3020 if (debugging) {
3020 buffer.Dispose(); 3021 buffer.Dispose();
3021 } 3022 }
3022 3023
3023 RecordFunctionCompilation( 3024 if (isolate->logger()->is_logging_code_events() ||
3024 CodeEventListener::FUNCTION_TAG, &info, "js-to-wasm", index, 3025 isolate->is_profiling()) {
3025 module->module->GetName(func->name_offset, func->name_length)); 3026 RecordFunctionCompilation(
3027 CodeEventListener::FUNCTION_TAG, isolate, code, "js-to-wasm", index,
3028 wasm::WasmName("export"),
3029 module->module->GetName(func->name_offset, func->name_length));
3030 }
3026 // Set the JSFunction's machine code. 3031 // Set the JSFunction's machine code.
3027 function->set_code(*code); 3032 function->set_code(*code);
3028 } 3033 }
3029 return function; 3034 return function;
3030 } 3035 }
3031 3036
3032 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, 3037 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate,
3033 Handle<JSFunction> function, 3038 Handle<JSFunction> function,
3034 wasm::FunctionSig* sig, 3039 wasm::FunctionSig* sig, uint32_t index,
3035 wasm::WasmName module_name, 3040 Handle<String> import_module,
3036 wasm::WasmName function_name) { 3041 Handle<String> import_function) {
3037 //---------------------------------------------------------------------------- 3042 //----------------------------------------------------------------------------
3038 // Create the Graph 3043 // Create the Graph
3039 //---------------------------------------------------------------------------- 3044 //----------------------------------------------------------------------------
3040 Zone zone(isolate->allocator()); 3045 Zone zone(isolate->allocator());
3041 Graph graph(&zone); 3046 Graph graph(&zone);
3042 CommonOperatorBuilder common(&zone); 3047 CommonOperatorBuilder common(&zone);
3043 MachineOperatorBuilder machine(&zone); 3048 MachineOperatorBuilder machine(&zone);
3044 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 3049 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
3045 3050
3046 Node* control = nullptr; 3051 Node* control = nullptr;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); 3090 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr);
3086 #ifdef ENABLE_DISASSEMBLER 3091 #ifdef ENABLE_DISASSEMBLER
3087 if (FLAG_print_opt_code && !code.is_null()) { 3092 if (FLAG_print_opt_code && !code.is_null()) {
3088 OFStream os(stdout); 3093 OFStream os(stdout);
3089 code->Disassemble(buffer.start(), os); 3094 code->Disassemble(buffer.start(), os);
3090 } 3095 }
3091 #endif 3096 #endif
3092 if (debugging) { 3097 if (debugging) {
3093 buffer.Dispose(); 3098 buffer.Dispose();
3094 } 3099 }
3100 }
3101 if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
3102 RecordFunctionCompilation(
3103 CodeEventListener::FUNCTION_TAG, isolate, code, "wasm-to-js", index,
3104 {import_module->ToCString().get(), import_module->length()},
3105 {import_function->ToCString().get(), import_function->length()});
3106 }
3095 3107
3096 RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, &info,
3097 "wasm-to-js", 0, module_name);
3098 }
3099 return code; 3108 return code;
3100 } 3109 }
3101 3110
3102 SourcePositionTable* WasmCompilationUnit::BuildGraphForWasmFunction( 3111 SourcePositionTable* WasmCompilationUnit::BuildGraphForWasmFunction(
3103 double* decode_ms) { 3112 double* decode_ms) {
3104 base::ElapsedTimer decode_timer; 3113 base::ElapsedTimer decode_timer;
3105 if (FLAG_trace_wasm_decode_time) { 3114 if (FLAG_trace_wasm_decode_time) {
3106 decode_timer.Start(); 3115 decode_timer.Start();
3107 } 3116 }
3108 // Create a TF graph during decoding. 3117 // Create a TF graph during decoding.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3251 if (job_->GenerateCode() != CompilationJob::SUCCEEDED) { 3260 if (job_->GenerateCode() != CompilationJob::SUCCEEDED) {
3252 return Handle<Code>::null(); 3261 return Handle<Code>::null();
3253 } 3262 }
3254 base::ElapsedTimer compile_timer; 3263 base::ElapsedTimer compile_timer;
3255 if (FLAG_trace_wasm_decode_time) { 3264 if (FLAG_trace_wasm_decode_time) {
3256 compile_timer.Start(); 3265 compile_timer.Start();
3257 } 3266 }
3258 Handle<Code> code = info_.code(); 3267 Handle<Code> code = info_.code();
3259 DCHECK(!code.is_null()); 3268 DCHECK(!code.is_null());
3260 3269
3261 RecordFunctionCompilation( 3270 if (isolate_->logger()->is_logging_code_events() ||
3262 CodeEventListener::FUNCTION_TAG, &info_, "WASM_function", 3271 isolate_->is_profiling()) {
3263 function_->func_index, 3272 RecordFunctionCompilation(
3264 module_env_->module->GetName(function_->name_offset, 3273 CodeEventListener::FUNCTION_TAG, isolate_, code, "WASM_function",
3265 function_->name_length)); 3274 function_->func_index, wasm::WasmName("module"),
3275 module_env_->module->GetName(function_->name_offset,
3276 function_->name_length));
3277 }
3266 3278
3267 if (FLAG_trace_wasm_decode_time) { 3279 if (FLAG_trace_wasm_decode_time) {
3268 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); 3280 double compile_ms = compile_timer.Elapsed().InMillisecondsF();
3269 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n", 3281 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n",
3270 static_cast<int>(function_->code_end_offset - 3282 static_cast<int>(function_->code_end_offset -
3271 function_->code_start_offset), 3283 function_->code_start_offset),
3272 compile_ms); 3284 compile_ms);
3273 } 3285 }
3274 3286
3275 return code; 3287 return code;
3276 } 3288 }
3277 3289
3278 } // namespace compiler 3290 } // namespace compiler
3279 } // namespace internal 3291 } // namespace internal
3280 } // namespace v8 3292 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/objects.h » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698