Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
LLVM
Logo
LLVM
  • Frequently Asked Questions (FAQ)
  • The LLVM Lexicon
  • Getting Started/Tutorials
    • Architecture & Platform Information for Compiler Writers
    • Performance Tips for Frontend Authors
    • Getting Started with the LLVM System
    • Getting Started with the LLVM System using Microsoft Visual Studio
    • LLVM Programmer’s Manual
    • Debugging LLVM
    • LLVM Tutorial: Table of Contents
      • My First Language Frontend with LLVM Tutorial
      • 1. Kaleidoscope: Kaleidoscope Introduction and the Lexer
      • 2. Kaleidoscope: Implementing a Parser and AST
      • 3. Kaleidoscope: Code generation to LLVM IR
      • 4. Kaleidoscope: Adding JIT and Optimizer Support
      • 5. Kaleidoscope: Extending the Language: Control Flow
      • 6. Kaleidoscope: Extending the Language: User-defined Operators
      • 7. Kaleidoscope: Extending the Language: Mutable Variables
      • 8. Kaleidoscope: Compiling to Object Code
      • 9. Kaleidoscope: Adding Debug Information
      • 10. Kaleidoscope: Conclusion and other useful LLVM tidbits
      • 1. Building a JIT: Starting out with KaleidoscopeJIT
      • 2. Building a JIT: Adding Optimizations – An introduction to ORC Layers
      • 3. Building a JIT: Per-function Lazy Compilation
      • 4. Building a JIT: Extreme Laziness - Using LazyReexports to JIT from ASTs
    • MyFirstTypoFix
  • Reference
    • How To Use Attributes
    • LLVM Command Guide
      • FileCheck - Flexible pattern matching file verifier
      • clang-tblgen - Description to C++ Code for Clang
      • dsymutil - manipulate archived DWARF debug symbol files
      • lit - LLVM Integrated Tester
      • llc - LLVM static compiler
      • lldb-tblgen - Description to C++ Code for LLDB
      • lli - directly execute programs from LLVM bitcode
      • llubi - LLVM UB-aware Interpreter
      • llvm-addr2line - a drop-in replacement for addr2line
      • llvm-ar - LLVM archiver
      • llvm-as - LLVM assembler
      • llvm-bcanalyzer - LLVM bitcode analyzer
      • llvm-cgdata - LLVM CodeGen Data Tool
      • llvm-config - Print LLVM compilation options
      • llvm-cov - emit coverage information
      • llvm-cxxfilt - LLVM symbol name demangler
      • llvm-cxxmap - Mangled name remapping tool
      • llvm-debuginfo-analyzer - Print a logical representation of low-level debug information.
      • llvm-diff - LLVM structural ‘diff’
      • llvm-dis - LLVM disassembler
      • llvm-dwarfdump - dump and verify DWARF debug information
      • llvm-dwarfutil - A tool to copy and manipulate debug info
      • llvm-exegesis - LLVM Machine Instruction Benchmark
      • llvm-extract - extract a function from an LLVM module
      • llvm-extract-bundle-entry - extract an offload bundle entry
      • llvm-ifs - shared object stubbing tool
      • llvm-install-name-tool - LLVM tool for manipulating install-names and rpaths
      • llvm-ir2vec - IR2Vec and MIR2Vec Embedding Generation Tool
      • llvm-lib - LLVM lib.exe compatible library tool
      • llvm-libtool-darwin - LLVM tool for creating libraries for Darwin
      • llvm-link - LLVM bitcode linker
      • llvm-lipo - LLVM tool for manipulating universal binaries
      • llvm-locstats - calculate statistics on DWARF debug location
      • llvm-mc - LLVM Machine Code Playground
      • llvm-mca - LLVM Machine Code Analyzer
      • llvm-nm - list LLVM bitcode and object file’s symbol table
      • llvm-objcopy - object copying and editing tool
      • llvm-objdump - LLVM’s object file dumper
      • llvm-offload-binary - LLVM Offload Binary Packager
      • llvm-opt-report - generate optimization report from YAML
      • llvm-otool - Mach-O dumping tool
      • llvm-pdbutil - PDB File forensics and diagnostics
      • llvm-profdata - Profile data tool
      • llvm-profgen - LLVM SPGO profile generation tool
      • llvm-ranlib - generates an archive index
      • llvm-readelf - GNU-style LLVM Object Reader
      • llvm-readobj - LLVM Object Reader
      • llvm-reduce - LLVM automatic testcase reducer.
      • llvm-remarkutil - Remark utility
      • llvm-size - print size information
      • llvm-stress - generate random .ll files
      • llvm-strings - print strings
      • llvm-strip - object stripping tool
      • llvm-symbolizer - convert addresses into source code locations
      • llvm-tblgen - Target Description to C++ Code for LLVM
      • llvm-test-mustache-spec - LLVM tool to test Mustache library compliance
      • llvm-tli-checker - TargetLibraryInfo vs library checker
      • mlir-tblgen - Description to C++ Code for MLIR
      • opt - LLVM optimizer
      • tblgen - Description to C++ Code
    • Using -opt-bisect-limit to debug optimization errors
    • Symbolizer Markup Format
    • The PDB File Format
      • The MSF File Format
      • The PDB Info Stream (aka the PDB Stream)
      • The PDB TPI and IPI Streams
      • The PDB DBI (Debug Info) Stream
      • The Module Information Stream
      • The PDB Public Symbol Stream
      • The PDB Global Symbol Stream
      • The PDB Serialized Hash Table Format
      • Introduction
      • On-Disk Format
      • Present and Deleted Bit Vectors
      • CodeView Symbol Records
      • CodeView Type Records
    • Garbage Collection with LLVM
    • Garbage Collection Safepoints in LLVM
    • libFuzzer – a library for coverage-guided fuzz testing.
    • Fuzzing LLVM libraries and tools
    • LLVM Language Reference Manual
    • LLVM IR Undefined Behavior (UB) Manual
    • Design and Usage of the InAlloca Attribute
    • LLVM Bitcode File Format
    • Machine IR (MIR) Format Reference Manual
    • Global Instruction Selection
      • Generic Machine IR
      • Generic Opcodes
      • MIR Patterns in TableGen
      • Core Pipeline
      • Porting GlobalISel to A New Target
      • Resources
      • IRTranslator
      • Legalizer
      • RegBankSelect
      • InstructionSelect
      • Known Bits Analysis
    • Convergent Operation Semantics
    • LLVM Testing Infrastructure Guide
      • test-suite Guide
    • GWP-ASan
    • XRay Instrumentation
    • Debugging with XRay
    • FaultMaps and implicit checks
    • LLVM Atomic Instructions and Concurrency Guide
    • Exception Handling in LLVM
    • LLVM Extensions
    • How to set up LLVM-style RTTI for your class hierarchy
    • LLVM Block Frequency Terminology
    • LLVM Branch Weight Metadata
    • The Often Misunderstood GEP Instruction
    • Scudo Hardened Allocator
    • Memory Model Relaxation Annotations
    • MemTagSanitizer
    • Dependence Graphs in LLVM
    • Speculative Load Hardening
    • Segmented Stacks in LLVM
    • LLVM’s Optional Rich Disassembly Output
    • Stack maps and patch points in LLVM
    • Coroutines in LLVM
    • Pointer Authentication
    • YAML I/O
    • Convergence And Uniformity
    • Machine Learning - Guided Optimization (MLGO)
    • Content Addressable Storage
    • LLVM CI Best Practices
    • LLVM AI Tool Use Policy
    • .llvm.callgraph Section Layout
    • LLVM Interface Export Annotations
    • LLVM PC Sections Metadata
    • LLVM Qualification Group
    • LLVM Security Response Group
    • LLVM Security Group Transparency Reports
    • System Library
    • Code Transformation Metadata
    • Type Metadata
    • XRay Flight Data Recorder Trace Format
  • User Guides
    • How To Build On ARM
    • How To Build Clang and LLVM with Profile-Guided Optimizations
    • How to cross-compile Clang/LLVM using Clang/LLVM
    • LLVM Code Coverage Mapping Format
    • Control Flow Verification Tool Design Document
    • Building a Distribution of LLVM
    • Building LLVM with CMake
    • A guide to Dockerfiles for building LLVM
    • Support Library
    • Advanced Build Configurations
    • Writing an LLVM Pass
    • Writing an LLVM Pass (legacy PM version)
    • LLVM’s Analysis and Transform Passes
      • KernelInfo
      • Loop Fusion in LLVM
    • Stack Safety Analysis
    • MergeFunctions pass, how it works
    • LLVM Alias Analysis Infrastructure
    • MemorySSA
    • MemProf: Memory Profiling for LLVM
    • LLVM Loop Terminology (and Canonical Forms)
    • LLVM Cycle Terminology
    • Auto-Vectorization in LLVM
      • Vectorization Plan
      • The Sandbox Vectorizer
    • LLVM Link Time Optimization: Design and Implementation
    • DTLTO
    • The LLVM gold plugin
    • Remarks
    • Source Level Debugging with LLVM
      • Debug Info Assignment Tracking
    • How to Update Debug Info: A Guide for LLVM Pass Authors
    • The LLVM Instrumentor Pass
    • Instruction referencing for debug info
    • Debug info migration: From intrinsics to records
    • Key Instructions debug info in LLVM and Clang
    • Instrumentation Profile Format
    • InstCombine contributor guide
    • Writing an LLVM Backend
      • How To Use Instruction Mappings
    • The LLVM Target-Independent Code Generator
    • TableGen Overview
      • TableGen BackEnds
      • 1 TableGen Backend Developer’s Guide
      • 1 TableGen Programmer’s Reference
    • MCJIT Design and Implementation
    • ORC Design and Implementation
    • JITLink and ORC’s ObjectLinkingLayer
    • Debugging JIT-ed Code
    • CommandLine 2.0 Library Manual
    • Extending LLVM: Adding instructions, intrinsics, types, etc.
    • How To Add A Constrained Floating-Point Intrinsic
    • How to build Windows Itanium applications.
    • How to Cross Compile Compiler-rt Builtins For Arm
    • Using ARM NEON instructions in big-endian mode
    • Support for AArch64 Scalable Matrix Extension in LLVM
    • Compiling CUDA with clang
    • User Guide for NVPTX Back-end
    • User Guide for AMDGPU Backend
      • Syntax of GFX7 Instructions
        • attr
        • dst
        • hwreg
        • imm16
        • imm16
        • label
        • m
        • msg
        • opt
        • opt
        • param
        • sbase
        • sbase
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm32
        • simm32
        • soffset
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • srsrc
        • ssamp
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • tgt
        • Type Deviation
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata0
        • vdata0
        • vdata1
        • vdata1
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • waitcnt
      • Syntax of GFX8 Instructions
        • attr
        • dst
        • hwreg
        • imask
        • imm16
        • imm16
        • label
        • m
        • m
        • msg
        • opt
        • opt
        • param
        • probe
        • sbase
        • sbase
        • sdata
        • sdata
        • sdata
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm32
        • simm32
        • simm32
        • soffset
        • soffset
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • srsrc
        • ssamp
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • tgt
        • Type Deviation
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata0
        • vdata0
        • vdata1
        • vdata1
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • waitcnt
      • Syntax of Core GFX9 Instructions
        • attr
        • dst
        • hwreg
        • imask
        • imm16
        • imm16
        • label
        • m
        • m
        • msg
        • opt
        • opt
        • param
        • probe
        • saddr
        • saddr
        • sbase
        • sbase
        • sbase
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm32
        • simm32
        • simm32
        • soffset
        • soffset
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • srsrc
        • ssamp
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • tgt
        • Type Deviation
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata0
        • vdata0
        • vdata1
        • vdata1
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • waitcnt
      • Syntax of gfx900, gfx902, gfx909 and gfx90c Instructions
        • FX Operand
        • m
        • src
        • src
        • vdst
      • Syntax of gfx904 Instructions
        • FX Operand
        • m
        • src
        • src
        • vdst
      • Syntax of gfx906 Instructions
        • FX Operand
        • m
        • m
        • src
        • src
        • src
        • src
        • src
        • Type Deviation
        • vdst
        • vsrc
      • Syntax of gfx908 Instructions
        • FX Operand
        • m
        • m
        • saddr
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • Type Deviation
        • vaddr
        • vaddr
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
      • Syntax of gfx90a Instructions
        • dst
        • FX Operand
        • hwreg
        • imask
        • imm16
        • imm16
        • label
        • m
        • m
        • msg
        • opt
        • opt
        • probe
        • saddr
        • saddr
        • sbase
        • sbase
        • sbase
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm32
        • simm32
        • simm32
        • soffset
        • soffset
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • srsrc
        • ssamp
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • Type Deviation
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata0
        • vdata0
        • vdata1
        • vdata1
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • waitcnt
      • Syntax of gfx942 Instructions
        • dst
        • dst
        • FX Operand
        • hwreg
        • imask
        • imm16
        • imm16
        • label
        • m
        • m
        • msg
        • opt
        • opt
        • probe
        • saddr
        • saddr
        • sbase
        • sbase
        • sbase
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm32
        • simm32
        • simm32
        • soffset
        • soffset
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • Type Deviation
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata0
        • vdata0
        • vdata1
        • vdata1
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • waitcnt
      • Syntax of GFX950 Instructions
        • addr
        • addr
        • data
        • data
        • data
        • data
        • data0
        • data0
        • data0
        • data0
        • data1
        • data1
        • literal
        • literal
        • literal
        • saddr
        • saddr
        • sbase
        • sbase
        • sbase
        • scale_src0
        • scale_src1
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm16
        • simm16
        • simm16
        • simm16
        • simm16
        • soffset
        • soffset
        • soffset
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src1
        • src1
        • src1
        • src1
        • src1
        • src1
        • src1
        • src1
        • src2
        • src2
        • src2
        • src2
        • src2
        • src2
        • src2
        • src2
        • src2
        • srsrc
        • ssrc0
        • ssrc0
        • ssrc0
        • ssrc0
        • ssrc0
        • ssrc1
        • ssrc1
        • ssrc1
        • ssrc1
        • vaddr
        • vcc
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc0
        • vsrc0
        • vsrc0
        • vsrc0
        • vsrc0
        • vsrc0
        • vsrc1
        • vsrc1
        • vsrc1
      • Syntax of GFX10 RDNA1 Instructions
        • attr
        • dst
        • FX Operand
        • hwreg
        • imm16
        • imm16
        • label
        • m
        • m
        • msg
        • opt
        • opt
        • param
        • probe
        • saddr
        • saddr
        • sbase
        • sbase
        • sbase
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm32
        • simm32
        • simm32
        • soffset
        • soffset
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • srsrc
        • ssamp
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • tgt
        • Type Deviation
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata0
        • vdata0
        • vdata1
        • vdata1
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • waitcnt
        • waitcnt_depctr
      • Syntax of gfx1011 and gfx1012 Instructions
        • src
        • src
        • src
        • src
        • Type Deviation
        • vdst
        • vsrc
      • Syntax of gfx1013 Instructions
        • srsrc
        • srsrc
        • vaddr
        • vaddr
        • vdst
        • vdst
      • Syntax of GFX10 RDNA2 Instructions
        • attr
        • dst
        • FX Operand
        • hwreg
        • imm16
        • imm16
        • label
        • m
        • m
        • msg
        • opt
        • opt
        • param
        • saddr
        • saddr
        • saddr
        • sbase
        • sbase
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm32
        • simm32
        • simm32
        • soffset
        • soffset
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • srsrc
        • srsrc
        • ssamp
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • tgt
        • Type Deviation
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata0
        • vdata0
        • vdata1
        • vdata1
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • waitcnt
        • waitcnt_depctr
      • Syntax of GFX11 Instructions
        • attr
        • delay
        • dst
        • FX Operand
        • hwreg
        • imm16
        • imm16
        • label
        • m
        • m
        • msg
        • msg
        • opt
        • saddr
        • saddr
        • saddr
        • sbase
        • sbase
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm32
        • simm32
        • simm32
        • soffset
        • soffset
        • soffset
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • src
        • srsrc
        • srsrc
        • srsrc
        • ssamp
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • ssrc
        • tgt
        • Type Deviation
        • Type Deviation
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata0
        • vdata0
        • vdata1
        • vdata1
        • vdata1
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vij
        • vparam
        • vparam0
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • waitcnt
        • waitcnt_depctr
      • Syntax of GFX12 Instructions
        • addr
        • attr
        • data0
        • data0
        • data0
        • data0
        • data1
        • data1
        • data1
        • data1
        • ioffset
        • literal
        • literal
        • literal
        • literal
        • rsrc
        • rsrc
        • saddr
        • saddr
        • samp
        • sbase
        • sbase
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdata
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • sdst
        • simm16
        • simm16
        • simm16
        • simm16
        • simm16
        • simm16
        • simm16
        • simm16
        • soffset
        • soffset
        • soffset
        • src0
        • src0
        • src0
        • src0
        • src0
        • src0
        • src1
        • src1
        • src1
        • src1
        • src1
        • src1
        • src1
        • src1
        • src2
        • src2
        • src2
        • src2
        • src2
        • src2
        • src2
        • src2
        • srcx0
        • srcy0
        • ssrc0
        • ssrc0
        • ssrc0
        • ssrc0
        • ssrc0
        • ssrc0
        • ssrc1
        • ssrc1
        • tgt
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vaddr
        • vcc
        • vdata
        • vdata
        • vdata
        • vdata
        • vdata
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdst
        • vdstx
        • vdsty
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc
        • vsrc0
        • vsrc1
        • vsrc1
        • vsrc2
        • vsrc3
        • vsrcx1
        • vsrcy1
      • Syntax of AMDGPU Instruction Modifiers
      • Syntax of AMDGPU Instruction Operands
      • AMDGPU Instruction Syntax
      • AMDGPU Instructions Notation
      • DWARF Extensions For Heterogeneous Debugging
      • Allow Location Descriptions on the DWARF Expression Stack
      • Developer Guideline for AMDGPU
    • AMDGPU Asynchronous Operations
    • AMDGPU DMA Operations
    • AMDGPU Execution Synchronization
    • AMDGPU Memory Model
    • User Guide for SPIR-V Target
    • User Guide for the DirectX Target
      • DirectX Container
      • Architecture and Design of DXIL Support in LLVM
      • Specification of DXIL Operations using TableGen Representation
      • DXIL Resource Handling
      • Root Signatures
    • User Guide for RISC-V Target
    • RISC-V Vector Extension
    • Scheduling Information for RISC-V VCIX Instructions
    • Sandbox IR: A transactional layer over LLVM IR
    • Telemetry framework in LLVM
    • Lightweight Fault Isolation (LFI) in LLVM
    • LLVM Admin Tasks
    • Benchmarking tips
    • CMake Primer
    • LLVM Community Code of Conduct
    • FatLTO
    • LLVM GitHub User Guide
    • Markdown Quickstart Template
    • Misexpect
    • Opaque Pointers
    • Using the New Pass Manager
    • LLVM CoC Incident Reporting Guide
    • Response Guide
    • TableGen Fundamentals
    • yaml2obj
  • Discourse Migration Guide
  • Getting Involved
    • Contributing to LLVM
    • LLVM Developer Policy
    • LLVM Code-Review Policy and Practices
    • LLVM Community Support Policy
    • Sphinx Quickstart Template
    • How to submit an LLVM bug report
    • LLVM Bug Life Cycle
    • LLVM Coding Standards
    • Bisecting LLVM code
    • Policies on git repositories
    • Creating an LLVM Project
    • How To Release LLVM To The Public
    • How To Validate a New Release
    • How To Add Your Build Configuration To LLVM Buildbot Infrastructure
    • LLVM 23.0.0git Release Notes
    • How to start LLVM Social in your town
    • Moving LLVM Projects to GitHub
    • Bugpoint Redesign
    • Test-Suite Extensions
    • Variable Names Plan
    • Vector Predication Roadmap
  • Request For Comment (RFC) process
  • Project Governance
