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

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

Issue 2103983003: Revert "[wasm] Complete separation of compilation and instantiation" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 2937 matching lines...) Expand 10 before | Expand all | Expand 10 after
2948 2948
2949 void WasmGraphBuilder::SetSourcePosition(Node* node, 2949 void WasmGraphBuilder::SetSourcePosition(Node* node,
2950 wasm::WasmCodePosition position) { 2950 wasm::WasmCodePosition position) {
2951 DCHECK_NE(position, wasm::kNoCodePosition); 2951 DCHECK_NE(position, wasm::kNoCodePosition);
2952 compiler::SourcePosition pos(position); 2952 compiler::SourcePosition pos(position);
2953 if (source_position_table_) 2953 if (source_position_table_)
2954 source_position_table_->SetSourcePosition(node, pos); 2954 source_position_table_->SetSourcePosition(node, pos);
2955 } 2955 }
2956 2956
2957 static void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag, 2957 static void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
2958 Isolate* isolate, Handle<Code> code, 2958 CompilationInfo* info,
2959 const char* message, uint32_t index, 2959 const char* message, uint32_t index,
2960 const wasm::WasmName& module_name, 2960 wasm::WasmName func_name) {
2961 const wasm::WasmName& func_name) { 2961 Isolate* isolate = info->isolate();
2962 DCHECK(isolate->logger()->is_logging_code_events() || 2962 if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
2963 isolate->is_profiling()); 2963 ScopedVector<char> buffer(128);
2964 2964 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length(),
2965 ScopedVector<char> buffer(128); 2965 func_name.start());
2966 SNPrintF(buffer, "%s#%d:%.*s:%.*s", message, index, module_name.length(), 2966 Handle<String> name_str =
2967 module_name.start(), func_name.length(), func_name.start()); 2967 isolate->factory()->NewStringFromAsciiChecked(buffer.start());
2968 Handle<String> name_str = 2968 Handle<String> script_str =
2969 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); 2969 isolate->factory()->NewStringFromAsciiChecked("(WASM)");
2970 Handle<String> script_str = 2970 Handle<Code> code = info->code();
2971 isolate->factory()->NewStringFromAsciiChecked("(WASM)"); 2971 Handle<SharedFunctionInfo> shared =
2972 Handle<SharedFunctionInfo> shared = 2972 isolate->factory()->NewSharedFunctionInfo(name_str, code, false);
2973 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); 2973 PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared,
2974 PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared, 2974 *script_str, 0, 0));
2975 *script_str, 0, 0)); 2975 }
2976 } 2976 }
2977 2977
2978 Handle<JSFunction> CompileJSToWasmWrapper(Isolate* isolate, 2978 Handle<JSFunction> CompileJSToWasmWrapper(
2979 wasm::ModuleEnv* module, 2979 Isolate* isolate, wasm::ModuleEnv* module, Handle<String> name,
2980 Handle<String> name, 2980 Handle<Code> wasm_code, Handle<JSObject> module_object, uint32_t index) {
2981 Handle<Code> wasm_code,
2982 uint32_t index) {
2983 const wasm::WasmFunction* func = &module->module->functions[index]; 2981 const wasm::WasmFunction* func = &module->module->functions[index];
2984 2982
2985 //---------------------------------------------------------------------------- 2983 //----------------------------------------------------------------------------
2986 // Create the JSFunction object. 2984 // Create the JSFunction object.
2987 //---------------------------------------------------------------------------- 2985 //----------------------------------------------------------------------------
2988 Handle<SharedFunctionInfo> shared = 2986 Handle<SharedFunctionInfo> shared =
2989 isolate->factory()->NewSharedFunctionInfo(name, wasm_code, false); 2987 isolate->factory()->NewSharedFunctionInfo(name, wasm_code, false);
2990 int params = static_cast<int>(func->sig->parameter_count()); 2988 int params = static_cast<int>(func->sig->parameter_count());
2991 shared->set_length(params); 2989 shared->set_length(params);
2992 shared->set_internal_formal_parameter_count(params); 2990 shared->set_internal_formal_parameter_count(params);
2993 Handle<JSFunction> function = isolate->factory()->NewFunction( 2991 Handle<JSFunction> function = isolate->factory()->NewFunction(
2994 isolate->wasm_function_map(), name, MaybeHandle<Code>()); 2992 isolate->wasm_function_map(), name, MaybeHandle<Code>());
2993 function->SetInternalField(0, *module_object);
2995 function->set_shared(*shared); 2994 function->set_shared(*shared);
2996 2995
2997 //---------------------------------------------------------------------------- 2996 //----------------------------------------------------------------------------
2998 // Create the Graph 2997 // Create the Graph
2999 //---------------------------------------------------------------------------- 2998 //----------------------------------------------------------------------------
3000 Zone zone(isolate->allocator()); 2999 Zone zone(isolate->allocator());
3001 Graph graph(&zone); 3000 Graph graph(&zone);
3002 CommonOperatorBuilder common(&zone); 3001 CommonOperatorBuilder common(&zone);
3003 MachineOperatorBuilder machine(&zone); 3002 MachineOperatorBuilder machine(&zone);
3004 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 3003 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3050 #ifdef ENABLE_DISASSEMBLER 3049 #ifdef ENABLE_DISASSEMBLER
3051 if (FLAG_print_opt_code && !code.is_null()) { 3050 if (FLAG_print_opt_code && !code.is_null()) {
3052 OFStream os(stdout); 3051 OFStream os(stdout);
3053 code->Disassemble(buffer.start(), os); 3052 code->Disassemble(buffer.start(), os);
3054 } 3053 }
3055 #endif 3054 #endif
3056 if (debugging) { 3055 if (debugging) {
3057 buffer.Dispose(); 3056 buffer.Dispose();
3058 } 3057 }
3059 3058
3060 if (isolate->logger()->is_logging_code_events() || 3059 RecordFunctionCompilation(
3061 isolate->is_profiling()) { 3060 CodeEventListener::FUNCTION_TAG, &info, "js-to-wasm", index,
3062 RecordFunctionCompilation( 3061 module->module->GetName(func->name_offset, func->name_length));
3063 CodeEventListener::FUNCTION_TAG, isolate, code, "js-to-wasm", index,
3064 wasm::WasmName("export"),
3065 module->module->GetName(func->name_offset, func->name_length));
3066 }
3067 // Set the JSFunction's machine code. 3062 // Set the JSFunction's machine code.
3068 function->set_code(*code); 3063 function->set_code(*code);
3069 } 3064 }
3070 return function; 3065 return function;
3071 } 3066 }
3072 3067
3073 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, 3068 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate,
3074 Handle<JSFunction> function, 3069 Handle<JSFunction> function,
3075 wasm::FunctionSig* sig, uint32_t index, 3070 wasm::FunctionSig* sig,
3076 Handle<String> import_module, 3071 wasm::WasmName module_name,
3077 MaybeHandle<String> import_function) { 3072 wasm::WasmName function_name) {
3078 //---------------------------------------------------------------------------- 3073 //----------------------------------------------------------------------------
3079 // Create the Graph 3074 // Create the Graph
3080 //---------------------------------------------------------------------------- 3075 //----------------------------------------------------------------------------
3081 Zone zone(isolate->allocator()); 3076 Zone zone(isolate->allocator());
3082 Graph graph(&zone); 3077 Graph graph(&zone);
3083 CommonOperatorBuilder common(&zone); 3078 CommonOperatorBuilder common(&zone);
3084 MachineOperatorBuilder machine(&zone); 3079 MachineOperatorBuilder machine(&zone);
3085 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 3080 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
3086 3081
3087 Node* control = nullptr; 3082 Node* control = nullptr;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3126 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); 3121 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr);
3127 #ifdef ENABLE_DISASSEMBLER 3122 #ifdef ENABLE_DISASSEMBLER
3128 if (FLAG_print_opt_code && !code.is_null()) { 3123 if (FLAG_print_opt_code && !code.is_null()) {
3129 OFStream os(stdout); 3124 OFStream os(stdout);
3130 code->Disassemble(buffer.start(), os); 3125 code->Disassemble(buffer.start(), os);
3131 } 3126 }
3132 #endif 3127 #endif
3133 if (debugging) { 3128 if (debugging) {
3134 buffer.Dispose(); 3129 buffer.Dispose();
3135 } 3130 }
3131
3132 RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, &info,
3133 "wasm-to-js", 0, module_name);
3136 } 3134 }
3137 if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
3138 const char* function_name = nullptr;
3139 int function_name_size = 0;
3140 if (!import_function.is_null()) {
3141 Handle<String> handle = import_function.ToHandleChecked();
3142 function_name = handle->ToCString().get();
3143 function_name_size = handle->length();
3144 }
3145 RecordFunctionCompilation(
3146 CodeEventListener::FUNCTION_TAG, isolate, code, "wasm-to-js", index,
3147 {import_module->ToCString().get(), import_module->length()},
3148 {function_name, function_name_size});
3149 }
3150
3151 return code; 3135 return code;
3152 } 3136 }
3153 3137
3154 SourcePositionTable* WasmCompilationUnit::BuildGraphForWasmFunction( 3138 SourcePositionTable* WasmCompilationUnit::BuildGraphForWasmFunction(
3155 double* decode_ms) { 3139 double* decode_ms) {
3156 base::ElapsedTimer decode_timer; 3140 base::ElapsedTimer decode_timer;
3157 if (FLAG_trace_wasm_decode_time) { 3141 if (FLAG_trace_wasm_decode_time) {
3158 decode_timer.Start(); 3142 decode_timer.Start();
3159 } 3143 }
3160 // Create a TF graph during decoding. 3144 // Create a TF graph during decoding.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3303 if (job_->GenerateCode() != CompilationJob::SUCCEEDED) { 3287 if (job_->GenerateCode() != CompilationJob::SUCCEEDED) {
3304 return Handle<Code>::null(); 3288 return Handle<Code>::null();
3305 } 3289 }
3306 base::ElapsedTimer compile_timer; 3290 base::ElapsedTimer compile_timer;
3307 if (FLAG_trace_wasm_decode_time) { 3291 if (FLAG_trace_wasm_decode_time) {
3308 compile_timer.Start(); 3292 compile_timer.Start();
3309 } 3293 }
3310 Handle<Code> code = info_.code(); 3294 Handle<Code> code = info_.code();
3311 DCHECK(!code.is_null()); 3295 DCHECK(!code.is_null());
3312 3296
3313 if (isolate_->logger()->is_logging_code_events() || 3297 RecordFunctionCompilation(
3314 isolate_->is_profiling()) { 3298 CodeEventListener::FUNCTION_TAG, &info_, "WASM_function",
3315 RecordFunctionCompilation( 3299 function_->func_index,
3316 CodeEventListener::FUNCTION_TAG, isolate_, code, "WASM_function", 3300 module_env_->module->GetName(function_->name_offset,
3317 function_->func_index, wasm::WasmName("module"), 3301 function_->name_length));
3318 module_env_->module->GetName(function_->name_offset,
3319 function_->name_length));
3320 }
3321 3302
3322 if (FLAG_trace_wasm_decode_time) { 3303 if (FLAG_trace_wasm_decode_time) {
3323 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); 3304 double compile_ms = compile_timer.Elapsed().InMillisecondsF();
3324 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n", 3305 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n",
3325 static_cast<int>(function_->code_end_offset - 3306 static_cast<int>(function_->code_end_offset -
3326 function_->code_start_offset), 3307 function_->code_start_offset),
3327 compile_ms); 3308 compile_ms);
3328 } 3309 }
3329 3310
3330 return code; 3311 return code;
3331 } 3312 }
3332 3313
3333 } // namespace compiler 3314 } // namespace compiler
3334 } // namespace internal 3315 } // namespace internal
3335 } // namespace v8 3316 } // 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