Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Phoenix Compiler and Tools Framework Andy Ayers Microsoft Phoenix

Similar presentations

Presentation on theme: "The Phoenix Compiler and Tools Framework Andy Ayers Microsoft Phoenix"— Presentation transcript:

1 The Phoenix Compiler and Tools Framework Andy Ayers Microsoft Phoenix

2 What is Phoenix? Phoenix is a codename for Microsoft’s 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 extensible configurable scalable A rich ecosystem for academic research and industrial users

5 Overview Phoenix Infrastructure.Net CodeGen Runtime JITs Pre-JIT OO and.Net optimizations Native CodeGen Advanced C++/OO Optimizations FP optimizations OpenMP Retargetable “Machine Models” ~3 months: -Od ~3 months: -O2 Chip Vendor CDK ~6 month ports Sample port + docs Academic RDK Managed API’s IP as DLLs Docs MSR & Partner Tools Built on Phoenix API’s Both HL and LL API’s Managed API’s Program Analysis Program Rewrite MSR Adv Lang Language Research Direct xfer to Phoenix Research Insulated from code generation AST Tools Static Analysis Tools Next Gen Front-Ends R/W Global Program Views

6 DelphiCobol HL Opts LL Opts Code Gen HL Opts LL Opts HL Opts Native Image C# Phoenix Core AST IR Syms Types CFG SSA Xlator Formatter Browser Phx APIs Profiler Obfuscator Visualizer Security Checker Refactor Lint VB C++ ILassembly C++ PreFast Profile Eiffel C++ Phx AST Lex/Yacc Tiger Code Gen CompilersTools

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 Driver (CL) Demo 1: Code Generation Microsoft C++ compiler ● Input: program text ● Output: COFF object file C++ Source Frontend (C1) Backend (C2) Obj File We’ll demo a Phoenix- based c2

9 IR States Phases transform IR, either within a state or from one state to another. For instance, Lower transforms MIR into LIR. Abstract Concrete Lowering Raising ASTHIRMIRLIREIR

10 View inside Phoenix-Based C2 AST HIR MIRLIREIR CIL Reader Type Checker MIR Lower SSA Const SSA Dest Canon Addr Modes Lower Reg Alloc EH Lower Stack Alloc Frame Gen Switch Lower Block Layout Flow Opts Encode Lister C2C1 CILCIL SOURCESOURCE OBJECTOBJECT

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 We’ll 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 Build control flow graph, solve data flow problem Unknown is the “state of v” at start of each block: Transfer function relates output of block to input: Meet combines outputs from predecessor blocks Classic Solution start v = = v start v = =v UndefinedDefinedMixed If block contains v= Else output = input must may

15 Code sketch using dataflow bool changed = true; while (changed) { for each (Phx::Graphs::BasicBlock block in func) { STATE ^ inState = inStates[block]; bool firstPred = true; for each(Phx::Graphs::BasicBlock predBlock in block->Predecessors) { STATE ^ predState = outStates[predBlock]; inState = meet(inState, predState); } inStates[id] = inState; STATE ^ newOutState = gcnew STATE(inState); for each(Phx::IR::Instr ^ instr in block->Instrs) { for each (Phx::IR::Opnd ^ opnd in instr->DstOpnds) { Phx::Syms::LocalVarSym ^ localSym = opnd->Sym->AsLocalVarSym; newOutState[localSym] = dst(newOutState[localSym]); } STATE ^ outState = outStates[id]; bool blockChanged = ! equals(newOutState, outState); if (blockChanged) { changed = true; outStates[id] = newOutState; } Update input state Compute output state Check for convergence

16 Demo: Unintialized Local Plug-In UninitializedLocal.cpp C++/CLI UninitialzedLocal.dll Test.cpp C1 Test.obj Phx-C2 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


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 don’t 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).


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

25 Summary Phoenix is Microsoft’s next-generation tools and code generation framework It’s written entirely in C++/CLI It’s available for you to experiment with now…

26 Questions?

Download ppt "The Phoenix Compiler and Tools Framework Andy Ayers Microsoft Phoenix"

Similar presentations

Ads by Google