Back to top
View this page
Edit this page

LLVM Link Time Optimization: Design and Implementation¶

  • Description

  • Design Philosophy

    • Example of link time optimization

    • Alternative Approaches

  • Multi-phase communication between libLTO and linker

    • Phase 1 : Read LLVM Bitcode Files

    • Phase 2 : Symbol Resolution

    • Phase 3 : Optimize Bitcode Files

    • Phase 4 : Symbol Resolution after optimization

  • libLTO

    • lto_module_t

    • lto_code_gen_t

Description¶

LLVM features powerful intermodular optimizations which can be used at link time. Link Time Optimization (LTO) is another name for intermodular optimization when performed during the link stage. This document describes the interface and design between the LTO optimizer and the linker.

Design Philosophy¶

The LLVM Link Time Optimizer provides complete transparency, while doing intermodular optimization, in the compiler tool chain. Its main goal is to let the developer take advantage of intermodular optimizations without making any significant changes to the developer’s makefiles or build system. This is achieved through tight integration with the linker. In this model, the linker treats LLVM bitcode files like native object files and allows mixing and matching among them. The linker uses libLTO, a shared object, to handle LLVM bitcode files. This tight integration between the linker and LLVM optimizer helps to do optimizations that are not possible in other models. The linker input allows the optimizer to avoid relying on conservative escape analysis.

