Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Variable Liveness: a variable is live at a point in a program if it may be used at a later point before being

redefined.

Liveness:

Define x : (left) x = //input x

Use x: (right) _ = x + 1 //output x

Live Ranges of x - (has to be used, if next instruction does not use x, then that instruction at current
point is dead.

Register interference graph - Two live rangers interfere if they overlap (same section of code)

-Graph Coloring

K coloring – when you color graph, you cant assign same color(registers) to nodes that
have same edge (empty complete-may not cover anything)

Pay bigger prices nodes in memory than those not(in registers)

Easy ones last, hardest ones FIRST(n-coloring)

Hardest = degrees >= number of colors


Easiest = degrees <= number of colors

More neighbors = more colors used, may not leave any colors for last node

If node n < Registers (easiest nodes) – remove from graph and do last

When you remove nodes, hardest nodes become easy nodes. When graph empty you are done.

Nodes are last, you color them first(easy).

Algorithm works if you can keep removing nodes until empty and can color all nodes

If doesn’t work (doesn’t mean that you cant color nodes, just that algorithm failed—empty complete
problem) //got stuck at removing nodes

- Take highest degree node(throw it away(go to memory) – remove node and its edges)
- Remove nodes n < R. (if you get stuck remove 1 or 2 nodes until rest of nodes have n < R)

Liveness Analysis and Live Range Construction

1. Global Analysis – look at whole control program(boundary-1st and last statement(entry+exit)


2. Local Analysis - look at basic program blocks(each individual instruction code) (before and
after statement) BETWEEN THE GLOBAL ANALYSIS

Once you know global information go back one step to local blocks and compute everything

Local

DEFINE KILL AND GEN for every block


Build CFG – Interferece Grraph (overlapping) -> Color it

1. Semantic Rules know how to write semantic rules


2. Show stack, llinks,how to access variables

3 topics – 3 questions

You might also like