A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

Similar documents
Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

Register Allocation. How to assign variables to finitely many registers? What to do when it can t be done? How to do so efficiently?

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

COMP108 Algorithmic Foundations

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

CS553 Lecture Register Allocation 1

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

Formal Concept Analysis

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

CS553 Lecture Register Allocation I 3

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

Announcements. Programming Project 4 due Saturday, August 18 at 11:30AM

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

Present state Next state Q + M N

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Numbering Boundary Nodes

Aquauno Video 6 Plus Page 1

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

QUESTIONS BEGIN HERE!

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

12. Traffic engineering

CS 241 Analysis of Algorithms

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

Section 3: Antiderivatives of Formulas

Seven-Segment Display Driver

Planar Upward Drawings

RAM Model. I/O Model. Real Machine Example: Nehalem : Algorithms in the Real World 4/9/13

XML and Databases. Outline. Recall: Top-Down Evaluation of Simple Paths. Recall: Top-Down Evaluation of Simple Paths. Sebastian Maneth NICTA and UNSW

(a) v 1. v a. v i. v s. (b)

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

The Course covers: Lexical Analysis Syntax Analysis Semantic Analysis Runtime environments Code Generation Code Optimization. CS 540 Spring 2013 GMU 2

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

Minimum Spanning Trees

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

Compression. Compression. Compression. This part of the course... Ifi, UiO Norsk Regnesentral Vårsemester 2005 Wolfgang Leister

Instructions for Section 1

Multipoint Alternate Marking method for passive and hybrid performance monitoring

QUESTIONS BEGIN HERE!

Constructive Geometric Constraint Solving

S i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

CSCI Compiler Design

Winter 2016 COMP-250: Introduction to Computer Science. Lecture 23, April 5, 2016

a b v a v b v c v = a d + bd +c d +ae r = p + a 0 s = r + b 0 4 ac + ad + bc + bd + e 5 = a + b = q 0 c + qc 0 + qc (a) s v (b)

Outline. Binary Tree

Section 10.4 Connectivity (up to paths and isomorphism, not including)

Problem solving by search

NP-Completeness. CS3230 (Algorithm) Traveling Salesperson Problem. What s the Big Deal? Given a Problem. What s the Big Deal? What s the Big Deal?

Ch 1.2: Solutions of Some Differential Equations

Organization. Dominators. Control-flow graphs 8/30/2010. Dominators, control-dependence. Dominator relation of CFGs

Process Discovery. prof.dr.ir. Wil van der Aalst.

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

CS 461, Lecture 17. Today s Outline. Example Run

Garnir Polynomial and their Properties

10/30/12. Today. CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James. DFS algorithm. Reachability Algorithms

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

Chapter 16. 1) is a particular point on the graph of the function. 1. y, where x y 1

Fundamental Algorithms for System Modeling, Analysis, and Optimization

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

1 Introduction to Modulo 7 Arithmetic

Trees as operads. Lecture A formalism of trees

The Plan. Honey, I Shrunk the Data. Why Compress. Data Compression Concepts. Braille Example. Braille. x y xˆ

Jonathan Turner Exam 2-10/28/03

13. Binary tree, height 4, eight terminal vertices 14. Full binary tree, seven vertices v 7 v13. v 19

CS September 2018

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

INTEGRALS. Chapter 7. d dx. 7.1 Overview Let d dx F (x) = f (x). Then, we write f ( x)

Multi-Section Coupled Line Couplers

Last time: introduced our first computational model the DFA.

MULTIPLE-LEVEL LOGIC OPTIMIZATION II

HIGHER ORDER DIFFERENTIAL EQUATIONS

In order to learn which questions have been answered correctly: 1. Print these pages. 2. Answer the questions.

Analysis and Evaluation of Address Arithmetic Capabilities in Custom DSP Architectures

Page 1. Question 19.1b Electric Charge II Question 19.2a Conductors I. ConcepTest Clicker Questions Chapter 19. Physics, 4 th Edition James S.

Analysis of Algorithms - Elementary graphs algorithms -

arxiv: v1 [cs.ds] 20 Feb 2008

Quartets and unrooted level-k networks

Computational Biology, Phylogenetic Trees. Consensus methods

Transcription:

A Simpl Co Gnrtor Co Gnrtion Chptr 8 II Gnrt o for singl si lok How to us rgistrs? In most mhin rhitturs, som or ll of th oprnsmust in rgistrs Rgistrs mk goo tmporris Hol vlus tht r omput in on si lok n us in othr loks Oftn us with run tim storg mngmnt 1 2 Rgistr n Arss Dsriptors For h vill rgistr, rgistr sriptor (RD) kps trk of th vrs whos urrnt vlu in tht rgistr Initilly mpty For h vr, n rss sriptor (AD) kps trk of th lotions whr th urrnt vlu of th vr n foun Lotion n rgistr, mmory rss, t. Co gnrtion Algorithm For thr rss instrution,.g. x=yz Us gtrg(x=yz) to slt rgistrs R x, R y, R z for x, y, z If y is not in R y, issu n instrution LD R y, y Similrly for x Issu th instrution ADD R R R Issu th instrution ADD R x, R y, R z Copy sttmnt x=y If y is not lry in rgistr, gnrt LD R y, y Ajust RD for R y so it inlus x Chng AD for x so its only lotion is R y Ening th si lok If x is us t othr loks, issu ST x, R x 3 4 Mnging Rgistr n Arss Dsriptors For LD R, x Chng RD for R so it hols only x Chng AD for x y ing R s n itionl lotion For ST x, R Chng AD for x to inlu its own mmory lotion For ADD R x, R y, R z Chng RD for R x so it hols only x Chng AD for x so its only lotion is R x Rmov R x from th AD of ny vr othr thn x Exmpl t = u = v = t u = = v u t, u, v r tmp vrs, whil,,, r glol Assum rgistrs r nough Rus rgistrs whnvr possil 5 6 1

