



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of intermediate representations (ir) in compiler design. Irs are produced by the front end, transformed by the middle end, and turned into native code by the back end. The importance of ir design, the properties of irs, and the major categories of irs: structural, linear, and hybrid. Examples of irs include abstract syntax trees (ast), directed acyclic graphs (dag), three address code, quadruples, and triples. The level of abstraction of irs influences the profitability and feasibility of optimizations.
Typology: Papers
1 / 5
This page cannot be seen from the preview
Don't miss anything!




CS430 2
Front End
Middle End
Back End
Source^ IR IR Code
Target Code
CS430 3
→ Ease of generation → Ease of manipulation → Procedure size → Freedom of expression → Level of abstraction
CS430 4
Three major categories
Examples: Trees, DAGs
Examples: 3 address code Stack machine code
Example: Control-flow graph
CS430 5
subscript
A i j
loadI 1 => r 1 sub rj, r 1 => r 2 loadI 10 => r 3 mult r 2 , r 3 => r 4 sub ri, r 1 => r 5 add r 4 , r 5 => r 6 loadI @A => r 7 Add r 7 , r 6 => r 8 High level AST:Good for memory load r 8 => rAij
disambiguation (^) Low level linear code: Good for address calculation
CS430 6
10
j 1
@A
load Low level AST (^) loadArray A,i,j
High level linear code
CS430 7
An abstract syntax tree is the procedure’s parse tree with the nodes for most non-terminal nodes removed
x - 2 * y
x
2 y
CS430 8
A directed acyclic graph (DAG) is an AST with a unique node for each value
x
2 y
z (^) /
w
z ← x - 2 * y w ← x / 2
Same expression twice means that the compiler might arrange to evaluate it just once!
CS430 9
Originally used for stack-based computers, now Java
x - 2 * y becomes
Advantages
Useful where code is transmitted over slow communication links ( the net )
push x push 2 push y multiply subtract
Implicit names take up no space, where explicit ones do!
CS430 10
Several different representations of three address code
Example: z ← x - 2 * y becomes
Advantages:
t ←←←← 2 * y z ←←←← x - t
CS430 11
Naïve representation of three address code
sub 5 4 2
load 4 X
mult 3 2 1
loadi 2 2
load 1 Y load r1, y loadI r2, 2 mult r3, r2, r load r4, x sub r5, r4, r
RISC assembly code Quadruples
The original FORTRAN compiler used “quads”
CS430 12
sub (4) (3)
load x
mult (1) (2)
loadI 2
(1) load y
(2)
(3) (4) (5)
Implicit names take no space!
CS430 19
Representing the code is only part of an IR
There are other necessary components
CS430 20
CS430 21
→ Stack (for function call frames) → Heap (for dynamically allocated memory) → Constant pool (shared constant data) → Code segment (instructions of class files)
→ Stack pointer (SP), local stack pointer (LSP), program counter (PC)
CS430 22
CS430 23
CS430 24
CS430 25
CS430 26