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 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 *control_ptr = graph()->NewNode(jsgraph()->common()->Merge(1), *control_ptr); | |
ahaas
2016/06/27 15:08:25
why do you create a Merge and an EffectPhi node he
gdeepti
2016/06/27 19:18:54
I misunderstood how control/effect pointers should
| |
1586 *effect_ptr = graph()->NewNode(jsgraph()->common()->EffectPhi(1), *effect_ptr, | |
1587 *control_ptr); | |
1588 input = BuildChangeUint32ToSmi(input); | |
1589 Node* inputs[] = { | |
1590 jsgraph()->CEntryStubConstant(function->result_size), input, // C entry | |
1591 jsgraph()->ExternalConstant( | |
1592 ExternalReference(function_id, jsgraph()->isolate())), // ref | |
1593 jsgraph()->Int32Constant(function->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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2276 Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) { | 2307 Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) { |
2277 value = graph()->NewNode(jsgraph()->machine()->WordSar(), value, | 2308 value = graph()->NewNode(jsgraph()->machine()->WordSar(), value, |
2278 BuildSmiShiftBitsConstant()); | 2309 BuildSmiShiftBitsConstant()); |
2279 if (jsgraph()->machine()->Is64()) { | 2310 if (jsgraph()->machine()->Is64()) { |
2280 value = | 2311 value = |
2281 graph()->NewNode(jsgraph()->machine()->TruncateInt64ToInt32(), value); | 2312 graph()->NewNode(jsgraph()->machine()->TruncateInt64ToInt32(), value); |
2282 } | 2313 } |
2283 return value; | 2314 return value; |
2284 } | 2315 } |
2285 | 2316 |
2317 Node* WasmGraphBuilder::BuildChangeUint32ToSmi(Node* value) { | |
2318 if (jsgraph()->machine()->Is64()) { | |
2319 value = | |
2320 graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), value); | |
2321 } | |
2322 return graph()->NewNode(jsgraph()->machine()->WordShl(), value, | |
2323 BuildSmiShiftBitsConstant()); | |
2324 } | |
2325 | |
2286 Node* WasmGraphBuilder::BuildChangeSmiToFloat64(Node* value) { | 2326 Node* WasmGraphBuilder::BuildChangeSmiToFloat64(Node* value) { |
2287 return graph()->NewNode(jsgraph()->machine()->ChangeInt32ToFloat64(), | 2327 return graph()->NewNode(jsgraph()->machine()->ChangeInt32ToFloat64(), |
2288 BuildChangeSmiToInt32(value)); | 2328 BuildChangeSmiToInt32(value)); |
2289 } | 2329 } |
2290 | 2330 |
2291 Node* WasmGraphBuilder::BuildTestNotSmi(Node* value) { | 2331 Node* WasmGraphBuilder::BuildTestNotSmi(Node* value) { |
2292 STATIC_ASSERT(kSmiTag == 0); | 2332 STATIC_ASSERT(kSmiTag == 0); |
2293 STATIC_ASSERT(kSmiTagMask == 1); | 2333 STATIC_ASSERT(kSmiTagMask == 1); |
2294 return graph()->NewNode(jsgraph()->machine()->WordAnd(), value, | 2334 return graph()->NewNode(jsgraph()->machine()->WordAnd(), value, |
2295 jsgraph()->IntPtrConstant(kSmiTagMask)); | 2335 jsgraph()->IntPtrConstant(kSmiTagMask)); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2581 if (value < effective_size) { | 2621 if (value < effective_size) { |
2582 // The bounds check will always succeed. | 2622 // The bounds check will always succeed. |
2583 return; | 2623 return; |
2584 } | 2624 } |
2585 } | 2625 } |
2586 | 2626 |
2587 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, | 2627 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, |
2588 jsgraph()->RelocatableInt32Constant( | 2628 jsgraph()->RelocatableInt32Constant( |
2589 static_cast<uint32_t>(effective_size), | 2629 static_cast<uint32_t>(effective_size), |
2590 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); | 2630 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
2591 | |
2592 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2631 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
2593 } | 2632 } |
2594 | 2633 |
2595 MachineType WasmGraphBuilder::GetTypeForUnalignedAccess(uint32_t alignment, | 2634 MachineType WasmGraphBuilder::GetTypeForUnalignedAccess(uint32_t alignment, |
2596 bool signExtend) { | 2635 bool signExtend) { |
2597 switch (alignment) { | 2636 switch (alignment) { |
2598 case 0: | 2637 case 0: |
2599 return signExtend ? MachineType::Int8() : MachineType::Uint8(); | 2638 return signExtend ? MachineType::Int8() : MachineType::Uint8(); |
2600 case 1: | 2639 case 1: |
2601 return signExtend ? MachineType::Int16() : MachineType::Uint16(); | 2640 return signExtend ? MachineType::Int16() : MachineType::Uint16(); |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3271 function_->code_start_offset), | 3310 function_->code_start_offset), |
3272 compile_ms); | 3311 compile_ms); |
3273 } | 3312 } |
3274 | 3313 |
3275 return code; | 3314 return code; |
3276 } | 3315 } |
3277 | 3316 |
3278 } // namespace compiler | 3317 } // namespace compiler |
3279 } // namespace internal | 3318 } // namespace internal |
3280 } // namespace v8 | 3319 } // namespace v8 |
OLD | NEW |