Using the Alias Analysis Evaluator API

I’m trying to test LLVMs alias analysis and the n^2 evaluator is a natural choice, but I can’t get my head around how I’m supposed to get results from it. I’ve found this class: LLVM: llvm::AAEvaluator Class Reference which contains a method to run the aa-eval over a function, which is great, but it only returns a PreservedAnalysis object, and internally the AAEvaluator class only has the total numbers of no/may alias results. How do I run this pass and then get alias results for any two pointers in the function which it was run on? If anyone can help me out with how this is done I’d really appreciate it.

The AAEvaluator is a printing pass (invoked as -passes=aa-eval), it’s not an analysis pass. You can’t get information from it.

If you want to get alias analysis results in other passes, you should use use the alias() method on AAResults.

So I can see on the AAResults docs that there’s an alias method taking two LLVM values, but do I need to explicitly run alias analysis passes over the function/module first before calling this method? Or will making the query run the alias analysis for me?

The query will run alias analysis for you.

There are some alias analysis providers that do use pre-computed state, though the only one that is production-quality is GlobalsAA. This pass needs to be explicitly scheduled in the pass pipeline for AAResults to make use of it, grep for GlobalsAA in PassBuilderPipelines.cpp to see how that looks like.

1 Like