t = u = Exmpl LD R1, ; LD R2, ; SUB R2, R1, R2 R1 R2 R3 t u v t,r1 R2 LD R3, ; SUB R1, R1, R3 u t,r3 R2 R1 v = t u = ADD R3, R2, R1 u t v R2 R1 R3 LD R2, u, v R2,R2 R1 R3 7 8 Funtion gtrg = v u ADD R1, R3, R1 v R2 R1 R3 ST, R2; ST, R1 v,r2,r1 R3 Consir piking R y for y in x = y z If y in rgistr, o nothing If y not in rgistr n thr is mpty on, hoos it s R y Lt v on of th vr in R W r OK if v is somwhr sis R W r OK if v is x W r OK if v is not us ltr Spill: ST v, R 9 10 Pphol Optimiztion Exm sliing winow n rpl instrution squn with shortr or fstr squn Runnt instrution limintion Flow of ontrol of optimiztion Algri simplifitions Us mhin iioms Eliminting Runnt Los n Stors LD, R0 ST R0, 11 12 2

Eliminting Unrhl Co Flow of Control Optimiztions if ug==1 goto L1 goto L2 L1: print ugging info if ug!=1 goto L2 L1: print ugging info goto L1 goto L2 L1: goto L2 L1: goto L2 if < goto L1 L1: goto L2 if < goto L2 L1: goto L2 13 Chptr 6: Intrmit Co 14 Gnrtion Rgistr Allotion n Assignmnt Exmpl Usg Counts An pproximt formul for th nfit from lloting rgistr for x loksbinl us ( x, B ) 2* liv ( x, B ) us(x,b) is th numr of tims x is us in B prior to ny finition of x liv(x,b) is 1 if x is liv on xit from B n is ssign vlu in B, 0 othrwis 15 16 Instrution Sltion y Tr Rwriting Instrution sltion n lrg omintionl tsk Evn th vlution orr is givn n rgistr llotion hs n on [i]=1 Tr Trnsltion Shms in in Rsp i = Rsp M C 1 LD R0, # ADD R0, R0, SP ADD R0, R0,i(SP) LD R1, INC R1 ST *R0, R1 17 18 3

Optiml Co Gnrtion for Exprssions W n hoos rgistrs optimlly If si lok onsists of singl xprssion, or It is suffiint to gnrt o for lok on xprssion t tim Ershov Numrs Assign th nos of n xprssion tr numr tht tlls how mny rgistrs n Ll lf 1 Th ll of n intrior no with on hil is th ll of its hil Th ll of n intrior no with two hilrn th lrgr on if th lls r iffrnt On plus th ll if th lls r th sm 19 20 ( )*() Ershov Numrs = = = * = Gnrting Co From Ll Exprssion Tr Rursiv lgorithm strting t th root Ll k mns k rgistrs will us R, R 1,, R k 1, whr >=1 is s To gnrt mhin o for no with ll k n two hilrn with qul lls Rursivly gnrt o for th right hil, using s 1: R 1, R 2,, Rsult in R k 1 Rursivly gnrt o for th right hil, using s : R, R 1,, Rsult in R k 2 Gnrt instrution OP R k 1, R k 2,R k 1 21 22 Gnrting Co From Ll Exprssion Tr To gnrt mhin o for no with ll k n two hilrn with unqul lls Rursivly gnrt o for th hil with ll k, using s : R, R 1 1,, Rsult in R k1 k 1 Rursivly gnrt o for th hil with ll m, using s : R, R 1,, Rsult in R m 1 Gnrt instrution OP R k 1, R m 1,R k 1 For lf x, if s is gnrt LD R, x LD R3, LD R2, ADD R3, R2, R3 LD R2, MUL R3, R2, R3 Ershov Numrs LD R2, LD R1, SUB R2, R1, R2 ADD R3, R2, R3 23 24 4

Insuffiint Supply of Rgistrs Input: ll tr n numr r of rgistrs For no N with t lst on hil ll r or grtr rursivly gnrt o for th ig hil with =1. Th rsult will ppr in R r Gnrt mhin instrution ST t k, R r If th littl hil hs ll r or grtr, =1. If th ll is j<r, thn =r j. Th rsult in R r Gnrt th instrution LD R r 1, t k Gnrt OP R r, R r, R r 1 or OP R r, R r 1, R r 25 Insuffiint Supply of Rgistrs LD R2, LD R1, ADD R2, R1, R2 LD R1, MUL R2, R1, R2 ST, R2 26 LD R2, LD R1, SUB R2, R1, R2 LD R1, ADD R2, R2, R1 5