LLVM-EXEGESIS(1)

๐Ÿ’– LLVM-EXEGESIS ๐Ÿ’–

okay bestie, gather round, because we're about to talk about llvm-exegesis โ€” that's the LLVM-EXEGESIS(1) manual page, the LLVM Machine Instruction Benchmark, and honestly? it's giving mad scientist lab equipment but make it cute. ๐Ÿงšโœจ


๐ŸŒธ NAME ๐ŸŒธ

llvm-exegesis โ€” LLVM Machine Instruction Benchmark ๐Ÿ’…


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

llvm-exegesis [options]

โœจ DESCRIPTION โœจ

so llvm-exegesis is this benchmarking tool that uses info LLVM already has lying around to measure characteristics of instructions on the machine you're on โ€” things like latency, throughput, or port decomposition. no cap. ๐Ÿ”ฅ

here's the vibe: you hand it an LLVM opcode name and a benchmarking mode, and llvm-exegesis generates a lil code snippet that makes execution as serial as possible (or as parallel as possible) so it can measure the latency (or, respectively, the inverse throughput / uop decomposition) of that instruction. that snippet gets jitted and โ€” unless you asked it not to โ€” executed on the host subtarget. then the time taken (or the resource usage) is measured using hardware performance counters. the result gets printed out as YAML to standard output. periodt. ๐Ÿ’…

the main goal of this tool is to automatically (in)validate LLVM's TableDef scheduling models. like, that's the whole point. and to help with that, they also provide analysis of the results. iconic behavior honestly.

also! llvm-exegesis can benchmark arbitrary user-provided code snippets too. so you're not stuck with just the built-in stuff. ๐Ÿฆ‹


๐ŸŒˆ SUPPORTED PLATFORMS ๐ŸŒˆ

rn llvm-exegesis only supports X86 (64-bit only), ARM (AArch64 only, and snippet generation is sparse), MIPS, and PowerPC (PowerPC64LE only) on Linux for benchmarking. not all benchmarking functionality is guaranteed to work on every platform, bestie โ€” some of it is lowkey platform-dependent. llvm-exegesis also has a separate analysis mode that is supported on every platform that LLVM is. ๐Ÿ’–

to enable benchmarking in llvm-exegesis, LLVM must be configured and built with LLVM_ENABLE_LIBPFM enabled, because llvm-exegesis depends on libpfm4 for accessing performance counters. benchmarking may fail if the target CPU is unsupported by libpfm. you can verify that by setting the LIBPFM_VERBOSE and LIBPFM_DEBUG environment variables to enable verbose or debug mode for libpfm. ๐Ÿ‘‘

if libpfm is installed in a non-standard directory, LLVM can be configured to locate the necessary library and header files by setting the LIBRARY_PATH, C_INCLUDE_PATH, and CPLUS_INCLUDE_PATH environment variables. and additionally, LD_LIBRARY_PATH should be set so that llvm-exegesis can locate the libpfm library during execution. don't skip that one, fr fr. ๐Ÿซถ


๐Ÿฆ‹ SNIPPET ANNOTATIONS ๐Ÿฆ‹

