comparison graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java @ 19164:b215b88e215f

Introduce LIRGenerationDebugContext.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 05 Feb 2015 19:17:47 +0100
parents 0751ebc54c13
children b3b81dfff200
comparison
equal deleted inserted replaced
19163:0751ebc54c13 19164:b215b88e215f
25 import static com.oracle.graal.api.code.CodeUtil.*; 25 import static com.oracle.graal.api.code.CodeUtil.*;
26 import static com.oracle.graal.api.code.ValueUtil.*; 26 import static com.oracle.graal.api.code.ValueUtil.*;
27 import static com.oracle.graal.compiler.common.GraalOptions.*; 27 import static com.oracle.graal.compiler.common.GraalOptions.*;
28 import static com.oracle.graal.compiler.common.cfg.AbstractControlFlowGraph.*; 28 import static com.oracle.graal.compiler.common.cfg.AbstractControlFlowGraph.*;
29 import static com.oracle.graal.lir.LIRValueUtil.*; 29 import static com.oracle.graal.lir.LIRValueUtil.*;
30 import static com.oracle.graal.lir.debug.LIRGenerationDebugContext.*;
30 31
31 import java.util.*; 32 import java.util.*;
32 33
33 import com.oracle.graal.alloc.*; 34 import com.oracle.graal.alloc.*;
34 import com.oracle.graal.api.code.*; 35 import com.oracle.graal.api.code.*;
37 import com.oracle.graal.compiler.alloc.Interval.RegisterPriority; 38 import com.oracle.graal.compiler.alloc.Interval.RegisterPriority;
38 import com.oracle.graal.compiler.alloc.Interval.SpillState; 39 import com.oracle.graal.compiler.alloc.Interval.SpillState;
39 import com.oracle.graal.compiler.common.*; 40 import com.oracle.graal.compiler.common.*;
40 import com.oracle.graal.compiler.common.cfg.*; 41 import com.oracle.graal.compiler.common.cfg.*;
41 import com.oracle.graal.compiler.common.util.*; 42 import com.oracle.graal.compiler.common.util.*;
42 import com.oracle.graal.compiler.gen.*;
43 import com.oracle.graal.debug.*; 43 import com.oracle.graal.debug.*;
44 import com.oracle.graal.debug.Debug.Scope; 44 import com.oracle.graal.debug.Debug.Scope;
45 import com.oracle.graal.lir.*; 45 import com.oracle.graal.lir.*;
46 import com.oracle.graal.lir.LIRInstruction.OperandFlag; 46 import com.oracle.graal.lir.LIRInstruction.OperandFlag;
47 import com.oracle.graal.lir.LIRInstruction.OperandMode; 47 import com.oracle.graal.lir.LIRInstruction.OperandMode;
48 import com.oracle.graal.lir.StandardOp.MoveOp; 48 import com.oracle.graal.lir.StandardOp.MoveOp;
49 import com.oracle.graal.lir.framemap.*; 49 import com.oracle.graal.lir.framemap.*;
50 import com.oracle.graal.lir.gen.*; 50 import com.oracle.graal.lir.gen.*;
51 import com.oracle.graal.nodes.*;
52 import com.oracle.graal.options.*; 51 import com.oracle.graal.options.*;
53 52
54 /** 53 /**
55 * An implementation of the linear scan register allocator algorithm described in <a 54 * An implementation of the linear scan register allocator algorithm described in <a
56 * href="http://doi.acm.org/10.1145/1064979.1064998" 55 * href="http://doi.acm.org/10.1145/1064979.1064998"
862 throw new GraalInternalError("liveIn set of first block must be empty: " + blockData.get(startBlock).liveIn); 861 throw new GraalInternalError("liveIn set of first block must be empty: " + blockData.get(startBlock).liveIn);
863 } 862 }
864 } 863 }
865 } 864 }
866 865
867 private static NodeLIRBuilder getNodeLIRGeneratorFromDebugContext() {
868 if (Debug.isEnabled()) {
869 NodeLIRBuilder lirGen = Debug.contextLookup(NodeLIRBuilder.class);
870 assert lirGen != null;
871 return lirGen;
872 }
873 return null;
874 }
875
876 private static ValueNode getValueForOperandFromDebugContext(Value value) {
877 NodeLIRBuilder gen = getNodeLIRGeneratorFromDebugContext();
878 if (gen != null) {
879 return gen.valueForOperand(value);
880 }
881 return null;
882 }
883
884 private void reportFailure(int numBlocks) { 866 private void reportFailure(int numBlocks) {
885 try (Scope s = Debug.forceLog()) { 867 try (Scope s = Debug.forceLog()) {
886 try (Indent indent = Debug.logAndIndent("report failure")) { 868 try (Indent indent = Debug.logAndIndent("report failure")) {
887 869
888 BitSet startBlockLiveIn = blockData.get(ir.getControlFlowGraph().getStartBlock()).liveIn; 870 BitSet startBlockLiveIn = blockData.get(ir.getControlFlowGraph().getStartBlock()).liveIn;
889 try (Indent indent2 = Debug.logAndIndent("Error: liveIn set of first block must be empty (when this fails, variables are used before they are defined):")) { 871 try (Indent indent2 = Debug.logAndIndent("Error: liveIn set of first block must be empty (when this fails, variables are used before they are defined):")) {
890 for (int operandNum = startBlockLiveIn.nextSetBit(0); operandNum >= 0; operandNum = startBlockLiveIn.nextSetBit(operandNum + 1)) { 872 for (int operandNum = startBlockLiveIn.nextSetBit(0); operandNum >= 0; operandNum = startBlockLiveIn.nextSetBit(operandNum + 1)) {
891 Interval interval = intervalFor(operandNum); 873 Interval interval = intervalFor(operandNum);
892 if (interval != null) { 874 if (interval != null) {
893 Value operand = interval.operand; 875 Value operand = interval.operand;
894 Debug.log("var %d; operand=%s; node=%s", operandNum, operand, getValueForOperandFromDebugContext(operand)); 876 Debug.log("var %d; operand=%s; node=%s", operandNum, operand, getSourceForOperandFromDebugContext(operand));
895 } else { 877 } else {
896 Debug.log("var %d; missing operand", operandNum); 878 Debug.log("var %d; missing operand", operandNum);
897 } 879 }
898 } 880 }
899 } 881 }
900 882
901 // print some additional information to simplify debugging 883 // print some additional information to simplify debugging
902 for (int operandNum = startBlockLiveIn.nextSetBit(0); operandNum >= 0; operandNum = startBlockLiveIn.nextSetBit(operandNum + 1)) { 884 for (int operandNum = startBlockLiveIn.nextSetBit(0); operandNum >= 0; operandNum = startBlockLiveIn.nextSetBit(operandNum + 1)) {
903 Interval interval = intervalFor(operandNum); 885 Interval interval = intervalFor(operandNum);
904 Value operand = null; 886 Value operand = null;
905 ValueNode valueForOperandFromDebugContext = null; 887 Object valueForOperandFromDebugContext = null;
906 if (interval != null) { 888 if (interval != null) {
907 operand = interval.operand; 889 operand = interval.operand;
908 valueForOperandFromDebugContext = getValueForOperandFromDebugContext(operand); 890 valueForOperandFromDebugContext = getSourceForOperandFromDebugContext(operand);
909 } 891 }
910 try (Indent indent2 = Debug.logAndIndent("---- Detailed information for var %d; operand=%s; node=%s ----", operandNum, operand, valueForOperandFromDebugContext)) { 892 try (Indent indent2 = Debug.logAndIndent("---- Detailed information for var %d; operand=%s; node=%s ----", operandNum, operand, valueForOperandFromDebugContext)) {
911 893
912 Deque<AbstractBlock<?>> definedIn = new ArrayDeque<>(); 894 Deque<AbstractBlock<?>> definedIn = new ArrayDeque<>();
913 HashSet<AbstractBlock<?>> usedIn = new HashSet<>(); 895 HashSet<AbstractBlock<?>> usedIn = new HashSet<>();