Skip to content

Instantly share code, notes, and snippets.

@aqjune
Last active July 7, 2023 03:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aqjune/b984d4984f9325c1d5f02f322c87a00d to your computer and use it in GitHub Desktop.
Save aqjune/b984d4984f9325c1d5f02f322c87a00d to your computer and use it in GitHub Desktop.
Useful clang/opt options

Parameters to clang

http://llvm.org/docs/ProgrammersManual.html#the-llvm-debug-macro-and-debug-option https://clang.llvm.org/docs/UsersManual.html#controlling-size-of-debug-information

-fno-discard-value-names
-g0
	Don’t generate any debug info (default).
-gline-tables-only
	Generate line number tables only.
	This kind of debug info allows to obtain stack traces with function names, file names and line numbers (by such tools as gdb or addr2line). It doesn’t contain any other data (e.g. description of local variables or function parameters).
-fstandalone-debug
	Clang supports a number of optimizations to reduce the size of debug information in the binary. They work based on the assumption that the debug type information can be spread out over multiple compilation units. For instance, Clang will not emit type definitions for types that are not needed by a module and could be replaced with a forward declaration. Further, Clang will only emit type info for a dynamic C++ class in the module that contains the vtable for the class.
	The -fstandalone-debug option turns off these optimizations. This is useful when working with 3rd-party libraries that don’t come with debug information. Note that Clang will never emit type information for types that are not referenced at all by the program.
-fno-standalone-debug
	On Darwin -fstandalone-debug is enabled by default. The -fno-standalone-debug option can be used to get to turn on the vtable-based optimization described above.
-g
	Generate complete debug info.

-###
	Get the full command line used to invoke the real compilation process.

-fsave-optimization-record
-save-stats=<value>     Save llvm statistics.
-save-stats             Save llvm statistics.
-save-temps=<value>     Save intermediate compilation results.
-save-temps             Save intermediate compilation results

-Xanalyzer <arg>        Pass <arg> to the static analyzer
-Xassembler <arg>       Pass <arg> to the assembler
-Xclang <arg>           Pass <arg> to the clang compiler
-Xcuda-fatbinary <arg>  Pass <arg> to fatbinary invocation
-Xcuda-ptxas <arg>      Pass <arg> to the ptxas assembler
-Xlinker <arg>          Pass <arg> to the linker
-Xopenmp-target=<triple> <arg> Pass <arg> to the target offloading toolchain identified by <triple>.
-Xopenmp-target <arg>   Pass <arg> to the target offloading toolchain.
-Xpreprocessor <arg>    Pass <arg> to the preprocessor
-x <language>           Treat subsequent input files as having type <language>

Parameters to clang -Xclang

How to get the list of parameters:

clang -Xclang --help tmp.cpp
-emit-codegen-only      Generate machine code, but discard output
-emit-header-module     Generate pre-compiled module file from a set of header files
-emit-html              Output input source as HTML
-emit-llvm-bc           Build ASTs then convert to LLVM, emit .bc file
-emit-llvm-only         Build ASTs and convert to LLVM, discarding output
-emit-llvm-uselists     Preserve order of LLVM use-lists when serializing
-emit-llvm              Use the LLVM representation for assembler and object files
-emit-module-interface  Generate pre-compiled module file from a C++ module interface
-emit-module            Generate pre-compiled module file from a module map
-emit-obj               Emit native object files
-emit-pch               Generate pre-compiled header file

-Rpass=<value>          Report transformations performed by optimization passes whose name matches the given POSIX regular expression
-disable-llvm-passes    Use together with -emit-llvm to get pristine LLVM IR from the frontend by not running any LLVM passes at all
-mllvm -disable-llvm-optzns
-print-stats            Print performance metrics and statistics
-fsave-optimization-record
-print-module-scope

-save-temps=<value>     Save intermediate compilation results.

Parameters to clang -mllvm

-filter-print-funcs=<function names>              - Only print IR for functions whose name match this for all print-[before|after][-all] options
-print-after-all                                  - Print IR after each pass
-print-before-all                                 - Print IR before each pass
-print-machineinstrs=<pass-name>                  - Print machine instrs
-simplify-mir                                     - Leave out unnecessary information when printing MIR
  -print-module-scope                               - When printing IR for print-[before|after]{-all} always print a module IR

-print-isel-input
	Print LLVM IR input to isel pass

ex)

-S -emit-llvm -mllvm -print-after-all -mllvm -filter-print-funcs="sqlite3Utf16ByteLen" 

Parameters to clang -cc1

Question: What's the difference between -cc1 and -Xclang?

-emit-html    Print the source file in HTML format
-save-temps=<value>     Save intermediate compilation results.

Parameters to opt

-analyze
-p print module after each transformation
-debug print debug
-debug-only=asdf
-strip-debug-declare                            - Strip all llvm.dbg.declare intrinsics
-time-passes
-stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment