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

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: Incorporated Feedback Created 4 years, 5 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 | « src/compiler/wasm-compiler.h ('k') | src/objects.h » ('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 "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 MaybeHandle<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 const char* function_name = nullptr;
3103 int function_name_size = 0;
3104 if (!import_function.is_null()) {
3105 Handle<String> handle = import_function.ToHandleChecked();
3106 function_name = handle->ToCString().get();
3107 function_name_size = handle->length();
3108 }
3109 RecordFunctionCompilation(
3110 CodeEventListener::FUNCTION_TAG, isolate, code, "wasm-to-js", index,
3111 {import_module->ToCString().get(), import_module->length()},
3112 {function_name, function_name_size});
3113 }
3095 3114
3096 RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, &info,
3097 "wasm-to-js", 0, module_name);
3098 }
3099 return code; 3115 return code;
3100 } 3116 }
3101 3117
3102 SourcePositionTable* WasmCompilationUnit::BuildGraphForWasmFunction( 3118 SourcePositionTable* WasmCompilationUnit::BuildGraphForWasmFunction(
3103 double* decode_ms) { 3119 double* decode_ms) {
3104 base::ElapsedTimer decode_timer; 3120 base::ElapsedTimer decode_timer;
3105 if (FLAG_trace_wasm_decode_time) { 3121 if (FLAG_trace_wasm_decode_time) {
3106 decode_timer.Start(); 3122 decode_timer.Start();
3107 } 3123 }
3108 // Create a TF graph during decoding. 3124 // Create a TF graph during decoding.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3251 if (job_->GenerateCode() != CompilationJob::SUCCEEDED) { 3267 if (job_->GenerateCode() != CompilationJob::SUCCEEDED) {
3252 return Handle<Code>::null(); 3268 return Handle<Code>::null();
3253 } 3269 }
3254 base::ElapsedTimer compile_timer; 3270 base::ElapsedTimer compile_timer;
3255 if (FLAG_trace_wasm_decode_time) { 3271 if (FLAG_trace_wasm_decode_time) {
3256 compile_timer.Start(); 3272 compile_timer.Start();
3257 } 3273 }
3258 Handle<Code> code = info_.code(); 3274 Handle<Code> code = info_.code();
3259 DCHECK(!code.is_null()); 3275 DCHECK(!code.is_null());
3260 3276
3261 RecordFunctionCompilation( 3277 if (isolate_->logger()->is_logging_code_events() ||
3262 CodeEventListener::FUNCTION_TAG, &info_, "WASM_function", 3278 isolate_->is_profiling()) {
3263 function_->func_index, 3279 RecordFunctionCompilation(
3264 module_env_->module->GetName(function_->name_offset, 3280 CodeEventListener::FUNCTION_TAG, isolate_, code, "WASM_function",
3265 function_->name_length)); 3281 function_->func_index, wasm::WasmName("module"),
3282 module_env_->module->GetName(function_->name_offset,
3283 function_->name_length));
3284 }
3266 3285
3267 if (FLAG_trace_wasm_decode_time) { 3286 if (FLAG_trace_wasm_decode_time) {
3268 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); 3287 double compile_ms = compile_timer.Elapsed().InMillisecondsF();
3269 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n", 3288 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n",
3270 static_cast<int>(function_->code_end_offset - 3289 static_cast<int>(function_->code_end_offset -
3271 function_->code_start_offset), 3290 function_->code_start_offset),
3272 compile_ms); 3291 compile_ms);
3273 } 3292 }
3274 3293
3275 return code; 3294 return code;
3276 } 3295 }
3277 3296
3278 } // namespace compiler 3297 } // namespace compiler
3279 } // namespace internal 3298 } // namespace internal
3280 } // namespace v8 3299 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698