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

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

Issue 1709653002: [wasm] Add support for import section. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: delete the import_code vector Created 4 years, 10 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/wasm/ast-decoder.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/platform.h" 9 #include "src/base/platform/platform.h"
10 10
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 Node* WasmGraphBuilder::CallDirect(uint32_t index, Node** args) { 1497 Node* WasmGraphBuilder::CallDirect(uint32_t index, Node** args) {
1498 DCHECK_NULL(args[0]); 1498 DCHECK_NULL(args[0]);
1499 1499
1500 // Add code object as constant. 1500 // Add code object as constant.
1501 args[0] = Constant(module_->GetFunctionCode(index)); 1501 args[0] = Constant(module_->GetFunctionCode(index));
1502 wasm::FunctionSig* sig = module_->GetFunctionSignature(index); 1502 wasm::FunctionSig* sig = module_->GetFunctionSignature(index);
1503 1503
1504 return BuildWasmCall(sig, args); 1504 return BuildWasmCall(sig, args);
1505 } 1505 }
1506 1506
1507 Node* WasmGraphBuilder::CallImport(uint32_t index, Node** args) {
1508 DCHECK_NULL(args[0]);
1509
1510 // Add code object as constant.
1511 args[0] = Constant(module_->GetImportCode(index));
1512 wasm::FunctionSig* sig = module_->GetFunctionSignature(index);
binji 2016/02/19 20:30:12 I think this should be GetImportSignature. I'm get
titzer 2016/02/21 09:18:35 Good catch. https://codereview.chromium.org/171799
1513
1514 return BuildWasmCall(sig, args);
1515 }
1507 1516
1508 Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args) { 1517 Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args) {
1509 DCHECK_NOT_NULL(args[0]); 1518 DCHECK_NOT_NULL(args[0]);
1510 DCHECK(module_ && module_->instance); 1519 DCHECK(module_ && module_->instance);
1511 1520
1512 MachineOperatorBuilder* machine = jsgraph()->machine(); 1521 MachineOperatorBuilder* machine = jsgraph()->machine();
1513 1522
1514 // Compute the code object by loading it from the function table. 1523 // Compute the code object by loading it from the function table.
1515 Node* key = args[0]; 1524 Node* key = args[0];
1516 1525
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 } 2040 }
2032 2041
2033 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "js-to-wasm", index, 2042 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "js-to-wasm", index,
2034 module->module->GetName(func->name_offset)); 2043 module->module->GetName(func->name_offset));
2035 // Set the JSFunction's machine code. 2044 // Set the JSFunction's machine code.
2036 function->set_code(*code); 2045 function->set_code(*code);
2037 } 2046 }
2038 return function; 2047 return function;
2039 } 2048 }
2040 2049
2041
2042 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module, 2050 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module,
2043 Handle<JSFunction> function, 2051 Handle<JSFunction> function,
2044 uint32_t index) { 2052 wasm::FunctionSig* sig, const char* name) {
2045 wasm::WasmFunction* func = &module->module->functions->at(index);
2046
2047 //---------------------------------------------------------------------------- 2053 //----------------------------------------------------------------------------
2048 // Create the Graph 2054 // Create the Graph
2049 //---------------------------------------------------------------------------- 2055 //----------------------------------------------------------------------------
2050 Zone zone; 2056 Zone zone;
2051 Graph graph(&zone); 2057 Graph graph(&zone);
2052 CommonOperatorBuilder common(&zone); 2058 CommonOperatorBuilder common(&zone);
2053 JSOperatorBuilder javascript(&zone); 2059 JSOperatorBuilder javascript(&zone);
2054 MachineOperatorBuilder machine(&zone); 2060 MachineOperatorBuilder machine(&zone);
2055 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); 2061 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine);
2056 2062
2057 Node* control = nullptr; 2063 Node* control = nullptr;
2058 Node* effect = nullptr; 2064 Node* effect = nullptr;
2059 2065
2060 WasmGraphBuilder builder(&zone, &jsgraph, func->sig); 2066 WasmGraphBuilder builder(&zone, &jsgraph, sig);
2061 builder.set_control_ptr(&control); 2067 builder.set_control_ptr(&control);
2062 builder.set_effect_ptr(&effect); 2068 builder.set_effect_ptr(&effect);
2063 builder.set_module(module); 2069 builder.set_module(module);
2064 builder.BuildWasmToJSWrapper(function, func->sig); 2070 builder.BuildWasmToJSWrapper(function, sig);
2065 2071
2066 Handle<Code> code = Handle<Code>::null(); 2072 Handle<Code> code = Handle<Code>::null();
2067 { 2073 {
2068 // Changes lowering requires types. 2074 // Changes lowering requires types.
2069 Typer typer(isolate, &graph); 2075 Typer typer(isolate, &graph);
2070 NodeVector roots(&zone); 2076 NodeVector roots(&zone);
2071 jsgraph.GetCachedNodes(&roots); 2077 jsgraph.GetCachedNodes(&roots);
2072 typer.Run(roots); 2078 typer.Run(roots);
2073 2079
2074 // Run generic and change lowering. 2080 // Run generic and change lowering.
2075 JSGenericLowering generic(true, &jsgraph); 2081 JSGenericLowering generic(true, &jsgraph);
2076 ChangeLowering changes(&jsgraph); 2082 ChangeLowering changes(&jsgraph);
2077 GraphReducer graph_reducer(&zone, &graph, jsgraph.Dead()); 2083 GraphReducer graph_reducer(&zone, &graph, jsgraph.Dead());
2078 graph_reducer.AddReducer(&changes); 2084 graph_reducer.AddReducer(&changes);
2079 graph_reducer.AddReducer(&generic); 2085 graph_reducer.AddReducer(&generic);
2080 graph_reducer.ReduceGraph(); 2086 graph_reducer.ReduceGraph();
2081 2087
2082 if (FLAG_trace_turbo_graph) { // Simple textual RPO. 2088 if (FLAG_trace_turbo_graph) { // Simple textual RPO.
2083 OFStream os(stdout); 2089 OFStream os(stdout);
2084 os << "-- Graph after change lowering -- " << std::endl; 2090 os << "-- Graph after change lowering -- " << std::endl;
2085 os << AsRPO(graph); 2091 os << AsRPO(graph);
2086 } 2092 }
2087 2093
2088 // Schedule and compile to machine code. 2094 // Schedule and compile to machine code.
2089 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, func->sig); 2095 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, sig);
2090 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. 2096 // TODO(titzer): this is technically a WASM wrapper, not a wasm function.
2091 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); 2097 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION);
2092 bool debugging = 2098 bool debugging =
2093 #if DEBUG 2099 #if DEBUG
2094 true; 2100 true;
2095 #else 2101 #else
2096 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; 2102 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
2097 #endif 2103 #endif
2098 const char* func_name = "wasm-to-js"; 2104 const char* func_name = "wasm-to-js";
2099 static unsigned id = 0; 2105 static unsigned id = 0;
2100 Vector<char> buffer; 2106 Vector<char> buffer;
2101 if (debugging) { 2107 if (debugging) {
2102 buffer = Vector<char>::New(128); 2108 buffer = Vector<char>::New(128);
2103 SNPrintF(buffer, "wasm-to-js#%d", id); 2109 SNPrintF(buffer, "wasm-to-js#%d", id);
2104 func_name = buffer.start(); 2110 func_name = buffer.start();
2105 } 2111 }
2106 2112
2107 CompilationInfo info(func_name, isolate, &zone, flags); 2113 CompilationInfo info(func_name, isolate, &zone, flags);
2108 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); 2114 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr);
2109 if (debugging) { 2115 if (debugging) {
2110 buffer.Dispose(); 2116 buffer.Dispose();
2111 } 2117 }
2112 2118
2113 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", index, 2119 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", 0,
2114 module->module->GetName(func->name_offset)); 2120 name);
2115 } 2121 }
2116 return code; 2122 return code;
2117 } 2123 }
2118 2124
2119 2125
2120 // Helper function to compile a single function. 2126 // Helper function to compile a single function.
2121 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, 2127 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
2122 wasm::ModuleEnv* module_env, 2128 wasm::ModuleEnv* module_env,
2123 const wasm::WasmFunction& function) { 2129 const wasm::WasmFunction& function) {
2124 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { 2130 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 module_env->module->GetName(function.name_offset)); 2207 module_env->module->GetName(function.name_offset));
2202 } 2208 }
2203 2209
2204 return code; 2210 return code;
2205 } 2211 }
2206 2212
2207 2213
2208 } // namespace compiler 2214 } // namespace compiler
2209 } // namespace internal 2215 } // namespace internal
2210 } // namespace v8 2216 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/wasm/ast-decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698