comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2533:c480605ef068

Removed canonicalizer.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 19:05:35 +0200
parents 2f271a85d104
children 4af63190ee3d
comparison
equal deleted inserted replaced
2532:3fca504f28ba 2533:c480605ef068
74 /** 74 /**
75 * Map used for local load elimination (i.e. within the current block). 75 * Map used for local load elimination (i.e. within the current block).
76 */ 76 */
77 final MemoryMap memoryMap; 77 final MemoryMap memoryMap;
78 78
79 final Canonicalizer canonicalizer; // canonicalizer which does strength reduction + constant folding
80 ScopeData scopeData; // Per-scope data; used for inlining 79 ScopeData scopeData; // Per-scope data; used for inlining
81 BlockBegin curBlock; // the current block 80 BlockBegin curBlock; // the current block
82 MutableFrameState curState; // the current execution state 81 MutableFrameState curState; // the current execution state
83 Instruction lastInstr; // the last instruction added 82 Instruction lastInstr; // the last instruction added
84 final LogStream log; 83 final LogStream log;
96 this.compilation = compilation; 95 this.compilation = compilation;
97 this.ir = ir; 96 this.ir = ir;
98 this.stats = compilation.stats; 97 this.stats = compilation.stats;
99 this.memoryMap = C1XOptions.OptLocalLoadElimination ? new MemoryMap() : null; 98 this.memoryMap = C1XOptions.OptLocalLoadElimination ? new MemoryMap() : null;
100 this.localValueMap = C1XOptions.OptLocalValueNumbering ? new ValueMap() : null; 99 this.localValueMap = C1XOptions.OptLocalValueNumbering ? new ValueMap() : null;
101 this.canonicalizer = C1XOptions.OptCanonicalize ? new Canonicalizer(compilation.runtime, compilation.method, compilation.target) : null;
102 log = C1XOptions.TraceBytecodeParserLevel > 0 ? new LogStream(TTY.out()) : null; 100 log = C1XOptions.TraceBytecodeParserLevel > 0 ? new LogStream(TTY.out()) : null;
103 } 101 }
104 102
105 /** 103 /**
106 * Builds the graph for a the specified {@code IRScope}. 104 * Builds the graph for a the specified {@code IRScope}.
752 750
753 void genGetStatic(int cpi, RiField field) { 751 void genGetStatic(int cpi, RiField field) {
754 RiType holder = field.holder(); 752 RiType holder = field.holder();
755 boolean isInitialized = !C1XOptions.TestPatching && field.isResolved() && holder.isResolved() && holder.isInitialized(); 753 boolean isInitialized = !C1XOptions.TestPatching && field.isResolved() && holder.isResolved() && holder.isInitialized();
756 CiConstant constantValue = null; 754 CiConstant constantValue = null;
757 if (isInitialized && C1XOptions.CanonicalizeConstantFields) { 755 if (isInitialized) {
758 constantValue = field.constantValue(null); 756 constantValue = field.constantValue(null);
759 } 757 }
760 if (constantValue != null) { 758 if (constantValue != null) {
761 push(constantValue.kind.stackKind(), appendConstant(constantValue)); 759 push(constantValue.kind.stackKind(), appendConstant(constantValue));
762 } else { 760 } else {
823 // of initialization is required), it can be commoned with static field accesses. 821 // of initialization is required), it can be commoned with static field accesses.
824 genResolveClass(RiType.Representation.StaticFields, holder, isInitialized, cpi); 822 genResolveClass(RiType.Representation.StaticFields, holder, isInitialized, cpi);
825 } 823 }
826 824
827 Value[] args = curState.popArguments(target.signature().argumentSlots(false)); 825 Value[] args = curState.popArguments(target.signature().argumentSlots(false));
828 if (!tryRemoveCall(target, args, true)) { 826 if (!tryInline(target, args)) {
829 if (!tryInline(target, args)) { 827 appendInvoke(INVOKESTATIC, target, args, true, cpi, constantPool);
830 appendInvoke(INVOKESTATIC, target, args, true, cpi, constantPool);
831 }
832 } 828 }
833 } 829 }
834 830
835 void genInvokeInterface(RiMethod target, int cpi, RiConstantPool constantPool) { 831 void genInvokeInterface(RiMethod target, int cpi, RiConstantPool constantPool) {
836 Value[] args = curState.popArguments(target.signature().argumentSlots(true)); 832 Value[] args = curState.popArguments(target.signature().argumentSlots(true));
837 if (!tryRemoveCall(target, args, false)) { 833
838 genInvokeIndirect(INVOKEINTERFACE, target, args, cpi, constantPool); 834 genInvokeIndirect(INVOKEINTERFACE, target, args, cpi, constantPool);
839 } 835
840 } 836 }
841 837
842 void genInvokeVirtual(RiMethod target, int cpi, RiConstantPool constantPool) { 838 void genInvokeVirtual(RiMethod target, int cpi, RiConstantPool constantPool) {
843 Value[] args = curState.popArguments(target.signature().argumentSlots(true)); 839 Value[] args = curState.popArguments(target.signature().argumentSlots(true));
844 if (!tryRemoveCall(target, args, false)) { 840 genInvokeIndirect(INVOKEVIRTUAL, target, args, cpi, constantPool);
845 genInvokeIndirect(INVOKEVIRTUAL, target, args, cpi, constantPool); 841
846 }
847 } 842 }
848 843
849 void genInvokeSpecial(RiMethod target, RiType knownHolder, int cpi, RiConstantPool constantPool) { 844 void genInvokeSpecial(RiMethod target, RiType knownHolder, int cpi, RiConstantPool constantPool) {
850 Value[] args = curState.popArguments(target.signature().argumentSlots(true)); 845 Value[] args = curState.popArguments(target.signature().argumentSlots(true));
851 if (!tryRemoveCall(target, args, false)) { 846 invokeDirect(target, args, knownHolder, cpi, constantPool);
852 invokeDirect(target, args, knownHolder, cpi, constantPool); 847
853 }
854 } 848 }
855 849
856 /** 850 /**
857 * Temporary work-around to support the @ACCESSOR Maxine annotation. 851 * Temporary work-around to support the @ACCESSOR Maxine annotation.
858 */ 852 */
1236 } 1230 }
1237 return false; 1231 return false;
1238 } 1232 }
1239 1233
1240 private Value appendConstant(CiConstant type) { 1234 private Value appendConstant(CiConstant type) {
1241 return appendWithBCI(new Constant(type), bci(), false); 1235 return appendWithBCI(new Constant(type), bci());
1242 } 1236 }
1243 1237
1244 private Value append(Instruction x) { 1238 private Value append(Instruction x) {
1245 return appendWithBCI(x, bci(), C1XOptions.OptCanonicalize); 1239 return appendWithBCI(x, bci());
1246 } 1240 }
1247 1241
1248 private Value appendWithoutOptimization(Instruction x, int bci) { 1242 private Value appendWithoutOptimization(Instruction x, int bci) {
1249 return appendWithBCI(x, bci, false); 1243 return appendWithBCI(x, bci);
1250 } 1244 }
1251 1245
1252 private Value appendWithBCI(Instruction x, int bci, boolean canonicalize) { 1246 private Value appendWithBCI(Instruction x, int bci) {
1253 if (canonicalize) {
1254 // attempt simple constant folding and strength reduction
1255 Value r = canonicalizer.canonicalize(x);
1256 List<Instruction> extra = canonicalizer.extra();
1257 if (extra != null) {
1258 // the canonicalization introduced instructions that should be added before this
1259 for (Instruction i : extra) {
1260 appendWithBCI(i, bci, false); // don't try to canonicalize the new instructions
1261 }
1262 }
1263 if (r instanceof Instruction) {
1264 // the result is an instruction that may need to be appended
1265 x = (Instruction) r;
1266 } else {
1267 // the result is not an instruction (and thus cannot be appended)
1268 return r;
1269 }
1270 }
1271 if (x.isAppended()) { 1247 if (x.isAppended()) {
1272 // the instruction has already been added 1248 // the instruction has already been added
1273 return x; 1249 return x;
1274 } 1250 }
1275 if (localValueMap != null) { 1251 if (localValueMap != null) {
1420 } 1396 }
1421 state.storeLocal(index, local); 1397 state.storeLocal(index, local);
1422 index += kind.sizeInSlots(); 1398 index += kind.sizeInSlots();
1423 } 1399 }
1424 return state; 1400 return state;
1425 }
1426
1427 boolean tryRemoveCall(RiMethod target, Value[] args, boolean isStatic) {
1428 if (target.isResolved()) {
1429 if (C1XOptions.CanonicalizeFoldableMethods) {
1430 // next try to fold the method call
1431 if (tryFoldable(target, args)) {
1432 return true;
1433 }
1434 }
1435 }
1436 return false;
1437 }
1438
1439 private boolean tryFoldable(RiMethod target, Value[] args) {
1440 CiConstant result = Canonicalizer.foldInvocation(compilation.runtime, target, args);
1441 if (result != null) {
1442 if (C1XOptions.TraceBytecodeParserLevel > 0) {
1443 log.println("|");
1444 log.println("| [folded " + target + " --> " + result + "]");
1445 log.println("|");
1446 }
1447
1448 pushReturn(returnKind(target), append(new Constant(result)));
1449 return true;
1450 }
1451 return false;
1452 } 1401 }
1453 1402
1454 private boolean tryInline(RiMethod target, Value[] args) { 1403 private boolean tryInline(RiMethod target, Value[] args) {
1455 boolean forcedInline = compilation.runtime.mustInline(target); 1404 boolean forcedInline = compilation.runtime.mustInline(target);
1456 if (forcedInline) { 1405 if (forcedInline) {