复制-补丁编译:一种高级语言和字节码的快速编译算法
Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode
摘要:
当编译发生在运行时时,快速编译是很重要的,例如现代数据库系统中的查询编译器和现代浏览器中的WebAssembly虚拟机。我们提出了复制和补丁,一个非常快速的编译技术,也产生高质量的代码。它能够将高级语言和低级字节码程序降低到二进制代码,通过将来自二进制实现变体的大型库的代码拼接在一起。我们称这些二进制实现为stendable,因为它们有漏洞,在代码生成过程中必须插入缺失值。我们展示了如何构建一个模板库,并描述了复制和补丁算法,生成优化的二进制代码。我们演示了两个使用情况下的复制和补丁:一个编译器的高级C语言的元编程和WebAssembly的编译器。我们的高级语言编译器的编译成本可以忽略不计:它从AST生成代码所用的时间比构造AST所用的时间要少。我们已经实现了一个SQL数据库查询编译器上的元编程系统,并表明,在TPC-H数据库基准测试,复制和补丁生成的代码比LLVM -O 0快两个数量级,比更高的优化水平快三个数量级。生成的代码比解释快一个数量级,比LLVM -O 0快14%。我们的WebAssembly编译器生成代码的速度比Liftoff快4.9 - 6.5倍,Liftoff是Google Chrome中的WebAssembly基线编译器。生成的代码在Coremark和PolyBenchC WebAssembly基准测试中的性能也超过了Liftoff的39%-63%。
英文摘要:
Fast compilation is important when compilation occurs at runtime, such as query compilers in modern database systems and WebAssembly virtual machines in modern browsers. We present copy-and-patch, an extremely fast compilation technique that also produces good quality code. It is capable of lowering both high-level languages and low-level bytecode programs to binary code, by stitching together code from a large library of binary implementation variants. We call these binary implementations stencils because they have holes where missing values must be inserted during code generation. We show how to construct a stencil library and describe the copy-and-patch algorithm that generates optimized binary code. We demonstrate two use cases of copy-and-patch: a compiler for a high-level C-like language intended for metaprogramming and a compiler for WebAssembly. Our high-level language compiler has negligible compilation cost: it produces code from an AST in less time than it takes to construct the AST. We have implemented an SQL database query compiler on top of this metaprogramming system and show that on TPC-H database benchmarks, copy-and-patch generates code two orders of magnitude faster than LLVM -O0 and three orders of magnitude faster than higher optimization levels. The generated code runs an order of magnitude faster than interpretation and 14% faster than LLVM -O0. Our WebAssembly compiler generates code 4.9X-6.5X faster than Liftoff, the WebAssembly baseline compiler in Google Chrome. The generated code also outperforms Liftoff's by 39%-63% on the Coremark and PolyBenchC WebAssembly benchmarks.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。