An Overview of the SUIF2 System
Download
Report
Transcript An Overview of the SUIF2 System
An Overview of the SUIF2 System
Monica Lam
Stanford University
http://suif.stanford.edu/
Team Members
Stanford University
Monica Lam
Gerald Aigner
Gerald Cheong
Amer Diwan
David Heine
Amy Lim
Vladimir Livshits
Virendra Mehta
Brian Murphy
Costa Sapuntzakis
Hansel Wan
Chris Wilson
Harvard
Michael Smith
Erven Rohou
Glenn Holloway
Gang Chen
Eric Feigin
Nick Gloy
Stuart Schechter
Jason Simmons
Omri Traub
Cliff Young
UCSB
Portland Group
Urs Hoelzle
David Moore
Andrew Duncan Vince Shuster
Bogdan Cocosel Deb Caruso
Holger Kienle
David Wohlford
Kristian Kvilekval Bob Scollard
Kevin O’gorman
Prashanth Ramdas
Radu Rugina
Andrew Rutz
The SUIF System
PGI Fortran
Interprocedural Analysis
Parallelization
Locality Opt
C
EDG C++
SUIF2
Alpha
Java
Inst. Scheduling
Register Allocation
x86
Overview of SUIF Components
Basic Infrastructure
Extensible IR and utilities
Modular compiler system
Pass submodule
Backend Infrastructure
Optimization framework
HL Analysis Infrastructure
Graphs, sccs
Presburger arithmetic (omega)
Farkas lemma&“Gaussian Elimination”
Interprocedural framework
Garbage collection (Boehm’s)
PGI Fortran, EDG C/C++, Java FE
Standard IR, OSUIF (for OO lang)
Hoof: Suif object specification language
SUIF1 / SUIF2 translators
Statement dismantlers
Suifbrowser
Register allocation
Scheduling
Alpha and x86 backends
Call graph
Affine partitioning for parallelism & locality
Steensgaard’s alias analysis
Interprocedural parallelization:
array/scalar dependence/privatization
Motivation for Extensible IR
Suif1 design
A fixed set of flat C++ classes
All codes must change if we add new IR nodes
e.g. printing objects, reading and writing to file
Higher level semantic objects
OSUIF (for object-oriented programming)
Verilog event-driven control flow semantics
Saturated arithmetic used in multimedia instruction sets
Program analysis concepts
phi nodes in SSA analysis
synchronization operations introduced by parallelization
Results of analysis
Concept I: Reflective IR
Metaclass: captures representation of IR nodes in a data structure
Enables common generic routines to implement
Persistence: reading/writing to disk
Cloning: routine that copies the data structure
Printing: a generic routine to print out the information
Walkers, iterators, visitors
Concept II:
Object hierarchy & virtual aggregate fields
ExecutionObject
Statement
get_child_statements
IfStatement
WhileStatement
get_then_part
get_else_part
get_body
Abstract names to refer to fundamental concepts in subclasses
e.g. get_child_statements
IfStatement: get_then_part and get_else_part, or
WhileStatement: get_body
Object hierarchy & virtual aggregate fields
Maximize reuse and modular code development
Write code that operates at the highest level of abstraction
A pass works, without recompilation, for code with new subclasses
if new refinements are immaterial to a pass.
The unknown information is maintained across a pass
Example:
Reuse an intraprocedural dead code elimination written for SUIF
on OSUIF (object-oriented SUIF) code
Concept III: Multiple Representations for
High-Level Analyses
Multiple representations for different semantic levels
e.g. FOR loops versus basic blocks in a control flow graph
=> Alternative representations
Mixture of high-level and low-level constructs
Dismantlers lower the representation
Concept IV: High-level object specification
Insulates user from details
Object Definition (.hoof)
SUIF Macro Generator
a general grammar-based tool
Interface for user (.h)
Implementation in
Meta-Class System (.cpp)
Meta-Class System
reading & writing to file in
machine-independent format
• Easy for the programmer
• Easy for the implementor to develop the system
Example of a Hoof Definition
C++
hoof
concrete New
{ int x; }
class New : public SuifObject
{
public:
int get_x();
void set_x(int the_value);
~New();
void print(…);
static const Lstring get_class_name();
…
}
Uniform data access functions (get_ & set_)
Automatic generation of meta class information etc.
Examples of Suif Nodes
abstract Statement : ExecutionObject
{
virtual list<Statement* owner> child_statements;
...
}
concrete IfStatement : Statement
{
Expression * condition in source_ops;
Statement * owner then_part in child_statements;
Statement * owner else_part in child_statements;
}
Motivation for a Modular Compiler System
SUIF1:
All passes read and write suif files: more modular and supportive of
experimentation
but it is slow
Data between passes are written out as annotations
Annotations must be expressed as strings when written out
Requires manual pickling of annotations
Nontrivial effort to support any interactivity
SUIF2
Concept I: A Modular Compiler Architecture
Executable
suifdriver
MODULES:
Passes
analyses
optimizations
Kernel
suifkernel
iokernel
IR
suifnodes
basicnodes
Components
Kernel: provides all basic functionality
iokernel: implements I/O
suifkernel: hides iokernel and provides modules support, cloning,
command line parsing, list of factories, etc.
Modules
passes: provides a pass framework
IR: basic program representations
Suifdriver
provides execution control over modules and passes
Memory/Memory vs File/File Passes
COMPILER
A series of stand-alone programs
Suif-file1
driver+module1
Suif-file2
driver+module2
Suif-file3
A driver that imports & applies
modules to program in memory
Suif-file1
Suifdriver
imports/executes
module1
module2
module3
driver+module3
Suif-file4
Suif-file4
Concept II: Dynamic Registration of Modules
Compilation State: SuifEnv
Keeps the loaded SUIF program
All the registered modules
A module is a C++ class
that implements either a pass or a set of nodes in IR
must have a unique module_name
one or more modules make up a dll (dynamically linked library)
each library includes a function (init_<dllname>) to register the
module dynamically
Dynamic Assembly of a Compiler
> suifdriver
suif> import basicnodes suifnodes
suif> import mylibrary
suif> load test.suif
suif> mylibrary_pass1
suif> print test.out
suif> save test.tsuif
The Suifdriver:
accepts a simple scripting language. (A version that accepts tcl/tk also
exists).
pre-registered modules (import, load, print, save)
imports libraries dynamically which can register new modules (new
commands)
System can easily be used for demand-driven program analysis e.g. SUIF
explorer or a debugger
Concept III: Easy to write a new analysis:
subclass of a pass module
Executable
suifdriver
Passes
analyses
optimizations
Kernel
suifkernel
iokernel
IR
suifnodes
basicnodes
Example Pass: Count Statements in Procedures
class mypass: public Pass {
public:
mypass(SuifEnv *env, const Lstring &name): Pass(env, name) {}
virtual ~mypass() {}
Module *clone() const {return(Module*) this:}
void do_procedure_definition (ProcedureDefinition* proc_def)
{
cout << proc_def->get_procedure_symbol() ->get_name()
cout << object_iterator<ExecutionObject>(proc_def).length();
}
}
extern “C” void init_mypass (SuifEnv *suif_env) {
suif_env->get_module_subsystem()->register_module
(new mypass (suif_env, “mypass”));
}
Research Infrastructure: Support at 3 Levels
I. Compose compiler with existing passes
Dynamic composition of different passes
II. Develop new passes
User concentrates on algorithmic issues
Infrastructure provides common functionalities
Write code once, can run on SUIF program in memory or a file
III. Develop new IR
High-level specification of the IR nodes
Old code works with new IR without recompilation
Deliverables
Infrastructure: basesuif system
Components: Front ends and passes
Testing
Documentation
Basic Infrastructure (Beta release)
SUIF object system
I/O, printing, cloning
Visitors: dispatch method according to type
Iterators: simple iteration of certain objects
Walkers: user-controllable traversal of data structures
Module subsystem
Hoof language implementation
Standard IR representation
General data structures
Infinite precision integers, strings
lists, sets, hash maps
assertion, error handling, command line parsing
SuifBrowser
Presents the source and SUIF code
Compiler components: C
EDG C
lcc C
SUIF +
cfenodes
SUIF1
SUIF
C
SUIF1
EDG C front end -> SUIF
Created cfenodes to represent C
constructs, which are then lowered
SUIF -> C
SUIF1 -> SUIF -> SUIF1
Enables SUIF1 users to use old SUIF1
passes in the compiler
Testing
PGI unit tests
16 errors out of > 3000 tests
Spec95int: all but gcc work.
(gcc not Ansi C, we are working on it).
Object-oriented Languages: C++ and Java
j2s
OSUIF
SUIF
C
EDG C++
OSUIF: object-extension of SUIF (for Java and
C++)
Types: classes, methods and fields
Symbols: fields & methods
SymbolTable: class-specific behavior for
member lookup
Statements: exception handling & objectoriented instructions
EDG C++ -> SUIF (on track)
Java
no threads, exception handling, dynamic loading
Java byte code-> OSUIF (Solaris)
Class loading, resolution of the constant pool
Control flow analysis (normal and exception handling)
Data flow analysis (construct type information)
OSUIF code generation
OSUIF -> SUIF
build-vtables: virtual tables
lower-instance-variables: layout of class-types
lower-methods: method dispatch
lower-static-fields, lower-static-methods: put static in global scope
Testing: compiled JDK 1.2beta2 javac compiler: 538 Java classes
Fortran front end
Based on PGI’s proprietary front end
PGI Fortran includes F90 and HPF;
only the F77 subset is translated to SUIF
To be released only in binary form
Alpha version delivered to Stanford, not yet released
Documentation
The SUIF2 Infrastructure Guide (an index to all documentation)
Overview of the SUIF Infrastructure
The SUIF Representation Guide
The Basic SUIF Programmer’s Guide
The SUIF System Programmer’s Reference Manual
All the high-level interfaces documented (example)
Generated from the .h files by Doxygen
All the cross references, e.g. class hierarchy information
Web page: http://suif.stanford.edu/
The End
Overview of SUIF Components
Basic Infrastructure
Extensible IR and utilities
PGI Fortran, EDG C/C++, Java FE
Standard IR, OSUIF (for OO lang)
Hoof: Suif object specification language
SUIF1 / SUIF2 translators
Statement dismantlers
Suifbrowser
Modular compiler system
Pass submodule
Backend Infrastructure
Optimization framework
Register allocation
Scheduling
Alpha code generator, x86 code generator
HL Analysis Infrastructure
Graphs, sccs
Presburger arithmetic (omega)
Farkas lemma&“Gaussian Elimination”
Interprocedural framework
Garbage collection (Boehm’s)
Released
Call graph
Affine partitioning for parallelism & locality
Steensgaard’s alias analysis
Interprocedural parallelization:
array/scalar dependence/privatization
Pre-release
In progress
Comments
Will never implement such a system if not for the infrastructure project
Enables safe type casting of objects
All objects created via factories
Owner edges embed a tree into program representation