Support for machine function cfg dot dump

Xinliang David Li xinliangli at gmail.com
Wed Jun 12 16:47:30 PDT 2013


(this patch has been sitting in my computer collecting dust for a
couple of months now, send it out before I forget about it).


Currently only 'opt' driver supports CFG dump. The existing command line is :

opt -<pass_arg> -dot-cfg ....

The pass scheduler will inject the dot-cfg pass after <pass_arg> pass.

However, this is not supported for neither 'clang' nor 'llc' driver.

In fact, there is *no* support for Machine CFG dump at all.

The following patch added the support to dump .dot CFG file for each
function before/after each pass -- just like IR dump.

The syntax is :

    <driver> -dot-cfg-after=<pass-arg> ...
    <driver> -dot-cfg-before=<pass-arg> ...

The cfg printer is also enhanced to allow the pass name and order
string to be included in the name.

For instance,

     opt -dot-cfg-after=gvn t.b ...  # t.b defines 'foo'

It will create file cfg.foo.after.gvn.dot

The new option is now unified across three drivers:

    opt -O2 -dot-cfg-after=gvn t.bc -o to.bc
    llc  -dot-cfg-before=machine-cp t.bc -o t.o
    clang -mllvm -dot-cfg-before=...   [1]


Brief descriptions of the changes:

1) The CFGPrinter code is templatized and refactored -- the main
implementation is moved into CFGPrinterBase<..>
2) CFG and CFGOnly dumps are now unified into the same template class
3) For Function class, CFGPrinterT used -- which is derived from CFGPrinterBase
4) For MachineFunction, MachineCFGPrinterT is derived from CFGPrinterBase
5) To avoid creating dependency backwards from core to analysis, the
cfgprinter is moved to Support, sitting in core.


[1]. This currently does not work because Clang driver has a bug that
it does not register driver scheduled pass names properly.  THis also
blocks option -print-before|after from working with clang driver.  I
have another patch for it.


LLVM builds fine and regression test is ok.

If the patch looks ok and useful, can someone help check this in?

thanks,

David



More information about the llvm-commits mailing list