0
votes

I am trying to manually build a list of instructions where a particular variable is getting assigned a value in the LLVM IR.

For local variables in a function, i can easily get the right set of instructions by using the instruction iterator and checking the operands of a particular instruction. This approach doesn't seem to work for the global variables since there's no store instruction associated with them.

Is there some way to get keep track of where the global variable is being defined without looking at the metadata field? If not, is there some way to create a dummy instruction which can be treated as a special marker for initial definition of the global variables?

1

1 Answers

0
votes

For local variables in a function, i can easily get the right set of instructions by using the instruction iterator and checking the operands of a particular instruction.

That's not entirely accurate. It's true as long as the variable is in memory (and assignment is done via store), but if it is promoted to registers you'll need to rely on llvm.dbg.value calls to track assignments into it.

This approach doesn't seem to work for the global variables since there's no store instruction associated with them.

Assignments to globals also appear as stores - except for the initial assignment.

Is there some way to get keep track of where the global variable is being defined without looking at the metadata field?

If by "where" you mean in which source line, you'll have to rely on the debug-info metadata.