Modern Compiler Internal Representations Silvius Rus 1/23/2002.
-
date post
19-Dec-2015 -
Category
Documents
-
view
229 -
download
3
Transcript of Modern Compiler Internal Representations Silvius Rus 1/23/2002.
![Page 1: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/1.jpg)
Modern Compiler Internal Representations
Silvius Rus
1/23/2002
![Page 2: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/2.jpg)
Presentation Navigator
Introduction Challenges Staged compilation Generate efficient code Case studies Conclusions
![Page 3: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/3.jpg)
Traditional Compiler Organization
Pass: output type– Read code as text: ASCII characters– Lexical scanner: language words– Syntactic parser: language phrases– Translation: attribute grammar phrases– Output generated code: binary stream
Focus on pipelining due to memory window constraints
![Page 4: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/4.jpg)
Traditional Compiler Internal Representation
Grammatical structure not always built explicitly
Implicit, built-in semantics Simple data structures:
– Transition tables– Token streams and stacks
![Page 5: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/5.jpg)
Presentation Navigator
Introduction Challenges Staged compilation Generate efficient code Case studies Conclusions
![Page 6: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/6.jpg)
Compiler Challenges
Versatile: – Understand multiple languages – Generate output for various architectures
Generated efficient code:– Fast: as fast as coded directly in the output language – Portable: runs on multiple platforms – Verifiable: runs provably within a specified class of behavior – Secure: provably respects certain security requirements
Extendable: need to extend in order to: – Incorporate new input language and/or target system– Take advantage of advances in run-time environments (such as ISA
changes, multithreading, distributed/parallel execution)
L+A < L*A
![Page 7: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/7.jpg)
Understand Multiple Languages - Output for Multiple Targets
Abstract IR:– Same representation for Fortran, C, C++, Java, …– Possible only for conceptually similar languages
Good points:– Perform complex transformations on a single representation
Bad points:– Language semantics may either get lost or need additional
particular representation– Specific architecture characteristics are more profitable to use
than common (abstractable) ones
![Page 8: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/8.jpg)
Presentation Navigator
Introduction Challenges Staged compilation Generate efficient code Case studies Conclusions
![Page 9: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/9.jpg)
Staged Compilation
Stage 1:– Load source file (text) into IR1 – machine independent– Optimize IR1– Stream IR1 to text file
Save/reload, pipe, HTTP, … text file– SUIF files, Java bytecode, .NET assembly
Stage 2:– Load text file into IR2 – machine dependent– Perform machine specific optimization on IR2– Generate executable code or interpret IR2
![Page 10: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/10.jpg)
Stage 1 Stage 2 Examples
Static Static SUIF, Promis
Static Dynamic SUN JIT, .NET JITer
Static Static + Dynamic
DyC, Quicksilver
Staged Compilation
![Page 11: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/11.jpg)
Staged Compilation
Prepare IR1 so that stage 2 is very cheap– Quicksilver
Insert templated optimized object code in bytecode Pack speculative optimization validation predicates in bytecode Keep method dependence graphs explicitly in bytecode
– Microsoft .NET Explicit type/class information in IL Preformatted, quickly accessible metadata
– Strings, tables, heaps– Custom data
Allow embedding of native code
![Page 12: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/12.jpg)
Presentation Navigator
Introduction Challenges Staged compilation Generate efficient code Case studies Conclusions
![Page 13: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/13.jpg)
Generate Fast And Portable Code
Fast code– IR close to machine structure
Mapping data to registers Mapping operations to opcodes Scheduling instructions for superscalar/VLIW processors
Portable code– Machine description must be totally abstracted
QuickSilver: templated optimized code
![Page 14: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/14.jpg)
Generate Verifiable Code
Microsoft .NET IL– Static and dynamic type safety - reflections– Managed code
Carries a minimum of information on itself Usually signed by compiler in Stage 1
– Managed data Only accessible from managed code Garbage collected
– Managed pointers
![Page 15: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/15.jpg)
Generate Secure Code
Hard to define limits– Make sure you run what you mean to– Limit rights
Per user Per software component
QuickSilver: digests .NET IL:
– Code is signed using encrypting of hashed original– Permissions are set per module
![Page 16: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/16.jpg)
Generate Efficient Code
IR may also provide support for:– Versioning (Quicksilver, .NET)– Culture (.NET)
![Page 17: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/17.jpg)
Presentation Navigator
Introduction Challenges Staged compilation Generate efficient code Case studies Conclusions
![Page 18: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/18.jpg)
Compiler Internal Representation - General Organization
High-level - completely machine independent– Abstract Syntax Tree – Control Flow Graph – Control Dependence Graph – Data Dependence Graph – Static Single Assignment
Medium-level - dependent on classes of machines– Virtual machine code, such as stack machine
Low level - dependent on particular ISA – Assembly, machine instruction graphs
![Page 19: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/19.jpg)
Case Study: Polaris
High level representation– Abstract Syntax Tree– Control Flow Graph– Control Dependence Graph– Data Dependence Graph– Gated Static Single Assignment
Some generality– Backends for various parallel execution systems
![Page 20: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/20.jpg)
Case Study: SUIF2
Multiple level representation– CFG, CDG, …– Quads– Machsuif– Custom annotations
Multiple frontends: Fortran, C, Java Multiple backends: SUIF VM, C, assembly Decoupled passes communicate only via SUIF Extendable: OSUIF
![Page 21: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/21.jpg)
Case Study: Promis
Switch to Promis organization presentation Switch to Promis IR presentation
![Page 22: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/22.jpg)
Case Study: KCC
Kook and Associates (KAI) C++ compiler:– C++ dedicated internal representation
Advanced C++ specific optimization
– Proprietary C++ specific object format Interprocedural optimization with modular compilation C++ specific debug information – usable with KDB
– Outputs C with calls to proprietary run-time library– Uses GNU gcc to generate machine code
![Page 23: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/23.jpg)
Case Study: Jalapeno QuickSilver
Quasi-static images– Java bytecode + proprietary format
Representation allows for optimizations– Explicit method dependence graph – Templated optimized object code – Speculative optimization validation predicates
![Page 24: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/24.jpg)
Case Study: .NET
Advertised 9 digit $$ figure project CLI (ECMA standard)
– Common type system Type info in intermediate code
– Common exception system Throw in Visual Basic, catch in C++
– Support for security, culture, versioning– Support for charging per-use– Custom info can be passed for original
language specific description
30+ languages
MSIL
native code
![Page 25: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/25.jpg)
Other Compilers – Open Source
GNU compiler:– C, Fortran, Java, C++ front-ends– Generates code for all major architectures– Low level internal representation– New version (3.x) has SSA
SGI open source project: discontinued
![Page 26: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/26.jpg)
Other Compilers – Commercial
Fortran, C, C++, Java produced by OS and/or hardware producers– HP, SGI, Intel, Microsoft, SUN
Other commercial compiler producers:– Borland, Watcom, etc.
Internal representation – company secret
![Page 27: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/27.jpg)
Presentation Navigator
Introduction Challenges Staged compilation Generate efficient code Case studies Conclusions
![Page 28: Modern Compiler Internal Representations Silvius Rus 1/23/2002.](https://reader030.fdocuments.in/reader030/viewer/2022032703/56649d395503460f94a1279f/html5/thumbnails/28.jpg)
Conclusions
Internal representation evolved– Programming paradigms– Changes in hardware– Changes in compiler/run-time system technology– New issues: security, verifiability, culture, versioning
Tendency: E Pluribus Unum