| 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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 case wasm::kExprF64Mod: | 621 case wasm::kExprF64Mod: |
| 622 return BuildF64Mod(left, right); | 622 return BuildF64Mod(left, right); |
| 623 case wasm::kExprI32AsmjsDivS: | 623 case wasm::kExprI32AsmjsDivS: |
| 624 return BuildI32AsmjsDivS(left, right); | 624 return BuildI32AsmjsDivS(left, right); |
| 625 case wasm::kExprI32AsmjsDivU: | 625 case wasm::kExprI32AsmjsDivU: |
| 626 return BuildI32AsmjsDivU(left, right); | 626 return BuildI32AsmjsDivU(left, right); |
| 627 case wasm::kExprI32AsmjsRemS: | 627 case wasm::kExprI32AsmjsRemS: |
| 628 return BuildI32AsmjsRemS(left, right); | 628 return BuildI32AsmjsRemS(left, right); |
| 629 case wasm::kExprI32AsmjsRemU: | 629 case wasm::kExprI32AsmjsRemU: |
| 630 return BuildI32AsmjsRemU(left, right); | 630 return BuildI32AsmjsRemU(left, right); |
| 631 case wasm::kExprI32AsmjsStoreMem8: |
| 632 return BuildAsmjsStoreMem(MachineType::Int8(), left, right); |
| 633 case wasm::kExprI32AsmjsStoreMem16: |
| 634 return BuildAsmjsStoreMem(MachineType::Int16(), left, right); |
| 635 case wasm::kExprI32AsmjsStoreMem: |
| 636 return BuildAsmjsStoreMem(MachineType::Int32(), left, right); |
| 637 case wasm::kExprF32AsmjsStoreMem: |
| 638 return BuildAsmjsStoreMem(MachineType::Float32(), left, right); |
| 639 case wasm::kExprF64AsmjsStoreMem: |
| 640 return BuildAsmjsStoreMem(MachineType::Float64(), left, right); |
| 631 default: | 641 default: |
| 632 op = UnsupportedOpcode(opcode); | 642 op = UnsupportedOpcode(opcode); |
| 633 } | 643 } |
| 634 return graph()->NewNode(op, left, right); | 644 return graph()->NewNode(op, left, right); |
| 635 } | 645 } |
| 636 | 646 |
| 637 Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input, | 647 Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input, |
| 638 wasm::WasmCodePosition position) { | 648 wasm::WasmCodePosition position) { |
| 639 const Operator* op; | 649 const Operator* op; |
| 640 MachineOperatorBuilder* m = jsgraph()->machine(); | 650 MachineOperatorBuilder* m = jsgraph()->machine(); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 return BuildF64SConvertI64(input); | 860 return BuildF64SConvertI64(input); |
| 851 } | 861 } |
| 852 op = m->RoundInt64ToFloat64(); | 862 op = m->RoundInt64ToFloat64(); |
| 853 break; | 863 break; |
| 854 case wasm::kExprF64UConvertI64: | 864 case wasm::kExprF64UConvertI64: |
| 855 if (m->Is32()) { | 865 if (m->Is32()) { |
| 856 return BuildF64UConvertI64(input); | 866 return BuildF64UConvertI64(input); |
| 857 } | 867 } |
| 858 op = m->RoundUint64ToFloat64(); | 868 op = m->RoundUint64ToFloat64(); |
| 859 break; | 869 break; |
| 860 case wasm::kExprI64SConvertF32: { | 870 case wasm::kExprI64SConvertF32: |
| 861 return BuildI64SConvertF32(input, position); | 871 return BuildI64SConvertF32(input, position); |
| 862 } | 872 case wasm::kExprI64SConvertF64: |
| 863 case wasm::kExprI64SConvertF64: { | |
| 864 return BuildI64SConvertF64(input, position); | 873 return BuildI64SConvertF64(input, position); |
| 865 } | 874 case wasm::kExprI64UConvertF32: |
| 866 case wasm::kExprI64UConvertF32: { | |
| 867 return BuildI64UConvertF32(input, position); | 875 return BuildI64UConvertF32(input, position); |
| 868 } | 876 case wasm::kExprI64UConvertF64: |
| 869 case wasm::kExprI64UConvertF64: { | |
| 870 return BuildI64UConvertF64(input, position); | 877 return BuildI64UConvertF64(input, position); |
| 871 } | 878 case wasm::kExprI32AsmjsLoadMem8S: |
| 879 return BuildAsmjsLoadMem(MachineType::Int8(), input); |
| 880 case wasm::kExprI32AsmjsLoadMem8U: |
| 881 return BuildAsmjsLoadMem(MachineType::Uint8(), input); |
| 882 case wasm::kExprI32AsmjsLoadMem16S: |
| 883 return BuildAsmjsLoadMem(MachineType::Int16(), input); |
| 884 case wasm::kExprI32AsmjsLoadMem16U: |
| 885 return BuildAsmjsLoadMem(MachineType::Uint16(), input); |
| 886 case wasm::kExprI32AsmjsLoadMem: |
| 887 return BuildAsmjsLoadMem(MachineType::Int32(), input); |
| 888 case wasm::kExprF32AsmjsLoadMem: |
| 889 return BuildAsmjsLoadMem(MachineType::Float32(), input); |
| 890 case wasm::kExprF64AsmjsLoadMem: |
| 891 return BuildAsmjsLoadMem(MachineType::Float64(), input); |
| 872 default: | 892 default: |
| 873 op = UnsupportedOpcode(opcode); | 893 op = UnsupportedOpcode(opcode); |
| 874 } | 894 } |
| 875 return graph()->NewNode(op, input); | 895 return graph()->NewNode(op, input); |
| 876 } | 896 } |
| 877 | 897 |
| 878 | 898 |
| 879 Node* WasmGraphBuilder::Float32Constant(float value) { | 899 Node* WasmGraphBuilder::Float32Constant(float value) { |
| 880 return jsgraph()->Float32Constant(value); | 900 return jsgraph()->Float32Constant(value); |
| 881 } | 901 } |
| (...skipping 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2624 jsgraph()->machine()->Uint32LessThanOrEqual(), index, | 2644 jsgraph()->machine()->Uint32LessThanOrEqual(), index, |
| 2625 jsgraph()->Int32Constant(static_cast<uint32_t>(effective_size))); | 2645 jsgraph()->Int32Constant(static_cast<uint32_t>(effective_size))); |
| 2626 | 2646 |
| 2627 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2647 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
| 2628 } | 2648 } |
| 2629 | 2649 |
| 2630 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, | 2650 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, |
| 2631 Node* index, uint32_t offset, | 2651 Node* index, uint32_t offset, |
| 2632 wasm::WasmCodePosition position) { | 2652 wasm::WasmCodePosition position) { |
| 2633 Node* load; | 2653 Node* load; |
| 2634 | 2654 // WASM semantics throw on OOB. Introduce explicit bounds check. |
| 2635 if (module_ && module_->asm_js()) { | 2655 BoundsCheckMem(memtype, index, offset, position); |
| 2636 // asm.js semantics use CheckedLoad (i.e. OOB reads return 0ish). | 2656 load = graph()->NewNode(jsgraph()->machine()->Load(memtype), |
| 2637 DCHECK_EQ(0, offset); | 2657 MemBuffer(offset), index, *effect_, *control_); |
| 2638 const Operator* op = jsgraph()->machine()->CheckedLoad(memtype); | |
| 2639 load = graph()->NewNode(op, MemBuffer(0), index, MemSize(0), *effect_, | |
| 2640 *control_); | |
| 2641 } else { | |
| 2642 // WASM semantics throw on OOB. Introduce explicit bounds check. | |
| 2643 BoundsCheckMem(memtype, index, offset, position); | |
| 2644 load = graph()->NewNode(jsgraph()->machine()->Load(memtype), | |
| 2645 MemBuffer(offset), index, *effect_, *control_); | |
| 2646 } | |
| 2647 | 2658 |
| 2648 *effect_ = load; | 2659 *effect_ = load; |
| 2649 | 2660 |
| 2650 if (type == wasm::kAstI64 && | 2661 if (type == wasm::kAstI64 && |
| 2651 ElementSizeLog2Of(memtype.representation()) < 3) { | 2662 ElementSizeLog2Of(memtype.representation()) < 3) { |
| 2652 // TODO(titzer): TF zeroes the upper bits of 64-bit loads for subword sizes. | 2663 // TODO(titzer): TF zeroes the upper bits of 64-bit loads for subword sizes. |
| 2653 if (memtype.IsSigned()) { | 2664 if (memtype.IsSigned()) { |
| 2654 // sign extend | 2665 // sign extend |
| 2655 load = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), load); | 2666 load = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), load); |
| 2656 } else { | 2667 } else { |
| 2657 // zero extend | 2668 // zero extend |
| 2658 load = | 2669 load = |
| 2659 graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), load); | 2670 graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), load); |
| 2660 } | 2671 } |
| 2661 } | 2672 } |
| 2662 | 2673 |
| 2663 return load; | 2674 return load; |
| 2664 } | 2675 } |
| 2665 | 2676 |
| 2666 Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index, | 2677 Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index, |
| 2667 uint32_t offset, Node* val, | 2678 uint32_t offset, Node* val, |
| 2668 wasm::WasmCodePosition position) { | 2679 wasm::WasmCodePosition position) { |
| 2669 Node* store; | 2680 Node* store; |
| 2670 if (module_ && module_->asm_js()) { | 2681 // WASM semantics throw on OOB. Introduce explicit bounds check. |
| 2671 // asm.js semantics use CheckedStore (i.e. ignore OOB writes). | 2682 BoundsCheckMem(memtype, index, offset, position); |
| 2672 DCHECK_EQ(0, offset); | 2683 StoreRepresentation rep(memtype.representation(), kNoWriteBarrier); |
| 2673 const Operator* op = | 2684 store = graph()->NewNode(jsgraph()->machine()->Store(rep), MemBuffer(offset), |
| 2674 jsgraph()->machine()->CheckedStore(memtype.representation()); | 2685 index, val, *effect_, *control_); |
| 2675 store = graph()->NewNode(op, MemBuffer(0), index, MemSize(0), val, *effect_, | |
| 2676 *control_); | |
| 2677 } else { | |
| 2678 // WASM semantics throw on OOB. Introduce explicit bounds check. | |
| 2679 BoundsCheckMem(memtype, index, offset, position); | |
| 2680 StoreRepresentation rep(memtype.representation(), kNoWriteBarrier); | |
| 2681 store = | |
| 2682 graph()->NewNode(jsgraph()->machine()->Store(rep), MemBuffer(offset), | |
| 2683 index, val, *effect_, *control_); | |
| 2684 } | |
| 2685 *effect_ = store; | 2686 *effect_ = store; |
| 2686 return store; | 2687 return store; |
| 2687 } | 2688 } |
| 2688 | 2689 |
| 2690 Node* WasmGraphBuilder::BuildAsmjsLoadMem(MachineType type, Node* index) { |
| 2691 // TODO(turbofan): fold bounds checks for constant asm.js loads. |
| 2692 // asm.js semantics use CheckedLoad (i.e. OOB reads return 0ish). |
| 2693 const Operator* op = jsgraph()->machine()->CheckedLoad(type); |
| 2694 Node* load = graph()->NewNode(op, MemBuffer(0), index, MemSize(0), *effect_, |
| 2695 *control_); |
| 2696 *effect_ = load; |
| 2697 return load; |
| 2698 } |
| 2699 |
| 2700 Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index, |
| 2701 Node* val) { |
| 2702 // TODO(turbofan): fold bounds checks for constant asm.js stores. |
| 2703 // asm.js semantics use CheckedStore (i.e. ignore OOB writes). |
| 2704 const Operator* op = |
| 2705 jsgraph()->machine()->CheckedStore(type.representation()); |
| 2706 Node* store = graph()->NewNode(op, MemBuffer(0), index, MemSize(0), val, |
| 2707 *effect_, *control_); |
| 2708 *effect_ = store; |
| 2709 return val; |
| 2710 } |
| 2689 | 2711 |
| 2690 void WasmGraphBuilder::PrintDebugName(Node* node) { | 2712 void WasmGraphBuilder::PrintDebugName(Node* node) { |
| 2691 PrintF("#%d:%s", node->id(), node->op()->mnemonic()); | 2713 PrintF("#%d:%s", node->id(), node->op()->mnemonic()); |
| 2692 } | 2714 } |
| 2693 | 2715 |
| 2694 | 2716 |
| 2695 Node* WasmGraphBuilder::String(const char* string) { | 2717 Node* WasmGraphBuilder::String(const char* string) { |
| 2696 return jsgraph()->Constant( | 2718 return jsgraph()->Constant( |
| 2697 jsgraph()->isolate()->factory()->NewStringFromAsciiChecked(string)); | 2719 jsgraph()->isolate()->factory()->NewStringFromAsciiChecked(string)); |
| 2698 } | 2720 } |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3108 const wasm::WasmFunction* function) { | 3130 const wasm::WasmFunction* function) { |
| 3109 WasmCompilationUnit* unit = | 3131 WasmCompilationUnit* unit = |
| 3110 CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0); | 3132 CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0); |
| 3111 ExecuteCompilation(unit); | 3133 ExecuteCompilation(unit); |
| 3112 return FinishCompilation(unit); | 3134 return FinishCompilation(unit); |
| 3113 } | 3135 } |
| 3114 | 3136 |
| 3115 } // namespace compiler | 3137 } // namespace compiler |
| 3116 } // namespace internal | 3138 } // namespace internal |
| 3117 } // namespace v8 | 3139 } // namespace v8 |
| OLD | NEW |