Mercurial > hg > graal-compiler
changeset 22568:3714119dfbc0
CFGPrinter: introduce IntervalDumper to abstract LSRA interval dumping.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 02 Sep 2015 11:47:11 +0200 |
parents | 6de3a450bc17 |
children | d2fcadb5bc37 |
files | graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanIntervalDumper.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/debug/IntervalDumper.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/StackIntervalDumper.java graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java |
diffstat | 7 files changed, 233 insertions(+), 87 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java Tue Sep 01 14:30:54 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java Wed Sep 02 11:47:11 2015 +0200 @@ -697,7 +697,7 @@ } } } - Debug.dump(Arrays.copyOf(intervals, intervalsSize), label); + Debug.dump(new LinearScanIntervalDumper(Arrays.copyOf(intervals, intervalsSize)), label); } public void printLir(String label, @SuppressWarnings("unused") boolean hirValid) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanIntervalDumper.java Wed Sep 02 11:47:11 2015 +0200 @@ -0,0 +1,73 @@ +/* + * 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.alloc.lsra; + +import static jdk.internal.jvmci.code.ValueUtil.*; +import jdk.internal.jvmci.meta.*; + +import com.oracle.graal.lir.alloc.lsra.Interval.UsePosList; +import com.oracle.graal.lir.debug.*; + +class LinearScanIntervalDumper implements IntervalDumper { + private final Interval[] intervals; + + public LinearScanIntervalDumper(Interval[] intervals) { + this.intervals = intervals; + } + + public void visitIntervals(IntervalVisitor visitor) { + for (Interval interval : intervals) { + if (interval != null) { + printInterval(interval, visitor); + } + } + } + + private static void printInterval(Interval interval, IntervalVisitor visitor) { + Value hint = interval.locationHint(false) != null ? interval.locationHint(false).operand : null; + AllocatableValue operand = interval.operand; + String type = isRegister(operand) ? "fixed" : operand.getLIRKind().getPlatformKind().toString(); + char typeChar = operand.getKind().getTypeChar(); + visitor.visitIntervalStart(interval.splitParent().operand, operand, interval.location(), hint, type, typeChar); + + // print ranges + Range cur = interval.first(); + while (cur != Range.EndMarker) { + visitor.visitRange(cur.from, cur.to); + cur = cur.next; + assert cur != null : "range list not closed with range sentinel"; + } + + // print use positions + int prev = -1; + UsePosList usePosList = interval.usePosList(); + for (int i = usePosList.size() - 1; i >= 0; --i) { + assert prev < usePosList.usePos(i) : "use positions not sorted"; + visitor.visitUsePos(usePosList.usePos(i), usePosList.registerPriority(i)); + prev = usePosList.usePos(i); + } + + visitor.visitIntervalEnd(interval.spillState()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/debug/IntervalDumper.java Wed Sep 02 11:47:11 2015 +0200 @@ -0,0 +1,61 @@ +/* + * 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; + +/** + * Provides abstract access to intervals for dumping. + */ +public interface IntervalDumper { + + public interface IntervalVisitor { + void visitIntervalStart(Object parentOperand, Object splitOperand, Object location, Object hint, String typeName, char typeChar); + + void visitRange(int from, int to); + + void visitUsePos(int pos, Object registerPrioObject); + + void visitIntervalEnd(Object spillState); + + } + + /** + * Visits the {@link IntervalVisitor} for every interval. + * + * The order is as follows: + * <ul> + * <li>Call {@link IntervalVisitor#visitIntervalStart}</li> + * <li>For every range: + * <ul> + * <li>Call {@link IntervalVisitor#visitRange}</li> + * </ul> + * <li>For every range: + * <ul> + * <li>Call {@link IntervalVisitor#visitUsePos}</li> + * </ul> + * </li> + * <li>call {@link IntervalVisitor#visitIntervalEnd}</li> + * </ul> + */ + void visitIntervals(IntervalVisitor visitor); + +}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java Tue Sep 01 14:30:54 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java Wed Sep 02 11:47:11 2015 +0200 @@ -413,7 +413,7 @@ } private void dumpIntervals(String label) { - Debug.dump(stackSlotMap, label); + Debug.dump(new StackIntervalDumper(Arrays.copyOf(stackSlotMap, stackSlotMap.length)), label); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/StackIntervalDumper.java Wed Sep 02 11:47:11 2015 +0200 @@ -0,0 +1,60 @@ +/* + * 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.stackslotalloc; + +import jdk.internal.jvmci.code.*; +import jdk.internal.jvmci.meta.*; + +import com.oracle.graal.lir.debug.*; + +class StackIntervalDumper implements IntervalDumper { + private final StackInterval[] intervals; + + public StackIntervalDumper(StackInterval[] intervals) { + this.intervals = intervals; + } + + public void visitIntervals(IntervalVisitor visitor) { + for (StackInterval interval : intervals) { + if (interval != null) { + printInterval(interval, visitor); + } + } + } + + private static void printInterval(StackInterval interval, IntervalVisitor visitor) { + Value hint = interval.locationHint() != null ? interval.locationHint().getOperand() : null; + VirtualStackSlot operand = interval.getOperand(); + String type = operand.getLIRKind().getPlatformKind().toString(); + char typeChar = operand.getKind().getTypeChar(); + visitor.visitIntervalStart(operand, operand, interval.location(), hint, type, typeChar); + + // print ranges + visitor.visitRange(interval.from(), interval.to()); + + // no use positions + + visitor.visitIntervalEnd("NOT_SUPPORTED"); + } + +}
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Tue Sep 01 14:30:54 2015 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Wed Sep 02 11:47:11 2015 +0200 @@ -22,8 +22,6 @@ */ package com.oracle.graal.printer; -import static jdk.internal.jvmci.code.ValueUtil.*; - import java.io.*; import java.util.*; @@ -35,9 +33,8 @@ import com.oracle.graal.graph.*; import com.oracle.graal.java.*; import com.oracle.graal.lir.*; -import com.oracle.graal.lir.alloc.lsra.*; -import com.oracle.graal.lir.alloc.lsra.Interval.UsePosList; -import com.oracle.graal.lir.stackslotalloc.*; +import com.oracle.graal.lir.debug.*; +import com.oracle.graal.lir.debug.IntervalDumper.IntervalVisitor; import com.oracle.graal.nodeinfo.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; @@ -508,84 +505,42 @@ } } - public void printIntervals(String label, Interval[] intervals) { + IntervalVisitor intervalVisitor = new IntervalVisitor() { + + public void visitIntervalStart(Object parentOperand, Object splitOperand, Object location, Object hint, String typeName, char typeChar) { + out.printf("%s %s ", splitOperand, typeName); + if (location != null) { + out.printf("\"[%s|%c]\"", location, typeChar); + } else { + out.printf("\"[%s|%c]\"", splitOperand, typeChar); + } + out.printf("%s %s ", parentOperand, hint != null ? hint : -1); + } + + public void visitRange(int from, int to) { + out.printf("[%d, %d[", from, to); + } + + public void visitUsePos(int usePos, Object registerPriority) { + out.printf("%d %s ", usePos, registerPriority); + } + + public void visitIntervalEnd(Object spillState) { + out.printf(" \"%s\"", spillState); + out.println(); + } + + }; + + public void printIntervals(String label, IntervalDumper intervals) { begin("intervals"); out.println(String.format("name \"%s\"", label)); - for (Interval interval : intervals) { - if (interval != null) { - printInterval(interval); - } - } + intervals.visitIntervals(intervalVisitor); end("intervals"); } - private void printInterval(Interval interval) { - out.printf("%s %s ", interval.operand, (isRegister(interval.operand) ? "fixed" : interval.kind().getPlatformKind())); - if (isRegister(interval.operand)) { - out.printf("\"[%s|%c]\"", interval.operand, interval.operand.getKind().getTypeChar()); - } else { - if (interval.location() != null) { - out.printf("\"[%s|%c]\"", interval.location(), interval.location().getKind().getTypeChar()); - } - } - - Interval hint = interval.locationHint(false); - out.printf("%s %s ", interval.splitParent().operand, hint != null ? hint.operand : -1); - - // print ranges - Range cur = interval.first(); - while (cur != Range.EndMarker) { - out.printf("[%d, %d[", cur.from, cur.to); - cur = cur.next; - assert cur != null : "range list not closed with range sentinel"; - } - - // print use positions - int prev = -1; - UsePosList usePosList = interval.usePosList(); - for (int i = usePosList.size() - 1; i >= 0; --i) { - assert prev < usePosList.usePos(i) : "use positions not sorted"; - out.printf("%d %s ", usePosList.usePos(i), usePosList.registerPriority(i)); - prev = usePosList.usePos(i); - } - - out.printf(" \"%s\"", interval.spillState()); - out.println(); - } - - public void printStackIntervals(String label, StackInterval[] intervals) { - begin("intervals"); - out.println(String.format("name \"%s\"", label)); - - for (StackInterval interval : intervals) { - if (interval != null) { - printStackInterval(interval); - } - } - - end("intervals"); - } - - private void printStackInterval(StackInterval interval) { - out.printf("%s %s ", interval.getOperand(), interval.isFixed() ? "fixed" : interval.kind().getPlatformKind()); - if (interval.location() != null) { - out.printf("\"[%s|%c]\"", interval.location(), interval.location().getKind().getTypeChar()); - } else { - out.printf("\"[%s|%c]\"", interval.getOperand(), interval.getOperand().getKind().getTypeChar()); - } - - StackInterval hint = interval.locationHint(); - out.printf("%s %s ", interval.getOperand(), hint != null ? hint.getOperand() : -1); - - out.printf("[%d, %d[", interval.from(), interval.to()); - - // print spill state - out.printf(" \"NOT_SUPPORTED\""); - out.println(); - } - public void printSchedule(String message, SchedulePhase theSchedule) { schedule = theSchedule; cfg = schedule.getCFG();
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Tue Sep 01 14:30:54 2015 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Wed Sep 02 11:47:11 2015 +0200 @@ -40,8 +40,7 @@ import com.oracle.graal.graph.*; import com.oracle.graal.java.*; import com.oracle.graal.lir.*; -import com.oracle.graal.lir.alloc.lsra.*; -import com.oracle.graal.lir.stackslotalloc.*; +import com.oracle.graal.lir.debug.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.cfg.*; import com.oracle.graal.phases.schedule.*; @@ -116,7 +115,7 @@ } private LIR lastLIR = null; - private Interval[] delayedIntervals = null; + private IntervalDumper delayedIntervals = null; public void dumpSandboxed(Object object, String message) { @@ -190,17 +189,15 @@ } else if (isCompilationResultAndInstalledCode(object)) { Object[] tuple = (Object[]) object; cfgPrinter.printMachineCode(disassemble(codeCache, (CompilationResult) tuple[0], (InstalledCode) tuple[1]), message); - } else if (object instanceof Interval[]) { + } else if (object instanceof IntervalDumper) { if (lastLIR == cfgPrinter.lir) { - cfgPrinter.printIntervals(message, (Interval[]) object); + cfgPrinter.printIntervals(message, (IntervalDumper) object); } else { if (delayedIntervals != null) { - Debug.log("Some delayed intervals were dropped (%s)", (Object) delayedIntervals); + Debug.log("Some delayed intervals were dropped (%s)", delayedIntervals); } - delayedIntervals = (Interval[]) object; + delayedIntervals = (IntervalDumper) object; } - } else if (object instanceof StackInterval[]) { - cfgPrinter.printStackIntervals(message, (StackInterval[]) object); } else if (isBlockList(object)) { cfgPrinter.printCFG(message, getBlockList(object), false); }