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 inllvm-exegesis, LLVM must be configured and built withLLVM_ENABLE_LIBPFMenabled, becausellvm-exegesisdepends onlibpfm4for 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 theLLVM-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 aLLVM-EXEGESIS-LIVEINare as follows:- Scratch memory register β the specific register that this value is put in is platform dependent (e.g., it is the
RDIregister 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.
- Scratch memory register β the specific register that this value is put in is platform dependent (e.g., it is the
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 theLLVM-EXEGESIS-MEM-MAPannotation. 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-exegesisneeds 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.,R8on 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-1will result in measuring every existing opcode. See example 1 for details. Eitheropcode-index,opcode-nameorsnippets-filemust 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 ofopcode-index,opcode-name, orsnippets-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 ofopcode-index,opcode-name, orsnippets-filehas 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:latencymode can flex either RDTSC or LBR.latency[LBR]is only available on X86 (at least Skylake, so no ancient hardware energy).- To run in
latencymode you need a positive value forx86-lbr-sample-periodand--repetition-mode=loop. - In
analysismode 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 asprepare-snippet, but also dumps an excerpt of the sequence (hex encoded). πassemble-measured-code: same asprepare-and-assemble-snippet, but also creates the full sequence that can be dumped to a file using--dump-object-to-disk.measure: same asassemble-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 islatency, 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:duplicatecreates a large, straight line basic block withmin-instructionsinstructions (repeating the snippetmin-instructions/snippet sizetimes).loopwill, optionally, duplicate the snippet until the loop body contains at leastloop-body-sizeinstructions, then wrap the result in a loop that executesmin-instructionsinstructions (so, again, repeating the snippetmin-instructions/snippet sizetimes).- The
loopmode, 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
minmode 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 bemin-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 is1, 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 theLEAinstruction on X86 depend on the value of assigned registers and immediates. Setting-max-configs-per-opcodelarger than1letsllvm-exegesisexplore 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 (analysismode) or write (latency/uops/inverse_throughputmodes) 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-versionfor 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=helpfor details.)--analysis-override-benchmark-triple-and-cpuβ by default,llvm-exegesisanalyzes 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-exegesisdumps the generated code to a temporary file so you can inspect it. Disabled by default.--use-dummy-perf-countersβ if set,llvm-exegesiswon'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 debuggingllvm-exegesisitself. Fake it till you make it. π--execution-mode=[inprocess,subprocess]β which execution mode to use.inprocessis the default.subprocessallows 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-exegesisrepeats 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-exegesissets the affinity of the subprocess to only include the specified CPU. Only works in thesubprocessexecution 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-0value π 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:
π COPYRIGHT π
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
- fedora 44: llvm 22.1.8-4.fc44 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 44: llvm 22.1.8-4.fc44 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms