Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Intermediate Representation - Lecture Slides | CMSC 430, Papers of Computer Science

Material Type: Paper; Class: INTRO TO COMPILERS; Subject: Computer Science; University: University of Maryland; Term: Spring 2006;

Typology: Papers

Pre 2010

Uploaded on 07/30/2009

koofers-user-mgp
koofers-user-mgp 🇺🇸

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Intermediate Representation - Lecture Slides | CMSC 430 and more Papers Computer Science in PDF only on Docsity! Intermediate representations source code front end opt. back end target codeir ir front end produces an intermediate representation (IR) for the program. optimizer transforms the code in IR form into an equivalent program that may run more efficiently. back end transforms the code in IR form into native code for the target machine The IR encodes knowledge that the compiler has derived about the source program. CMSC 430 Lecture 8, Page 1 Intermediate representations Advantages • compiler can make multiple passes over program • break the compiler into manageable pieces • support multiple languages and architectures using multiple front & back ends • enables machine-independent optimization Desirable properties • easy & inexpensive to generate and manipulate • contains sufficient information Examples • abstract syntax tree (AST) • directed acyclic graph (DAG) • control flow graph (CFG) • three address code • stack code CMSC 430 Lecture 8, Page 2 Intermediate representations Broadly speaking, IRs fall into three categories: Structural • structural IRs are graphically oriented • examples: trees, directed acyclic graphs • heavily used in source to source translators • nodes, edges tend to be large Linear • pseudo-code for some abstract machine • large variation in level of abstraction • simple, compact data structures • easier to rearrange Hybrids • combination of graphs and linear code • attempt to take best of each • examples: control-flow graph CMSC 430 Lecture 8, Page 3 Abstract syntax tree An abstract syntax tree (AST) is the procedure’s parse tree with the nodes for most non-terminal symbols removed. - <id,x> * <num,2> <id,y> This represents “x - 2 * y”. For ease of manipulation, can use a linearized (operator) form of the tree. x 2 y * - in postfix form. CMSC 430 Lecture 8, Page 4 Directed acyclic graph A directed acyclic graph (DAG) is an AST with a unique node for each value. ← <id,x> + * sin <id,y> <num,2> * <id,x> ← <id,z> / x ← 2 * y + sin(2*x) z ← x / 2 CMSC 430 Lecture 8, Page 5 Control flow graph The control flow graph (CFG) models the transfers of control in the procedure. • nodes in the graph are basic blocks maximal-length straight-line blocks of code • edges in the graph represent control flow loops, if-then-else, case, goto Example if (x=y) then s1 else s2 s3 becomes x=y s1 s2 s3 CMSC 430 Lecture 8, Page 6 Three address code Three address code generally allow statements of the form: x ← y op z with a single operator and, at most, three names. Complex expressions like x - 2 * y are simplified to t1 ← 2 * y t2 ← x - t1 Advantages • compact form (direct naming) • names for intermediate values Register transfer language (RTL) • only load/store instructions access memory • all other operands are registers • version of three address code for RISC CMSC 430 Lecture 8, Page 7 Three address code Typical statement types 1. assignments — x ← y op z 2. assignments — x ← op y 3. assignments — x ← y[i] 4. assignments — x ← y 5. branches — goto L 6. conditional branches — if x relop y goto L 7. procedure calls — param x and call p 8. address and pointer assignments Can represent three address code using quadruples x - 2 * y (1) load t1 y (2) loadi t2 2 (3) mult t3 t2 t1 (4) load t4 x (5) sub t5 t4 t2 CMSC 430 Lecture 8, Page 8
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved