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