Search code examples
debuggingcompiler-constructionclangllvm

Dump IR after each LLVM optimization (each pass), both LLVM IR passes and backend debugging


I want to find some debugging options for Clang/LLVM which work like GCC's -fdump-tree-all-all, -fdump-rtl-all, and -fdump-ipa-all-all.

Basically, I want to have an LLVM IR dump before and after each optimization pass. Also, it can be useful to have all dumps of the AST from Clang and all phases of code generation (backend phases, Selection DAG, ISEL-SDNode, register allocation, and MCInsts).

I was able to find only the Clang's -ccc-print-phases, but it will only print high-level phases names, e.g., preprocess-compile-assemble-link; but no any dump of IR.

Also there is Life of an instruction in LLVM paper with -cc1-ast-dump option to dump Clang ASTs, but I want more, especially for code generation.


Solution

  • It seems that you've already discovered how to do dumps on the Clang AST level and LLVM IR level. For code generation, the following are useful:

    -debug for a detailed textual dump of instruction selection and later stages. Also, the -view*-dags show (pop-up) DAGs:

    llc -help-hidden | grep dags
    

    Output:

    -view-dag-combine-lt-dags  - Pop up a window to show dags before the
                                 post legalize types dag combine pass
    -view-dag-combine1-dags    - Pop up a window to show dags before
                                 the  first dag combine pass
    -view-dag-combine2-dags    - Pop up a window to show dags before the
                                 second dag combine pass
    -view-isel-dags            - Pop up a window to show isel dags
                                 as they are selected
    -view-legalize-dags        - Pop up a window to show dags before legalize
    -view-legalize-types-dags  - Pop up a window to show dags
                                 before legalize types
    -view-misched-dags         - Pop up a window to show MISched
                                 dags after they are processed
    -view-sched-dags           - Pop up a window to show sched
                                 dags as they are processed
    -view-sunit-dags           - Pop up a window to show SUnit dags
                                 after they are processed
    

    These may not show up if you haven't configured and compiled LLVM with Graphviz support.