-
-
Save mahesh-attarde/1b23cbc906760f66c2edb21f2947d7f8 to your computer and use it in GitHub Desktop.
# Print All passes enabled | |
$opt=-O0 | |
echo 'int;' | clang -xc $opt - -o /dev/null -\#\#\# | |
# https://clang.llvm.org/docs/ClangCommandLineReference.html | |
# Print clang options, default values | |
echo 'int;' | clang -xc - -o /dev/null -mllvm -print-all-options | |
clang -help | |
clang -cc1 -help | |
clang -cc1 -mllvm -help | |
clang -cc1 -mllvm -help-list-hidden | |
clang -cc1as -help | |
## preprocessor | |
# Dump all macros set by different options | |
clang -E -dM <source> # does not need emit-llvm etc. | |
### IR | |
clang -O0 -emit-llvm -Xclang -disable-llvm-passes -S bug.c -o bug.ll | |
opt bug.ll -o bug.opt.ll -passes='sroa,instcombine,loop(loop-rotate,indvars),dot-cfg' -S | |
# DUMP AST | |
clang -Xclang -ast-dump -ast-dump -ast-dump-filter=func | |
clang -cc1 -ast-dump -ast-dump -ast-dump-filter=func | |
## Export DOT to PDF | |
dot -Tpdf cfg.dot -o cfg.pdf |
https://maskray.me/blog/2022-08-28-march-mcpu-mtune
-march=X: (execution domain) Generate code that can use instructions available in the architecture X -mtune=X: (optimization domain) Optimize for the microarchitecture X, but does not change the ABI or make assumptions about available instructions -mcpu=X: Specify both -march= and -mtune= but can be overridden by the two options. The supported values are generally the same as -mtune=. The architecture name is inferred from X
simplest case where only one option is desired, use -march= for x86 and -mcpu= for other targets. When optimizing for the local machine, just use -march=native for x86 and -mcpu=native for other targets. When the architecture and microarchitecture are both specified, i.e. when both the execution domain and the optimization domain need to be specified, specify -march= and -mtune=, and avoid -mcpu=.
SIMD blog http://0x80.pl/notesen.html