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

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

Issue 2051043002: Implement Wasm GrowMemory opcode as a wasm runtime call (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 5 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
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 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 op = m->RoundUint64ToFloat64(); 874 op = m->RoundUint64ToFloat64();
875 break; 875 break;
876 case wasm::kExprI64SConvertF32: 876 case wasm::kExprI64SConvertF32:
877 return BuildI64SConvertF32(input, position); 877 return BuildI64SConvertF32(input, position);
878 case wasm::kExprI64SConvertF64: 878 case wasm::kExprI64SConvertF64:
879 return BuildI64SConvertF64(input, position); 879 return BuildI64SConvertF64(input, position);
880 case wasm::kExprI64UConvertF32: 880 case wasm::kExprI64UConvertF32:
881 return BuildI64UConvertF32(input, position); 881 return BuildI64UConvertF32(input, position);
882 case wasm::kExprI64UConvertF64: 882 case wasm::kExprI64UConvertF64:
883 return BuildI64UConvertF64(input, position); 883 return BuildI64UConvertF64(input, position);
884 case wasm::kExprGrowMemory:
885 return BuildGrowMemory(input);
884 case wasm::kExprI32AsmjsLoadMem8S: 886 case wasm::kExprI32AsmjsLoadMem8S:
885 return BuildAsmjsLoadMem(MachineType::Int8(), input); 887 return BuildAsmjsLoadMem(MachineType::Int8(), input);
886 case wasm::kExprI32AsmjsLoadMem8U: 888 case wasm::kExprI32AsmjsLoadMem8U:
887 return BuildAsmjsLoadMem(MachineType::Uint8(), input); 889 return BuildAsmjsLoadMem(MachineType::Uint8(), input);
888 case wasm::kExprI32AsmjsLoadMem16S: 890 case wasm::kExprI32AsmjsLoadMem16S:
889 return BuildAsmjsLoadMem(MachineType::Int16(), input); 891 return BuildAsmjsLoadMem(MachineType::Int16(), input);
890 case wasm::kExprI32AsmjsLoadMem16U: 892 case wasm::kExprI32AsmjsLoadMem16U:
891 return BuildAsmjsLoadMem(MachineType::Uint16(), input); 893 return BuildAsmjsLoadMem(MachineType::Uint16(), input);
892 case wasm::kExprI32AsmjsLoadMem: 894 case wasm::kExprI32AsmjsLoadMem:
893 return BuildAsmjsLoadMem(MachineType::Int32(), input); 895 return BuildAsmjsLoadMem(MachineType::Int32(), input);
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 trap_->ZeroCheck32(wasm::kTrapFloatUnrepresentable, 1566 trap_->ZeroCheck32(wasm::kTrapFloatUnrepresentable,
1565 BuildCCall(sig_builder.Build(), args), position); 1567 BuildCCall(sig_builder.Build(), args), position);
1566 const Operator* load_op = jsgraph()->machine()->Load(result_type); 1568 const Operator* load_op = jsgraph()->machine()->Load(result_type);
1567 Node* load = 1569 Node* load =
1568 graph()->NewNode(load_op, stack_slot_result, jsgraph()->Int32Constant(0), 1570 graph()->NewNode(load_op, stack_slot_result, jsgraph()->Int32Constant(0),
1569 *effect_, *control_); 1571 *effect_, *control_);
1570 *effect_ = load; 1572 *effect_ = load;
1571 return load; 1573 return load;
1572 } 1574 }
1573 1575
1576 Node* WasmGraphBuilder::BuildGrowMemory(Node* input) {
1577 Runtime::FunctionId f = Runtime::kWasmGrowMemory;
ahaas 2016/06/24 11:10:15 personal preference: would it be possible to use b
gdeepti 2016/06/25 00:28:41 Done.
1578 const Runtime::Function* fun = Runtime::FunctionForId(f);
1579 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
1580 jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties,
1581 CallDescriptor::kNoFlags);
1582 Node** control_ptr = control_;
1583 Node** effect_ptr = effect_;
1584 wasm::ModuleEnv* module = module_;
1585 *control_ptr = graph()->NewNode(jsgraph()->common()->Merge(1), *control_ptr);
1586 *effect_ptr = graph()->NewNode(jsgraph()->common()->EffectPhi(1), *effect_ptr,
1587 *control_ptr);
1588 input = BuildChangeUint32ToSmi(input);
1589 Node* inputs[] = {
1590 jsgraph()->CEntryStubConstant(fun->result_size), input, // C entry
1591 jsgraph()->ExternalConstant(
1592 ExternalReference(f, jsgraph()->isolate())), // ref
1593 jsgraph()->Int32Constant(fun->nargs), // arity
1594 jsgraph()->HeapConstant(module->instance->context), // context
1595 *effect_ptr,
1596 *control_ptr};
1597 Node* node = graph()->NewNode(jsgraph()->common()->Call(desc),
1598 static_cast<int>(arraysize(inputs)), inputs);
1599 *control_ptr = node;
1600 *effect_ptr = node;
1601 node = BuildChangeSmiToInt32(node);
1602 return node;
1603 }
1604
1574 Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right, 1605 Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right,
1575 wasm::WasmCodePosition position) { 1606 wasm::WasmCodePosition position) {
1576 MachineOperatorBuilder* m = jsgraph()->machine(); 1607 MachineOperatorBuilder* m = jsgraph()->machine();
1577 trap_->ZeroCheck32(wasm::kTrapDivByZero, right, position); 1608 trap_->ZeroCheck32(wasm::kTrapDivByZero, right, position);
1578 Node* before = *control_; 1609 Node* before = *control_;
1579 Node* denom_is_m1; 1610 Node* denom_is_m1;
1580 Node* denom_is_not_m1; 1611 Node* denom_is_not_m1;
1581 Branch( 1612 Branch(
1582 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)), 1613 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)),
1583 &denom_is_m1, &denom_is_not_m1); 1614 &denom_is_m1, &denom_is_not_m1);
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) { 2306 Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) {
2276 value = graph()->NewNode(jsgraph()->machine()->WordSar(), value, 2307 value = graph()->NewNode(jsgraph()->machine()->WordSar(), value,
2277 BuildSmiShiftBitsConstant()); 2308 BuildSmiShiftBitsConstant());
2278 if (jsgraph()->machine()->Is64()) { 2309 if (jsgraph()->machine()->Is64()) {
2279 value = 2310 value =
2280 graph()->NewNode(jsgraph()->machine()->TruncateInt64ToInt32(), value); 2311 graph()->NewNode(jsgraph()->machine()->TruncateInt64ToInt32(), value);
2281 } 2312 }
2282 return value; 2313 return value;
2283 } 2314 }
2284 2315
2316 Node* WasmGraphBuilder::BuildChangeUint32ToSmi(Node* value) {
2317 if (jsgraph()->machine()->Is64()) {
2318 value =
2319 graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), value);
2320 }
2321 return graph()->NewNode(jsgraph()->machine()->WordShl(), value,
2322 BuildSmiShiftBitsConstant());
2323 }
2324
2285 Node* WasmGraphBuilder::BuildChangeSmiToFloat64(Node* value) { 2325 Node* WasmGraphBuilder::BuildChangeSmiToFloat64(Node* value) {
2286 return graph()->NewNode(jsgraph()->machine()->ChangeInt32ToFloat64(), 2326 return graph()->NewNode(jsgraph()->machine()->ChangeInt32ToFloat64(),
2287 BuildChangeSmiToInt32(value)); 2327 BuildChangeSmiToInt32(value));
2288 } 2328 }
2289 2329
2290 Node* WasmGraphBuilder::BuildTestNotSmi(Node* value) { 2330 Node* WasmGraphBuilder::BuildTestNotSmi(Node* value) {
2291 STATIC_ASSERT(kSmiTag == 0); 2331 STATIC_ASSERT(kSmiTag == 0);
2292 STATIC_ASSERT(kSmiTagMask == 1); 2332 STATIC_ASSERT(kSmiTagMask == 1);
2293 return graph()->NewNode(jsgraph()->machine()->WordAnd(), value, 2333 return graph()->NewNode(jsgraph()->machine()->WordAnd(), value,
2294 jsgraph()->IntPtrConstant(kSmiTagMask)); 2334 jsgraph()->IntPtrConstant(kSmiTagMask));
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2580 if (value < effective_size) { 2620 if (value < effective_size) {
2581 // The bounds check will always succeed. 2621 // The bounds check will always succeed.
2582 return; 2622 return;
2583 } 2623 }
2584 } 2624 }
2585 2625
2586 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, 2626 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index,
2587 jsgraph()->RelocatableInt32Constant( 2627 jsgraph()->RelocatableInt32Constant(
2588 static_cast<uint32_t>(effective_size), 2628 static_cast<uint32_t>(effective_size),
2589 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); 2629 RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
2590
2591 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); 2630 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position);
2592 } 2631 }
2593 2632
2594 MachineType WasmGraphBuilder::GetTypeForUnalignedAccess(uint32_t alignment, 2633 MachineType WasmGraphBuilder::GetTypeForUnalignedAccess(uint32_t alignment,
2595 bool signExtend) { 2634 bool signExtend) {
2596 switch (alignment) { 2635 switch (alignment) {
2597 case 0: 2636 case 0:
2598 return signExtend ? MachineType::Int8() : MachineType::Uint8(); 2637 return signExtend ? MachineType::Int8() : MachineType::Uint8();
2599 case 1: 2638 case 1:
2600 return signExtend ? MachineType::Int16() : MachineType::Uint16(); 2639 return signExtend ? MachineType::Int16() : MachineType::Uint16();
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
3270 function_->code_start_offset), 3309 function_->code_start_offset),
3271 compile_ms); 3310 compile_ms);
3272 } 3311 }
3273 3312
3274 return code; 3313 return code;
3275 } 3314 }
3276 3315
3277 } // namespace compiler 3316 } // namespace compiler
3278 } // namespace internal 3317 } // namespace internal
3279 } // namespace v8 3318 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/messages.h » ('j') | src/runtime/runtime-wasm.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698