changeset 20975:3ffe4efcc399

Allocate visiting lambdas earlier
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 14 Apr 2015 11:36:54 -0700
parents 1af76d197949
children 1ee4ac09b741
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LocationMarker.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/FixPointIntervalBuilder.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java
diffstat 3 files changed, 78 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- 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<OperandFlag> 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<OperandFlag> 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<OperandFlag> 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<OperandFlag> 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<OperandFlag> 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;
--- 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<OperandFlag> 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<OperandFlag> 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<OperandFlag> 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<OperandFlag> 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<OperandFlag> flags) {
             StackInterval interval = getOrCreateInterval(stackSlot);
--- 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<LIRInstruction> 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<OperandFlag> 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<OperandFlag> flags) {
+                if (isVirtualStackSlot(value)) {
+                    VirtualStackSlot slot = asVirtualStackSlot(value);
+                    StackInterval interval = get(slot);
+                    assert interval != null;
+                    return interval.location();
+                }
+                return value;
             }
-            return value;
-        }
+        };
 
         // ====================
         //