# HG changeset patch # User Josef Eisl # Date 1407917438 -7200 # Node ID 067dbd8e7114bfc8d2ec89e19261c9f07dc3a109 # Parent a62a928287e469e942d6bbeb17cfdcdf3568908a Use ValueConsumer in LinearScan where possible. diff -r a62a928287e4 -r 067dbd8e7114 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 Aug 12 17:18:48 2014 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java Wed Aug 13 10:10:38 2014 +0200 @@ -612,14 +612,13 @@ intervalsSize = operandSize(); intervals = new Interval[intervalsSize + (intervalsSize >> SPLIT_INTERVALS_CAPACITY_RIGHT_SHIFT)]; - ValueProcedure setVariableProc = new ValueProcedure() { + ValueConsumer setVariableConsumer = new ValueConsumer() { @Override - public Value doValue(Value value) { + public void visitValue(Value value) { if (isVariable(value)) { getOrCreateInterval(asVariable(value)); } - return value; } }; @@ -649,8 +648,8 @@ opIdToBlockMap[index] = block; assert instructionForId(opId) == op : "must match"; - op.forEachTemp(setVariableProc); - op.forEachOutput(setVariableProc); + op.visitEachTemp(setVariableConsumer); + op.visitEachOutput(setVariableConsumer); index++; opId += 2; // numbering of lirOps by two @@ -679,10 +678,10 @@ List instructions = ir.getLIRforBlock(block); int numInst = instructions.size(); - ValueProcedure useProc = new ValueProcedure() { + ValueConsumer useConsumer = new ValueConsumer() { @Override - protected Value doValue(Value operand) { + protected void visitValue(Value operand) { if (isVariable(operand)) { int operandNum = operandNumber(operand); if (!liveKill.get(operandNum)) { @@ -697,25 +696,23 @@ if (DetailedAsserts.getValue()) { verifyInput(block, liveKill, operand); } - return operand; } }; - ValueProcedure stateProc = new ValueProcedure() { + ValueConsumer stateConsumer = new ValueConsumer() { @Override - public Value doValue(Value operand) { + public void visitValue(Value operand) { int operandNum = operandNumber(operand); if (!liveKill.get(operandNum)) { liveGen.set(operandNum); Debug.log("liveGen in state for operand %d", operandNum); } - return operand; } }; - ValueProcedure defProc = new ValueProcedure() { + ValueConsumer defConsumer = new ValueConsumer() { @Override - public Value doValue(Value operand) { + public void visitValue(Value operand) { if (isVariable(operand)) { int varNum = operandNumber(operand); liveKill.set(varNum); @@ -731,7 +728,6 @@ // process them only in debug mode so that this can be checked verifyTemp(liveKill, operand); } - return operand; } }; @@ -740,13 +736,13 @@ final LIRInstruction op = instructions.get(j); try (Indent indent2 = Debug.logAndIndent("handle op %d", op.id())) { - op.forEachInput(useProc); - op.forEachAlive(useProc); + op.visitEachInput(useConsumer); + op.visitEachAlive(useConsumer); // Add uses of live locals from interpreter's point of view for proper debug // information generation - op.forEachState(stateProc); - op.forEachTemp(defProc); - op.forEachOutput(defProc); + op.visitEachState(stateConsumer); + op.visitEachTemp(defConsumer); + op.visitEachOutput(defConsumer); } } // end of instruction iteration @@ -1142,34 +1138,32 @@ void buildIntervals() { try (Indent indent = Debug.logAndIndent("build intervals")) { - InstructionValueProcedure outputProc = new InstructionValueProcedure() { + InstructionValueConsumer outputConsumer = new InstructionValueConsumer() { @Override - public Value doValue(LIRInstruction op, Value operand, OperandMode mode, EnumSet flags) { + public void visitValue(LIRInstruction op, Value operand, OperandMode mode, EnumSet flags) { if (isVariableOrRegister(operand)) { addDef((AllocatableValue) operand, op, registerPriorityOfOutputOperand(op), operand.getLIRKind()); addRegisterHint(op, operand, mode, flags, true); } - return operand; } }; - InstructionValueProcedure tempProc = new InstructionValueProcedure() { + InstructionValueConsumer tempConsumer = new InstructionValueConsumer() { @Override - public Value doValue(LIRInstruction op, Value operand, OperandMode mode, EnumSet flags) { + public void visitValue(LIRInstruction op, Value operand, OperandMode mode, EnumSet flags) { if (isVariableOrRegister(operand)) { addTemp((AllocatableValue) operand, op.id(), RegisterPriority.MustHaveRegister, operand.getLIRKind()); addRegisterHint(op, operand, mode, flags, false); } - return operand; } }; - InstructionValueProcedure aliveProc = new InstructionValueProcedure() { + InstructionValueConsumer aliveConsumer = new InstructionValueConsumer() { @Override - public Value doValue(LIRInstruction op, Value operand, OperandMode mode, EnumSet flags) { + public void visitValue(LIRInstruction op, Value operand, OperandMode mode, EnumSet flags) { if (isVariableOrRegister(operand)) { RegisterPriority p = registerPriorityOfInputOperand(flags); final int opId = op.id(); @@ -1177,14 +1171,13 @@ addUse((AllocatableValue) operand, blockFrom, opId + 1, p, operand.getLIRKind()); addRegisterHint(op, operand, mode, flags, false); } - return operand; } }; - InstructionValueProcedure inputProc = new InstructionValueProcedure() { + InstructionValueConsumer inputConsumer = new InstructionValueConsumer() { @Override - public Value doValue(LIRInstruction op, Value operand, OperandMode mode, EnumSet flags) { + public void visitValue(LIRInstruction op, Value operand, OperandMode mode, EnumSet flags) { if (isVariableOrRegister(operand)) { final int opId = op.id(); final int blockFrom = getFirstLirInstructionId((blockForId(opId))); @@ -1192,18 +1185,16 @@ addUse((AllocatableValue) operand, blockFrom, opId, p, operand.getLIRKind()); addRegisterHint(op, operand, mode, flags, false); } - return operand; } }; - InstructionValueProcedure stateProc = new InstructionValueProcedure() { + InstructionValueConsumer stateProc = new InstructionValueConsumer() { @Override - public Value doValue(LIRInstruction op, Value operand) { + public void visitValue(LIRInstruction op, Value operand) { final int opId = op.id(); final int blockFrom = getFirstLirInstructionId((blockForId(opId))); addUse((AllocatableValue) operand, blockFrom, opId + 1, RegisterPriority.None, operand.getLIRKind()); - return operand; } }; @@ -1260,17 +1251,17 @@ Debug.log("operation destroys all caller-save registers"); } - op.forEachOutput(outputProc); - op.forEachTemp(tempProc); - op.forEachAlive(aliveProc); - op.forEachInput(inputProc); + op.visitEachOutput(outputConsumer); + op.visitEachTemp(tempConsumer); + op.visitEachAlive(aliveConsumer); + op.visitEachInput(inputConsumer); // Add uses of live locals from interpreter's point of view for proper // debug information generation // Treat these operands as temp values (if the live range is extended // to a call site, the value would be in a register at // the call otherwise) - op.forEachState(stateProc); + op.visitEachState(stateProc); // special steps for some instructions (especially moves) handleMethodArguments(op); @@ -2199,25 +2190,24 @@ } } - class CheckProcedure extends ValueProcedure { + class CheckConsumer extends ValueConsumer { boolean ok; Interval curInterval; @Override - protected Value doValue(Value operand) { + protected void visitValue(Value operand) { if (isRegister(operand)) { if (intervalFor(operand) == curInterval) { ok = true; } } - return operand; } } void verifyNoOopsInFixedIntervals() { try (Indent indent = Debug.logAndIndent("verifying that no oops are in fixed intervals *")) { - CheckProcedure checkProc = new CheckProcedure(); + CheckConsumer checkConsumer = new CheckConsumer(); Interval fixedIntervals; Interval otherIntervals; @@ -2246,15 +2236,15 @@ // This interval is live out of this op so make sure // that this interval represents some value that's // referenced by this op either as an input or output. - checkProc.curInterval = interval; - checkProc.ok = false; + checkConsumer.curInterval = interval; + checkConsumer.ok = false; - op.forEachInput(checkProc); - op.forEachAlive(checkProc); - op.forEachTemp(checkProc); - op.forEachOutput(checkProc); + op.visitEachInput(checkConsumer); + op.visitEachAlive(checkConsumer); + op.visitEachTemp(checkConsumer); + op.visitEachOutput(checkConsumer); - assert checkProc.ok : "fixed intervals should never be live across an oopmap point"; + assert checkConsumer.ok : "fixed intervals should never be live across an oopmap point"; } } }