llvm a compila ilation framework for lifelong progr for
play

LLVM: A Compila ilation Framework for Lifelong Progr for Lifelong - PowerPoint PPT Presentation

Systems and Internet Infrastructure Security ity Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA LLVM: A Compila ilation Framework for Lifelong Progr for


  1. Systems and Internet Infrastructure Security ity Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA LLVM: A Compila ilation Framework for Lifelong Progr for Lifelong Progr gram Analysis and gram Analysis and Transfor ormation Chris Lattner an and Vikram Adve Presented by: N Nirupama Talele Systems and Internet Infrastructure Security (SIIS) Laboratory Page 1

  2. Agenda • What is LLVM • LLVM Code Represent ntation • LLVM Compiler Archite itecture • Framework Analysis Systems and Internet Infrastructure Security (SIIS) Laboratory Page 2

  3. LLVM “Compiler framework desig signed to support transparent, • lifelong, program analysis is and transformation” Provides high level info to to compiler transformations • ‣ Compile-time ‣ Link-time ‣ Run-time ‣ In-idle-time Systems and Internet Infrastructure Security (SIIS) Laboratory Page 3

  4. LLVM • Program analysis shou uld occur through the lifetime of a program ‣ ‣ Intra-procedural optimiz Intra-procedural optimiz izations (link time) izations (link time) ‣ Machine-dependent opt ptimizations (install time) ‣ Dynamic optimization (r (run time) ‣ Profile-guided optimizat ations (idle time) Systems and Internet Infrastructure Security (SIIS) Laboratory Page 4

  5. LLVM Difference e with VMs • No high-level construct cts ‣ classes, inheritance, etc etc • No runtime system or o r object model • Does not guarantee sa afety ‣ type and memory Systems and Internet Infrastructure Security (SIIS) Laboratory Page 5

  6. LLVM Analysis • Aim to make lifelong an analysis transparent to programmers • Achieved through two p parts: ‣ Code Representation ‣ Compiler Architecture Systems and Internet Infrastructure Security (SIIS) Laboratory Page 6

  7. LLVM Code Repr presentation Key feature: high and low w level • RISC-like instruction set • ‣ ‣ SSA-based representation SSA-based representation Low-level, language indep ependent type system • LLVM is complementary to to virtual machines(like • JVM,Microsoft CLI), not an an alternative Systems and Internet Infrastructure Security (SIIS) Laboratory Page 7

  8. LLVM Code Repr presentation • How Support Lifelong A Analysis? • 5 capabilities ‣ Persistent program info formation ‣ ‣ Offline code generation Offline code generation n n ‣ User-based profiling/op ptimization ‣ Transparent runtime mo odel ‣ Uniform, whole program m compilation • No previous system pro rovides all 5 Systems and Internet Infrastructure Security (SIIS) Laboratory Page 8

  9. Instruction Set Avoids machine specific co constraints • Infinite set of typed virtual al registers • ‣ In SSA form ‣ Includes support for phi fun nctions ‣ ‣ This allows flow insensitive This allows flow insensitive ve algo to gain benefits of flow ve algo to gain benefits of flow sensitive without expensive ve Data Flow analysis Avoids same code for mul ultiple instructions (overloaded • opcodes) Is in load/store form -progr grams transfer values between • registers and memory sole lely via load and store operations using typed po ointers Systems and Internet Infrastructure Security (SIIS) Laboratory Page 9

  10. Type Information • Makes all address arith ithmetic explicit, exposing it to all LLVM optimizatio ions. Example :- Example :- X[i].a = 1; (assuming a is third field) X[i].a = 1; (assuming a is third field) X[i].a = 1; (assuming a is third field) X[i].a = 1; (assuming a is third field) %p = getelementptr %xty* %X, long %i, ubyte 3; %p = getelementptr %xty* %X, long %i, ubyte 3; store int 1, int* %p; • All addressable objects ts (“lvalues”) are explicitly allocated Systems and Internet Infrastructure Security (SIIS) Laboratory Page 10

  11. Exception Hand dling • Exceptions mechanism m based on two instructions ‣ invoke ‣ unwind unwind • Isolate code to throw/re /recover from exceptions to front-end libraries • Handling automatic var ariable destructors: ‣ An invoke instruction is is used to halt unwinding, the destructor is run, then u unwinding is continued with the unwind instruction. Systems and Internet Infrastructure Security (SIIS) Laboratory Page 11

  12. LLVM Compiler A Architecture • Remember: goal to ena nable transformations at link-time, install-time, ru run-time, and idle-time • Must be transparent to • Must be transparent to to application developers to application developers and end-users • Efficient enough for use se with real-world applications Systems and Internet Infrastructure Security (SIIS) Laboratory Page 12

  13. LLVM Compiler A Architecture This strategy provides the e 5 benefits discussed earlier • Some limitations • ‣ Language specific optimiza ations must be performed on front end ‣ Benefit to languages like Ja Java requiring sophisticated runtime systems? Systems and Internet Infrastructure Security (SIIS) Laboratory Page 13

  14. LLVM Compiler A Architecture Front-end compiler • ‣ Translate source code to LL LLVM representation ‣ Perform language specific o c optimizations ‣ Need not perform SSA const nstruction at this time ‣ Invoke LLVM passes for glo lobal inter procedural optimization at module level Systems and Internet Infrastructure Security (SIIS) Laboratory Page 14

  15. LLVM Compiler A Architecture Linker/Interprocedure Opti ptimizer • ‣ Various analyses occur Points-to analysis • Mod/Ref analysis • Dead global elimination, dead d argument elimination, constant • propagation, array bounds che heck, etc Can be speeded up by adding g inter-procedural summaries) • Systems and Internet Infrastructure Security (SIIS) Laboratory Page 15

  16. LLVM Compiler A Architecture Native Code Generation • ‣ JIT or Offline ‣ Currently supports Sparc V c V9 and x86 architectures Systems and Internet Infrastructure Security (SIIS) Laboratory Page 16

  17. LLVM Compiler A Architecture Reoptimizers • ‣ Identifies frequently run cod code and ‘hotspots’ ‣ Performs additional optimiza izations, thus native code generation can be performe ed ahead of time ‣ Idle-time reoptimizer Systems and Internet Infrastructure Security (SIIS) Laboratory Page 17

  18. LLVM Analysis • When compiled to LLV VM, a program can undergo the following a analyses ‣ Flow-insensitive, field-s sensitive, context-sensitive points-to analysis ‣ Uses Data Structure An nalysis (DSA) Systems and Internet Infrastructure Security (SIIS) Laboratory Page 18

  19. LLVM Analysis – Code Size • Relatively compact cod ode size Systems and Internet Infrastructure Security (SIIS) Laboratory Page 19

  20. Conclusion • LLVM is language inde ependent • Optimizations at all sta tages of software lifetime (compile,link, runtime, e , etc) • Compact code size • Efficient- due to small, ll, uniform instruction set in low level representation ion • Future work: can high-l level VMs be implemented on top of f the LLVM runtime optimization and code g e generation framework? Systems and Internet Infrastructure Security (SIIS) Laboratory Page 20

  21. Questions? Systems and Internet Infrastructure Security (SIIS) Laboratory Page 21

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend