Introduction to Advanced Topics Chapter 1 - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Introduction to Advanced Topics Chapter 1

Description:

(tail-calls elimination) replacement of heap by stack. Object Oriented Programs ... Fin. assembly. Tokens. AST. AST. LIR=XIL. LIR. Data-cache optimizer. Low-to ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 29
Provided by: thoma423
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Advanced Topics Chapter 1


1
Introduction to Advanced TopicsChapter 1
  • Mooly Sagiv
  • Schrierber 317
  • 03-640-7606
  • www.math.tau.ac.il/sagiv/courses/acd.html

2
Outline
  • Course requirements
  • Review of compiler structure
  • Advanced issues inelementary topics
  • The importance of optimizations
  • Structure of optimizing compilers
  • Placement of optimizations
  • Advanced topics

3
Course Requirements
  • Prepare course notes 10
  • Theoretical assignments 30
  • Final home exam 60

4
Compiler Structure
String of characters
Scanner
tokens
Parser
Symbol table and access routines
OS Interface
AST
Semantic analyzer
IR
Code Generator
Object code
5
Advanced Issues inElementary Topics
  • Symbol table management(3)
  • Efficiency
  • Overloading
  • Type Inference
  • Intermediate Language Selection(4)
  • Run-Time Support(5)
  • Producing Code Generators (6)

6
procedure BACH is procedure put (x
boolean) is begin null end procedure put
(x float) is begin null end procedure
put (x integer) is begin null end package
x is type boolean is (false, true)
function f return boolean
-- (D1) end x package body x is
function f return boolean is begin null
end end x function f return float
is begin null end -- (D2) use
x begin put (f)
-- (A1) A declare
f integer
-- (D3) begin put (f)
-- (A2)
B declare function f return integer
is begin null end -- (D4) begin
put (f)
-- (A3) end B end A
end BACH
7
Advanced Issues inElementary Topics
  • Symbol table management(3)
  • Efficiency
  • Overloading
  • Type Inference
  • Intermediate Language Selection(4)
  • Run-Time Support(5)
  • Producing Code Generators (6)

8
Advanced Issues inElementary Topics
  • Symbol table management(3)
  • Efficiency
  • Overloading
  • Type Inference
  • Intermediate Language Selection(4)
  • Run-Time Support(5)
  • Producing Code Generators (6)

9
Intermediate Language Selection
  • Low Vs. High level control flow structures
  • Flat Vs. Hierarchical (tree)
  • Machine Vs. High level of instructions
  • (Symbolic) Registers Vs. Stack
  • Normal forms (SSA)
  • Intermediate forms Control Flow Graph, Call
    Graph, Program Dependence Graph
  • Issues Engineering, efficiency, portability,
    optimization level

10
IRs in the Book
LIR s2? s1 s4 ? s3 s6 ?
s5 L1 if s2 gts6 goto L2 s7 ? addr a
s8 ? 4s9 s10 ? s7s8 s10 ? 2
s2 ? s2 s4 goto L1 L2
MIR v? v1 t2 ? v2 t3 ?
v3 L1 if v gtt3 goto L2 t4 ? addr a
t5 ? 4i t6 ? t4t5 t6 ? 2 v
? v t2 goto L1 L2
HIR for v ?v1 by v2 to v3 do
ai 2 endfor
11
Single Static Assignment Form (SSA)
s2? s1 s4 ? s3 s6 ?
s5 L1 if s2 gts6 goto L2 s7 ? addr a
s8 ? 4s9 s10 ? s7s8 s10 ? 2
s2 ? s2 s4 L2
12
Advanced Issues inElementary Topics
  • Symbol table management(3)
  • Efficiency
  • Overloading
  • Type Inference
  • Intermediate Language Selection(4)
  • Run-Time Support(5)
  • Producing Code Generators (6)

13
Run-Time Support
  • Data representation and instructions
  • Register usage
  • Stack frames (activation records)
  • Parameter passing disciplines
  • Symbolic and polymorphic language support
  • Garbage Collection

14
Advanced Issues inElementary Topics
  • Symbol table management(3)
  • Efficiency
  • Overloading
  • Type Inference
  • Intermediate Language Selection(4)
  • Run-Time Support(5)
  • Producing Code Generators (6)

15
The Importance of Optimizations
  • One pass compilers produce slow code
  • Much of the time spent in loops
  • optimize loops
  • Machines can be simpler and faster if optimizing
    compilers are used (RISC, VLIW)
  • Programs are complex and general
  • Compilers need to be modular

