Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 60 |
| 61 void MergeControlToEnd(JSGraph* jsgraph, Node* node) { | 61 void MergeControlToEnd(JSGraph* jsgraph, Node* node) { |
| 62 Graph* g = jsgraph->graph(); | 62 Graph* g = jsgraph->graph(); |
| 63 if (g->end()) { | 63 if (g->end()) { |
| 64 NodeProperties::MergeControlToEnd(g, jsgraph->common(), node); | 64 NodeProperties::MergeControlToEnd(g, jsgraph->common(), node); |
| 65 } else { | 65 } else { |
| 66 g->SetEnd(g->NewNode(jsgraph->common()->End(1), node)); | 66 g->SetEnd(g->NewNode(jsgraph->common()->End(1), node)); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 Node* BuildCallToRuntime(Runtime::FunctionId f, JSGraph* jsgraph, | 70 // Do only call this function for code which is not reused across |
|
titzer
2017/02/24 09:06:06
s/Do only/Only/
Clemens Hammacher
2017/02/24 10:00:40
Done.
| |
| 71 Handle<Context> context, Node** parameters, | 71 // instantiations, as we do not patch the embedded context. |
| 72 int parameter_count, Node** effect_ptr, | 72 Node* BuildCallToRuntimeWithContext(Runtime::FunctionId f, JSGraph* jsgraph, |
| 73 Node* control) { | 73 Node* context, Node** parameters, |
| 74 int parameter_count, Node** effect_ptr, | |
| 75 Node* control) { | |
| 74 const Runtime::Function* fun = Runtime::FunctionForId(f); | 76 const Runtime::Function* fun = Runtime::FunctionForId(f); |
| 75 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 77 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| 76 jsgraph->zone(), f, fun->nargs, Operator::kNoProperties, | 78 jsgraph->zone(), f, fun->nargs, Operator::kNoProperties, |
| 77 CallDescriptor::kNoFlags); | 79 CallDescriptor::kNoFlags); |
| 78 // CEntryStubConstant nodes have to be created and cached in the main | 80 // CEntryStubConstant nodes have to be created and cached in the main |
| 79 // thread. At the moment this is only done for CEntryStubConstant(1). | 81 // thread. At the moment this is only done for CEntryStubConstant(1). |
| 80 DCHECK_EQ(1, fun->result_size); | 82 DCHECK_EQ(1, fun->result_size); |
| 81 // At the moment we only allow 2 parameters. If more parameters are needed, | 83 // At the moment we only allow 3 parameters. If more parameters are needed, |
| 82 // increase this constant accordingly. | 84 // increase this constant accordingly. |
| 83 static const int kMaxParams = 3; | 85 static const int kMaxParams = 3; |
| 84 DCHECK_GE(kMaxParams, parameter_count); | 86 DCHECK_GE(kMaxParams, parameter_count); |
| 85 Node* inputs[kMaxParams + 6]; | 87 Node* inputs[kMaxParams + 6]; |
| 86 int count = 0; | 88 int count = 0; |
| 87 inputs[count++] = jsgraph->CEntryStubConstant(fun->result_size); | 89 inputs[count++] = jsgraph->CEntryStubConstant(fun->result_size); |
| 88 for (int i = 0; i < parameter_count; i++) { | 90 for (int i = 0; i < parameter_count; i++) { |
| 89 inputs[count++] = parameters[i]; | 91 inputs[count++] = parameters[i]; |
| 90 } | 92 } |
| 91 inputs[count++] = jsgraph->ExternalConstant( | 93 inputs[count++] = jsgraph->ExternalConstant( |
| 92 ExternalReference(f, jsgraph->isolate())); // ref | 94 ExternalReference(f, jsgraph->isolate())); // ref |
| 93 inputs[count++] = jsgraph->Int32Constant(fun->nargs); // arity | 95 inputs[count++] = jsgraph->Int32Constant(fun->nargs); // arity |
| 94 inputs[count++] = context.is_null() | 96 inputs[count++] = context; // context |
| 95 ? jsgraph->SmiConstant(0) | |
| 96 : jsgraph->HeapConstant(context); // context | |
| 97 inputs[count++] = *effect_ptr; | 97 inputs[count++] = *effect_ptr; |
| 98 inputs[count++] = control; | 98 inputs[count++] = control; |
| 99 | 99 |
| 100 Node* node = | 100 Node* node = |
| 101 jsgraph->graph()->NewNode(jsgraph->common()->Call(desc), count, inputs); | 101 jsgraph->graph()->NewNode(jsgraph->common()->Call(desc), count, inputs); |
| 102 *effect_ptr = node; | 102 *effect_ptr = node; |
| 103 return node; | 103 return node; |
| 104 } | 104 } |
| 105 | 105 |
| 106 Node* BuildCallToRuntime(Runtime::FunctionId f, JSGraph* jsgraph, | |
| 107 Node** parameters, int parameter_count, | |
| 108 Node** effect_ptr, Node* control) { | |
| 109 return BuildCallToRuntimeWithContext(f, jsgraph, jsgraph->NoContextConstant(), | |
| 110 parameters, parameter_count, effect_ptr, | |
| 111 control); | |
| 112 } | |
| 113 | |
| 106 } // namespace | 114 } // namespace |
| 107 | 115 |
| 108 // TODO(eholk): Support trap handlers on other platforms. | 116 // TODO(eholk): Support trap handlers on other platforms. |
| 109 #if V8_TARGET_ARCH_X64 && V8_OS_LINUX | 117 #if V8_TARGET_ARCH_X64 && V8_OS_LINUX |
| 110 const bool kTrapHandlerSupported = true; | 118 const bool kTrapHandlerSupported = true; |
| 111 #else | 119 #else |
| 112 const bool kTrapHandlerSupported = false; | 120 const bool kTrapHandlerSupported = false; |
| 113 #endif | 121 #endif |
| 114 | 122 |
| 115 // A helper that handles building graph fragments for trapping. | 123 // A helper that handles building graph fragments for trapping. |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 trap_position_ = | 330 trap_position_ = |
| 323 graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 1), | 331 graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 1), |
| 324 position_node, *control_ptr); | 332 position_node, *control_ptr); |
| 325 | 333 |
| 326 Node* trap_reason_smi = builder_->BuildChangeInt32ToSmi(trap_reason_); | 334 Node* trap_reason_smi = builder_->BuildChangeInt32ToSmi(trap_reason_); |
| 327 Node* trap_position_smi = builder_->BuildChangeInt32ToSmi(trap_position_); | 335 Node* trap_position_smi = builder_->BuildChangeInt32ToSmi(trap_position_); |
| 328 | 336 |
| 329 if (module && !module->instance->context.is_null()) { | 337 if (module && !module->instance->context.is_null()) { |
| 330 Node* parameters[] = {trap_reason_smi, // message id | 338 Node* parameters[] = {trap_reason_smi, // message id |
| 331 trap_position_smi}; // byte position | 339 trap_position_smi}; // byte position |
| 332 BuildCallToRuntime(Runtime::kThrowWasmError, jsgraph(), | 340 BuildCallToRuntime(Runtime::kThrowWasmError, jsgraph(), parameters, |
| 333 Handle<Context>::null(), parameters, | |
| 334 arraysize(parameters), effect_ptr, *control_ptr); | 341 arraysize(parameters), effect_ptr, *control_ptr); |
| 335 } | 342 } |
| 336 if (false) { | 343 if (false) { |
| 337 // End the control flow with a throw | 344 // End the control flow with a throw |
| 338 Node* thrw = | 345 Node* thrw = |
| 339 graph()->NewNode(common()->Throw(), jsgraph()->ZeroConstant(), | 346 graph()->NewNode(common()->Throw(), jsgraph()->ZeroConstant(), |
| 340 *effect_ptr, *control_ptr); | 347 *effect_ptr, *control_ptr); |
| 341 MergeControlToEnd(jsgraph(), thrw); | 348 MergeControlToEnd(jsgraph(), thrw); |
| 342 } else { | 349 } else { |
| 343 // End the control flow with returning 0xdeadbeef | 350 // End the control flow with returning 0xdeadbeef |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 Node* effect_true = *effect; | 501 Node* effect_true = *effect; |
| 495 | 502 |
| 496 Handle<Code> code = jsgraph()->isolate()->builtins()->WasmStackGuard(); | 503 Handle<Code> code = jsgraph()->isolate()->builtins()->WasmStackGuard(); |
| 497 CallInterfaceDescriptor idesc = | 504 CallInterfaceDescriptor idesc = |
| 498 WasmStackGuardDescriptor(jsgraph()->isolate()); | 505 WasmStackGuardDescriptor(jsgraph()->isolate()); |
| 499 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 506 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 500 jsgraph()->isolate(), jsgraph()->zone(), idesc, 0, | 507 jsgraph()->isolate(), jsgraph()->zone(), idesc, 0, |
| 501 CallDescriptor::kNoFlags, Operator::kNoProperties); | 508 CallDescriptor::kNoFlags, Operator::kNoProperties); |
| 502 Node* stub_code = jsgraph()->HeapConstant(code); | 509 Node* stub_code = jsgraph()->HeapConstant(code); |
| 503 | 510 |
| 504 Node* context = jsgraph()->SmiConstant(0); | 511 Node* context = jsgraph()->NoContextConstant(); |
| 505 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, | 512 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, |
| 506 context, *effect, stack_check.if_false); | 513 context, *effect, stack_check.if_false); |
| 507 | 514 |
| 508 SetSourcePosition(call, position); | 515 SetSourcePosition(call, position); |
| 509 | 516 |
| 510 Node* ephi = graph()->NewNode(jsgraph()->common()->EffectPhi(2), effect_true, | 517 Node* ephi = graph()->NewNode(jsgraph()->common()->EffectPhi(2), effect_true, |
| 511 call, stack_check.merge); | 518 call, stack_check.merge); |
| 512 | 519 |
| 513 *control = stack_check.merge; | 520 *control = stack_check.merge; |
| 514 *effect = ephi; | 521 *effect = ephi; |
| (...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1785 | 1792 |
| 1786 Node* WasmGraphBuilder::GrowMemory(Node* input) { | 1793 Node* WasmGraphBuilder::GrowMemory(Node* input) { |
| 1787 Diamond check_input_range( | 1794 Diamond check_input_range( |
| 1788 graph(), jsgraph()->common(), | 1795 graph(), jsgraph()->common(), |
| 1789 graph()->NewNode(jsgraph()->machine()->Uint32LessThanOrEqual(), input, | 1796 graph()->NewNode(jsgraph()->machine()->Uint32LessThanOrEqual(), input, |
| 1790 jsgraph()->Uint32Constant(FLAG_wasm_max_mem_pages)), | 1797 jsgraph()->Uint32Constant(FLAG_wasm_max_mem_pages)), |
| 1791 BranchHint::kTrue); | 1798 BranchHint::kTrue); |
| 1792 | 1799 |
| 1793 check_input_range.Chain(*control_); | 1800 check_input_range.Chain(*control_); |
| 1794 | 1801 |
| 1795 Runtime::FunctionId function_id = Runtime::kWasmGrowMemory; | 1802 Node* parameters[] = {BuildChangeUint32ToSmi(input)}; |
| 1796 const Runtime::Function* function = Runtime::FunctionForId(function_id); | 1803 Node* old_effect = *effect_; |
| 1797 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 1804 Node* call = BuildCallToRuntime(Runtime::kWasmGrowMemory, jsgraph(), |
| 1798 jsgraph()->zone(), function_id, function->nargs, Operator::kNoThrow, | 1805 parameters, arraysize(parameters), effect_, |
| 1799 CallDescriptor::kNoFlags); | 1806 check_input_range.if_true); |
| 1800 wasm::ModuleEnv* module = module_; | |
| 1801 input = BuildChangeUint32ToSmi(input); | |
| 1802 Node* inputs[] = { | |
| 1803 jsgraph()->CEntryStubConstant(function->result_size), input, // C entry | |
| 1804 jsgraph()->ExternalConstant( | |
| 1805 ExternalReference(function_id, jsgraph()->isolate())), // ref | |
| 1806 jsgraph()->Int32Constant(function->nargs), // arity | |
| 1807 jsgraph()->HeapConstant(module->instance->context), // context | |
| 1808 *effect_, | |
| 1809 check_input_range.if_true}; | |
| 1810 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), | |
| 1811 static_cast<int>(arraysize(inputs)), inputs); | |
| 1812 | 1807 |
| 1813 Node* result = BuildChangeSmiToInt32(call); | 1808 Node* result = BuildChangeSmiToInt32(call); |
| 1814 | 1809 |
| 1815 result = check_input_range.Phi(MachineRepresentation::kWord32, result, | 1810 result = check_input_range.Phi(MachineRepresentation::kWord32, result, |
| 1816 jsgraph()->Int32Constant(-1)); | 1811 jsgraph()->Int32Constant(-1)); |
| 1817 *effect_ = graph()->NewNode(jsgraph()->common()->EffectPhi(2), call, *effect_, | 1812 *effect_ = graph()->NewNode(jsgraph()->common()->EffectPhi(2), call, |
| 1818 check_input_range.merge); | 1813 old_effect, check_input_range.merge); |
| 1819 *control_ = check_input_range.merge; | 1814 *control_ = check_input_range.merge; |
| 1820 return result; | 1815 return result; |
| 1821 } | 1816 } |
| 1822 | 1817 |
| 1823 Node* WasmGraphBuilder::Throw(Node* input) { | 1818 Node* WasmGraphBuilder::Throw(Node* input) { |
| 1824 MachineOperatorBuilder* machine = jsgraph()->machine(); | 1819 MachineOperatorBuilder* machine = jsgraph()->machine(); |
| 1825 | 1820 |
| 1826 // Pass the thrown value as two SMIs: | 1821 // Pass the thrown value as two SMIs: |
| 1827 // | 1822 // |
| 1828 // upper = static_cast<uint32_t>(input) >> 16; | 1823 // upper = static_cast<uint32_t>(input) >> 16; |
| 1829 // lower = input & 0xFFFF; | 1824 // lower = input & 0xFFFF; |
| 1830 // | 1825 // |
| 1831 // This is needed because we can't safely call BuildChangeInt32ToTagged from | 1826 // This is needed because we can't safely call BuildChangeInt32ToTagged from |
| 1832 // this method. | 1827 // this method. |
| 1833 // | 1828 // |
| 1834 // TODO(wasm): figure out how to properly pass this to the runtime function. | 1829 // TODO(wasm): figure out how to properly pass this to the runtime function. |
| 1835 Node* upper = BuildChangeInt32ToSmi( | 1830 Node* upper = BuildChangeInt32ToSmi( |
| 1836 graph()->NewNode(machine->Word32Shr(), input, Int32Constant(16))); | 1831 graph()->NewNode(machine->Word32Shr(), input, Int32Constant(16))); |
| 1837 Node* lower = BuildChangeInt32ToSmi( | 1832 Node* lower = BuildChangeInt32ToSmi( |
| 1838 graph()->NewNode(machine->Word32And(), input, Int32Constant(0xFFFFu))); | 1833 graph()->NewNode(machine->Word32And(), input, Int32Constant(0xFFFFu))); |
| 1839 | 1834 |
| 1840 Node* parameters[] = {lower, upper}; // thrown value | 1835 Node* parameters[] = {lower, upper}; // thrown value |
| 1841 return BuildCallToRuntime(Runtime::kWasmThrow, jsgraph(), | 1836 return BuildCallToRuntime(Runtime::kWasmThrow, jsgraph(), parameters, |
| 1842 module_->instance->context, parameters, | |
| 1843 arraysize(parameters), effect_, *control_); | 1837 arraysize(parameters), effect_, *control_); |
| 1844 } | 1838 } |
| 1845 | 1839 |
| 1846 Node* WasmGraphBuilder::Catch(Node* input, wasm::WasmCodePosition position) { | 1840 Node* WasmGraphBuilder::Catch(Node* input, wasm::WasmCodePosition position) { |
| 1847 CommonOperatorBuilder* common = jsgraph()->common(); | 1841 CommonOperatorBuilder* common = jsgraph()->common(); |
| 1848 | 1842 |
| 1849 Node* parameters[] = {input}; // caught value | 1843 Node* parameters[] = {input}; // caught value |
| 1850 Node* value = | 1844 Node* value = |
| 1851 BuildCallToRuntime(Runtime::kWasmGetCaughtExceptionValue, jsgraph(), | 1845 BuildCallToRuntime(Runtime::kWasmGetCaughtExceptionValue, jsgraph(), |
| 1852 module_->instance->context, parameters, | 1846 parameters, arraysize(parameters), effect_, *control_); |
| 1853 arraysize(parameters), effect_, *control_); | |
| 1854 | 1847 |
| 1855 Node* is_smi; | 1848 Node* is_smi; |
| 1856 Node* is_heap; | 1849 Node* is_heap; |
| 1857 BranchExpectFalse(BuildTestNotSmi(value), &is_heap, &is_smi); | 1850 BranchExpectFalse(BuildTestNotSmi(value), &is_heap, &is_smi); |
| 1858 | 1851 |
| 1859 // is_smi | 1852 // is_smi |
| 1860 Node* smi_i32 = BuildChangeSmiToInt32(value); | 1853 Node* smi_i32 = BuildChangeSmiToInt32(value); |
| 1861 Node* is_smi_effect = *effect_; | 1854 Node* is_smi_effect = *effect_; |
| 1862 | 1855 |
| 1863 // is_heap | 1856 // is_heap |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2764 wasm::FunctionSig* sig) { | 2757 wasm::FunctionSig* sig) { |
| 2765 int wasm_count = static_cast<int>(sig->parameter_count()); | 2758 int wasm_count = static_cast<int>(sig->parameter_count()); |
| 2766 int count = wasm_count + 3; | 2759 int count = wasm_count + 3; |
| 2767 Node** args = Buffer(count); | 2760 Node** args = Buffer(count); |
| 2768 | 2761 |
| 2769 // Build the start and the JS parameter nodes. | 2762 // Build the start and the JS parameter nodes. |
| 2770 Node* start = Start(wasm_count + 5); | 2763 Node* start = Start(wasm_count + 5); |
| 2771 *control_ = start; | 2764 *control_ = start; |
| 2772 *effect_ = start; | 2765 *effect_ = start; |
| 2773 | 2766 |
| 2767 // Create the context parameter | |
| 2768 Node* context = graph()->NewNode( | |
| 2769 jsgraph()->common()->Parameter( | |
| 2770 Linkage::GetJSCallContextParamIndex(wasm_count + 1), "%context"), | |
| 2771 graph()->start()); | |
| 2772 | |
| 2774 if (!HasJSCompatibleSignature(sig_)) { | 2773 if (!HasJSCompatibleSignature(sig_)) { |
| 2775 // Throw a TypeError. The native context is good enough here because we | 2774 // Throw a TypeError. Use the context of the calling javascript function |
| 2776 // only throw a TypeError. | 2775 // (passed as a parameter), such that the generated code is context |
| 2777 BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(), | 2776 // independent. |
| 2778 jsgraph()->isolate()->native_context(), nullptr, 0, | 2777 BuildCallToRuntimeWithContext(Runtime::kWasmThrowTypeError, jsgraph(), |
| 2779 effect_, *control_); | 2778 context, nullptr, 0, effect_, *control_); |
| 2780 | 2779 |
| 2781 // Add a dummy call to the wasm function so that the generated wrapper | 2780 // Add a dummy call to the wasm function so that the generated wrapper |
| 2782 // contains a reference to the wrapped wasm function. Without this reference | 2781 // contains a reference to the wrapped wasm function. Without this reference |
| 2783 // the wasm function could not be re-imported into another wasm module. | 2782 // the wasm function could not be re-imported into another wasm module. |
| 2784 int pos = 0; | 2783 int pos = 0; |
| 2785 args[pos++] = HeapConstant(wasm_code); | 2784 args[pos++] = HeapConstant(wasm_code); |
| 2786 args[pos++] = *effect_; | 2785 args[pos++] = *effect_; |
| 2787 args[pos++] = *control_; | 2786 args[pos++] = *control_; |
| 2788 | 2787 |
| 2789 // We only need a dummy call descriptor. | 2788 // We only need a dummy call descriptor. |
| 2790 wasm::FunctionSig::Builder dummy_sig_builder(jsgraph()->zone(), 0, 0); | 2789 wasm::FunctionSig::Builder dummy_sig_builder(jsgraph()->zone(), 0, 0); |
| 2791 CallDescriptor* desc = wasm::ModuleEnv::GetWasmCallDescriptor( | 2790 CallDescriptor* desc = wasm::ModuleEnv::GetWasmCallDescriptor( |
| 2792 jsgraph()->zone(), dummy_sig_builder.Build()); | 2791 jsgraph()->zone(), dummy_sig_builder.Build()); |
| 2793 *effect_ = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); | 2792 *effect_ = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); |
| 2794 Return(jsgraph()->UndefinedConstant()); | 2793 Return(jsgraph()->UndefinedConstant()); |
| 2795 return; | 2794 return; |
| 2796 } | 2795 } |
| 2797 | 2796 |
| 2798 // Create the context parameter | |
| 2799 Node* context = graph()->NewNode( | |
| 2800 jsgraph()->common()->Parameter( | |
| 2801 Linkage::GetJSCallContextParamIndex(wasm_count + 1), "%context"), | |
| 2802 graph()->start()); | |
| 2803 | |
| 2804 int pos = 0; | 2797 int pos = 0; |
| 2805 args[pos++] = HeapConstant(wasm_code); | 2798 args[pos++] = HeapConstant(wasm_code); |
| 2806 | 2799 |
| 2807 // Convert JS parameters to WASM numbers. | 2800 // Convert JS parameters to WASM numbers. |
| 2808 for (int i = 0; i < wasm_count; ++i) { | 2801 for (int i = 0; i < wasm_count; ++i) { |
| 2809 Node* param = Param(i + 1); | 2802 Node* param = Param(i + 1); |
| 2810 Node* wasm_param = FromJS(param, context, sig->GetParam(i)); | 2803 Node* wasm_param = FromJS(param, context, sig->GetParam(i)); |
| 2811 args[pos++] = wasm_param; | 2804 args[pos++] = wasm_param; |
| 2812 } | 2805 } |
| 2813 | 2806 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2844 int wasm_count = static_cast<int>(sig->parameter_count()); | 2837 int wasm_count = static_cast<int>(sig->parameter_count()); |
| 2845 | 2838 |
| 2846 // Build the start and the parameter nodes. | 2839 // Build the start and the parameter nodes. |
| 2847 Isolate* isolate = jsgraph()->isolate(); | 2840 Isolate* isolate = jsgraph()->isolate(); |
| 2848 CallDescriptor* desc; | 2841 CallDescriptor* desc; |
| 2849 Node* start = Start(wasm_count + 3); | 2842 Node* start = Start(wasm_count + 3); |
| 2850 *effect_ = start; | 2843 *effect_ = start; |
| 2851 *control_ = start; | 2844 *control_ = start; |
| 2852 | 2845 |
| 2853 if (!HasJSCompatibleSignature(sig_)) { | 2846 if (!HasJSCompatibleSignature(sig_)) { |
| 2854 // Throw a TypeError. The native context is good enough here because we | 2847 // Throw a TypeError. Embedding the context is ok here, since this code is |
| 2855 // only throw a TypeError. | 2848 // regenerated at instantiation time. |
| 2856 Return(BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(), | 2849 Node* context = |
| 2857 jsgraph()->isolate()->native_context(), nullptr, | 2850 jsgraph()->HeapConstant(jsgraph()->isolate()->native_context()); |
| 2858 0, effect_, *control_)); | 2851 Return(BuildCallToRuntimeWithContext(Runtime::kWasmThrowTypeError, |
| 2852 jsgraph(), context, nullptr, 0, | |
| 2853 effect_, *control_)); | |
| 2859 return; | 2854 return; |
| 2860 } | 2855 } |
| 2861 | 2856 |
| 2862 Node** args = Buffer(wasm_count + 7); | 2857 Node** args = Buffer(wasm_count + 7); |
| 2863 | 2858 |
| 2864 Node* call; | 2859 Node* call; |
| 2865 bool direct_call = false; | 2860 bool direct_call = false; |
| 2866 | 2861 |
| 2867 if (target->IsJSFunction()) { | 2862 if (target->IsJSFunction()) { |
| 2868 Handle<JSFunction> function = Handle<JSFunction>::cast(target); | 2863 Handle<JSFunction> function = Handle<JSFunction>::cast(target); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3000 DCHECK_EQ(args_size_bytes, offset); | 2995 DCHECK_EQ(args_size_bytes, offset); |
| 3001 | 2996 |
| 3002 // We are passing the raw arg_buffer here. To the GC and other parts, it looks | 2997 // We are passing the raw arg_buffer here. To the GC and other parts, it looks |
| 3003 // like a Smi (lowest bit not set). In the runtime function however, don't | 2998 // like a Smi (lowest bit not set). In the runtime function however, don't |
| 3004 // call Smi::value on it, but just cast it to a byte pointer. | 2999 // call Smi::value on it, but just cast it to a byte pointer. |
| 3005 Node* parameters[] = { | 3000 Node* parameters[] = { |
| 3006 jsgraph()->HeapConstant(instance), // wasm instance | 3001 jsgraph()->HeapConstant(instance), // wasm instance |
| 3007 jsgraph()->SmiConstant(function_index), // function index | 3002 jsgraph()->SmiConstant(function_index), // function index |
| 3008 arg_buffer, // argument buffer | 3003 arg_buffer, // argument buffer |
| 3009 }; | 3004 }; |
| 3010 BuildCallToRuntime(Runtime::kWasmRunInterpreter, jsgraph(), | 3005 BuildCallToRuntime(Runtime::kWasmRunInterpreter, jsgraph(), parameters, |
| 3011 instance->compiled_module()->native_context(), parameters, | |
| 3012 arraysize(parameters), effect_, *control_); | 3006 arraysize(parameters), effect_, *control_); |
| 3013 | 3007 |
| 3014 // Read back the return value. | 3008 // Read back the return value. |
| 3015 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && | 3009 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && |
| 3016 sig->GetReturn() == wasm::kWasmI64) { | 3010 sig->GetReturn() == wasm::kWasmI64) { |
| 3017 MachineType load_rep = wasm::WasmOpcodes::MachineTypeFor(wasm::kWasmI32); | 3011 MachineType load_rep = wasm::WasmOpcodes::MachineTypeFor(wasm::kWasmI32); |
| 3018 Node* lower = | 3012 Node* lower = |
| 3019 graph()->NewNode(jsgraph()->machine()->Load(load_rep), arg_buffer, | 3013 graph()->NewNode(jsgraph()->machine()->Load(load_rep), arg_buffer, |
| 3020 Int32Constant(0), *effect_, *control_); | 3014 Int32Constant(0), *effect_, *control_); |
| 3021 Node* upper = | 3015 Node* upper = |
| (...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4138 function_->code_start_offset), | 4132 function_->code_start_offset), |
| 4139 compile_ms); | 4133 compile_ms); |
| 4140 } | 4134 } |
| 4141 | 4135 |
| 4142 return code; | 4136 return code; |
| 4143 } | 4137 } |
| 4144 | 4138 |
| 4145 } // namespace compiler | 4139 } // namespace compiler |
| 4146 } // namespace internal | 4140 } // namespace internal |
| 4147 } // namespace v8 | 4141 } // namespace v8 |
| OLD | NEW |