DOC PREVIEW
CMU CS 15745 - Lecture 3

This preview shows page 1-2-3-4 out of 12 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1The LLVM CompilerThe LLVM CompilerFramework and InfrastructureFramework and Infrastructure15-745: Optimizing Compilers15-745: Optimizing CompilersDavid David KoesKoes1/22/20081/22/2008Substantial portions courtesy Chris Lattner and Vikram Adve2LLVM Compiler SystemLLVM Compiler SystemThe LLVM Compiler InfrastructureThe LLVM Compiler InfrastructureProvides reusable components for building compilersProvides reusable components for building compilersReduce the time/cost to build a new compilerReduce the time/cost to build a new compilerBuild static compilers, Build static compilers, JITsJITs, trace-based optimizers, ..., trace-based optimizers, ...The LLVM Compiler FrameworkThe LLVM Compiler FrameworkEnd-to-end compilers using the LLVM infrastructureEnd-to-end compilers using the LLVM infrastructureC and C++ C and C++ gcc frontendgcc frontendBackends Backends for C, X86, for C, X86, SparcSparc, PowerPC, Alpha, Arm,, PowerPC, Alpha, Arm,Thumb, IA-64Thumb, IA-64……3Three primary LLVM componentsThree primary LLVM componentsThe LLVM The LLVM Virtual Instruction SetVirtual Instruction SetThe common language- and target-independent IRThe common language- and target-independent IRInternal (IR) and external (persistent) representationInternal (IR) and external (persistent) representationA collection of well-integrated librariesA collection of well-integrated librariesAnalyses, optimizations, code generators, JITAnalyses, optimizations, code generators, JITcompiler, garbage collection support, profiling, compiler, garbage collection support, profiling, ……A collection of tools built from the librariesA collection of tools built from the librariesAssemblers, automatic debugger, linker, codeAssemblers, automatic debugger, linker, codegenerator, compiler driver, modular optimizer, generator, compiler driver, modular optimizer, ……4Tutorial OverviewTutorial OverviewIntroduction to the running exampleIntroduction to the running exampleLLVM C/C++ Compiler OverviewLLVM C/C++ Compiler OverviewHigh-level view of an example LLVM compilerHigh-level view of an example LLVM compilerThe LLVM Virtual Instruction SetThe LLVM Virtual Instruction SetIR overview and type-systemIR overview and type-systemLLVM C++ IR and important APILLVM C++ IR and important API’’ssBasics, Basics, PassManagerPassManager, dataflow, , dataflow, ArgPromotionArgPromotionImportant LLVM ToolsImportant LLVM Tools25Running example: Running example: arg arg promotionpromotionConsider use of by-reference parameters:Consider use of by-reference parameters:int int callee(constcallee(const int &X) { int &X) { return X+1; return X+1;}}int caller() {int caller() { return callee(4); return callee(4);}}int int callee(constcallee(const int *X) { int *X) { return *X+1; return *X+1; // memory load// memory load}}int caller() {int caller() { int int tmptmp; ; // stack object// stack object tmptmp = 4; = 4; // memory store// memory store return return callee(&tmpcallee(&tmp););}}compiles toEliminated load in calleeEliminated store in callerEliminated stack slot for ‘tmp’int int callee(intcallee(int X) { X) { return X+1; return X+1;}}int caller() {int caller() { return callee(4); return callee(4);}}We want:We want:6Why is this hard?Why is this hard?Requires interprocedural analysis:Requires interprocedural analysis:Must change the prototype of the Must change the prototype of the calleecalleeMust update all call sites Must update all call sites  we must we must knowknow all callers all callersWhat about callers outside the translation unit?What about callers outside the translation unit?Requires alias analysis:Requires alias analysis:Reference could alias other pointers in Reference could alias other pointers in calleecalleeMust know that loaded value doesnMust know that loaded value doesn’’t change fromt change fromfunction entry to the loadfunction entry to the loadMust know the pointer is not being stored throughMust know the pointer is not being stored throughReference might not be to a stack object!Reference might not be to a stack object!7Tutorial OverviewTutorial OverviewIntroduction to the running exampleIntroduction to the running exampleLLVM C/C++ Compiler OverviewLLVM C/C++ Compiler OverviewHigh-level view of an example LLVM compilerHigh-level view of an example LLVM compilerThe LLVM Virtual Instruction SetThe LLVM Virtual Instruction SetIR overview and type-systemIR overview and type-systemLLVM C++ IR and important APILLVM C++ IR and important API’’ssBasics, Basics, PassManagerPassManager, dataflow, , dataflow, ArgPromotionArgPromotionImportant LLVM ToolsImportant LLVM Tools8The LLVM C/C++ CompilerThe LLVM C/C++ CompilerFrom the high level, it is a standard compiler:From the high level, it is a standard compiler:Compatible with standard Compatible with standard makefilesmakefilesUses GCCUses GCC 4.2 C and C++ parser4.2 C and C++ parserGenerates nativeGenerates native executables/object files/assemblyexecutables/object files/assemblyDistinguishing features:Distinguishing features:Uses LLVM optimizers, not GCC optimizersUses LLVM optimizers, not GCC optimizersPass Pass -emit-llvm -emit-llvm to outputto output LLVM IRLLVM IR-S: human readable -S: human readable ““assemblyassembly””-c-c: efficient: efficient ““bitcodebitcode”” binary binary39Looking into events at compile-timeLooking into events at compile-timellvm-gcc/llvm-g++ -O -SC/C++ file assemblyGENERICGIMPLE(tree-ssa)LLVM IRMachineCode IR>50 LLVM Analysis & Optimization Passes:Dead Global Elimination, IP Constant Propagation, DeadArgument Elimination, Inlining, Reassociation, LICM, LoopOpts, Memory Promotion, Dead Store Elimination, ADCE, …IR-emit-llvmLLVMasm10Looking into events at link-timeLooking into events at link-timeLLVM bitcode .o fileLLVM bitcode .o filellvm-ldexecutableLLVMLinkerLink-timeOptimizer.bc file for LLVM JIT>30 LLVM Analysis &Optimization PassesOptionally “internalizes”:marks most functions asinternal, to improve IPOPerfect place for argumentpromotion optimization!Native executable-native11Goals of the compiler designGoals of the compiler


View Full Document

CMU CS 15745 - Lecture 3

Documents in this Course
Lecture

Lecture

14 pages

Lecture

Lecture

19 pages

Lecture

Lecture

8 pages

Lecture

Lecture

5 pages

Lecture

Lecture

6 pages

lecture

lecture

17 pages

Lecture

Lecture

17 pages

Lecture

Lecture

18 pages

lecture

lecture

14 pages

lecture

lecture

8 pages

lecture

lecture

5 pages

Lecture

Lecture

19 pages

lecture

lecture

10 pages

Lecture

Lecture

20 pages

Lecture

Lecture

8 pages

Lecture

Lecture

7 pages

lecture

lecture

59 pages

Lecture

Lecture

10 pages

Task 2

Task 2

2 pages

Handout

Handout

18 pages

Load more
Download Lecture 3
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 3 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 3 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?