changeset 13516:0b17dd482532

don't optimize moves involving unallocatable registers
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 02 Jan 2014 14:56:47 -0800
parents 03bb0ee05409
children eefb0224149d
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/MoveResolver.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java
diffstat 3 files changed, 38 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java	Thu Jan 02 18:02:01 2014 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java	Thu Jan 02 14:56:47 2014 -0800
@@ -29,6 +29,8 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
+import com.oracle.graal.graph.Node.Verbosity;
+import com.oracle.graal.lir.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.util.*;
 import com.oracle.graal.options.*;
@@ -224,12 +226,20 @@
                 } else {
                     Debug.log("Use -G:+DumpOnError to enable dumping of graphs on this error");
                 }
+            } else if (o instanceof LIR) {
+                Debug.log("Context obj %s", o);
+                if (DumpOnError.getValue()) {
+                    Debug.dump(o, "LIR");
+                } else {
+                    Debug.log("Use -G:+DumpOnError to enable dumping of graphs on this error");
+                }
             } else if (o instanceof Node) {
                 String location = GraphUtil.approxSourceLocation((Node) o);
+                String node = ((Node) o).toString(Verbosity.Debugger);
                 if (location != null) {
-                    Debug.log("Context obj %s (approx. location: %s)", o, location);
+                    Debug.log("Context obj %s (approx. location: %s)", node, location);
                 } else {
-                    Debug.log("Context obj %s", o);
+                    Debug.log("Context obj %s", node);
                 }
             } else {
                 Debug.log("Context obj %s", o);
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/MoveResolver.java	Thu Jan 02 18:02:01 2014 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/MoveResolver.java	Thu Jan 02 14:56:47 2014 -0800
@@ -23,11 +23,13 @@
 package com.oracle.graal.compiler.alloc;
 
 import static com.oracle.graal.api.code.ValueUtil.*;
+
 import java.util.*;
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.debug.*;
+import com.oracle.graal.debug.internal.*;
 import com.oracle.graal.lir.*;
 
 /**
@@ -120,6 +122,12 @@
         for (i = 0; i < mappingTo.size(); i++) {
             Interval interval = mappingTo.get(i);
             boolean unique = usedRegs.add(interval.location());
+            if (!unique) {
+                DebugScope.dump(this.allocator.ir, "exception");
+                DebugScope.dump(this.allocator.intervals, "exception");
+                DebugScope.dump(interval, "interval");
+                System.err.println(interval);
+            }
             assert unique : "cannot write to same register twice";
         }
 
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java	Thu Jan 02 18:02:01 2014 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java	Thu Jan 02 14:56:47 2014 -0800
@@ -83,6 +83,11 @@
 
     Register[] callerSaveRegs;
 
+    /**
+     * Contains the register number for registers which can be optimized and -1 for the others.
+     */
+    int[] eligibleRegs;
+
     Map<StackSlot, Integer> stackIndices = new HashMap<>();
 
     int numRegs;
@@ -97,12 +102,22 @@
      */
     private void doOptimize(LIR lir, FrameMap frameMap, ResolvedJavaMethod method) {
 
-        try (Indent indent = Debug.logAndIndent(false, "eliminate redundant moves in %s", method)) {
+        try (Indent indent = Debug.logAndIndent("eliminate redundant moves in %s", method)) {
 
             callerSaveRegs = frameMap.registerConfig.getCallerSaveRegisters();
 
             initBlockData(lir);
 
+            // Compute a table of the registers which are eligible for move optimization.
+            // Unallocatable registers should never be optimized.
+            eligibleRegs = new int[numRegs];
+            Arrays.fill(eligibleRegs, -1);
+            for (Register reg : frameMap.registerConfig.getAllocatableRegisters()) {
+                if (reg.number < numRegs) {
+                    eligibleRegs[reg.number] = reg.number;
+                }
+            }
+
             if (!solveDataFlow(lir)) {
                 return;
             }
@@ -448,8 +463,9 @@
         if (isRegister(location)) {
             int regNum = ((RegisterValue) location).getRegister().number;
             if (regNum < numRegs) {
-                return regNum;
+                return eligibleRegs[regNum];
             }
+            return -1;
         }
         if (isStackSlot(location)) {
             StackSlot slot = (StackSlot) location;