LLVM-EXEGESIS(1)

πŸ’… LLVM-EXEGESIS(1) β€” the LLVM manual, section 1 ✨

okay bestie, buckle up, because this is the page for llvm-exegesis, aka LLVM Machine Instruction Benchmark, and it's giving extremely main character energy. it lives in the LLVM manual (manual name: LLVM, section 1), and it's long, so this is part 1 of 3. let's go πŸ¦‹


🌸 NAME 🌸

llvm-exegesis β€” LLVM Machine Instruction Benchmark πŸ‘‘


✨ SYNOPSIS ✨

llvm-exegesis [options]

πŸ’– DESCRIPTION πŸ’–

so. llvm-exegesis is a benchmarking tool, and what it does is use all the info chilling inside LLVM to measure characteristics of instructions on your actual host machine β€” things like latency, throughput, or port decomposition. no cap, it measures the real deal. πŸ”₯

Here's the vibe: you hand it an LLVM opcode name plus a benchmarking mode, and it generates a code snippet that makes execution as serial (or as parallel, depending) as it possibly can β€” so that we can measure the latency (or, respectively, the inverse throughput / uop decomposition) of that instruction. That snippet gets jitted, and then β€” unless you explicitly asked it not to β€” it gets executed on the host subtarget. The time taken (or resource usage, respectively) is measured using hardware performance counters. Then the result is printed out as YAML to standard output. πŸ’…

And the whole main goal of this tool? To automatically (in)validate LLVM's TableDef scheduling models. iconic. To help with that, we also throw in some analysis of the results. πŸŽ€

Oh and also β€” llvm-exegesis can benchmark arbitrary user-provided code snippets too. yes really. 🫢


🌈 SUPPORTED PLATFORMS 🌈

so right now, for benchmarking, llvm-exegesis only supports:

  • X86 (64-bit only)
  • ARM (AArch64 only, and snippet generation is sparse)
  • MIPS
  • PowerPC (PowerPC64LE only)
  • RISC-V (RV64I/E and RV32I/E)

...and all of that is Linux only. Also, not all benchmarking functionality is guaranteed to work on every platform, so like, manage your expectations bestie. πŸ™ˆ

But! llvm-exegesis also has a separate analysis mode</c> that is supported on every platform that LLVM is. slay. ✨

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. And 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. Additionally, LD_LIBRARY_PATH should be set so that llvm-exegesis can locate the libpfm library during execution. 🧚


