1 / 25

Register Usage

Register Usage. Keep as many values in registers as possible Register assignment Register allocation Popular techniques Local vs. global Graph coloring Bin packing. Local Register Assignment. Given Control-flow graph of basic blocks List of 3-addr statements per BB

sotom
Download Presentation

Register Usage

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. 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 def y def x use y use x use y use x def x use x

  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? s1 s2 s3 s4

  6. Interference Graph • Values and interference • Nodes are the values • Edge between two nodes iff they interfere s1 s2 s3 s4

  7. Graph Coloring Example

  8. Graph Coloring Example • 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 N = 3 s1 s2 s0 s3 s4

  12. Another Coloring Example N = 3 s1 s2 s0 s4 s3 s4

  13. Another Coloring Example N = 3 s1 s2 s0 s4 s3 s4

  14. Another Coloring Example N = 3 s1 s2 s0 s3 s4 s3 s4

  15. Another Coloring Example N = 3 s1 s2 s2 s0 s3 s4 s3 s4

  16. Another Coloring Example N = 3 s1 s2 s2 s0 s3 s4 s3 s4

  17. Another Coloring Example N = 3 s1 s2 s2 s0 s3 s4 s3 s4

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

  19. Another Coloring Example N = 3 s1 s2 s0 s3 s4 s3 s4

  20. Another Coloring Example N = 3 s1 s2 s0 s4 s3 s4

  21. Another Coloring Example N = 3 s1 s2 s0 s4 s3 s4

  22. Another Coloring Example N = 3 s1 s2 s0 s3 s4

  23. Another Coloring Example N = 3 s1 s2 s0 s3 s4

  24. 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

  25. 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 10nestingDepthOfLoop • useCost = sum over all uses of cost of a load times 10nestingDepthOfLoop • Choose the value with the lowest spill cost

More Related