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

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: Review changes 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
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/messages.h » ('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 "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 function_id = Runtime::kWasmGrowMemory;
1578 const Runtime::Function* function = Runtime::FunctionForId(function_id);
1579 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
1580 jsgraph()->zone(), function_id, function->nargs, Operator::kNoProperties,
1581 CallDescriptor::kNoFlags);
1582 Node** control_ptr = control_;
1583 Node** effect_ptr = effect_;
1584 wasm::ModuleEnv* module = module_;
1585 input = BuildChangeUint32ToSmi(input);
1586 Node* inputs[] = {
1587 jsgraph()->CEntryStubConstant(function->result_size), input, // C entry
1588 jsgraph()->ExternalConstant(
1589 ExternalReference(function_id, jsgraph()->isolate())), // ref
1590 jsgraph()->Int32Constant(function->nargs), // arity
1591 jsgraph()->HeapConstant(module->instance->context), // context
1592 *effect_ptr,
1593 *control_ptr};
1594 Node* node = graph()->NewNode(jsgraph()->common()->Call(desc),
1595 static_cast<int>(arraysize(inputs)), inputs);
1596 *control_ptr = node;
1597 *effect_ptr = node;
1598 node = BuildChangeSmiToInt32(node);
1599 return node;
1600 }
1601
1574 Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right, 1602 Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right,
1575 wasm::WasmCodePosition position) { 1603 wasm::WasmCodePosition position) {
1576 MachineOperatorBuilder* m = jsgraph()->machine(); 1604 MachineOperatorBuilder* m = jsgraph()->machine();
1577 trap_->ZeroCheck32(wasm::kTrapDivByZero, right, position); 1605 trap_->ZeroCheck32(wasm::kTrapDivByZero, right, position);
1578 Node* before = *control_; 1606 Node* before = *control_;
1579 Node* denom_is_m1; 1607 Node* denom_is_m1;
1580 Node* denom_is_not_m1; 1608 Node* denom_is_not_m1;
1581 Branch( 1609 Branch(
1582 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)), 1610 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)),
1583 &denom_is_m1, &denom_is_not_m1); 1611 &denom_is_m1, &denom_is_not_m1);
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) { 2304 Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) {
2277 value = graph()->NewNode(jsgraph()->machine()->WordSar(), value, 2305 value = graph()->NewNode(jsgraph()->machine()->WordSar(), value,
2278 BuildSmiShiftBitsConstant()); 2306 BuildSmiShiftBitsConstant());
2279 if (jsgraph()->machine()->Is64()) { 2307 if (jsgraph()->machine()->Is64()) {
2280 value = 2308 value =
2281 graph()->NewNode(jsgraph()->machine()->TruncateInt64ToInt32(), value); 2309 graph()->NewNode(jsgraph()->machine()->TruncateInt64ToInt32(), value);
2282 } 2310 }
2283 return value; 2311 return value;
2284 } 2312 }
2285 2313
2314 Node* WasmGraphBuilder::BuildChangeUint32ToSmi(Node* value) {
2315 if (jsgraph()->machine()->Is64()) {
2316 value =
2317 graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), value);
2318 }
2319 return graph()->NewNode(jsgraph()->machine()->WordShl(), value,
2320 BuildSmiShiftBitsConstant());
2321 }
2322
2286 Node* WasmGraphBuilder::BuildChangeSmiToFloat64(Node* value) { 2323 Node* WasmGraphBuilder::BuildChangeSmiToFloat64(Node* value) {
2287 return graph()->NewNode(jsgraph()->machine()->ChangeInt32ToFloat64(), 2324 return graph()->NewNode(jsgraph()->machine()->ChangeInt32ToFloat64(),
2288 BuildChangeSmiToInt32(value)); 2325 BuildChangeSmiToInt32(value));
2289 } 2326 }
2290 2327
2291 Node* WasmGraphBuilder::BuildTestNotSmi(Node* value) { 2328 Node* WasmGraphBuilder::BuildTestNotSmi(Node* value) {
2292 STATIC_ASSERT(kSmiTag == 0); 2329 STATIC_ASSERT(kSmiTag == 0);
2293 STATIC_ASSERT(kSmiTagMask == 1); 2330 STATIC_ASSERT(kSmiTagMask == 1);
2294 return graph()->NewNode(jsgraph()->machine()->WordAnd(), value, 2331 return graph()->NewNode(jsgraph()->machine()->WordAnd(), value,
2295 jsgraph()->IntPtrConstant(kSmiTagMask)); 2332 jsgraph()->IntPtrConstant(kSmiTagMask));
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2581 if (value < effective_size) { 2618 if (value < effective_size) {
2582 // The bounds check will always succeed. 2619 // The bounds check will always succeed.
2583 return; 2620 return;
2584 } 2621 }
2585 } 2622 }
2586 2623
2587 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, 2624 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index,
2588 jsgraph()->RelocatableInt32Constant( 2625 jsgraph()->RelocatableInt32Constant(
2589 static_cast<uint32_t>(effective_size), 2626 static_cast<uint32_t>(effective_size),
2590 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); 2627 RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
2591
2592 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); 2628 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position);
2593 } 2629 }
2594 2630
2595 MachineType WasmGraphBuilder::GetTypeForUnalignedAccess(uint32_t alignment, 2631 MachineType WasmGraphBuilder::GetTypeForUnalignedAccess(uint32_t alignment,
2596 bool signExtend) { 2632 bool signExtend) {
2597 switch (alignment) { 2633 switch (alignment) {
2598 case 0: 2634 case 0:
2599 return signExtend ? MachineType::Int8() : MachineType::Uint8(); 2635 return signExtend ? MachineType::Int8() : MachineType::Uint8();
2600 case 1: 2636 case 1:
2601 return signExtend ? MachineType::Int16() : MachineType::Uint16(); 2637 return signExtend ? MachineType::Int16() : MachineType::Uint16();
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
3271 function_->code_start_offset), 3307 function_->code_start_offset),
3272 compile_ms); 3308 compile_ms);
3273 } 3309 }
3274 3310
3275 return code; 3311 return code;
3276 } 3312 }
3277 3313
3278 } // namespace compiler 3314 } // namespace compiler
3279 } // namespace internal 3315 } // namespace internal
3280 } // namespace v8 3316 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698