2004-09-22-LCPC LLVM Tutorial
61 pages
English

2004-09-22-LCPC LLVM Tutorial

-

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
61 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

The LLVM Compiler Framework and InfrastructureChris Lattner Vikram Advelattner@cs.uiuc.edu vadve@cs.uiuc.eduhttp://llvm.cs.uiuc.edu/LCPC Tutorial: September 22, 2004AcknowledgementsUIUC Contributors: External Contributors:v Tanya Brethour v Henrik Bachv Misha Brukman v Nate Begemanv Cameron Buschardt v Jeff Cohenv John Criswell v Paolo Invernizziv Alkis Evlogimenos v Brad Jonesv Brian Gaeke v Vladimir Merzliakovv Ruchira Sasanka vPrusv Anand Shukla v Reid Spencerv Bill WendlingFunding: This work is sponsored by the NSF Next Generation Software program through grants EIA-0093426 (an NSF CAREER award) and EIA-0103756. It is also supported in part by the NSF Operating Systems and Compilers program (grant #CCR-9988482), the NSF Embedded Systems program (grant #CCR-0209202), the MARCO/DARPA Gigascale Systems Research Center (GSRC), IBM through the DARPA-funded PERCS project, and the Motorola University Partnerships in Research program.http://llvm.cs.uiuc.edu/ Chris Lattner – lattner@cs.uiuc.eduLLVM Compiler Systemn The LLVM Compiler InfrastructurevProvides reusable components for building compilersvReduce the time/cost to build a new compilervBuild static compilers, JITs, trace-based optimizers, ...n The LLVM Compiler FrameworkvEnd-to-end compilers using the LLVM infrastructurevC and C++ are robust and aggressive:n Java, Scheme and others are in developmentvEmit C code or native code for X86, Sparc, PowerPChttp://llvm.cs.uiuc.edu/ Chris ...

Informations

Publié par
Nombre de lectures 77
Langue English

Extrait

