Compiler Support for Parallel Evaluation of C++ Constant Expressions
Andrew Gozillon, Hossein Haeri, James Riordan, Paul Keir · Annals of Computer Science and Information Systems · 2023
Metaprogramming, the practice of writing programs that manipulate other programs at compile-time, continues to impact software development; enabling new approaches to optimisation, static analysis, and reflection.Nevertheless, a significant challenge associated with advanced metaprogramming techniques, including the constexpr functionality introduced to C++ in 2011, is an increase in compilation times.This paper presents ClangOz, a novel Clang-based research compiler that addresses this issue by evaluating relevant constant expressions in parallel, thereby reducing compilation time.ClangOz includes a set of compiler intrinsics that allows developers to parallelise their own code and take full advantage of recent constexpr language support.By utilising parallel evaluation, ClangOz significantly reduces the compile time for metaprogramming-intensive codebases, enhancing developer productivity and iterative software development processes.Benchmark results demonstrate the performance advantage of ClangOz over traditional compilers, including a decrease in compilation times across all benchmarks; and parallel efficiency of up to 95% in one case.The evaluation of constant expressions in parallel unlocks substantial speedups, enabling developers to leverage advanced metaprogramming techniques without sacrificing compilation efficiency.We highlight the opportunities afforded by the constexpr functionality and emphasise the importance of compiler support for efficient metaprogramming.By introducing ClangOz, a compiler tailored for parallel evaluation of relevant constant expressions, developers can utilise modern metaprogramming while minimising compilation times parametrically.