llvm-exegesis supports benchmarking arbitrary snippets of assembly. but here's the thing โ€” benchmarking those snippets often requires some setup so they can execute properly. so llvm-exegesis has five annotations plus some additional utilities to help with setup, so your snippets can be benchmarked properly. let's go through them one by one bestie ๐Ÿ’…

  • LLVM-EXEGESIS-DEFREG <register name> โ€” adding this annotation to the text assembly snippet you're benchmarking marks that register as requiring a definition. a value will automatically be provided unless a second parameter, a hex value, is passed in. that second form looks like LLVM-EXEGESIS-DEFREG <register name> <hex value>. the <hex value> is a bit pattern used to fill the register. and if it's a value smaller than the register, it gets sign extended to match the size of the register. โœจ
  • LLVM-EXEGESIS-LIVEIN <register name> โ€” this annotation lets you specify registers that should keep their value upon starting the benchmark. in some cases, values can be passed through registers from the benchmarking setup. the registers and the values assigned to them that can be utilized in the benchmarking script with a LLVM-EXEGESIS-LIVEIN are as follows:
    • Scratch memory register โ€” the specific register that this value gets put in is platform dependent (e.g., it's the RDI register on X86 Linux). setting this register as a live in ensures that a pointer to a block of memory (1MB) is placed within this register, which can then be used by the snippet. ๐Ÿ’–
  • LLVM-EXEGESIS-MEM-DEF <value name> <size> <value> โ€” this annotation lets you specify memory definitions that can later be mapped into the execution process of a snippet with the LLVM-EXEGESIS-MEM-MAP annotation. each value is named using the <value name> argument so it can be referenced later within a map annotation. the size is specified in a decimal number of bytes and the value is given in hexadecimal. if the size of the value is less than the specified size, the value will be repeated until it fills the entire section of memory. using this annotation requires using the subprocess execution mode. ๐ŸŽ€
  • LLVM-EXEGESIS-MEM-MAP <value name> <address> โ€” this annotation allows mapping previously defined memory definitions into the execution context of a process. the value name refers to a previously defined memory definition, and the address is a decimal number that specifies the address the memory definition should start at. note that a single memory definition can be mapped multiple times. using this annotation requires the subprocess execution mode. ๐Ÿ”ฅ
  • LLVM-EXEGESIS-SNIPPET-ADDRESS <address> โ€” this annotation allows for setting the address where the beginning of the snippet to be executed will be mapped in at. the address is given in hexadecimal. heads up: the snippet also includes setup code, so the instruction exactly at the specified address will not be the first instruction in the snippet. using this annotation requires the subprocess execution mode. this is useful in cases where the memory accessed by the snippet depends on the location of the snippet, like RIP-relative addressing. ๐Ÿ’…
  • LLVM-EXEGESIS-LOOP-REGISTER <register name> โ€” this annotation specifies the loop register to use for keeping track of the current iteration when using the loop repetition mode. llvm-exegesis needs to keep track of the current loop iteration within the loop repetition mode in a performant manner (i.e., no memory accesses), and it uses a register to do this. this register has an architecture specific default (e.g., R8 on X86), but that might conflict with some snippets. this annotation lets you change the register to prevent interference between the loop index register and the snippet. ๐Ÿฆ‹

๐Ÿ‘‘ EXAMPLE 1: BENCHMARKING INSTRUCTIONS ๐Ÿ‘‘

okay assume you have an X86-64 machine (bestie, you probably do). to measure the latency of a single instruction, run:

$ llvm-exegesis --mode=latency --opcode-name=ADD64rr

measuring the uop decomposition or inverse throughput of an instruction works similarly:

$ llvm-exegesis --mode=uops --opcode-name=ADD64rr
$ llvm-exegesis --mode=inverse_throughput --opcode-name=ADD64rr

the output is a YAML document (the default is to write to stdout, but you can redirect the output to a file using --benchmarks-file):

---
key:
  opcode_name:     ADD64rr
  mode:            latency
  config:          ''
cpu_name:        haswell
llvm_triple:     x86_64-unknown-linux-gnu
num_repetitions: 10000
measurements:
  - { key: latency, value: 1.0058, debug_string: '' }
error:           ''
info:            'explicit self cycles, selecting one aliasing configuration.
Snippet:
ADD64rr R8, R8, R10
'
...

and to measure the latency of all instructions for the host architecture, run:

$ llvm-exegesis --mode=latency --opcode-index=-1

๐ŸŒธ EXAMPLE 2: BENCHMARKING A CUSTOM CODE SNIPPET ๐ŸŒธ

to measure the latency/uops of a custom piece of code, you can specify the snippets-file option (- reads from standard input). ๐Ÿ˜Œ

$ echo "vzeroupper" | llvm-exegesis --mode=uops --snippets-file=-

real-life code snippets typically depend on registers or memory. llvm-exegesis checks the liveliness of registers (i.e. any register use has a corresponding def or is a "live in"). so if your code depends on the value of some registers, you need to use snippet annotations to ensure setup is performed properly. don't skip this step bestie, it'll bite you. ๐Ÿ’€

for example, the following code snippet depends on the values of XMM1 (which will be set by the tool) and the memory buffer passed in RDI (live in).

# LLVM-EXEGESIS-LIVEIN RDI
# LLVM-EXEGESIS-DEFREG XMM1 42
vmulps        (%rdi), %xmm1, %xmm2
vhaddps       %xmm2, %xmm2, %xmm3
addq $0x10, %rdi

๐ŸŽ€ EXAMPLE 3: BENCHMARKING WITH MEMORY ANNOTATIONS ๐ŸŽ€

some snippets require memory setup in specific places to execute without crashing. setting up memory can be accomplished with the LLVM-EXEGESIS-MEM-DEF and LLVM-EXEGESIS-MEM-MAP annotations. to execute the following snippet:

movq $8192, %rax
movq (%rax), %rdi

we need to have at least eight bytes of memory allocated starting 0x2000. we can create the necessary execution environment with the following annotations added to the snippet:

# LLVM-EXEGESIS-MEM-DEF test1 4096 7fffffff
# LLVM-EXEGESIS-MEM-MAP test1 8192

movq $8192, %rax
movq (%rax), %rdi

๐Ÿ’œ EXAMPLE 4: ANALYSIS ๐Ÿ’œ

assuming you have a set of benchmarked instructions (either latency or uops) as YAML in file /tmp/benchmarks.yaml, you can analyze the results using the following command:

$ llvm-exegesis --mode=analysis \
--benchmarks-file=/tmp/benchmarks.yaml \
--analysis-clusters-output-file=/tmp/clusters.csv \
--analysis-inconsistencies-output-file=/tmp/inconsistencies.html

this will group the instructions into clusters with the same performance characteristics. the clusters will be written out to /tmp/clusters.csv in the following format:

cluster_id,opcode_name,config,sched_class
...
2,ADD32ri8_DB,,WriteALU,1.00
2,ADD32ri_DB,,WriteALU,1.01
2,ADD32rr,,WriteALU,1.01
2,ADD32rr_DB,,WriteALU,1.00
2,ADD32rr_REV,,WriteALU,1.00
2,ADD64i32,,WriteALU,1.01
2,ADD64ri32,,WriteALU,1.01
2,MOVSX64rr32,,BSWAP32r_BSWAP64r_MOVSX64rr32,1.00
2,VPADDQYrr,,VPADDBYrr_VPADDDYrr_VPADDQYrr_VPADDWYrr_VPSUBBYrr_VPSUBDYrr_VPSUBQYrr_VPSUBWYrr,1.02
2,VPSUBQYrr,,VPADDBYrr_VPADDDYrr_VPADDQYrr_VPADDWYrr_VPSUBBYrr_VPSUBDYrr_VPSUBQYrr_VPSUBWYrr,1.01
2,ADD64ri8,,WriteALU,1.00
2,SETBr,,WriteSETCC,1.01
...

llvm-exegesis will also analyze the clusters to point out inconsistencies in the scheduling information. the output is an html file. for example, /tmp/inconsistencies.html will contain messages like the following : [image] ๐Ÿ™ˆ

note that the scheduling class names will be resolved only when llvm-exegesis is compiled in debug mode, else only the class id will be shown. this does not invalidate any of the analysis results though. ๐Ÿ’–


โœจ OPTIONS โœจ

  • --help โ€” print a summary of command line options. the classic. ๐Ÿ‘‘
  • --opcode-index=<LLVM opcode index> โ€” specify the opcode to measure, by index. specifying -1 will result in measuring every existing opcode. see example 1 for details. either opcode-index, opcode-name or snippets-file must be set. ๐Ÿ”ฅ
  • --opcode-name=<opcode name 1>,<opcode name 2>,... โ€” specify the opcode to measure, by name. several opcodes can be specified as a comma-separated list. see example 1 for details. either opcode-index, opcode-name or snippets-file must be set. ๐Ÿ’…
  • --snippets-file=<filename> โ€” tells the tool which custom code snippet to measure. Peep Example 2 for the deets. Heads up: you literally have to set one of opcode-index, opcode-name or snippets-file โ€” no vibes-only runs bestie. ๐Ÿ’…
  • --mode=[latency|uops|inverse_throughput|analysis] โ€” pick your run mode. Some modes come with extra requirements and options, so read on:
    • latency mode can make use of either RDTSC or LBR. latency[LBR] is only available on X86 (at least Skylake, so no dusty hardware pls). To run in latency mode, you must specify a positive value for x86-lbr-sample-period and --repetition-mode=loop. Both. Or it's not happening. ๐Ÿซ 
    • In analysis mode, you also need to specify at least one of -analysis-clusters-output-file= and -analysis-inconsistencies-output-file=. It's giving "you can't analyze nothing". ๐Ÿ’€
  • --benchmark-phase=[prepare-snippet|prepare-and-assemble-snippet|assemble-measured-code|measure] โ€” by default, when -mode= is specified, the generated snippet gets executed and measured, which means we have to actually be running on the hardware the snippet was generated for, and that hardware has to support performance measurements. Iconic, but demanding. That said, you can stop early before the measuring stage. Your choices:
    • prepare-snippet: only generate the minimal instruction sequence.
    • prepare-and-assemble-snippet: same as prepare-snippet, but also dumps an excerpt of the sequence (hex encoded).
    • assemble-measured-code: same as prepare-and-assemble-snippet, but also creates the full sequence that can be dumped to a file using --dump-object-to-disk.
    • measure: same as assemble-measured-code, but also runs the measurement. The full send. ๐Ÿ”ฅ
  • --x86-lbr-sample-period=<nBranches/sample> โ€” sets the LBR sampling period, aka how many branches we let pass before snagging a sample. When a positive value is set here and the mode is latency, we'll use LBRs for measuring. Picking the "right" period: a small value is preferred, but if you sample too often you can get throttling. Use a prime number to avoid consistently skipping certain blocks โ€” trust, that part matters. ๐Ÿงš
  • --x86-disable-upper-sse-registers โ€” using the upper xmm registers (xmm8-xmm15) forces a longer instruction encoding, which can put more pressure on the frontend fetch and decode stages, potentially reducing how fast instructions get dispatched to the backend, especially on older hardware. Comparing baseline results with this mode enabled can help you figure out the effects of the frontend and can be used to improve latency and throughput estimates. โœจ
  • --repetition-mode=[duplicate|loop|min|middle-half-duplicate|middle-half-loop] โ€” pick your repetition mode, bestie:
    • duplicate creates a large, straight line basic block with min-instructions instructions (repeating the snippet min-instructions/snippet size times).
    • loop will, optionally, duplicate the snippet until the loop body contains at least loop-body-size instructions, and then wrap the result in a loop which will execute min-instructions instructions (thus, again, repeating the snippet min-instructions/snippet size times). The loop mode, especially with loop unrolling, tends to better hide the effects of the CPU frontend on architectures that cache decoded instructions โ€” but it consumes a register for counting iterations. ๐Ÿ’€
    • If you're performing an analysis over many opcodes, it may be best to instead use the min mode, which will run each other mode, and produce the minimal measured result.
    • The middle half repetition modes will either duplicate or run the snippet in a loop depending upon the specific mode. The middle half repetition modes will run two benchmarks, one twice the length of the first one, and then subtract the difference between them to get values without overhead. Math girlies stay winning. โž—
  • --min-instructions=<Number of instructions> โ€” the target number of executed instructions. Note that the actual repetition count of the snippet will be min-instructions/snippet size. Higher values lead to more accurate measurements but lengthen the benchmark โ€” the eternal tradeoff. โš–๏ธ
  • --loop-body-size=<Preferred loop body size> โ€” only effective for -repetition-mode=[loop|min]. Instead of looping over the snippet directly, it first duplicates it so that the loop body contains at least this many instructions. This potentially results in the loop body being cached in the CPU Op Cache / Loop Cache, which may have higher throughput than the CPU decoders. ๐Ÿš€
  • --max-configs-per-opcode=<value> โ€” the maximum configurations that can be generated for each opcode. By default this is 1, meaning we assume a single measurement is enough to characterize an opcode. This might not be true of all instructions: for example, the performance characteristics of the LEA instruction on X86 depends on the value of assigned registers and immediates. Setting a value larger than 1 lets llvm-exegesis explore more configurations to discover if some register or immediate assignments lead to different performance characteristics. ๐Ÿ”
  • --benchmarks-file=</path/to/file> โ€” the file to read (analysis mode) or write (latency/uops/inverse_throughput modes) benchmark results to. "-" uses stdin/stdout. ๐ŸŽ€
  • --analysis-clusters-output-file=</path/to/file> โ€” if provided, write the analysis clusters as CSV to this file. "-" prints to stdout. By default, this analysis is not run.
  • --analysis-inconsistencies-output-file=</path/to/file> โ€” if non-empty, write inconsistencies found during analysis to this file. - prints to stdout. By default, this analysis is not run.
  • --analysis-filter=[all|reg-only|mem-only] โ€” by default, all benchmark results are analysed, but sometimes it's useful to only look at the ones that don't involve memory, or the opposite. This option lets you either keep all benchmarks, or filter out (ignore) either all the ones that do involve memory (involve instructions that may read or write to memory), or the opposite โ€” only keep such benchmarks. ๐ŸŒˆ
  • --analysis-clustering=[dbscan,naive] โ€” which clustering algorithm to use. By default DBSCAN is used. The naive clustering algorithm is better for doing further work on the -analysis-inconsistencies-output-file= output: it will create one cluster per opcode, and check that the cluster is stable (all points are neighbours). ๐Ÿค
  • --analysis-numpoints=<dbscan numPoints parameter> โ€” the numPoints parameter to be used for DBSCAN clustering (analysis mode, DBSCAN only).
  • --analysis-clustering-epsilon=<dbscan epsilon parameter> โ€” the epsilon parameter used for clustering of benchmark points (analysis mode).
  • --analysis-inconsistency-epsilon=<epsilon> โ€” the epsilon parameter used for detection of when the cluster is different from the LLVM schedule profile values (analysis mode).
  • --analysis-display-unstable-clusters โ€” if there's more than one benchmark for an opcode, those benchmarks may end up not being clustered into the same cluster if the measured performance characteristics are different. By default all such opcodes are filtered out. This flag will instead show only such unstable opcodes. Drama. Show only the mess. ๐Ÿ’…
  • --ignore-invalid-sched-class=false โ€” if set, ignore instructions that do not have a sched class (class idx = 0). ๐Ÿ™ˆ
  • --mtriple=<triple name> โ€” target triple. See -version for available targets.
  • --mcpu=<cpu name> โ€” if set, measure the cpu characteristics using the counters for this CPU. This is useful when creating new sched models (the host CPU is unknown to LLVM). (-mcpu=help for details) ๐Ÿ‘‘
  • --analysis-override-benchmark-triple-and-cpu โ€” by default, llvm-exegesis will analyze the benchmarks for the triple/CPU they were measured for, but if you want to analyze them for some other combination (specified via -mtriple/-mcpu), you can pass this flag. โœจ
  • --dump-object-to-disk=true โ€” if set, llvm-exegesis will dump the generated code to a temporary file to enable code inspection. Disabled by default. ๐Ÿ—‚๏ธ
  • --use-dummy-perf-counters โ€” if set, llvm-exegesis will not read any real performance counters and return a dummy value instead. This can be used to ensure a snippet doesn't crash when hardware performance counters are unavailable, and for debugging llvm-exegesis itself. ๐Ÿฉน
  • --execution-mode=[inprocess,subprocess] โ€” what execution mode to use. The inprocess execution mode is the default. The subprocess execution mode allows for additional features such as memory annotations but is currently restricted to X86-64 on Linux. ๐Ÿง
  • --benchmark-repeat-count=<repeat-count> โ€” lets you specify the number of times to repeat the measurement when performing latency measurements. By default, llvm-exegesis will repeat a latency measurement enough times to balance run-time and noise reduction. ๐Ÿ”
  • --validation-counter=[instructions-retired,l1d-cache-load-misses,l1d-cache-store-misses,l1i-cache-load-misses,data-tlb-load-misses,data-tld-store-misses,instruction-tlb-load-misses] โ€” enables the use of validation counters, which measure additional microarchitectural events like cache misses to validate snippet execution conditions. These events are measured using the perf subsystem in a group with the performance counter used to measure the value of interest. This flag can be specified multiple times to measure multiple events. The maximum number of validation counters is platform dependent. ๐Ÿงฎ
  • --benchmark-process-cpu=<cpu id> โ€” the number of the CPU that should be used to run the benchmarking subprocess. When starting the subprocess, llvm-exegesis will set the affinity of the subprocess to only include the specified CPU. This option only works in the subprocess execution mode. ๐Ÿ“Œ

๐Ÿšช EXIT STATUS ๐Ÿšช

llvm-exegesis returns 0 on success. Otherwise, an error message is printed to standard error, and the tool returns a non 0 value. Simple. Clean. No notes. โœจ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Maintained by the LLVM Team (https://llvm.org/). ๐Ÿ’–


2003-2025, LLVM Project


Okay bestie that's the whole page, you made it to the end, I'm so proud of you fr fr ๐Ÿซถ This icon of a manual page is from the LLVM Project โ€” that copyright situation is 2003-2025, LLVM Project โ€” and this particular version was dated 2025-09-03. Go measure something and slay. ๐Ÿ’…๐ŸŒธ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from