[LLVMdev] [patch] Dotty printer for dependency trees

Nick Lewycky nicholas at mxc.ca
Wed Jul 15 22:14:55 PDT 2009


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 trees

Great! 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.




More information about the llvm-dev mailing list