LLVM in Action
Explore how to compile native C code into LLVM Intermediate Representation using LLVM's Clang compiler. Understand compiler flags like -S, -O3, and -emit-llvm, how the LLVM IR is structured, and its role in generating optimized machine code for multiple architectures. This lesson helps you grasp the fundamentals of LLVM compilation relevant for WebAssembly workflows.
We'll cover the following...
In this section, let’s use LLVM’s Clang compiler to compile native code into LLVM IR. This will give a better idea of how LLVM works and will be useful for understanding how the compilers use LLVM later.
We first create a C file called sum.c with the following command:
Then we add the following code to it:
The sum.c file contains a simple sum function that takes in two unsigned integers and returns the sum of them. LLVM provides the Clang LLVM compiler to compile the C source code. In order to generate the LLVM IR, run the following command:
We provided the Clang compiler with the ...