changeset 19164:b215b88e215f

Introduce LIRGenerationDebugContext.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 05 Feb 2015 19:17:47 +0100
parents 0751ebc54c13
children b3b81dfff200
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/debug/LIRGenerationDebugContext.java
diffstat 3 files changed, 68 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Thu Feb 05 18:37:10 2015 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Thu Feb 05 19:17:47 2015 +0100
@@ -27,6 +27,7 @@
 import static com.oracle.graal.compiler.common.GraalOptions.*;
 import static com.oracle.graal.compiler.common.cfg.AbstractControlFlowGraph.*;
 import static com.oracle.graal.lir.LIRValueUtil.*;
+import static com.oracle.graal.lir.debug.LIRGenerationDebugContext.*;
 
 import java.util.*;
 
@@ -39,7 +40,6 @@
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.common.cfg.*;
 import com.oracle.graal.compiler.common.util.*;
-import com.oracle.graal.compiler.gen.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.debug.Debug.Scope;
 import com.oracle.graal.lir.*;
@@ -48,7 +48,6 @@
 import com.oracle.graal.lir.StandardOp.MoveOp;
 import com.oracle.graal.lir.framemap.*;
 import com.oracle.graal.lir.gen.*;
-import com.oracle.graal.nodes.*;
 import com.oracle.graal.options.*;
 
 /**
@@ -864,23 +863,6 @@
         }
     }
 
-    private static NodeLIRBuilder getNodeLIRGeneratorFromDebugContext() {
-        if (Debug.isEnabled()) {
-            NodeLIRBuilder lirGen = Debug.contextLookup(NodeLIRBuilder.class);
-            assert lirGen != null;
-            return lirGen;
-        }
-        return null;
-    }
-
-    private static ValueNode getValueForOperandFromDebugContext(Value value) {
-        NodeLIRBuilder gen = getNodeLIRGeneratorFromDebugContext();
-        if (gen != null) {
-            return gen.valueForOperand(value);
-        }
-        return null;
-    }
-
     private void reportFailure(int numBlocks) {
         try (Scope s = Debug.forceLog()) {
             try (Indent indent = Debug.logAndIndent("report failure")) {
@@ -891,7 +873,7 @@
                         Interval interval = intervalFor(operandNum);
                         if (interval != null) {
                             Value operand = interval.operand;
-                            Debug.log("var %d; operand=%s; node=%s", operandNum, operand, getValueForOperandFromDebugContext(operand));
+                            Debug.log("var %d; operand=%s; node=%s", operandNum, operand, getSourceForOperandFromDebugContext(operand));
                         } else {
                             Debug.log("var %d; missing operand", operandNum);
                         }
@@ -902,10 +884,10 @@
                 for (int operandNum = startBlockLiveIn.nextSetBit(0); operandNum >= 0; operandNum = startBlockLiveIn.nextSetBit(operandNum + 1)) {
                     Interval interval = intervalFor(operandNum);
                     Value operand = null;
-                    ValueNode valueForOperandFromDebugContext = null;
+                    Object valueForOperandFromDebugContext = null;
                     if (interval != null) {
                         operand = interval.operand;
-                        valueForOperandFromDebugContext = getValueForOperandFromDebugContext(operand);
+                        valueForOperandFromDebugContext = getSourceForOperandFromDebugContext(operand);
                     }
                     try (Indent indent2 = Debug.logAndIndent("---- Detailed information for var %d; operand=%s; node=%s ----", operandNum, operand, valueForOperandFromDebugContext)) {
 
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java	Thu Feb 05 18:37:10 2015 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java	Thu Feb 05 19:17:47 2015 +0100
@@ -42,6 +42,7 @@
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.StandardOp.JumpOp;
+import com.oracle.graal.lir.debug.*;
 import com.oracle.graal.lir.gen.*;
 import com.oracle.graal.lir.gen.LIRGenerator.Options;
 import com.oracle.graal.nodes.*;
@@ -81,7 +82,7 @@
 @MatchableNode(nodeClass = XorNode.class, inputs = {"x", "y"}, commutative = true)
 @MatchableNode(nodeClass = PiNode.class, inputs = {"object"})
 @MatchableNode(nodeClass = ConstantLocationNode.class, shareable = true)
-public abstract class NodeLIRBuilder implements NodeLIRBuilderTool {
+public abstract class NodeLIRBuilder implements NodeLIRBuilderTool, LIRGenerationDebugContext {
 
     private final NodeMap<Value> nodeOperands;
     private final DebugInfoBuilder debugInfoBuilder;
@@ -143,6 +144,11 @@
     }
 
     @Override
+    public Object getSourceForOperand(Value value) {
+        return valueForOperand(value);
+    }
+
+    @Override
     public Value setResult(ValueNode x, Value operand) {
         assert (!isRegister(operand) || !gen.attributes(asRegister(operand)).isAllocatable());
         assert nodeOperands != null && (nodeOperands.get(x) == null || nodeOperands.get(x) instanceof ComplexMatchValue) : "operand cannot be set twice";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/debug/LIRGenerationDebugContext.java	Thu Feb 05 19:17:47 2015 +0100
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.lir.debug;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.debug.*;
+import com.oracle.graal.lir.*;
+
+/**
+ * Provides information about {@link LIR} generation for debugging purposes.
+ */
+public interface LIRGenerationDebugContext {
+
+    /**
+     * Gets an object that represents the source of an {@link LIR} {@link Value operand} in a higher
+     * representation.
+     */
+    Object getSourceForOperand(Value value);
+
+    static LIRGenerationDebugContext getFromDebugContext() {
+        if (Debug.isEnabled()) {
+            LIRGenerationDebugContext lirGen = Debug.contextLookup(LIRGenerationDebugContext.class);
+            assert lirGen != null;
+            return lirGen;
+        }
+        return null;
+    }
+
+    static Object getSourceForOperandFromDebugContext(Value value) {
+        LIRGenerationDebugContext gen = getFromDebugContext();
+        if (gen != null) {
+            return gen.getSourceForOperand(value);
+        }
+        return null;
+    }
+
+}