36
Phoenix John Lefor Shahrokh Mortazavi Microsoft Research Developer Division

Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Embed Size (px)

Citation preview

Page 1: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

PhoenixPhoenixJohn Lefor Shahrokh MortazaviMicrosoft Research Developer Division

Page 2: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

OverviewOverview

What is Phoenix?A little BackgroundPhoenix Internals + demosPhoenix Academic ProgramQ&A

Page 3: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

What is Phoenix?What is Phoenix?

Framework for Analysis, Optimization & Codegen

Used by Microsoft ToolsAvailable to academic community and 3rd parties

Core tech for all future Microsoft compilersJITs, PreJITs, C++ Backend

Phoenix supports researchCompiler / tools DevelopmentTest bed for algorithm comparisonRobust enough for large code bases

Page 4: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Why Phoenix?

Robust, stable, documented, supported, long-livedWide APIJIT, PreJIT, batch modesDual Mode: .NET / nativePlug-insReal-world Apps

Page 5: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Why Phoenix (Microsoft)?

No duplicated effortFaster re-targettingResearchproduct xferIncrease academic presence

Page 6: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phoenix : NowPhoenix : NowBuilds Longhorn (next Windows release)JITs Avalon, Powerpoint (msil version)Passes large test suites: C++, C#Supports Whidbey (next Visual Studio release)Used in tools development3rd party partnersUsed in researchBut – few optimizations, as yet! (slated for mid 05)

Page 7: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

What’s changed since last year?What’s changed since last year?

Research group merged with Product groupMSR still very much involved

Much more robust – still ways to goAST supportX64, IA64 support improvedVerifier addedSeveral internal clientsAcademic program kicked off (more later)Shipped two Phx Research Dev Kit CD’s

Page 8: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phx uses inside MsftPhx uses inside Msft

Various code generation configs slated for next Visual Studio releaseFxCop on Phx: DF based AnalysisObfuscationAssembly analysis & rewritingSecurity related toolsProgram Discovery tools

Page 9: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division
Page 10: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phoenix ConfigurationsPhoenix Configurations

CLR

JIT

er

CLR

Pre

JIT

er

VC++

VC

++

BE

The Phoenix Building Blocks

Core StructuresAnd Utilities

High Level Optimizations

Low LevelOptimizations

MachineAbstractions

Dynamic Tools

BB

TV

ulca

n

Static Tools

Err

or

Det

ectio

n

Page 11: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

HIR LIR

HL

Opt

s

Ret

arge

t

LL O

pts

Cod

e G

en

HL

Opt

s

LL O

pts

LL O

pts

HL

Opt

s

Phx + Tools 10k foot viewPhx + Tools 10k foot view

PEs

VB

C++

C#

Phx Core LibCore structures, Utils; AST, CodeGen Srvcs

I/OSyncTransmgr

MasterProgram DB

+Profiles

PreFix

PreFast

Designer1

Designer2

Visualizer

Modeler

Editor+

Browser

Xlator

Formatter

Re

ad

ers: C

IL, MS

IL, HIR

, PE

ProgramRepresentation

[ AST]

CustomExtendedPgm Rep[AST+]

Phx APIs

ConvChecker

Obfuscator

SecurityChecker

FxCop

Phx APIs

EXE

•X86•IA64•X64•ARM•MSIL

Page 12: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Dual ModeDual Mode

Entire source base compilable as managed or unmanaged code (C++ feature)

Plug-ins can be in any language

Company Direction: Managed APIsManaged API required by Research CommunityJIT & PreJIT still require nativeMC++ Dogfooding

Page 13: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Coding Conventionsand DocumentationCoding Conventionsand Documentation

Standardized style and namingPhoenix uses formatting and convention checking toolsDocumentation extracted from sources

[Doc Demo]

Working on shipping sources and design docs

Page 14: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

InternalsInternalsUnitsIRASTsSymbolsTypesFieldsObject Description Language (PDL)Graph packageAlias PackageEH RepresentationMulti-Threading SupportSSA

Page 15: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Current Phases In CompilerCurrent Phases In Compiler

Reader

TypeChecker

MIR Lower

Simple RVD

Lower

RegAlloc

StackAlloc

FrameGeneration

SwitchLower

LIR PhaseList

BlockLayout

Encode/Emit

Finalize

Page 16: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phx Based Compiler OrganizationPhx Based Compiler Organization

Global (whole program)

FuncFunc

FuncFunc

FuncFunc

FuncFunc

FuncFunc

Func

Symbol Table

Symbol Table

Instruction Stream

Flow Graph

Exception Handling Info

Type System

Region Graph

Framework supports multi-threaded compilation at the function level.

DataData

Data

Data Instrs

Page 17: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

