changeset 22451:df65e223fd34

LSRA: LinearScanAssignLocationsPhase refactor assignLocations.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 13 Aug 2015 12:02:01 +0200
parents 7932a885e4bb
children 0c3050170ba8
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanAssignLocationsPhase.java
diffstat 1 files changed, 46 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanAssignLocationsPhase.java	Thu Aug 13 11:35:37 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanAssignLocationsPhase.java	Thu Aug 13 12:02:01 2015 +0200
@@ -29,11 +29,11 @@
 import java.util.*;
 
 import jdk.internal.jvmci.code.*;
-import com.oracle.graal.debug.*;
 import jdk.internal.jvmci.meta.*;
 
 import com.oracle.graal.compiler.common.alloc.*;
 import com.oracle.graal.compiler.common.cfg.*;
+import com.oracle.graal.debug.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.LIRInstruction.OperandFlag;
 import com.oracle.graal.lir.LIRInstruction.OperandMode;
@@ -156,7 +156,6 @@
         int numInst = instructions.size();
         boolean hasDead = false;
 
-        InstructionValueProcedure assignProc = (op, operand, mode, flags) -> isVariable(operand) ? colorLirOperand(op, (Variable) operand, mode) : operand;
         for (int j = 0; j < numInst; j++) {
             final LIRInstruction op = instructions.get(j);
             if (op == null) {
@@ -164,40 +163,9 @@
                  * this can happen when spill-moves are removed in eliminateSpillMoves
                  */
                 hasDead = true;
-                continue;
-            }
-
-            // remove useless moves
-            MoveOp move = null;
-            if (op instanceof MoveOp) {
-                move = (MoveOp) op;
-                AllocatableValue result = move.getResult();
-                if (isVariable(result) && allocator.isMaterialized(result, op.id(), OperandMode.DEF)) {
-                    /*
-                     * This happens if a materializable interval is originally not spilled but then
-                     * kicked out in LinearScanWalker.splitForSpilling(). When kicking out such an
-                     * interval this move operation was already generated.
-                     */
-                    instructions.set(j, null);
-                    hasDead = true;
-                    continue;
-                }
-            }
-
-            op.forEachInput(assignProc);
-            op.forEachAlive(assignProc);
-            op.forEachTemp(assignProc);
-            op.forEachOutput(assignProc);
-
-            // compute reference map and debug information
-            op.forEachState((inst, state) -> computeDebugInfo(inst, state));
-
-            // remove useless moves
-            if (move != null) {
-                if (move.getInput().equals(move.getResult())) {
-                    instructions.set(j, null);
-                    hasDead = true;
-                }
+            } else if (assignLocations(op)) {
+                instructions.set(j, null);
+                hasDead = true;
             }
         }
 
@@ -207,6 +175,48 @@
         }
     }
 
+    /**
+     * Assigns the operand of an {@link LIRInstruction}.
+     *
+     * @param op The {@link LIRInstruction} that should be colored.
+     * @return {@code true} if the instruction should be deleted.
+     */
+    protected boolean assignLocations(LIRInstruction op) {
+        assert op != null;
+
+        InstructionValueProcedure assignProc = (inst, operand, mode, flags) -> isVariable(operand) ? colorLirOperand(inst, (Variable) operand, mode) : operand;
+        // remove useless moves
+        MoveOp move = null;
+        if (op instanceof MoveOp) {
+            move = (MoveOp) op;
+            AllocatableValue result = move.getResult();
+            if (isVariable(result) && allocator.isMaterialized(result, op.id(), OperandMode.DEF)) {
+                /*
+                 * This happens if a materializable interval is originally not spilled but then
+                 * kicked out in LinearScanWalker.splitForSpilling(). When kicking out such an
+                 * interval this move operation was already generated.
+                 */
+                return true;
+            }
+        }
+
+        op.forEachInput(assignProc);
+        op.forEachAlive(assignProc);
+        op.forEachTemp(assignProc);
+        op.forEachOutput(assignProc);
+
+        // compute reference map and debug information
+        op.forEachState((inst, state) -> computeDebugInfo(inst, state));
+
+        // remove useless moves
+        if (move != null) {
+            if (move.getInput().equals(move.getResult())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private void assignLocations() {
         try (Indent indent = Debug.logAndIndent("assign locations")) {
             for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {