# HG changeset patch # User Tom Rodriguez # Date 1429036614 25200 # Node ID 3ffe4efcc39939e5d38808082d3dd63eff9c5748 # Parent 1af76d1979495bd9a2581fe2ace942a36099283b Allocate visiting lambdas earlier diff -r 1af76d197949 -r 3ffe4efcc399 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LocationMarker.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LocationMarker.java Tue Apr 14 11:36:48 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LocationMarker.java Tue Apr 14 11:36:54 2015 -0700 @@ -119,14 +119,6 @@ private static final EnumSet REGISTER_FLAG_SET = EnumSet.of(OperandFlag.REG); private static final LIRKind REFERENCE_KIND = LIRKind.reference(Kind.Object); - private void forEachDestroyedCallerSavedRegister(LIRInstruction op, ValueConsumer consumer) { - if (op.destroysCallerSavedRegisters()) { - for (Register reg : frameMap.getRegisterConfig().getCallerSaveRegisters()) { - consumer.visitValue(reg.asValue(REFERENCE_KIND), OperandMode.TEMP, REGISTER_FLAG_SET); - } - } - } - private final class BlockClosure { private final ReferenceMap currentSet; @@ -145,50 +137,53 @@ private void processInstructionBottomUp(LIRInstruction op) { try (Indent indent = Debug.logAndIndent("handle op %d, %s", op.id(), op)) { // kills - op.visitEachTemp(this::defConsumer); - op.visitEachOutput(this::defConsumer); - forEachDestroyedCallerSavedRegister(op, this::defConsumer); + + op.visitEachTemp(defConsumer); + op.visitEachOutput(defConsumer); + if (op.destroysCallerSavedRegisters()) { + for (Register reg : frameMap.getRegisterConfig().getCallerSaveRegisters()) { + defConsumer.visitValue(reg.asValue(REFERENCE_KIND), OperandMode.TEMP, REGISTER_FLAG_SET); + } + } // gen - values that are considered alive for this state - op.visitEachAlive(this::useConsumer); - op.visitEachState(this::useConsumer); + op.visitEachAlive(useConsumer); + op.visitEachState(useConsumer); // mark locations - op.forEachState((inst, info) -> markLocation(inst, info, this.getCurrentSet())); + op.forEachState(stateConsumer); // gen - op.visitEachInput(this::useConsumer); + op.visitEachInput(useConsumer); } } - /** - * @see InstructionValueConsumer - * @param operand - * @param mode - * @param flags - */ - private void useConsumer(Value operand, OperandMode mode, EnumSet flags) { - LIRKind kind = operand.getLIRKind(); - if (shouldProcessValue(operand) && !kind.isValue() && !kind.isDerivedReference()) { - // no need to insert values and derived reference - Debug.log("set operand: %s", operand); - frameMap.setReference(operand, currentSet); + InstructionStateProcedure stateConsumer = new InstructionStateProcedure() { + public void doState(LIRInstruction inst, LIRFrameState info) { + markLocation(inst, info, getCurrentSet()); } - } + }; - /** - * @see InstructionValueConsumer - * @param operand - * @param mode - * @param flags - */ - private void defConsumer(Value operand, OperandMode mode, EnumSet flags) { - if (shouldProcessValue(operand)) { - Debug.log("clear operand: %s", operand); - frameMap.clearReference(operand, currentSet); - } else { - assert isIllegal(operand) || operand.getPlatformKind() != Kind.Illegal || mode == OperandMode.TEMP : String.format("Illegal PlatformKind is only allowed for TEMP mode: %s, %s", - operand, mode); + ValueConsumer useConsumer = new ValueConsumer() { + public void visitValue(Value operand, OperandMode mode, EnumSet flags) { + LIRKind kind = operand.getLIRKind(); + if (shouldProcessValue(operand) && !kind.isValue() && !kind.isDerivedReference()) { + // no need to insert values and derived reference + Debug.log("set operand: %s", operand); + frameMap.setReference(operand, currentSet); + } } - } + }; + + ValueConsumer defConsumer = new ValueConsumer() { + public void visitValue(Value operand, OperandMode mode, EnumSet flags) { + if (shouldProcessValue(operand)) { + Debug.log("clear operand: %s", operand); + frameMap.clearReference(operand, currentSet); + } else { + assert isIllegal(operand) || operand.getPlatformKind() != Kind.Illegal || mode == OperandMode.TEMP : String.format( + "Illegal PlatformKind is only allowed for TEMP mode: %s, %s", operand, mode); + } + } + }; protected boolean shouldProcessValue(Value operand) { return (isRegister(operand) && attributes(asRegister(operand)).isAllocatable() || isStackSlot(operand)) && operand.getPlatformKind() != Kind.Illegal; diff -r 1af76d197949 -r 3ffe4efcc399 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/FixPointIntervalBuilder.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/FixPointIntervalBuilder.java Tue Apr 14 11:36:48 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/FixPointIntervalBuilder.java Tue Apr 14 11:36:54 2015 -0700 @@ -172,55 +172,42 @@ private void processInstructionBottomUp(LIRInstruction op) { try (Indent indent = Debug.logAndIndent("handle op %d, %s", op.id(), op)) { // kills - op.visitEachTemp(this::defConsumer); - op.visitEachOutput(this::defConsumer); + op.visitEachTemp(defConsumer); + op.visitEachOutput(defConsumer); // gen - values that are considered alive for this state - op.visitEachAlive(this::useConsumer); - op.visitEachState(this::useConsumer); + op.visitEachAlive(useConsumer); + op.visitEachState(useConsumer); // mark locations // gen - op.visitEachInput(this::useConsumer); + op.visitEachInput(useConsumer); } } - /** - * @see InstructionValueConsumer - * - * @param inst - * @param operand - * @param mode - * @param flags - */ - private void useConsumer(LIRInstruction inst, Value operand, OperandMode mode, EnumSet flags) { - if (isVirtualStackSlot(operand)) { - VirtualStackSlot vslot = asVirtualStackSlot(operand); - addUse(vslot, inst, flags); - usePos.add(inst); - Debug.log("set operand: %s", operand); - currentSet.set(vslot.getId()); + InstructionValueConsumer useConsumer = new InstructionValueConsumer() { + public void visitValue(LIRInstruction inst, Value operand, OperandMode mode, EnumSet flags) { + if (isVirtualStackSlot(operand)) { + VirtualStackSlot vslot = asVirtualStackSlot(operand); + addUse(vslot, inst, flags); + usePos.add(inst); + Debug.log("set operand: %s", operand); + currentSet.set(vslot.getId()); + } } - } + }; - /** - * - * @see InstructionValueConsumer - * - * @param inst - * @param operand - * @param mode - * @param flags - */ - private void defConsumer(LIRInstruction inst, Value operand, OperandMode mode, EnumSet flags) { - if (isVirtualStackSlot(operand)) { - VirtualStackSlot vslot = asVirtualStackSlot(operand); - addDef(vslot, inst); - usePos.add(inst); - Debug.log("clear operand: %s", operand); - currentSet.clear(vslot.getId()); + InstructionValueConsumer defConsumer = new InstructionValueConsumer() { + public void visitValue(LIRInstruction inst, Value operand, OperandMode mode, EnumSet flags) { + if (isVirtualStackSlot(operand)) { + VirtualStackSlot vslot = asVirtualStackSlot(operand); + addDef(vslot, inst); + usePos.add(inst); + Debug.log("clear operand: %s", operand); + currentSet.clear(vslot.getId()); + } + } - - } + }; private void addUse(VirtualStackSlot stackSlot, LIRInstruction inst, EnumSet flags) { StackInterval interval = getOrCreateInterval(stackSlot); diff -r 1af76d197949 -r 3ffe4efcc399 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java Tue Apr 14 11:36:48 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java Tue Apr 14 11:36:54 2015 -0700 @@ -363,30 +363,26 @@ private void assignStackSlots(Set usePos) { for (LIRInstruction op : usePos) { - op.forEachInput(this::assignSlot); - op.forEachAlive(this::assignSlot); - op.forEachState(this::assignSlot); + op.forEachInput(assignSlot); + op.forEachAlive(assignSlot); + op.forEachState(assignSlot); - op.forEachTemp(this::assignSlot); - op.forEachOutput(this::assignSlot); + op.forEachTemp(assignSlot); + op.forEachOutput(assignSlot); } } - /** - * @see ValueProcedure - * @param value - * @param mode - * @param flags - */ - private Value assignSlot(Value value, OperandMode mode, EnumSet flags) { - if (isVirtualStackSlot(value)) { - VirtualStackSlot slot = asVirtualStackSlot(value); - StackInterval interval = get(slot); - assert interval != null; - return interval.location(); + ValueProcedure assignSlot = new ValueProcedure() { + public Value doValue(Value value, OperandMode mode, EnumSet flags) { + if (isVirtualStackSlot(value)) { + VirtualStackSlot slot = asVirtualStackSlot(value); + StackInterval interval = get(slot); + assert interval != null; + return interval.location(); + } + return value; } - return value; - } + }; // ==================== //