What is the role of SSAS and SSAS

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

SSA Overview

The SSA was introduced in Go1.7, which greatly improved the performance of the compiler, but it also caused some slowdown in the compilation process. Here is a brief description of the SSA and SSA applications, combined with online food and books.

The SSA stands for the static single-assignment, which is an IR (middle representation Code), to ensure that each variable is assigned only once. This can help simplify the compiler's optimization algorithm.

 y := 1 y := 2 x := y

The above code, for example, y = 1 is actually not available, and this is determined by the defined reach analysis to determine y whether to use 1 or 2, and SSAS has an identifier that can be called a version or "generation".

 y1 := 1 y2 := 2 x1 := y2

This will not have any indirect value. The benefit expressed in SSAS is that the non-use of the same variable is represented as a different "generation", which facilitates the implementation of many compiler optimization algorithms.

A concept:

Φ (read as FAI) function, which represents the "generation" to assign a value based on the control flow.

Examples can refer to this paragraph of Vikiri.

Three definitions:

A dominate B, if starting from the starting point must go through a to B. In other words, A is the only way to B.

A strictly dominate B, if a dominate B, and A and B are unequal.

A dominance frontier contains B, if a does not have strictly dominate B, but dominate a precursor node of B.

The pseudo-code of the Dominance frontier is determined in a traversal manner.

for each node b    if the number of immediate predecessors of b ≥ 2        for each p in immediate predecessors of b            runner := p            while runner ≠ idom(b)                add b to runner’s dominance frontier set                runner := idom(runner)

Idom (b) Represents the node of the adjacent strictly dominate B. There is only one such point, because the adjacent points have two words will not be the only way.

As an example, 2 of the precursors are 1 and 7,7 no SD (strictly dominate) 2, so add 2 to the 7 DF (dominate Frontiers). 3 is 7 of the adjacent SD, then 3 is not 2 SD so 2 is added to the 3 DF, then 2 is 3 adjacent SD, then 2 is not 2 of the SD, so 2 is added to the DF 2, and finally traverse to 7, 5 and 6 is not 7 of the SD so add 7 to the 5 and 6 df.

DF (a) can be thought of as a collection of points that can be reached through a, but not a route.

With this definition, you can insert the Φ function and rename it later. If you have defined a in X, then all DF (X) requires a φ function. and the Φ function itself is also a definition.

For example, or the same example.

1 There is a definition of J, but DF (1) is empty, 5 has the definition of J, and 5 DF has 7, so 7 is inserted into a φ (J, J). J is now defined in 7 (through the Φ function) so DF (7) in 2 also has φ (J, J), 6 also has the definition of J but 7 has the Φ function, 2 DF has 2, but 2 already has φ function. A similar approach can be applied to I and K. Then rename the definition to complete the SSA conversion.

Application of SSA

Above is just a popular explanation for the SSA, no more detailed theory and algorithms and proofs, because the proof is really ugly, the following is the application of SSA.

DEAD CODE Elimination

Because each variable has a "generation" (because everyone is assigned only once), it is easy to check out the variables that are not being used and delete the corresponding definitions. In addition, if you delete the definition of v=x, this statement is also deleted in the use table of X.

Simple constant extension

For example v = φ(c1,c2,...,cn) , if C is equal, it can be replaced directly with C, or v=c if C is a constant, it can be replaced directly. While doing this, you can do other optimizations that can be done in a single traversal, for example copy propagation , x=y or x=φ(y) you can replace x directly with Y. For example constant folding , x=a+b if a+b it is a constant, you can assign a value directly with a constant.

Of course there are other optimization algorithms, starting from the simplicity of the SSA.

Converting from SSAS back to original code

y = φ(x1, x2, x3)This form should be split back into the original form according to the conditional branch, such as satisfying 1 conditions, using y=x1 this form. And it may be natural to change X1 and X2 back to use the same register, but some of the methods in the optimization process (copy propagation) have optimized most of the move instructions, and re-pushing X may have a life-cycle effect, so it retains the "generation".

Summarize

In fact, this is the def-use replaced by the use-def convenient to do code optimization: It hurt me to see so long

Reference documents

    1. Tiger Book 19th Chapter
    2. Wikipedia
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.