Accessing an out-of-tree custom AA in LLVM


I am still wondering how to access the results of my custom, out-of-tree AA in other (out-of-tree) passes; using the LLVM provided mechanisms for AA "enrichment", and using opt as the top-level. I have attached some code which works (on LLVM 8, still) for me, but some questions remain:

(1) What is the correct way to hook my call-back into the ExternalAAWrapperPass? The code I can find uses createExternalAAWrapper pass with an appropriate CB, but in my case I don't have a pass manager lying around I can hook the resulting ImmutablePass into. Instead, my approach is to rely on the ExternalAAWrapperPass to be there, and then (in my custom_aa_pass::runOnFunction !) manually hook in the CB. That feels wrong, but seems to work. Previously, I experimented with subclassing ExternalAAWrapperPass, but that was fragile.

(2) Using the LegacyAARGetter in a ModulePass works (after adding ⚙ D71348 Add ExternalAAWrapperPass to createLegacyPMAAResults. ), but I manually need to instantiate the custom_aa_pass via a command line argument to opt; it is somehow not picked up from AA.addRequired<custom_aa_pass>(), and also manually nudging it with an additional getAnalysis<custom-aa-pass>(F) in runOnModule does not make it appear. Is that intentional?

Overall, the entire (legacy) pass manager code feels like black magic to me, and it is not quite clear whether what I have come up with is sensible. Any comments (other than code style, please; I know it is different ^^) on the attached would be much appreciated!


aa_tie_in.cpp (13 KB)