The Phoenix Compiler and Tools Framework - PowerPoint PPT Presentation

About This Presentation
Title:

The Phoenix Compiler and Tools Framework

Description:

Phoenix is a codename for Microsoft's next-generation, state of the art ... Layered set of analysis and transformations components ... – PowerPoint PPT presentation

Number of Views:129
Avg rating:3.0/5.0
Slides: 27
Provided by: andya59
Category:

less

Transcript and Presenter's Notes

Title: The Phoenix Compiler and Tools Framework


1
The Phoenix Compiler and Tools Framework
  • Andy Ayers
  • Microsoft Phoenix
  • AndyA_at_microsoft.com

2
What is Phoenix?
  • Phoenix is a codename for Microsofts
    next-generation, state of the art infrastructure
    for program analysis and transformation

3
Why Phoenix?
VS
4
Phoenix Goals
  • An industry leading compilation
  • and tools framework

An infrastructure that is robust retargetable ext
ensible configurable scalable
A rich ecosystem for academic research and
industrial users
5
Overview
AST Tools
.Net CodeGen
  • Static Analysis Tools
  • Next Gen Front-Ends
  • R/W Global Program Views

MSR Adv Lang
  • Runtime JITs
  • Pre-JIT
  • OO and .Net optimizations
  • Language Research
  • Direct xfer to Phoenix
  • Research Insulated from code generation

Phoenix Infrastructure
Native CodeGen
MSR Partner Tools
  • Advanced C/OO Optimizations
  • FP optimizations
  • OpenMP
  • Built on Phoenix APIs
  • Both HL and LL APIs
  • Managed APIs
  • Program Analysis
  • Program Rewrite

Academic RDK
Retargetable
  • Managed APIs
  • IP as DLLs
  • Docs

Chip Vendor CDK
  • Machine Models
  • 3 months -Od
  • 3 months -O2
  • 6 month ports
  • Sample port docs

6
Compilers
Tools
Browser
Visualizer
Lint
HL Opts
LL Opts
Code Gen
HL Opts
LL Opts
LL Opts
HL Opts
Code Gen
Formatter
Obfuscator
Refactor
Xlator
Profiler
SecurityChecker
Phx APIs
Phoenix Core AST IR Syms Types
CFG SSA
PreFast
Native Image
C IL
assembly
Profile
Phx AST
C
Lex/Yacc
C
VB
C
Delphi
Cobol
Eiffel
Tiger
7
Phoenix Architecture
  • Core set of extensible classes to represent
  • IR, Symbols, Types, Graphs, Trees, Regions
  • Layered set of analysis and transformations
    components
  • Data Flow Analysis, Loops, Aliasing, Dead Code,
    Redundant Code, Inlining
  • Common input/output library for binary formats
  • PE, LIB, OBJ, CIL, MSIL, PDB

8
Demo 1 Code Generation
  • Microsoft C compiler
  • Input program text
  • Output COFF object file

Well demo a Phoenix-based c2
Driver (CL)
C Source
Frontend (C1)
Backend (C2)
Obj File
9
IR States
Abstract
Concrete
Lowering
Raising
  • Phases transform IR, either within a state or
    from one state to another.
  • For instance, Lower transforms MIR into LIR.

10
View inside Phoenix-Based C2
S O U R C E
O B J E C T
CI L
HIR
AST
MIR
LIR
EIR
CIL Reader Type Checker
MIR LowerSSA Const SSA Dest Canon Addr Modes
Lower Reg Alloc EH Lower Stack Alloc Frame
Gen Switch Lower Block Layout Flow Opts
Encode Lister
C2
C1
11
Extending Phoenix
  • All Phoenix clients can host plug-ins
  • Plug-ins can
  • Add new components
  • Extend existing components
  • Reconfigure clients
  • Extensibility relies on
  • Reflection
  • Events Delegates

12
Example Uninitialized Local Detection
  • Would like to warn the user that x is not
    initialized before use
  • To do this we need to perform a dataflow analysis
    within the compiler
  • Well add a phase to C2 to do this, via a plug-in
  • int foo()
  • int x
  • return x

13
Detecting an Uninitialized Use
  • For each local variable v
  • Examine all paths from the entry of the method to
    each use of v
  • If on every path v is not initialized before the
    use
  • v must be used before it is defined
  • If there is some path where v is not initialized
    before the use
  • v may be used before it is defined

14
Classic Solution
  • Build control flow graph, solve data flow
    problem
  • Unknown is the state of v at start of each
    block
  • Transfer function relatesoutput of block to
    input
  • Meet combines outputs frompredecessor blocks

Undefined
Defined
Mixed
If block contains v
start
start
Else output input
v
v
must
v
may
v
15
Code sketch using dataflow
  • bool changed true
  • while (changed)
  • for each (PhxGraphsBasicBlock block in
    func)
  • STATE inState inStatesblock
  • bool firstPred true
  • for each(PhxGraphsBasicBlock predBlock
    in block-gtPredecessors)
  • STATE predState outStatespredBlock
  • inState meet(inState, predState)
  • inStatesid inState
  • STATE newOutState gcnew STATE(inState)

Update input state
Compute output state
Check for convergence
16
Demo Unintialized Local Plug-In
UninitializedLocal.cpp
Test.cpp
C/CLI
C1
Phx-C2
UninitialzedLocal.dll
Test.obj
To Run cl -d2plugin UninitializedLocal.dll -c
Test.cpp
17
Demo 3 Phoenix PE Explorer
  • Phoenix can also read and write PE files directly
  • Implement your own compiler or linker
  • Create post link tools for analysis,
    instrumentation or optimization
  • Phx-Explorer is only 800 LOC client code on top
    of Phoenix core library

18
(No Transcript)
19
Demo 4 Binary Rewriting
  • mtrace injects tracing code into managed
    applications

20
Phoenix IR vs MSIL
  • Phoenix IR makes everything explicit
  • Operands
  • Control flow
  • Exception handling
  • Side effects
  • Memory model
  • Better format for analysis and transformation
  • Identical model for .Net and native code
  • Many analyses dont need to make a distinction

21
Current Status
  • RDKs released every 6 mos (May 06) with regular
    updates.
  • Phoenix is now building Vista
  • 15 universities engaged via academic program
  • Code quality, code size, features, compile times
    not yet on par with the retail product (but
    closing ground fast).

22
(No Transcript)
23
Recap
  • Phoenix is a powerful and flexible framework for
    compilers tools
  • C2 backend
  • PE file read/write
  • JIT PreJIT (not shown)
  • Universal plugins on a common IR
  • You can use the same components we use in your
    own work.
  • Download available now
  • Prerequisite VS2005 (VC Express will work,
    mostly)
  • Evaluation license prohibits redist or commercial
    use

24
More Info
  • http//research.microsoft.com/phoenix

25
Summary
  • Phoenix is Microsofts next-generation tools and
    code generation framework
  • Its written entirely in C/CLI
  • Its available for you to experiment with now

26
Questions?
http//research.microsoft.com/phoenix andya_at_micros
oft.com
Write a Comment
User Comments (0)
About PowerShow.com