1 / 30

Memory Allocation and circular-arc graphs

Memory Allocation and circular-arc graphs. Presented By Mohammed Alali ST: STRUCTURED GRAPHS AND THEIR APPLICATIONS - CS 6/75995 Dr. Dragan. Introduction. Problem formulation [13] : We have a program P and a number of available registers N:

Download Presentation

Memory Allocation and circular-arc graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Memory Allocation and circular-arc graphs Presented By Mohammed Alali ST: STRUCTURED GRAPHS AND THEIR APPLICATIONS - CS 6/75995 Dr. Dragan

  2. Introduction • Problem formulation [13]: • We have a program P and a number of available registers N: • Can each of the temporaries/variables of P be mapped to one of the N registers such that temporary variables with interfering live ranges are assigned to different registers? NP-Complete

  3. Register Allocation: Definition • Register allocation = assigning registers to values (i.e. Variables, constants …) [12] • Done by the compiler. • Crucial low level optimization (2x-7x faster than cache) [12]: • Big performance improvements. • Optimality = minimizing the number of registers [8] : • More compact design which increases register utilization.

  4. Register Allocation: Definition • The register allocation phase of the compiler stands between [19]: • The optimization phase and the final code assembly and emission phase. • Intermediate Language (IL) assumes unlimited number of registers. • Optimization phase eliminates references to storage: more data in registers. • Register Allocation phase maps the unlimited symbols to the +/-32 registers. • When necessary: Spill to memory & reload later.

  5. Register Allocation: Process Description • [20] : • If-then-else. • While loop. • It mainly depends on the concept of variable Liveness. • A variable is ”live” if it holds a value that may be used in the future [6]. • If two variables are LIVE simultaneously, they cannot be allocated to the same register. • Control Flow Graphs (CFG) analysis: • Def. : All paths that might be traversed through a program during its execution • Essential to compiler optimizations and static analysis. • Nodes Coalescing: • The process of combining two nodes/values.

  6. Register Allocation: Process Description [21] • Nodes Coalescing Example: • Not always effective: • May increase chromatic number (more registers).

  7. Register Allocation: Process Description • Basic Example [12]: • We have a program P with 6 variables: a = c+ d e = a + b f = e – 1 • Lets assume that a and e will die after being used. Then a and e locations can be reused. • Therefore, we can allocate a, e and f to one register (r1): r1 = r2 + r3 r1 = r1 + r4 r1 = r1 - 1 • Number of registers used = 4 for 6 variables.

  8. Register Allocation: Traditional Solution • Chaitin et al. (1981) basic steps [19]: • Compute variable liveness to get the number of names. • Build the interference graph • Perform nodes coalescing when possible. • Attempt to find a 32-coloring of the graph. • If one cannot be found • Modifying the program (spilling) and its graph until a 32-coloring is obtained.

  9. Register Allocation: Traditional Solution • Example [12]: • Compute variable liveness

  10. Register Allocation: Traditional Solution {b,c,f} {a,c,f} {c,d,f} {c,d,e,f} {c,e} {b,c,e,f} {c,f} {b} a f b e c d • Example [12]: • Construct interference graph where: • Nodes = variables • Edges = lifetimes of variables. • Formally [8]: Let V be the set of variables in the program. An interference graph G =(V,E) is defined, where (u, v) ∈ E indicates that variables u and v interfere, i.e., their lifetimes overlap and thus require separate storage resources. • Two variables can be allocated to same register if no edge connects them

  11. Register Allocation: Traditional Solution {b,c,f} {a,c,f} {c,d,f} {c,d,e,f} {c,e} {b,c,e,f} {c,f} {b} a f b e c d • Example [12]: • Coloring: • Colors = registers • K-Colorable: K = number of machine registers. • If the IG is k-colorable, there’s a register assignment that uses no more than k registers. • 4 colors are needed.

  12. Register Allocation: Traditional Solution a f b e c d • Example [12]:

  13. Register Allocation: Traditional Solution • Complexity? [12][19][21]: • NP-Complete! • Chaitin et al. [19] proved that the problem is NP-Hard using reduction from the Graph Coloring problem in general graphs. • Because every graph is the interference graph of some program. • Heuristics through elimination and spilling could help. [21] • Still a powerful technique.

  14. Register Allocation: Traditional Solution • Some other known algorithms/approaches [15]: • Using Integer Linear Programming and may run in worst-case exponential time, such as the algorithm of Appel and George [14]. • Other algorithms use polynomial-time heuristics, such as the algorithm of Briggs, Cooper, and Torczon[16]. • The Linear Scan algorithm of Poletto and Sarkar [17]. • And many others …

  15. Question : Can we do better? • Yes. Two Important properties should be satisfied: • Static Single Assignment (SSA) • Circular arc models (Chordal Graphs).

  16. Circular-arc graphs : Definition [9] • A circular-arc graph is the intersection graph of a set of arcs on the circle [1][9]. • A graph G is called a circular-arc graph if [9]: • There exists a family Cof arcs such that • Then, its circular-arc graph is G = (V, E) where • And • G(F) is called proper circular-arc graph if no arc is contained in any other [5][1]. • They are a natural generalization of interval graphs [2]. [9]

  17. Circular-arc graphs : Definition [9] • General assumptions [1]: • All arcs are closed (contain both endpoints). • No arc consists of the whole circle. • The families of arcs are all finite. • Some Applications [5]: • Compiler design and optimization. • Allocating bandwidth in all-optical WDM. • Scheduling. [9]

  18. Circular-arc graphs : Complexity [9] • Recognition [7][11]: • Initially conjectured by Booth recognition is NP-complete [3] . • Tucker disproved this with an O(n3) algorithm[1]. • Hsu improved this to O(nm) -- m is the number of edges [6]. • Eschenand Spinrad further improved this to O(n2)[4]. • McConnell (2003) gave the first linear O(n+m) recognition algorithm [7]. • Colorability: NP-Complete (Garey et al. 1980 [2]). • 3-Colourability: Polynomial (Garey et al. 1980 [2]). [9]

  19. Circular-arc graphs : Challenges? Conflict Graphs Chordal Graphs Circular arc Graphs Interval Graphs [9] [22] Circular-arc models does NOTalways produce Chordal graphs. Therefore, we have to transform program P to SSA form [13].

  20. Static Single Assignment (SSA): Definition Simple Example: • SSA is an intermediate representation used in many compilers like gcc 4 [13]. • If a program is in SSA form, then every variable is assigned exactly once • Each use refers to exactly one definition [13]. • SSA construction algorithm is used to build transform non-SSA to SSA. • Eg. Cytron et al. 1991 [23]. [25] Non-SSA SSA SSA

  21. SSA and Chordality: Author’s Claims • Bouchezand Hack (2006) proved the result that strict programs in SSA form have Chordal Interference Graphs. (Hack’s Ph.D. Dissertation).[13][21] • Chordal graphs can be colored in linear time.[13][26] • He utilized Dominance property to redefine liveness of variables. • A variable v dominates v’, if all paths from Dv to v’ contain v. • A program P is strict if each usage of a variable v is dominated by Dv.

  22. SSA and Chordality: Steps Summary “ Before a value v is added to a PEO, add all values whose definitions are dominated by v A Post order walk of the dominance tree defines a PEO A pre order walk of the dominance tree yields a coloring sequence IGs of SSA-form programs can be colored optimally in O(k · |V|) Without constructing the interference graph itself “ [27][21]

  23. SSA and Chordality: Simple Example [27] [27] :

  24. b a SSA and Chordality: Simple Example [27] e c d a b c d e The Circular-arc model will look something like this:

  25. SSA and Chordality: Simple Example [27] • How can we create a 4-cycle {a, c, d, e}? • Redefinition of a violates SSA property.

  26. Remarks: [21] • This leads to a single pass register allocator architecture looking like [21] • No iterations. • SSA separate spilling from coalescing [27] • Both remain challenging. • Implementation: http://pp.ipd.kit.edu/firm/

  27. References A. Tucker, Coloring a family of circular arcs, SIAM J. Appl. Math., 29 (1975), pp. 493–502. M.R. Garey, D.S. Johnson, G.L. Miller, and C.H. Papadimitriou. The complexity of coloring circular arcs and chords. SIAM J. Alg. Disc. Meth., 1(2):216-227, June 1980. K.S. Booth. PQ-Tree Algorithms. Ph.D. thesis, Department of Computer Science, University of California, Berkeley, CA, 1975. E.M. Eschen and J.P. Spinrad. An O(n2) algorithm for circular-arc graph recognition. Proceedings of the Fourth Annual ACM–SIAM Symposium on Discrete Algorithms, pp. 128–137, 1993. M. Valencia-Pabon. Revisiting Tucker’s algorithm to color circular arc graphs. SIAM Journal on Computing, 32(4), pp. 1067-1072, 2003. W.L. Hsu. O(mn) algorithms for the recognition and isomorphism problems on circular-arc graphs. SIAM J. Comput., 24:411–439, 1995. McConnell, Ross (2003), Linear-time recognition of circular-arc graphs, Algorithmica 37 (2): 93–147, doi:10.1007/s00453-003-1032-7 Brisk, P.; Dabiri, F.; Jafari, R.; Sarrafzadeh, M., "Optimal register sharing for high-level synthesis of SSA form programs," Computer-Aided Design of Integrated Circuits and Systems, IEEE Transactions on , vol.25, no.5, pp.772,779, May 2006 doi: 10.1109/TCAD.2006.870409 http://en.wikipedia.org/wiki/Circular-arc_graph http://en.wikipedia.org/wiki/Live_variable_analysis http://graphclasses.org/classes/gc_133.html Register Allocation via Graph Coloring Lecture. John Cavazos. University of Delaware. Register Allocation Lecture. Ajay Mathew. Carnegie Mellon University.

  28. References Andrew W Appel and Lal George. Optimal spilling for cisc machines with few registers. In International Conference on Programming Languages Design and Im- plementation, pages 243–253. ACM Press, 2001. N. Fritz, P. Lucas, and P. Slusallek. CGiS, a new language for data-parallel GPU programming. In B. Girod, H.-P. Seidel, and M. Magnor, editors, Proceedings of “Vision, Modeling, and Visualization”, pages 241–248, 2004. Preston Briggs, Keith D. Cooper, and Linda Torczon. Improvements to graph coloring register allocation. Transactions on Programming Languages and Systems (TOPLAS), 16(3):428–455, 1994. MassimilianoPoletto and Vivek Sarkar. Linear scan register allocation. ACM Transactions on Programming Languages and Systems, 21(5):895–913, 1999. M. Valencia-Pabon. Revisiting Tucker's algorithm to color circular arc graphs. SIAM J. Comput., 32 (2003), pp. 1067–1072 Chaitin, Gregory (04/2004). "Register allocation and spilling via graph coloring". SIGPLAN notices; ACM Special Interest Group on Programming Languages(0362-1340), 39 (4), p. 66. http://en.wikipedia.org/wiki/Control_flow_graph Sebastian Hack , Daniel Grund , Gerhard Goos, Register allocation for programs in SSA-Form, Proceedings of the 15th international conference on Compiler Construction, March 30-31, 2006, Vienna, Austria [doi>10.1007/11688839_20] Springer, D.L.; Thomas, D.E., "Exploiting the special structure of conflict and compatibility graphs in high-level synthesis," Computer-Aided Design of Integrated Circuits and Systems, IEEE Transactions on , vol.13, no.7, pp.843,856, Jul 1994doi: 10.1109/43.293941 Ron Cytron , Jeanne Ferrante , Barry K. Rosen , Mark N. Wegman , F. Kenneth Zadeck, Efficiently computing static single assignment form and the control dependence graph, ACM Transactions on Programming Languages and Systems (TOPLAS), v.13 n.4, p.451-490, Oct. 1991 [doi>10.1145/115372.115320]

  29. References Maw-Shang Chang, Efficient Algorithms for the Domination Problems on Interval and Circular-Arc Graphs, SIAM Journal on Computing, v.27 n.6, p.1671-1694, Dec. 1998 [doi>10.1137/S0097539792238431] http://en.wikipedia.org/wiki/Static_single_assignment_form http://graphclasses.org/classes/gc_32.html http://www.cdl.uni-saarland.de/projects/ssara/hack_ssara_ssa09.pdf

  30. Thank you

More Related