Re: JIT compiling with LLVM v9.0
От | Jeff Davis |
---|---|
Тема | Re: JIT compiling with LLVM v9.0 |
Дата | |
Msg-id | CAMp0ubdRD=FCNb+2L-dVU_36O=OiJ8T-DFNO9rVTcKZjgoXhVA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: JIT compiling with LLVM v9.0 (Andres Freund <andres@anarazel.de>) |
Ответы |
Re: JIT compiling with LLVM v9.0
|
Список | pgsql-hackers |
On Wed, Jan 24, 2018 at 11:02 PM, Andres Freund <andres@anarazel.de> wrote: > Not entirely sure what you mean. You mean why I don't inline > slot_getsomeattrs() etc and instead generate code manually? The reason > is that the generated code is a *lot* smarter due to knowing the > specific tupledesc. I would like to see if we can get a combination of JIT and LTO to work together to specialize generic code at runtime. Let's say you have a function f(int x, int y, int z). You want to be able to specialize it on y at runtime, so that a loop gets unrolled in the common case where y is small. 1. At build time, create bitcode for the generic implementation of f(). 2. At run time, load the generic bitcode into a module (let's call it the "generic module") 3. At run time, create a new module (let's call it the "bind module") that only does the following things: a. declares a global variable bind_y, and initialize it to the value 3 b. declares a wrapper function f_wrapper(int x, int z), and all the function does is call f(x, bind_y, z) 4. Link the generic module and the bind module together (let's call the result the "linked module") 5. Optimize the linked module After sorting out a few details about symbols and inlining, what will happen is that the generic f() will be inlined into f_wrapper, and it will see that bind_y is a constant, and then unroll a "for" loop over y. I experimented a bit before and it works for basic cases, but I'm not sure if it's as good as your hand-generated LLVM. If we can make this work, it would be a big win for readability/maintainability. The hand-generated LLVM is limited to the bind module, which is very simple, and doesn't need to be changed when the implementation of f() changes. Regards, Jeff Davis
В списке pgsql-hackers по дате отправления: