Creating local variable in function LLVM

徘徊边缘 提交于 2019-12-02 02:56:31

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)) {
      ..
    }
  }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!