Copy-and-patch compilation: a fast compilation algorithm for high-level languages and bytecode

Author:

Xu Haoran1,Kjolstad Fredrik1

Affiliation:

1. Stanford University, USA

Abstract

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.

Publisher

Association for Computing Machinery (ACM)

Subject

Safety, Risk, Reliability and Quality,Software

Reference66 articles.

1. Syrus Akbary. 2018. Wasmer Cranelift backend. Wasmer. https://github.com/wasmerio/wasmer/tree/master/lib/compiler-cranelift Syrus Akbary. 2018. Wasmer Cranelift backend. Wasmer. https://github.com/wasmerio/wasmer/tree/master/lib/compiler-cranelift

2. Bytecode Alliance. 2018. Cranelift Code Generator. Bytecode Alliance. https://github.com/bytecodealliance/cranelift Bytecode Alliance. 2018. Cranelift Code Generator. Bytecode Alliance. https://github.com/bytecodealliance/cranelift

3. AutoCAD. 2018. AutoCAD Web App. AutoCAD. https://web.autocad.com/ AutoCAD. 2018. AutoCAD Web App. AutoCAD. https://web.autocad.com/

4. Clemens Backes. 2018. Liftoff: a new baseline compiler for WebAssembly in V8. Google. https://v8.dev/blog/liftoff Clemens Backes. 2018. Liftoff: a new baseline compiler for WebAssembly in V8. Google. https://v8.dev/blog/liftoff

Cited by 7 articles. 订阅此论文施引文献 订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献

1. Compilation of Modular and General Sparse Workspaces;Proceedings of the ACM on Programming Languages;2024-06-20

2. Dr Wenowdis: Specializing Dynamic Language C Extensions using Type Information;Proceedings of the 13th ACM SIGPLAN International Workshop on the State Of the Art in Program Analysis;2024-06-20

3. Compile-Time Analysis of Compiler Frameworks for Query Compilation;2024 IEEE/ACM International Symposium on Code Generation and Optimization (CGO);2024-03-02

4. Whose Baseline Compiler is it Anyway?;2024 IEEE/ACM International Symposium on Code Generation and Optimization (CGO);2024-03-02

5. Fast Template-Based Code Generation for MLIR;Proceedings of the 33rd ACM SIGPLAN International Conference on Compiler Construction;2024-02-17

同舟云学术

1.学者识别学者识别

2.学术分析学术分析

3.人才评估人才评估

"同舟云学术"是以全球学者为主线,采集、加工和组织学术论文而形成的新型学术文献查询和分析系统,可以对全球学者进行文献检索和人才价值评估。用户可以通过关注某些学科领域的顶尖人物而持续追踪该领域的学科进展和研究前沿。经过近期的数据扩容,当前同舟云学术共收录了国内外主流学术期刊6万余种,收集的期刊论文及会议论文总量共计约1.5亿篇,并以每天添加12000余篇中外论文的速度递增。我们也可以为用户提供个性化、定制化的学者数据。欢迎来电咨询!咨询电话:010-8811{复制后删除}0370

www.globalauthorid.com

TOP

Copyright © 2019-2024 北京同舟云网络信息技术有限公司
京公网安备11010802033243号  京ICP备18003416号-3