Register allocation is a way to increase program execution speed by allocating program variables to registers as much as possible. Register is one of the most important problems in compiler optimization (good register allocation can increase program execution speed by more than 250%), and it is also one of the hottest research fields in compiler theory (the research field has proposed a large number of register assignment related algorithms).
1. Graph coloring (Graph coloring) method is the most common method to solve register assignment problem. The intersection graph (interference graph) is used to indicate whether the lifetime of program variables intersects, and the question of assigning registers to variables can be approximated as coloring a intersecting graph: intersecting nodes cannot have the same color; each color corresponds to a register. Chaitin and others first proposed the method of the register allocation based on graph coloring, the coloring method of Kempe was adopted, that is, any node with less than k can be colored by K. To judge whether a graph can be colored by K (k>=3) color, that is, the problem of k coloring, is Karp proved to be a np-complete problem. However, register allocation is not just a matter of graph coloring. When the number of registers is not sufficient to allocate certain variables, the variables must be overflowed into memory, and the process becomes
spill。 The problem of minimizing overflow costs is also a np-complete problem. If this problem is simplified-assuming that all overflow costs are equal, the problem of minimizing the overflow cost is equivalent to the K coloring problem and remains a np-complete problem. In addition, if the lifetime of two variables is adjacent only because it appears in the same copy instruction, then by assigning the two variables to the same register, you can eliminate the copy instruction and become
coalescing。 The effort in this direction has been one of the main drivers of register allocation in the 1/4 centuries after Chaitin's article, which has sprung up including aggressive coalescing,conservative coalescing and optimistic Coalescing. However, assigning two variables to the same register is equivalent to merging the two variables into the same variable and life time merging, thus aggravating the clustering of the intersecting graphs and decreasing the coloring of the intersecting graphs. Bouchez and others have proved that the current coalescing problem is np-complete. In order to reduce the clustering phenomenon of intersecting graphs, to improve the coloring of intersecting graphs, you can break the lifetime of a variable into two variables by copying the variable to a temporary variable and replacing it with the use of the temporary variable, which is called the lifetime of the
Live Range Splitting。 Obviously, this is a process contrary to the role of coalescing. Bouchez and others considered the complexity of the method. In addition, register aliases need to be considered in registers allocation (
aliasing) and pre-coloring (
pre-coloring) problem. A register alias means that in some architectures, the assignment of a register may affect another register. For example, in x86, assigning to an ax register affects the AL and AH registers. Pre-coloring means that certain variables must be assigned to a specific register. For example, many architectures use specific registers to pass function arguments. George and Appel developed the Chaitin algorithm, considered the coalescing process and the assignment process, and the iterations between the processes, which has a wide influence on the method of register allocation based on graph coloring.
3. Linear Scan AlgorithmThe linear scan algorithm (linear scan) was first proposed by Poletto and Sarkar, and has great influence in GCC, LLVM and Java hotspot compilers. The linear scanning algorithm simplifies the allocation problem based on graph coloring, considering the coloring of an ordered life period sequence, which improves the speed of register allocation (linear speed) without excessively reducing the use of registers.
4. Integer linear programming algorithmGoodwin and Wilken put forward the first integer linear programming algorithm for register assignment problem (integer linear programming), although it has exponential complexity in the worst case, but it can make full use of registers.
5. PBQP algorithmIn the compiler domain, the partitioned Boolean quadratic problem is used to resolve instruction selection and register allocation issues. For register allocation, the complexity of the PBQP algorithm is vk^3, where V is the number of variables and K is the number of registers. The experiments of Hames and others show that their PBQP implementation can find the optimal register allocation scheme for the 97.4% function in Spec CPU 2000.
6. Multi-Flow Commodities AlgorithmKoes and Goldstein are the first to address register allocation as a Multi-Flow commodities problem.
7. Register allocation based on static single assignment (SSA)An important breakthrough in the register allocation problem occurred in 2005, when 3 research teams independently demonstrated that the intersection of the programs represented by the SSA was a string graph (chordal graph). And the string graph can be colored in polynomial time. The method of register allocation based on SSA form can benefit from three aspects: smaller register pressure, separation between spilling and register assignment process, simpler register assignment algorithm.
from:http://blog.csdn.net/lm2302293/article/details/6790812
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.