# HG changeset patch # User Lukas Stadler # Date 1310650943 -7200 # Node ID 9518546712e1fb30fef9edc699164b1b7e8cea0a # Parent e41017cddf3a0733fa18ed8144a9fc69e0cba548# Parent 064ebe531f9e3414707a0db94cd01a0b616f4687 merge diff -r e41017cddf3a -r 9518546712e1 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java Thu Jul 14 15:41:13 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java Thu Jul 14 15:42:23 2011 +0200 @@ -193,6 +193,9 @@ } else if (compare.y().isConstant() && compare.x() instanceof NormalizeCompare) { return optimizeNormalizeCmp(compare, compare.y().asConstant(), (NormalizeCompare) compare.x()); } + if (compare.x() == compare.y() && compare.x().kind != CiKind.Float && compare.x().kind != CiKind.Double) { + return Constant.forBoolean(compare.condition().check(1, 1), compare.graph()); + } return compare; } diff -r e41017cddf3a -r 9518546712e1 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/LoopUtil.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/LoopUtil.java Thu Jul 14 15:41:13 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/LoopUtil.java Thu Jul 14 15:42:23 2011 +0200 @@ -232,49 +232,18 @@ assert loop.cfgNodes().isMarked(noExit); PeelingResult peeling = preparePeeling(loop, split); - rewirePeeling(peeling, loop, split, true); + rewireInversion(peeling, loop, split); // move peeled part to the end LoopBegin loopBegin = loop.loopBegin(); LoopEnd loopEnd = loopBegin.loopEnd(); FixedNode lastNode = (FixedNode) loopEnd.singlePredecessor(); - Graph graph = loopBegin.graph(); if (loopBegin.next() != lastNode) { lastNode.successors().replace(loopEnd, loopBegin.next()); loopBegin.setNext(noExit); split.successors().replace(noExit, loopEnd); } - // rewire dataOut - NodeBitMap exitMergesPhis = graph.createNodeBitMap(); - for (Entry entry : peeling.exits.entries()) { - StateSplit newExit = entry.getValue(); - Merge merge = ((EndNode) newExit.next()).merge(); - exitMergesPhis.markAll(merge.phis()); - } - for (Entry entry : peeling.dataOut.entries()) { - Value originalValue = (Value) entry.getKey(); - if (originalValue instanceof Phi && ((Phi) originalValue).merge() == loopBegin) { - continue; - } - Value newValue = (Value) entry.getValue(); - Phi phi = null; - List usages = new ArrayList(originalValue.usages()); - for (Node usage : usages) { - if (exitMergesPhis.isMarked(usage) || ( - loop.nodes().isNotNewMarked(usage) - && peeling.peeledNodes.isNotNewNotMarked(usage) - && !(usage instanceof Phi && ((Phi) usage).merge() == loopBegin)) - && !(usage instanceof FrameState && ((FrameState) usage).block() == loopBegin)) { - if (phi == null) { - phi = new Phi(originalValue.kind, loopBegin, PhiType.Value, graph); - phi.addInput(newValue); - phi.addInput(originalValue); - } - usage.inputs().replace(originalValue, phi); - } - } - } //rewire phi usage in peeled part int backIndex = loopBegin.phiPredecessorIndex(loopBegin.loopEnd()); for (Phi phi : loopBegin.phis()) { @@ -329,7 +298,7 @@ for (Entry entry : peeling.dataOut.entries()) { System.out.println(" - " + entry.getKey() + " -> " + entry.getValue()); }*/ - rewirePeeling(peeling, loop, loopEnd, false); + rewirePeeling(peeling, loop); /*if (compilation.compiler.isObserved()) { compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "After rewirePeeling", loopEnd.graph(), true, false)); }*/ @@ -345,6 +314,14 @@ GraalMetrics.LoopsPeeled++; } + private static void rewireInversion(PeelingResult peeling, Loop loop, FixedNode from) { + rewirePeeling(peeling, loop, from, true); + } + + private static void rewirePeeling(PeelingResult peeling, Loop loop) { + rewirePeeling(peeling, loop, loop.loopBegin().loopEnd(), false); + } + private static void rewirePeeling(PeelingResult peeling, Loop loop, FixedNode from, boolean inversion) { LoopBegin loopBegin = loop.loopBegin(); Graph graph = loopBegin.graph(); @@ -398,6 +375,7 @@ for (Node exit : peeling.unaffectedExits) { exitPoints.add(exit); } + for (Entry entry : peeling.exits.entries()) { StateSplit original = (StateSplit) entry.getKey(); StateSplit newExit = entry.getValue(); @@ -446,6 +424,43 @@ } } + if (inversion) { + // rewire dataOut in non-peeled body + NodeBitMap exitMergesPhis = graph.createNodeBitMap(); + for (Entry entry : peeling.exits.entries()) { + StateSplit newExit = entry.getValue(); + Merge merge = ((EndNode) newExit.next()).merge(); + exitMergesPhis.markAll(merge.phis()); + } + for (Entry entry : peeling.dataOut.entries()) { + Value originalValue = (Value) entry.getKey(); + if (originalValue instanceof Phi && ((Phi) originalValue).merge() == loopBegin) { + continue; + } + Value newValue = (Value) entry.getValue(); + Phi phi = null; + List usages = new ArrayList(originalValue.usages()); + for (Node usage : usages) { + if (exitMergesPhis.isMarked(usage) || ( + loop.nodes().isNotNewMarked(usage) + && peeling.peeledNodes.isNotNewNotMarked(usage) + && !(usage instanceof Phi && ((Phi) usage).merge() == loopBegin)) + && !(usage instanceof FrameState && ((FrameState) usage).block() == loopBegin)) { + if (phi == null) { + phi = new Phi(originalValue.kind, loopBegin, PhiType.Value, graph); + phi.addInput(newValue); + phi.addInput(originalValue); + NodeMap exitMap = newExitValues.get(originalValue); + for (Node exit : peeling.unaffectedExits) { + exitMap.set(exit, phi); + } + } + usage.inputs().replace(originalValue, phi); + } + } + } + } + for (Entry> entry : newExitValues.entries()) { Value original = (Value) entry.getKey(); NodeMap pointToValue = entry.getValue(); diff -r e41017cddf3a -r 9518546712e1 src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveFilter.java --- a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveFilter.java Thu Jul 14 15:41:13 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveFilter.java Thu Jul 14 15:42:23 2011 +0200 @@ -25,9 +25,7 @@ import com.sun.hotspot.igv.graph.Diagram; import com.sun.hotspot.igv.graph.Figure; -import com.sun.hotspot.igv.graph.InputSlot; import com.sun.hotspot.igv.graph.Selector; -import com.sun.hotspot.igv.data.Properties; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -52,48 +50,26 @@ } public void apply(Diagram diagram) { - for (RemoveRule r : rules) { + List
selected = r.getSelector().selected(diagram); + Set
toRemove = new HashSet
(selected); - List
list = r.getSelector().selected(diagram); - Set
figuresToRemove = new HashSet
(); - - List
protectedFigures = null; - if (r.getRemoveAllWithoutPredecessor()) { - protectedFigures = diagram.getRootFigures(); + if (r.getRemoveOrphans()) { + boolean changed; + do { + changed = false; + for (Figure f : diagram.getFigures()) { + if (!toRemove.contains(f)) { + if (toRemove.containsAll(f.getPredecessors()) && toRemove.containsAll(f.getSuccessors())) { + toRemove.add(f); + changed = true; + } + } + } + } while (changed); } - for (Figure f : list) { - if (r.getRemoveOnlyInputs()) { - List inputSlots = new ArrayList(); - for (InputSlot is : f.getInputSlots()) { - inputSlots.add(is); - } - for (InputSlot is : inputSlots) { - f.removeSlot(is); - } - - f.createInputSlot(); - } else { - figuresToRemove.add(f); - } - } - - if (r.getRemoveAllWithoutPredecessor()) { - boolean progress = true; - while (progress) { - List
rootFigures = diagram.getRootFigures(); - progress = false; - for (Figure f : rootFigures) { - if (!protectedFigures.contains(f)) { - figuresToRemove.add(f); - progress = true; - } - } - } - } - - diagram.removeAllFigures(figuresToRemove); + diagram.removeAllFigures(toRemove); } } @@ -104,29 +80,23 @@ public static class RemoveRule { private Selector selector; - private boolean removeAllWithoutPredecessor; - private boolean removeOnlyInputs; + private boolean removeOrphans; - public RemoveRule(Selector selector, boolean b) { - this(selector, b, false); + public RemoveRule(Selector selector) { + this(selector, false); } - public RemoveRule(Selector selector, boolean removeAllWithoutPredecessor, boolean removeOnlyInputs) { + public RemoveRule(Selector selector, boolean removeOrphans) { this.selector = selector; - this.removeOnlyInputs = removeOnlyInputs; - this.removeAllWithoutPredecessor = removeAllWithoutPredecessor; + this.removeOrphans = removeOrphans; } public Selector getSelector() { return selector; } - public boolean getRemoveOnlyInputs() { - return removeOnlyInputs; - } - - public boolean getRemoveAllWithoutPredecessor() { - return removeAllWithoutPredecessor; + public boolean getRemoveOrphans() { + return removeOrphans; } } } diff -r e41017cddf3a -r 9518546712e1 src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/helper.js --- a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/helper.js Thu Jul 14 15:41:13 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/helper.js Thu Jul 14 15:42:23 2011 +0200 @@ -35,7 +35,13 @@ function remove(property, regexp) { var f = new RemoveFilter(""); - f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), false, false)); + f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)))); + f.apply(graph); +} + +function removeIncludingOrphans(property, regexp) { + var f = new RemoveFilter(""); + f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), true)); f.apply(graph); } diff -r e41017cddf3a -r 9518546712e1 src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/filters/GraalGradientColorFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/filters/GraalGradientColorFilter.java Thu Jul 14 15:42:23 2011 +0200 @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2011, 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.sun.hotspot.igv.graal.filters; + +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import java.awt.Color; +import java.awt.LinearGradientPaint; +import java.awt.PaintContext; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; +import java.awt.image.Raster; +import java.util.List; + +/** + * Filter that colors nodes using a customizable color gradient, based on how + * a numeric property is located in a specified interval. + * + * @author Peter Hofer + */ +public class GraalGradientColorFilter { + + public enum Mode { + LINEAR, + LOGARITHMIC + }; + + private String propertyName = "probability"; + private float minValue = 0; + private float maxValue = 500; + private float[] fractions = {0, 0.5f, 1}; + private Color[] colors = {Color.BLUE, Color.YELLOW, Color.RED}; + private int shadeCount = 8; + private Mode mode = Mode.LOGARITHMIC; + + public void apply(Diagram d) { + Rectangle bounds = new Rectangle(shadeCount, 1); + LinearGradientPaint lgp = new LinearGradientPaint(bounds.x, bounds.y, bounds.width, bounds.y, fractions, colors); + PaintContext context = lgp.createContext(null, bounds, bounds.getBounds2D(), AffineTransform.getTranslateInstance(0, 0), new RenderingHints(null)); + Raster raster = context.getRaster(bounds.x, bounds.y, bounds.width, bounds.height); + int[] rgb = raster.getPixels(bounds.x, bounds.y, bounds.width, bounds.height, (int[]) null); + Color[] shades = new Color[rgb.length / 3]; + for (int i = 0; i < shades.length; ++i) { + shades[i] = new Color(rgb[i * 3], rgb[i * 3 + 1], rgb[i * 3 + 2]); + } + + List
figures = d.getFigures(); + for (Figure f : figures) { + String property = f.getProperties().get(propertyName); + if (property != null) { + try { + float value = Float.parseFloat(property); + + Color nodeColor; + if (value <= minValue) { + nodeColor = colors[0]; + } else if (value >= maxValue) { + nodeColor = colors[colors.length - 1]; + } else { + double normalized = value - minValue; + double interval = maxValue - minValue; + int index; + // Use Math.ceil() to make values above zero distinguishable from zero + if (mode == Mode.LOGARITHMIC) { + index = (int) Math.ceil(shades.length * Math.log(1 + normalized) / Math.log(1 + interval)); + } else if (mode == Mode.LINEAR) { + index = (int) Math.ceil(shades.length * normalized / interval); + } else { + throw new RuntimeException("Unknown mode"); + } + nodeColor = shades[index]; + } + f.setColor(nodeColor); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + public String getPropertyName() { + return propertyName; + } + + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } + + public float getMinValue() { + return minValue; + } + + public void setMinValue(float minValue) { + this.minValue = minValue; + } + + public float getMaxValue() { + return maxValue; + } + + public void setMaxValue(float maxValue) { + this.maxValue = maxValue; + } + + public float[] getFractions() { + return fractions; + } + + public void setFractions(float[] fractions) { + this.fractions = fractions; + } + + public Color[] getColors() { + return colors; + } + + public void setColors(Color[] colors) { + this.colors = colors; + } + + public int getShadeCount() { + return shadeCount; + } + + public void setShadeCount(int steps) { + this.shadeCount = steps; + } + + public Mode getMode() { + return mode; + } + + public void setMode(Mode mode) { + this.mode = mode; + } +} diff -r e41017cddf3a -r 9518546712e1 src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/filters/probability.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/filters/probability.filter Thu Jul 14 15:42:23 2011 +0200 @@ -0,0 +1,9 @@ +var pf = new com.sun.hotspot.igv.graal.filters.GraalGradientColorFilter(); +pf.setMode(com.sun.hotspot.igv.graal.filters.GraalGradientColorFilter.Mode.LOGARITHMIC); +pf.setPropertyName("probability"); +pf.setMinValue(0); +pf.setMaxValue(500); +pf.setColors([blue, yellow, red]); +pf.setFractions([0, 0.5, 1]); +pf.setShadeCount(8); +pf.apply(graph); diff -r e41017cddf3a -r 9518546712e1 src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/layer.xml --- a/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/layer.xml Thu Jul 14 15:41:13 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/layer.xml Thu Jul 14 15:42:23 2011 +0200 @@ -13,5 +13,9 @@ + + + + diff -r e41017cddf3a -r 9518546712e1 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter Thu Jul 14 15:41:13 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter Thu Jul 14 15:42:23 2011 +0200 @@ -20,5 +20,5 @@ ), false ) ); -f.addRule( new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher("name", "Phi|Store.")), false)); +f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher("name", "Phi|Store.")))); f.apply(graph); \ No newline at end of file