LLVMLLVM Compiler SystemThree primary LLVM componentsThe LLVM C/C++ CompilerThe LLVM C/C++ Compiler (cont)Looking into events at compile-timeExample Intermediate RepresentationCurrent Uses/Projects made with LLVMFuture of LLVMLLVMLLVMDeveloped by University of Developed by University of Illinois at Urbana-Champaign Illinois at Urbana-Champaign CIS deptCIS deptCisc 471Cisc 471Matthew WarnerMatthew WarnerLLVM Compiler SystemLLVM Compiler SystemLLVM = Low Level Virtual Machine LLVM = Low Level Virtual Machine The LLVM Compiler InfrastructureThe LLVM Compiler InfrastructureProvides reusable components for building Provides reusable components for building compilerscompilersReduce the time/cost to build a new compilerReduce the time/cost to build a new compilerBuild static compilers, JITs, trace-based Build static compilers, JITs, trace-based optimizers, ...optimizers, ...The LLVM Compiler FrameworkThe LLVM Compiler FrameworkEnd-to-end compilers using the LLVM infrastructureEnd-to-end compilers using the LLVM infrastructureC and C++ are robust and aggressive:C and C++ are robust and aggressive:Java, Scheme and others are in developmentJava, Scheme and others are in developmentEmit C code or native code for X86, Sparc, PowerPCEmit C code or native code for X86, Sparc, PowerPCThree primary LLVM Three primary LLVM componentscomponentsThe LLVM The LLVM Virtual Instruction SetVirtual Instruction SetThe common language- and target-independent IRThe common language- and target-independent IRInternal (IR) and external (persistent) Internal (IR) and external (persistent) representationrepresentationA collection of well-integrated librariesA collection of well-integrated librariesAnalyses, optimizations, code generators, JIT Analyses, optimizations, code generators, JIT compiler, garbage collection support, profiling, …compiler, garbage collection support, profiling, …A collection of tools built from the librariesA collection of tools built from the librariesAssemblers, automatic debugger, linker, code Assemblers, automatic debugger, linker, code generator, compiler driver, modular optimizer, …generator, compiler driver, modular optimizer, …The LLVM C/C++ The LLVM C/C++ CompilerCompilerFrom the high level, it is a standard compiler:From the high level, it is a standard compiler:Compatible with standard makefilesCompatible with standard makefilesUses GCC 3.4 C and C++ parserUses GCC 3.4 C and C++ parserDistinguishing features:Distinguishing features:Uses LLVM optimizers, not GCC optimizersUses LLVM optimizers, not GCC optimizers.o files contain LLVM IR/bytecode, not machine code.o files contain LLVM IR/bytecode, not machine codeExecutable can be bytecode (JIT’d) or machine codeExecutable can be bytecode (JIT’d) or machine codellvmg++llvmgccC fileC++ file.o file.o filellvm linker executableCompile Time Link TimeThe LLVM C/C++ Compiler The LLVM C/C++ Compiler (cont)(cont)Standard compiler organization, which uses LLVM as midlevel IR:– Language specific front-end lowers code to LLVM IR– Language/target independent optimizers improve code– Code generator converts LLVM code to target (e.g. IA64) codeLooking into events at Looking into events at compile-timecompile-timellvmgccC file .o file llvmg++C++ file .o fileModified version of G++Emits LLVM IR as text fileLowers C++ AST to LLVMModified version of GCCEmits LLVM IR as text fileLowers C AST to LLVMLLVM IR ParserLLVM Verifier40 LLVM Analysis & Optimization PassesLLVM .bc File WriterC to LLVM FrontendCompile-time OptimizerC++ to LLVM FrontendCompile-time Optimizer“cc1” “cc1plus” “gccas”“gccas”Dead Global Elimination, IP Constant Propagation, Dead Argument Elimination, Inlining, Reassociation, LICM, Loop Opts, Memory Promotion, Dead Store Elimination, ADCE, …Example Intermediate Example Intermediate RepresentationRepresentation; Declare the string constant as a global constant...; Declare the string constant as a global [email protected]@.LC0 = = internalinternal constant [13 x i8] c"hello world\0A\00" constant [13 x i8] c"hello world\0A\00" ; [13 x i8]*; [13 x i8]* ; External declaration of the puts function; External declaration of the puts functiondeclare i32 @puts(i8 *) declare i32 @puts(i8 *) ; i32(i8 *)*; i32(i8 *)* ; Definition of main function; Definition of main functiondefine i32 @main() { define i32 @main() { ; i32()*; i32()* ; Convert [13x i8 ]* to i8 *...; Convert [13x i8 ]* to i8 *... %cast210 = getelementptr %cast210 = getelementptr [13 x i8 ]* @.LC0, i64 0, i64 0 [13 x i8 ]* @.LC0, i64 0, i64 0 ; i8 *; i8 * ; Call puts function to write out the string to stdout...; Call puts function to write out the string to stdout... call i32 @puts(i8 * %cast210) call i32 @puts(i8 * %cast210)ret i32 0 ret i32 0 } }Current Uses/Projects made Current Uses/Projects made with LLVMwith LLVMRegister Allocation solving by Using Register Allocation solving by Using Puzzle Solving techniquesPuzzle Solving techniquesScheme compilerScheme compilerJIT Compiler for LLVM bytecodeJIT Compiler for LLVM bytecodeFuture of LLVMFuture of LLVMCurrently a partial version of the Currently a partial version of the Java compiler exists and need to be Java compiler exists and need to be extendedextendedImprove optimizations for Improve optimizations for performanceperformanceMost of LLVM’s current optimizations Most of LLVM’s current optimizations are performance based, need are performance based, need optimizations for sizeoptimizations for
View Full Document