comparison graal/com.oracle.max.criutils/src/com/oracle/max/criutils/CompilationPrinter.java @ 4169:f5328dda9714

Initial commit of SSA-based spill-all register assignment
author Christian Wimmer <Christian.Wimmer@Oracle.com>
date Wed, 28 Dec 2011 18:13:25 -0800
parents bc8527f3071c
children 319860ae697a
comparison
equal deleted inserted replaced
4168:0bc4815d2069 4169:f5328dda9714
23 package com.oracle.max.criutils; 23 package com.oracle.max.criutils;
24 24
25 import java.io.*; 25 import java.io.*;
26 26
27 import com.sun.cri.ci.*; 27 import com.sun.cri.ci.*;
28 import com.sun.cri.ci.CiAddress.Scale;
29 import com.sun.cri.ci.CiValue.Formatter;
30 import com.sun.cri.ri.*; 28 import com.sun.cri.ri.*;
31 29
32 /** 30 /**
33 * Utility for printing compilation related data structures at various compilation phases. 31 * Utility for printing compilation related data structures at various compilation phases.
34 * The output format is such that it can then be fed to the 32 * The output format is such that it can then be fed to the
103 } 101 }
104 102
105 /** 103 /**
106 * Formats a given {@linkplain FrameState JVM frame state} as a multi line string. 104 * Formats a given {@linkplain FrameState JVM frame state} as a multi line string.
107 */ 105 */
108 protected String debugInfoToString(CiCodePos codePos, CiBitMap registerRefMap, CiBitMap frameRefMap, OperandFormatter fmt, CiArchitecture arch) { 106 protected String debugInfoToString(CiCodePos codePos, CiBitMap registerRefMap, CiBitMap frameRefMap, CiArchitecture arch) {
109 StringBuilder sb = new StringBuilder(); 107 StringBuilder sb = new StringBuilder();
110 108
111 if (registerRefMap != null) { 109 if (registerRefMap != null) {
112 sb.append("reg-ref-map:"); 110 sb.append("reg-ref-map:");
113 for (int reg = registerRefMap.nextSetBit(0); reg >= 0; reg = registerRefMap.nextSetBit(reg + 1)) { 111 for (int reg = registerRefMap.nextSetBit(0); reg >= 0; reg = registerRefMap.nextSetBit(reg + 1)) {
132 if (curCodePos instanceof CiFrame) { 130 if (curCodePos instanceof CiFrame) {
133 CiFrame frame = (CiFrame) curCodePos; 131 CiFrame frame = (CiFrame) curCodePos;
134 if (frame.numStack > 0) { 132 if (frame.numStack > 0) {
135 sb.append("stack: "); 133 sb.append("stack: ");
136 for (int i = 0; i < frame.numStack; i++) { 134 for (int i = 0; i < frame.numStack; i++) {
137 sb.append(valueToString(frame.getStackValue(i), fmt)).append(' '); 135 sb.append(valueToString(frame.getStackValue(i))).append(' ');
138 } 136 }
139 sb.append("\n"); 137 sb.append("\n");
140 } 138 }
141 139
142 if (frame.numLocks > 0) { 140 if (frame.numLocks > 0) {
143 sb.append("locks: "); 141 sb.append("locks: ");
144 for (int i = 0; i < frame.numLocks; ++i) { 142 for (int i = 0; i < frame.numLocks; ++i) {
145 sb.append(valueToString(frame.getLockValue(i), fmt)).append(' '); 143 sb.append(valueToString(frame.getLockValue(i))).append(' ');
146 } 144 }
147 sb.append("\n"); 145 sb.append("\n");
148 } 146 }
149 147
150 sb.append("locals: "); 148 sb.append("locals: ");
151 for (int i = 0; i < frame.numLocals; i++) { 149 for (int i = 0; i < frame.numLocals; i++) {
152 sb.append(valueToString(frame.getLocalValue(i), fmt)).append(' '); 150 sb.append(valueToString(frame.getLocalValue(i))).append(' ');
153 } 151 }
154 sb.append("\n"); 152 sb.append("\n");
155 } 153 }
156 curCodePos = curCodePos.caller; 154 curCodePos = curCodePos.caller;
157 } while (curCodePos != null); 155 } while (curCodePos != null);
158 } 156 }
159 return sb.toString(); 157 return sb.toString();
160 } 158 }
161 159
162 160 protected String valueToString(CiValue value) {
163 protected String valueToString(CiValue value, Formatter operandFmt) {
164 if (value == null) { 161 if (value == null) {
165 return "-"; 162 return "-";
166 } 163 }
167 return operandFmt.format(value); 164 return value.toString();
168 }
169
170
171 /**
172 * Formats LIR operands as expected by the C1 Visualizer.
173 */
174 public static class OperandFormatter extends Formatter {
175 /**
176 * The textual delimiters used for an operand depend on the context in which it is being
177 * printed. When printed as part of a frame state or as the result operand in a HIR node listing,
178 * it is enclosed in double-quotes (i.e. {@code "}'s).
179 */
180 public final boolean asStateOrHIROperandResult;
181
182 public OperandFormatter(boolean asStateOrHIROperandResult) {
183 this.asStateOrHIROperandResult = asStateOrHIROperandResult;
184 }
185
186 @Override
187 public String format(CiValue operand) {
188 if (operand.isLegal()) {
189 String op;
190 if (operand.isVariableOrRegister() || operand.isStackSlot()) {
191 op = operand.name();
192 } else if (operand.isConstant()) {
193 CiConstant constant = (CiConstant) operand;
194 op = operand.kind.javaName + ":" + operand.kind.format(constant.boxedValue());
195 } else if (operand.isAddress()) {
196 CiAddress address = (CiAddress) operand;
197 op = "Base:" + format(address.base);
198 if (!address.index.isIllegal()) {
199 op += " Index:" + format(address.index);
200 }
201 if (address.scale != Scale.Times1) {
202 op += " * " + address.scale.value;
203 }
204 op += " Disp:" + address.displacement;
205 } else {
206 assert operand.isIllegal();
207 op = "-";
208 }
209 if (operand.kind != CiKind.Illegal) {
210 op += "|" + operand.kind.typeChar;
211 }
212 if (asStateOrHIROperandResult) {
213 op = " \"" + op.replace('"', '\'') + "\" ";
214 }
215 return op;
216 }
217 return "";
218 }
219 } 165 }
220 166
221 public void printMachineCode(String code, String label) { 167 public void printMachineCode(String code, String label) {
222 if (code.length() == 0) { 168 if (code.length() == 0) {
223 return; 169 return;