Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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-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.

like image 882
osgx Avatar asked Jul 28 '13 02:07

osgx


People also ask

What is LLVM optimization?

DESCRIPTION. The opt command is the modular LLVM optimizer and analyzer. It takes LLVM source files as input, runs the specified optimizations or analyses on it, and then outputs the optimized file.

What are LLVM passes?

All LLVM passes are subclasses of the Pass class, which implement functionality by overriding virtual methods inherited from Pass .

Does LLVM optimize?

LLVM currently does not optimize well loads and stores of large aggregate types (i.e. structs and arrays). As an alternative, consider loading individual fields from memory. Aggregates that are smaller than the largest (performant) load or store instruction supported by the targeted hardware are well supported.

What is mem2reg?

-mem2reg : Promote Memory to Register This file promotes memory references to be register references. It promotes alloca instructions which only have loads and stores as uses.


2 Answers

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.

like image 140
Eli Bendersky Avatar answered Oct 27 '22 23:10

Eli Bendersky


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

like image 28
Zinovy Nis Avatar answered Oct 27 '22 23:10

Zinovy Nis