Many program transformations and optimizations require information about the future behavior of the program. A standard way to obtain this information is to build an intermediate program representation, then use a backwards program analysis to propagate relevant information against the flow of control back to the transformation/optimization site. We instead propose to use prophecy variables, which predict information about the future execution of the program, to enable such transformations and optimizations. We implement prophecy variables in BuildIt, a lightweight domain specific language implementation system. BuildIt uses staged compilation to implement high performance domain specific languages embedded within a standard general purpose programming language (C++). The BuildIt first phase uses standard C++ program execution to generate optimized C, C++, and CUDA second phase code. This approach enables BuildIt to eliminate programming language implementation components such as parsers and intermediate representations, delivering a dramatic decrease in the engineering effort required to implement domain specific languages. The combination of prophecy variables and repeated forward program execution enables BuildIt to extend this approach to include transformations and optimizations that require information about the future execution of the program without backwards analyses and without the engineering overhead associated with implementing these analyses. We formalize the use of prophecy variables for this purpose, discuss the implementation of prophecy variables and repeated execution in BuildIt, and present experimental results for BuildIt computations that benefit from optimizations enabled by the information that prophecy variables provide.
翻译:许多程序转换与优化需要关于程序未来行为的信息。获取此类信息的标准方法是构建中间程序表示,然后使用逆向程序分析将相关信息逆着控制流传播回转换/优化点。我们提出改用预言变量——一种预测程序未来执行信息的机制——来实现此类转换与优化。我们在BuildIt(一个轻量级领域特定语言实现系统)中实现了预言变量。BuildIt采用分阶段编译技术,在标准通用编程语言(C++)中嵌入实现高性能领域特定语言。BuildIt第一阶段利用标准C++程序执行来生成优化的C、C++和CUDA第二阶段代码。该方法使BuildIt能够消除解析器和中间表示等编程语言实现组件,显著降低了实现领域特定语言所需的工程开销。预言变量与重复正向程序执行的结合,使BuildIt能够将该方法扩展到需要程序未来执行信息的转换与优化,既无需逆向分析,也避免了实现这些分析带来的工程负担。我们形式化了预言变量在此场景下的应用,讨论了BuildIt中预言变量与重复执行的实现机制,并通过实验展示了BuildIt计算如何受益于预言变量所提供信息启发的优化。