[ORC] Support non-moving cloneToContext #148688
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are two usability concerns, in some cases, with the new
cloneToContextfrom #146852.This API assumes the LLVM context is in a
ThreadSafeContext, but I have no need for that. My IR gen is single-threaded. IR gen (viaIRBuilder) uses the context and module often, so I would need to do a whole lot ofwithContextDowith closures just to do things like create a new basic block.The new cloning function requires a
ThreadSafeModule, which can only be constructed by moving (i.e. consuming) a module. This prevents me from caching my C++ modules, which explodes the number I need to generate. Cloning should be read-only, so the module consuming here feels like it's just an implication of TSMs being used.We can address both of these by:
Adding a
getContextUnlockedtoThreadSafeContext, following what exists forThreadSafeModule; this allows me to store a raw pointer for easy use with IR genAdd an overload for
cloneToContextwhich take aconst Module &and use that as the implementation for the TSM version@lhames for vis.