Example of link time optimization¶

The following example illustrates the advantages of LTO’s integrated approach and clean interface. This example requires a system linker which supports LTO through the interface described in this document. Here, clang transparently invokes system linker.

  • Input source file a.c is compiled into LLVM bitcode form.

  • Input source file main.c is compiled into native object code.

--- a.h ---
extern int foo1(void);
extern void foo2(void);
extern void foo4(void);

--- a.c ---
#include "a.h"

static signed int i = 0;

void foo2(void) {
  i = -1;
}

static int foo3() {
  foo4();
  return 10;
}

int foo1(void) {
  int data = 0;

  if (i < 0)
    data = foo3();

  data = data + 42;
  return data;
}

--- main.c ---
#include <stdio.h>
#include "a.h"

void foo4(void) {
  printf("Hi\n");
}

int main() {
  return foo1();
}

To compile, run:

% clang -flto -c a.c -o a.o        # <-- a.o is LLVM bitcode file
% clang -c main.c -o main.o        # <-- main.o is native object file
% clang -flto a.o main.o -o main   # <-- standard link command with -flto
  • In this example, the linker recognizes that foo2() is an externally visible symbol defined in LLVM bitcode file. The linker completes its usual symbol resolution pass and finds that foo2() is not used anywhere. This information is used by the LLVM optimizer and it removes foo2().

  • As soon as foo2() is removed, the optimizer recognizes that condition i < 0 is always false, which means foo3() is never used. Hence, the optimizer also removes foo3().

  • And this in turn, enables linker to remove foo4().

