In llvm::Module
there are 2 interesting fields:
typedef SymbolTableList<Function> FunctionListType;
typedef SymbolTableList<GlobalVariable> GlobalListType;
GlobalListType GlobalList; ///< The Global Variables in the module
FunctionListType FunctionList; ///< The Functions in the module
So, if we will define some functions or global variables, we will be able to use them from any other places of our program just asking our module for them. But what about function local variables? How to define them?
Local variables are allocated via alloca
at runtime.
To create AllocaInst you need to
llvm::BasicBlock::iterator I = ...
const llvm::Type *Ty =
auto AI = new AllocaInst(Ty, 0, Name, I);
To find allocas in a function you need to iterate over instructions:
for (auto I = F->begin(), E = F->end(); I != E; ++I) {
for (auto J = I->begin(), E = I->end(); J != E; ++J) {
if (auto AI = dyn_cast<AllocaInst>(*J)) {
..
}
}
}
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