| 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 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 const size_t count = 1 + params + extra; | 1478 const size_t count = 1 + params + extra; |
| 1479 | 1479 |
| 1480 // Reallocate the buffer to make space for extra inputs. | 1480 // Reallocate the buffer to make space for extra inputs. |
| 1481 args = Realloc(args, count); | 1481 args = Realloc(args, count); |
| 1482 | 1482 |
| 1483 // Add effect and control inputs. | 1483 // Add effect and control inputs. |
| 1484 args[params + 1] = *effect_; | 1484 args[params + 1] = *effect_; |
| 1485 args[params + 2] = *control_; | 1485 args[params + 2] = *control_; |
| 1486 | 1486 |
| 1487 CallDescriptor* descriptor = | 1487 CallDescriptor* descriptor = |
| 1488 module_->GetWasmCallDescriptor(jsgraph()->zone(), sig); | 1488 wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig); |
| 1489 const Operator* op = jsgraph()->common()->Call(descriptor); | 1489 const Operator* op = jsgraph()->common()->Call(descriptor); |
| 1490 Node* call = graph()->NewNode(op, static_cast<int>(count), args); | 1490 Node* call = graph()->NewNode(op, static_cast<int>(count), args); |
| 1491 | 1491 |
| 1492 *effect_ = call; | 1492 *effect_ = call; |
| 1493 return call; | 1493 return call; |
| 1494 } | 1494 } |
| 1495 | 1495 |
| 1496 | 1496 |
| 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]); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 // Convert JS parameters to WASM numbers. | 1666 // Convert JS parameters to WASM numbers. |
| 1667 for (int i = 0; i < params; i++) { | 1667 for (int i = 0; i < params; i++) { |
| 1668 Node* param = graph()->NewNode(jsgraph()->common()->Parameter(i), start); | 1668 Node* param = graph()->NewNode(jsgraph()->common()->Parameter(i), start); |
| 1669 args[pos++] = FromJS(param, context, sig->GetParam(i)); | 1669 args[pos++] = FromJS(param, context, sig->GetParam(i)); |
| 1670 } | 1670 } |
| 1671 | 1671 |
| 1672 args[pos++] = *effect_; | 1672 args[pos++] = *effect_; |
| 1673 args[pos++] = *control_; | 1673 args[pos++] = *control_; |
| 1674 | 1674 |
| 1675 // Call the WASM code. | 1675 // Call the WASM code. |
| 1676 CallDescriptor* desc = module_->GetWasmCallDescriptor(jsgraph()->zone(), sig); | 1676 CallDescriptor* desc = |
| 1677 wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig); |
| 1677 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); | 1678 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); |
| 1678 Node* jsval = | 1679 Node* jsval = |
| 1679 ToJS(call, context, | 1680 ToJS(call, context, |
| 1680 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); | 1681 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); |
| 1681 Node* ret = | 1682 Node* ret = |
| 1682 graph()->NewNode(jsgraph()->common()->Return(), jsval, call, start); | 1683 graph()->NewNode(jsgraph()->common()->Return(), jsval, call, start); |
| 1683 | 1684 |
| 1684 MergeControlToEnd(jsgraph(), ret); | 1685 MergeControlToEnd(jsgraph(), ret); |
| 1685 } | 1686 } |
| 1686 | 1687 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2085 graph_reducer.AddReducer(&generic); | 2086 graph_reducer.AddReducer(&generic); |
| 2086 graph_reducer.ReduceGraph(); | 2087 graph_reducer.ReduceGraph(); |
| 2087 | 2088 |
| 2088 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | 2089 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
| 2089 OFStream os(stdout); | 2090 OFStream os(stdout); |
| 2090 os << "-- Graph after change lowering -- " << std::endl; | 2091 os << "-- Graph after change lowering -- " << std::endl; |
| 2091 os << AsRPO(graph); | 2092 os << AsRPO(graph); |
| 2092 } | 2093 } |
| 2093 | 2094 |
| 2094 // Schedule and compile to machine code. | 2095 // Schedule and compile to machine code. |
| 2095 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, sig); | 2096 CallDescriptor* incoming = |
| 2097 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, sig); |
| 2096 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. | 2098 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. |
| 2097 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 2099 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 2098 bool debugging = | 2100 bool debugging = |
| 2099 #if DEBUG | 2101 #if DEBUG |
| 2100 true; | 2102 true; |
| 2101 #else | 2103 #else |
| 2102 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; | 2104 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; |
| 2103 #endif | 2105 #endif |
| 2104 const char* func_name = "wasm-to-js"; | 2106 const char* func_name = "wasm-to-js"; |
| 2105 static unsigned id = 0; | 2107 static unsigned id = 0; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2167 ScopedVector<char> buffer(128); | 2169 ScopedVector<char> buffer(128); |
| 2168 SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", | 2170 SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", |
| 2169 function.func_index, | 2171 function.func_index, |
| 2170 module_env->module->GetName(function.name_offset)); | 2172 module_env->module->GetName(function.name_offset)); |
| 2171 thrower.Failed(buffer.start(), result); | 2173 thrower.Failed(buffer.start(), result); |
| 2172 return Handle<Code>::null(); | 2174 return Handle<Code>::null(); |
| 2173 } | 2175 } |
| 2174 | 2176 |
| 2175 // Run the compiler pipeline to generate machine code. | 2177 // Run the compiler pipeline to generate machine code. |
| 2176 CallDescriptor* descriptor = | 2178 CallDescriptor* descriptor = |
| 2177 module_env->GetWasmCallDescriptor(&zone, function.sig); | 2179 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig); |
| 2178 if (kPointerSize == 4) { | 2180 if (kPointerSize == 4) { |
| 2179 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor); | 2181 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor); |
| 2180 } | 2182 } |
| 2181 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 2183 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 2182 // add flags here if a meaningful name is helpful for debugging. | 2184 // add flags here if a meaningful name is helpful for debugging. |
| 2183 bool debugging = | 2185 bool debugging = |
| 2184 #if DEBUG | 2186 #if DEBUG |
| 2185 true; | 2187 true; |
| 2186 #else | 2188 #else |
| 2187 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; | 2189 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2207 module_env->module->GetName(function.name_offset)); | 2209 module_env->module->GetName(function.name_offset)); |
| 2208 } | 2210 } |
| 2209 | 2211 |
| 2210 return code; | 2212 return code; |
| 2211 } | 2213 } |
| 2212 | 2214 |
| 2213 | 2215 |
| 2214 } // namespace compiler | 2216 } // namespace compiler |
| 2215 } // namespace internal | 2217 } // namespace internal |
| 2216 } // namespace v8 | 2218 } // namespace v8 |
| OLD | NEW |