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 2782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2793 : Int64Lowering::GetParameterCountAfterLowering(sig); | 2793 : Int64Lowering::GetParameterCountAfterLowering(sig); |
2794 | 2794 |
2795 // Build the start and the parameter nodes. | 2795 // Build the start and the parameter nodes. |
2796 Node* start = Start(param_count + 3); | 2796 Node* start = Start(param_count + 3); |
2797 *effect_ = start; | 2797 *effect_ = start; |
2798 *control_ = start; | 2798 *control_ = start; |
2799 | 2799 |
2800 // Compute size for the argument buffer. | 2800 // Compute size for the argument buffer. |
2801 int args_size_bytes = 0; | 2801 int args_size_bytes = 0; |
2802 for (int i = 0; i < wasm_count; i++) { | 2802 for (int i = 0; i < wasm_count; i++) { |
2803 args_size_bytes += 1 << ElementSizeLog2Of(sig->GetParam(i)); | 2803 args_size_bytes += |
2804 RoundUpToMultipleOfPowOf2(1 << ElementSizeLog2Of(sig->GetParam(i)), 8); | |
2804 } | 2805 } |
2805 | 2806 |
2806 // The return value is also passed via this buffer: | 2807 // The return value is also passed via this buffer: |
2807 DCHECK_GE(wasm::kV8MaxWasmFunctionReturns, sig->return_count()); | 2808 DCHECK_GE(wasm::kV8MaxWasmFunctionReturns, sig->return_count()); |
2808 // TODO(wasm): Handle multi-value returns. | 2809 // TODO(wasm): Handle multi-value returns. |
2809 DCHECK_EQ(1, wasm::kV8MaxWasmFunctionReturns); | 2810 DCHECK_EQ(1, wasm::kV8MaxWasmFunctionReturns); |
2810 int return_size_bytes = | 2811 int return_size_bytes = |
2811 sig->return_count() == 0 ? 0 : 1 << ElementSizeLog2Of(sig->GetReturn(0)); | 2812 sig->return_count() == 0 ? 0 : 1 << ElementSizeLog2Of(sig->GetReturn(0)); |
2812 | 2813 |
2813 // Get a stack slot for the arguments. | 2814 // Get a stack slot for the arguments. |
2814 Node* arg_buffer = args_size_bytes == 0 && return_size_bytes == 0 | 2815 Node* arg_buffer = |
2815 ? jsgraph()->IntPtrConstant(0) | 2816 args_size_bytes == 0 && return_size_bytes == 0 |
2816 : graph()->NewNode(jsgraph()->machine()->StackSlot( | 2817 ? jsgraph()->IntPtrConstant(0) |
2817 std::max(args_size_bytes, return_size_bytes))); | 2818 : graph()->NewNode(jsgraph()->machine()->StackSlot( |
2819 std::max(args_size_bytes, return_size_bytes), 8)); | |
Clemens Hammacher
2017/05/18 11:52:05
Wouldn't this be the only change required?
ivica.bogosavljevic
2017/05/18 12:21:43
Unfortunately no. if you had three parameters, fir
| |
2818 | 2820 |
2819 // Now store all our arguments to the buffer. | 2821 // Now store all our arguments to the buffer. |
2820 int param_index = 0; | 2822 int param_index = 0; |
2821 int offset = 0; | 2823 int offset = 0; |
2822 | 2824 |
2823 for (int i = 0; i < wasm_count; i++) { | 2825 for (int i = 0; i < wasm_count; i++) { |
2824 Node* param = Param(param_index++); | 2826 Node* param = Param(param_index++); |
2825 if (Int64Lowering::IsI64AsTwoParameters(jsgraph()->machine(), | 2827 if (Int64Lowering::IsI64AsTwoParameters(jsgraph()->machine(), |
2826 sig->GetParam(i))) { | 2828 sig->GetParam(i))) { |
2827 StoreRepresentation store_rep(wasm::kWasmI32, | 2829 StoreRepresentation store_rep(wasm::kWasmI32, |
(...skipping 10 matching lines...) Expand all Loading... | |
2838 param, *effect_, *control_); | 2840 param, *effect_, *control_); |
2839 offset += 8; | 2841 offset += 8; |
2840 | 2842 |
2841 } else { | 2843 } else { |
2842 MachineRepresentation param_rep = sig->GetParam(i); | 2844 MachineRepresentation param_rep = sig->GetParam(i); |
2843 StoreRepresentation store_rep(param_rep, | 2845 StoreRepresentation store_rep(param_rep, |
2844 WriteBarrierKind::kNoWriteBarrier); | 2846 WriteBarrierKind::kNoWriteBarrier); |
2845 *effect_ = | 2847 *effect_ = |
2846 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer, | 2848 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer, |
2847 Int32Constant(offset), param, *effect_, *control_); | 2849 Int32Constant(offset), param, *effect_, *control_); |
2848 offset += 1 << ElementSizeLog2Of(param_rep); | 2850 |
2851 offset += RoundUpToMultipleOfPowOf2(1 << ElementSizeLog2Of(param_rep), 8); | |
2849 } | 2852 } |
2850 } | 2853 } |
2851 DCHECK_EQ(param_count, param_index); | 2854 DCHECK_EQ(param_count, param_index); |
2852 DCHECK_EQ(args_size_bytes, offset); | 2855 DCHECK_EQ(args_size_bytes, offset); |
2853 | 2856 |
2854 // We are passing the raw arg_buffer here. To the GC and other parts, it looks | 2857 // 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 | 2858 // 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. | 2859 // call Smi::value on it, but just cast it to a byte pointer. |
2857 Node* parameters[] = { | 2860 Node* parameters[] = { |
2858 jsgraph()->HeapConstant(instance), // wasm instance | 2861 jsgraph()->HeapConstant(instance), // wasm instance |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3834 | 3837 |
3835 Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index, | 3838 Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index, |
3836 wasm::FunctionSig* sig, | 3839 wasm::FunctionSig* sig, |
3837 Handle<WasmInstanceObject> instance) { | 3840 Handle<WasmInstanceObject> instance) { |
3838 //---------------------------------------------------------------------------- | 3841 //---------------------------------------------------------------------------- |
3839 // Create the Graph | 3842 // Create the Graph |
3840 //---------------------------------------------------------------------------- | 3843 //---------------------------------------------------------------------------- |
3841 Zone zone(isolate->allocator(), ZONE_NAME); | 3844 Zone zone(isolate->allocator(), ZONE_NAME); |
3842 Graph graph(&zone); | 3845 Graph graph(&zone); |
3843 CommonOperatorBuilder common(&zone); | 3846 CommonOperatorBuilder common(&zone); |
3844 MachineOperatorBuilder machine(&zone); | 3847 MachineOperatorBuilder machine( |
3848 &zone, MachineType::PointerRepresentation(), | |
3849 InstructionSelector::SupportedMachineOperatorFlags(), | |
3850 InstructionSelector::AlignmentRequirements()); | |
3845 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 3851 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
3846 | 3852 |
3847 Node* control = nullptr; | 3853 Node* control = nullptr; |
3848 Node* effect = nullptr; | 3854 Node* effect = nullptr; |
3849 | 3855 |
3850 WasmGraphBuilder builder(nullptr, &zone, &jsgraph, sig); | 3856 WasmGraphBuilder builder(nullptr, &zone, &jsgraph, sig); |
3851 builder.set_control_ptr(&control); | 3857 builder.set_control_ptr(&control); |
3852 builder.set_effect_ptr(&effect); | 3858 builder.set_effect_ptr(&effect); |
3853 builder.BuildWasmInterpreterEntry(func_index, sig, instance); | 3859 builder.BuildWasmInterpreterEntry(func_index, sig, instance); |
3854 | 3860 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4128 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { | 4134 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { |
4129 WasmCompilationUnit unit(isolate, module_env, function); | 4135 WasmCompilationUnit unit(isolate, module_env, function); |
4130 unit.InitializeHandles(); | 4136 unit.InitializeHandles(); |
4131 unit.ExecuteCompilation(); | 4137 unit.ExecuteCompilation(); |
4132 return unit.FinishCompilation(thrower); | 4138 return unit.FinishCompilation(thrower); |
4133 } | 4139 } |
4134 | 4140 |
4135 } // namespace compiler | 4141 } // namespace compiler |
4136 } // namespace internal | 4142 } // namespace internal |
4137 } // namespace v8 | 4143 } // namespace v8 |
OLD | NEW |