21

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
osgx
  • 90,338
  • 53
  • 357
  • 513
  • 5
    Hmm, there are "`-print-after-all` - Print IR after each pass; -print-before-all - `Print IR before each pass`" for IR phases, but how to get dumps from backend? – osgx Jul 28 '13 at 02:37
  • You can print debug info from backend phases yourself, eg. `CGDebugInfo` object from codegen. – shrm Jul 28 '13 at 04:12
  • mishr, Isn't CGDebugInfo from clang IR emitter, not from llvm backend? I want to get info from LLVM IR-to-machine code backend (codegen) – osgx Jul 28 '13 at 04:21
  • True. Maybe this will help. See the last 2 sections, and maybe you need to chase how it was done. http://nondot.org/sabre/LLVMNotes/DebugInfoVariableInfo.txt – shrm Jul 28 '13 at 04:43

3 Answers3

16

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • Eli, can you add information about clang and IR dumps into your answer too? – osgx Jul 29 '13 at 17:57
  • 1
    And -print-machineinstrs may be useful. My llc from llvm 3.2 doesn't have any of `-view-*-dags`. – osgx Jul 29 '13 at 18:00
  • @osgx: see my edit w.r.t. not having `-view-*`. As for other dumps, feel free to edit my answer with the information you've already pasted into the questions and comments :) – Eli Bendersky Jul 29 '13 at 18:08
6

It is not fully about your question, but to see the passes applied, you can do:

clang test.c -Ofast -march=core-avx2 -mllvm -debug-pass=Arguments

You will see something like:

Pass Arguments: -datalayout -notti -basictti -x86tti -targetlibinfo -jump-instr-table-info -targetpassconfig -no-aa -tbaa -scoped-noalias -basicaa -collector-metadata -machinemoduleinfo -machine-branch-prob -jump-instr-tables -verify -verify-di -domtree -loops -loop-simplify -scalar-evolution -iv-users -loop-reduce -gc-lowering -unreachableblockelim -consthoist -partially-inline-libcalls -codegenprepare -verify-di -stack-protector -verify -domtree -loops -branch-prob -machinedomtree -expand-isel-pseudos -tailduplication -opt-phis -machinedomtree -slotindexes -stack-coloring -localstackalloc -dead-mi-elimination -machinedomtree -machine-loops -machine-trace-metrics -early-ifcvt -machinelicm -machine-cse -machine-sink -peephole-opts -dead-mi-elimination -processimpdefs -unreachable-mbb-elimination -livevars -machinedomtree -machine-loops -phi-node-elimination -twoaddressinstruction -slotindexes -liveintervals -simple-register-coalescing -misched -machine-block-freq -livedebugvars -livestacks -virtregmap -liveregmatrix -edge-bundles -spill-code-placement -virtregrewriter -stack-slot-coloring -machinelicm -edge-bundles -prologepilog -machine-block-freq -branch-folder -tailduplication -machine-cp -postrapseudos -machinedomtree -machine-loops -post-RA-sched -gc-analysis -machine-block-freq -block-placement2 -stackmap-liveness -machinedomtree -machine-loops

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zinovy Nis
  • 455
  • 6
  • 9
  • 1
    Zinovy, thank you, it can be helpful too. What is the mininal version of clang/llvm to use the "`-debug-pass=Arguments`"? – osgx Aug 25 '14 at 21:08
  • 3
    `-mllvm -debug-pass=Structure` is even nicer. It includes the output of `-debug-pass=Arguments`, but also dumps a tree of optimizations applied with human-readable names. – gluk47 Feb 02 '16 at 14:59
  • Re `-debug-pass=Arguments`: Not [`-fdebug-pass-arguments`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fdebug-pass-arguments)? Did it change in a later version? – Peter Mortensen May 21 '23 at 18:15
-4

I am using llvm-gcc-4.2 on Mac OS X v10.8 (Mountain Lion) and -fdump-tree-all works.

gcc  -fdump-tree-all -o test file1.c file2.c file1.h -I  . 
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user847988
  • 984
  • 1
  • 16
  • 30