| OLD | NEW |
| 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 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 Node* WasmGraphBuilder::CallDirect(uint32_t index, Node** args) { | 1496 Node* WasmGraphBuilder::CallDirect(uint32_t index, Node** args) { |
| 1497 DCHECK_NULL(args[0]); | 1497 DCHECK_NULL(args[0]); |
| 1498 | 1498 |
| 1499 // Add code object as constant. | 1499 // Add code object as constant. |
| 1500 args[0] = Constant(module_->GetFunctionCode(index)); | 1500 args[0] = Constant(module_->GetFunctionCode(index)); |
| 1501 wasm::FunctionSig* sig = module_->GetFunctionSignature(index); | 1501 wasm::FunctionSig* sig = module_->GetFunctionSignature(index); |
| 1502 | 1502 |
| 1503 return BuildWasmCall(sig, args); | 1503 return BuildWasmCall(sig, args); |
| 1504 } | 1504 } |
| 1505 | 1505 |
| 1506 Node* WasmGraphBuilder::CallImport(uint32_t index, Node** args) { |
| 1507 DCHECK_NULL(args[0]); |
| 1508 |
| 1509 // Add code object as constant. |
| 1510 args[0] = Constant(module_->GetImportCode(index)); |
| 1511 wasm::FunctionSig* sig = module_->GetFunctionSignature(index); |
| 1512 |
| 1513 return BuildWasmCall(sig, args); |
| 1514 } |
| 1506 | 1515 |
| 1507 Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args) { | 1516 Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args) { |
| 1508 DCHECK_NOT_NULL(args[0]); | 1517 DCHECK_NOT_NULL(args[0]); |
| 1509 DCHECK(module_ && module_->instance); | 1518 DCHECK(module_ && module_->instance); |
| 1510 | 1519 |
| 1511 MachineOperatorBuilder* machine = jsgraph()->machine(); | 1520 MachineOperatorBuilder* machine = jsgraph()->machine(); |
| 1512 | 1521 |
| 1513 // Compute the code object by loading it from the function table. | 1522 // Compute the code object by loading it from the function table. |
| 1514 Node* key = args[0]; | 1523 Node* key = args[0]; |
| 1515 | 1524 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2009 Handle<Code> code = | 2018 Handle<Code> code = |
| 2010 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 2019 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
| 2011 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "js-to-wasm", index, | 2020 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "js-to-wasm", index, |
| 2012 module->module->GetName(func->name_offset)); | 2021 module->module->GetName(func->name_offset)); |
| 2013 // Set the JSFunction's machine code. | 2022 // Set the JSFunction's machine code. |
| 2014 function->set_code(*code); | 2023 function->set_code(*code); |
| 2015 } | 2024 } |
| 2016 return function; | 2025 return function; |
| 2017 } | 2026 } |
| 2018 | 2027 |
| 2019 | |
| 2020 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module, | 2028 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module, |
| 2021 Handle<JSFunction> function, | 2029 Handle<JSFunction> function, |
| 2022 uint32_t index) { | 2030 wasm::FunctionSig* sig, const char* name) { |
| 2023 wasm::WasmFunction* func = &module->module->functions->at(index); | |
| 2024 | |
| 2025 //---------------------------------------------------------------------------- | 2031 //---------------------------------------------------------------------------- |
| 2026 // Create the Graph | 2032 // Create the Graph |
| 2027 //---------------------------------------------------------------------------- | 2033 //---------------------------------------------------------------------------- |
| 2028 Zone zone; | 2034 Zone zone; |
| 2029 Graph graph(&zone); | 2035 Graph graph(&zone); |
| 2030 CommonOperatorBuilder common(&zone); | 2036 CommonOperatorBuilder common(&zone); |
| 2031 JSOperatorBuilder javascript(&zone); | 2037 JSOperatorBuilder javascript(&zone); |
| 2032 MachineOperatorBuilder machine(&zone); | 2038 MachineOperatorBuilder machine(&zone); |
| 2033 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); | 2039 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); |
| 2034 | 2040 |
| 2035 Node* control = nullptr; | 2041 Node* control = nullptr; |
| 2036 Node* effect = nullptr; | 2042 Node* effect = nullptr; |
| 2037 | 2043 |
| 2038 WasmGraphBuilder builder(&zone, &jsgraph, func->sig); | 2044 WasmGraphBuilder builder(&zone, &jsgraph, sig); |
| 2039 builder.set_control_ptr(&control); | 2045 builder.set_control_ptr(&control); |
| 2040 builder.set_effect_ptr(&effect); | 2046 builder.set_effect_ptr(&effect); |
| 2041 builder.set_module(module); | 2047 builder.set_module(module); |
| 2042 builder.BuildWasmToJSWrapper(function, func->sig); | 2048 builder.BuildWasmToJSWrapper(function, sig); |
| 2043 | 2049 |
| 2044 Handle<Code> code = Handle<Code>::null(); | 2050 Handle<Code> code = Handle<Code>::null(); |
| 2045 { | 2051 { |
| 2046 // Changes lowering requires types. | 2052 // Changes lowering requires types. |
| 2047 Typer typer(isolate, &graph); | 2053 Typer typer(isolate, &graph); |
| 2048 NodeVector roots(&zone); | 2054 NodeVector roots(&zone); |
| 2049 jsgraph.GetCachedNodes(&roots); | 2055 jsgraph.GetCachedNodes(&roots); |
| 2050 typer.Run(roots); | 2056 typer.Run(roots); |
| 2051 | 2057 |
| 2052 // Run generic and change lowering. | 2058 // Run generic and change lowering. |
| 2053 JSGenericLowering generic(true, &jsgraph); | 2059 JSGenericLowering generic(true, &jsgraph); |
| 2054 ChangeLowering changes(&jsgraph); | 2060 ChangeLowering changes(&jsgraph); |
| 2055 GraphReducer graph_reducer(&zone, &graph, jsgraph.Dead()); | 2061 GraphReducer graph_reducer(&zone, &graph, jsgraph.Dead()); |
| 2056 graph_reducer.AddReducer(&changes); | 2062 graph_reducer.AddReducer(&changes); |
| 2057 graph_reducer.AddReducer(&generic); | 2063 graph_reducer.AddReducer(&generic); |
| 2058 graph_reducer.ReduceGraph(); | 2064 graph_reducer.ReduceGraph(); |
| 2059 | 2065 |
| 2060 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | 2066 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
| 2061 OFStream os(stdout); | 2067 OFStream os(stdout); |
| 2062 os << "-- Graph after change lowering -- " << std::endl; | 2068 os << "-- Graph after change lowering -- " << std::endl; |
| 2063 os << AsRPO(graph); | 2069 os << AsRPO(graph); |
| 2064 } | 2070 } |
| 2065 | 2071 |
| 2066 // Schedule and compile to machine code. | 2072 // Schedule and compile to machine code. |
| 2067 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, func->sig); | 2073 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, sig); |
| 2068 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. | 2074 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. |
| 2069 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 2075 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 2070 CompilationInfo info("wasm-to-js", isolate, &zone, flags); | 2076 CompilationInfo info("wasm-to-js", isolate, &zone, flags); |
| 2071 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 2077 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
| 2072 | 2078 |
| 2073 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", index, | 2079 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", 0, |
| 2074 module->module->GetName(func->name_offset)); | 2080 name); |
| 2075 } | 2081 } |
| 2076 return code; | 2082 return code; |
| 2077 } | 2083 } |
| 2078 | 2084 |
| 2079 | 2085 |
| 2080 // Helper function to compile a single function. | 2086 // Helper function to compile a single function. |
| 2081 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, | 2087 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, |
| 2082 wasm::ModuleEnv* module_env, | 2088 wasm::ModuleEnv* module_env, |
| 2083 const wasm::WasmFunction& function) { | 2089 const wasm::WasmFunction& function) { |
| 2084 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { | 2090 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2158 module_env->module->GetName(function.name_offset)); | 2164 module_env->module->GetName(function.name_offset)); |
| 2159 } | 2165 } |
| 2160 | 2166 |
| 2161 return code; | 2167 return code; |
| 2162 } | 2168 } |
| 2163 | 2169 |
| 2164 | 2170 |
| 2165 } // namespace compiler | 2171 } // namespace compiler |
| 2166 } // namespace internal | 2172 } // namespace internal |
| 2167 } // namespace v8 | 2173 } // namespace v8 |
| OLD | NEW |