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

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

Issue 2516413003: [wasm] Add ProtectedStore instruction (Closed)
Patch Set: Merging with master Created 4 years 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
« no previous file with comments | « src/compiler/verifier.cc ('k') | src/compiler/x64/code-generator-x64.cc » ('j') | 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/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 inputs[count++] = control; 93 inputs[count++] = control;
94 94
95 Node* node = 95 Node* node =
96 jsgraph->graph()->NewNode(jsgraph->common()->Call(desc), count, inputs); 96 jsgraph->graph()->NewNode(jsgraph->common()->Call(desc), count, inputs);
97 *effect_ptr = node; 97 *effect_ptr = node;
98 return node; 98 return node;
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 // TODO(eholk): Support trap handlers on other platforms.
104 #if V8_TARGET_ARCH_X64 && V8_OS_LINUX
105 const bool kTrapHandlerSupported = true;
106 #else
107 const bool kTrapHandlerSupported = false;
108 #endif
109
103 // A helper that handles building graph fragments for trapping. 110 // A helper that handles building graph fragments for trapping.
104 // To avoid generating a ton of redundant code that just calls the runtime 111 // To avoid generating a ton of redundant code that just calls the runtime
105 // to trap, we generate a per-trap-reason block of code that all trap sites 112 // to trap, we generate a per-trap-reason block of code that all trap sites
106 // in this function will branch to. 113 // in this function will branch to.
107 class WasmTrapHelper : public ZoneObject { 114 class WasmTrapHelper : public ZoneObject {
108 public: 115 public:
109 explicit WasmTrapHelper(WasmGraphBuilder* builder) 116 explicit WasmTrapHelper(WasmGraphBuilder* builder)
110 : builder_(builder), 117 : builder_(builder),
111 jsgraph_(builder->jsgraph()), 118 jsgraph_(builder->jsgraph()),
112 graph_(builder->jsgraph() ? builder->jsgraph()->graph() : nullptr) {} 119 graph_(builder->jsgraph() ? builder->jsgraph()->graph() : nullptr) {}
(...skipping 2828 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 } 2948 }
2942 2949
2943 2950
2944 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, 2951 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype,
2945 Node* index, uint32_t offset, 2952 Node* index, uint32_t offset,
2946 uint32_t alignment, 2953 uint32_t alignment,
2947 wasm::WasmCodePosition position) { 2954 wasm::WasmCodePosition position) {
2948 Node* load; 2955 Node* load;
2949 2956
2950 // WASM semantics throw on OOB. Introduce explicit bounds check. 2957 // WASM semantics throw on OOB. Introduce explicit bounds check.
2951 if (!FLAG_wasm_trap_handler) { 2958 if (!FLAG_wasm_trap_handler || !kTrapHandlerSupported) {
2952 BoundsCheckMem(memtype, index, offset, position); 2959 BoundsCheckMem(memtype, index, offset, position);
2953 } 2960 }
2954 bool aligned = static_cast<int>(alignment) >= 2961 bool aligned = static_cast<int>(alignment) >=
2955 ElementSizeLog2Of(memtype.representation()); 2962 ElementSizeLog2Of(memtype.representation());
2956 2963
2957 if (aligned || 2964 if (aligned ||
2958 jsgraph()->machine()->UnalignedLoadSupported(memtype, alignment)) { 2965 jsgraph()->machine()->UnalignedLoadSupported(memtype, alignment)) {
2959 if (FLAG_wasm_trap_handler) { 2966 if (FLAG_wasm_trap_handler && kTrapHandlerSupported) {
2960 DCHECK(FLAG_wasm_guard_pages); 2967 DCHECK(FLAG_wasm_guard_pages);
2961 Node* context = HeapConstant(module_->instance->context); 2968 Node* context = HeapConstant(module_->instance->context);
2962 Node* position_node = jsgraph()->Int32Constant(position); 2969 Node* position_node = jsgraph()->Int32Constant(position);
2963 load = graph()->NewNode(jsgraph()->machine()->ProtectedLoad(memtype), 2970 load = graph()->NewNode(jsgraph()->machine()->ProtectedLoad(memtype),
2964 MemBuffer(offset), index, context, position_node, 2971 MemBuffer(offset), index, context, position_node,
2965 *effect_, *control_); 2972 *effect_, *control_);
2966 } else { 2973 } else {
2967 load = graph()->NewNode(jsgraph()->machine()->Load(memtype), 2974 load = graph()->NewNode(jsgraph()->machine()->Load(memtype),
2968 MemBuffer(offset), index, *effect_, *control_); 2975 MemBuffer(offset), index, *effect_, *control_);
2969 } 2976 }
2970 } else { 2977 } else {
2971 DCHECK(!FLAG_wasm_trap_handler); 2978 // TODO(eholk): Support unaligned loads with trap handlers.
2979 DCHECK(!FLAG_wasm_trap_handler || !kTrapHandlerSupported);
2972 load = graph()->NewNode(jsgraph()->machine()->UnalignedLoad(memtype), 2980 load = graph()->NewNode(jsgraph()->machine()->UnalignedLoad(memtype),
2973 MemBuffer(offset), index, *effect_, *control_); 2981 MemBuffer(offset), index, *effect_, *control_);
2974 } 2982 }
2975 2983
2976 *effect_ = load; 2984 *effect_ = load;
2977 2985
2978 #if defined(V8_TARGET_BIG_ENDIAN) 2986 #if defined(V8_TARGET_BIG_ENDIAN)
2979 load = BuildChangeEndianness(load, memtype, type); 2987 load = BuildChangeEndianness(load, memtype, type);
2980 #endif 2988 #endif
2981 2989
(...skipping 13 matching lines...) Expand all
2995 return load; 3003 return load;
2996 } 3004 }
2997 3005
2998 3006
2999 Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index, 3007 Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
3000 uint32_t offset, uint32_t alignment, Node* val, 3008 uint32_t offset, uint32_t alignment, Node* val,
3001 wasm::WasmCodePosition position) { 3009 wasm::WasmCodePosition position) {
3002 Node* store; 3010 Node* store;
3003 3011
3004 // WASM semantics throw on OOB. Introduce explicit bounds check. 3012 // WASM semantics throw on OOB. Introduce explicit bounds check.
3005 BoundsCheckMem(memtype, index, offset, position); 3013 if (!FLAG_wasm_trap_handler || !kTrapHandlerSupported) {
3014 BoundsCheckMem(memtype, index, offset, position);
3015 }
3006 StoreRepresentation rep(memtype.representation(), kNoWriteBarrier); 3016 StoreRepresentation rep(memtype.representation(), kNoWriteBarrier);
3007 3017
3008 bool aligned = static_cast<int>(alignment) >= 3018 bool aligned = static_cast<int>(alignment) >=
3009 ElementSizeLog2Of(memtype.representation()); 3019 ElementSizeLog2Of(memtype.representation());
3010 3020
3011 #if defined(V8_TARGET_BIG_ENDIAN) 3021 #if defined(V8_TARGET_BIG_ENDIAN)
3012 val = BuildChangeEndianness(val, memtype); 3022 val = BuildChangeEndianness(val, memtype);
3013 #endif 3023 #endif
3014 3024
3015 if (aligned || 3025 if (aligned ||
3016 jsgraph()->machine()->UnalignedStoreSupported(memtype, alignment)) { 3026 jsgraph()->machine()->UnalignedStoreSupported(memtype, alignment)) {
3017 StoreRepresentation rep(memtype.representation(), kNoWriteBarrier); 3027 if (FLAG_wasm_trap_handler && kTrapHandlerSupported) {
3018 store = 3028 Node* context = HeapConstant(module_->instance->context);
3019 graph()->NewNode(jsgraph()->machine()->Store(rep), MemBuffer(offset), 3029 Node* position_node = jsgraph()->Int32Constant(position);
3020 index, val, *effect_, *control_); 3030 store = graph()->NewNode(
3031 jsgraph()->machine()->ProtectedStore(memtype.representation()),
3032 MemBuffer(offset), index, val, context, position_node, *effect_,
3033 *control_);
3034 } else {
3035 StoreRepresentation rep(memtype.representation(), kNoWriteBarrier);
3036 store =
3037 graph()->NewNode(jsgraph()->machine()->Store(rep), MemBuffer(offset),
3038 index, val, *effect_, *control_);
3039 }
3021 } else { 3040 } else {
3041 // TODO(eholk): Support unaligned stores with trap handlers.
3042 DCHECK(!FLAG_wasm_trap_handler || !kTrapHandlerSupported);
3022 UnalignedStoreRepresentation rep(memtype.representation()); 3043 UnalignedStoreRepresentation rep(memtype.representation());
3023 store = 3044 store =
3024 graph()->NewNode(jsgraph()->machine()->UnalignedStore(rep), 3045 graph()->NewNode(jsgraph()->machine()->UnalignedStore(rep),
3025 MemBuffer(offset), index, val, *effect_, *control_); 3046 MemBuffer(offset), index, val, *effect_, *control_);
3026 } 3047 }
3027 3048
3028 *effect_ = store; 3049 *effect_ = store;
3029 3050
3030 return store; 3051 return store;
3031 } 3052 }
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
3488 function_->code_start_offset), 3509 function_->code_start_offset),
3489 compile_ms); 3510 compile_ms);
3490 } 3511 }
3491 3512
3492 return code; 3513 return code;
3493 } 3514 }
3494 3515
3495 } // namespace compiler 3516 } // namespace compiler
3496 } // namespace internal 3517 } // namespace internal
3497 } // namespace v8 3518 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/verifier.cc ('k') | src/compiler/x64/code-generator-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698