How to determine all global variables of a LLVM module?
I want to modify them using a module pass.
Use the env command. The env command returns a list of all global variables that have been defined. If a global variable exists in a script that hasn't been run yet, it will not show up in the output from env .
A global variable is a variable which is accessible in multiple scopes. In Python, it is better to use a single module to hold all the global variables you want to use and whenever you want to use them, just import this module, and then you can modify that and it will be visible in other modules that do the same.
The best way to share global variables across modules across a single program is to create a config module. Just import the config module in all modules of your application; the module then becomes available as a global name.
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()) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With