Download presentation

Presentation is loading. Please wait.

Published byAubrey Burdon Modified over 2 years ago

1
Register Usage Keep as many values in registers as possible Register assignment Register allocation Popular techniques – Local vs. global – Graph coloring – Bin packing

2
Local Register Assignment Given – Control-flow graph of basic blocks – List of 3-addr statements per BB – Set of “ live ” scalar values per stmt – Sets of scalar values used, defined per stmt Design a local register assignment/allocation algorithm

3
Graph Coloring Assign a color to each node in graph Two nodes connected by an edge must have different colors Classic problem in graph theory NP complete – But good heuristics exist for register allocation

4
Live Ranges def y def x use y def x def y use x def x use x use y

5
Graph Coloring Register Assign Each value is allocated a (symbolic) register “ Variables ” interfere iff live ranges overlap Two interfering values cannot share register How can we tell if two values interfere? s1s2 s3s4

6
Interference Graph Values and interference – Nodes are the values – Edge between two nodes iff they interfere s1s2 s3s4

7
Graph Coloring Example

8
3 Colors

9
Heuristics for Register Coloring Coloring a graph with N colors For each node, m – If degree(m) < N Node can always be colored, because After coloring adjacent nodes, at least one color left for current node – If degree(m) >= N Still may be colorable with N colors

10
Heuristics for Register Coloring Remove nodes that have degree < N – Push the removed nodes onto a stack When all the nodes have degree >= N – Find a node to spill (no color for that node) – Remove that node When graph empty, start to color – Pop a node from stack back – Color node different from adjacent (colored) nodes

11
Another Coloring Example s1s2 s3s4 s0 N = 3

12
Another Coloring Example s1s2 s3s4 s0 N = 3 s4

13
Another Coloring Example s1s2 s3s4 s0 N = 3 s4

14
Another Coloring Example s1s2 s3s4 s0 N = 3 s4 s3

15
Another Coloring Example s1s2 s3s4 s0 N = 3 s4 s3 s2

16
Another Coloring Example s1s2 s3s4 s0 N = 3 s4 s3 s2

17
Another Coloring Example s1s2 s3s4 s0 N = 3 s4 s3 s2

18
Another Coloring Example s1 s3s4 s0 N = 3 s4 s3 s2

19
Another Coloring Example s1 s3s4 s0 N = 3 s4 s2

20
Another Coloring Example s1 s3s4 s0 N = 3 s2

21
Another Coloring Example s1 s3s4 s0 N = 3 s2

22
Which value to pick? One with interference degree >= N One with minimal spill cost (cost of placing value in memory rather than in register) What is spill cost? – Cost of extra load and store instructions

23
One Way to Compute Spill Cost Goal: give priority to values used in loops So assume loops execute 10 times Spill cost = defCost + useCost defCost = sum over all definitions of cost of a store times 10 nestingDepthOfLoop useCost = sum over all uses of cost of a load times 10 nestingDepthOfLoop Choose the value with the lowest spill cost

Similar presentations

OK

Carnegie Mellon Lecture 6 Register Allocation I. Introduction II. Abstraction and the Problem III. Algorithm Reading: Chapter 8.8.4 Before next class:

Carnegie Mellon Lecture 6 Register Allocation I. Introduction II. Abstraction and the Problem III. Algorithm Reading: Chapter 8.8.4 Before next class:

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google