Chromium Code Reviews| 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 |
| 227 Node* ret_dead; | |
| 228 if (builder_->GetFunctionSignature()->return_count() > 0) { | |
| 229 switch (builder_->GetFunctionSignature()->GetReturn()) { | |
| 230 case wasm::kAstI32: | |
| 231 ret_dead = graph()->NewNode(jsgraph()->common()->Return(), | |
|
titzer
2015/12/11 13:49:26
You can just make the return value node in these c
| |
| 227 jsgraph()->Int32Constant(0xdeadbeef), | 232 jsgraph()->Int32Constant(0xdeadbeef), |
| 228 *effect_ptr, *control_ptr); | 233 *effect_ptr, *control_ptr); |
| 234 break; | |
| 235 case wasm::kAstI64: | |
| 236 ret_dead = | |
| 237 graph()->NewNode(jsgraph()->common()->Return(), | |
| 238 jsgraph()->Int64Constant(0xdeadbeefdeadbeef), | |
| 239 *effect_ptr, *control_ptr); | |
| 240 break; | |
| 241 case wasm::kAstF32: | |
| 242 ret_dead = graph()->NewNode( | |
| 243 jsgraph()->common()->Return(), | |
| 244 jsgraph()->Float32Constant(bit_cast<float>(0xdeadbeef)), | |
| 245 *effect_ptr, *control_ptr); | |
| 246 break; | |
| 247 case wasm::kAstF64: | |
| 248 ret_dead = | |
| 249 graph()->NewNode(jsgraph()->common()->Return(), | |
| 250 jsgraph()->Float64Constant( | |
| 251 bit_cast<double>(0xdeadbeefdeadbeef)), | |
| 252 *effect_ptr, *control_ptr); | |
| 253 break; | |
| 254 default: | |
| 255 UNREACHABLE(); | |
| 256 ret_dead = nullptr; | |
| 257 } | |
| 258 } else { | |
| 259 ret_dead = graph()->NewNode(common()->Return(), | |
| 260 jsgraph()->Int32Constant(0xdeadbeef), | |
| 261 *effect_ptr, *control_ptr); | |
| 262 } | |
| 229 end = ret_dead; | 263 end = ret_dead; |
| 230 } | 264 } |
| 231 | 265 |
| 232 MergeControlToEnd(jsgraph(), end); | 266 MergeControlToEnd(jsgraph(), end); |
| 233 } | 267 } |
| 234 }; | 268 }; |
| 235 | 269 |
| 236 | 270 |
| 237 WasmGraphBuilder::WasmGraphBuilder(Zone* zone, JSGraph* jsgraph) | 271 WasmGraphBuilder::WasmGraphBuilder(Zone* zone, JSGraph* jsgraph, |
| 272 wasm::FunctionSig* function_signature) | |
| 238 : zone_(zone), | 273 : zone_(zone), |
| 239 jsgraph_(jsgraph), | 274 jsgraph_(jsgraph), |
| 240 module_(nullptr), | 275 module_(nullptr), |
| 241 mem_buffer_(nullptr), | 276 mem_buffer_(nullptr), |
| 242 mem_size_(nullptr), | 277 mem_size_(nullptr), |
| 243 function_table_(nullptr), | 278 function_table_(nullptr), |
| 244 control_(nullptr), | 279 control_(nullptr), |
| 245 effect_(nullptr), | 280 effect_(nullptr), |
| 246 cur_buffer_(def_buffer_), | 281 cur_buffer_(def_buffer_), |
| 247 cur_bufsize_(kDefaultBufferSize), | 282 cur_bufsize_(kDefaultBufferSize), |
| 248 trap_(new (zone) WasmTrapHelper(this)) { | 283 trap_(new (zone) WasmTrapHelper(this)), |
| 284 function_signature_(function_signature) { | |
| 249 DCHECK_NOT_NULL(jsgraph_); | 285 DCHECK_NOT_NULL(jsgraph_); |
| 250 } | 286 } |
| 251 | 287 |
| 252 | 288 |
| 253 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } | 289 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } |
| 254 | 290 |
| 255 | 291 |
| 256 Node* WasmGraphBuilder::Start(unsigned params) { | 292 Node* WasmGraphBuilder::Start(unsigned params) { |
| 257 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); | 293 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); |
| 258 graph()->SetStart(start); | 294 graph()->SetStart(start); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 break; | 872 break; |
| 837 case wasm::kExprF32UConvertI64: | 873 case wasm::kExprF32UConvertI64: |
| 838 op = m->RoundUint64ToFloat32(); | 874 op = m->RoundUint64ToFloat32(); |
| 839 break; | 875 break; |
| 840 case wasm::kExprF64SConvertI64: | 876 case wasm::kExprF64SConvertI64: |
| 841 op = m->RoundInt64ToFloat64(); | 877 op = m->RoundInt64ToFloat64(); |
| 842 break; | 878 break; |
| 843 case wasm::kExprF64UConvertI64: | 879 case wasm::kExprF64UConvertI64: |
| 844 op = m->RoundUint64ToFloat64(); | 880 op = m->RoundUint64ToFloat64(); |
| 845 break; | 881 break; |
| 882 case wasm::kExprI64SConvertF32: { | |
| 883 Node* trunc = graph()->NewNode(m->TryTruncateFloat32ToInt64(), input); | |
| 884 Node* result = | |
| 885 graph()->NewNode(jsgraph()->common()->Projection(0), trunc); | |
| 886 Node* overflow = | |
| 887 graph()->NewNode(jsgraph()->common()->Projection(1), trunc); | |
| 888 trap_->ZeroCheck64(kTrapFloatUnrepresentable, overflow); | |
| 889 return result; | |
| 890 } | |
| 891 case wasm::kExprI64SConvertF64: { | |
| 892 Node* trunc = graph()->NewNode(m->TryTruncateFloat64ToInt64(), input); | |
| 893 Node* result = | |
| 894 graph()->NewNode(jsgraph()->common()->Projection(0), trunc); | |
| 895 Node* overflow = | |
| 896 graph()->NewNode(jsgraph()->common()->Projection(1), trunc); | |
| 897 trap_->ZeroCheck64(kTrapFloatUnrepresentable, overflow); | |
| 898 return result; | |
| 899 } | |
| 900 case wasm::kExprI64UConvertF32: { | |
| 901 Node* trunc = graph()->NewNode(m->TryTruncateFloat32ToUint64(), input); | |
| 902 Node* result = | |
| 903 graph()->NewNode(jsgraph()->common()->Projection(0), trunc); | |
| 904 Node* overflow = | |
| 905 graph()->NewNode(jsgraph()->common()->Projection(1), trunc); | |
| 906 trap_->ZeroCheck64(kTrapFloatUnrepresentable, overflow); | |
| 907 return result; | |
| 908 } | |
| 909 case wasm::kExprI64UConvertF64: { | |
| 910 Node* trunc = graph()->NewNode(m->TryTruncateFloat64ToUint64(), input); | |
| 911 Node* result = | |
| 912 graph()->NewNode(jsgraph()->common()->Projection(0), trunc); | |
| 913 Node* overflow = | |
| 914 graph()->NewNode(jsgraph()->common()->Projection(1), trunc); | |
| 915 trap_->ZeroCheck64(kTrapFloatUnrepresentable, overflow); | |
| 916 return result; | |
| 917 } | |
| 846 case wasm::kExprF64ReinterpretI64: | 918 case wasm::kExprF64ReinterpretI64: |
| 847 op = m->BitcastInt64ToFloat64(); | 919 op = m->BitcastInt64ToFloat64(); |
| 848 break; | 920 break; |
| 849 case wasm::kExprI64ReinterpretF64: | 921 case wasm::kExprI64ReinterpretF64: |
| 850 op = m->BitcastFloat64ToInt64(); | 922 op = m->BitcastFloat64ToInt64(); |
| 851 break; | 923 break; |
| 852 case wasm::kExprI64Clz: | 924 case wasm::kExprI64Clz: |
| 853 op = m->Word64Clz(); | 925 op = m->Word64Clz(); |
| 854 break; | 926 break; |
| 855 case wasm::kExprI64Ctz: { | 927 case wasm::kExprI64Ctz: { |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1609 Zone zone; | 1681 Zone zone; |
| 1610 Graph graph(&zone); | 1682 Graph graph(&zone); |
| 1611 CommonOperatorBuilder common(&zone); | 1683 CommonOperatorBuilder common(&zone); |
| 1612 JSOperatorBuilder javascript(&zone); | 1684 JSOperatorBuilder javascript(&zone); |
| 1613 MachineOperatorBuilder machine(&zone); | 1685 MachineOperatorBuilder machine(&zone); |
| 1614 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); | 1686 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); |
| 1615 | 1687 |
| 1616 Node* control = nullptr; | 1688 Node* control = nullptr; |
| 1617 Node* effect = nullptr; | 1689 Node* effect = nullptr; |
| 1618 | 1690 |
| 1619 WasmGraphBuilder builder(&zone, &jsgraph); | 1691 WasmGraphBuilder builder(&zone, &jsgraph, func->sig); |
| 1620 builder.set_control_ptr(&control); | 1692 builder.set_control_ptr(&control); |
| 1621 builder.set_effect_ptr(&effect); | 1693 builder.set_effect_ptr(&effect); |
| 1622 builder.set_module(module); | 1694 builder.set_module(module); |
| 1623 builder.BuildJSToWasmWrapper(wasm_code, func->sig); | 1695 builder.BuildJSToWasmWrapper(wasm_code, func->sig); |
| 1624 | 1696 |
| 1625 //---------------------------------------------------------------------------- | 1697 //---------------------------------------------------------------------------- |
| 1626 // Run the compilation pipeline. | 1698 // Run the compilation pipeline. |
| 1627 //---------------------------------------------------------------------------- | 1699 //---------------------------------------------------------------------------- |
| 1628 { | 1700 { |
| 1629 // Changes lowering requires types. | 1701 // Changes lowering requires types. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1691 Zone zone; | 1763 Zone zone; |
| 1692 Graph graph(&zone); | 1764 Graph graph(&zone); |
| 1693 CommonOperatorBuilder common(&zone); | 1765 CommonOperatorBuilder common(&zone); |
| 1694 JSOperatorBuilder javascript(&zone); | 1766 JSOperatorBuilder javascript(&zone); |
| 1695 MachineOperatorBuilder machine(&zone); | 1767 MachineOperatorBuilder machine(&zone); |
| 1696 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); | 1768 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); |
| 1697 | 1769 |
| 1698 Node* control = nullptr; | 1770 Node* control = nullptr; |
| 1699 Node* effect = nullptr; | 1771 Node* effect = nullptr; |
| 1700 | 1772 |
| 1701 WasmGraphBuilder builder(&zone, &jsgraph); | 1773 WasmGraphBuilder builder(&zone, &jsgraph, func->sig); |
| 1702 builder.set_control_ptr(&control); | 1774 builder.set_control_ptr(&control); |
| 1703 builder.set_effect_ptr(&effect); | 1775 builder.set_effect_ptr(&effect); |
| 1704 builder.set_module(module); | 1776 builder.set_module(module); |
| 1705 builder.BuildWasmToJSWrapper(function, func->sig); | 1777 builder.BuildWasmToJSWrapper(function, func->sig); |
| 1706 | 1778 |
| 1707 Handle<Code> code = Handle<Code>::null(); | 1779 Handle<Code> code = Handle<Code>::null(); |
| 1708 { | 1780 { |
| 1709 // Changes lowering requires types. | 1781 // Changes lowering requires types. |
| 1710 Typer typer(isolate, &graph); | 1782 Typer typer(isolate, &graph); |
| 1711 NodeVector roots(&zone); | 1783 NodeVector roots(&zone); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1779 env.SumLocals(); | 1851 env.SumLocals(); |
| 1780 | 1852 |
| 1781 // Create a TF graph during decoding. | 1853 // Create a TF graph during decoding. |
| 1782 Zone zone; | 1854 Zone zone; |
| 1783 Graph graph(&zone); | 1855 Graph graph(&zone); |
| 1784 CommonOperatorBuilder common(&zone); | 1856 CommonOperatorBuilder common(&zone); |
| 1785 MachineOperatorBuilder machine( | 1857 MachineOperatorBuilder machine( |
| 1786 &zone, MachineType::PointerRepresentation(), | 1858 &zone, MachineType::PointerRepresentation(), |
| 1787 InstructionSelector::SupportedMachineOperatorFlags()); | 1859 InstructionSelector::SupportedMachineOperatorFlags()); |
| 1788 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 1860 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
| 1789 WasmGraphBuilder builder(&zone, &jsgraph); | 1861 WasmGraphBuilder builder(&zone, &jsgraph, function.sig); |
| 1790 wasm::TreeResult result = wasm::BuildTFGraph( | 1862 wasm::TreeResult result = wasm::BuildTFGraph( |
| 1791 &builder, &env, // -- | 1863 &builder, &env, // -- |
| 1792 module_env->module->module_start, // -- | 1864 module_env->module->module_start, // -- |
| 1793 module_env->module->module_start + function.code_start_offset, // -- | 1865 module_env->module->module_start + function.code_start_offset, // -- |
| 1794 module_env->module->module_start + function.code_end_offset); // -- | 1866 module_env->module->module_start + function.code_end_offset); // -- |
| 1795 | 1867 |
| 1796 if (result.failed()) { | 1868 if (result.failed()) { |
| 1797 if (FLAG_trace_wasm_compiler) { | 1869 if (FLAG_trace_wasm_compiler) { |
| 1798 OFStream os(stdout); | 1870 OFStream os(stdout); |
| 1799 os << "Compilation failed: " << result << std::endl; | 1871 os << "Compilation failed: " << result << std::endl; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1830 code->Disassemble(buffer, os); | 1902 code->Disassemble(buffer, os); |
| 1831 } | 1903 } |
| 1832 #endif | 1904 #endif |
| 1833 return code; | 1905 return code; |
| 1834 } | 1906 } |
| 1835 | 1907 |
| 1836 | 1908 |
| 1837 } // namespace compiler | 1909 } // namespace compiler |
| 1838 } // namespace internal | 1910 } // namespace internal |
| 1839 } // namespace v8 | 1911 } // namespace v8 |
| OLD | NEW |