16
SPARC code ldw a, r1 ldw b, r2 add r1,
r2, r3 stw r3, c ldw c, r3 add r3, 1,
r4 stw r4, d
Optimized SPARC code add r1, r2, r3 add r3,
1, r4
C code int a, b, c, d c a b d c 1
2 cycles
10 cycles
17
Application Dependent Optimizations
  • Functional programs
  • replacement of recursion by loops (tail-calls
    elimination)
  • replacement of heap by stack
  • Object Oriented Programs
  • Dead member elimination
  • Replacement of virtual by static function
  • Numeric Code
  • Database Code

18
(No Transcript)
19
Mixed vs. Low Level Optimizers
  • Mixed
  • Sun-SPARC, Dec. Alpha, SGI-MIPS, Intels 386
  • Easier to port
  • More efficient compilation?
  • Supports CISC
  • Low Level
  • HP-PA-RISC/IBM-Power PC
  • More efficient code
  • Conceptually simpler (in RISC)
  • Used for multiple programming languages

20
Translation by Preprocessing
  • Some programming languages are translated into C
  • Elimination of includes, C(cfront), Haskel
  • Quick and portable solution
  • C supports some indirect source level debugging
  • Other examples Fortran into vector Fortran
    program

21
Data-Cache Optimizations(20)
String
Scanner
Tokens
Parser
AST
Semantic
HIR
Data-cache optimizer
MIR
?
Object
22
IBM PowerPC compiler
23
Outline
  • Review of compiler structure
  • Advanced issues inelementary topics
  • The importance of optimizations
  • Structure of optimizing compilers
  • Placement of optimizations
  • Advanced Topics

24
Scalar replacement of array references Data-cache
optimizations
Procedure integration Tail-call
elimination Scalar replacement of
aggregates Sparse constant propagation Interproced
ural constant propagation Procedure
specialization and cloning Sparse conditional
constant propagation
Inline expansion Leaf-routine optimizations Instru
ction Scheduling 1 Register allocation Instruction
Scheduling 2 Intraprocedural I-cache
optimizations Instruction prefetching Data
prefertching Branch predication
Global value numbering Local and global copy
propagation Sparse conditional constant
propagation Dead code elimination
Common Subexpression Elimination Loop invariant
code motion
Partial redundency Elimination
Interprocedural register allocation Interprocedura
l I-cache optimization
25
Scalar replacement after constant propagation
c ? B.x
a? 1 a 1
N
Y
B.x? 1.0 B.y ? 1.0
c
read B.x read B.y
B.x 1.0
c
Y
N
26
Scalar replacement before constant propagation
d ? B.x
B.x ? 1.0 c ? 2 read B.y B.x 1.0
d
d
N
Y
B.x ? B.x c
d
d
27
Theoretically Open Questions
  • Picking the right order
  • Combining optimizations
  • Proving correctness

28
Tentative Schedule
  • 30/3 Introduction(1)
  • 13/4 No class (read Chapter 2 and solve Homework
    1)
  • 20/4 Yom Hazikaron
  • 24/4 9am, Intermediate Representations(4)
  • 27/4 Control Flow Analysis (7)
  • 4/5 Data Flow Analysis (8)
  • 11/5 Dependence Analysis and Dependence Graphs(9)
  • 18/5 Introduction to Optimization(11)
  • 25/5 Early Optimizations (12)
  • 1/6 Redundancy Elimination (13)
  • 8/6 Loop Optimizations (14)
  • 7/6 Interprocedural Analysis and Optimizations
    (19)
  • 14/6 Optimizations for memory hierarchy (20)
  • 21/6 Case Studies of Compilers and Future Trends
    (21)

29
Uncovered Chapters
  • Symbol tables(3)
  • Run-time support(5)
  • Producing code generators automatically (6)
  • Alias analysis(10)
  • Procedure optimizations (15)
  • Register allocation (16)
  • Code scheduling (17)
  • Control-Flow and Low-Level Optimizations (18)

30
Uncovered Topics
  • Code profiling
  • Source level debugging
  • Parallelization and vectorization
  • Just in time compilation

31
Advanced Topics
  • Code Profiling
  • Parallelization and vectorization
  • Just in time compilation
  • Optimize for Power
  • Trusted compilers
Write a Comment
User Comments (0)
About PowerShow.com