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

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

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.

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



回答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



回答3:

I am using llvm-gcc-4.2 on Mountain Lion and -fdump-tree-all works.

gcc  -fdump-tree-all -o test file1.c file2.c file1.h -I  .  


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!