| 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 | 5 |
| 6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
| 7 #include "src/compiler/change-lowering.h" | 7 #include "src/compiler/change-lowering.h" |
| 8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
| 9 #include "src/compiler/diamond.h" | 9 #include "src/compiler/diamond.h" |
| 10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 *effect_ptr = node; | 216 *effect_ptr = node; |
| 217 } | 217 } |
| 218 if (false) { | 218 if (false) { |
| 219 // End the control flow with a throw | 219 // End the control flow with a throw |
| 220 Node* thrw = | 220 Node* thrw = |
| 221 graph()->NewNode(common()->Throw(), jsgraph()->ZeroConstant(), | 221 graph()->NewNode(common()->Throw(), jsgraph()->ZeroConstant(), |
| 222 *effect_ptr, *control_ptr); | 222 *effect_ptr, *control_ptr); |
| 223 end = thrw; | 223 end = thrw; |
| 224 } else { | 224 } else { |
| 225 // End the control flow with returning 0xdeadbeef | 225 // End the control flow with returning 0xdeadbeef |
| 226 Node* ret_dead = graph()->NewNode(common()->Return(), | 226 Node* ret_value; |
| 227 jsgraph()->Int32Constant(0xdeadbeef), | 227 if (builder_->GetFunctionSignature()->return_count() > 0) { |
| 228 *effect_ptr, *control_ptr); | 228 switch (builder_->GetFunctionSignature()->GetReturn()) { |
| 229 end = ret_dead; | 229 case wasm::kAstI32: |
| 230 ret_value = jsgraph()->Int32Constant(0xdeadbeef); |
| 231 break; |
| 232 case wasm::kAstI64: |
| 233 ret_value = jsgraph()->Int64Constant(0xdeadbeefdeadbeef); |
| 234 break; |
| 235 case wasm::kAstF32: |
| 236 ret_value = jsgraph()->Float32Constant(bit_cast<float>(0xdeadbeef)); |
| 237 break; |
| 238 case wasm::kAstF64: |
| 239 ret_value = jsgraph()->Float64Constant( |
| 240 bit_cast<double>(0xdeadbeefdeadbeef)); |
| 241 break; |
| 242 default: |
| 243 UNREACHABLE(); |
| 244 ret_value = nullptr; |
| 245 } |
| 246 } else { |
| 247 ret_value = jsgraph()->Int32Constant(0xdeadbeef); |
| 248 } |
| 249 end = graph()->NewNode(jsgraph()->common()->Return(), ret_value, |
| 250 *effect_ptr, *control_ptr); |
| 230 } | 251 } |
| 231 | 252 |
| 232 MergeControlToEnd(jsgraph(), end); | 253 MergeControlToEnd(jsgraph(), end); |
| 233 } | 254 } |
| 234 }; | 255 }; |
| 235 | 256 |
| 236 | 257 |
| 237 WasmGraphBuilder::WasmGraphBuilder(Zone* zone, JSGraph* jsgraph) | 258 WasmGraphBuilder::WasmGraphBuilder(Zone* zone, JSGraph* jsgraph, |
| 259 wasm::FunctionSig* function_signature) |
| 238 : zone_(zone), | 260 : zone_(zone), |
| 239 jsgraph_(jsgraph), | 261 jsgraph_(jsgraph), |
| 240 module_(nullptr), | 262 module_(nullptr), |
| 241 mem_buffer_(nullptr), | 263 mem_buffer_(nullptr), |
| 242 mem_size_(nullptr), | 264 mem_size_(nullptr), |
| 243 function_table_(nullptr), | 265 function_table_(nullptr), |
| 244 control_(nullptr), | 266 control_(nullptr), |
| 245 effect_(nullptr), | 267 effect_(nullptr), |
| 246 cur_buffer_(def_buffer_), | 268 cur_buffer_(def_buffer_), |
| 247 cur_bufsize_(kDefaultBufferSize), | 269 cur_bufsize_(kDefaultBufferSize), |
| 248 trap_(new (zone) WasmTrapHelper(this)) { | 270 trap_(new (zone) WasmTrapHelper(this)), |
| 271 function_signature_(function_signature) { |
| 249 DCHECK_NOT_NULL(jsgraph_); | 272 DCHECK_NOT_NULL(jsgraph_); |
| 250 } | 273 } |
| 251 | 274 |
| 252 | 275 |
| 253 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } | 276 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } |
| 254 | 277 |
| 255 | 278 |
| 256 Node* WasmGraphBuilder::Start(unsigned params) { | 279 Node* WasmGraphBuilder::Start(unsigned params) { |
| 257 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); | 280 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); |
| 258 graph()->SetStart(start); | 281 graph()->SetStart(start); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 break; | 859 break; |
| 837 case wasm::kExprF32UConvertI64: | 860 case wasm::kExprF32UConvertI64: |
| 838 op = m->RoundUint64ToFloat32(); | 861 op = m->RoundUint64ToFloat32(); |
| 839 break; | 862 break; |
| 840 case wasm::kExprF64SConvertI64: | 863 case wasm::kExprF64SConvertI64: |
| 841 op = m->RoundInt64ToFloat64(); | 864 op = m->RoundInt64ToFloat64(); |
| 842 break; | 865 break; |
| 843 case wasm::kExprF64UConvertI64: | 866 case wasm::kExprF64UConvertI64: |
| 844 op = m->RoundUint64ToFloat64(); | 867 op = m->RoundUint64ToFloat64(); |
| 845 break; | 868 break; |
| 869 case wasm::kExprI64SConvertF32: { |
| 870 Node* trunc = graph()->NewNode(m->TryTruncateFloat32ToInt64(), input); |
| 871 Node* result = |
| 872 graph()->NewNode(jsgraph()->common()->Projection(0), trunc); |
| 873 Node* overflow = |
| 874 graph()->NewNode(jsgraph()->common()->Projection(1), trunc); |
| 875 trap_->ZeroCheck64(kTrapFloatUnrepresentable, overflow); |
| 876 return result; |
| 877 } |
| 878 case wasm::kExprI64SConvertF64: { |
| 879 Node* trunc = graph()->NewNode(m->TryTruncateFloat64ToInt64(), input); |
| 880 Node* result = |
| 881 graph()->NewNode(jsgraph()->common()->Projection(0), trunc); |
| 882 Node* overflow = |
| 883 graph()->NewNode(jsgraph()->common()->Projection(1), trunc); |
| 884 trap_->ZeroCheck64(kTrapFloatUnrepresentable, overflow); |
| 885 return result; |
| 886 } |
| 887 case wasm::kExprI64UConvertF32: { |
| 888 Node* trunc = graph()->NewNode(m->TryTruncateFloat32ToUint64(), input); |
| 889 Node* result = |
| 890 graph()->NewNode(jsgraph()->common()->Projection(0), trunc); |
| 891 Node* overflow = |
| 892 graph()->NewNode(jsgraph()->common()->Projection(1), trunc); |
| 893 trap_->ZeroCheck64(kTrapFloatUnrepresentable, overflow); |
| 894 return result; |
| 895 } |
| 896 case wasm::kExprI64UConvertF64: { |
| 897 Node* trunc = graph()->NewNode(m->TryTruncateFloat64ToUint64(), input); |
| 898 Node* result = |
| 899 graph()->NewNode(jsgraph()->common()->Projection(0), trunc); |
| 900 Node* overflow = |
| 901 graph()->NewNode(jsgraph()->common()->Projection(1), trunc); |
| 902 trap_->ZeroCheck64(kTrapFloatUnrepresentable, overflow); |
| 903 return result; |
| 904 } |
| 846 case wasm::kExprF64ReinterpretI64: | 905 case wasm::kExprF64ReinterpretI64: |
| 847 op = m->BitcastInt64ToFloat64(); | 906 op = m->BitcastInt64ToFloat64(); |
| 848 break; | 907 break; |
| 849 case wasm::kExprI64ReinterpretF64: | 908 case wasm::kExprI64ReinterpretF64: |
| 850 op = m->BitcastFloat64ToInt64(); | 909 op = m->BitcastFloat64ToInt64(); |
| 851 break; | 910 break; |
| 852 case wasm::kExprI64Clz: | 911 case wasm::kExprI64Clz: |
| 853 op = m->Word64Clz(); | 912 op = m->Word64Clz(); |
| 854 break; | 913 break; |
| 855 case wasm::kExprI64Ctz: { | 914 case wasm::kExprI64Ctz: { |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 Zone zone; | 1668 Zone zone; |
| 1610 Graph graph(&zone); | 1669 Graph graph(&zone); |
| 1611 CommonOperatorBuilder common(&zone); | 1670 CommonOperatorBuilder common(&zone); |
| 1612 JSOperatorBuilder javascript(&zone); | 1671 JSOperatorBuilder javascript(&zone); |
| 1613 MachineOperatorBuilder machine(&zone); | 1672 MachineOperatorBuilder machine(&zone); |
| 1614 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); | 1673 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); |
| 1615 | 1674 |
| 1616 Node* control = nullptr; | 1675 Node* control = nullptr; |
| 1617 Node* effect = nullptr; | 1676 Node* effect = nullptr; |
| 1618 | 1677 |
| 1619 WasmGraphBuilder builder(&zone, &jsgraph); | 1678 WasmGraphBuilder builder(&zone, &jsgraph, func->sig); |
| 1620 builder.set_control_ptr(&control); | 1679 builder.set_control_ptr(&control); |
| 1621 builder.set_effect_ptr(&effect); | 1680 builder.set_effect_ptr(&effect); |
| 1622 builder.set_module(module); | 1681 builder.set_module(module); |
| 1623 builder.BuildJSToWasmWrapper(wasm_code, func->sig); | 1682 builder.BuildJSToWasmWrapper(wasm_code, func->sig); |
| 1624 | 1683 |
| 1625 //---------------------------------------------------------------------------- | 1684 //---------------------------------------------------------------------------- |
| 1626 // Run the compilation pipeline. | 1685 // Run the compilation pipeline. |
| 1627 //---------------------------------------------------------------------------- | 1686 //---------------------------------------------------------------------------- |
| 1628 { | 1687 { |
| 1629 // Changes lowering requires types. | 1688 // Changes lowering requires types. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 Zone zone; | 1750 Zone zone; |
| 1692 Graph graph(&zone); | 1751 Graph graph(&zone); |
| 1693 CommonOperatorBuilder common(&zone); | 1752 CommonOperatorBuilder common(&zone); |
| 1694 JSOperatorBuilder javascript(&zone); | 1753 JSOperatorBuilder javascript(&zone); |
| 1695 MachineOperatorBuilder machine(&zone); | 1754 MachineOperatorBuilder machine(&zone); |
| 1696 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); | 1755 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); |
| 1697 | 1756 |
| 1698 Node* control = nullptr; | 1757 Node* control = nullptr; |
| 1699 Node* effect = nullptr; | 1758 Node* effect = nullptr; |
| 1700 | 1759 |
| 1701 WasmGraphBuilder builder(&zone, &jsgraph); | 1760 WasmGraphBuilder builder(&zone, &jsgraph, func->sig); |
| 1702 builder.set_control_ptr(&control); | 1761 builder.set_control_ptr(&control); |
| 1703 builder.set_effect_ptr(&effect); | 1762 builder.set_effect_ptr(&effect); |
| 1704 builder.set_module(module); | 1763 builder.set_module(module); |
| 1705 builder.BuildWasmToJSWrapper(function, func->sig); | 1764 builder.BuildWasmToJSWrapper(function, func->sig); |
| 1706 | 1765 |
| 1707 Handle<Code> code = Handle<Code>::null(); | 1766 Handle<Code> code = Handle<Code>::null(); |
| 1708 { | 1767 { |
| 1709 // Changes lowering requires types. | 1768 // Changes lowering requires types. |
| 1710 Typer typer(isolate, &graph); | 1769 Typer typer(isolate, &graph); |
| 1711 NodeVector roots(&zone); | 1770 NodeVector roots(&zone); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 env.SumLocals(); | 1838 env.SumLocals(); |
| 1780 | 1839 |
| 1781 // Create a TF graph during decoding. | 1840 // Create a TF graph during decoding. |
| 1782 Zone zone; | 1841 Zone zone; |
| 1783 Graph graph(&zone); | 1842 Graph graph(&zone); |
| 1784 CommonOperatorBuilder common(&zone); | 1843 CommonOperatorBuilder common(&zone); |
| 1785 MachineOperatorBuilder machine( | 1844 MachineOperatorBuilder machine( |
| 1786 &zone, MachineType::PointerRepresentation(), | 1845 &zone, MachineType::PointerRepresentation(), |
| 1787 InstructionSelector::SupportedMachineOperatorFlags()); | 1846 InstructionSelector::SupportedMachineOperatorFlags()); |
| 1788 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 1847 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
| 1789 WasmGraphBuilder builder(&zone, &jsgraph); | 1848 WasmGraphBuilder builder(&zone, &jsgraph, function.sig); |
| 1790 wasm::TreeResult result = wasm::BuildTFGraph( | 1849 wasm::TreeResult result = wasm::BuildTFGraph( |
| 1791 &builder, &env, // -- | 1850 &builder, &env, // -- |
| 1792 module_env->module->module_start, // -- | 1851 module_env->module->module_start, // -- |
| 1793 module_env->module->module_start + function.code_start_offset, // -- | 1852 module_env->module->module_start + function.code_start_offset, // -- |
| 1794 module_env->module->module_start + function.code_end_offset); // -- | 1853 module_env->module->module_start + function.code_end_offset); // -- |
| 1795 | 1854 |
| 1796 if (result.failed()) { | 1855 if (result.failed()) { |
| 1797 if (FLAG_trace_wasm_compiler) { | 1856 if (FLAG_trace_wasm_compiler) { |
| 1798 OFStream os(stdout); | 1857 OFStream os(stdout); |
| 1799 os << "Compilation failed: " << result << std::endl; | 1858 os << "Compilation failed: " << result << std::endl; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1830 code->Disassemble(buffer, os); | 1889 code->Disassemble(buffer, os); |
| 1831 } | 1890 } |
| 1832 #endif | 1891 #endif |
| 1833 return code; | 1892 return code; |
| 1834 } | 1893 } |
| 1835 | 1894 |
| 1836 | 1895 |
| 1837 } // namespace compiler | 1896 } // namespace compiler |
| 1838 } // namespace internal | 1897 } // namespace internal |
| 1839 } // namespace v8 | 1898 } // namespace v8 |
| OLD | NEW |