Hi, I started to work with llvm and liked the CFG dotty printer a lot. However there was none for the dominance trees. I implemented dotty printing for dominance trees and introduced these new flags: -dot-dom : Print dominance tree of function to 'dot' file -dot-dom-only : Print dominance tree of function to 'dot' file (with no function bodies) -dot-postdom : Print postdominance tree of function to 'dot' file -dot-postdom-only : Print postdominance tree of function to 'dot' file (with no function bodies) -view-dom : View dominance tree of function -view-dom-only : View dominance tree of function (with no function bodies) -view-postdom : View postdominance tree of function -view-postdom-only : View postdominance tree of function (with no function bodies) The patch contains these changes: 1. Move DOTGraphTraits<const Function*> to CFGPrinter.h to reuse it later. 2. Add nodes_iterator to GraphTraits<DomTreeNode *>, GraphTraits<DominatorTree*>, GraphTraits<PostDominatorTree*> to enable the GraphWriter on these data structures. 3. The file DomPrinter.cpp containing the actual passes, printers & Co. It is simple as almost everything already existed. 4. A little bug fix in lib/Analysis/CFGPrinter.cpp. virtual bool runOnFunction(Function &F) { - F.viewCFG(); + F.viewCFGOnly(); return false; "opt -view-cfg-only" showed too much. Any feedback is highly appreciated. See you Tobi
On Wed, 2009-07-15 at 00:20 +0200, Tobias Grosser wrote:> Hi, > > I started to work with llvm and liked the CFG dotty printer a lot. > However there was none for the dominance trees. > > I implemented dotty printing for dominance treesAnd here is the patch. Tobi -------------- next part -------------- A non-text attachment was scrubbed... Name: llvm-dot-dominance-printer.patch Type: text/x-patch Size: 19236 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090715/2b7c5cc9/attachment.bin>
Tobias Grosser wrote:> On Wed, 2009-07-15 at 00:20 +0200, Tobias Grosser wrote: >> Hi, >> >> I started to work with llvm and liked the CFG dotty printer a lot. >> However there was none for the dominance trees. >> >> I implemented dotty printing for dominance treesGreat! I'm a huge fan of graphviz integration in the compiler.> And here is the patch.What's up with copying from CFGPrinter.cpp into CFGPrinter.h? You shouldn't need that. + static nodes_iterator nodes_begin (DomTreeNode * N) { + return df_begin<DomTreeNode *> (N); + } + + static nodes_iterator nodes_end (DomTreeNode *N) { + return df_end<DomTreeNode *> (N); + } No spaces between the function name and the parenthesis. This occurs a few times. @@ -112,7 +59,7 @@ namespace { CFGOnlyViewer() : FunctionPass(&ID) {} virtual bool runOnFunction(Function &F) { - F.viewCFG(); + F.viewCFGOnly(); return false; } Put that back. viewCFG shows the CFG with full instructions inside it while viewCFGOnly shows just the block without the instruction listing inside. This pass is intended to show the details. + template<> + struct DOTGraphTraits<DomTreeNode*> : public DefaultDOTGraphTraits { + static std::string getNodeLabel(DomTreeNode *Node, + DomTreeNode *Graph, + bool ShortNames) { Tabs are forbidden in LLVM. Also, neither "namespace llvm {" nor "template<>" increase indent level. + return DOTGraphTraits<const Function*>::getNodeLabel( + (const BasicBlock*) BB, (const Function *) BB->getParent(), + ShortNames); + } If you're just changing constness, please use const_cast<>. But why isn't this using DOMGraphTraits<Function*> instead? + struct DomViewer: public FunctionPass { Missing space before colon.