# HG changeset patch # User Roland Schatz # Date 1363078940 -3600 # Node ID 2c5df42999dd9236e31f5ff01c1033affdb96679 # Parent 3e8d66931c801b9f3a51ae871d4e31acd8e347fd Fix hinting in register allocator. diff -r 3e8d66931c80 -r 2c5df42999dd graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/AMD64AllocatorTest.java --- a/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/AMD64AllocatorTest.java Tue Mar 12 10:02:10 2013 +0100 +++ b/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/AMD64AllocatorTest.java Tue Mar 12 10:02:20 2013 +0100 @@ -37,7 +37,6 @@ return x + 5; } - @Ignore @Test public void test2() { test("test2snippet", 2, 0, 0); diff -r 3e8d66931c80 -r 2c5df42999dd graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java Tue Mar 12 10:02:10 2013 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java Tue Mar 12 10:02:20 2013 +0100 @@ -347,6 +347,15 @@ return intervals[operandNumber]; } + Interval getOrCreateInterval(Value operand) { + Interval ret = intervalFor(operand); + if (ret == null) { + return createInterval(operand); + } else { + return ret; + } + } + /** * Gets the highest instruction id allocated by this object. */ @@ -968,11 +977,7 @@ TTY.println(" use %s from %d to %d (%s)", operand, from, to, registerPriority.name()); } - Interval interval = intervalFor(operand); - if (interval == null) { - interval = createInterval(operand); - } - + Interval interval = getOrCreateInterval(operand); if (kind != Kind.Illegal) { interval.setKind(kind); } @@ -990,11 +995,8 @@ if (GraalOptions.TraceLinearScanLevel >= 2) { TTY.println(" temp %s tempPos %d (%s)", operand, tempPos, RegisterPriority.MustHaveRegister.name()); } - Interval interval = intervalFor(operand); - if (interval == null) { - interval = createInterval(operand); - } + Interval interval = getOrCreateInterval(operand); if (kind != Kind.Illegal) { interval.setKind(kind); } @@ -1014,42 +1016,26 @@ if (GraalOptions.TraceLinearScanLevel >= 2) { TTY.println(" def %s defPos %d (%s)", operand, defPos, registerPriority.name()); } - Interval interval = intervalFor(operand); - if (interval != null) { - if (kind != Kind.Illegal) { - interval.setKind(kind); - } + Interval interval = getOrCreateInterval(operand); + if (kind != Kind.Illegal) { + interval.setKind(kind); + } - Range r = interval.first(); - if (r.from <= defPos) { - // Update the starting point (when a range is first created for a use, its - // start is the beginning of the current block until a def is encountered.) - r.from = defPos; - interval.addUsePos(defPos, registerPriority); - - } else { - // Dead value - make vacuous interval - // also add register priority for dead intervals - interval.addRange(defPos, defPos + 1); - interval.addUsePos(defPos, registerPriority); - if (GraalOptions.TraceLinearScanLevel >= 2) { - TTY.println("Warning: def of operand %s at %d occurs without use", operand, defPos); - } - } + Range r = interval.first(); + if (r.from <= defPos) { + // Update the starting point (when a range is first created for a use, its + // start is the beginning of the current block until a def is encountered.) + r.from = defPos; + interval.addUsePos(defPos, registerPriority); } else { // Dead value - make vacuous interval // also add register priority for dead intervals - interval = createInterval(operand); - if (kind != Kind.Illegal) { - interval.setKind(kind); - } - interval.addRange(defPos, defPos + 1); interval.addUsePos(defPos, registerPriority); if (GraalOptions.TraceLinearScanLevel >= 2) { - TTY.println("Warning: dead value %s at %d in live intervals", operand, defPos); + TTY.println("Warning: def of operand %s at %d occurs without use", operand, defPos); } } @@ -1114,7 +1100,7 @@ } } - void addRegisterHint(final LIRInstruction op, final Value targetValue, OperandMode mode, EnumSet flags) { + void addRegisterHint(final LIRInstruction op, final Value targetValue, OperandMode mode, EnumSet flags, final boolean hintAtDef) { if (flags.contains(OperandFlag.HINT) && isVariableOrRegister(targetValue)) { op.forEachRegisterHint(targetValue, mode, new ValueProcedure() { @@ -1122,15 +1108,20 @@ @Override protected Value doValue(Value registerHint) { if (isVariableOrRegister(registerHint)) { - Interval from = intervalFor(registerHint); - Interval to = intervalFor(targetValue); - if (from != null && to != null) { + Interval from = getOrCreateInterval(registerHint); + Interval to = getOrCreateInterval(targetValue); + + // hints always point from def to use + if (hintAtDef) { to.setLocationHint(from); - if (GraalOptions.TraceLinearScanLevel >= 4) { - TTY.println("operation at opId %d: added hint from interval %d to %d", op.id(), from.operandNumber, to.operandNumber); - } - return registerHint; + } else { + from.setLocationHint(to); } + + if (GraalOptions.TraceLinearScanLevel >= 4) { + TTY.println("operation at opId %d: added hint from interval %d to %d", op.id(), from.operandNumber, to.operandNumber); + } + return registerHint; } return null; } @@ -1201,7 +1192,7 @@ public Value doValue(Value operand, OperandMode mode, EnumSet flags) { if (isVariableOrRegister(operand)) { addDef(operand, opId, registerPriorityOfOutputOperand(op), operand.getKind().getStackKind()); - addRegisterHint(op, operand, mode, flags); + addRegisterHint(op, operand, mode, flags, true); } return operand; } @@ -1212,7 +1203,7 @@ public Value doValue(Value operand, OperandMode mode, EnumSet flags) { if (isVariableOrRegister(operand)) { addTemp(operand, opId, RegisterPriority.MustHaveRegister, operand.getKind().getStackKind()); - addRegisterHint(op, operand, mode, flags); + addRegisterHint(op, operand, mode, flags, false); } return operand; } @@ -1224,7 +1215,7 @@ if (isVariableOrRegister(operand)) { RegisterPriority p = registerPriorityOfInputOperand(flags); addUse(operand, blockFrom, opId + 1, p, operand.getKind().getStackKind()); - addRegisterHint(op, operand, mode, flags); + addRegisterHint(op, operand, mode, flags, false); } return operand; } @@ -1236,7 +1227,7 @@ if (isVariableOrRegister(operand)) { RegisterPriority p = registerPriorityOfInputOperand(flags); addUse(operand, blockFrom, opId, p, operand.getKind().getStackKind()); - addRegisterHint(op, operand, mode, flags); + addRegisterHint(op, operand, mode, flags, false); } return operand; }