For AA imlpementations: same pointers for runOnModule(...) and alias(...)?

Hi all,

I’m writing an AA pass that overrides the runOnModule( Module & M ) and alias( const Value* V1, …) methods. I’m trying to understand my options for relating per-Value information computed during runOnModule, to the Value objects passed into my alias method.

Is attaching metadata to those objects during runOnModule, and reading it during alias(…), pretty much the only decent way to match up a given IR Value across those two methods’ invocations?

Thanks, Christian

P.S. Apologies if this email is too close to a duplicate post. I’ve seen a few variations on this question lately on IRC and this email list, but I haven’t seen any clear answer.

From: "Christian Convey" <christian.convey@gmail.com>
To: "LLVM Developers Mailing List" <llvmdev@cs.uiuc.edu>
Sent: Friday, June 26, 2015 2:18:48 PM
Subject: [LLVMdev] For AA imlpementations: same pointers for runOnModule(...) and alias(...)?

Hi all,

I'm writing an AA pass that overrides the runOnModule( Module & M )
and alias( const Value* V1, ...) methods. I'm trying to understand
my options for relating per- Value information computed during
runOnModule , to the Value objects passed into my alias method.

Is attaching metadata to those objects during runOnModule , and
reading it during alias(...) , pretty much the only decent way to
match up a given IR Value across those two methods' invocations?

There are two ways of doing this:

1. Add metadata (as you've suggested)

2. Maintain a cache in your pass (either by making your pass invariant or by marking other passes as preserving it). This cache can make use of TrackingVH (value handles) or WeakVH (weak value handles), see include/llvm/IR/ValueHandle.h, as appropriate on both functions and values. If this gives you sufficient guarantees, it likely easier and more efficient.

-Hal