This example illustrates the advantage of tight integration with the linker. Here, the optimizer can not remove foo3() without the linker’s input.

Alternative Approaches¶

Compiler driver invokes link time optimizer separately.

In this model the link time optimizer is not able to take advantage of information collected during the linker’s normal symbol resolution phase. In the above example, the optimizer can not remove foo2() without the linker’s input because it is externally visible. This in turn prohibits the optimizer from removing foo3().

Use separate tool to collect symbol information from all object files.

In this model, a new, separate, tool or library replicates the linker’s capability to collect information for link time optimization. Not only is this code duplication difficult to justify, but it also has several other disadvantages. For example, the linking semantics and the features provided by the linker on various platform are not unique. This means, this new tool needs to support all such features and platforms in one super tool or a separate tool per platform is required. This increases maintenance cost for link time optimizer significantly, which is not necessary. This approach also requires staying synchronized with linker developments on various platforms, which is not the main focus of the link time optimizer. Finally, this approach increases end user’s build time due to the duplication of work done by this separate tool and the linker itself.

Multi-phase communication between libLTO and linker¶

The linker collects information about symbol definitions and uses in various link objects which is more accurate than any information collected by other tools during typical build cycles. The linker collects this information by looking at the definitions and uses of symbols in native .o files and using symbol visibility information. The linker also uses user-supplied information, such as a list of exported symbols. LLVM optimizer collects control flow information, data flow information and knows much more about program structure from the optimizer’s point of view. Our goal is to take advantage of tight integration between the linker and the optimizer by sharing this information during various linking phases.

