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.
翻译:当在运行时进行编译,例如现代数据库系统中的查询汇编器和现代浏览器中的WebAssembly 虚拟机器中的查询汇编器等,快速编译非常重要。我们展示了极快的编译技术,这是一个极快的编译技术,它也产生高质量的代码。它能够将高层次语言和低层次的字节程序降低到二进制代码,从一个大型的二进制执行变量库中缝合代码。我们将这些二进制执行程序称为“小”标准,因为它们有在代码生成过程中必须插入缺失值的洞洞。我们展示了如何在Stenciil库中建一个存储器库并描述生成优化的基线二进制代码代码的复制和批配算算法。我们展示了两个版本的复制和批录案例:一个用于元程序编排的高C类语言的编译器,而我们高层次的语言编译器的编译器比创建AST要快得多。我们还在两个版本系统顶端上安装了一个SQLLLLC的调调调调快的代码, 以比我们更高级的版本的版本的版本的LPSerma的版本的调调调调调调调调调调调调快。