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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #else | 42 #else |
43 #define WASM_64 0 | 43 #define WASM_64 0 |
44 #endif | 44 #endif |
45 | 45 |
46 namespace v8 { | 46 namespace v8 { |
47 namespace internal { | 47 namespace internal { |
48 namespace compiler { | 48 namespace compiler { |
49 | 49 |
50 namespace { | 50 namespace { |
51 const Operator* UnsupportedOpcode(wasm::WasmOpcode opcode) { | 51 const Operator* UnsupportedOpcode(wasm::WasmOpcode opcode) { |
52 if (wasm::WasmOpcodes::IsSupported(opcode)) { | |
53 V8_Fatal(__FILE__, __LINE__, | |
54 "Unsupported opcode #%d:%s reported as supported", opcode, | |
55 wasm::WasmOpcodes::OpcodeName(opcode)); | |
56 } | |
57 V8_Fatal(__FILE__, __LINE__, "Unsupported opcode #%d:%s", opcode, | 52 V8_Fatal(__FILE__, __LINE__, "Unsupported opcode #%d:%s", opcode, |
58 wasm::WasmOpcodes::OpcodeName(opcode)); | 53 wasm::WasmOpcodes::OpcodeName(opcode)); |
59 return nullptr; | 54 return nullptr; |
60 } | 55 } |
61 | 56 |
62 | 57 |
63 void MergeControlToEnd(JSGraph* jsgraph, Node* node) { | 58 void MergeControlToEnd(JSGraph* jsgraph, Node* node) { |
64 Graph* g = jsgraph->graph(); | 59 Graph* g = jsgraph->graph(); |
65 if (g->end()) { | 60 if (g->end()) { |
66 NodeProperties::MergeControlToEnd(g, jsgraph->common(), node); | 61 NodeProperties::MergeControlToEnd(g, jsgraph->common(), node); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 op = m->Uint32LessThan(); | 459 op = m->Uint32LessThan(); |
465 std::swap(left, right); | 460 std::swap(left, right); |
466 break; | 461 break; |
467 case wasm::kExprI32GeU: | 462 case wasm::kExprI32GeU: |
468 op = m->Uint32LessThanOrEqual(); | 463 op = m->Uint32LessThanOrEqual(); |
469 std::swap(left, right); | 464 std::swap(left, right); |
470 break; | 465 break; |
471 case wasm::kExprI64And: | 466 case wasm::kExprI64And: |
472 op = m->Word64And(); | 467 op = m->Word64And(); |
473 break; | 468 break; |
474 // todo(ahaas): I added a list of missing instructions here to make merging | |
475 // easier when I do them one by one. | |
476 // kExprI64Add: | |
477 case wasm::kExprI64Add: | 469 case wasm::kExprI64Add: |
478 op = m->Int64Add(); | 470 op = m->Int64Add(); |
479 break; | 471 break; |
480 // kExprI64Sub: | |
481 case wasm::kExprI64Sub: | 472 case wasm::kExprI64Sub: |
482 op = m->Int64Sub(); | 473 op = m->Int64Sub(); |
483 break; | 474 break; |
484 // kExprI64Mul: | |
485 case wasm::kExprI64Mul: | 475 case wasm::kExprI64Mul: |
486 op = m->Int64Mul(); | 476 op = m->Int64Mul(); |
487 break; | 477 break; |
488 // kExprI64DivS: | |
489 case wasm::kExprI64DivS: | 478 case wasm::kExprI64DivS: |
490 return BuildI64DivS(left, right, position); | 479 return BuildI64DivS(left, right, position); |
491 // kExprI64DivU: | |
492 case wasm::kExprI64DivU: | 480 case wasm::kExprI64DivU: |
493 return BuildI64DivU(left, right, position); | 481 return BuildI64DivU(left, right, position); |
494 // kExprI64RemS: | |
495 case wasm::kExprI64RemS: | 482 case wasm::kExprI64RemS: |
496 return BuildI64RemS(left, right, position); | 483 return BuildI64RemS(left, right, position); |
497 // kExprI64RemU: | |
498 case wasm::kExprI64RemU: | 484 case wasm::kExprI64RemU: |
499 return BuildI64RemU(left, right, position); | 485 return BuildI64RemU(left, right, position); |
500 case wasm::kExprI64Ior: | 486 case wasm::kExprI64Ior: |
501 op = m->Word64Or(); | 487 op = m->Word64Or(); |
502 break; | 488 break; |
503 // kExprI64Xor: | |
504 case wasm::kExprI64Xor: | 489 case wasm::kExprI64Xor: |
505 op = m->Word64Xor(); | 490 op = m->Word64Xor(); |
506 break; | 491 break; |
507 // kExprI64Shl: | |
508 case wasm::kExprI64Shl: | 492 case wasm::kExprI64Shl: |
509 op = m->Word64Shl(); | 493 op = m->Word64Shl(); |
510 right = MaskShiftCount64(right); | 494 right = MaskShiftCount64(right); |
511 break; | 495 break; |
512 // kExprI64ShrU: | |
513 case wasm::kExprI64ShrU: | 496 case wasm::kExprI64ShrU: |
514 op = m->Word64Shr(); | 497 op = m->Word64Shr(); |
515 right = MaskShiftCount64(right); | 498 right = MaskShiftCount64(right); |
516 break; | 499 break; |
517 // kExprI64ShrS: | |
518 case wasm::kExprI64ShrS: | 500 case wasm::kExprI64ShrS: |
519 op = m->Word64Sar(); | 501 op = m->Word64Sar(); |
520 right = MaskShiftCount64(right); | 502 right = MaskShiftCount64(right); |
521 break; | 503 break; |
522 // kExprI64Eq: | |
523 case wasm::kExprI64Eq: | 504 case wasm::kExprI64Eq: |
524 op = m->Word64Equal(); | 505 op = m->Word64Equal(); |
525 break; | 506 break; |
526 // kExprI64Ne: | |
527 case wasm::kExprI64Ne: | 507 case wasm::kExprI64Ne: |
528 return Invert(Binop(wasm::kExprI64Eq, left, right)); | 508 return Invert(Binop(wasm::kExprI64Eq, left, right)); |
529 // kExprI64LtS: | |
530 case wasm::kExprI64LtS: | 509 case wasm::kExprI64LtS: |
531 op = m->Int64LessThan(); | 510 op = m->Int64LessThan(); |
532 break; | 511 break; |
533 case wasm::kExprI64LeS: | 512 case wasm::kExprI64LeS: |
534 op = m->Int64LessThanOrEqual(); | 513 op = m->Int64LessThanOrEqual(); |
535 break; | 514 break; |
536 case wasm::kExprI64LtU: | 515 case wasm::kExprI64LtU: |
537 op = m->Uint64LessThan(); | 516 op = m->Uint64LessThan(); |
538 break; | 517 break; |
539 case wasm::kExprI64LeU: | 518 case wasm::kExprI64LeU: |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 } | 767 } |
789 case wasm::kExprF64Tan: { | 768 case wasm::kExprF64Tan: { |
790 return BuildF64Tan(input); | 769 return BuildF64Tan(input); |
791 } | 770 } |
792 case wasm::kExprF64Exp: { | 771 case wasm::kExprF64Exp: { |
793 return BuildF64Exp(input); | 772 return BuildF64Exp(input); |
794 } | 773 } |
795 case wasm::kExprF64Log: { | 774 case wasm::kExprF64Log: { |
796 return BuildF64Log(input); | 775 return BuildF64Log(input); |
797 } | 776 } |
798 // kExprI32ConvertI64: | |
799 case wasm::kExprI32ConvertI64: | 777 case wasm::kExprI32ConvertI64: |
800 op = m->TruncateInt64ToInt32(); | 778 op = m->TruncateInt64ToInt32(); |
801 break; | 779 break; |
802 // kExprI64SConvertI32: | |
803 case wasm::kExprI64SConvertI32: | 780 case wasm::kExprI64SConvertI32: |
804 op = m->ChangeInt32ToInt64(); | 781 op = m->ChangeInt32ToInt64(); |
805 break; | 782 break; |
806 // kExprI64UConvertI32: | |
807 case wasm::kExprI64UConvertI32: | 783 case wasm::kExprI64UConvertI32: |
808 op = m->ChangeUint32ToUint64(); | 784 op = m->ChangeUint32ToUint64(); |
809 break; | 785 break; |
810 // kExprF64ReinterpretI64: | |
811 case wasm::kExprF64ReinterpretI64: | 786 case wasm::kExprF64ReinterpretI64: |
812 op = m->BitcastInt64ToFloat64(); | 787 op = m->BitcastInt64ToFloat64(); |
813 break; | 788 break; |
814 // kExprI64ReinterpretF64: | |
815 case wasm::kExprI64ReinterpretF64: | 789 case wasm::kExprI64ReinterpretF64: |
816 op = m->BitcastFloat64ToInt64(); | 790 op = m->BitcastFloat64ToInt64(); |
817 break; | 791 break; |
818 // kExprI64Clz: | |
819 case wasm::kExprI64Clz: | 792 case wasm::kExprI64Clz: |
820 op = m->Word64Clz(); | 793 op = m->Word64Clz(); |
821 break; | 794 break; |
822 // kExprI64Ctz: | |
823 case wasm::kExprI64Ctz: { | 795 case wasm::kExprI64Ctz: { |
824 if (m->Word64Ctz().IsSupported()) { | 796 if (m->Word64Ctz().IsSupported()) { |
825 op = m->Word64Ctz().op(); | 797 op = m->Word64Ctz().op(); |
826 break; | 798 break; |
827 } else if (m->Is32() && m->Word32Ctz().IsSupported()) { | 799 } else if (m->Is32() && m->Word32Ctz().IsSupported()) { |
828 op = m->Word64CtzPlaceholder(); | 800 op = m->Word64CtzPlaceholder(); |
829 break; | 801 break; |
830 } else if (m->Word64ReverseBits().IsSupported()) { | 802 } else if (m->Word64ReverseBits().IsSupported()) { |
831 Node* reversed = graph()->NewNode(m->Word64ReverseBits().op(), input); | 803 Node* reversed = graph()->NewNode(m->Word64ReverseBits().op(), input); |
832 Node* result = graph()->NewNode(m->Word64Clz(), reversed); | 804 Node* result = graph()->NewNode(m->Word64Clz(), reversed); |
833 return result; | 805 return result; |
834 } else { | 806 } else { |
835 return BuildI64Ctz(input); | 807 return BuildI64Ctz(input); |
836 } | 808 } |
837 } | 809 } |
838 // kExprI64Popcnt: | |
839 case wasm::kExprI64Popcnt: { | 810 case wasm::kExprI64Popcnt: { |
840 if (m->Word64Popcnt().IsSupported()) { | 811 if (m->Word64Popcnt().IsSupported()) { |
841 op = m->Word64Popcnt().op(); | 812 op = m->Word64Popcnt().op(); |
842 } else if (m->Is32() && m->Word32Popcnt().IsSupported()) { | 813 } else if (m->Is32() && m->Word32Popcnt().IsSupported()) { |
843 op = m->Word64PopcntPlaceholder(); | 814 op = m->Word64PopcntPlaceholder(); |
844 } else { | 815 } else { |
845 return BuildI64Popcnt(input); | 816 return BuildI64Popcnt(input); |
846 } | 817 } |
847 break; | 818 break; |
848 } | 819 } |
849 // kExprF32SConvertI64: | |
850 case wasm::kExprI64Eqz: | 820 case wasm::kExprI64Eqz: |
851 op = m->Word64Equal(); | 821 op = m->Word64Equal(); |
852 return graph()->NewNode(op, input, jsgraph()->Int64Constant(0)); | 822 return graph()->NewNode(op, input, jsgraph()->Int64Constant(0)); |
853 case wasm::kExprF32SConvertI64: | 823 case wasm::kExprF32SConvertI64: |
854 if (m->Is32()) { | 824 if (m->Is32()) { |
855 return BuildF32SConvertI64(input); | 825 return BuildF32SConvertI64(input); |
856 } | 826 } |
857 op = m->RoundInt64ToFloat32(); | 827 op = m->RoundInt64ToFloat32(); |
858 break; | 828 break; |
859 // kExprF32UConvertI64: | |
860 case wasm::kExprF32UConvertI64: | 829 case wasm::kExprF32UConvertI64: |
861 if (m->Is32()) { | 830 if (m->Is32()) { |
862 return BuildF32UConvertI64(input); | 831 return BuildF32UConvertI64(input); |
863 } | 832 } |
864 op = m->RoundUint64ToFloat32(); | 833 op = m->RoundUint64ToFloat32(); |
865 break; | 834 break; |
866 // kExprF64SConvertI64: | |
867 case wasm::kExprF64SConvertI64: | 835 case wasm::kExprF64SConvertI64: |
868 if (m->Is32()) { | 836 if (m->Is32()) { |
869 return BuildF64SConvertI64(input); | 837 return BuildF64SConvertI64(input); |
870 } | 838 } |
871 op = m->RoundInt64ToFloat64(); | 839 op = m->RoundInt64ToFloat64(); |
872 break; | 840 break; |
873 // kExprF64UConvertI64: | |
874 case wasm::kExprF64UConvertI64: | 841 case wasm::kExprF64UConvertI64: |
875 if (m->Is32()) { | 842 if (m->Is32()) { |
876 return BuildF64UConvertI64(input); | 843 return BuildF64UConvertI64(input); |
877 } | 844 } |
878 op = m->RoundUint64ToFloat64(); | 845 op = m->RoundUint64ToFloat64(); |
879 break; | 846 break; |
880 // kExprI64SConvertF32: | |
881 case wasm::kExprI64SConvertF32: { | 847 case wasm::kExprI64SConvertF32: { |
882 return BuildI64SConvertF32(input, position); | 848 return BuildI64SConvertF32(input, position); |
883 } | 849 } |
884 // kExprI64SConvertF64: | |
885 case wasm::kExprI64SConvertF64: { | 850 case wasm::kExprI64SConvertF64: { |
886 return BuildI64SConvertF64(input, position); | 851 return BuildI64SConvertF64(input, position); |
887 } | 852 } |
888 // kExprI64UConvertF32: | |
889 case wasm::kExprI64UConvertF32: { | 853 case wasm::kExprI64UConvertF32: { |
890 return BuildI64UConvertF32(input, position); | 854 return BuildI64UConvertF32(input, position); |
891 } | 855 } |
892 // kExprI64UConvertF64: | |
893 case wasm::kExprI64UConvertF64: { | 856 case wasm::kExprI64UConvertF64: { |
894 return BuildI64UConvertF64(input, position); | 857 return BuildI64UConvertF64(input, position); |
895 } | 858 } |
896 default: | 859 default: |
897 op = UnsupportedOpcode(opcode); | 860 op = UnsupportedOpcode(opcode); |
898 } | 861 } |
899 return graph()->NewNode(op, input); | 862 return graph()->NewNode(op, input); |
900 } | 863 } |
901 | 864 |
902 | 865 |
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3103 | 3066 |
3104 Handle<Code> FinishCompilation(WasmCompilationUnit* unit) { | 3067 Handle<Code> FinishCompilation(WasmCompilationUnit* unit) { |
3105 Handle<Code> result = unit->FinishCompilation(); | 3068 Handle<Code> result = unit->FinishCompilation(); |
3106 delete unit; | 3069 delete unit; |
3107 return result; | 3070 return result; |
3108 } | 3071 } |
3109 | 3072 |
3110 } // namespace compiler | 3073 } // namespace compiler |
3111 } // namespace internal | 3074 } // namespace internal |
3112 } // namespace v8 | 3075 } // namespace v8 |
OLD | NEW |