Search code examples
llvmllvm-ir

Determine all global variables of a module


How to determine all global variables of a LLVM module?

I want to modify them using a module pass.


Solution

  • 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()) ...