Closed brechtvl closed 10 months ago
Maybe a better solution would be to introduce an OSL non-opaque pointer type that wraps an llvm::Value*
and llvm::Type*
for the data it points to. That would sidestep the need to figure out the right types for batch mode types and llvm_store_value
.
The full consequences of adding that additional abstraction to LLVM_Util
are not clear to me, if perhaps using higher level abstractions than the LLVM API will get us into trouble later.
Maybe a better solution would be to introduce an OSL non-opaque pointer type that wraps an
llvm::Value*
andllvm::Type*
for the data it points to.
If llvm's point of view are that type's don't matter for pointers, well something higher needs to actually track them. So an having a wrapper of those 2 seems like a very reasonable approach to be able to ease into the transition.
What I was thinking is that LLVM_Util::op_load would be augmented with another parameter giving the type that we expect, and everyplace we call op_load, we would pass the expected type. For old LLVM versions, it would just check that they matched, for new LLVM that would be what the opaque pointer would need to know what it is.
So the first step -- add the type paramter to op_load, pass it everywhere it's needed, check that it's right -- can be done first, independently, to get the whole thing plumbed to throw the switch for opaque pointers.
@lgritz there is already a version of op_load
(and GEP
) with a type, and for non-batched code it was relatively straightforward to use them everywhere.
For the batched code I'm having difficulty finding what the right types are just from the context of each function. When tracing further backwards I can't see clearly when a type is wide or not, or when it's a wide bool or integer mask. It may just be my unfamiliarity with the code and @AlexMWells can tell quickly.
I left TODO comments in the code where I was uncertain.
I got batched mode tests to pass as well now on my system. OptiX likely still broken due to the casting issue mentioned in the description.
Other changes:
Which version of clang-format
should I be using? I tried 12, 15 and 16 and none matched exactly.
Our CI job uses clang-format 14
It turns out there is another significant change in LLVM 16, where support for default optimization levels (O0, O1, O2, O3) was removed from the legacy pass manager.
I added support for the new pass manager to address that. For the custom optimization levels 10-13 it still uses the legacy pass manager since I did not implement those. And of course the performance impact of this should be checked.
It's probably time to break up this PR into multiple smaller ones.
You're a big hero for all of this, Brecht.
Yeah, the more bite sized chunks, the better. Maybe the order should be:
@brechtvl, We currently claim to support as far back as llvm 9, but such a wide range is really not necessary (and perhaps not desirable, because it's too much trouble to always test against them all). I would prefer (if possible) to preserve the ability to build against several old versions (i.e., not force us to move our minimum all the way up to llvm 16), but at the same time, if it helps you to bring the floor up somewhat, you should definitely feel free to do so.
I don't expect any of these changes to require raising the floor.
The changes that allow us to build against LLVM16 but still using typed pointers (I think 16 still allows it, optionally, but in 17 it's gone for good).
I was hoping the non-opaque pointers would still work, but I got this error loading the bitcode. Even though -Xclang -no-opaque-pointers
is passed when compiling the bitcode.
Opaque pointers are only supported in -opaque-pointers mode (Producer: 'LLVM16.0.0' Reader: 'LLVM 16.0.0')
I guess it's not too surprising given the LLVM docs:
LLVM 15: Opaque pointers are enabled by default. Typed pointers are still supported. LLVM 16: Opaque pointers are enabled by default. Typed pointers are supported on a best-effort basis only and not tested. https://llvm.org/docs/OpaquePointers.html
This is now replaced by #1728, #1729 and #1730.
Is there a preferred order in which we review and integrate them?
For reviewing the order does not matter. For merging, #1730 should be done last.
This PR is closed and outdated now, please see #1728 instead.
Description
LLVM 16 was released a while ago but OSL does not support it yet. The main challenge is that this version requires opaque pointers, that is you can no longer tell from a pointer value which data type it points to.
Changes made:
GEP
andop_load
methods without type, and refactor code to always pass the type.op_scatter
andop_gather
.clangASTMatchers
library for LLVM 16, will be skipped for older LLVM version.makeArrayRef
totoArrayRef
tollvm::makeArrayRef
deprecation warnings.llvm::Align
.Remaining work:
BackendLLVM::llvm_store_value
betweenint64
andchar*
, but we can no longer compare the pointer type. This function is called from many places and it's unclear to me when this happens. According to a4e779c4 this code is only temporary.Tests
No new tests as the whole testsuite covers this.
Some tests are failing currently as this is work in progress.
Checklist: