Lecture 12: Compiler Backend
|
|
- Abigayle Cannon
- 5 years ago
- Views:
Transcription
1 CS 515 Programming Language and Compilers I Lecture 1: Compiler Backend (The lectures are based on the slides copyrighted by Keith Cooper and Linda Torczon from Rice University.) Zheng (Eddy) Zhang Rutgers University Fall 017, 1/1/017
2 Review: Compiler Middle End (Optimizer) Front End IR Middle End IR Back End Machine code Errors Front End works from the syntax of the source code Middle End works from intermediate representation (IR) Analyzes IR to learn about the code Transforms IR to improve final code s 1. Parallelization. Redundancy elimination 3. Data flow analysis (DFA) framework. Single static assignment (SSA)
3 3 Compiler Back End Source code Front End IR Middle End IR Back End Machine code Errors Back End converts intermediate representation (IR) into machine code 1. Instruction Selection: IR > Assembly code (ASM) assuming registers. Instruction Scheduling: Assembly (ASM) > Reordered assembly (ASM) 3. Register Allocation: Assembly assuming registers > Assembly assuming finite registers
4 Input to Back End Source code Front End IR Middle End IR Back End Machine code Errors Back End deals with either linear IR or treelike IR Encode information: Branches, memory tags, hierarchy of memory operations, and etc. s: clang is RISC like, gcc is a lower level, linear IR. Assumptions: Enough register names Order of operations & flow of values
5 5 Compiler Back End Instruction Selection Mapping IR into assembly code Assumes a fixed storage mapping & code shape Combining operations, using address modes Instruction Scheduling Reordering operations to hide latencies Assumes a fixed choice of operations Changes demand for registers Register Allocation Deciding which values will reside in registers Assumes a fixed order of existing operations Changes name space; may add false sharing
6 6 Compiler Back End Instruction Selection Mapping IR into assembly code Assumes a fixed storage mapping & code shape Combining operations, using address modes Instruction Scheduling Reordering operations to hide latencies Assumes a fixed choice of operations Changes demand for registers Register Allocation Deciding which values will reside in registers Assumes a fixed order of existing operations Changes name space; may add false sharing
7 7 The Fundamental Problem Consider the registertoregister copy operation Using ILOC (an RISClike intermediate representation in EAC) An obvious implementation: ii ra rb Other potential implementations (algebraic identify) addi r a,0 Þ r b subi r a,0 Þ r b lshifti r a,0 Þ r b multi r a,1 Þ r b divi r a,1 Þ r b rshifti r a,0 Þ r b ori r a,0 Þ r b xori r a,0 Þ r b and others
8 8 Instruction Selection Modeled as A Pattern Matching Method Must produce good code What is good code? Must run quickly Tree Naive Code Desired Code x loadi r5 loadao r0, r5 r6 loadai r0, r5 IDENT <a, r0, > IDENT <b, r0, 8> loadi 8 r7 loadao r0,r7 r8 loadai r0, 8 r6 mult r5, r6 r7 mult r6, r8 r9
9 9 Instruction Selection Modeled as A Pattern Matching Method Must produce good code What is good code? Must run quickly Tree Naive Code Desired Code x loadi r5 loadao r0, r5 r6 loadai r0, r5 IDENT <a, r0, > BER <> loadi r7 mult r6, r7 r8 multi r5, r7
10 10 Instruction Selection Modeled as A Pattern Matching Method Must produce good code What is good code? Must run quickly Tree Naive Code Desired Code x loadi r5 loadao r0, r5 r6 loadai r0, r5 IDENT <a, r0, > BER <> loadi r7 mult r6, r7 r8 add r5, r5 r7
11 11 Instruction Selection Modeled as A Pattern Matching Method Must produce good code What is good code? Must run quickly Tree Naive Code Desired Code IDENT <c,, > x IDENT > loadi r5 loadi r6 loadao r5, r6 r7 r8 loadi r9 loadi r5 loadai r5, r6 loadai r7 mult r6, r7 r8 common offset loadao r8, r9 r10 mult r7, r10 r11
12 1 Tree Pattern Matching Tree Patterns and LowLevel AST as Input Match treepatterns against a lowlevel AST tree Each pattern maps to a sequence of targetmachine ops a code template Each pattern is associated with a cost Tree Pattern x Template shows how to implement the subtree Cost is used to drive process to lowcost code sequences IDENT <a, r0, > BER <>
13 13 Lowlevel Abstract Syntax Tree (AST) for w x y w: at x: its reference at 6 y: at 1 : in a register : a constant : label 6 1
14 1 Tree Pattern Matching Goal is to tile the lowlevel AST Each tile corresponds to a tree pattern (also a sequence of operations) 6 1
15 15 Tiling Definition A tiling is a collection of <node, op> pairs node is a node in the AST op is a tree pattern op also represents a sequence of operations (a code template) A tiling implements an AST if it covers every node in the AST: <node, op> tiling the over lap between any two trees occurs at most at one node when two tree patterns overlap, they must be compatible
16 16 Prefix Notation A concise notation to describe the machine operations Tree Tree (r, c) (c, r) r c c r Describes both linear code IR and tree IR
17 17 Tile the Tree Specify a mapping from AST to operations Provide a set of rewrite rules that describe the AST Encode tree syntax, in linear prefix form Each rule also has a code template and a cost
18 18 Building a rule for load Tree ILOC Rule Reg load ri rj Regi (Regj)
19 19 Building a rule for loadai (load address immediate) Tree ILOC Rule loadai ri, cj rk Regk ((Regi, j)) Reg
20 0 Building a rule for loadao (load address offset) Tree ILOC Rule loadao ri, rj rk Regk ((Regi, Regj)) Reg Reg
21 1 The Simplification Step Each rule implements one operator A complex operation is broken into multiple single operator rules Reg ( (Reg1,)), cost: 1 (rule for loadai) Reg (T1), cost: 1 T1 (Reg1,), cost: 0 } Total cost is still 1 Use a unique LHS or class or type to tie them together
22 Rewrite Rules Rule Cost Template 0 Goal Goal Stmt 0 1 Goal Stmt 0 Stmt (Reg1, Reg) 1 store r r1 3 Stmt (T1, Reg3) 1 storeao r3 T1.r1, T1.r Stmt (T, Reg3) 1 storeai r3 T.r1, T.n 5 Reg 1 1 loadi l1 rnew 6 Reg Reg 1 1 loadi n1 rnew 8 Reg (Reg1) 1 load r1 rnew 9 Reg (T1) 1 loadao T1.r1, T1.r rnew 10 Reg (T) 1 loadai T.r1, T.n rnew 11 Reg (Reg1,Reg) 1 add r1, r rnew 1 Reg (Reg1,T3) 1 addi r1, n rnew 13 Reg (T31,Reg) 1 addi r, n1 rnew 1 Reg (Reg1,Reg) 1 sub r1, r rnew 15 Reg (Reg1,T3) 1 subi r1, n rnew 16 Reg (T31,Reg) 1 subi r, n1 rnew 17 Reg (Reg1,Reg) 1 mult r1, r rnew 18 Reg (Reg1,T3) 1 multi r1, n rnew 19 Reg (T31,Reg) 1 multi r, n1 rnew 0 T1 (Reg1,Reg) 0 // reg reg for loadao 1 T (Reg1, T3) 0 // reg con for loadai T (T3, Reg1) 0 // con reg for loadai 3 T3 1 0 // con for immed arith ops
23 3 Tile the Tree Tile(n) for each class c, Label(n,c) Ø if n has two children then Tile (IR left child(n)) Tile (IR right child(n)) for each rule r that implements n if (Label(IR left child(n),left(r)) Ø ) and (Label(IR right child(n),right(r)) Ø ) then Label(n, lhs(r)) Label(n,lhs(r)) U { r } else if n has one child Tile(IR child of n) for each rule r that implements n if (Label(IR child(n),rhs(r)) Ø) then Label(n,lhs(r)) Label(n,lhs(r)) U { r } else / n is a leaf / Label(n,) { all rules that implement n } class corresponds to the lhs of a rule Label(node, class) is an array of rule numbers IR left child(n) & IR right child(n) are functions to navigate the IR tree lhs(r), left(r), & right(r) return symbols in rule r. If r has children, then left & right must be classes. left(r) and right(r) navigate the pattern tree. Similar navigation primitives for unary nodes (child rather than left child) and the rules (rhs rather than left & right).
24 Tile the Tree Tile(n) for each class c, Label(n,c) Ø if n has two children then Tile (IR left child(n)) Tile (IR right child(n)) for each rule r that implements n if (Label(IR left child(n),left(r)) Ø ) and (Label(IR right child(n),right(r)) Ø ) then Label(n, lhs(r)) Label(n,lhs(r)) U { r } else if n has one child Tile(IR child of n) for each rule r that implements n if (Label(IR child(n),rhs(r)) Ø) then Label(n,lhs(r)) Label(n,lhs(r)) U { r } else / n is a leaf / Label(n,) { all rules that implement n } class corresponds to the lhs of a rule. class = Goal, or class = Reg, or Rule 0 Goal Goal Stmt 1 Goal Stmt Stmt (Reg1, Reg) 3 Stmt (T1, Reg 3 ) Stmt (T, Reg 3 ) 5 Reg 1 6 Reg 1 7 Reg 1
25 5 Tile the Tree Tile(n) for each class c, Label(n,c) Ø if n has two children then Tile (IR left child(n)) Tile (IR right child(n)) for each rule r that implements n if (Label(IR left child(n), left(r)) Ø ) and (Label(IR right child(n), right(r)) Ø ) then Label(n, lhs(r)) Label(n, lhs(r)) U { r } else if n has one child Tile(IR child of n) for each rule r that implements n if (Label(IR child(n),rhs(r)) Ø) then Label(n,lhs(r)) Label(n,lhs(r)) U { r } else / n is a leaf / Label(n,) { all rules that implement n } class corresponds to the lhs of a rule. : class = Goal, or class = Reg, or Label(node, class) is an array of rule numbers : Label(nodeA, Reg) = {6} nodea: nodeb: Rule 0 Goal Goal Stmt. 6 Reg 1
26 6 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
27 7 Step by step rewriting Stmt T1 T T3 Reg , 1 Rule 0 Goal Goal Stmt 1 Goal Stmt Stmt (Reg1, 3 Stmt (T1, Stmt (T, 5 Reg 1 6 Reg 1 7 Reg , , , , 3,
28 8 Step by step rewriting Stmt T1 T T3 Reg , 1 Rule 0 Goal Goal Stmt 1 Goal Stmt Stmt (Reg1, 3 Stmt (T1, Stmt (T, 5 Reg 1 6 Reg 1 7 Reg , , , , 3,
29 9 Step by step rewriting Stmt T1 T T3 Reg , 1 Rule 0 Goal Goal Stmt 1 Goal Stmt Stmt (Reg1, 3 Stmt (T1, Stmt (T, 5 Reg 1 6 Reg 1 7 Reg , , , 19 3 T // constant for immed arith ops 16, 3,
30 30 Step by step rewriting Stmt T1 T T3 Reg , 1 Rule 0 Goal Goal Stmt 1 Goal Stmt Stmt (Reg1, 3 Stmt (T1, Stmt (T, 5 Reg 1 6 Reg 1 7 Reg , , , 19 3 T // constant for immed arith ops 16, 3,
31 31 Step by step rewriting Stmt T1 T T3 Reg {Reg} {T3, Reg} , 1 1 Goal Goal Stmt 11 Reg (Reg 1,Reg ) Reg (Reg 1,T3 ) , 1 0 T1 (Reg 1,Reg ) 1 T (Reg 1, T3) 1 17, , 3,
32 3 Step by step rewriting Stmt T1 T T3 Reg , {Reg} {T3, Reg} , 1 1 Goal Goal Stmt 11 Reg (Reg 1,Reg ) Reg (Reg 1,T3 ) , 1 0 T1 (Reg 1,Reg ) 1 T (Reg 1, T3) 1 17, , 3,
33 33 Step by step rewriting Stmt T1 T T3 Reg , {Reg} {T3, Reg} , 1 1 Goal Goal Stmt 11 Reg (Reg 1,Reg ) Reg (Reg 1,T3 ) , 1 0 T1 (Reg 1,Reg ) 1 T (Reg 1, T3) 1 17, , 3,
34 3 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
35 35 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
36 36 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
37 37 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
38 38 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
39 39 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
40 0 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
41 1 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
42 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
43 3 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
44 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
45 5 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
46 6 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
47 7 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
48 8 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
49 9 Step by step rewriting 6 Label(1, Reg) = { rule 11, rule 1 } 1 Stmt T1 T T3 Reg , , , , , 3,
50 50 Step by step rewriting Stmt T1 T T3 Reg , , , , , 3,
51 51 Cost Selection When there are multiple rules for one tree node Rule 8: requires 11, 6, 7 Rule 9: requires 0, 6, 7 Rule 10: requires 1, 6, Stmt T1 T T3 Reg , , 1 Rule Reg (Reg1) 1 load r1 rnew 9 Reg 11 (T1) 1 loadao 3T1.r1, T1.r 7 rnew 10 Reg (T) 1 loadai T.r1, T.n rnew , 1 0 T1 (Reg1,Reg) 0 // reg reg for loadao 1 T (Reg1, T3) 0 // reg con for loadai 1 17, 19 6 Reg Reg 1 1 loadi n1 rnew , 3, Cost Template 3 T3 1 0 // con for immed arith ops 11 Reg (Reg1,Reg) 1 add r1, r rnew 1 Reg (Reg1,T3) 1 addi r1, n rnew
52 5 Cost Selection When there are multiple rules for one tree node Rule 8: requires 11, 6, 7 Rule 9: requires 0, 6, 7 Rule 10: requires 1, 6, Node 7 Stmt T1 T T3 Reg , , 1 Rule Reg (Reg1) 1 load r1 rnew 9 Reg 11 (T1) 1 loadao 3T1.r1, T1.r 7 rnew 10 Reg (T) 1 loadai T.r1, T.n rnew , 1 0 T1 (Reg1,Reg) 0 // reg reg for loadao 1 T (Reg1, T3) 0 // reg con for loadai 1 17, 19 6 Reg Reg 1 1 loadi n1 rnew , 3, Cost Template 3 T3 1 0 // con for immed arith ops 11 Reg (Reg1,Reg) 1 add r1, r rnew 1 Reg (Reg1,T3) 1 addi r1, n rnew
53 53 Cost Selection When there are multiple rules for one tree node Rule 8: requires 11, 6, 7 Rule 9: requires 0, 6, 7 Rule 10: requires 1, 6, Node 7 Node 6 1 Stmt T1 T T3 Reg , , 1 Rule Reg (Reg1) 1 load r1 rnew 9 Reg 11 (T1) 1 loadao 3T1.r1, T1.r 7 rnew 10 Reg (T) 1 loadai T.r1, T.n rnew , 1 0 T1 (Reg1,Reg) 0 // reg reg for loadao 1 T (Reg1, T3) 0 // reg con for loadai 1 17, 19 6 Reg Reg 1 1 loadi n1 rnew , 3, Cost Template 3 T3 1 0 // con for immed arith ops 11 Reg (Reg1,Reg) 1 add r1, r rnew 1 Reg (Reg1,T3) 1 addi r1, n rnew
54 5 Cost Selection When there are multiple rules for one tree node Rule 8: requires 11, 6, 7 Rule 9: requires 0, 6, 7 Rule 10: requires 1, 6, Node 7 Node 6 1 Node Node 5 Stmt T1 T T3 Reg , , 1 Rule Reg (Reg1) 1 load r1 rnew 9 Reg 11 (T1) 1 loadao 3T1.r1, T1.r 7 rnew 10 Reg (T) 1 loadai T.r1, T.n rnew , 1 0 T1 (Reg1,Reg) 0 // reg reg for loadao 1 T (Reg1, T3) 0 // reg con for loadai 1 17, 19 6 Reg Reg 1 1 loadi n1 rnew , 3, Cost Template 3 T3 1 0 // con for immed arith ops 11 Reg (Reg1,Reg) 1 add r1, r rnew 1 Reg (Reg1,T3) 1 addi r1, n rnew
55 Tile the Tree A Further Optimization 55 Tile(n) for each class c, Label(n,c) Ø if n has two children then Tile (IR left child(n)) Tile (IR right child(n)) for each rule r that implements n if (Label(IR left child(n),left(r)) Ø ) and (Label(IR right child(n),right(r)) Ø ) then Label(n,lhs(r)) Label(n,lhs(r)) U { r } else if n has one child Tile(IR child of n) for each rule r that implements n if (Label(IR child(n),rhs(r)) Ø) then Label(n,lhs(r)) Label(n,lhs(r)) { r } else / n is a leaf / Label(n,) { all rules that implement n } Cost(n, ) {costs corresponding to precomputed set of rules} For a particular node n in the IR tree and a particular class c, we only need to track the lowestcost match. That is, Label(n, c) contains only one match at any point of tree pattern matching. Cost(n,c) largest integer NewCost RuleCost(r) Cost(n,left(r)) Cost(n,right(r)) If (NewCost < Cost(n,lhs(r)) then Label(n,lhs(r)) r Cost(n,lhs(r)) NewCost NewCost RuleCost(r) Cost(n,rhs(r)) If (NewCost < Cost(n,lhs(r)) then Label(n,lhs(r)) r Cost(n,lhs(r)) NewCost
56 56 Code Generation Two step process: mark the choices & emit the code Pass 1: Walk the tree, top to bottom, and mark choice of rules If we have a choice, pick the low cost label. Choice of one tile often determines the choices at its subtrees. Pass : Walk the tree, bottom to top, and emit code Tie together tiles with temporary register names. Stmt T1 T T3 Reg One node might correspond to different classes (lhs)
57 Reading Engineering A Compiler Chapter 11
Instruction Selection, II Tree-pattern matching
Instruction Selection, II Tree-pattern matching Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 4 at Rice University have explicit permission
More informationInstruction Selection: Preliminaries. Comp 412
COMP 412 FALL 2017 Instruction Selection: Preliminaries Comp 412 source code Front End Optimizer Back End target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled
More informationInstruction Selection: Peephole Matching. Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Instruction Selection: Peephole Matching Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. The Problem Writing a compiler is a lot of work Would like to reuse components
More informationInstruction Selection and Scheduling
Instruction Selection and Scheduling The Problem Writing a compiler is a lot of work Would like to reuse components whenever possible Would like to automate construction of components Front End Middle
More informationCS 406/534 Compiler Construction Instruction Selection and Global Register Allocation
CS 406/534 Compiler Construction Instruction Selection and Global Register Allocation Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith
More informationIntroduction to Optimization, Instruction Selection and Scheduling, and Register Allocation
Introduction to Optimization, Instruction Selection and Scheduling, and Register Allocation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Traditional Three-pass Compiler
More informationTopic 6 Basic Back-End Optimization
Topic 6 Basic Back-End Optimization Instruction Selection Instruction scheduling Register allocation 2008/4/8 \course\cpeg421-08s\topic-6.ppt 1 ABET Outcome Ability to apply knowledge of basic code generation
More informationCS415 Compilers Register Allocation. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Register Allocation These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Review: The Back End IR Instruction Selection IR Register
More informationCSE 504: Compiler Design. Instruction Selection
Instruction Selection Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Instruction Selection techniques Tree Walk Tiling based approach Peephole Optimization Instruction Selection Difficulty of Instruction
More informationAgenda. CSE P 501 Compilers. Big Picture. Compiler Organization. Intermediate Representations. IR for Code Generation. CSE P 501 Au05 N-1
Agenda CSE P 501 Compilers Instruction Selection Hal Perkins Autumn 2005 Compiler back-end organization Low-level intermediate representations Trees Linear Instruction selection algorithms Tree pattern
More informationCS415 Compilers. Instruction Scheduling and Lexical Analysis
CS415 Compilers Instruction Scheduling and Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Instruction Scheduling (Engineer
More informationCS415 Compilers. Intermediate Represeation & Code Generation
CS415 Compilers Intermediate Represeation & Code Generation These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Review - Types of Intermediate Representations
More informationThe ILOC Simulator User Documentation
The ILOC Simulator User Documentation Spring 2015 Semester The ILOC instruction set is taken from the book, Engineering A Compiler, published by the Morgan- Kaufmann imprint of Elsevier [1]. The simulator
More informationThe ILOC Simulator User Documentation
The ILOC Simulator User Documentation Comp 506, Spring 2017 The ILOC instruction set is taken from the book, Engineering A Compiler, published by the Morgan- Kaufmann imprint of Elsevier [1]. The simulator
More informationGenerating Code for Assignment Statements back to work. Comp 412 COMP 412 FALL Chapters 4, 6 & 7 in EaC2e. source code. IR IR target.
COMP 412 FALL 2017 Generating Code for Assignment Statements back to work Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights
More informationCopyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies
More informationIntermediate Representations
COMP 506 Rice University Spring 2018 Intermediate Representations source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students
More informationThe ILOC Simulator User Documentation
The ILOC Simulator User Documentation COMP 412, Fall 2015 Documentation for Lab 1 The ILOC instruction set is taken from the book, Engineering A Compiler, published by the Elsevier Morgan-Kaufmann [1].
More informationImplementing Control Flow Constructs Comp 412
COMP 412 FALL 2018 Implementing Control Flow Constructs Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students
More informationComputing Inside The Parser Syntax-Directed Translation, II. Comp 412 COMP 412 FALL Chapter 4 in EaC2e. source code. IR IR target.
COMP 412 FALL 20167 Computing Inside The Parser Syntax-Directed Translation, II Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2017, Keith D. Cooper & Linda Torczon, all
More informationIntermediate Representations
Most of the material in this lecture comes from Chapter 5 of EaC2 Intermediate Representations Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP
More informationCS415 Compilers. Lexical Analysis
CS415 Compilers Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Lecture 7 1 Announcements First project and second homework
More informationCode Shape II Expressions & Assignment
Code Shape II Expressions & Assignment Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make
More informationCS5363 Final Review. cs5363 1
CS5363 Final Review cs5363 1 Programming language implementation Programming languages Tools for describing data and algorithms Instructing machines what to do Communicate between computers and programmers
More informationCS 406/534 Compiler Construction Putting It All Together
CS 406/534 Compiler Construction Putting It All Together Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy
More informationLocal Register Allocation (critical content for Lab 2) Comp 412
Updated After Tutorial COMP 412 FALL 2018 Local Register Allocation (critical content for Lab 2) Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda
More informationIntroduction to Compiler
Formal Languages and Compiler (CSE322) Introduction to Compiler Jungsik Choi chjs@khu.ac.kr 2018. 3. 8 Traditional Two-pass Compiler Source Front End Back End Compiler Target High level functions Recognize
More informationComputing Inside The Parser Syntax-Directed Translation, II. Comp 412
COMP 412 FALL 2018 Computing Inside The Parser Syntax-Directed Translation, II Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights
More informationMODULE 32 DAG based Code Generation and Dynamic Programming
MODULE 32 DAG based Code Generation and Dynamic Programming In this module, we would try to understand the code generation algorithm from DAG after the DAG has been reordered and labeled. As another approach
More informationIntermediate Code Generation (ICG)
Intermediate Code Generation (ICG) Transform AST to lower-level intermediate representation Basic Goals: Separation of Concerns Generate efficient code sequences for individual operations Keep it fast
More informationCS 406/534 Compiler Construction Instruction Scheduling
CS 406/534 Compiler Construction Instruction Scheduling Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy
More informationThe Software Stack: From Assembly Language to Machine Code
COMP 506 Rice University Spring 2018 The Software Stack: From Assembly Language to Machine Code source code IR Front End Optimizer Back End IR target code Somewhere Out Here Copyright 2018, Keith D. Cooper
More informationLocal Optimization: Value Numbering The Desert Island Optimization. Comp 412 COMP 412 FALL Chapter 8 in EaC2e. target code
COMP 412 FALL 2017 Local Optimization: Value Numbering The Desert Island Optimization Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon,
More informationIntermediate Representations
Intermediate Representations Intermediate Representations (EaC Chaper 5) Source Code Front End IR Middle End IR Back End Target Code Front end - produces an intermediate representation (IR) Middle end
More informationCS 406/534 Compiler Construction Instruction Scheduling beyond Basic Block and Code Generation
CS 406/534 Compiler Construction Instruction Scheduling beyond Basic Block and Code Generation Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on
More informationHandling Assignment Comp 412
COMP 412 FALL 2018 Handling Assignment Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp
More informationCompiler Optimisation
Compiler Optimisation 1 Introductory Lecture Hugh Leather IF 1.18a hleather@inf.ed.ac.uk Institute for Computing Systems Architecture School of Informatics University of Edinburgh 2018 Textbooks Engineering
More informationParsing II Top-down parsing. Comp 412
COMP 412 FALL 2018 Parsing II Top-down parsing Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled
More informationCode Shape Comp 412 COMP 412 FALL Chapters 4, 5, 6 & 7 in EaC2e. source code. IR IR target. code. Front End Optimizer Back End
COMP 412 FALL 2017 Code Shape Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at
More informationCS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Overview of the Course These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Critical Facts Welcome to CS415 Compilers Topics in the
More informationIntermediate Representations
Intermediate Representations Where In The Course Are We? Rest of the course: compiler writer needs to choose among alternatives Choices affect the quality of compiled code time to compile There may be
More informationCS 314 Principles of Programming Languages Fall 2017 A Compiler and Optimizer for tinyl Due date: Monday, October 23, 11:59pm
CS 314 Principles of Programming Languages Fall 2017 A Compiler and Optimizer for tinyl Due date: Monday, October 23, 11:59pm THIS IS NOT A GROUP PROJECT! You may talk about the project and possible solutions
More informationLexical Analysis. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.
Lexical Analysis Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved.
More informationIntermediate Representations Part II
Intermediate Representations Part II Types of Intermediate Representations Three major categories Structural Linear Hybrid Directed Acyclic Graph A directed acyclic graph (DAG) is an AST with a unique
More informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationThe structure of a compiler
The structure of a compiler O(n) A compiler is a lot of fast stuff followed by hard problems scanning parsing intermediate code generation Polynomial time Code optimization: local dataflow, global dataflow,
More informationCS 406/534 Compiler Construction Parsing Part I
CS 406/534 Compiler Construction Parsing Part I Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy and Dr.
More informationParsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.
Parsing Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students
More informationopt. front end produce an intermediate representation optimizer transforms the code in IR form into an back end transforms the code in IR form into
Intermediate representations source code front end ir opt. ir back end target code front end produce an intermediate representation (IR) for the program. optimizer transforms the code in IR form into an
More informationSemantic actions for expressions
Semantic actions for expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate representations
More informationIntermediate Code & Local Optimizations
Lecture Outline Intermediate Code & Local Optimizations Intermediate code Local optimizations Compiler Design I (2011) 2 Code Generation Summary We have so far discussed Runtime organization Simple stack
More informationData Structures and Algorithms in Compiler Optimization. Comp314 Lecture Dave Peixotto
Data Structures and Algorithms in Compiler Optimization Comp314 Lecture Dave Peixotto 1 What is a compiler Compilers translate between program representations Interpreters evaluate their input to produce
More informationCS 432 Fall Mike Lam, Professor. Code Generation
CS 432 Fall 2015 Mike Lam, Professor Code Generation Compilers "Back end" Source code Tokens Syntax tree Machine code char data[20]; int main() { float x = 42.0; return 7; } 7f 45 4c 46 01 01 01 00 00
More informationClass Information ANNOUCEMENTS
Class Information ANNOUCEMENTS Third homework due Friday, October 13, 11:59pm. First project will be posted soon. Midterm exam: Friday, October 27, in class. Don t forget to work on your C and Linux skills
More informationFront End. Hwansoo Han
Front nd Hwansoo Han Traditional Two-pass Compiler Source code Front nd IR Back nd Machine code rrors High level functions Recognize legal program, generate correct code (OS & linker can accept) Manage
More informationIntermediate Code & Local Optimizations. Lecture 20
Intermediate Code & Local Optimizations Lecture 20 Lecture Outline Intermediate code Local optimizations Next time: global optimizations 2 Code Generation Summary We have discussed Runtime organization
More informationLab 3, Tutorial 1 Comp 412
COMP 412 FALL 2018 Lab 3, Tutorial 1 Comp 412 source code IR IR Front End Optimizer Back End target code Copyright 2018, Keith D. Cooper, Linda Torczon & Zoran Budimlić, all rights reserved. Students enrolled
More informationAcknowledgement. CS Compiler Design. Intermediate representations. Intermediate representations. Semantic Analysis - IR Generation
Acknowledgement CS3300 - Compiler Design Semantic Analysis - IR Generation V. Krishna Nandivada IIT Madras Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all
More informationCS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Syntax Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Limits of Regular Languages Advantages of Regular Expressions
More information(just another operator) Ambiguous scalars or aggregates go into memory
Handling Assignment (just another operator) lhs rhs Strategy Evaluate rhs to a value (an rvalue) Evaluate lhs to a location (an lvalue) > lvalue is a register move rhs > lvalue is an address store rhs
More informationCode Generation. M.B.Chandak Lecture notes on Language Processing
Code Generation M.B.Chandak Lecture notes on Language Processing Code Generation It is final phase of compilation. Input from ICG and output in the form of machine code of target machine. Major issues
More informationSyntax Analysis, III Comp 412
Updated algorithm for removal of indirect left recursion to match EaC3e (3/2018) COMP 412 FALL 2018 Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, III Comp 412 source code
More informationCSE P 501 Compilers. Register Allocation Hal Perkins Autumn /22/ Hal Perkins & UW CSE P-1
CSE P 501 Compilers Register Allocation Hal Perkins Autumn 2011 11/22/2011 2002-11 Hal Perkins & UW CSE P-1 Agenda Register allocation constraints Local methods Faster compile, slower code, but good enough
More informationCSE 401/M501 Compilers
CSE 401/M501 Compilers Intermediate Representations Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 G-1 Agenda Survey of Intermediate Representations Graphical Concrete/Abstract Syntax Trees (ASTs)
More informationCompiler Design. Code Shaping. Hwansoo Han
Compiler Design Code Shaping Hwansoo Han Code Shape Definition All those nebulous properties of the code that impact performance & code quality Includes code, approach for different constructs, cost, storage
More informationSyntax Analysis, III Comp 412
COMP 412 FALL 2017 Syntax Analysis, III Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp
More informationAlternatives for semantic processing
Semantic Processing Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies
More informationCSE P 501 Compilers. Instruc7on Selec7on Hal Perkins Winter UW CSE P 501 Winter 2016 N-1
CSE P 501 Compilers Instruc7on Selec7on Hal Perkins Winter 2016 UW CSE P 501 Winter 2016 N-1 Agenda Compiler back- end organiza7on Instruc7on selec7on tree padern matching Credits: Slides by Keith Cooper
More informationCompilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam
Compilers Intermediate representations and code generation Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Today Intermediate representations and code generation Scanner Parser Semantic
More informationRegister Allocation. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.
Register Allocation Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP at Rice. Copyright 00, Keith D. Cooper & Linda Torczon, all rights reserved.
More informationLecture Compiler Middle-End
Lecture 16-18 18 Compiler Middle-End Jianwen Zhu Electrical and Computer Engineering University of Toronto Jianwen Zhu 2009 - P. 1 What We Have Done A lot! Compiler Frontend Defining language Generating
More informationSyntax Analysis, V Bottom-up Parsing & The Magic of Handles Comp 412
Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, V Bottom-up Parsing & The Magic of Handles Comp 412 COMP 412 FALL 2018 source code IR Front End Optimizer Back End IR target
More informationLecture Outline. Intermediate code Intermediate Code & Local Optimizations. Local optimizations. Lecture 14. Next time: global optimizations
Lecture Outline Intermediate code Intermediate Code & Local Optimizations Lecture 14 Local optimizations Next time: global optimizations Prof. Aiken CS 143 Lecture 14 1 Prof. Aiken CS 143 Lecture 14 2
More informationInstruction Scheduling
Instruction Scheduling Michael O Boyle February, 2014 1 Course Structure Introduction and Recap Course Work Scalar optimisation and dataflow L5 Code generation L6 Instruction scheduling Next register allocation
More informationComputing Inside The Parser Syntax-Directed Translation. Comp 412 COMP 412 FALL Chapter 4 in EaC2e. source code. IR IR target.
COMP 412 FALL 2017 Computing Inside The Parser Syntax-Directed Translation Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights
More informationIntermediate Representations & Symbol Tables
Intermediate Representations & Symbol Tables Copyright 2014, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission
More informationGoal is to produce more ecient code for expressions
Better code generation Goal is to produce more ecient code for expressions We consider directed acyclic graphs (DAG) \optimal" register allocation for trees Sethi-Ullman \more optimal" register allocation
More informationCS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction
CS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith
More informationCS 432 Fall Mike Lam, Professor. Data-Flow Analysis
CS 432 Fall 2018 Mike Lam, Professor Data-Flow Analysis Compilers "Back end" Source code Tokens Syntax tree Machine code char data[20]; int main() { float x = 42.0; return 7; } 7f 45 4c 46 01 01 01 00
More informationCSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1
CSE P 501 Compilers Intermediate Representations Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 G-1 Administrivia Semantics/types/symbol table project due ~2 weeks how goes it? Should be caught up on
More informationThe View from 35,000 Feet
The View from 35,000 Feet This lecture is taken directly from the Engineering a Compiler web site with only minor adaptations for EECS 6083 at University of Cincinnati Copyright 2003, Keith D. Cooper,
More informationOperator Strength Reduc1on
COMP 512 Rice University Spring 2015 Generali*es and the Cocke- Kennedy Algorithm Copyright 2015, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University
More informationSyntax-directed translation. Context-sensitive analysis. What context-sensitive questions might the compiler ask?
Syntax-directed translation Context-sensitive analysis The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the
More informationAn Overview of Compilation
An Overview of Compilation (www.cse.iitb.ac.in/ uday) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay January 2014 cs306 Compilation Overview: Outline 1/18 Outline
More informationAdministration. Where we are. Canonical form. Canonical form. One SEQ node. CS 412 Introduction to Compilers
Administration CS 412 Introduction to Compilers Andrew Myers Cornell University Lecture 15: Canonical IR 26 Feb 01 HW3 due Friday Prelim 1 next Tuesday evening (7:30-9:30PM) location TBA covers topics
More informationLow-level optimization
Low-level optimization Advanced Course on Compilers Spring 2015 (III-V): Lecture 6 Vesa Hirvisalo ESG/CSE/Aalto Today Introduction to code generation finding the best translation Instruction selection
More informationSyntax Analysis, VI Examples from LR Parsing. Comp 412
Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, VI Examples from LR Parsing Comp 412 COMP 412 FALL 2018 source code IR IR target Front End Optimizer Back End code Copyright
More informationCompiler Optimisation
Compiler Optimisation Michael O Boyle mob@inf.e.ac.uk Room 1.06 January, 2014 1 Two recommene books for the course Recommene texts Engineering a Compiler Engineering a Compiler by K. D. Cooper an L. Torczon.
More informationCode generation for modern processors
Code generation for modern processors Definitions (1 of 2) What are the dominant performance issues for a superscalar RISC processor? Refs: AS&U, Chapter 9 + Notes. Optional: Muchnick, 16.3 & 17.1 Instruction
More informationIntroduction to Optimization Local Value Numbering
COMP 506 Rice University Spring 2018 Introduction to Optimization Local Value Numbering source IR IR target code Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights
More informationCode generation for modern processors
Code generation for modern processors What are the dominant performance issues for a superscalar RISC processor? Refs: AS&U, Chapter 9 + Notes. Optional: Muchnick, 16.3 & 17.1 Strategy il il il il asm
More informationParsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones
Parsing III (Top-down parsing: recursive descent & LL(1) ) (Bottom-up parsing) CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper,
More informationHigh-level View of a Compiler
High-level View of a Compiler Source Compiler Implications Must recognize legal (and illegal) programs Must generate correct Must manage storage of all variables (and ) Must agree with OS & linker on format
More informationThe ILOC Virtual Machine (Lab 1 Background Material) Comp 412
COMP 12 FALL 20 The ILOC Virtual Machine (Lab 1 Background Material) Comp 12 source code IR Front End OpMmizer Back End IR target code Copyright 20, Keith D. Cooper & Linda Torczon, all rights reserved.
More informationSoftware Tools for Lab 1
Software Tools for Lab 1 We have built a number of tools to help you build and debug Lab 1 An ILOC Simulator Essentially, an interpreter for Lab 1 ILOC Matches the Lab 1 specs Single functional unit, latencies
More informationIntermediate Representations
Compiler Design 1 Intermediate Representations Compiler Design 2 Front End & Back End The portion of the compiler that does scanning, parsing and static semantic analysis is called the front-end. The translation
More informationRuntime Support for Algol-Like Languages Comp 412
COMP 412 FALL 2018 Runtime Support for Algol-Like Languages Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students
More informationCode Generation. CS 540 George Mason University
Code Generation CS 540 George Mason University Compiler Architecture Intermediate Language Intermediate Language Source language Scanner (lexical analysis) tokens Parser (syntax analysis) Syntactic structure
More informationCompiler Optimization Techniques
Compiler Optimization Techniques Department of Computer Science, Faculty of ICT February 5, 2014 Introduction Code optimisations usually involve the replacement (transformation) of code from one sequence
More informationParsing II Top-down parsing. Comp 412
COMP 412 FALL 2017 Parsing II Top-down parsing Comp 412 source code IR Front End OpMmizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled
More information