Skip to main content

ssa optimistic

· 2 min read

优化的本质是什么呢?

比如ssa,是减少死代码,通过常量传播和常量折叠减少运行时的计算

比如sql的逻辑优化: 就是一个逻辑下推 通过变换减少读io

编译的一般步骤:

lex : 词法分析 parse: 语法分析构造语法树 cfg优化
codegen

在golang 和php都有ssa 优化,ssa 优化是通过控制流图来做常量传递 常量折叠 和 死代码去除

php的ssa 优化在opcache中,而golang的也在类似的包里面

structure induction

CFG

construct cfg

ssa

what is ssa

A program is defined to be in SSA form if each variable is a target of exactly one assignment statement in the program text.

如果程序里面每个变量只被赋值一次那么这个程序就具有ssa 形式

def-use chain and use-def chain

Under SSA form, each variable is defined once. Def-use chains?are data structures that provide, for the single definition of a variable, the set of all its uses. In turn, a use-def chain?, which under SSA consists of a single name, uniquely specifies the definition that reaches the use.

def-use chain 就是输入是 定义(赋值) , 输出是使用被使用的变量的集合

use-def chain 刚好相反 输入是使用的变量 而 输出是他的定义(赋值)的集合, 对于ssa 的程序来说, 每个变量只被赋值(定义)一次,所以这个use-def这个数据结构在ssa形式下这个集合只有一个元素 ssa 形式下

ssa properties

ssa 有什么性质 ?

DG

JG

insert φ-function

construct ssa

destruct ssa

相关阅读