Chromium Code Reviews| Index: src/compiler/wasm-compiler.cc |
| diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc |
| index 09290af06aa7023f3da35cb95f735427f4b24834..f30e1891e5ee046fc05732934cdd76de909174b9 100644 |
| --- a/src/compiler/wasm-compiler.cc |
| +++ b/src/compiler/wasm-compiler.cc |
| @@ -877,6 +877,8 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input, |
| return BuildI64UConvertF32(input, position); |
| case wasm::kExprI64UConvertF64: |
| return BuildI64UConvertF64(input, position); |
| + case wasm::kExprGrowMemory: |
| + return BuildGrowMemory(input); |
| case wasm::kExprI32AsmjsLoadMem8S: |
| return BuildAsmjsLoadMem(MachineType::Int8(), input); |
| case wasm::kExprI32AsmjsLoadMem8U: |
| @@ -1605,6 +1607,36 @@ Node* WasmGraphBuilder::BuildFloatToIntConversionInstruction( |
| return load; |
| } |
| +Node* WasmGraphBuilder::BuildGrowMemory(Node* input) { |
| + Runtime::FunctionId f = Runtime::kWasmGrowMemory; |
| + const Runtime::Function* fun = Runtime::FunctionForId(f); |
| + CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| + jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties, |
| + CallDescriptor::kNoFlags); |
| + Node** control_ptr = control_; |
| + Node** effect_ptr = effect_; |
| + wasm::ModuleEnv* module = module_; |
| + *control_ptr = graph()->NewNode(jsgraph()->common()->Merge(1), *control_ptr); |
| + *effect_ptr = graph()->NewNode(jsgraph()->common()->EffectPhi(1), *effect_ptr, |
| + *control_ptr); |
| + input = BuildChangeInt32ToTagged(input); |
|
titzer
2016/06/10 09:38:13
I think this is OK for now, but this does mean tha
gdeepti
2016/06/10 22:39:57
I'm assuming by allocation you mean heap number al
|
| + Node* inputs[] = {jsgraph()->CEntryStubConstant(fun->result_size), // C entry |
| + input, jsgraph()->Constant(module->instance->js_object), |
| + jsgraph()->ExternalConstant( |
| + ExternalReference(f, jsgraph()->isolate())), // ref |
| + jsgraph()->Int32Constant(fun->nargs), // arity |
| + jsgraph()->Constant(module->instance->context), // context |
| + *effect_ptr, |
| + *control_ptr}; |
| + Node* node = graph()->NewNode(jsgraph()->common()->Call(desc), |
| + static_cast<int>(arraysize(inputs)), inputs); |
| + *control_ptr = node; |
| + *effect_ptr = node; |
| + node = BuildChangeTaggedToFloat64(node); |
| + node = graph()->NewNode(jsgraph()->machine()->ChangeFloat64ToInt32(), node); |
| + return node; |
| +} |
| + |
| Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right, |
| wasm::WasmCodePosition position) { |
| MachineOperatorBuilder* m = jsgraph()->machine(); |
| @@ -2542,10 +2574,13 @@ Node* WasmGraphBuilder::MemSize(uint32_t offset) { |
| DCHECK(module_ && module_->instance); |
| uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); |
| if (offset == 0) { |
| - if (!mem_size_) mem_size_ = jsgraph()->Int32Constant(size); |
| + if (!mem_size_) |
| + mem_size_ = jsgraph()->RelocatableInt32Constant( |
| + size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
| return mem_size_; |
| } else { |
| - return jsgraph()->Int32Constant(size + offset); |
| + return jsgraph()->RelocatableInt32Constant( |
| + size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
| } |
| } |
| @@ -2592,29 +2627,28 @@ void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, |
| size_t size = module_->instance->mem_size; |
| byte memsize = wasm::WasmOpcodes::MemSize(memtype); |
| + // Check against the effective size. |
| + size_t effective_size; |
| if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) { |
| - // The access will always throw (unless memory is grown). |
| - Node* cond = jsgraph()->Int32Constant(0); |
| - trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
| - return; |
| + effective_size = 0; |
| + } else { |
| + effective_size = size - offset - memsize + 1; |
| } |
| - |
| - // Check against the effective size. |
| - size_t effective_size = size - offset - memsize; |
| CHECK(effective_size <= kMaxUInt32); |
| Uint32Matcher m(index); |
| if (m.HasValue()) { |
| uint32_t value = m.Value(); |
| - if (value <= effective_size) { |
| + if (value < effective_size) { |
| // The bounds check will always succeed. |
| return; |
| } |
| } |
| - Node* cond = graph()->NewNode( |
| - jsgraph()->machine()->Uint32LessThanOrEqual(), index, |
| - jsgraph()->Int32Constant(static_cast<uint32_t>(effective_size))); |
| + Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, |
| + jsgraph()->RelocatableInt32Constant( |
| + static_cast<uint32_t>(effective_size), |
| + RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
| trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
| } |