Open norcalli opened 1 month ago
If I find the time, I can try to bisect it but maybe it's just a result of the LLVM change
Yeah, I was wondering if this was going to come bite us.
LLVM 17 completely removed the old optimization pipeline. Therefore, I had to make a hard switch over with that LLVM version to the new optimization pipeline. In the process, I had to remove the manual inliner. Maybe it's possible to adapt, but to be honest the new optimization pipeline is pretty undocumented and even the stuff I've tried to do so far has been pretty inscrutable.
There is some good news: this impacts JIT mode only. If you use terralib.saveobj
you'll see the function get inlined as expected.
Add the following to the bottom of tests/ainline.t
:
print(terralib.saveobj(nil, "llvmir", {bar=bar}))
Then you'll see it print out:
So then there are two possible workarounds:
terralib.saveobj
to generate either .o
files or binaries/libraries directlyAh I see, that makes sense. I think I can live with that workaround, although probably prudent to print out a warning or something for setinlined
until the JIT pipeline supports it.
Tangentially but also related, I was wondering if there was an easy way to load/link against .o
files directly without first turning them into an archive or library directly from terra. Seems like it might be more relevant now with saveobj producing different code.
Although for this case, I can produce llvm bitcode and link that back in, which works (but has the disadvantage of linking into the global namespace?) ala
local exports = {main=main}
local O = terralib.linkllvmstring(terralib.saveobj(nil, "bitcode", exports))
for k, v in pairs(exports) do
print(O:extern(k, v.type))
end
I have produced a set of Linux binaries for 1.2.0 with LLVM 16, and attached them to the release with a note about this as a known issue. It looks ok on my end, but please check to see if this works for you:
The call terralib.linklibrary
ultimately decomposes into llvm::sys::DynamicLibrary::LoadLibraryPermanently
. Based on the documentation I would guess that it only works on shared objects, but you're welcome to test it out:
https://llvm.org/doxygen/classllvm_1_1sys_1_1DynamicLibrary.html#a53d32d3b3baefdec31d3d94b0586d437
yup it looks like it works! thank you! I did briefly look into the pass system myself to see if I could figure it out but I gave up haha. llvm docs are as inscrutable as always. I tried reading the Rust crate docs too just to see if I could make a JIT engine with inlining.
terra-Linux-x86_64-094c5ad (1.1.1)
terra-Linux-x86_64-094c5ad (1.2.0)
I noticed this from the disassembly on one of my personal projects, but it seems like inlining doesn't work and I checked against the existing test and that seems to be the case.