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/assembler-inl.h" | 9 #include "src/assembler-inl.h" |
10 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
(...skipping 2793 matching lines...) Loading... | |
2804 } | 2804 } |
2805 | 2805 |
2806 // The return value is also passed via this buffer: | 2806 // The return value is also passed via this buffer: |
2807 DCHECK_GE(wasm::kV8MaxWasmFunctionReturns, sig->return_count()); | 2807 DCHECK_GE(wasm::kV8MaxWasmFunctionReturns, sig->return_count()); |
2808 // TODO(wasm): Handle multi-value returns. | 2808 // TODO(wasm): Handle multi-value returns. |
2809 DCHECK_EQ(1, wasm::kV8MaxWasmFunctionReturns); | 2809 DCHECK_EQ(1, wasm::kV8MaxWasmFunctionReturns); |
2810 int return_size_bytes = | 2810 int return_size_bytes = |
2811 sig->return_count() == 0 ? 0 : 1 << ElementSizeLog2Of(sig->GetReturn(0)); | 2811 sig->return_count() == 0 ? 0 : 1 << ElementSizeLog2Of(sig->GetReturn(0)); |
2812 | 2812 |
2813 // Get a stack slot for the arguments. | 2813 // Get a stack slot for the arguments. |
2814 Node* arg_buffer = args_size_bytes == 0 && return_size_bytes == 0 | 2814 Node* arg_buffer = |
2815 ? jsgraph()->IntPtrConstant(0) | 2815 args_size_bytes == 0 && return_size_bytes == 0 |
2816 : graph()->NewNode(jsgraph()->machine()->StackSlot( | 2816 ? jsgraph()->IntPtrConstant(0) |
2817 std::max(args_size_bytes, return_size_bytes))); | 2817 : graph()->NewNode(jsgraph()->machine()->StackSlot( |
2818 std::max(args_size_bytes, return_size_bytes), 8)); | |
2818 | 2819 |
2819 // Now store all our arguments to the buffer. | 2820 // Now store all our arguments to the buffer. |
2820 int param_index = 0; | 2821 int param_index = 0; |
2821 int offset = 0; | 2822 int offset = 0; |
2822 | 2823 |
2823 for (int i = 0; i < wasm_count; i++) { | 2824 for (int i = 0; i < wasm_count; i++) { |
2824 Node* param = Param(param_index++); | 2825 Node* param = Param(param_index++); |
2825 if (Int64Lowering::IsI64AsTwoParameters(jsgraph()->machine(), | 2826 if (Int64Lowering::IsI64AsTwoParameters(jsgraph()->machine(), |
2826 sig->GetParam(i))) { | 2827 sig->GetParam(i))) { |
2827 StoreRepresentation store_rep(wasm::kWasmI32, | 2828 int alignment = offset % (1 << ElementSizeLog2Of(wasm::kWasmI32)); |
2828 WriteBarrierKind::kNoWriteBarrier); | 2829 bool offset_aligned = (alignment == 0); |
2829 *effect_ = | |
2830 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer, | |
2831 Int32Constant(offset + kInt64LowerHalfMemoryOffset), | |
2832 param, *effect_, *control_); | |
2833 | 2830 |
2834 param = Param(param_index++); | 2831 if (offset_aligned || |
Clemens Hammacher
2017/05/23 12:35:12
You introduce lots of code duplication here.
Pleas
ivica.bogosavljevic
2017/05/23 13:54:40
I like this approach better, consider it done
| |
2835 *effect_ = | 2832 jsgraph()->machine()->UnalignedStoreSupported( |
2836 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer, | 2833 MachineType::TypeForRepresentation(wasm::kWasmI32), 0)) { |
2837 Int32Constant(offset + kInt64UpperHalfMemoryOffset), | 2834 StoreRepresentation store_rep(wasm::kWasmI32, |
2838 param, *effect_, *control_); | 2835 WriteBarrierKind::kNoWriteBarrier); |
2836 | |
2837 *effect_ = graph()->NewNode( | |
2838 jsgraph()->machine()->Store(store_rep), arg_buffer, | |
2839 Int32Constant(offset + kInt64LowerHalfMemoryOffset), param, | |
2840 *effect_, *control_); | |
2841 | |
2842 param = Param(param_index++); | |
2843 *effect_ = graph()->NewNode( | |
2844 jsgraph()->machine()->Store(store_rep), arg_buffer, | |
2845 Int32Constant(offset + kInt64UpperHalfMemoryOffset), param, | |
2846 *effect_, *control_); | |
2847 } else { | |
2848 UnalignedStoreRepresentation store_rep(wasm::kWasmI32); | |
2849 | |
2850 *effect_ = graph()->NewNode( | |
2851 jsgraph()->machine()->UnalignedStore(store_rep), arg_buffer, | |
2852 Int32Constant(offset + kInt64LowerHalfMemoryOffset), param, | |
2853 *effect_, *control_); | |
2854 | |
2855 param = Param(param_index++); | |
2856 *effect_ = graph()->NewNode( | |
2857 jsgraph()->machine()->UnalignedStore(store_rep), arg_buffer, | |
2858 Int32Constant(offset + kInt64UpperHalfMemoryOffset), param, | |
2859 *effect_, *control_); | |
2860 } | |
2839 offset += 8; | 2861 offset += 8; |
2840 | 2862 |
2841 } else { | 2863 } else { |
2842 MachineRepresentation param_rep = sig->GetParam(i); | 2864 MachineRepresentation param_rep = sig->GetParam(i); |
2843 StoreRepresentation store_rep(param_rep, | 2865 int alignment = offset % (1 << ElementSizeLog2Of(param_rep)); |
2844 WriteBarrierKind::kNoWriteBarrier); | 2866 bool offset_aligned = (alignment == 0); |
2845 *effect_ = | 2867 |
2846 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer, | 2868 if (offset_aligned || |
2847 Int32Constant(offset), param, *effect_, *control_); | 2869 jsgraph()->machine()->UnalignedStoreSupported( |
2870 MachineType::TypeForRepresentation(param_rep), 0)) { | |
2871 StoreRepresentation store_rep(param_rep, | |
2872 WriteBarrierKind::kNoWriteBarrier); | |
2873 *effect_ = | |
2874 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer, | |
2875 Int32Constant(offset), param, *effect_, *control_); | |
2876 | |
2877 } else { | |
2878 UnalignedStoreRepresentation store_rep(param_rep); | |
2879 *effect_ = graph()->NewNode( | |
2880 jsgraph()->machine()->UnalignedStore(store_rep), arg_buffer, | |
2881 Int32Constant(offset), param, *effect_, *control_); | |
2882 } | |
2848 offset += 1 << ElementSizeLog2Of(param_rep); | 2883 offset += 1 << ElementSizeLog2Of(param_rep); |
2849 } | 2884 } |
2850 } | 2885 } |
2851 DCHECK_EQ(param_count, param_index); | 2886 DCHECK_EQ(param_count, param_index); |
2852 DCHECK_EQ(args_size_bytes, offset); | 2887 DCHECK_EQ(args_size_bytes, offset); |
2853 | 2888 |
2854 // We are passing the raw arg_buffer here. To the GC and other parts, it looks | 2889 // We are passing the raw arg_buffer here. To the GC and other parts, it looks |
2855 // like a Smi (lowest bit not set). In the runtime function however, don't | 2890 // like a Smi (lowest bit not set). In the runtime function however, don't |
2856 // call Smi::value on it, but just cast it to a byte pointer. | 2891 // call Smi::value on it, but just cast it to a byte pointer. |
2857 Node* parameters[] = { | 2892 Node* parameters[] = { |
(...skipping 976 matching lines...) Loading... | |
3834 | 3869 |
3835 Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index, | 3870 Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index, |
3836 wasm::FunctionSig* sig, | 3871 wasm::FunctionSig* sig, |
3837 Handle<WasmInstanceObject> instance) { | 3872 Handle<WasmInstanceObject> instance) { |
3838 //---------------------------------------------------------------------------- | 3873 //---------------------------------------------------------------------------- |
3839 // Create the Graph | 3874 // Create the Graph |
3840 //---------------------------------------------------------------------------- | 3875 //---------------------------------------------------------------------------- |
3841 Zone zone(isolate->allocator(), ZONE_NAME); | 3876 Zone zone(isolate->allocator(), ZONE_NAME); |
3842 Graph graph(&zone); | 3877 Graph graph(&zone); |
3843 CommonOperatorBuilder common(&zone); | 3878 CommonOperatorBuilder common(&zone); |
3844 MachineOperatorBuilder machine(&zone); | 3879 MachineOperatorBuilder machine( |
3880 &zone, MachineType::PointerRepresentation(), | |
3881 InstructionSelector::SupportedMachineOperatorFlags(), | |
3882 InstructionSelector::AlignmentRequirements()); | |
3845 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 3883 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
3846 | 3884 |
3847 Node* control = nullptr; | 3885 Node* control = nullptr; |
3848 Node* effect = nullptr; | 3886 Node* effect = nullptr; |
3849 | 3887 |
3850 WasmGraphBuilder builder(nullptr, &zone, &jsgraph, sig); | 3888 WasmGraphBuilder builder(nullptr, &zone, &jsgraph, sig); |
3851 builder.set_control_ptr(&control); | 3889 builder.set_control_ptr(&control); |
3852 builder.set_effect_ptr(&effect); | 3890 builder.set_effect_ptr(&effect); |
3853 builder.BuildWasmInterpreterEntry(func_index, sig, instance); | 3891 builder.BuildWasmInterpreterEntry(func_index, sig, instance); |
3854 | 3892 |
(...skipping 273 matching lines...) Loading... | |
4128 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { | 4166 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { |
4129 WasmCompilationUnit unit(isolate, module_env, function); | 4167 WasmCompilationUnit unit(isolate, module_env, function); |
4130 unit.InitializeHandles(); | 4168 unit.InitializeHandles(); |
4131 unit.ExecuteCompilation(); | 4169 unit.ExecuteCompilation(); |
4132 return unit.FinishCompilation(thrower); | 4170 return unit.FinishCompilation(thrower); |
4133 } | 4171 } |
4134 | 4172 |
4135 } // namespace compiler | 4173 } // namespace compiler |
4136 } // namespace internal | 4174 } // namespace internal |
4137 } // namespace v8 | 4175 } // namespace v8 |
OLD | NEW |