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

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

Issue 1962553002: [wasm] Fold bounds checks during graph building. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | 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 "src/isolate-inl.h" 7 #include "src/isolate-inl.h"
8 8
9 #include "src/base/platform/elapsed-timer.h" 9 #include "src/base/platform/elapsed-timer.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 2553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2564 StoreRepresentation(mem_type.representation(), kNoWriteBarrier)); 2564 StoreRepresentation(mem_type.representation(), kNoWriteBarrier));
2565 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), val, 2565 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), val,
2566 *effect_, *control_); 2566 *effect_, *control_);
2567 *effect_ = node; 2567 *effect_ = node;
2568 return node; 2568 return node;
2569 } 2569 }
2570 2570
2571 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, 2571 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index,
2572 uint32_t offset, 2572 uint32_t offset,
2573 wasm::WasmCodePosition position) { 2573 wasm::WasmCodePosition position) {
2574 // TODO(turbofan): fold bounds checks for constant indexes.
2575 DCHECK(module_ && module_->instance); 2574 DCHECK(module_ && module_->instance);
2576 size_t size = module_->instance->mem_size; 2575 size_t size = module_->instance->mem_size;
2577 byte memsize = wasm::WasmOpcodes::MemSize(memtype); 2576 byte memsize = wasm::WasmOpcodes::MemSize(memtype);
2578 Node* cond; 2577
2579 if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) { 2578 if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) {
2580 // The access will always throw. 2579 // The access will always throw (unless memory is grown).
2581 cond = jsgraph()->Int32Constant(0); 2580 Node* cond = jsgraph()->Int32Constant(0);
2582 } else { 2581 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position);
Clemens Hammacher 2016/05/09 08:32:31 Why not trap_->TrapAlways?
titzer 2016/05/09 08:38:17 Yes, that would be great, but the nodes that will
2583 // Check against the limit. 2582 return;
2584 size_t limit = size - offset - memsize;
2585 CHECK(limit <= kMaxUInt32);
2586 cond = graph()->NewNode(
2587 jsgraph()->machine()->Uint32LessThanOrEqual(), index,
2588 jsgraph()->Int32Constant(static_cast<uint32_t>(limit)));
2589 } 2583 }
2590 2584
2585 // Check against the effective size.
2586 size_t effective_size = size - offset - memsize;
2587 CHECK(effective_size <= kMaxUInt32);
Clemens Hammacher 2016/05/09 08:32:31 Wouldn't a DCHECK suffice here?
titzer 2016/05/09 08:38:17 I really, really, don't want to wrap around in pro
Clemens Hammacher 2016/05/09 08:47:40 It really should not be possible here, since (offs
2588
2589 Uint32Matcher m(index);
2590 if (m.HasValue()) {
2591 uint32_t value = m.Value();
2592 if (value <= effective_size) {
2593 // The bounds check will always succeed.
2594 return;
2595 }
2596 }
2597
2598 Node* cond = graph()->NewNode(
2599 jsgraph()->machine()->Uint32LessThanOrEqual(), index,
2600 jsgraph()->Int32Constant(static_cast<uint32_t>(effective_size)));
2601
2591 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); 2602 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position);
2592 } 2603 }
2593 2604
2594 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, 2605 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype,
2595 Node* index, uint32_t offset, 2606 Node* index, uint32_t offset,
2596 wasm::WasmCodePosition position) { 2607 wasm::WasmCodePosition position) {
2597 Node* load; 2608 Node* load;
2598 2609
2599 if (module_ && module_->asm_js()) { 2610 if (module_ && module_->asm_js()) {
2600 // asm.js semantics use CheckedLoad (i.e. OOB reads return 0ish). 2611 // asm.js semantics use CheckedLoad (i.e. OOB reads return 0ish).
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
3072 const wasm::WasmFunction* function) { 3083 const wasm::WasmFunction* function) {
3073 WasmCompilationUnit* unit = 3084 WasmCompilationUnit* unit =
3074 CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0); 3085 CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0);
3075 ExecuteCompilation(unit); 3086 ExecuteCompilation(unit);
3076 return FinishCompilation(unit); 3087 return FinishCompilation(unit);
3077 } 3088 }
3078 3089
3079 } // namespace compiler 3090 } // namespace compiler
3080 } // namespace internal 3091 } // namespace internal
3081 } // namespace v8 3092 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698