Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(797)

Side by Side Diff: src/compiler/instruction-selector.cc

Issue 651783003: [turbofan] Make VisitBranch and friends to backend specific. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/instruction-selector.h ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/instruction-selector.h" 5 #include "src/compiler/instruction-selector.h"
6 6
7 #include "src/compiler/instruction-selector-impl.h" 7 #include "src/compiler/instruction-selector-impl.h"
8 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
9 #include "src/compiler/node-properties-inl.h" 9 #include "src/compiler/node-properties-inl.h"
10 #include "src/compiler/pipeline.h" 10 #include "src/compiler/pipeline.h"
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 return VisitConstant(node); 600 return VisitConstant(node);
601 case IrOpcode::kFloat32Constant: 601 case IrOpcode::kFloat32Constant:
602 return MarkAsDouble(node), VisitConstant(node); 602 return MarkAsDouble(node), VisitConstant(node);
603 case IrOpcode::kFloat64Constant: 603 case IrOpcode::kFloat64Constant:
604 return MarkAsDouble(node), VisitConstant(node); 604 return MarkAsDouble(node), VisitConstant(node);
605 case IrOpcode::kHeapConstant: 605 case IrOpcode::kHeapConstant:
606 case IrOpcode::kNumberConstant: 606 case IrOpcode::kNumberConstant:
607 // TODO(turbofan): only mark non-smis as references. 607 // TODO(turbofan): only mark non-smis as references.
608 return MarkAsReference(node), VisitConstant(node); 608 return MarkAsReference(node), VisitConstant(node);
609 case IrOpcode::kCall: 609 case IrOpcode::kCall:
610 return VisitCall(node, NULL, NULL); 610 return VisitCall(node);
611 case IrOpcode::kFrameState: 611 case IrOpcode::kFrameState:
612 case IrOpcode::kStateValues: 612 case IrOpcode::kStateValues:
613 return; 613 return;
614 case IrOpcode::kLoad: { 614 case IrOpcode::kLoad: {
615 LoadRepresentation rep = OpParameter<LoadRepresentation>(node); 615 LoadRepresentation rep = OpParameter<LoadRepresentation>(node);
616 MarkAsRepresentation(rep, node); 616 MarkAsRepresentation(rep, node);
617 return VisitLoad(node); 617 return VisitLoad(node);
618 } 618 }
619 case IrOpcode::kStore: 619 case IrOpcode::kStore:
620 return VisitStore(node); 620 return VisitStore(node);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 return VisitLoadStackPointer(node); 738 return VisitLoadStackPointer(node);
739 default: 739 default:
740 V8_Fatal(__FILE__, __LINE__, "Unexpected operator #%d:%s @ node #%d", 740 V8_Fatal(__FILE__, __LINE__, "Unexpected operator #%d:%s @ node #%d",
741 node->opcode(), node->op()->mnemonic(), node->id()); 741 node->opcode(), node->op()->mnemonic(), node->id());
742 } 742 }
743 } 743 }
744 744
745 745
746 #if V8_TURBOFAN_BACKEND 746 #if V8_TURBOFAN_BACKEND
747 747
748 void InstructionSelector::VisitWord32Equal(Node* node) {
749 FlagsContinuation cont(kEqual, node);
750 Int32BinopMatcher m(node);
751 if (m.right().Is(0)) {
752 return VisitWord32Test(m.left().node(), &cont);
753 }
754 VisitWord32Compare(node, &cont);
755 }
756
757
758 void InstructionSelector::VisitInt32LessThan(Node* node) {
759 FlagsContinuation cont(kSignedLessThan, node);
760 VisitWord32Compare(node, &cont);
761 }
762
763
764 void InstructionSelector::VisitInt32LessThanOrEqual(Node* node) {
765 FlagsContinuation cont(kSignedLessThanOrEqual, node);
766 VisitWord32Compare(node, &cont);
767 }
768
769
770 void InstructionSelector::VisitUint32LessThan(Node* node) {
771 FlagsContinuation cont(kUnsignedLessThan, node);
772 VisitWord32Compare(node, &cont);
773 }
774
775
776 void InstructionSelector::VisitUint32LessThanOrEqual(Node* node) {
777 FlagsContinuation cont(kUnsignedLessThanOrEqual, node);
778 VisitWord32Compare(node, &cont);
779 }
780
781
782 void InstructionSelector::VisitWord64Equal(Node* node) {
783 FlagsContinuation cont(kEqual, node);
784 Int64BinopMatcher m(node);
785 if (m.right().Is(0)) {
786 return VisitWord64Test(m.left().node(), &cont);
787 }
788 VisitWord64Compare(node, &cont);
789 }
790
791
792 void InstructionSelector::VisitInt32AddWithOverflow(Node* node) {
793 if (Node* ovf = node->FindProjection(1)) {
794 FlagsContinuation cont(kOverflow, ovf);
795 return VisitInt32AddWithOverflow(node, &cont);
796 }
797 FlagsContinuation cont;
798 VisitInt32AddWithOverflow(node, &cont);
799 }
800
801
802 void InstructionSelector::VisitInt32SubWithOverflow(Node* node) {
803 if (Node* ovf = node->FindProjection(1)) {
804 FlagsContinuation cont(kOverflow, ovf);
805 return VisitInt32SubWithOverflow(node, &cont);
806 }
807 FlagsContinuation cont;
808 VisitInt32SubWithOverflow(node, &cont);
809 }
810
811
812 void InstructionSelector::VisitInt64LessThan(Node* node) {
813 FlagsContinuation cont(kSignedLessThan, node);
814 VisitWord64Compare(node, &cont);
815 }
816
817
818 void InstructionSelector::VisitInt64LessThanOrEqual(Node* node) {
819 FlagsContinuation cont(kSignedLessThanOrEqual, node);
820 VisitWord64Compare(node, &cont);
821 }
822
823
824 void InstructionSelector::VisitUint64LessThan(Node* node) {
825 FlagsContinuation cont(kUnsignedLessThan, node);
826 VisitWord64Compare(node, &cont);
827 }
828
829
830 void InstructionSelector::VisitTruncateFloat64ToInt32(Node* node) { 748 void InstructionSelector::VisitTruncateFloat64ToInt32(Node* node) {
831 OperandGenerator g(this); 749 OperandGenerator g(this);
832 Emit(kArchTruncateDoubleToI, g.DefineAsRegister(node), 750 Emit(kArchTruncateDoubleToI, g.DefineAsRegister(node),
833 g.UseRegister(node->InputAt(0))); 751 g.UseRegister(node->InputAt(0)));
834 } 752 }
835 753
836 754
837 void InstructionSelector::VisitFloat64Equal(Node* node) {
838 FlagsContinuation cont(kUnorderedEqual, node);
839 VisitFloat64Compare(node, &cont);
840 }
841
842
843 void InstructionSelector::VisitFloat64LessThan(Node* node) {
844 FlagsContinuation cont(kUnorderedLessThan, node);
845 VisitFloat64Compare(node, &cont);
846 }
847
848
849 void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) {
850 FlagsContinuation cont(kUnorderedLessThanOrEqual, node);
851 VisitFloat64Compare(node, &cont);
852 }
853
854
855 void InstructionSelector::VisitLoadStackPointer(Node* node) { 755 void InstructionSelector::VisitLoadStackPointer(Node* node) {
856 OperandGenerator g(this); 756 OperandGenerator g(this);
857 Emit(kArchStackPointer, g.DefineAsRegister(node)); 757 Emit(kArchStackPointer, g.DefineAsRegister(node));
858 } 758 }
859 759
860 #endif // V8_TURBOFAN_BACKEND 760 #endif // V8_TURBOFAN_BACKEND
861 761
862 // 32 bit targets do not implement the following instructions. 762 // 32 bit targets do not implement the following instructions.
863 #if V8_TARGET_ARCH_32_BIT && V8_TURBOFAN_BACKEND 763 #if V8_TARGET_ARCH_32_BIT && V8_TURBOFAN_BACKEND
864 764
(...skipping 11 matching lines...) Expand all
876 776
877 void InstructionSelector::VisitWord64Shr(Node* node) { UNIMPLEMENTED(); } 777 void InstructionSelector::VisitWord64Shr(Node* node) { UNIMPLEMENTED(); }
878 778
879 779
880 void InstructionSelector::VisitWord64Sar(Node* node) { UNIMPLEMENTED(); } 780 void InstructionSelector::VisitWord64Sar(Node* node) { UNIMPLEMENTED(); }
881 781
882 782
883 void InstructionSelector::VisitWord64Ror(Node* node) { UNIMPLEMENTED(); } 783 void InstructionSelector::VisitWord64Ror(Node* node) { UNIMPLEMENTED(); }
884 784
885 785
786 void InstructionSelector::VisitWord64Equal(Node* node) { UNIMPLEMENTED(); }
787
788
886 void InstructionSelector::VisitInt64Add(Node* node) { UNIMPLEMENTED(); } 789 void InstructionSelector::VisitInt64Add(Node* node) { UNIMPLEMENTED(); }
887 790
888 791
889 void InstructionSelector::VisitInt64Sub(Node* node) { UNIMPLEMENTED(); } 792 void InstructionSelector::VisitInt64Sub(Node* node) { UNIMPLEMENTED(); }
890 793
891 794
892 void InstructionSelector::VisitInt64Mul(Node* node) { UNIMPLEMENTED(); } 795 void InstructionSelector::VisitInt64Mul(Node* node) { UNIMPLEMENTED(); }
893 796
894 797
895 void InstructionSelector::VisitInt64Div(Node* node) { UNIMPLEMENTED(); } 798 void InstructionSelector::VisitInt64Div(Node* node) { UNIMPLEMENTED(); }
896 799
897 800
801 void InstructionSelector::VisitInt64LessThan(Node* node) { UNIMPLEMENTED(); }
802
803
804 void InstructionSelector::VisitInt64LessThanOrEqual(Node* node) {
805 UNIMPLEMENTED();
806 }
807
808
898 void InstructionSelector::VisitUint64Div(Node* node) { UNIMPLEMENTED(); } 809 void InstructionSelector::VisitUint64Div(Node* node) { UNIMPLEMENTED(); }
899 810
900 811
901 void InstructionSelector::VisitInt64Mod(Node* node) { UNIMPLEMENTED(); } 812 void InstructionSelector::VisitInt64Mod(Node* node) { UNIMPLEMENTED(); }
902 813
903 814
815 void InstructionSelector::VisitUint64LessThan(Node* node) { UNIMPLEMENTED(); }
816
817
904 void InstructionSelector::VisitUint64Mod(Node* node) { UNIMPLEMENTED(); } 818 void InstructionSelector::VisitUint64Mod(Node* node) { UNIMPLEMENTED(); }
905 819
906 820
907 void InstructionSelector::VisitChangeInt32ToInt64(Node* node) { 821 void InstructionSelector::VisitChangeInt32ToInt64(Node* node) {
908 UNIMPLEMENTED(); 822 UNIMPLEMENTED();
909 } 823 }
910 824
911 825
912 void InstructionSelector::VisitChangeUint32ToUint64(Node* node) { 826 void InstructionSelector::VisitChangeUint32ToUint64(Node* node) {
913 UNIMPLEMENTED(); 827 UNIMPLEMENTED();
914 } 828 }
915 829
916 830
917 void InstructionSelector::VisitTruncateInt64ToInt32(Node* node) { 831 void InstructionSelector::VisitTruncateInt64ToInt32(Node* node) {
918 UNIMPLEMENTED(); 832 UNIMPLEMENTED();
919 } 833 }
920 834
921 #endif // V8_TARGET_ARCH_32_BIT && V8_TURBOFAN_BACKEND 835 #endif // V8_TARGET_ARCH_32_BIT && V8_TURBOFAN_BACKEND
922 836
923 837
924 // 32-bit targets and unsupported architectures need dummy implementations of
925 // selected 64-bit ops.
926 #if V8_TARGET_ARCH_32_BIT || !V8_TURBOFAN_BACKEND
927
928 void InstructionSelector::VisitWord64Test(Node* node, FlagsContinuation* cont) {
929 UNIMPLEMENTED();
930 }
931
932
933 void InstructionSelector::VisitWord64Compare(Node* node,
934 FlagsContinuation* cont) {
935 UNIMPLEMENTED();
936 }
937
938 #endif // V8_TARGET_ARCH_32_BIT || !V8_TURBOFAN_BACKEND
939
940
941 void InstructionSelector::VisitFinish(Node* node) { 838 void InstructionSelector::VisitFinish(Node* node) {
942 OperandGenerator g(this); 839 OperandGenerator g(this);
943 Node* value = node->InputAt(0); 840 Node* value = node->InputAt(0);
944 Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(value)); 841 Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(value));
945 } 842 }
946 843
947 844
948 void InstructionSelector::VisitParameter(Node* node) { 845 void InstructionSelector::VisitParameter(Node* node) {
949 OperandGenerator g(this); 846 OperandGenerator g(this);
950 int index = OpParameter<int>(node); 847 int index = OpParameter<int>(node);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 // fall through to the next block. 891 // fall through to the next block.
995 Emit(kArchNop, NULL)->MarkAsControl(); 892 Emit(kArchNop, NULL)->MarkAsControl();
996 } else { 893 } else {
997 // jump to the next block. 894 // jump to the next block.
998 OperandGenerator g(this); 895 OperandGenerator g(this);
999 Emit(kArchJmp, NULL, g.Label(target))->MarkAsControl(); 896 Emit(kArchJmp, NULL, g.Label(target))->MarkAsControl();
1000 } 897 }
1001 } 898 }
1002 899
1003 900
1004 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
1005 BasicBlock* fbranch) {
1006 OperandGenerator g(this);
1007 Node* user = branch;
1008 Node* value = branch->InputAt(0);
1009
1010 FlagsContinuation cont(kNotEqual, tbranch, fbranch);
1011
1012 // If we can fall through to the true block, invert the branch.
1013 if (IsNextInAssemblyOrder(tbranch)) {
1014 cont.Negate();
1015 cont.SwapBlocks();
1016 }
1017
1018 // Try to combine with comparisons against 0 by simply inverting the branch.
1019 while (CanCover(user, value)) {
1020 if (value->opcode() == IrOpcode::kWord32Equal) {
1021 Int32BinopMatcher m(value);
1022 if (m.right().Is(0)) {
1023 user = value;
1024 value = m.left().node();
1025 cont.Negate();
1026 } else {
1027 break;
1028 }
1029 } else if (value->opcode() == IrOpcode::kWord64Equal) {
1030 Int64BinopMatcher m(value);
1031 if (m.right().Is(0)) {
1032 user = value;
1033 value = m.left().node();
1034 cont.Negate();
1035 } else {
1036 break;
1037 }
1038 } else {
1039 break;
1040 }
1041 }
1042
1043 // Try to combine the branch with a comparison.
1044 if (CanCover(user, value)) {
1045 switch (value->opcode()) {
1046 case IrOpcode::kWord32Equal:
1047 cont.OverwriteAndNegateIfEqual(kEqual);
1048 return VisitWord32Compare(value, &cont);
1049 case IrOpcode::kInt32LessThan:
1050 cont.OverwriteAndNegateIfEqual(kSignedLessThan);
1051 return VisitWord32Compare(value, &cont);
1052 case IrOpcode::kInt32LessThanOrEqual:
1053 cont.OverwriteAndNegateIfEqual(kSignedLessThanOrEqual);
1054 return VisitWord32Compare(value, &cont);
1055 case IrOpcode::kUint32LessThan:
1056 cont.OverwriteAndNegateIfEqual(kUnsignedLessThan);
1057 return VisitWord32Compare(value, &cont);
1058 case IrOpcode::kUint32LessThanOrEqual:
1059 cont.OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual);
1060 return VisitWord32Compare(value, &cont);
1061 case IrOpcode::kWord64Equal:
1062 cont.OverwriteAndNegateIfEqual(kEqual);
1063 return VisitWord64Compare(value, &cont);
1064 case IrOpcode::kInt64LessThan:
1065 cont.OverwriteAndNegateIfEqual(kSignedLessThan);
1066 return VisitWord64Compare(value, &cont);
1067 case IrOpcode::kInt64LessThanOrEqual:
1068 cont.OverwriteAndNegateIfEqual(kSignedLessThanOrEqual);
1069 return VisitWord64Compare(value, &cont);
1070 case IrOpcode::kUint64LessThan:
1071 cont.OverwriteAndNegateIfEqual(kUnsignedLessThan);
1072 return VisitWord64Compare(value, &cont);
1073 case IrOpcode::kFloat64Equal:
1074 cont.OverwriteAndNegateIfEqual(kUnorderedEqual);
1075 return VisitFloat64Compare(value, &cont);
1076 case IrOpcode::kFloat64LessThan:
1077 cont.OverwriteAndNegateIfEqual(kUnorderedLessThan);
1078 return VisitFloat64Compare(value, &cont);
1079 case IrOpcode::kFloat64LessThanOrEqual:
1080 cont.OverwriteAndNegateIfEqual(kUnorderedLessThanOrEqual);
1081 return VisitFloat64Compare(value, &cont);
1082 case IrOpcode::kProjection:
1083 // Check if this is the overflow output projection of an
1084 // <Operation>WithOverflow node.
1085 if (OpParameter<size_t>(value) == 1u) {
1086 // We cannot combine the <Operation>WithOverflow with this branch
1087 // unless the 0th projection (the use of the actual value of the
1088 // <Operation> is either NULL, which means there's no use of the
1089 // actual value, or was already defined, which means it is scheduled
1090 // *AFTER* this branch).
1091 Node* node = value->InputAt(0);
1092 Node* result = node->FindProjection(0);
1093 if (result == NULL || IsDefined(result)) {
1094 switch (node->opcode()) {
1095 case IrOpcode::kInt32AddWithOverflow:
1096 cont.OverwriteAndNegateIfEqual(kOverflow);
1097 return VisitInt32AddWithOverflow(node, &cont);
1098 case IrOpcode::kInt32SubWithOverflow:
1099 cont.OverwriteAndNegateIfEqual(kOverflow);
1100 return VisitInt32SubWithOverflow(node, &cont);
1101 default:
1102 break;
1103 }
1104 }
1105 }
1106 break;
1107 default:
1108 break;
1109 }
1110 }
1111
1112 // Branch could not be combined with a compare, emit compare against 0.
1113 VisitWord32Test(value, &cont);
1114 }
1115
1116
1117 void InstructionSelector::VisitReturn(Node* value) { 901 void InstructionSelector::VisitReturn(Node* value) {
1118 OperandGenerator g(this); 902 OperandGenerator g(this);
1119 if (value != NULL) { 903 if (value != NULL) {
1120 Emit(kArchRet, NULL, g.UseLocation(value, linkage()->GetReturnLocation(), 904 Emit(kArchRet, NULL, g.UseLocation(value, linkage()->GetReturnLocation(),
1121 linkage()->GetReturnType())); 905 linkage()->GetReturnType()));
1122 } else { 906 } else {
1123 Emit(kArchRet, NULL); 907 Emit(kArchRet, NULL);
1124 } 908 }
1125 } 909 }
1126 910
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 1011
1228 1012
1229 #if !V8_TURBOFAN_BACKEND 1013 #if !V8_TURBOFAN_BACKEND
1230 1014
1231 #define DECLARE_UNIMPLEMENTED_SELECTOR(x) \ 1015 #define DECLARE_UNIMPLEMENTED_SELECTOR(x) \
1232 void InstructionSelector::Visit##x(Node* node) { UNIMPLEMENTED(); } 1016 void InstructionSelector::Visit##x(Node* node) { UNIMPLEMENTED(); }
1233 MACHINE_OP_LIST(DECLARE_UNIMPLEMENTED_SELECTOR) 1017 MACHINE_OP_LIST(DECLARE_UNIMPLEMENTED_SELECTOR)
1234 #undef DECLARE_UNIMPLEMENTED_SELECTOR 1018 #undef DECLARE_UNIMPLEMENTED_SELECTOR
1235 1019
1236 1020
1237 void InstructionSelector::VisitInt32AddWithOverflow(Node* node, 1021 void InstructionSelector::VisitCall(Node* node) { UNIMPLEMENTED(); }
1238 FlagsContinuation* cont) {
1239 UNIMPLEMENTED();
1240 }
1241
1242
1243 void InstructionSelector::VisitInt32SubWithOverflow(Node* node,
1244 FlagsContinuation* cont) {
1245 UNIMPLEMENTED();
1246 }
1247
1248
1249 void InstructionSelector::VisitWord32Test(Node* node, FlagsContinuation* cont) {
1250 UNIMPLEMENTED();
1251 }
1252
1253
1254 void InstructionSelector::VisitWord32Compare(Node* node,
1255 FlagsContinuation* cont) {
1256 UNIMPLEMENTED();
1257 }
1258
1259
1260 void InstructionSelector::VisitFloat64Compare(Node* node,
1261 FlagsContinuation* cont) {
1262 UNIMPLEMENTED();
1263 }
1264
1265
1266 void InstructionSelector::VisitCall(Node* call, BasicBlock* continuation,
1267 BasicBlock* deoptimization) {}
1268 1022
1269 #endif // !V8_TURBOFAN_BACKEND 1023 #endif // !V8_TURBOFAN_BACKEND
1270 1024
1271 } // namespace compiler 1025 } // namespace compiler
1272 } // namespace internal 1026 } // namespace internal
1273 } // namespace v8 1027 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/instruction-selector.h ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698