22

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.

4
  • 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
    Commented Jul 28, 2013 at 2:37
  • You can print debug info from backend phases yourself, eg. CGDebugInfo object from codegen.
    – shrm
    Commented Jul 28, 2013 at 4: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
    Commented Jul 28, 2013 at 4:21
  • True. Maybe this will help. See the last 2 sections, and maybe you need to chase how it was done. nondot.org/sabre/LLVMNotes/DebugInfoVariableInfo.txt
    – shrm
    Commented Jul 28, 2013 at 4:43

3 Answers 3

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.

3
  • Eli, can you add information about clang and IR dumps into your answer too?
    – osgx
    Commented Jul 29, 2013 at 17:57
  • 1
    And -print-machineinstrs may be useful. My llc from llvm 3.2 doesn't have any of -view-*-dags.
    – osgx
    Commented Jul 29, 2013 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 :) Commented Jul 29, 2013 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

4
  • 1
    Zinovy, thank you, it can be helpful too. What is the mininal version of clang/llvm to use the "-debug-pass=Arguments"?
    – osgx
    Commented Aug 25, 2014 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
    Commented Feb 2, 2016 at 14:59
  • 1
    Re -debug-pass=Arguments: Not -fdebug-pass-arguments? Did it change in a later version? Commented Oct 30, 2023 at 17:48
  • -debug-pass=Arguments/Structure cannot be recognize in the latest clang. Use -fdebug-pass-arguments/structure instead as Peter pointed out.
    – Alec.Zhou
    Commented Jul 4 at 7:13
-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  . 
1
  • 1
    Does it output LLVM IR core, or only GCC's internal representation?
    – osgx
    Commented Mar 16, 2014 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.