LLVM officially supports Garbage Collection environments.
Such environments must be able to detect type of accessed object.
With opaque pointers the only possible way for memory intrinsics is
elementtype argument attribute. This patch adds the support in the
form of LangRef, verifier and pass updates.
Details
- Reviewers
- None
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Not familiar with GC requirements, but this at least sounds plausible to me (maybe @reames can confirm?) However, I think that if we go down this line, we should probably go all in: Drop the element_size argument from the intrinsics and make elementtype required by the IR verifier, and adjust lowering to perform copies in the correct type.
I don't understand the motivation here. Clearly, such an environment could tag the operations this way, and probably should. However, why does that need to be in the LangRef as a requirement? Is the idea to disallow some particular transform in tree that can't meet this?
The optimizer can insert new atomic memcpy/memmove calls, e.g loop-idiom-recognize would do that. Currently, when loop-idiom-recognize inserts such a call it doesn't tag it with the element type, which makes it an incorrect transform for us.
If we document the requirement in the langref we can a) add a verification rule to catch these situations, b) fix such transforms upstream. I think we can restrict this requirement to functions that have a GC strategy specified.
Idea is being able to push something like these though upstream:
https://reviews.llvm.org/D125690
https://reviews.llvm.org/D127892
From our downstream point of view they look reasonable, but we've encountered upstream resistance on first (so most likely will see it on second as well if we do it unconditionally)
Thanks @dantrushin for the patch. We have now had nasty miscompiles in practice (lowering memory intrinsics to regular loops and miss adding barriers for GC) and would like to make progress with this patch.
As a first step, we plan to document in the LangRef that functions having GCStrategy specified needs to have elementtype attribute set for the src and dest arguments for the atomic intrinsics. Also, introducing the API to record the elementtype (https://reviews.llvm.org/D125690).
The next step would be to have the verification rule for this and to teach passes/utilities about this: LoopIdiomRecognize and LowerMemIntrinsics.cpp (utility API for atomic mem intrinsics).
Once both of these have baked in, we can then remove the elementsize argument altogether from the atomic mem intrinsics since they can be inferred from the elementtype and remove the GCStrategy requirement as well. This also allows non-GC users of atomic memory intrinsics enough time to react to the change.
This perhaps deserves an RFC on the mailing list.
This is a POC of most of the changes for the RFC to follow. The change will be split into LangRef + API as one change, Verifier + pass updates as another change.