79.4k views
4 votes
Illustrate an example where variable/register coalescing leads to a case where a bipartite VRCG becomes a VRCG with an odd cycle. Specifically, make sure to include pseudocode of your example, the interference graphs before and after coalescing, as well as the VRCG before and after coalescing.

Note: Your pseudocode should be of the form
variablename = variablename op variablename
For Example:
e = p + q
Operations should be of the following types for simplicity: -,*,^,+,=,/

1 Answer

3 votes

Final answer:

Variable/register coalescing is an optimization in compiler design, which can create complications when it leads to the formation of odd cycles in the VRCG, making register allocation more challenging. The example provided shows how coalescing could turn a bipartite VRCG into one with an odd cycle, requiring more than two registers.

Step-by-step explanation:

Variable/Register Coalescing and VRCG with an Odd Cycle

Variable/register coalescing is an optimization technique used in compiler design to reduce the number of registers required by combining two or more variables if they do not interfere with each other. In other words, if two variables are not used at the same time, they can share the same storage (register). However, coalescing can sometimes complicate the allocation process, especially if it forms cycles in the variable register conflict graph (VRCG).

Let's consider the following pseudocode:

a = b + c
b = a - d
e = a + b

Initially, the interference graph before coalescing might look like this with no conflicts between a and b:

b d
\ /
a - e - c

After coalescing a and b, the graph may look like:

ab
/ | \
d e - c

This pseudocode and coalescing lead to an odd cycle in the VRCG, making it impossible to allocate two registers without spilling.

The VRCG before coalescing did not have an odd cycle, thus making it possible for a two-color graph coloring algorithm to find a viable register allocation. But after coalescing, this is no longer the case.

If we look at the odd cycle introduced:

ab - e
\ /
c

We can see that 'ab', 'e', and 'c' each have to be a different color/register due to their mutual interference, which necessitates more than two registers or spilling some variables to memory.

User MarredCheese
by
7.7k points