IR Instruction StreamIR Instruction Stream

Example of pre-lowered and post-lowered instructions: *p += 1

[p] [p]

ADD

1 p

[p(eax)] [p(eax)]

x86add

1 p(eax)cc

HIR

LIR

int32 int32 ptr-int32int32

int32 int32 ptr-int32int32condCode

EH handler

EH handler

Page 18: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

IR OpcodesIR OpcodesHigh Level

Opcode::NewObjOpcode::CastClassOpcode::ChkTypeInitOpcode::CallVirt

Mid LevelOpcode::AddOpcode::CallOpcode::AssignOpcode::StrCmp

Lower LevelOpcode::x86addOpcode::x86mov

Page 19: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

IR From Source to MachineIR From Source to MachineSource:

z = a + b + c;

HIR:

t1 = ADD a, b

t2 = ADD t1, c

z = ASSIGN t2

LIR:

t1(EAX), cc = x86add a(EAX), b(EDX)

t2(EAX), cc = x86add t1(EAX), c(EBX)

z = x86mov t2(eax)

Page 20: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Views of IR FunctionsViews of IR FunctionsEnter

IF

LOOP

Exit

Enter

IF

LOOP

Exit

InstructionStream

Flow GraphRegions

Page 21: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

IRExplorer DemoIRExplorer Demo

Page 22: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Type systemType system

Type system is internal to PhoenixIndependent of source language type system(s)Own rules for consistency.It is extensible (can add new primitive types and rules for typechecking).

Rich typesSpans source-level to machine types

All operands have typesUsed for code generation, GC tracking, optimization.

Page 23: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

ExtensibilityExtensibility

Most Phoenix objects can have extensibility objects attached.Maintained by compare and copy routinesUser determines how extensions are used:

New fields/properties on instructionsNew fields/properties on operands

Possibility: subclassing/factories to extend instructions and operands with target specific info

Page 24: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phx Definition LanguagePhx Definition Language

Header/CodeGen Tool to assist withDual-Mode CompilationExtensibility

BenefitsAutomatic declarations of property variablesAutomatic generation of Kind/Is/As testsAutomatic packing of boolean variablesAutomatic generation of two-level APIOpen classes for extensibilityUnmanaged “Metadata”

Page 25: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Example of PDL SolutionExample of PDL Solutionpublic [gc,extensible]

class Sym

{

[dump] virtual void Dump();

virtual property PhxString NameString get;

property Phx::Boolean IsToolGenerated

{ isToolGenerated }

}

Page 26: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Static Extensibility ExampleStatic Extensibility Example// In Phoenix common PDL file

public [gc,extensible]

class Sym

{

...

}

// In a JIT-specific PDL file

extend class Sym

{

property Phx::RTAddr RTAddr { rtAddr }

}

Page 27: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phoenix: Exception HandlingPhoenix: Exception Handling

Support EH models present in C++, Microsoft CLR, and SEH.Allow an efficient mapping to existing target specific EH interfaces Express explicit control flow in the presence of exceptions. Permit precise data-flow information to be built easily.Allow traditional global optimizations in the presence of exceptions.Allow optimizations of exception constructs in the IR.

Page 28: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

ASTsASTs

ASTs can be imported from C++ and C#Available for static analysis or code genCCI functionality being merged into PhxFxCop being ported overShould be available in next 1 or 2 RDK drops[AST Demo]

Page 29: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Academic ProgramAcademic Program

Page 30: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phoenix Academic ProgramPhoenix Academic Program

Provides very early access to PhoenixUse Phoenix for research and/or teachingGives us feedback on functionality and robustness

Page 31: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phoenix LicensingPhoenix Licensing

Evaluation License – MS and individualAccess to Phoenix binaries and documentationAccess to Phoenix Academic ForumNo rights to publish

Research License – MS and institutionAccess as beforePublication rightsInstructional opportunities

Page 32: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Academic Users of PhoenixAcademic Users of Phoenix

Bayesian reasoning for crash analysisSoftware phase detectionOptimization investigation – register allocation algorithmsRefactoring analysis – outlining opportunitiesPath profilingGraduate level compiler course

Page 33: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phoenix Academic (cont’d) Phoenix Academic (cont’d)

Phoenix Academic Forum (PAF)Support websiteMonitored by Phoenix teamYour participation leads to success

http://research.microsoft.com/phoenix

Page 34: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division
Page 35: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

Phoenix Availability (cont’d)Phoenix Availability (cont’d)

Phoenix is ConfidentialEmail [email protected] an NDARegister at PAF support website

“Current bits” binary; docs; samples; tools

Page 36: Phoenix John LeforShahrokh Mortazavi Microsoft ResearchDeveloper Division

© 2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.