Open nickdesaulniers opened 4 years ago
Besides -Xclang <clang specific option>
, there's also -mllvm <llvm specific option>
"If using clang-cl, -Xclang -emit-llvm emits human readable IR. -Xclang -emit-bc emits the bitcode."
"-Xclang -disable-O0-optnone"
"-DLLVM_PARALLEL_COMPILE_JOBS=4 -DLLVM_PARALLEL_LINK_JOBS=1"
@pirama-arumuga-nainar mentioned: "If you're building debug version, -DBUILD_SHARED_LIBS may help as well. It builds LLVM modules as shared libraries instead of statically linking them into the tools."
@topperc mentioned "might want to mention opt -instnamer and opt -metarenamer"
Does it make sense to mention https://github.com/ClangBuiltLinux/linux/issues/908 ? Perhaps would be interesting if something along those lines would be mentioned.
-filter-print-funcs=@foo for only printing changes to @foo
-stats
to print STATISTIC
s
opt -dot-cfg -dot-cfg-only -view-cfg -view-cfg-only -print-changed
via Jamie Schmeiser
"Understanding Changes made by a Pass in the Opt Pipeline."
EDIT: should be -passes=dot-cfg
now with NPM
-dM -E
to print preprocessor tokens
When using debugger you can call Function::viewCFG()
which will produce a CFG dot file from the current function and open it in the external editor like xdot. Sometimes much easier to read and see the structure than using dump() to view the IR.
@Kazhuu wait, a debugger can launch child processes? Neat!
I was also quite surprised by this when I figured it out. Documentation here. Also make sure xdg-open
launches xdot or similar program to view dot files rather than some text editor.
-Xclang -disable-lifetime-markers
cleans up the IR a little at the cost of excessive stack usage.
opt -help-hidden
shows options that can be passed to llvm through clang via -mllvm <option>
.
-print-module-scope
to print whole module rather than loop or function.
-fsyntax-only
stop after semantic analysis
-filter-print-funcs=test_bit
to only print changes to one function. (Might be -print-funcs=
for llc though: https://reviews.llvm.org/D15776, unverified).
-Xclang -print-stats
-fno-discard-value-names
-debug-pass=Arguments
to get the list of passes run (deprecated, see below)
EDIT: -debug-pass=Structure
also works
via @zygoloid :
What flags are you passing to %clang_cc1? The default -cc1 action is -fsyntax-only
-emit-codegen-only is roughly equivalent to -S -o /dev/null
Not specific to LLVM at all, but I found this useful to share externally, via @MaskRay :
In the linker, there are four link modes: -no-pie, -pie, -shared, -r. They are mutually exclusive.
-no-pie (position dependent executable) allows -fno-pic/-fpie/-fpic object files.
-pie (position independent executable) allows -fpie/-fpic object files.
-shared (shared object) allows -fpic object files.
-r (relocatable link)
The lower case -fpic and the upper case -fPIC are only distinguishable on very few ancient targets (ppc32, sparc).
via @arsenm
llc -global-isel=0/1 -fast-isel=0/1
llc -asm-verbose=false
to remove comments from asm via @samitolvanen .
or clang -fno-verbose-asm
for .c code.
opt
now has -print-pipeline-passes
(NPM) instead of -debug-pass=Arguments
(LPM).
-debug-pass-manager -passes='default<O1>'
Further, from clang:
-Xclang -fdebug-pass-manager
llvm-extract
now needs --recursive
to extract called functions' definitions
more git specific, but how to get the last 100 committers of a file, sorted by number of commits:
git log --format="%aN %aE" <your file> | head -n 100 | sort | uniq -c | sort -nr
Value::getNameOrAsOperand
is a better choice (once assertions or debug is enabled) than Value::getName
for un-named Value
s.
via https://reviews.llvm.org/rG91d15aa0b8bf, there's now utils/reduce_pipeline.py
via @Compudj you can use -passes='print<memoryssa>'
. This is documented, but I'm curious if print
works with more passes than just memoryssa?
Edit: I think -passes='print<memoryssa>'
is perhaps shorthand for -passes=memoryssa -print-after=memoryssa -print-module-scope
.
To view a cfg in clang, ensure -DCLANG_ENABLE_STATIC_ANALYZER=ON
otherwise <TODO: fill in error>
. Then clang -cc1 -analyze -analyzer-checker=debug.ViewCFG
or -analyzer-checker=debug.DumpCFG
.
Since I mix this up occasionally: Frontend runs before Driver.
-print-pipeline-passes
can be used to dump a pass pipeline that can then be fed back into opt
.
opt
supports -disable-output
rather than generating output but then writing it to /dev/null
.
The llvm intrinsics list gets generated into llvm/llvm-project/llvm/include/llvm/IR/IntrinsicEnums.inc.
uwtable
can cause CFI directives to be emitted. nounwind
can also help avoid these from -fasynchronous-unwind-tables
(or use -fno-asynchronous-unwind-tables
)
opt -print-passes
via @topperc : llc -debug-pass=Executions
via @arsenm: llc -debug-pass=Structure
diagtool tree
prints a tree of diagnostic groups. diagtool tree <warning flag minus -W prefix>
prints just that specific subtree.
printReg
in llvm/lib/CodeGen/TargetRegisterInfo.cpp to print vregs
https://github.com/llvm/llvm-project/commit/bf492371033378cec4c0443a3f87db0f818bbade added support for -mllvm -print-pipeline-passes
to be invocable from clang.
print part of the AST with:
-Xclang -ast-dump -Xclang -ast-dump-filter=<fn name>
will match multiple functions with fn name
in them.
If setting different -DLLVM_TARGETS_TO_BUILD
flags is something you sometimes do, you probably always want to be setting -ULLVM_TARGETS_TO_BUILD
first, even if you're not using -D
in order to reset the cmake cache.
(llc
args):
Test different register allocators: -regalloc={greedy|fast|basic|pbqp}
Verify results of register allocation: -verify-regalloc
Test different instruction selectors: -fast-isel={0|1}
, -global-isel={0|1}
(true
and false
may also be used rather than 0|1
).
Verify MIR: -verify-machineinstrs
(needs to be enabled explicitly, sadly).
-mregnames
will print the registers as r31
rather than 31
for powerpc for gcc. `-mregnames isn't supported by clang ATM.
https://github.com/llvm/llvm-project/issues/69631
It looks like -mllvm -ppc-asm-full-reg-names
should work, but did not IME.
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
to generate compile_commands.json.
ninja -d keepdepfile <target>
to retain .d files.
cmake option --trace-source=<path/to/CmakeLists.txt>
will output every statement executed from path/to/CmakeLists.txt
.
via @tejohnson, for getting optimization remarks out of the linker during LTO:
Yep,
-Wl,-mllvm,-pass-remarks={regex}
you can use-Wl,-plugin-opt,-pass-remarks=
but that form is just supported for gold compatibility.
"-DLLVM_ENABLE_OPTIMIZED_TABLEGEN=ON is a savior when building Debug"