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

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

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