Problemcore
Register binding
Also called register sharing in high-level synthesis.
Assign the variables of a scheduled design to registers so that variables with overlapping lifetimes get different registers, with the fewest registers and multiplexers.
Register binding is the step of high-level synthesis that maps each value of a scheduled design to a register, so that two values that are live in the same step use different registers. The main goal is the fewest registers, and the second goal is a small interconnect. For straight-line code the lifetimes are intervals, and the least number of registers is the largest number of values live in one step, which the left-edge algorithm reaches. When values live across the back edge of a loop, the lifetimes are arcs of a circle and the problem is NP-complete.
In plain words
Each intermediate result must be kept somewhere from the moment it is computed until the last time it is used. Registers are the boxes that keep results. Two results can share a box if one is no longer needed when the other arrives. For code with no loops, each result needs its box during one unbroken stretch of time, and the number of boxes needed is the largest number of results that must be kept at the same moment. A simple scan from left to right reaches that number. Inside a loop, some results are kept from the end of one round into the start of the next. The stretches then wrap around like hours on a clock face, and finding the fewest boxes becomes a hard puzzle.
Definition
The timing rules are those of the resource compatibility graph page: value is written at the end of step , last read in step , and held in the steps . A register can be read and written in the same step, as in a finite state machine with datapath.
Input. A schedule of one block of straight-line code, with no chaining, and a set of values with integers .
Feasible solutions. A register binding such that with implies .
Objective. Minimize the number of registers . A second objective, used among the bindings with the fewest registers, is the interconnect: the number of distinct units that write each register plus the number of distinct unit ports that read it, summed over the registers.
Decision form. Given and an integer , is there a binding with at most registers?
Loop form. A loop body has steps and runs again and again, and the binding is the same in every iteration. A value written at the end of step and last read in step of the same iteration (), or of the next iteration (), is held in the steps taken modulo , with step 0 meaning step of the previous iteration. Each lifetime is an arc of a circle with points, and two values conflict when their arcs meet.
Resource binding is the same kind of problem for operations and units, with busy sets in place of lifetimes. Interconnect binding takes the registers as given and chooses the multiplexers and operand ports.
Variants
- Fewest registers, then least interconnect. Among the bindings with the fewest registers, choose one that shares sources and destinations. Weighted bipartite matching binding does this step by step.
- Conditional code. Values on exclusive branches can share a register even if their steps overlap. The conflict graph is then no longer an interval graph.
- Loops and pipelines. In a pipelined loop with initiation interval , a lifetime can be longer than , and copies of one value from different iterations are live together. Unrolling the loop, or renaming the registers in turn, gives each copy its own register.
- Register files. Values go to a few multiport register files instead of single registers. Then the number of read and write ports per step is also limited.
- Compiler register allocation. A compiler has a fixed number of registers and must spill values to memory when they do not fit. See the register allocation problem and Chaitin's allocator. In synthesis, the number of registers is chosen, so nothing is spilled.
Examples
Straight-line code. Seven values in a schedule of 5 steps:
| value | lifetime | ||
|---|---|---|---|
| 0 | 2 | ||
| 0 | 1 | ||
| 1 | 3 | ||
| 1 | 3 | ||
| 2 | 5 | ||
| 3 | 4 | ||
| 4 | 5 |
The live values per step number 2, 3, 3, 2 and 2, so at least 3 registers are needed. The left-edge algorithm takes the values in order of the first step of their lifetime and fills one register at a time: register 1 gets and then , register 2 gets , , and , and register 3 gets . That is 3 registers.
A loop where the live count is not enough. A loop body of 5 steps has five values . For , is written at the end of step and last read in step . is written at the end of step 4 and last read in step 1 of the next iteration, and is written at the end of step 5 of the previous iteration. The lifetimes are . Every step has exactly 2 live values, but the conflict graph is the 5-cycle, so 3 registers are needed. If the loop is unrolled twice, the 10 values have lifetimes of 2 consecutive steps on a circle of 10 steps, the conflict graph is the 10-cycle, and 2 registers suffice for two iterations.
Known algorithms
- Left-edge algorithm. Exact for straight-line code, in time for sorting plus one pass per register. Kurdahi and Parker used it in the REAL program (1987). See the left-edge algorithm and interval partitioning, which assigns each value to any free register in order of start.
- Weighted bipartite matching binding. Reaches the fewest registers for straight-line code, and chooses among the free registers by an assignment problem per step to save interconnect. Heuristic for the interconnect. See weighted bipartite matching binding.
- Clique partitioning. Tseng-Siewiorek clique partitioning on the variable compatibility graph. Heuristic: it can need more registers than the live count, even on straight-line code.
- Chordal coloring. Exact whenever the conflict graph is chordal, which covers interval graphs. See chordal graph coloring.
- Circular arcs. For loops, cut the circle at one step and color the rest as intervals, which gives at most twice the live count, see circular-arc coloring. For a fixed number of registers, Garey, Johnson, Miller and Papadimitriou give a polynomial test.
- Integer programming. Exact for small designs, with any interconnect cost.
| Algorithm | Time | Space | Properties | Code |
|---|---|---|---|---|
| Tseng-Siewiorek clique partitioning | O(n^2 m) worst | O(n + m) extra | deterministicnot exactofflineiterative | 1 language |
| Weighted bipartite matching binding | O(n log n + n L^2 + n L D) worst | O(n + L^2 + L D) extra | deterministicnot exactofflineiterative | 1 language |
Bounds
Let be the largest number of values live in one step: .
Lower bound. Every binding uses at least registers, because the values live in one step pairwise conflict.
Straight-line code: the bound is exact. The lifetimes are intervals of consecutive steps, so the conflict graph is an interval graph. Pairwise intersecting intervals share a step, so the largest clique has values. The interval coloring depth theorem shows that intervals of depth can be colored with colors, and the left-edge algorithm finds such a coloring. Proof for left-edge: it sorts the values by the first step of their lifetime and fills registers one at a time, adding a value when its first step is after the last step of the value placed last. Let be the first value of the last register it opens, with first step . In each register , was skipped, so the value placed last in at that moment ends at step or later. It comes before in the order, so it starts at step or earlier, and it is live in step . The values are distinct, and with they give values live in step , so . So the least number of registers is exactly , and finding it takes polynomial time.
Loops. The least number lies between and : the values live in one fixed step take at most registers, and the rest are intervals once the circle is cut at that step, so more registers suffice. The 5-cycle example has and needs 3.
Reductions
Straight-line code to interval coloring. A binding is a proper coloring of the interval graph of the lifetimes, and the reverse holds too. So straight-line register binding is the coloring of an interval graph, see graph coloring.
Circular-arc coloring to loop register binding. Garey, Johnson, Miller and Papadimitriou (1980) proved that deciding whether a family of circular arcs can be colored with colors is NP-complete when is part of the input. Each family of arcs can be drawn with endpoints among points of a circle, keeping the same pairs of meeting arcs. Take such a family. An arc that covers the whole circle meets every other arc and needs a color of its own, so remove each such arc and lower by one. For each other arc taken modulo , make a value written at the end of step (step of the previous iteration when ) and last read in step , in the same iteration if and in the next one if . Its lifetime is exactly the arc. Two values conflict exactly when their arcs meet, so the loop needs at most registers exactly when the arcs can be colored with colors. The construction takes polynomial time, and a binding is checked in polynomial time. So loop register binding is NP-complete.
To compiler register allocation. Register binding of straight-line code is register allocation without spills on an interval interference graph, see the register allocation problem.
Applications
- Datapath synthesis. Every high-level synthesis flow binds values to registers after scheduling, often with the left-edge algorithm as the first step.
- Loop pipelines. Values that cross iterations in DSP loops need the circular-arc view, or unrolling to reach the live count.
- Power. A register that holds fewer values toggles less, so some binders trade registers for lower switching activity.
References
- Fadi J. Kurdahi and Alice C. Parker, REAL, a program for REgister ALlocation, Proceedings of the 24th Design Automation Conference, 210 to 215, 1987, register allocation by the left-edge algorithm on value lifetimes, and its optimality for designs with no conditional branches
- M. R. Garey, D. S. Johnson, G. L. Miller and C. H. Papadimitriou, The complexity of coloring circular arcs and chords, SIAM Journal on Algebraic and Discrete Methods 1(2), 216 to 227, 1980, the main results (coloring circular arcs is NP-complete when the number of colors is part of the input)
- Giovanni De Micheli, Synthesis and Optimization of Digital Circuits, McGraw-Hill, 1994, Chapter 6, Resource Sharing and Binding (register sharing, variable lifetimes and the left-edge algorithm, and circular-arc graphs for loops)
- Martin Charles Golumbic, Algorithmic Graph Theory and Perfect Graphs, second edition, Elsevier, 2004, Chapter 8, Interval Graphs (interval graphs are chordal and perfect)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag KVYDH6 Edit this page History Report an error Markdown