ClangBuiltLinux / llvm-dev-conf-2020

Slides from LLVM Dev Conf 2020
4 stars 1 forks source link

tips #3

Open nickdesaulniers opened 4 years ago

nickdesaulniers commented 4 years ago

"-DLLVM_ENABLE_OPTIMIZED_TABLEGEN=ON is a savior when building Debug"

nickdesaulniers commented 4 years ago

Besides -Xclang <clang specific option>, there's also -mllvm <llvm specific option>

nickdesaulniers commented 4 years ago

"If using clang-cl, -Xclang -emit-llvm emits human readable IR. -Xclang -emit-bc emits the bitcode."

nickdesaulniers commented 4 years ago

"-Xclang -disable-O0-optnone"

nickdesaulniers commented 4 years ago

"-DLLVM_PARALLEL_COMPILE_JOBS=4 -DLLVM_PARALLEL_LINK_JOBS=1"

nickdesaulniers commented 4 years ago

@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"

xdevs23 commented 4 years ago

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.

nickdesaulniers commented 4 years ago

-filter-print-funcs=@foo for only printing changes to @foo

nickdesaulniers commented 4 years ago

-stats to print STATISTICs

nickdesaulniers commented 4 years ago

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

nickdesaulniers commented 4 years ago

-dM -E to print preprocessor tokens

Kazhuu commented 3 years ago

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.

nickdesaulniers commented 3 years ago

@Kazhuu wait, a debugger can launch child processes? Neat!

Kazhuu commented 3 years ago

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.

nickdesaulniers commented 3 years ago

-Xclang -disable-lifetime-markers cleans up the IR a little at the cost of excessive stack usage.

nickdesaulniers commented 3 years ago

opt -help-hidden shows options that can be passed to llvm through clang via -mllvm <option>.

nickdesaulniers commented 3 years ago

-print-module-scope to print whole module rather than loop or function.

nickdesaulniers commented 3 years ago

-fsyntax-only stop after semantic analysis

nickdesaulniers commented 3 years ago

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

nickdesaulniers commented 3 years ago

-Xclang -print-stats

nickdesaulniers commented 3 years ago

-fno-discard-value-names

nickdesaulniers commented 3 years ago

-debug-pass=Arguments to get the list of passes run (deprecated, see below)

EDIT: -debug-pass=Structure also works

nickdesaulniers commented 3 years ago

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

nickdesaulniers commented 3 years ago

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).
nickdesaulniers commented 3 years ago

via @arsenm

llc -global-isel=0/1 -fast-isel=0/1
nickdesaulniers commented 3 years ago

llc -asm-verbose=false to remove comments from asm via @samitolvanen .

or clang -fno-verbose-asm for .c code.

nickdesaulniers commented 3 years ago

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

nickdesaulniers commented 3 years ago

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
nickdesaulniers commented 3 years ago

Value::getNameOrAsOperand is a better choice (once assertions or debug is enabled) than Value::getName for un-named Values.

nickdesaulniers commented 3 years ago

via https://reviews.llvm.org/rG91d15aa0b8bf, there's now utils/reduce_pipeline.py

nickdesaulniers commented 2 years ago

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.

nickdesaulniers commented 2 years ago

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.

nickdesaulniers commented 2 years ago

Since I mix this up occasionally: Frontend runs before Driver.

nickdesaulniers commented 2 years ago

-print-pipeline-passes can be used to dump a pass pipeline that can then be fed back into opt.

nickdesaulniers commented 2 years ago

opt supports -disable-output rather than generating output but then writing it to /dev/null.

nickdesaulniers commented 2 years ago

The llvm intrinsics list gets generated into llvm/llvm-project/llvm/include/llvm/IR/IntrinsicEnums.inc.

nickdesaulniers commented 2 years ago

uwtable can cause CFI directives to be emitted. nounwind can also help avoid these from -fasynchronous-unwind-tables (or use -fno-asynchronous-unwind-tables)

nickdesaulniers commented 1 year ago

opt -print-passes

nickdesaulniers commented 1 year ago

via @topperc : llc -debug-pass=Executions

nickdesaulniers commented 1 year ago

via @arsenm: llc -debug-pass=Structure

nickdesaulniers commented 1 year ago

diagtool tree prints a tree of diagnostic groups. diagtool tree <warning flag minus -W prefix> prints just that specific subtree.

nickdesaulniers commented 1 year ago

printReg in llvm/lib/CodeGen/TargetRegisterInfo.cpp to print vregs

nickdesaulniers commented 1 year ago

https://github.com/llvm/llvm-project/commit/bf492371033378cec4c0443a3f87db0f818bbade added support for -mllvm -print-pipeline-passes to be invocable from clang.

nickdesaulniers commented 1 year ago

print part of the AST with:

-Xclang -ast-dump -Xclang -ast-dump-filter=<fn name>

will match multiple functions with fn name in them.

nickdesaulniers commented 1 year ago

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.

nickdesaulniers commented 1 year ago

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

nickdesaulniers commented 1 year ago

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

nickdesaulniers commented 10 months ago

-DCMAKE_EXPORT_COMPILE_COMMANDS=ON to generate compile_commands.json.

ninja -d keepdepfile <target> to retain .d files.

nickdesaulniers commented 10 months ago

cmake option --trace-source=<path/to/CmakeLists.txt> will output every statement executed from path/to/CmakeLists.txt.

nickdesaulniers commented 8 months ago

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.