From 7ace7941f06d1e87d1bd95c3522524eebc55470a Mon Sep 17 00:00:00 2001 From: David Leopoldseder Date: Fri, 23 Feb 2024 16:24:16 +0100 Subject: [PATCH] cfg: add logging decorator for cfg traversal --- .../compiler/nodes/cfg/ControlFlowGraph.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/cfg/ControlFlowGraph.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/cfg/ControlFlowGraph.java index ad13088d26ed..7f55cd03c28e 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/cfg/ControlFlowGraph.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/cfg/ControlFlowGraph.java @@ -44,6 +44,7 @@ import jdk.graal.compiler.debug.DebugContext; import jdk.graal.compiler.debug.GraalError; import jdk.graal.compiler.debug.MemUseTrackerKey; +import jdk.graal.compiler.debug.TTY; import jdk.graal.compiler.graph.Node; import jdk.graal.compiler.graph.NodeMap; import jdk.graal.compiler.graph.iterators.NodeIterable; @@ -219,6 +220,44 @@ public void updateCachedLocalLoopFrequency(LoopBeginNode lb, Function { + private final ControlFlowGraph.RecursiveVisitor visitor; + private String indent = ""; + + public LoggingCFGDecorator(ControlFlowGraph.RecursiveVisitor visitor, ControlFlowGraph cfg) { + this.visitor = visitor; + TTY.printf("DomTree for %s%n", cfg.graph); + printDomTree(cfg.getStartBlock(), ""); + } + + private static void printDomTree(HIRBlock cur, String indent) { + TTY.printf("%s%s [dom %s, post dom %s]%n", indent, cur, cur.getDominator(), cur.getPostdominator()); + HIRBlock dominated = cur.getFirstDominated(); + while (dominated != null) { + printDomTree(dominated, indent + "\t"); + dominated = dominated.getDominatedSibling(); + } + } + + @Override + public HIRBlock enter(HIRBlock b) { + TTY.printf("%sEnter block %s for %s%n", indent, b, visitor); + indent += "\t"; + return visitor.enter(b); + } + + @Override + public void exit(HIRBlock b, HIRBlock value) { + indent = indent.substring(0, indent.length() - 1); + TTY.printf("%sExit block %s with value %s for %s%n", indent, b, value, visitor); + visitor.exit(b, value); + } + } + @SuppressWarnings("unchecked") public void visitDominatorTreeDefault(RecursiveVisitor visitor) {