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 "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 2497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2508 reinterpret_cast<uintptr_t>(module_->instance->mem_start + offset), | 2508 reinterpret_cast<uintptr_t>(module_->instance->mem_start + offset), |
2509 RelocInfo::WASM_MEMORY_REFERENCE); | 2509 RelocInfo::WASM_MEMORY_REFERENCE); |
2510 } | 2510 } |
2511 } | 2511 } |
2512 | 2512 |
2513 | 2513 |
2514 Node* WasmGraphBuilder::MemSize(uint32_t offset) { | 2514 Node* WasmGraphBuilder::MemSize(uint32_t offset) { |
2515 DCHECK(module_ && module_->instance); | 2515 DCHECK(module_ && module_->instance); |
2516 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); | 2516 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); |
2517 if (offset == 0) { | 2517 if (offset == 0) { |
2518 if (!mem_size_) mem_size_ = jsgraph()->Int32Constant(size); | 2518 if (!mem_size_) |
| 2519 mem_size_ = jsgraph()->RelocatableInt32Constant( |
| 2520 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
2519 return mem_size_; | 2521 return mem_size_; |
2520 } else { | 2522 } else { |
2521 return jsgraph()->Int32Constant(size + offset); | 2523 return jsgraph()->RelocatableInt32Constant( |
| 2524 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
2522 } | 2525 } |
2523 } | 2526 } |
2524 | 2527 |
2525 | 2528 |
2526 Node* WasmGraphBuilder::FunctionTable() { | 2529 Node* WasmGraphBuilder::FunctionTable() { |
2527 DCHECK(module_ && module_->instance && | 2530 DCHECK(module_ && module_->instance && |
2528 !module_->instance->function_table.is_null()); | 2531 !module_->instance->function_table.is_null()); |
2529 if (!function_table_) { | 2532 if (!function_table_) { |
2530 function_table_ = jsgraph()->Constant(module_->instance->function_table); | 2533 function_table_ = jsgraph()->Constant(module_->instance->function_table); |
2531 } | 2534 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2569 size_t size = module_->instance->mem_size; | 2572 size_t size = module_->instance->mem_size; |
2570 byte memsize = wasm::WasmOpcodes::MemSize(memtype); | 2573 byte memsize = wasm::WasmOpcodes::MemSize(memtype); |
2571 Node* cond; | 2574 Node* cond; |
2572 if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) { | 2575 if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) { |
2573 // The access will always throw. | 2576 // The access will always throw. |
2574 cond = jsgraph()->Int32Constant(0); | 2577 cond = jsgraph()->Int32Constant(0); |
2575 } else { | 2578 } else { |
2576 // Check against the limit. | 2579 // Check against the limit. |
2577 size_t limit = size - offset - memsize; | 2580 size_t limit = size - offset - memsize; |
2578 CHECK(limit <= kMaxUInt32); | 2581 CHECK(limit <= kMaxUInt32); |
2579 cond = graph()->NewNode( | 2582 cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThanOrEqual(), |
2580 jsgraph()->machine()->Uint32LessThanOrEqual(), index, | 2583 index, jsgraph()->RelocatableInt32Constant( |
2581 jsgraph()->Int32Constant(static_cast<uint32_t>(limit))); | 2584 static_cast<uint32_t>(limit), |
| 2585 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
2582 } | 2586 } |
2583 | 2587 |
2584 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond); | 2588 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond); |
2585 } | 2589 } |
2586 | 2590 |
2587 | 2591 |
2588 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, | 2592 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, |
2589 Node* index, uint32_t offset) { | 2593 Node* index, uint32_t offset) { |
2590 Node* load; | 2594 Node* load; |
2591 | 2595 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2999 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( | 3003 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( |
3000 static_cast<int>(jsgraph->graph()->zone()->allocation_size())); | 3004 static_cast<int>(jsgraph->graph()->zone()->allocation_size())); |
3001 graph_zone_scope.Destroy(); | 3005 graph_zone_scope.Destroy(); |
3002 return code; | 3006 return code; |
3003 } | 3007 } |
3004 | 3008 |
3005 | 3009 |
3006 } // namespace compiler | 3010 } // namespace compiler |
3007 } // namespace internal | 3011 } // namespace internal |
3008 } // namespace v8 | 3012 } // namespace v8 |
OLD | NEW |