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/platform.h" | 9 #include "src/base/platform/platform.h" |
10 | 10 |
11 #include "src/compiler/access-builder.h" | 11 #include "src/compiler/access-builder.h" |
12 #include "src/compiler/change-lowering.h" | 12 #include "src/compiler/change-lowering.h" |
13 #include "src/compiler/common-operator.h" | 13 #include "src/compiler/common-operator.h" |
14 #include "src/compiler/diamond.h" | 14 #include "src/compiler/diamond.h" |
15 #include "src/compiler/graph.h" | 15 #include "src/compiler/graph.h" |
16 #include "src/compiler/graph-visualizer.h" | 16 #include "src/compiler/graph-visualizer.h" |
17 #include "src/compiler/instruction-selector.h" | 17 #include "src/compiler/instruction-selector.h" |
| 18 #include "src/compiler/int64-lowering.h" |
18 #include "src/compiler/js-generic-lowering.h" | 19 #include "src/compiler/js-generic-lowering.h" |
19 #include "src/compiler/js-graph.h" | 20 #include "src/compiler/js-graph.h" |
20 #include "src/compiler/js-operator.h" | 21 #include "src/compiler/js-operator.h" |
21 #include "src/compiler/linkage.h" | 22 #include "src/compiler/linkage.h" |
22 #include "src/compiler/machine-operator.h" | 23 #include "src/compiler/machine-operator.h" |
23 #include "src/compiler/node-matchers.h" | 24 #include "src/compiler/node-matchers.h" |
24 #include "src/compiler/pipeline.h" | 25 #include "src/compiler/pipeline.h" |
25 #include "src/compiler/simplified-lowering.h" | 26 #include "src/compiler/simplified-lowering.h" |
26 #include "src/compiler/simplified-operator.h" | 27 #include "src/compiler/simplified-operator.h" |
27 #include "src/compiler/source-position.h" | 28 #include "src/compiler/source-position.h" |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 std::swap(left, right); | 475 std::swap(left, right); |
475 break; | 476 break; |
476 case wasm::kExprI32GtU: | 477 case wasm::kExprI32GtU: |
477 op = m->Uint32LessThan(); | 478 op = m->Uint32LessThan(); |
478 std::swap(left, right); | 479 std::swap(left, right); |
479 break; | 480 break; |
480 case wasm::kExprI32GeU: | 481 case wasm::kExprI32GeU: |
481 op = m->Uint32LessThanOrEqual(); | 482 op = m->Uint32LessThanOrEqual(); |
482 std::swap(left, right); | 483 std::swap(left, right); |
483 break; | 484 break; |
| 485 case wasm::kExprI64And: |
| 486 op = m->Word64And(); |
| 487 break; |
484 #if WASM_64 | 488 #if WASM_64 |
485 // Opcodes only supported on 64-bit platforms. | 489 // Opcodes only supported on 64-bit platforms. |
486 // TODO(titzer): query the machine operator builder here instead of #ifdef. | 490 // TODO(titzer): query the machine operator builder here instead of #ifdef. |
487 case wasm::kExprI64Add: | 491 case wasm::kExprI64Add: |
488 op = m->Int64Add(); | 492 op = m->Int64Add(); |
489 break; | 493 break; |
490 case wasm::kExprI64Sub: | 494 case wasm::kExprI64Sub: |
491 op = m->Int64Sub(); | 495 op = m->Int64Sub(); |
492 break; | 496 break; |
493 case wasm::kExprI64Mul: | 497 case wasm::kExprI64Mul: |
(...skipping 30 matching lines...) Expand all Loading... |
524 | 528 |
525 Node* rem = graph()->NewNode(m->Int64Mod(), left, right, d.if_false); | 529 Node* rem = graph()->NewNode(m->Int64Mod(), left, right, d.if_false); |
526 | 530 |
527 return d.Phi(MachineRepresentation::kWord64, jsgraph()->Int64Constant(0), | 531 return d.Phi(MachineRepresentation::kWord64, jsgraph()->Int64Constant(0), |
528 rem); | 532 rem); |
529 } | 533 } |
530 case wasm::kExprI64RemU: | 534 case wasm::kExprI64RemU: |
531 op = m->Uint64Mod(); | 535 op = m->Uint64Mod(); |
532 return graph()->NewNode(op, left, right, | 536 return graph()->NewNode(op, left, right, |
533 trap_->ZeroCheck64(kTrapRemByZero, right)); | 537 trap_->ZeroCheck64(kTrapRemByZero, right)); |
534 case wasm::kExprI64And: | |
535 op = m->Word64And(); | |
536 break; | |
537 case wasm::kExprI64Ior: | 538 case wasm::kExprI64Ior: |
538 op = m->Word64Or(); | 539 op = m->Word64Or(); |
539 break; | 540 break; |
540 case wasm::kExprI64Xor: | 541 case wasm::kExprI64Xor: |
541 op = m->Word64Xor(); | 542 op = m->Word64Xor(); |
542 break; | 543 break; |
543 case wasm::kExprI64Shl: | 544 case wasm::kExprI64Shl: |
544 op = m->Word64Shl(); | 545 op = m->Word64Shl(); |
545 break; | 546 break; |
546 case wasm::kExprI64ShrU: | 547 case wasm::kExprI64ShrU: |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 if (!m->Float64RoundTruncate().IsSupported()) return BuildF64Trunc(input); | 777 if (!m->Float64RoundTruncate().IsSupported()) return BuildF64Trunc(input); |
777 op = m->Float64RoundTruncate().op(); | 778 op = m->Float64RoundTruncate().op(); |
778 break; | 779 break; |
779 } | 780 } |
780 case wasm::kExprF64NearestInt: { | 781 case wasm::kExprF64NearestInt: { |
781 if (!m->Float64RoundTiesEven().IsSupported()) | 782 if (!m->Float64RoundTiesEven().IsSupported()) |
782 return BuildF64NearestInt(input); | 783 return BuildF64NearestInt(input); |
783 op = m->Float64RoundTiesEven().op(); | 784 op = m->Float64RoundTiesEven().op(); |
784 break; | 785 break; |
785 } | 786 } |
786 | 787 case wasm::kExprI32ConvertI64: |
| 788 op = m->TruncateInt64ToInt32(); |
| 789 break; |
787 #if WASM_64 | 790 #if WASM_64 |
788 // Opcodes only supported on 64-bit platforms. | 791 // Opcodes only supported on 64-bit platforms. |
789 // TODO(titzer): query the machine operator builder here instead of #ifdef. | 792 // TODO(titzer): query the machine operator builder here instead of #ifdef. |
790 case wasm::kExprI32ConvertI64: | |
791 op = m->TruncateInt64ToInt32(); | |
792 break; | |
793 case wasm::kExprI64SConvertI32: | 793 case wasm::kExprI64SConvertI32: |
794 op = m->ChangeInt32ToInt64(); | 794 op = m->ChangeInt32ToInt64(); |
795 break; | 795 break; |
796 case wasm::kExprI64UConvertI32: | 796 case wasm::kExprI64UConvertI32: |
797 op = m->ChangeUint32ToUint64(); | 797 op = m->ChangeUint32ToUint64(); |
798 break; | 798 break; |
799 case wasm::kExprF32SConvertI64: | 799 case wasm::kExprF32SConvertI64: |
800 op = m->RoundInt64ToFloat32(); | 800 op = m->RoundInt64ToFloat32(); |
801 break; | 801 break; |
802 case wasm::kExprF32UConvertI64: | 802 case wasm::kExprF32UConvertI64: |
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 | 1881 |
1882 | 1882 |
1883 Node* WasmGraphBuilder::String(const char* string) { | 1883 Node* WasmGraphBuilder::String(const char* string) { |
1884 return jsgraph()->Constant( | 1884 return jsgraph()->Constant( |
1885 jsgraph()->isolate()->factory()->NewStringFromAsciiChecked(string)); | 1885 jsgraph()->isolate()->factory()->NewStringFromAsciiChecked(string)); |
1886 } | 1886 } |
1887 | 1887 |
1888 | 1888 |
1889 Graph* WasmGraphBuilder::graph() { return jsgraph()->graph(); } | 1889 Graph* WasmGraphBuilder::graph() { return jsgraph()->graph(); } |
1890 | 1890 |
| 1891 void WasmGraphBuilder::Int64LoweringForTesting() { |
| 1892 #if !WASM_64 |
| 1893 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), jsgraph()->common(), |
| 1894 jsgraph()->zone()); |
| 1895 r.ReduceGraph(); |
| 1896 #endif |
| 1897 } |
1891 | 1898 |
1892 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 1899 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
1893 CompilationInfo* info, | 1900 CompilationInfo* info, |
1894 const char* message, uint32_t index, | 1901 const char* message, uint32_t index, |
1895 const char* func_name) { | 1902 const char* func_name) { |
1896 Isolate* isolate = info->isolate(); | 1903 Isolate* isolate = info->isolate(); |
1897 if (isolate->logger()->is_logging_code_events() || | 1904 if (isolate->logger()->is_logging_code_events() || |
1898 isolate->cpu_profiler()->is_profiling()) { | 1905 isolate->cpu_profiler()->is_profiling()) { |
1899 ScopedVector<char> buffer(128); | 1906 ScopedVector<char> buffer(128); |
1900 SNPrintF(buffer, "%s#%d:%s", message, index, func_name); | 1907 SNPrintF(buffer, "%s#%d:%s", message, index, func_name); |
1901 Handle<String> name_str = | 1908 Handle<String> name_str = |
1902 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); | 1909 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); |
1903 Handle<String> script_str = | 1910 Handle<String> script_str = |
1904 isolate->factory()->NewStringFromAsciiChecked("(WASM)"); | 1911 isolate->factory()->NewStringFromAsciiChecked("(WASM)"); |
1905 Handle<Code> code = info->code(); | 1912 Handle<Code> code = info->code(); |
1906 Handle<SharedFunctionInfo> shared = | 1913 Handle<SharedFunctionInfo> shared = |
1907 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); | 1914 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); |
1908 PROFILE(isolate, | 1915 PROFILE(isolate, |
1909 CodeCreateEvent(tag, *code, *shared, info, *script_str, 0, 0)); | 1916 CodeCreateEvent(tag, *code, *shared, info, *script_str, 0, 0)); |
1910 } | 1917 } |
1911 } | 1918 } |
1912 | 1919 |
1913 | |
1914 Handle<JSFunction> CompileJSToWasmWrapper( | 1920 Handle<JSFunction> CompileJSToWasmWrapper( |
1915 Isolate* isolate, wasm::ModuleEnv* module, Handle<String> name, | 1921 Isolate* isolate, wasm::ModuleEnv* module, Handle<String> name, |
1916 Handle<Code> wasm_code, Handle<JSObject> module_object, uint32_t index) { | 1922 Handle<Code> wasm_code, Handle<JSObject> module_object, uint32_t index) { |
1917 wasm::WasmFunction* func = &module->module->functions->at(index); | 1923 wasm::WasmFunction* func = &module->module->functions->at(index); |
1918 | 1924 |
1919 //---------------------------------------------------------------------------- | 1925 //---------------------------------------------------------------------------- |
1920 // Create the JSFunction object. | 1926 // Create the JSFunction object. |
1921 //---------------------------------------------------------------------------- | 1927 //---------------------------------------------------------------------------- |
1922 Handle<SharedFunctionInfo> shared = | 1928 Handle<SharedFunctionInfo> shared = |
1923 isolate->factory()->NewSharedFunctionInfo(name, wasm_code, false); | 1929 isolate->factory()->NewSharedFunctionInfo(name, wasm_code, false); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2130 module_env->module->GetName(function.name_offset)); | 2136 module_env->module->GetName(function.name_offset)); |
2131 } | 2137 } |
2132 | 2138 |
2133 return code; | 2139 return code; |
2134 } | 2140 } |
2135 | 2141 |
2136 | 2142 |
2137 } // namespace compiler | 2143 } // namespace compiler |
2138 } // namespace internal | 2144 } // namespace internal |
2139 } // namespace v8 | 2145 } // namespace v8 |
OLD | NEW |