The LLVM Compiler Framework and Infrastructure
Chris Lattner lattner@cs.uiuc.edu
Vikram Adve vadve@cs.uiuc.edu
http://llvm.cs.uiuc.edu/
LCPC Tutorial: September 22, 2004
Acknowledgements
External Contributors: vHenrik Bach vNate Begeman vJeff Cohen vPaolo Invernizzi vBrad Jones vVladimir Merzliakov vVladimir Prus vReid Spencer
UIUC Contributors: vTanya Brethour vMisha Brukman vCameron Buschardt vJohn Criswell vAlkis Evlogimenos vBrian Gaeke vRuchira Sasanka vAnand Shukla vBill Wendling Funding: This work is sponsored by the NSF Next Generation Software program through grants EIA-0093426 (an NSF CAREER award) and EIA-0103756. It is also supported in part by the NSF Operating Systems and Compilers program (grant #CCR-9988482), the NSF Embedded Systems program (grant #CCR-0209202), the MARCO/DARPA Gigascale Systems Research Center (GSRC), IBM through the DARPA-funded PERCS project, and the Motorola University Partnerships in Research program.
http://llvm.cs.uiuc.edu/
Chris Lattner –lattner@cs.uiuc.edu
LLVM Compiler System
nThe LLVM Compiler Infrastructure vProvides reusable components for building compilers vReduce the time/cost to build a new compiler vBuild static compilers, JITs, trace-based optimizers, ...
nThe LLVM Compiler Framework vEnd-to-end compilers using the LLVM infrastructure vC and C++ are robust and aggressive: nJava, Scheme and others are in development vEmit C code or native code for X86, Sparc, PowerPC
http://llvm.cs.uiuc.edu/
Chris Lattner –lattner@cs.uiuc.edu
Three primary LLVM components
nThe LLVMVirtual Instruction Set vThe common language- and target-independent IR vInternal (IR) and external (persistent) representation
nA collection of well-integrated libraries vAnalyses, optimizations, code generators, JIT compiler, garbage collection support, profiling, …
nA collection of tools built from the libraries vAssemblers, automatic debugger, linker, code generator, compiler driver, modular optimizer, …
http://llvm.cs.uiuc.edu/
Chris Lattner –lattner@cs.uiuc.edu
Tutorial Overview
nIntroduction to the running example nLLVM C/C++ Compiler Overview vHigh-level view of an example LLVM compiler nThe LLVM Virtual Instruction Set vIR overview and type-system nLLVM C++ IR and important API’s vBasics, PassManager, dataflow, ArgPromotion nImportant LLVM Tools vopt, code generator, JIT, test suite, bugpoint nExample applications of LLVM
http://llvm.cs.uiuc.edu/
Chris Lattner –lattner@cs.uiuc.edu
Running example: arg promotion
Consider use of by-reference parameters: int callee(const int &X) { int callee(const int *X) { return X+1; return *X+1;// memory load } } int caller() {compiles toint caller() { return callee(4); int tmp;// stack object } tmp = 4;// memory store return callee(&tmp);
We want: int callee(int X) { return X+1; } int caller() { return callee(4); }
http://llvm.cs.uiuc.edu/
}
üEliminated load in callee üEliminated store in caller üEliminated stack slot for ‘tmp’
Chris Lattner –lattner@cs.uiuc.edu
Why is this hard?
nRequires interprocedural analysis: vMust change the prototype of the callee vMust update all call sitesàwe mustknowall callers vWhat about callers outside the translation unit? nRequires alias analysis: vReference could alias other pointers in callee vMust know that loaded value doesn’t change from function entry to the load vMust know the pointer is not being stored through nReference might not be to a stack object!
http://llvm.cs.uiuc.edu/
Chris Lattner –lattner@cs.uiuc.edu
Tutorial Overview
nIntroduction to the running example nLLVM C/C++ Compiler Overview vHigh-level view of an example LLVM compiler nThe LLVM Virtual Instruction Set vIR overview and type-system nLLVM C++ IR and important API’s vBasics, PassManager, dataflow, ArgPromotion nImportant LLVM Tools vopt, code generator, JIT, test suite, bugpoint nExample applications of LLVM
http://llvm.cs.uiuc.edu/
Chris Lattner –lattner@cs.uiuc.edu
The LLVM C/C++ Compiler
nthe high level, it is a standard compiler:From vCompatible with standard makefiles vUses GCC 3.4 C and C++ parser
C file llvmgcc .o file llvm linker executable C++ file llvmg++ .o file
Compile Time Link Time nDistinguishing features: vUses LLVM optimizers, not GCC optimizers v.o files contain LLVM IR/bytecode, not machine code vExecutable can be bytecode (JIT’d) or machine code
http://llvm.cs.uiuc.edu/
Chris Lattner –lattner@cs.uiuc.edu
Looking into events at compile-time
C file llvmgcc .o file
C to LLVM Compile-time Frontend Optimizer “cc1” “gccas”
C++ file llvmg++ .o file
C++ to LLVM Compile-time Frontend Optimizer “cc1plus” “gccas”
M LLVM IR io LLVM 40 LLVM Analysis & d LLVM .bc ++ E Parser R Verifier Optimization Passes L File Writer t file Lowers o owers ++ o LVM
Dead Global Elimination, IP Constant Propagation, Dead Argument Elimination, Inlining, Reassociation, LICM, Loop Opts, Memory Promotion, Dead Store Elimination, ADCE, …
http://llvm.cs.uiuc.edu/
Chris Lattner –lattner@cs.uiuc.edu
Looking into events at link-time
.o file LLVM .o file Linker
.o file llvm linker executable .o file
Link-time Optimizer
20 LLVM Analysis & Optimization Passes Optionally “internalizes”: marks most functions as internal, to improve IPO
Perfect place for argument promotion optimization!
http://llvm.cs.uiuc.edu/
.bc file for LLVM JIT NaBtiavcek Code Native executable end “llc” BCa cCkoedned C Compiler “llc –march=c” “gcc”
Link in native .o files and libraries here
Native executable
Chris Lattner –lattner@cs.uiuc.edu
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents