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

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

Issue 2134593002: [wasm] cloning compiled module before instantiation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [wasm] cloning compiled module before instantiation 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/factory.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 3095 matching lines...) Expand 10 before | Expand all | Expand 10 after
3106 Handle<String> name_str = 3106 Handle<String> name_str =
3107 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); 3107 isolate->factory()->NewStringFromAsciiChecked(buffer.start());
3108 Handle<String> script_str = 3108 Handle<String> script_str =
3109 isolate->factory()->NewStringFromAsciiChecked("(WASM)"); 3109 isolate->factory()->NewStringFromAsciiChecked("(WASM)");
3110 Handle<SharedFunctionInfo> shared = 3110 Handle<SharedFunctionInfo> shared =
3111 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); 3111 isolate->factory()->NewSharedFunctionInfo(name_str, code, false);
3112 PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared, 3112 PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared,
3113 *script_str, 0, 0)); 3113 *script_str, 0, 0));
3114 } 3114 }
3115 3115
3116 Handle<JSFunction> CompileJSToWasmWrapper(Isolate* isolate, 3116 Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::ModuleEnv* module,
3117 wasm::ModuleEnv* module, 3117 Handle<Code> wasm_code, uint32_t index) {
3118 Handle<String> name,
3119 Handle<Code> wasm_code,
3120 uint32_t index) {
3121 const wasm::WasmFunction* func = &module->module->functions[index]; 3118 const wasm::WasmFunction* func = &module->module->functions[index];
3122 3119
3123 //---------------------------------------------------------------------------- 3120 //----------------------------------------------------------------------------
3124 // Create the JSFunction object.
3125 //----------------------------------------------------------------------------
3126 Handle<SharedFunctionInfo> shared =
3127 isolate->factory()->NewSharedFunctionInfo(name, wasm_code, false);
3128 int params = static_cast<int>(func->sig->parameter_count());
3129 shared->set_length(params);
3130 shared->set_internal_formal_parameter_count(params);
3131 Handle<JSFunction> function = isolate->factory()->NewFunction(
3132 isolate->wasm_function_map(), name, MaybeHandle<Code>());
3133 function->set_shared(*shared);
3134
3135 //----------------------------------------------------------------------------
3136 // Create the Graph 3121 // Create the Graph
3137 //---------------------------------------------------------------------------- 3122 //----------------------------------------------------------------------------
3138 Zone zone(isolate->allocator()); 3123 Zone zone(isolate->allocator());
3139 Graph graph(&zone); 3124 Graph graph(&zone);
3140 CommonOperatorBuilder common(&zone); 3125 CommonOperatorBuilder common(&zone);
3141 MachineOperatorBuilder machine(&zone); 3126 MachineOperatorBuilder machine(&zone);
3142 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 3127 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
3143 3128
3144 Node* control = nullptr; 3129 Node* control = nullptr;
3145 Node* effect = nullptr; 3130 Node* effect = nullptr;
3146 3131
3147 WasmGraphBuilder builder(&zone, &jsgraph, func->sig); 3132 WasmGraphBuilder builder(&zone, &jsgraph, func->sig);
3148 builder.set_control_ptr(&control); 3133 builder.set_control_ptr(&control);
3149 builder.set_effect_ptr(&effect); 3134 builder.set_effect_ptr(&effect);
3150 builder.set_module(module); 3135 builder.set_module(module);
3151 builder.BuildJSToWasmWrapper(wasm_code, func->sig); 3136 builder.BuildJSToWasmWrapper(wasm_code, func->sig);
3152 3137
3153 //---------------------------------------------------------------------------- 3138 //----------------------------------------------------------------------------
3154 // Run the compilation pipeline. 3139 // Run the compilation pipeline.
3155 //---------------------------------------------------------------------------- 3140 //----------------------------------------------------------------------------
3156 { 3141 if (FLAG_trace_turbo_graph) { // Simple textual RPO.
3157 if (FLAG_trace_turbo_graph) { // Simple textual RPO. 3142 OFStream os(stdout);
3158 OFStream os(stdout); 3143 os << "-- Graph after change lowering -- " << std::endl;
3159 os << "-- Graph after change lowering -- " << std::endl; 3144 os << AsRPO(graph);
3160 os << AsRPO(graph); 3145 }
3161 }
3162 3146
3163 // Schedule and compile to machine code. 3147 // Schedule and compile to machine code.
3164 int params = static_cast<int>( 3148 int params =
3165 module->GetFunctionSignature(index)->parameter_count()); 3149 static_cast<int>(module->GetFunctionSignature(index)->parameter_count());
3166 CallDescriptor* incoming = Linkage::GetJSCallDescriptor( 3150 CallDescriptor* incoming = Linkage::GetJSCallDescriptor(
3167 &zone, false, params + 1, CallDescriptor::kNoFlags); 3151 &zone, false, params + 1, CallDescriptor::kNoFlags);
3168 Code::Flags flags = Code::ComputeFlags(Code::JS_TO_WASM_FUNCTION); 3152 Code::Flags flags = Code::ComputeFlags(Code::JS_TO_WASM_FUNCTION);
3169 bool debugging = 3153 bool debugging =
3170 #if DEBUG 3154 #if DEBUG
3171 true; 3155 true;
3172 #else 3156 #else
3173 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; 3157 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
3174 #endif 3158 #endif
3175 Vector<const char> func_name = ArrayVector("js-to-wasm"); 3159 Vector<const char> func_name = ArrayVector("js-to-wasm");
3176 3160
3177 static unsigned id = 0; 3161 static unsigned id = 0;
3178 Vector<char> buffer; 3162 Vector<char> buffer;
3179 if (debugging) { 3163 if (debugging) {
3180 buffer = Vector<char>::New(128); 3164 buffer = Vector<char>::New(128);
3181 int chars = SNPrintF(buffer, "js-to-wasm#%d", id); 3165 int chars = SNPrintF(buffer, "js-to-wasm#%d", id);
3182 func_name = Vector<const char>::cast(buffer.SubVector(0, chars)); 3166 func_name = Vector<const char>::cast(buffer.SubVector(0, chars));
3183 } 3167 }
3184 3168
3185 CompilationInfo info(func_name, isolate, &zone, flags); 3169 CompilationInfo info(func_name, isolate, &zone, flags);
3186 Handle<Code> code = 3170 Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph);
3187 Pipeline::GenerateCodeForTesting(&info, incoming, &graph);
3188 #ifdef ENABLE_DISASSEMBLER 3171 #ifdef ENABLE_DISASSEMBLER
3189 if (FLAG_print_opt_code && !code.is_null()) { 3172 if (FLAG_print_opt_code && !code.is_null()) {
3190 OFStream os(stdout); 3173 OFStream os(stdout);
3191 code->Disassemble(buffer.start(), os); 3174 code->Disassemble(buffer.start(), os);
3192 } 3175 }
3193 #endif 3176 #endif
3194 if (debugging) { 3177 if (debugging) {
3195 buffer.Dispose(); 3178 buffer.Dispose();
3196 } 3179 }
3197 3180
3198 if (isolate->logger()->is_logging_code_events() || 3181 if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
3199 isolate->is_profiling()) { 3182 RecordFunctionCompilation(
3200 RecordFunctionCompilation( 3183 CodeEventListener::FUNCTION_TAG, isolate, code, "js-to-wasm", index,
3201 CodeEventListener::FUNCTION_TAG, isolate, code, "js-to-wasm", index, 3184 wasm::WasmName("export"),
3202 wasm::WasmName("export"), 3185 module->module->GetName(func->name_offset, func->name_length));
3203 module->module->GetName(func->name_offset, func->name_length));
3204 }
3205 // Set the JSFunction's machine code.
3206 function->set_code(*code);
3207 } 3186 }
3208 return function; 3187 return code;
3209 } 3188 }
3210 3189
3211 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, 3190 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate,
3212 Handle<JSFunction> function, 3191 Handle<JSFunction> function,
3213 wasm::FunctionSig* sig, uint32_t index, 3192 wasm::FunctionSig* sig, uint32_t index,
3214 Handle<String> import_module, 3193 Handle<String> import_module,
3215 MaybeHandle<String> import_function) { 3194 MaybeHandle<String> import_function) {
3216 //---------------------------------------------------------------------------- 3195 //----------------------------------------------------------------------------
3217 // Create the Graph 3196 // Create the Graph
3218 //---------------------------------------------------------------------------- 3197 //----------------------------------------------------------------------------
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
3464 function_->code_start_offset), 3443 function_->code_start_offset),
3465 compile_ms); 3444 compile_ms);
3466 } 3445 }
3467 3446
3468 return code; 3447 return code;
3469 } 3448 }
3470 3449
3471 } // namespace compiler 3450 } // namespace compiler
3472 } // namespace internal 3451 } // namespace internal
3473 } // namespace v8 3452 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698