[LLVMdev] Extracting the global variables accessed by individual function with function pass

Duncan Sands baldrick at free.fr
Mon Sep 2 04:15:25 PDT 2013


Hi,

> Is there a way to dump the global variables, which are accessed (read/written
> to) by each function within the LLVM function pass?
> Any pointers on how that info can be extracted in LLVM for each function in the
> application?

you will have to write your own pass to do this.  For each global, visit each
of its uses (via use_begin, use_end).  If the use is a constant (isa<Constant>),
visit each of its uses too (do this recursively until you aren't visiting
constants any more).  If a use isn't a constant, check whether it's parent
(getParent) is the function you are interested in.  The point of recursing on
constant uses is that the global may be used in a constant expression (eg a
constant bitcast) before actually being used by an instruction.

Ciao, Duncan.



More information about the llvm-dev mailing list