Initial Patch to Support Speculative Compilation in ORC v2 APIs. Idea is to replicate the mapping provided by the lazyreexports utility (SymbolAliasMap) to find which Callable Symbol the stubs symbols lazy reexports and where the Callable Symbol lives (Impl JITDylibs).
Instrument IR with calls to the run time function orc_speculate_for at the entry block of Functions which calls other functions. At run time the call to __orc_speculate_for triggers the compilation of functions and update the pointer of the lazy reexports stubs.
This Patch introduces two maps : Imap and SpeculationMap,
Imap - replicates the source symbols and impl JITDylibs for each alias.
Speculation Map - lives inside the Speculator, which keeps track of for each function address what are the likely functions that the function may call at runtime.
Simple flow is at runtime Speculator queries the Imap to find the source symbols and impl JITDylibs.
Things to do:
- Write run time function implementation.
- Make Stub Pointer Updation through Notify Resolved
- Test Cases
Current Implementation finds likely functions one hop at a time, in my opinion is it not a drawback.
One minor observation: I think that adding the ability to configure the pass pipeline here provides more degrees of freedom than necessary. If the aim is to simplify the QueryAnalysis by providing a preconfigured pass pipeline then the IRSpeculationLayer should configure that pipeline (and expose no registration mechanism). If the aim is for the pipeline to remain configurable (which seems like a good idea) then you can remove the PassBuilder and FunctionPassManager from the layer entirely (simplifying the layer implementation) and have the QueryAnalysis capture them when it is created.
Note that this is just polish if you have time. I would not let it block your progress on real experiments.