llvm-as
Assemble LLVM assembly language into bitcode
TLDR
Assemble an IR file
Assemble an IR file and include a module hash in the produced Bitcode file
Read an IR file from stdin and assemble it
SYNOPSIS
llvm-as [options] input.ll [-o output.bc]
PARAMETERS
-o filename
Specify the output bitcode filename. If omitted, llvm-as writes to standard output.
--help
Display a summary of command-line options.
--version
Display the version of llvm-as.
--disable-verify
Disable the LLVM IR verifier. By default, llvm-as verifies the IR for correctness after parsing, which can be computationally intensive for very large files.
--debug-pass-manager
Enable debug output for the pass manager, useful for understanding optimization passes. (Less common for llvm-as itself, but a general LLVM option).
--mcpu=cpu
Specify the target CPU to generate code for. (More relevant for llc but can be passed through to underlying LLVM components).
--mtriple=triple
Specify the target triple (e.g., x86_64-unknown-linux-gnu). This defines the architecture, vendor, OS, and ABI.
DESCRIPTION
llvm-as is the LLVM assembler, a crucial component of the LLVM compilation toolchain. Its primary function is to translate human-readable LLVM assembly language code (files typically ending with .ll) into LLVM bitcode (files typically ending with .bc). LLVM bitcode is a compact, binary representation of LLVM Intermediate Representation (IR), which is suitable for further processing by other LLVM tools like optimizers (opt) or code generators (llc). This command is essential when developers or compilers generate LLVM IR in text form and need to convert it into the binary bitcode format for efficiency or compatibility with subsequent compilation steps. It acts as the inverse of llvm-dis, which disassembles bitcode back into human-readable assembly.
CAVEATS
llvm-as strictly expects valid LLVM IR text as input; it is not a general-purpose assembler for native machine code. Errors in the input LLVM IR will generally result in parsing or verification failures. The output bitcode's compatibility may depend on the LLVM version it was generated with, as the LLVM IR format evolves over time.
INPUT AND OUTPUT
llvm-as typically takes a file with a .ll extension as input, which contains LLVM assembly language. The output is a binary file with a .bc extension, representing LLVM bitcode. If no output file is specified with -o, the bitcode is written to standard output, which can then be piped to another LLVM tool.
ROLE IN THE LLVM TOOLCHAIN
In a typical compilation flow, source code (e.g., C/C++) is compiled by a front-end (like clang) into LLVM IR. This IR can be either directly in bitcode format or, in some cases, emitted as textual LLVM assembly. llvm-as is used to convert this textual assembly into bitcode, allowing it to be processed by optimizers (opt), linked with other bitcode modules (llvm-link), and finally compiled into machine code by the LLVM backend (llc).
HISTORY
llvm-as has been an integral part of the LLVM project since its early days. It was developed as a necessary utility to bridge the gap between human-readable LLVM IR (often generated by front-ends like clang in assembly form for debugging or specific transformations) and the more compact, efficient binary bitcode format required for subsequent compilation stages. Its continuous development mirrors the evolution of the LLVM IR itself, ensuring compatibility with the latest features and optimizations of the LLVM ecosystem.