comparison graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java @ 7063:0d7dfa5b79e8

merged inlining and intrinsification phases some optimizations for Integer- and TypeSwitch added iterator to do the inlining in control-flow order
author Christian Haeubl <haeubl@ssw.jku.at>
date Thu, 15 Nov 2012 15:10:41 +0100
parents 55afed7bc209
children 7d815d842ee0
comparison
equal deleted inserted replaced
7062:8c5333c80cfd 7063:0d7dfa5b79e8
839 if (keyCount == 0) { 839 if (keyCount == 0) {
840 emitJump(getLIRBlock(x.defaultSuccessor()), null); 840 emitJump(getLIRBlock(x.defaultSuccessor()), null);
841 } else { 841 } else {
842 Variable value = load(operand(x.value())); 842 Variable value = load(operand(x.value()));
843 LabelRef defaultTarget = x.defaultSuccessor() == null ? null : getLIRBlock(x.defaultSuccessor()); 843 LabelRef defaultTarget = x.defaultSuccessor() == null ? null : getLIRBlock(x.defaultSuccessor());
844 if (value.getKind() == Kind.Object || keyCount < GraalOptions.SequentialSwitchLimit) { 844 if (value.getKind() == Kind.Object) {
845 // only a few entries 845 // only a few entries
846 emitSequentialSwitch(x, value, defaultTarget); 846 emitSequentialSwitch(x, value, defaultTarget);
847 } else { 847 } else {
848 long valueRange = x.keyAt(keyCount - 1).asLong() - x.keyAt(0).asLong() + 1; 848 long valueRange = x.keyAt(keyCount - 1).asLong() - x.keyAt(0).asLong() + 1;
849 int switchRangeCount = switchRangeCount(x); 849 int switchRangeCount = switchRangeCount(x);
850 int rangeDensity = keyCount / switchRangeCount; 850 if (switchRangeCount == 0) {
851 if (rangeDensity >= GraalOptions.RangeTestsSwitchDensity) { 851 emitJump(getLIRBlock(x.defaultSuccessor()), null);
852 emitSwitchRanges(x, switchRangeCount, value, defaultTarget); 852 } else if (switchRangeCount >= GraalOptions.MinimumJumpTableSize && keyCount / (double) valueRange >= GraalOptions.MinTableSwitchDensity) {
853 } else if (keyCount / (double) valueRange >= GraalOptions.MinTableSwitchDensity) {
854 int minValue = x.keyAt(0).asInt(); 853 int minValue = x.keyAt(0).asInt();
855 assert valueRange < Integer.MAX_VALUE; 854 assert valueRange < Integer.MAX_VALUE;
856 LabelRef[] targets = new LabelRef[(int) valueRange]; 855 LabelRef[] targets = new LabelRef[(int) valueRange];
857 for (int i = 0; i < valueRange; i++) { 856 for (int i = 0; i < valueRange; i++) {
858 targets[i] = defaultTarget; 857 targets[i] = defaultTarget;
859 } 858 }
860 for (int i = 0; i < keyCount; i++) { 859 for (int i = 0; i < keyCount; i++) {
861 targets[x.keyAt(i).asInt() - minValue] = getLIRBlock(x.keySuccessor(i)); 860 targets[x.keyAt(i).asInt() - minValue] = getLIRBlock(x.keySuccessor(i));
862 } 861 }
863 emitTableSwitch(minValue, defaultTarget, targets, value); 862 emitTableSwitch(minValue, defaultTarget, targets, value);
863 } else if (keyCount / switchRangeCount >= GraalOptions.RangeTestsSwitchDensity) {
864 emitSwitchRanges(x, switchRangeCount, value, defaultTarget);
864 } else { 865 } else {
865 emitSequentialSwitch(x, value, defaultTarget); 866 emitSequentialSwitch(x, value, defaultTarget);
866 } 867 }
867 } 868 }
868 } 869 }
889 protected abstract void emitSwitchRanges(int[] lowKeys, int[] highKeys, LabelRef[] targets, LabelRef defaultTarget, Value key); 890 protected abstract void emitSwitchRanges(int[] lowKeys, int[] highKeys, LabelRef[] targets, LabelRef defaultTarget, Value key);
890 protected abstract void emitTableSwitch(int lowKey, LabelRef defaultTarget, LabelRef[] targets, Value key); 891 protected abstract void emitTableSwitch(int lowKey, LabelRef defaultTarget, LabelRef[] targets, Value key);
891 892
892 private static int switchRangeCount(SwitchNode x) { 893 private static int switchRangeCount(SwitchNode x) {
893 int keyCount = x.keyCount(); 894 int keyCount = x.keyCount();
894 int i = 0; 895 int switchRangeCount = 0;
895 while (i < keyCount && x.keySuccessorIndex(i) == x.defaultSuccessorIndex()) { 896 int defaultSux = x.defaultSuccessorIndex();
896 i++; 897
897 } 898 int key = x.keyAt(0).asInt();
898 if (i == keyCount) { 899 int sux = x.keySuccessorIndex(0);
899 return 0; 900 for (int i = 0; i < keyCount; i++) {
900 } else { 901 int newKey = x.keyAt(i).asInt();
901 int switchRangeCount = 1; 902 int newSux = x.keySuccessorIndex(i);
902 i++; 903 if (newSux != defaultSux && (newKey != key + 1 || sux != newSux)) {
903 for (; i < keyCount; i++) { 904 switchRangeCount++;
904 if (x.keySuccessorIndex(i) != x.defaultSuccessorIndex()) { 905 }
905 if (x.keyAt(i).asInt() != x.keyAt(i - 1).asInt() + 1 || x.keySuccessorIndex(i) != x.keySuccessorIndex(i - 1)) { 906 key = newKey;
906 switchRangeCount++; 907 sux = newSux;
907 } 908 }
908 } 909 return switchRangeCount;
909 }
910 return switchRangeCount;
911 }
912 } 910 }
913 911
914 private void emitSwitchRanges(SwitchNode x, int switchRangeCount, Variable keyValue, LabelRef defaultTarget) { 912 private void emitSwitchRanges(SwitchNode x, int switchRangeCount, Variable keyValue, LabelRef defaultTarget) {
913 assert switchRangeCount >= 1 : "switch ranges should not be used for emitting only the default case";
914
915 int[] lowKeys = new int[switchRangeCount]; 915 int[] lowKeys = new int[switchRangeCount];
916 int[] highKeys = new int[switchRangeCount]; 916 int[] highKeys = new int[switchRangeCount];
917 LabelRef[] targets = new LabelRef[switchRangeCount]; 917 LabelRef[] targets = new LabelRef[switchRangeCount];
918 918
919 int keyCount = x.keyCount(); 919 int keyCount = x.keyCount();
920 int defaultSuccessor = x.defaultSuccessorIndex(); 920 int defaultSuccessor = x.defaultSuccessorIndex();
921 921
922 int current = 0; 922 int current = -1;
923 int i = 0; 923 int key = -1;
924 while (i < keyCount && x.keySuccessorIndex(i) == x.defaultSuccessorIndex()) { 924 int successor = -1;
925 i++; 925 for (int i = 0; i < keyCount; i++) {
926 } 926 int newSuccessor = x.keySuccessorIndex(i);
927 if (i == keyCount) { 927 int newKey = x.keyAt(i).asInt();
928 emitJump(defaultTarget, null); 928 if (newSuccessor != defaultSuccessor) {
929 } else { 929 if (key + 1 == newKey && successor == newSuccessor) {
930 int key = x.keyAt(i).asInt(); 930 // still in same range
931 int successor = x.keySuccessorIndex(i); 931 highKeys[current] = newKey;
932 lowKeys[current] = key; 932 } else {
933 highKeys[current] = key; 933 current++;
934 targets[current] = getLIRBlock(x.blockSuccessor(successor)); 934 lowKeys[current] = newKey;
935 i++; 935 highKeys[current] = newKey;
936 for (; i < keyCount; i++) { 936 targets[current] = getLIRBlock(x.blockSuccessor(newSuccessor));
937 int newSuccessor = x.keySuccessorIndex(i); 937 }
938 if (newSuccessor != defaultSuccessor) { 938 }
939 int newKey = x.keyAt(i).asInt(); 939 key = newKey;
940 if (key + 1 == newKey && successor == newSuccessor) { 940 successor = newSuccessor;
941 // still in same range 941 }
942 highKeys[current] = newKey; 942 assert current == switchRangeCount - 1;
943 } else { 943 emitSwitchRanges(lowKeys, highKeys, targets, defaultTarget, keyValue);
944 current++;
945 lowKeys[current] = newKey;
946 highKeys[current] = newKey;
947 targets[current] = getLIRBlock(x.blockSuccessor(newSuccessor));
948 }
949 key = newKey;
950 }
951 successor = newSuccessor;
952 }
953 assert current == switchRangeCount - 1;
954 emitSwitchRanges(lowKeys, highKeys, targets, defaultTarget, keyValue);
955 }
956 } 944 }
957 945
958 public FrameMap frameMap() { 946 public FrameMap frameMap() {
959 return frameMap; 947 return frameMap;
960 } 948 }