Phase 1 : Read LLVM Bitcode Files¶

The linker first reads all object files in natural order and collects symbol information. This includes native object files as well as LLVM bitcode files. To minimize the cost to the linker in the case that all .o files are native object files, the linker only calls lto_module_create() when a supplied object file is found to not be a native object file. If lto_module_create() returns that the file is an LLVM bitcode file, the linker then iterates over the module using lto_module_get_symbol_name() and lto_module_get_symbol_attribute() to get all symbols defined and referenced. This information is added to the linker’s global symbol table.

The lto* functions are all implemented in a shared object libLTO. This allows the LLVM LTO code to be updated independently of the linker tool. On platforms that support it, the shared object is lazily loaded.

Phase 2 : Symbol Resolution¶

In this stage, the linker resolves symbols using global symbol table. It may report undefined symbol errors, read archive members, replace weak symbols, etc. The linker is able to do this seamlessly even though it does not know the exact content of input LLVM bitcode files. If dead code stripping is enabled then the linker collects the list of live symbols.

Phase 3 : Optimize Bitcode Files¶

After symbol resolution, the linker tells the LTO shared object which symbols are needed by native object files. In the example above, the linker reports that only foo1() is used by native object files using lto_codegen_add_must_preserve_symbol(). Next the linker invokes the LLVM optimizer and code generators using lto_codegen_compile() which returns a native object file created by merging the LLVM bitcode files and applying various optimization passes.

