Generating Code From DAGs Directed Ascyclic Graph (DAG) A tree structure such that nodes may have more than one parent Multiple parents are allowed so.

Slides:



Advertisements
Similar presentations
Example of Constructing the DAG (1)t 1 := 4 * iStep (1):create node 4 and i 0 Step (2):create node Step (3):attach identifier t 1 (2)t 2 := a[t 1 ]Step.
Advertisements

Tiling Examples for X86 ISA Slides Selected from Radu Ruginas CS412/413 Lecture on Instruction Selection at Cornell.
CSCI 4717/5717 Computer Architecture
An Array-Based Algorithm for Simultaneous Multidimensional Aggregates By Yihong Zhao, Prasad M. Desphande and Jeffrey F. Naughton Presented by Kia Hall.
Lecture 11: Code Optimization CS 540 George Mason University.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Architecture-dependent optimizations Functional units, delay slots and dependency analysis.
ECE Synthesis & Verification - Lecture 2 1 ECE 667 Spring 2011 ECE 667 Spring 2011 Synthesis and Verification of Digital Circuits High-Level (Architectural)
Data Dependencies Describes the normal situation that the data that instructions use depend upon the data created by other instructions, or data is stored.
1 CS 201 Compiler Construction Machine Code Generation.
SSA.
DMOR Branch and bound. Integer programming Modelling logical constraints and making them linear: – Conjuction – Disjunction – Implication – Logical constraints.
CSC 213 – Large Scale Programming or. Today’s Goals  Begin by discussing basic approach of quick sort  Divide-and-conquer used, but how does this help?
Stanford University CS243 Winter 2006 Wei Li 1 SSA.
Parallel Scheduling of Complex DAGs under Uncertainty Grzegorz Malewicz.
File Management Chapter 12. File Management A file is a named entity used to save results from a program or provide data to a program. Access control.
1 IF IDEX MEM L.D F4,0(R2) MUL.D F0, F4, F6 ADD.D F2, F0, F8 L.D F2, 0(R2) WB IF IDM1 MEM WBM2M3M4M5M6M7 stall.
Lecture 26 Epilogue: Or Everything else you Wanted to Know about Compilers (more accurately Everything else I wanted you to Know) Topics Getreg – Error.
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
1 Handling nested procedures Method 1 : static (access) links –Reference to the frame of the lexically enclosing procedure –Static chains of such links.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
EECC551 - Shaaban #1 Spring 2004 lec# Static Compiler Optimization Techniques We already examined the following static compiler techniques aimed.
EECC551 - Shaaban #1 Winter 2003 lec# Static Compiler Optimization Techniques We already examined the following static compiler techniques aimed.
Arithmetic Expression Consider the expression arithmetic expression: (a – b) + ((c + d) + (e * f)) that can be represented as the following tree.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
Improving Code Generation Honors Compilers April 16 th 2002.
Register Tracking Register tracking improves on a simple code generator Uses a simple local register allocation scheme in which the contents of allocatable.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
EECC551 - Shaaban #1 Winter 2002 lec# Static Compiler Optimization Techniques We already examined the following static compiler techniques aimed.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Saman Amarasinghe ©MIT Fall 1998 Simple Machine Model Instructions are executed in sequence –Fetch, decode, execute, store results –One instruction.
CS420 lecture eight Greedy Algorithms. Going from A to G Starting with a full tank, we can drive 350 miles before we need to gas up, minimize the number.
Register Allocation and Spilling via Graph Coloring G. J. Chaitin IBM Research, 1982.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Computer Organization and Architecture Reduced Instruction Set Computers (RISC) Chapter 13.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Computer Science and Software Engineering University of Wisconsin - Platteville 12. Heap Yan Shi CS/SE 2630 Lecture Notes Partially adopted from C++ Plus.
Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2004 Simonas Šaltenis E1-215b
Chapter pages1 File Management Chapter 12.
Fall 2002 Lecture 14: Instruction Scheduling. Saman Amarasinghe ©MIT Fall 1998 Outline Modern architectures Branch delay slots Introduction to.
Data Structures : Project 5 Data Structures Project 5 – Expression Trees and Code Generation.
Compiler Construction
Tot 15 LTPDA Graphic User Interface summary and status N. Tateo 26/06/2007.
EKT 221/4 DIGITAL ELECTRONICS II  Registers, Micro-operations and Implementations - Part3.
CSC 107 – Programming For Science. Today’s Goal  When lecture over, start understanding pointers  What a pointer is and what it is not  Why pointers.
Lectures on Greedy Algorithms and Dynamic Programming
Union-find Algorithm Presented by Michael Cassarino.
Procedures – Generating the Code Lecture 21 Mon, Apr 4, 2005.
Intermediate Code Representations
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
© University of Auckland Trees – (cont.) CS 220 Data Structures & Algorithms Dr. Ian Watson.
Lecture 8 : Priority Queue Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
More on Loop Optimization Data Flow Analysis CS 480.
POWERS and ORDER of OPERATIONS PRE265 Parentheses (includes brackets) Exponents & Roots Multiplication & Division (left to right) Addition & Subtraction.
Reading data into sorted list Want to suck text file in and produce sorted list of the contents: Option 1 : read directly into array based list, sort afterwards.
Cartesian Trees Amihood Amir Bar-Ilan University.
Autumn 2006CSE P548 - Dataflow Machines1 Von Neumann Execution Model Fetch: send PC to memory transfer instruction from memory to CPU increment PC Decode.
B Tree Insertion (ID)‏ Suppose we want to insert 60 into this order 3 B-Tree Starting at the root: 10 < 60 < 88, so we look to the middle child. Since.
More Code Generation and Optimization Pat Morin COMP 3002.
CMSC 341 Lecture 13 Leftist Heaps
Unit IV Code Generation
CS 201 Compiler Construction
UNIT V Run Time Environments.
Minimum Spanning Tree.
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Compiler Construction
Graphs & Trees.
B Tree Insertion (ID)‏ Suppose we want to insert 60 into this order 3 B-Tree Starting at the root: 10 < 60 < 88, so we look to the middle child. Since.
Presentation transcript:

