Hi I'm trying to get a graphviz output (DOT) of a code I'm compiling. I want to see the DFG/CFG of the LLVM assembly, how the operations are chained together. The documentation mentions something about calling certain methods from within gdb, but isn't there some option when invoking the compiler (I've seen some -print-cfg and -dot-cfg options mentioned in some source files, but I can't find which tool supports them) Also, LLVM-TV seems outdated. I've tried to compile it with 2.5 LLVM and got various errors due to API changes. Tried to correct them, but got overwhelmed. Has the project been abandoned? thanks, Ioannis
On Aug 13, 2009, at 8:56 AM, Ioannis Nousias wrote:> Hi > > I'm trying to get a graphviz output (DOT) of a code I'm compiling. I > want to see the DFG/CFG of the LLVM assembly, how the operations are > chained together. The documentation mentions something about calling > certain methods from within gdb, but isn't there some option when > invoking the compiler (I've seen some -print-cfg and -dot-cfg options > mentioned in some source files, but I can't find which tool supports > them)This should help: http://llvm.org/docs/ProgrammersManual.html#ViewGraph> > Also, LLVM-TV seems outdated. I've tried to compile it with 2.5 LLVM > and > got various errors due to API changes. Tried to correct them, but got > overwhelmed. Has the project been abandoned?Yes, it is really really old and abandoned. -Chris
Chris Lattner wrote: On Aug 13, 2009, at 8:56 AM, Ioannis Nousias wrote:> Hi > > I'm trying to get a graphviz output (DOT) of a code I'm compiling. I > want to see the DFG/CFG of the LLVM assembly, how the operations are > chained together. The documentation mentions something about calling > certain methods from within gdb, but isn't there some option when > invoking the compiler (I've seen some -print-cfg and -dot-cfg options > mentioned in some source files, but I can't find which tool supports > them) > > This should help: > http://llvm.org/docs/ProgrammersManual.html#ViewGraph >Hey Chris. Thanks for the prompt response. That's what I was referring to before. If I'm getting this right, I should do a debug build of LLVM and the run it from gdb? So say, I run llvmc from gdb, pass on the code I want to compile and then what? Should I do a break point somewhere first, or wait for the program to finish and then call the methods?(which I don't think it would work). I'm confused. I was hoping for some CLI option or a separate tool that just parses in LLVM assembly and spits out DOT.>> >> Also, LLVM-TV seems outdated. I've tried to compile it with 2.5 LLVM and >> got various errors due to API changes. Tried to correct them, but got >> overwhelmed. Has the project been abandoned? > > Yes, it is really really old and abandoned. >too bad. looked interesting thanks, Ioannis
On Thu, 2009-08-13 at 17:17 +0100, Ioannis Nousias wrote:> Chris Lattner wrote: > > On Aug 13, 2009, at 8:56 AM, Ioannis Nousias wrote: > > > Hi > > > > I'm trying to get a graphviz output (DOT) of a code I'm compiling. I > > want to see the DFG/CFG of the LLVM assembly, how the operations are > > chained together. The documentation mentions something about calling > > certain methods from within gdb, but isn't there some option when > > invoking the compiler (I've seen some -print-cfg and -dot-cfg options > > mentioned in some source files, but I can't find which tool supports > > them) > > > > This should help: > > http://llvm.org/docs/ProgrammersManual.html#ViewGraph > > > Hey Chris. Thanks for the prompt response. > That's what I was referring to before. If I'm getting this right, I > should do a debug build of LLVM and the run it from gdb? So say, I run > llvmc from gdb, pass on the code I want to compile and then what? Should > I do a break point somewhere first, or wait for the program to finish > and then call the methods?(which I don't think it would work). I'm > confused. I was hoping for some CLI option or a separate tool that just > parses in LLVM assembly and spits out DOT.The flags for dot output work as any other optimization or analysis pass. So you can specify them at any tool that allows to pass optimization flags. You can use e.g. the "opt" binary and run it on any code that is already in llvm intermediate code. Use: opt -dot-cfg file.bc Any other tool that passes the flags to opt should also work. Tobi
Thanks Tobi for the tip. however I also need the Data-Flow-Graph of each basic block/functions. As I said, I need a view of how the instructions 'link' to each other (via registers or memory aliasing or whatnot) thanks again and sorry for the ping-pong, Ioannis Tobias Grosser wrote:> On Thu, 2009-08-13 at 17:17 +0100, Ioannis Nousias wrote: > >> Chris Lattner wrote: >> >> On Aug 13, 2009, at 8:56 AM, Ioannis Nousias wrote: >> >> >>> Hi >>> >>> I'm trying to get a graphviz output (DOT) of a code I'm compiling. I >>> want to see the DFG/CFG of the LLVM assembly, how the operations are >>> chained together. The documentation mentions something about calling >>> certain methods from within gdb, but isn't there some option when >>> invoking the compiler (I've seen some -print-cfg and -dot-cfg options >>> mentioned in some source files, but I can't find which tool supports >>> them) >>> >>> This should help: >>> http://llvm.org/docs/ProgrammersManual.html#ViewGraph >>> >>> >> Hey Chris. Thanks for the prompt response. >> That's what I was referring to before. If I'm getting this right, I >> should do a debug build of LLVM and the run it from gdb? So say, I run >> llvmc from gdb, pass on the code I want to compile and then what? Should >> I do a break point somewhere first, or wait for the program to finish >> and then call the methods?(which I don't think it would work). I'm >> confused. I was hoping for some CLI option or a separate tool that just >> parses in LLVM assembly and spits out DOT. >> > > The flags for dot output work as any other optimization or analysis > pass. So you can specify them at any tool that allows to pass > optimization flags. > You can use e.g. the "opt" binary and run it on any code that is already > in llvm intermediate code. > > Use: > > opt -dot-cfg file.bc > > Any other tool that passes the flags to opt should also work. > > Tobi > > > > >
Hi Ioannis, On Thu, 2009-08-13 at 19:31 +0100, Ioannis Nousias wrote:> Thanks Tobi for the tip. > > however I also need the Data-Flow-Graph of each basic block/functions. > As I said, I need a view of how the instructions 'link' to each other > (via registers or memory aliasing or whatnot)I believe that there is not yet a DOT printer for this kind of information. grep DOTGraphTraits -R * should give you all data types, for which dot printing is implemented, and the data flow does not seem to exist. However there is already a graph representation of the data flow information in "include/llvm/Support/DataFlow.h": ------------------------------------------------------------------------- This file defines specializations of GraphTraits that allows Use-Def and Def-Use relations to be treated as proper graphs for generic algorithms. ------------------------------------------------------------------------- It should be easy to write the DOTPrinter for this data type. You can take the CFGPrinter as reference. Tobi
ok, thanks for these pointers. I will look into this Ioannis Tobias Grosser wrote:> Hi Ioannis, > > On Thu, 2009-08-13 at 19:31 +0100, Ioannis Nousias wrote: > >> Thanks Tobi for the tip. >> >> however I also need the Data-Flow-Graph of each basic block/functions. >> As I said, I need a view of how the instructions 'link' to each other >> (via registers or memory aliasing or whatnot) >> > > > I believe that there is not yet a DOT printer for this kind of > information. > > grep DOTGraphTraits -R * > > should give you all data types, for which dot printing is implemented, > and the data flow does not seem to exist. However there is already a > graph representation of the data flow information in > "include/llvm/Support/DataFlow.h": > > ------------------------------------------------------------------------- > This file defines specializations of GraphTraits that allows Use-Def and > Def-Use relations to be treated as proper graphs for generic algorithms. > ------------------------------------------------------------------------- > > It should be easy to write the DOTPrinter for this data type. You can > take the CFGPrinter as reference. > > Tobi > >
I've tried to write a DFGPrinter based on the CFGPrinter, as you suggested, but encountered problems. The GraphWriter expects GraphTraits<GraphType>::nodes_begin()/nodes_end(). The way this is implemented in CFG.h, a function is a graph of basic blocks. A GraphTraits<Function*> inherits from GraphTraits<BasicBlock*>, and implements those nodes_begin()/nodes_end() wrapper functions. Should I modify CFG.h and make now BasicBlock a graph of Instruction(s) ? The DataFlow.h deals with Value and User. Now BasicBlock is derived from Value and Instruction from User, but I don't understand how that helps. It's a bit confusing to be honest. Can you help? thanks, Ioannis Tobias Grosser wrote:> Hi Ioannis, > > On Thu, 2009-08-13 at 19:31 +0100, Ioannis Nousias wrote: > >> Thanks Tobi for the tip. >> >> however I also need the Data-Flow-Graph of each basic block/functions. >> As I said, I need a view of how the instructions 'link' to each other >> (via registers or memory aliasing or whatnot) >> > > > I believe that there is not yet a DOT printer for this kind of > information. > > grep DOTGraphTraits -R * > > should give you all data types, for which dot printing is implemented, > and the data flow does not seem to exist. However there is already a > graph representation of the data flow information in > "include/llvm/Support/DataFlow.h": > > ------------------------------------------------------------------------- > This file defines specializations of GraphTraits that allows Use-Def and > Def-Use relations to be treated as proper graphs for generic algorithms. > ------------------------------------------------------------------------- > > It should be easy to write the DOTPrinter for this data type. You can > take the CFGPrinter as reference. > > Tobi > > >