Post on 29-Dec-2015
PhoenixPhoenixJohn Lefor Shahrokh MortazaviMicrosoft Research Developer Division
OverviewOverview
What is Phoenix?A little BackgroundPhoenix Internals + demosPhoenix Academic ProgramQ&A
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
Why Phoenix?
Robust, stable, documented, supported, long-livedWide APIJIT, PreJIT, batch modesDual Mode: .NET / nativePlug-insReal-world Apps
Why Phoenix (Microsoft)?
No duplicated effortFaster re-targettingResearchproduct xferIncrease academic presence
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)
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
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
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
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
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
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
InternalsInternalsUnitsIRASTsSymbolsTypesFieldsObject Description Language (PDL)Graph packageAlias PackageEH RepresentationMulti-Threading SupportSSA
Current Phases In CompilerCurrent Phases In Compiler
Reader
TypeChecker
MIR Lower
Simple RVD
Lower
RegAlloc
StackAlloc
FrameGeneration
SwitchLower
LIR PhaseList
BlockLayout
Encode/Emit
Finalize
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
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
IR OpcodesIR OpcodesHigh Level
Opcode::NewObjOpcode::CastClassOpcode::ChkTypeInitOpcode::CallVirt
Mid LevelOpcode::AddOpcode::CallOpcode::AssignOpcode::StrCmp
Lower LevelOpcode::x86addOpcode::x86mov
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)
Views of IR FunctionsViews of IR FunctionsEnter
IF
LOOP
Exit
Enter
IF
LOOP
Exit
InstructionStream
Flow GraphRegions
IRExplorer DemoIRExplorer Demo
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.
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
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”
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 }
}
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 }
}
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.
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]
Academic ProgramAcademic Program
Phoenix Academic ProgramPhoenix Academic Program
Provides very early access to PhoenixUse Phoenix for research and/or teachingGives us feedback on functionality and robustness
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
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
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
Phoenix Availability (cont’d)Phoenix Availability (cont’d)
Phoenix is ConfidentialEmail PhxAP@microsoft.comSign an NDARegister at PAF support website
“Current bits” binary; docs; samples; tools
© 2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.