Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix B: LLVM Features (Legacy)

Note: Starting from the version after v0.0.1-beta.3, the Inference compiler no longer uses LLVM. WebAssembly is generated directly via wasm-encoder. This appendix is preserved as a reference for users on older versions.

LLVM FeatureStageDescription
-mcpu=mvpCompilationTarget WebAssembly 1.0 baseline without post-MVP features.
-mattr=+<feature>CompilationMachine Attributes. Enables + or disables - specific CPU features
mattr: sign-extCompilationEnable Sign-Extension Operators. Enables instructions that make converting small signed integers (like 8-bit or 16-bit int) to larger ones much faster.
mattr: bulk-memoryCompilationEnables instructions like memory.copy (like memcpy) and memory.fill (like memset). Without this, the compiler has to generate slow loops to copy data byte-by-byte.
mattr: mutable-globalsCompilationAllows the Wasm module to import/export global variables that can be changed (mutated). This is often required for setting up the "Stack Pointer" for managing memory manually or linking dynamic libraries.
mattr: multivalueCompilationAllows a Wasm function to return multiple values natively (e.g., returning two integers on the stack), and allows blocks/loops to have inputs.
mattr: reference-typesCompilationAllows Wasm to hold "opaque" references to host objects (like a JavaScript object or a DOM node) using the externref type. It is essential for Garbage Collection integration.
mattr: tail-callCompilationAdds return_call instructions. If a function ends by calling another function, it reuses the current stack frame instead of creating a new one.
mattr: extended-constCompilationStandard Wasm global variables can only be initialized with simple constants (e.g., 5). This feature allows basic math in initializers, like global x = 5 + 3.
mattr: simd128CompilationSingle Instruction, Multiple Data. It allows the CPU to process 128 bits of data (e.g., four 32-bit integers) in a single clock cycle.
-filetype=objCompilationOutput an Object File.
-flavor wasmLinking (lld)Execute WebAssembly linking.
--no-entryLinking (lld)Do not expect a main (_start) function. Useful for libraries or modules that will be invoked by a host environment.
--export=mainLinking (lld)Explicitly export the main function from the Wasm module. Necessary for standalone executables.
--export-dynamicLinking (lld)Instead of picking specific functions to export, this blindly exports every global symbol.
--gc-sectionsLinking (lld)This is Dead Code Elimination.
-z stack-size=<size>Linking (lld)Sets the size of the stack for the Wasm module.
--stack-firstLinking (lld)Places the stack at the beginning of linear memory (before the Data/Heap). Usually, Wasm places static data (strings, globals) at the bottom (address 0), and the stack starts after that, growing upwards (or downwards towards data). Stack-First Layout: Places the Stack at the very beginning of memory (starting near 0) and the Data/Heap follows it. Since the stack grows downwards (towards address 0), if the program overflows the stack, it hits address 0 and causes a Trap (crash) immediately. Without this, a stack overflow might silently overwrite static data (heap corruption).