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

12,273

Solution 1

It seems that you've already discovered how to do dumps on Clang AST level and LLVM IR level. For codegen, 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
  -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 & compiled LLVM with graphviz support.

Solution 2

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

Share:
12,273

Related videos on Youtube

osgx
Author by

osgx

Linux programmer, interested in compilers (with theory and standard-compliance), cryptography, OS and microelectronics design Working deeply with compilers, standard-compliance and OS libraries.

Updated on August 26, 2020

Comments

  • osgx
    osgx over 3 years

    I want to find some debugging options for clang/LLVM which work like gcc's -fdump-tree-all-all -fdump-rtl-all-all -fdump-ipa-all-all.

    Basically I want to have an LLVM IR dumps before and after each optimization pass, also it can be useful to have all dumps of AST from clang and all phases of code generation (backend phases, Selection DAG, ISEL-SDNode, register allocation, 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 codegen.

    • osgx
      osgx over 10 years
      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
    osgx over 10 years
    Eli, can you add information about clang and IR dumps into your answer too?
  • osgx
    osgx over 10 years
    And -print-machineinstrs may be useful. My llc from llvm 3.2 doesn't have any of -view-*-dags.
  • Eli Bendersky
    Eli Bendersky over 10 years
    @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 :)
  • osgx
    osgx about 10 years
    Does it output LLVM IR core, or only GCC's internal representation?
  • osgx
    osgx over 9 years
    Zinovy, thank you, it can be helpful too. What is the mininal version of clang/llvm to use the "-debug-pass=Arguments"?
  • gluk47
    gluk47 about 8 years
    -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.

Related