Generating Code From DAGs Directed Ascyclic Graph (DAG) A tree structure such that nodes may have more than one parent Multiple parents are allowed so that an expression can be used more than once

Redundant Expressions DAG for (a+b)+(a+b) b + a +

Updated Variables The expression i = i + 1 with updated variable highlighted 1 +(i) i

Code to Optimize g = c * (a + b) + (a + b) c = a + b a = (c * d) + (e – f)

Convert Code to Trees + = g + * + c b a ba + = c d c + = a – * f e b a

Convert Tree to DAG + (G) * + c b a * + (C)+ (C) c b a * + (C)+ (C) c – * f e d +(A) b a

Schedule DAG Nodes The first operator scheduled will be the last evaluated Because a DAG can have more than one root, start at rightmost root Nodes are added to DAG from left to right, so rightmost is the last to be created and added to graph Work left-to-right within sub-DAG scheduling each operator in turn Within a sub-DAG, schedule an operator if all of its parents have been scheduled

Scheduled Nodes b a + 4 (G) * (C) c – 3 * 2 f e d + 1 (A)

Determining Virtual Registers Start at node with schedule number 1 Assign the node that currently has the lowest schedule number m and has not already been assigned to a register set to the next sequential virtual register set Vn, where n = 1,2, … Recursively assign each left node in the tree under m to virtual register set Vn so long as its lowest schedule number parent belongs to Vn Continue until all nodes are assigned virtual regisers

Virtual Registers Assigned b a + 4 (G) V3 * 5 V3 + 6 (C) V1 c – 3 V2 * 2 V1 f e d + 1 (A) V1

Virtual Register Span A virtual register’s span is the nodes it is needed for Two virtual registers may be mapped into the same hardware registers if their spans do not overlap V1 is mapped alone to R1 since its span is from node 1 to node 6 V2 and V3 are mapped into R2 since their spans do not overlap RegisterSpan V1 V2 V

Code Generation Generate code from highest schedule number to lowest schedule number Make sure that register that is saved is real register that virtual register at that node maps to Delay stores until code for lowest schedule number parent is about to be output

Code Generation (1) Load a, r1(7) Load e, r2 (2) Add b, r1(8) Sub f, r2 (3) load c, r2(9) Store c, r1 (4) Mult r1, r2(10) Mult d, r1 (5) Add r1, r2(11) Add r2, r1 (6) Store g, r2(12) Store a, r1 b a + 4 (G) r2 * 5 r2 + 6 (C) r1 c – 3 r2 * 2 r1 f e d + 1 (A) r1

Node Scheduling c b d * 2 a + 1 c b * da a * (b + c) + (b + c) + d(b + c) * a + d + (b + c)

Virtual Registers c b d + 4 V3 + 3 V2 * 2 V1 a + 1 V1 c b + 4 V1 + 3 V2 V1 * V1 da RegisterSpan V1 V2 V RegisterSpan V1 V

Real Registers c b d + 4 R3 + 3 R2 * 2 R1 a + 1 R1 c b + 4 R1 + 3 R2 R1 * R1 da

Code Comparison Load b, r3Load b, r1 Add c, r3Add c, r1 Move r3, r2Load d, r2 Add d, r2Add r1, r2 Load a, r1Mult a, r1 Mult r3, r1Add r2, r1 Add r2, r1

Aliasing When aliasing is included in DAGs, code generation becomes more complicted For example, assignment to one array element, say a(i) may effect the value of a seemingly different array element, a(j) DAGs must be generated so that aliasing is handled

Problems 1.Stores cannot be delayed. For example, a(i) = j must be stored immediately, because later a(k) could be referenced where i = k 2.An assignment to an alias must kill all previous references to that alias. For example a(i) = j; a(k) = m; /* this kills the association of j with a(i) */ 3.The order of writes to, and reads from, aliased data objects must be preserved

DAG for j = a(i) i a Ind  (j)

DAG for a(i) = j i a Ind (%1)

DAG for a(i) = j i a Ind (%1) j (%1  ) DAG for a(k) = m k a Ind (%1) m (%2  )

DAG for a(i) = j; k = a(m); i a Ind (%1) j(%1  ) m a Ind (%2)  (k) i a Ind (%1) m a Ind (%2)  (k) j(%1  )