Copy-and-Patch Binary Code Generation

11/26/2020
by   Haoran Xu, et al.
0

Runtime compilation of runtime-constructed code is becoming standard practice in libraries, DSLs, and database management systems. Since compilation is expensive, systems that are sensitive to compile times such as relational database query compilers compile only hot code and interprets the rest with a much slower interpreter. We present a code generation technique that lowers an AST to binary code by stitching together code from a large library of binary AST node implementations. We call the implementations stencils because they have holes where values must be inserted during code generation. We show how to construct such a stencil library and describe the copy-and-patch technique that generates optimized binary code. The result is a code generator with negligible cost: it produces code from an AST in less time than it takes to construct the AST. Compared to LLVM, compilation is two orders of magnitude faster than -O0 and three orders of magnitude faster than higher optimization levels. The generated code runs an order of magnitude faster than interpretation and runs even faster than LLVM -O0. Thus, copy-and-patch can effectively replace both interpreters and LLVM -O0, making code generation more effective in compile-time sensitive applications.

READ FULL TEXT

page 10

page 11

research
04/17/2022

SymForce: Symbolic Computation and Code Generation for Robotics

We present SymForce, a library for fast symbolic computation, code gener...
research
10/15/2021

Sparsity-Specific Code Optimization using Expression Trees

We introduce a code generator that converts unoptimized C++ code operati...
research
06/14/2022

CERT: Continual Pre-Training on Sketches for Library-Oriented Code Generation

Code generation is a longstanding challenge, aiming to generate a code s...
research
08/04/2021

Relational E-Matching

We present a new approach to e-matching based on relational join; in par...
research
06/18/2021

VSAC: Efficient and Accurate Estimator for H and F

We present VSAC, a RANSAC-type robust estimator with a number of novelti...
research
02/06/2022

Solidfmm: A highly optimised library of operations on the solid harmonics for use in fast multipole methods

We present solidfmm, a highly optimised C++ library for the solid harmon...

Please sign up or login with your details

Forgot password? Click here to reset