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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 | 10 |
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 } | 983 } |
984 | 984 |
985 Node* WasmGraphBuilder::Float64Constant(double value) { | 985 Node* WasmGraphBuilder::Float64Constant(double value) { |
986 return jsgraph()->Float64Constant(value); | 986 return jsgraph()->Float64Constant(value); |
987 } | 987 } |
988 | 988 |
989 Node* WasmGraphBuilder::HeapConstant(Handle<HeapObject> value) { | 989 Node* WasmGraphBuilder::HeapConstant(Handle<HeapObject> value) { |
990 return jsgraph()->HeapConstant(value); | 990 return jsgraph()->HeapConstant(value); |
991 } | 991 } |
992 | 992 |
993 Node* WasmGraphBuilder::Branch(Node* cond, Node** true_node, | 993 namespace { |
994 Node** false_node) { | 994 Node* Branch(JSGraph* jsgraph, Node* cond, Node** true_node, Node** false_node, |
| 995 Node* control, BranchHint hint) { |
995 DCHECK_NOT_NULL(cond); | 996 DCHECK_NOT_NULL(cond); |
996 DCHECK_NOT_NULL(*control_); | 997 DCHECK_NOT_NULL(control); |
997 Node* branch = | 998 Node* branch = |
998 graph()->NewNode(jsgraph()->common()->Branch(), cond, *control_); | 999 jsgraph->graph()->NewNode(jsgraph->common()->Branch(hint), cond, control); |
999 *true_node = graph()->NewNode(jsgraph()->common()->IfTrue(), branch); | 1000 *true_node = jsgraph->graph()->NewNode(jsgraph->common()->IfTrue(), branch); |
1000 *false_node = graph()->NewNode(jsgraph()->common()->IfFalse(), branch); | 1001 *false_node = jsgraph->graph()->NewNode(jsgraph->common()->IfFalse(), branch); |
1001 return branch; | 1002 return branch; |
1002 } | 1003 } |
| 1004 } // namespace |
| 1005 |
| 1006 Node* WasmGraphBuilder::BranchNoHint(Node* cond, Node** true_node, |
| 1007 Node** false_node) { |
| 1008 return Branch(jsgraph(), cond, true_node, false_node, *control_, |
| 1009 BranchHint::kNone); |
| 1010 } |
| 1011 |
| 1012 Node* WasmGraphBuilder::BranchExpectTrue(Node* cond, Node** true_node, |
| 1013 Node** false_node) { |
| 1014 return Branch(jsgraph(), cond, true_node, false_node, *control_, |
| 1015 BranchHint::kTrue); |
| 1016 } |
| 1017 |
| 1018 Node* WasmGraphBuilder::BranchExpectFalse(Node* cond, Node** true_node, |
| 1019 Node** false_node) { |
| 1020 return Branch(jsgraph(), cond, true_node, false_node, *control_, |
| 1021 BranchHint::kFalse); |
| 1022 } |
1003 | 1023 |
1004 Node* WasmGraphBuilder::Switch(unsigned count, Node* key) { | 1024 Node* WasmGraphBuilder::Switch(unsigned count, Node* key) { |
1005 return graph()->NewNode(jsgraph()->common()->Switch(count), key, *control_); | 1025 return graph()->NewNode(jsgraph()->common()->Switch(count), key, *control_); |
1006 } | 1026 } |
1007 | 1027 |
1008 Node* WasmGraphBuilder::IfValue(int32_t value, Node* sw) { | 1028 Node* WasmGraphBuilder::IfValue(int32_t value, Node* sw) { |
1009 DCHECK_EQ(IrOpcode::kSwitch, sw->opcode()); | 1029 DCHECK_EQ(IrOpcode::kSwitch, sw->opcode()); |
1010 return graph()->NewNode(jsgraph()->common()->IfValue(value), sw); | 1030 return graph()->NewNode(jsgraph()->common()->IfValue(value), sw); |
1011 } | 1031 } |
1012 | 1032 |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 CommonOperatorBuilder* common = jsgraph()->common(); | 1771 CommonOperatorBuilder* common = jsgraph()->common(); |
1752 | 1772 |
1753 Node* parameters[] = {input}; // caught value | 1773 Node* parameters[] = {input}; // caught value |
1754 Node* value = | 1774 Node* value = |
1755 BuildCallToRuntime(Runtime::kWasmGetCaughtExceptionValue, jsgraph(), | 1775 BuildCallToRuntime(Runtime::kWasmGetCaughtExceptionValue, jsgraph(), |
1756 module_->instance->context, parameters, | 1776 module_->instance->context, parameters, |
1757 arraysize(parameters), effect_, *control_); | 1777 arraysize(parameters), effect_, *control_); |
1758 | 1778 |
1759 Node* is_smi; | 1779 Node* is_smi; |
1760 Node* is_heap; | 1780 Node* is_heap; |
1761 Branch(BuildTestNotSmi(value), &is_heap, &is_smi); | 1781 BranchExpectFalse(BuildTestNotSmi(value), &is_heap, &is_smi); |
1762 | 1782 |
1763 // is_smi | 1783 // is_smi |
1764 Node* smi_i32 = BuildChangeSmiToInt32(value); | 1784 Node* smi_i32 = BuildChangeSmiToInt32(value); |
1765 Node* is_smi_effect = *effect_; | 1785 Node* is_smi_effect = *effect_; |
1766 | 1786 |
1767 // is_heap | 1787 // is_heap |
1768 *control_ = is_heap; | 1788 *control_ = is_heap; |
1769 Node* heap_f64 = BuildLoadHeapNumberValue(value, is_heap); | 1789 Node* heap_f64 = BuildLoadHeapNumberValue(value, is_heap); |
1770 | 1790 |
1771 // *control_ needs to point to the current control dependency (is_heap) in | 1791 // *control_ needs to point to the current control dependency (is_heap) in |
(...skipping 19 matching lines...) Expand all Loading... |
1791 return value_i32; | 1811 return value_i32; |
1792 } | 1812 } |
1793 | 1813 |
1794 Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right, | 1814 Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right, |
1795 wasm::WasmCodePosition position) { | 1815 wasm::WasmCodePosition position) { |
1796 MachineOperatorBuilder* m = jsgraph()->machine(); | 1816 MachineOperatorBuilder* m = jsgraph()->machine(); |
1797 trap_->ZeroCheck32(wasm::kTrapDivByZero, right, position); | 1817 trap_->ZeroCheck32(wasm::kTrapDivByZero, right, position); |
1798 Node* before = *control_; | 1818 Node* before = *control_; |
1799 Node* denom_is_m1; | 1819 Node* denom_is_m1; |
1800 Node* denom_is_not_m1; | 1820 Node* denom_is_not_m1; |
1801 Branch( | 1821 BranchExpectFalse( |
1802 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)), | 1822 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)), |
1803 &denom_is_m1, &denom_is_not_m1); | 1823 &denom_is_m1, &denom_is_not_m1); |
1804 *control_ = denom_is_m1; | 1824 *control_ = denom_is_m1; |
1805 trap_->TrapIfEq32(wasm::kTrapDivUnrepresentable, left, kMinInt, position); | 1825 trap_->TrapIfEq32(wasm::kTrapDivUnrepresentable, left, kMinInt, position); |
1806 if (*control_ != denom_is_m1) { | 1826 if (*control_ != denom_is_m1) { |
1807 *control_ = graph()->NewNode(jsgraph()->common()->Merge(2), denom_is_not_m1, | 1827 *control_ = graph()->NewNode(jsgraph()->common()->Merge(2), denom_is_not_m1, |
1808 *control_); | 1828 *control_); |
1809 } else { | 1829 } else { |
1810 *control_ = before; | 1830 *control_ = before; |
1811 } | 1831 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 wasm::WasmCodePosition position) { | 1953 wasm::WasmCodePosition position) { |
1934 if (jsgraph()->machine()->Is32()) { | 1954 if (jsgraph()->machine()->Is32()) { |
1935 return BuildDiv64Call( | 1955 return BuildDiv64Call( |
1936 left, right, ExternalReference::wasm_int64_div(jsgraph()->isolate()), | 1956 left, right, ExternalReference::wasm_int64_div(jsgraph()->isolate()), |
1937 MachineType::Int64(), wasm::kTrapDivByZero, position); | 1957 MachineType::Int64(), wasm::kTrapDivByZero, position); |
1938 } | 1958 } |
1939 trap_->ZeroCheck64(wasm::kTrapDivByZero, right, position); | 1959 trap_->ZeroCheck64(wasm::kTrapDivByZero, right, position); |
1940 Node* before = *control_; | 1960 Node* before = *control_; |
1941 Node* denom_is_m1; | 1961 Node* denom_is_m1; |
1942 Node* denom_is_not_m1; | 1962 Node* denom_is_not_m1; |
1943 Branch(graph()->NewNode(jsgraph()->machine()->Word64Equal(), right, | 1963 BranchExpectFalse(graph()->NewNode(jsgraph()->machine()->Word64Equal(), right, |
1944 jsgraph()->Int64Constant(-1)), | 1964 jsgraph()->Int64Constant(-1)), |
1945 &denom_is_m1, &denom_is_not_m1); | 1965 &denom_is_m1, &denom_is_not_m1); |
1946 *control_ = denom_is_m1; | 1966 *control_ = denom_is_m1; |
1947 trap_->TrapIfEq64(wasm::kTrapDivUnrepresentable, left, | 1967 trap_->TrapIfEq64(wasm::kTrapDivUnrepresentable, left, |
1948 std::numeric_limits<int64_t>::min(), position); | 1968 std::numeric_limits<int64_t>::min(), position); |
1949 if (*control_ != denom_is_m1) { | 1969 if (*control_ != denom_is_m1) { |
1950 *control_ = graph()->NewNode(jsgraph()->common()->Merge(2), denom_is_not_m1, | 1970 *control_ = graph()->NewNode(jsgraph()->common()->Merge(2), denom_is_not_m1, |
1951 *control_); | 1971 *control_); |
1952 } else { | 1972 } else { |
1953 *control_ = before; | 1973 *control_ = before; |
1954 } | 1974 } |
1955 return graph()->NewNode(jsgraph()->machine()->Int64Div(), left, right, | 1975 return graph()->NewNode(jsgraph()->machine()->Int64Div(), left, right, |
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3413 function_->code_start_offset), | 3433 function_->code_start_offset), |
3414 compile_ms); | 3434 compile_ms); |
3415 } | 3435 } |
3416 | 3436 |
3417 return code; | 3437 return code; |
3418 } | 3438 } |
3419 | 3439 |
3420 } // namespace compiler | 3440 } // namespace compiler |
3421 } // namespace internal | 3441 } // namespace internal |
3422 } // namespace v8 | 3442 } // namespace v8 |
OLD | NEW |