πŸŽ€ 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 and some additional utilities to help with that setup, so your snippets can be benchmarked properly. let's break them down πŸ‘‡

  • LLVM-EXEGESIS-DEFREG <register name> β€” adding this annotation to the text assembly snippet you're benchmarking marks the register as requiring a definition. A value will automatically be provided, unless you pass in a second parameter, a hex value. You do that with the LLVM-EXEGESIS-DEFREG <register name> <hex value> format. The <hex value> is a bit pattern used to fill the register. If it's a value smaller than the register, it is 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. Values can be passed through registers from the benchmarking setup in some cases. 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 is put in is platform dependent (e.g., it is 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 that can 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 for 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 lets you set the address where the beginning of the snippet to be executed will be mapped in at. The address is given in hexadecimal. Note that 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. iykyk.
  • 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 this 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 πŸ”₯

Assume you have an X86-64 machine. 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
'
...

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"). If your code depends on the value of some registers, you need to use snippet annotations to ensure setup is performed properly. ✨

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. short king behavior honestly 🫢
  • --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>,... β€” bestie, this is how you say which opcode you wanna measure, by name. You can stack a bunch of them by separating with commas. Peep example 1 for the whole tea. And heads up: you must set at least one of opcode-index, opcode-name, or snippets-file. No optionals here. πŸ’…
  • --snippets-file=<filename> β€” wanna measure your own custom code snippet? Drop the filename right here. Example 2 has the details. And yeah, same rule as above: one of opcode-index, opcode-name, or snippets-file has to be set. Pick your fighter. ✨
  • --mode=[latency|uops|inverse_throughput|analysis] β€” the run mode, aka what vibe we're going for. Lowkey some modes come with extra requirements and extra options, so read the fine print:
    • latency mode can flex either RDTSC or LBR.
    • latency[LBR] is only available on X86 (at least Skylake, so no ancient hardware energy).
    • To run in latency mode you need a positive value for x86-lbr-sample-period and --repetition-mode=loop.
    • In analysis mode you also need to specify at least one of -analysis-clusters-output-file= and -analysis-inconsistencies-output-file=. Not optional, bestie.
  • --benchmark-phase=[prepare-snippet|prepare-and-assemble-snippet|assemble-measured-code|measure] β€” so by default, when -mode= is set, the generated snippet gets executed and measured, and that requires we're running on the exact hardware the snippet was generated for, and that it supports performance measurements. Big ask, ik. But plot twist: you can stop early before measuring. The choices:
    • prepare-snippet: only generates 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 whole shebang.
  • --x86-lbr-sample-period=<nBranches/sample> β€” sets the LBR sampling period, aka how many branches go by before we snag a sample. When you give this a positive value and the mode is latency, we'll use LBRs for measuring. Picking the "right" sampling period: smaller is preferred, but if you sample too often you might get throttled 😭. Use a prime number so you don't consistently skip certain blocks. Math ate, fr fr. πŸ”₯
  • --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 and potentially lower the rate instructions get dispatched to the backend β€” especially on older hardware. Comparing your baseline results with this mode enabled helps you figure out the frontend effects, and can be used to improve latency and throughput estimates. Big brain behavior. πŸ‘‘
  • --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, then wrap the result in a loop that executes min-instructions instructions (so, 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. Trade-offs, always.
    • If you're doing an analysis over many opcodes, it may be best to use the min mode instead, 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 on the specific mode. They run two benchmarks, one twice the length of the first, then subtract the difference between them to get values without overhead. Sneaky clean. ✨
  • --min-instructions=<Number of instructions> β€” the target number of executed instructions. Heads up though: the actual repetition count of the snippet will be min-instructions/snippet size. Higher values = more accurate measurements, but they lengthen the benchmark. Accuracy costs time, the way it always does. πŸ’…
  • --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 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. Cached and cozy. 🧚
  • --max-configs-per-opcode=<value> β€” the maximum configurations that can be generated for each opcode. Default is 1, meaning we assume a single measurement is enough to characterize an opcode. But ngl that's not true of all instructions: for example, the performance characteristics of the LEA instruction on X86 depend on the value of assigned registers and immediates. Setting -max-configs-per-opcode larger than 1 lets llvm-exegesis explore more configurations to discover whether some register or immediate assignments lead to different performance characteristics. Dig deeper. πŸ”
  • --benchmarks-file=</path/to/file> β€” the file to read (analysis mode) or write (latency/uops/inverse_throughput modes) benchmark results to. And "-" uses stdin/stdout. Classic.
  • --analysis-clusters-output-file=</path/to/file> β€” if you provide it, the analysis clusters get written as CSV to this file. "-" prints to stdout. By default, this analysis is not run. You gotta opt in. πŸ’–
  • --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 either.
  • --analysis-filter=[all|reg-only|mem-only] β€” by default all benchmark results get analysed, but sometimes it's useful to only look at the ones that do not involve memory, or the opposite. This option lets you either keep all benchmarks, or filter out (ignore) either all the ones that involve memory (instructions that may read or write to memory), or the opposite β€” only keep such benchmarks. Pick your lane. πŸŽ€
  • --analysis-clustering=[dbscan,naive] β€” which clustering algorithm to use. Default is DBSCAN. The naive clustering algorithm is better for doing further work on the -analysis-inconsistencies-output-file= output β€” it creates one cluster per opcode and checks that the cluster is stable (all points are neighbours). Neighbourly vibes. 🌸
  • --analysis-numpoints=<dbscan numPoints parameter> β€” sets the numPoints parameter used for DBSCAN clustering (analysis mode, DBSCAN only). πŸ¦‹
  • --analysis-clustering-epsilon=<dbscan epsilon parameter> β€” sets the epsilon parameter used for clustering of benchmark points (analysis mode).
  • --analysis-inconsistency-epsilon=<epsilon> β€” sets the epsilon parameter used to detect 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 together if the measured performance characteristics differ. By default all such opcodes get filtered out. This flag instead shows only such unstable opcodes. Chaos, but on purpose. πŸ’€
  • --ignore-invalid-sched-class=false β€” if set, ignore instructions that don't have a sched class (class idx = 0). Simple as.
  • --mtriple=<triple name> β€” the target triple. See -version for available targets. πŸ‘‘
  • --mcpu=<cpu name> β€” if set, measure the cpu characteristics using the counters for this CPU. Super useful when you're creating new sched models (like when the host CPU is unknown to LLVM). (-mcpu=help for details.)
  • --analysis-override-benchmark-triple-and-cpu β€” by default, llvm-exegesis analyzes benchmarks for the triple/CPU they were measured for. But if you wanna analyze them for some other combination (specified via -mtriple/-mcpu), pass this flag. Main character energy: analyze whoever you want. πŸ’…
  • --dump-object-to-disk=<filename> β€” if set, llvm-exegesis dumps the generated code to a temporary file so you can inspect it. Disabled by default.
  • --use-dummy-perf-counters β€” if set, llvm-exegesis won't read any real performance counters and returns a dummy value instead. Handy for making sure a snippet doesn't crash when hardware performance counters aren't available, and for debugging llvm-exegesis itself. Fake it till you make it. πŸ™ˆ
  • --execution-mode=[inprocess,subprocess] β€” which execution mode to use. inprocess is the default. subprocess allows extra features like memory annotations, but it's currently restricted to X86-64 on Linux. Fancy but picky.
  • --benchmark-repeat-count=<repeat-count> β€” lets you specify how many times to repeat the measurement when doing latency measurements. By default, llvm-exegesis repeats a latency measurement enough times to balance run-time and noise reduction. Balance is everything, bestie. ⭐
  • --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] β€” turns on validation counters, which measure extra microarchitectural events like cache misses to validate snippet execution conditions. These events get measured using the perf subsystem in a group with the performance counter used to measure the value of interest. You can specify this flag multiple times to measure multiple events. The max number of validation counters is platform dependent. Stack 'em up. πŸ”₯
  • --benchmark-process-cpu=<cpu id> β€” specifies the number of the CPU that should be used to run the benchmarking subprocess. When starting the subprocess, llvm-exegesis sets the affinity of the subprocess to only include the specified CPU. Only works in the subprocess execution mode. Pin it down, periodt. πŸŽ€

πŸ’– EXIT STATUS πŸ’–

okay so bestie, here's the vibe check on how this whole thing ends πŸ‘‘

  • 0 β€” success!! the run went off without a hitch, she ate, no notes πŸ’…βœ¨
  • anything that is not 0 β€” not it. an error message gets printed to standard error, and the tool hands back a non-0 value 😭 so like, always check your exit status before you start celebrating, fr fr.
lowkey the most important habit ever: echo $? right after you run it. the error text goes to standard error, not standard output, so if you're piping stuff around and wondering why it's quiet... that's why πŸ™ˆ

✨ AUTHOR ✨

maintained by the LLVM Team 🫢 they're the ones keeping this whole thing iconic:

https://llvm.org/


2003-2026, LLVM Project β€” yeah, that's a whole two-decade-plus era, no cap πŸŒˆπŸ‘‘


and that's a wrap on the whole page, bestie πŸ¦‹ if you made it all the way here you are genuinely built different πŸ’œ this lil doc came from the LLVM source docs, rendered as version 22, and the date stamped on it is 2026-07-16 🌸 go forth, benchmark something, and slay βœ¨πŸ’– periodt.

πŸ“¦ where this page comes from