Download presentation
Presentation is loading. Please wait.
Published byBennett Thompson Modified over 6 years ago
1
Introduction to Advanced Topics Chapter 1 Text Book: Advanced compiler Design implementation By Steven S Muchnick (Elsevier)
2
Outline Review of compiler structure
Advanced issues in elementary topics The importance of optimizations Structure of optimizing compilers Placement of optimizations Advanced topics
3
Compiler Structure String of characters Scanner tokens Parser
Symbol table and access routines AST OS Interface Semantic analyzer IR Code Generator Object code
4
Advanced Issues in Elementary Topics
Symbol table management(3) Efficiency Overloading Type Inference Intermediate Language Selection(4) Run-Time Support(5) Producing Code Generators (6)
5
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
6
IRs in the Book LIR MIR s2 s1 v v1 HIR s4 s3 t2 v2
L1: if s2 >s6 goto L2 s7 addr a s8 4*s9 s10 s7+s8 [s10] 2 s2 s2 + s4 goto L1 L2: MIR v v1 t2 v2 t3 v3 L1: if v >t3 goto L2 t4 addr a t5 4*i t6 t4+t5 *t6 2 v v + t2 goto L1 L2: HIR for v v1 by v2 to v3 do a[i] :=2 endfor
7
Advanced Issues in Elementary Topics
Symbol table management(3) Efficiency Overloading Type Inference Intermediate Language Selection(4) Run-Time Support(5) Producing Code Generators (6)
8
Run-Time Support Data representation and instructions Register usage
Stack frames (activation records) Parameter passing disciplines Symbolic language support Garbage Collection
9
Advanced Issues in Elementary Topics
Symbol table management(3) Efficiency Overloading Type Inference Intermediate Language Selection(4) Run-Time Support(5) Producing Code Generators (6)
10
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
11
SPARC code C code ldw a, r1 ldw b, r2 add r1, r2, r3 Optimized
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
12
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
13
IR generator String Object Scanner Parser Semantic LIR generator
Optimizer Fin. assembly Tokens AST LIR Object String Scanner Parser Semantic IR generator Optimizer Code generator Tokens AST MIR LIR Post. optimizer
14
Mixed vs. Low Level Optimizers
Sun-SPARC, Dec. Alpha, SGI-MIPS, Intel’s 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
15
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
16
Data-Cache Optimizations(20)
String Scanner Tokens Parser AST Semantic HIR Data-cache optimizer MIR Object
17
IBM PowerPC compiler String Scanner Tokens Parser AST Semantic
Object Scanner Parser Semantic LIR generator Optimizer Fin. assembly Tokens AST LIR=XIL LIR Data-cache optimizer Low-to-High High-to-Low HIR=YIL
18
Outline Review of compiler structure
Advanced issues in elementary topics The importance of optimizations Structure of optimizing compilers Placement of optimizations Advanced Topics
19
Scalar replacement of array references Data-cache optimizations
Procedure integration Tail-call elimination Scalar replacement of aggregates Sparse constant propagation Interprocedural constant propagation Procedure specialization and cloning Sparse conditional constant propagation Inline expansion Leaf-routine optimizations Instruction 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 Interprocedural register allocation Interprocedural I-cache optimization Partial redundency Elimination
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.