Title: An Overview of the SUIF2 System
1An Overview of the SUIF2 System
- Monica Lam
- Stanford University
- http//suif.stanford.edu/
2The SUIF System
PGI Fortran
Java
EDG C
Interprocedural Analysis Parallelization Locality
Opt
Inst. Scheduling Register Allocation
SUIF2
Alpha
x86
C
3Research Infrastructure Support at 3 Levels
- I. Compose compiler with existing passes
- Front ends passes
- Easy expression of compiler compositions
(dynamically) - II. Develop new passes
- User concentrates on algorithmic issues
- Infrastructure takes care of common
functionalities - Standard intermediate representation and
associate tools - Common utilities and data structures
- III. Develop new IR (new language constructs or
analyses) - Easy definition of IR nodes
- Old code works with new IR without recompilation
4I Compose Compiler with Existing Passes
- Previous system
- Each pass is an independent program that
reads/writes SUIF in a file - Advantages modular, visibility of intermediate
results - Disadvantages expensive disk access
- New system
- write code once, can run on program on disk or in
memory - simple development, efficient deployment
- How?
- A pass a common driver module
- A compound pass
- a common driver series of modules loaded
dynamically
5Modular Compiler System
COMPILER
A driver that imports applies modules to
program in memory
A series of stand-alone programs
Suif-file1
Suif-file1
drivermodule1
Suif-file2
Suifdriver imports/executes module1 module2
module3
drivermodule2
Suif-file3
drivermodule3
Suif-file4
Suif-file4
6SUIF Driver
- gt suifdriver
- suifgt import basicnodes suifnodes
- suifgt import mylibrary
- suifgt load test.suif
- suifgt mylibrary_pass1
- suifgt print test.out
- suifgt save test.tsuif
- Suifdriver
- accepts a simple scripting language
- pre-registered modules (import, load, print,
save) - loads libraries dynamically which can register
new modules (new commands)
7The SUIF Architecture
MODULES
8Components
- 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 using a scripting language
9II. Develop a New Pass
- 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 lt-- Derive from
this framework - IR basic program representations
- Suifdriver
- provides execution control over modules and
passes using a scripting language
10Compilation System SuifEnv Modules
- SuifEnv
- Keeps the states of the compilation
- Holds onto the representation (FileSetBlock) and
the loaded 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
- no global variables
- one or more modules make up a dll
- each library includes a function (init_ltdllnamegt)
to register all modules dynamically - Registration is based on a prototype object
11Example 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 ltlt proc_def-gtget_procedure_symbol()
-gtget_name() - cout ltlt object_iteratorltExecutionObjectgt(proc_
def).length() -
-
- extern C void init_mypass (SuifEnv suif_env)
- suif_env-gtget_module_subsystem()-gtregister_module
- (new mypass (suif_env, mypass))
-
12Tools for writing passes
- Traversing and manipulating data structures
- Visitors dispatch method according to type
- Iterators simple iteration of certain objects
- Walkers user-controllable traversal of data
structures - Data structures
- Infinite precision integers
- strings
- lists, sets, hash maps
- assertion/error handling
13Program Representation
- Multiple representations for semantics at
different abstraction levels - e.g. FOR loops or statement list with branches
and jumps - High-level representation useful for high-level
transformations - gt Superset representation
- mixture of high-level and low-level constructs
- Dismantlers lower representation
- Allow analysis to operate at different levels of
abstraction - e.g. analysis may/may not care about specific
arithmetic operators - gt Uses object-oriented class hierarchy
14SUIF IR Design
- Root Object
- Uniform functionality
- Fields accessed with get_ltfieldgt, and set_ltfieldgt
- printing
- I/O to disk
- cloning
- iterators
- walkers
- Memory management aid
- object creation via factories
- owner edges embed a tree into program
representation
15Supports Code with Abstraction
ExecutionObject
Statement
get_child_statements
IfStatement
WhileStatement
get_then_part get_else_part
get_body
- Maximize reuse by abstract fields
- allow uniform access to different child
components
16III. Extending the IR
- Goals
- Support extension by different research groups
- Code written for a high-level IR should work on
refined IR (without recompilation!) - Easy specification of new extensions
- Grammar-based specification
- How?
- Meta-class system
- Objects contain information describing
representation - If environment does not include definitions of
refinements - information retained even if methods are not
available - written out when representation saved
17Insulating the User from the Implementation
Object Definition (.hoof)
SUIF Macro Generator a general grammar-based tool
Meta-Class System reading writing to file in
machine-independent format
Interface for user (.h) Implementation in
Meta-Class System (.cpp)
- Easy for the programmer
- Easy for the implementor to develop the system
18Example of a Hoof Definition
- concrete New
- int x
- class New public SuifObject
-
- public
- int get_x()
- void set_x(int the_value)
- example()
- void print()
- static const Lstring get_class_name()
-
-
- Uniform data access functions (get_ set_)
- Automatic generation of meta class information
etc.
19Examples of Suif Nodes
- abstract Statement ExecutionObject
-
- virtual listltStatement ownergt
child_statements - ...
-
- concrete IfStatement Statement
-
- Expression condition in source_ops
- Statement owner then_part in
child_statements - Statement owner else_part in
child_statements -
20Documentation
- The SUIF2 Infrastructure Guide (an index to all
documentation) - Overview of the SUIF Infrastructure
- The SUIF Representation Guide
- The Basic SUIF Programmers Guide
- Web page http//suif.stanford.edu/suif2