| 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 2785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2796 int pos = 0; | 2796 int pos = 0; |
| 2797 args[pos++] = HeapConstant(wasm_code); | 2797 args[pos++] = HeapConstant(wasm_code); |
| 2798 | 2798 |
| 2799 // Convert JS parameters to WASM numbers. | 2799 // Convert JS parameters to WASM numbers. |
| 2800 for (int i = 0; i < wasm_count; ++i) { | 2800 for (int i = 0; i < wasm_count; ++i) { |
| 2801 Node* param = Param(i + 1); | 2801 Node* param = Param(i + 1); |
| 2802 Node* wasm_param = FromJS(param, context, sig->GetParam(i)); | 2802 Node* wasm_param = FromJS(param, context, sig->GetParam(i)); |
| 2803 args[pos++] = wasm_param; | 2803 args[pos++] = wasm_param; |
| 2804 } | 2804 } |
| 2805 | 2805 |
| 2806 // Set the ThreadInWasm flag before we do the actual call. |
| 2807 if (trap_handler::EnableTrapHandler()) { |
| 2808 BuildCallToRuntime(Runtime::kSetThreadInWasm, jsgraph(), |
| 2809 jsgraph()->isolate()->native_context(), nullptr, 0, |
| 2810 effect_, *control_); |
| 2811 } |
| 2812 |
| 2806 args[pos++] = *effect_; | 2813 args[pos++] = *effect_; |
| 2807 args[pos++] = *control_; | 2814 args[pos++] = *control_; |
| 2808 | 2815 |
| 2809 // Call the WASM code. | 2816 // Call the WASM code. |
| 2810 CallDescriptor* desc = | 2817 CallDescriptor* desc = |
| 2811 wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig); | 2818 wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig); |
| 2812 | 2819 |
| 2813 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); | 2820 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); |
| 2814 *effect_ = call; | 2821 *effect_ = call; |
| 2822 |
| 2823 // Clear the ThreadInWasmFlag |
| 2824 if (trap_handler::EnableTrapHandler()) { |
| 2825 BuildCallToRuntime(Runtime::kClearThreadInWasm, jsgraph(), |
| 2826 jsgraph()->isolate()->native_context(), nullptr, 0, |
| 2827 effect_, *control_); |
| 2828 } |
| 2829 |
| 2815 Node* retval = call; | 2830 Node* retval = call; |
| 2816 Node* jsval = ToJS( | 2831 Node* jsval = ToJS( |
| 2817 retval, sig->return_count() == 0 ? wasm::kWasmStmt : sig->GetReturn()); | 2832 retval, sig->return_count() == 0 ? wasm::kWasmStmt : sig->GetReturn()); |
| 2818 Return(jsval); | 2833 Return(jsval); |
| 2819 } | 2834 } |
| 2820 | 2835 |
| 2821 int WasmGraphBuilder::AddParameterNodes(Node** args, int pos, int param_count, | 2836 int WasmGraphBuilder::AddParameterNodes(Node** args, int pos, int param_count, |
| 2822 wasm::FunctionSig* sig) { | 2837 wasm::FunctionSig* sig) { |
| 2823 // Convert WASM numbers to JS values. | 2838 // Convert WASM numbers to JS values. |
| 2824 int param_index = 0; | 2839 int param_index = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2849 jsgraph()->isolate()->native_context(), nullptr, | 2864 jsgraph()->isolate()->native_context(), nullptr, |
| 2850 0, effect_, *control_)); | 2865 0, effect_, *control_)); |
| 2851 return; | 2866 return; |
| 2852 } | 2867 } |
| 2853 | 2868 |
| 2854 Node** args = Buffer(wasm_count + 7); | 2869 Node** args = Buffer(wasm_count + 7); |
| 2855 | 2870 |
| 2856 Node* call; | 2871 Node* call; |
| 2857 bool direct_call = false; | 2872 bool direct_call = false; |
| 2858 | 2873 |
| 2874 if (trap_handler::EnableTrapHandler()) { |
| 2875 BuildCallToRuntime(Runtime::kClearThreadInWasm, jsgraph(), |
| 2876 jsgraph()->isolate()->native_context(), nullptr, 0, |
| 2877 effect_, *control_); |
| 2878 } |
| 2879 |
| 2859 if (target->IsJSFunction()) { | 2880 if (target->IsJSFunction()) { |
| 2860 Handle<JSFunction> function = Handle<JSFunction>::cast(target); | 2881 Handle<JSFunction> function = Handle<JSFunction>::cast(target); |
| 2861 if (function->shared()->internal_formal_parameter_count() == wasm_count) { | 2882 if (function->shared()->internal_formal_parameter_count() == wasm_count) { |
| 2862 direct_call = true; | 2883 direct_call = true; |
| 2863 int pos = 0; | 2884 int pos = 0; |
| 2864 args[pos++] = jsgraph()->Constant(target); // target callable. | 2885 args[pos++] = jsgraph()->Constant(target); // target callable. |
| 2865 // Receiver. | 2886 // Receiver. |
| 2866 if (is_sloppy(function->shared()->language_mode()) && | 2887 if (is_sloppy(function->shared()->language_mode()) && |
| 2867 !function->shared()->native()) { | 2888 !function->shared()->native()) { |
| 2868 args[pos++] = | 2889 args[pos++] = |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 args[pos++] = HeapConstant(isolate->native_context()); | 2934 args[pos++] = HeapConstant(isolate->native_context()); |
| 2914 args[pos++] = *effect_; | 2935 args[pos++] = *effect_; |
| 2915 args[pos++] = *control_; | 2936 args[pos++] = *control_; |
| 2916 | 2937 |
| 2917 call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); | 2938 call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); |
| 2918 } | 2939 } |
| 2919 | 2940 |
| 2920 *effect_ = call; | 2941 *effect_ = call; |
| 2921 SetSourcePosition(call, 0); | 2942 SetSourcePosition(call, 0); |
| 2922 | 2943 |
| 2944 if (trap_handler::EnableTrapHandler()) { |
| 2945 BuildCallToRuntime(Runtime::kSetThreadInWasm, jsgraph(), |
| 2946 jsgraph()->isolate()->native_context(), nullptr, 0, |
| 2947 effect_, *control_); |
| 2948 } |
| 2949 |
| 2923 // Convert the return value back. | 2950 // Convert the return value back. |
| 2924 Node* i32_zero = jsgraph()->Int32Constant(0); | 2951 Node* i32_zero = jsgraph()->Int32Constant(0); |
| 2925 Node* val = sig->return_count() == 0 | 2952 Node* val = sig->return_count() == 0 |
| 2926 ? i32_zero | 2953 ? i32_zero |
| 2927 : FromJS(call, HeapConstant(isolate->native_context()), | 2954 : FromJS(call, HeapConstant(isolate->native_context()), |
| 2928 sig->GetReturn()); | 2955 sig->GetReturn()); |
| 2929 Return(val); | 2956 Return(val); |
| 2930 } | 2957 } |
| 2931 | 2958 |
| 2932 void WasmGraphBuilder::BuildWasmInterpreterEntry( | 2959 void WasmGraphBuilder::BuildWasmInterpreterEntry( |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3860 function_->code_start_offset), | 3887 function_->code_start_offset), |
| 3861 compile_ms); | 3888 compile_ms); |
| 3862 } | 3889 } |
| 3863 | 3890 |
| 3864 return code; | 3891 return code; |
| 3865 } | 3892 } |
| 3866 | 3893 |
| 3867 } // namespace compiler | 3894 } // namespace compiler |
| 3868 } // namespace internal | 3895 } // namespace internal |
| 3869 } // namespace v8 | 3896 } // namespace v8 |
| OLD | NEW |