Lowering llvm.gcwrite

How to customize the lowering process of llvm.gcwrite? As referenced in the GC document: “The exact code generated is specified by the Function’s selected GC strategy.” But I just didn’t see anything in the GCStrategy class that related. Any ideas?

I believe the relationship is inversed. Lowering passes for llvm.gcwrite and llvm.gcread are supposed to act based on the Garbage Collector strategy of the contained function.

If you have a custom garbage collector strategy then you are expected to also provide passes to lower the llvm.gcwrite and llvm.gcread intrinsics (if you require them) [0]. You’d so by creating a custom pass, using the normal pass plugin infrastructure, which would replace those intrinsics with your desired implementation. The pass should make sure to only do that replacement in functions that have your GCStrategy.

If you don’t do any lowering there is a CodeGen pass later that cleans up any llvm.gcwrite and llvm.gcread that are left into simple loads and stores [1].

[0] Garbage Collection with LLVM — LLVM 16.0.0git documentation
[1] https://github.com/llvm/llvm-project/blob/ee0133dc6d195e7cf0324dd825c483e8a907ba28/llvm/lib/CodeGen/GCRootLowering.cpp#L191

1 Like

Thanks for reply, just curious about the changes since I noted that there was some code snippet like “bool customWriteBarrier() const { return CustomWriteBarriers; }” but later was removed, and I could’t find the corresponding commit and explanation.

JFYI, gcread and gcwrite are essentially unmaintained. I’m not aware of anyone using them for anything beyond hobby efforts in the last 5 years. You’d be well advises to make sure the test coverage is adequate and that your expected uses are covered. If not, things may very well have bit-rotten.

2 Likes