outline
play

Outline Fine-Grain Register Allocation Based on a Global Spill - PDF document

Outline Fine-Grain Register Allocation Based on a Global Spill Costs Analysis Graph coloring register allocation q Motivation example q 2003. 9. 25 (Thr.) Proposed register allocation algorithm q Allocation benefit model q Seoul National


  1. Outline Fine-Grain Register Allocation Based on a Global Spill Costs Analysis Graph coloring register allocation q Motivation example q 2003. 9. 25 (Thr.) Proposed register allocation algorithm q Allocation benefit model q Seoul National University Experimental results q Conclusions q Dae-Hwan Kim dhkim@capp.snu.ac.kr Hyuk-Jae Lee hjlee@ee.snu.ac.kr Overview of Register Allocation Graph-Coloring Register Allocation Determines whether a live range (variable/temporary) is to be Dominant allocation paradigm (Chaitin, Brigss, …) q q stored in a register or in memory Models register allocation problem as a graph coloring problem q of an interference graph Goal: Interference graph: an undirected graph, where q q � Store live ranges as many as possible in registers � A node: a live range � Minimize the number of memory accesses (load/store instructions) � there is an edge between two nodes if corresponding live ranges interfere. � Interfering live ranges can not share the same register An important compiler technique q � The reduction of load/store instructions leads to the decrease of execution The contribution of graph coloring approach: the simplicity by q time, code size and power consumption. abstracting each live range as a single node of an interference graph Graph-Coloring Limitations Motivation Example What is not represented in the conventional graph coloring Suppose the number of registers is two. q q approach ? Graph coloring spills ‘C’ with 3 memory accesses q does not specify where and how much live ranges interfere � Different spill cost at each reference in the flow analysis q Spill A after (3) and before (8): 2 memory accesses q A = foo1( ); A 5 B = A + 1; A = foo1( ); (1) foo2(A + B); B = A + 1; (2) C = foo3(); foo2(A + B); (3) foo4(C + 1); C = foo3(); (4) B C 3 4 foo5(C + 2); foo4(C + 1); (5) foo6(B + 3); foo5(C + 2); (6) foo7(A + 4); D foo6(B + 3); (7) 1 D = A - B; foo7(A + 4); (8) D = A - B; (9) �

  2. Overview of Proposed Algorithm Variable Reference Flow Graph Decides whether to allocate a register or not for every reference The proposed approach constructs a varef-graph (variable q q of a variable reference flow graph) When there is no free register, it determines allocation based on Node: a variable reference q q the allocation benefit in the reference flow Edge: control flow of the program (i.e, execution order of the q variable references of the program) Two stages q � Variable allocation: variables are allocated with the number of machine The varef-graph models the execution order of the references in q registers the program. � Scratch allocation: temporaries and unallocated variables are allocated Varef-Gaph Example Allocation Algorithm 1 A The proposed algorithm visits each node of a varef-graph in the q (1) A = 1; breadth-first order. 2 (2) if (A) A (3) B = 1; When no register is free for a node, the allocator estimates the q else 3 4 benefit and loss of register preemption for each register, and B B (4) B = 2; (5) return A + B; selects the register with the maximum benefit. 5 A If all registers have larger loss than benefit, no register is q assigned to the node. 6 B For those nodes that are not assigned to a register, the second q code example Variable reference flow graph stage register allocation, called scratch allocation, is performed. Variable Allocation Algorithm Register Allocation Benefit Visit each node in the graph BenefitRegAlloc(n,r) = PenaltySpill(n,r) – PenaltyPreempt(n,r) q � n: node number, r: register number Any register Previously assigned available ? PenaltySpill(n,r): the total number of load/store instructions that q register available ? Yes are required if node ‘n’ is spilled. Yes No No Assign the register with the Assign the previously Assign any register PenaltyPreempt(n,r): the total number of load/store instructions q maximum non-negative benefit assigned register that are required when node ‘n’ preempts register ‘r’. Continue until all nodes visited �

  3. Impact Range Impact Range Example (1) q Suppose register allocation visits node ‘5’ The decision for one node affects the q 1 1 2 R1 q Suppose the number of registers is 2 A = register allocation for another node A A R1 � If node ‘1’ is spilled, node ‘6’ is also spilled 2 q VarHold(n,r): the variable that holds register ‘r’ when B = B 3 B 4 R2 R2 the register allocation is performed for node ‘n’. Impact Range: the set of the nodes that are q q NodeHold(n,r): the nodes for VarHold(n,r) affected by the register allocation for a 5 6 3 4 N B C = C = given node. q VarHold(5,r1)=‘A’, NodeHold(5, r1) = {1,2}. 7 8 9 The impact range of node ‘n’ for register ‘r’ N A A q q NextRef(n) = {p| p is a next reference of n} . 5 = C is defined as the path from node ‘n’ to the q NextRef(1) = {11} , NextRef(2) = {8,9,11}, next references of a variable that currently 10 C q NextRef({1,2}) = {8, 9,11} holds register ‘r’. 6 q ImpactRange(5,r1) = path (5, 8) ∪ path (5, 9) ∪ path (5,11) = A 11 A = { } ∪ { } ∪ path(5,11) = {5, 7, 10, 11} Impact Range Example (2) Definition of Impact Set q subpath(n,p,s) is the path(p,s) ⊂ path(n,s). 1 2 A A R1 q subpath(1, 5, 11) = path(5, 11) = {5, 7, 10, 11} Only two types of nodes in the impact range contribute to R1 q q SubPathRange (n,p) = ∪ s subpath (n, p, s) BenefitRegAlloc(n,r) for all s ∈ NextRef(n) 1) The node that references the same variable as node ‘n’ B 3 B 4 R2 R2 q SubPathRange (S,p) = ∪ n SubPathRange (n, p) for all n ∈ S 2) The node that references the variable that holds register ‘r’ when node ‘n’ is visited for register allocation. q ImpactRange(n,r) = SubPathRange (NodeHold(n,r),n) 5 6 N B q ImpactRange(5, ‘r1’) var(n): the variable that is referenced by node ‘n’. q = SubPathRange(NodeHold(5,r1), 5) 7 8 9 VarHold(n,r): the variable that holds register ‘r’ when the register N A A q = SubPathRange({1,2}, 5) allocation is performed for node ‘n’ = subpath(1, 5, 11) ∪ subpath(2, 5, 8) ∪ subpath(2, 5, 9) ∪ subpath(2, 5, 11) 10 C ImpactSet(n,r) = { m| m ∈ ImpactRange(n,r), and q = {5, 7, 10,11 } ∪ { } ∪ { } ∪ {5, 7, 10.11} (var(m) = var(n) or var(m) = VarHold(n,r)} = {5, 7, 10,11} 11 A Impact Set Example Benefit Model q ImpactRange(5,r1) = path (5, 8) ∪ path (5, 9) ∪ 1 2 R1 A A path (5,11) PenaltySpill(n,r) = Σ m ∈ ImpactSet(n,r) and var(m)=var(n) cost(m) R1 q = { } ∪ { } ∪ path(5,11) PenaltyPreempt(n,r) = Σ m ∈ ImpactSet(n,r) and var(m)=VarHold(n,r) cost(m) q 3 4 B B R2 R2 = {5, 7, 10, 11} � n: node number, r: register number � var(n): the variable that is referenced by node ‘n’. q var(5) = ‘N’ 5 6 N B � VarHold(n,r): the variable that holds register ‘r’ when the register q VarHold(5, ‘r1’) = ‘A’ allocation is performed for node ‘n’. q ImpactSet(5, ‘r1’) = { 5, 7, 11} 7 8 9 N A A BenefitRegAlloc(n,r) = PenaltySpill(n,r) – PenaltyPreempt(n,r) q � n: node number, r: register number 10 C 11 A �

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend