How to determine all global variables of a LLVM module?
I want to modify them using a module pass.
llvm::Module
class has getGlobalList()
method:
/// Get the Module's list of global variables.
GlobalListType &getGlobalList() { return GlobalList; }
So you can do something like:
for (auto &Global : M->getModule()->getGlobalList()) ...
In LLVM-17, getGlobalList()
has been made a private method. The list of global variables can be accessed via iterators (both mutable and const versions are available): global_begin() and global_end(). Referring to the code of Module.h makes it quite clear. A for loop like the following will do the needful:
for (auto Global = M->getModule()->global_begin();
Global != M->getModule()->global_end();
++Global)