0

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?

vPraetor
  • 313
  • 1
  • 3
  • 13

1 Answers1

0

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.

Oak
  • 26,231
  • 8
  • 93
  • 152
  • I am doing this before the variables are promoted to registers. I was finally able to get a (Value *) for the global allocs via getNamedValue() method and am able to use it to track redefinitions of global variables. Might not be best solution but it seems to do the job for now. – vPraetor Mar 06 '14 at 19:08