Phase 4 : Symbol Resolution after optimization¶

In this phase, the linker reads optimized a native object file and updates the internal global symbol table to reflect any changes. The linker also collects information about any changes in use of external symbols by LLVM bitcode files. In the example above, the linker notes that foo4() is not used any more. If dead code stripping is enabled then the linker refreshes the live symbol information appropriately and performs dead code stripping.

After this phase, the linker continues linking as if it never saw LLVM bitcode files.

libLTO¶

libLTO is a shared object that is part of the LLVM tools, and is intended for use by a linker. libLTO provides an abstract C interface to use the LLVM interprocedural optimizer without exposing details of LLVM’s internals. The intention is to keep the interface as stable as possible even when the LLVM optimizer continues to evolve. It should even be possible for a completely different compilation technology to provide a different libLTO that works with their object files and the standard linker tool.

lto_module_t¶

A non-native object file is handled via an lto_module_t. The following functions allow the linker to check if a file (on disk or in a memory buffer) is a file which libLTO can process:

lto_module_is_object_file(const char*)
lto_module_is_object_file_for_target(const char*, const char*)
lto_module_is_object_file_in_memory(const void*, size_t)
lto_module_is_object_file_in_memory_for_target(const void*, size_t, const char*)

If the object file can be processed by libLTO, the linker creates a lto_module_t by using one of:

