Attending this event?
View analytic
Wednesday, September 26 • 16:45 - 17:45
Using Compile-time Code Generation to build an LLVM IR Pattern Matcher

Sign up or log in to save this to your schedule and see who's attending!

Although expression templates have been around for many years and are a great example of compile-time code generation, they have typically been limited to relatively short expressions who's grammar can be expressed as a tree. What do you do when you want to express something more like an assembly-language program, with loops (cycles) in it? This was the problem that I encountered when trying to identify certain loop patterns in an LLVM compiler back end. The LLVM infrastructure provides a pattern matching library, but it has some limitations -- most notably the inability to express cycles in the code it matches.

Taking the idea of expression templates and kicking it up a notch, I created a library that allows an input pattern to be expressed directly in C++ using a syntax that resembles assembly language then generate, at compile time, an actual pattern-matching subroutine customized for that pattern. In the process, I deepened my knowledge of constexpr expressions, and built an interesting infrastructure that I will now share with you.

This talk is for the advanced C++ programmer. An understanding of templates, type traits, and basic metaprogramming is assumed. No prior knowledge of LLVM or compilers is required, though compiler back-end implementers will find this talk especially interesting.

avatar for Pablo Halpern

Pablo Halpern

Pablo Halpern has been programming in C++ since 1989 and has been a member of the C++ Standards Committee since 2007. His work with allocators began at Bloomberg LP, where he developed an appreciation for the simple and powerful allocator model in use there. In 2005, he started writing... Read More →

Wednesday September 26, 2018 16:45 - 17:45

Attendees (21)