(编译器/程序优化)常量传播:一种静态优化技术,把已知为常量的变量值在程序的后续使用处“传播/替换”为该常量,从而简化表达式、暴露更多可优化机会(常与常量折叠一起使用)。在某些语境下也可泛指把“恒定信息”在计算过程中传递下去。
/ˈkɒnstənt ˌprɒpəˈɡeɪʃən/
After constant propagation, the compiler replaced x with 10 everywhere it was safe.
经过常量传播后,编译器在所有安全的位置把 x 都替换成了 10。
Constant propagation can reduce runtime checks by turning dependent conditions into compile-time constants.
常量传播可以把依赖变量的条件变成编译期常量,从而减少运行时检查。
constant 来自拉丁语 constans(“坚定的、不变的”);propagation 来自拉丁语 propagare(“繁殖、扩展、传播”)。组合起来字面意思是“传播不变的值”,在编译原理中专指把“已确定的常量信息”沿控制流/数据流传递并用于替换。