Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2887053003: MIPS[64]: Reland of `Fix unaligned arguments storage in Wasm-to-interpreter entry` (Closed)
Patch Set: Simplifications. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/compiler/wasm-compiler.h ('K') | « src/compiler/wasm-compiler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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...) Expand 10 before | Expand all | Expand 10 after
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 lower_half_offset = offset + kInt64LowerHalfMemoryOffset;
2828 WriteBarrierKind::kNoWriteBarrier); 2829 int upper_half_offset = offset + kInt64UpperHalfMemoryOffset;
2829 *effect_ = 2830
2830 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer, 2831 *effect_ = graph()->NewNode(
2831 Int32Constant(offset + kInt64LowerHalfMemoryOffset), 2832 GetSafeStoreOperator(jsgraph()->machine(), lower_half_offset,
2832 param, *effect_, *control_); 2833 wasm::kWasmI32),
2834 arg_buffer, Int32Constant(lower_half_offset), param, *effect_,
2835 *control_);
2833 2836
2834 param = Param(param_index++); 2837 param = Param(param_index++);
2835 *effect_ = 2838 *effect_ = graph()->NewNode(
2836 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer, 2839 GetSafeStoreOperator(jsgraph()->machine(), upper_half_offset,
2837 Int32Constant(offset + kInt64UpperHalfMemoryOffset), 2840 wasm::kWasmI32),
2838 param, *effect_, *control_); 2841 arg_buffer, Int32Constant(upper_half_offset), param, *effect_,
2842 *control_);
2839 offset += 8; 2843 offset += 8;
2840 2844
2841 } else { 2845 } else {
2842 MachineRepresentation param_rep = sig->GetParam(i); 2846 MachineRepresentation param_rep = sig->GetParam(i);
2843 StoreRepresentation store_rep(param_rep, 2847 *effect_ = graph()->NewNode(
2844 WriteBarrierKind::kNoWriteBarrier); 2848 GetSafeStoreOperator(jsgraph()->machine(), offset, param_rep),
2845 *effect_ = 2849 arg_buffer, Int32Constant(offset), param, *effect_, *control_);
2846 graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer,
2847 Int32Constant(offset), param, *effect_, *control_);
2848 offset += 1 << ElementSizeLog2Of(param_rep); 2850 offset += 1 << ElementSizeLog2Of(param_rep);
2849 } 2851 }
2850 } 2852 }
2851 DCHECK_EQ(param_count, param_index); 2853 DCHECK_EQ(param_count, param_index);
2852 DCHECK_EQ(args_size_bytes, offset); 2854 DCHECK_EQ(args_size_bytes, offset);
2853 2855
2854 // We are passing the raw arg_buffer here. To the GC and other parts, it looks 2856 // 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 2857 // 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. 2858 // call Smi::value on it, but just cast it to a byte pointer.
2857 Node* parameters[] = { 2859 Node* parameters[] = {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 } 3026 }
3025 } 3027 }
3026 3028
3027 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, 3029 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index,
3028 jsgraph()->RelocatableInt32Constant( 3030 jsgraph()->RelocatableInt32Constant(
3029 static_cast<uint32_t>(effective_size), 3031 static_cast<uint32_t>(effective_size),
3030 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); 3032 RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
3031 TrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); 3033 TrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position);
3032 } 3034 }
3033 3035
3036 const Operator* WasmGraphBuilder::GetSafeStoreOperator(
3037 MachineOperatorBuilder* machine, int offset, wasm::ValueType type) {
3038 int alignment = offset % (1 << ElementSizeLog2Of(type));
3039 if (alignment == 0 || machine->UnalignedStoreSupported(
3040 MachineType::TypeForRepresentation(type), 0)) {
3041 StoreRepresentation rep(type, WriteBarrierKind::kNoWriteBarrier);
3042 return machine->Store(rep);
3043 }
3044 UnalignedStoreRepresentation rep(type);
3045 return machine->UnalignedStore(rep);
3046 }
3047
3034 Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype, 3048 Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
3035 Node* index, uint32_t offset, 3049 Node* index, uint32_t offset,
3036 uint32_t alignment, 3050 uint32_t alignment,
3037 wasm::WasmCodePosition position) { 3051 wasm::WasmCodePosition position) {
3038 Node* load; 3052 Node* load;
3039 3053
3040 // WASM semantics throw on OOB. Introduce explicit bounds check. 3054 // WASM semantics throw on OOB. Introduce explicit bounds check.
3041 if (!FLAG_wasm_trap_handler || !V8_TRAP_HANDLER_SUPPORTED) { 3055 if (!FLAG_wasm_trap_handler || !V8_TRAP_HANDLER_SUPPORTED) {
3042 BoundsCheckMem(memtype, index, offset, position); 3056 BoundsCheckMem(memtype, index, offset, position);
3043 } 3057 }
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
3834 3848
3835 Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index, 3849 Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
3836 wasm::FunctionSig* sig, 3850 wasm::FunctionSig* sig,
3837 Handle<WasmInstanceObject> instance) { 3851 Handle<WasmInstanceObject> instance) {
3838 //---------------------------------------------------------------------------- 3852 //----------------------------------------------------------------------------
3839 // Create the Graph 3853 // Create the Graph
3840 //---------------------------------------------------------------------------- 3854 //----------------------------------------------------------------------------
3841 Zone zone(isolate->allocator(), ZONE_NAME); 3855 Zone zone(isolate->allocator(), ZONE_NAME);
3842 Graph graph(&zone); 3856 Graph graph(&zone);
3843 CommonOperatorBuilder common(&zone); 3857 CommonOperatorBuilder common(&zone);
3844 MachineOperatorBuilder machine(&zone); 3858 MachineOperatorBuilder machine(
3859 &zone, MachineType::PointerRepresentation(),
3860 InstructionSelector::SupportedMachineOperatorFlags(),
3861 InstructionSelector::AlignmentRequirements());
3845 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 3862 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
3846 3863
3847 Node* control = nullptr; 3864 Node* control = nullptr;
3848 Node* effect = nullptr; 3865 Node* effect = nullptr;
3849 3866
3850 WasmGraphBuilder builder(nullptr, &zone, &jsgraph, sig); 3867 WasmGraphBuilder builder(nullptr, &zone, &jsgraph, sig);
3851 builder.set_control_ptr(&control); 3868 builder.set_control_ptr(&control);
3852 builder.set_effect_ptr(&effect); 3869 builder.set_effect_ptr(&effect);
3853 builder.BuildWasmInterpreterEntry(func_index, sig, instance); 3870 builder.BuildWasmInterpreterEntry(func_index, sig, instance);
3854 3871
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { 4145 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) {
4129 WasmCompilationUnit unit(isolate, module_env, function); 4146 WasmCompilationUnit unit(isolate, module_env, function);
4130 unit.InitializeHandles(); 4147 unit.InitializeHandles();
4131 unit.ExecuteCompilation(); 4148 unit.ExecuteCompilation();
4132 return unit.FinishCompilation(thrower); 4149 return unit.FinishCompilation(thrower);
4133 } 4150 }
4134 4151
4135 } // namespace compiler 4152 } // namespace compiler
4136 } // namespace internal 4153 } // namespace internal
4137 } // namespace v8 4154 } // namespace v8
OLDNEW
« src/compiler/wasm-compiler.h ('K') | « src/compiler/wasm-compiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698