lto_module_create(const char*)
lto_module_create_from_memory(const void*, size_t)

and when done, the handle is released via

lto_module_dispose(lto_module_t)

The linker can introspect the non-native object file by getting the number of symbols and getting the name and attributes of each symbol via:

lto_module_get_num_symbols(lto_module_t)
lto_module_get_symbol_name(lto_module_t, unsigned int)
lto_module_get_symbol_attribute(lto_module_t, unsigned int)

The attributes of a symbol include the alignment, visibility, and kind.

Tools working with object files on Darwin (e.g. lipo) may need to know properties like the CPU type:

lto_module_get_macho_cputype(lto_module_t mod, unsigned int *out_cputype, unsigned int *out_cpusubtype)

lto_code_gen_t¶

Once the linker has loaded each non-native object files into an lto_module_t, it can request libLTO to process them all and generate a native object file. This is done in a couple of steps. First, a code generator is created with:

lto_codegen_create()

Then, each non-native object file is added to the code generator with:

lto_codegen_add_module(lto_code_gen_t, lto_module_t)

The linker then has the option of setting some codegen options. Whether or not to generate DWARF debug info is set with:

lto_codegen_set_debug_model(lto_code_gen_t)

which kind of position independence is set with:

lto_codegen_set_pic_model(lto_code_gen_t)

And each symbol that is referenced by a native object file or otherwise must not be optimized away is set with:

lto_codegen_add_must_preserve_symbol(lto_code_gen_t, const char*)

After all these settings are done, the linker requests that a native object file be created from the modules with the settings using:

lto_codegen_compile(lto_code_gen_t, size*)

which returns a pointer to a buffer containing the generated native object file. The linker then parses that and links it with the rest of the native object files.

Next
DTLTO
Previous
The Sandbox Vectorizer
Copyright © 2003-2026, LLVM Project
Made with Sphinx and @pradyunsg's Furo
Last updated on 2026-07-09
On this page
  • LLVM Link Time Optimization: Design and Implementation
    • Description
    • Design Philosophy
      • Example of link time optimization
      • Alternative Approaches
    • Multi-phase communication between libLTO and linker
      • Phase 1 : Read LLVM Bitcode Files
      • Phase 2 : Symbol Resolution
      • Phase 3 : Optimize Bitcode Files
      • Phase 4 : Symbol Resolution after optimization
    • libLTO
      • lto_module_t
      • lto_code_gen_t