Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/opt/Canonicalizer.java @ 2521:2f271a85d104
Removed intrinsic-related instructions
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 16:40:09 +0200 |
parents | f6125fb5bfbc |
children |
comparison
equal
deleted
inserted
replaced
2520:99307021e3f5 | 2521:2f271a85d104 |
---|---|
1020 newIf.setStateAfter(i.stateAfter()); | 1020 newIf.setStateAfter(i.stateAfter()); |
1021 setCanonical(newIf); | 1021 setCanonical(newIf); |
1022 } | 1022 } |
1023 } | 1023 } |
1024 | 1024 |
1025 private void visitUnsafeRawOp(UnsafeRawOp i) { | |
1026 if (i.base() instanceof ArithmeticOp) { | |
1027 // if the base is an arithmetic op, try reducing | |
1028 ArithmeticOp root = (ArithmeticOp) i.base(); | |
1029 if (!root.isLive() && root.opcode == LADD) { | |
1030 // match unsafe(x + y) if the x + y is not pinned | |
1031 // try reducing (x + y) and (y + x) | |
1032 Value y = root.y(); | |
1033 Value x = root.x(); | |
1034 if (reduceRawOp(i, x, y) || reduceRawOp(i, y, x)) { | |
1035 // the operation was reduced | |
1036 return; | |
1037 } | |
1038 if (y instanceof Convert) { | |
1039 // match unsafe(x + (long) y) | |
1040 Convert convert = (Convert) y; | |
1041 if (convert.opcode == I2L && convert.value().kind.isInt()) { | |
1042 // the conversion is redundant | |
1043 setUnsafeRawOp(i, x, convert.value(), 0); | |
1044 } | |
1045 } | |
1046 } | |
1047 } | |
1048 } | |
1049 | |
1050 private boolean reduceRawOp(UnsafeRawOp i, Value base, Value index) { | |
1051 if (index instanceof Convert) { | |
1052 // skip any conversion operations | |
1053 index = ((Convert) index).value(); | |
1054 } | |
1055 if (index instanceof ShiftOp) { | |
1056 // try to match the index as a shift by a constant | |
1057 ShiftOp shift = (ShiftOp) index; | |
1058 CiKind st = shift.y().kind; | |
1059 if (shift.y().isConstant() && st.isInt()) { | |
1060 int val = shift.y().asConstant().asInt(); | |
1061 switch (val) { | |
1062 case 0: // fall through | |
1063 case 1: // fall through | |
1064 case 2: // fall through | |
1065 case 3: return setUnsafeRawOp(i, base, shift.x(), val); | |
1066 } | |
1067 } | |
1068 } | |
1069 if (index instanceof ArithmeticOp) { | |
1070 // try to match the index as a multiply by a constant | |
1071 // note that this case will not happen if C1XOptions.CanonicalizeMultipliesToShifts is true | |
1072 ArithmeticOp arith = (ArithmeticOp) index; | |
1073 CiKind st = arith.y().kind; | |
1074 if (arith.opcode == IMUL && arith.y().isConstant() && st.isInt()) { | |
1075 int val = arith.y().asConstant().asInt(); | |
1076 switch (val) { | |
1077 case 1: return setUnsafeRawOp(i, base, arith.x(), 0); | |
1078 case 2: return setUnsafeRawOp(i, base, arith.x(), 1); | |
1079 case 4: return setUnsafeRawOp(i, base, arith.x(), 2); | |
1080 case 8: return setUnsafeRawOp(i, base, arith.x(), 3); | |
1081 } | |
1082 } | |
1083 } | |
1084 | |
1085 return false; | |
1086 } | |
1087 | |
1088 private boolean setUnsafeRawOp(UnsafeRawOp i, Value base, Value index, int log2scale) { | |
1089 i.setBase(base); | |
1090 i.setIndex(index); | |
1091 i.setLog2Scale(log2scale); | |
1092 return true; | |
1093 } | |
1094 | |
1095 @Override | |
1096 public void visitUnsafeGetRaw(UnsafeGetRaw i) { | |
1097 if (C1XOptions.CanonicalizeUnsafes) { | |
1098 visitUnsafeRawOp(i); | |
1099 } | |
1100 } | |
1101 | |
1102 @Override | |
1103 public void visitUnsafePutRaw(UnsafePutRaw i) { | |
1104 if (C1XOptions.CanonicalizeUnsafes) { | |
1105 visitUnsafeRawOp(i); | |
1106 } | |
1107 } | |
1108 | |
1109 private Object argAsObject(Value[] args, int index) { | 1025 private Object argAsObject(Value[] args, int index) { |
1110 CiConstant c = args[index].asConstant(); | 1026 CiConstant c = args[index].asConstant(); |
1111 if (c != null) { | 1027 if (c != null) { |
1112 return runtime.asJavaObject(c); | 1028 return runtime.asJavaObject(c); |
1113 } | 1029 } |
1161 C1XMetrics.MethodsFolded++; | 1077 C1XMetrics.MethodsFolded++; |
1162 } | 1078 } |
1163 return result; | 1079 return result; |
1164 } | 1080 } |
1165 | 1081 |
1166 @Override | |
1167 public void visitTypeEqualityCheck(TypeEqualityCheck i) { | |
1168 if (i.condition == Condition.EQ && i.left() == i.right()) { | |
1169 setCanonical(null); | |
1170 } | |
1171 } | |
1172 | |
1173 @Override | |
1174 public void visitBoundsCheck(BoundsCheck b) { | |
1175 Value index = b.index(); | |
1176 Value length = b.length(); | |
1177 | |
1178 if (index.isConstant() && length.isConstant()) { | |
1179 int i = index.asConstant().asInt(); | |
1180 int l = index.asConstant().asInt(); | |
1181 Condition c = b.condition; | |
1182 if (c.check(i, l)) { | |
1183 setCanonical(null); | |
1184 } | |
1185 } | |
1186 } | |
1187 | |
1188 private RiType getTypeOf(Value x) { | 1082 private RiType getTypeOf(Value x) { |
1189 if (x.isConstant()) { | 1083 if (x.isConstant()) { |
1190 return runtime.getTypeOf(x.asConstant()); | 1084 return runtime.getTypeOf(x.asConstant()); |
1191 } | 1085 } |
1192 return null; | 1086 return null; |