Creating local variable in function LLVM

前端 未结 1 1233
-上瘾入骨i
-上瘾入骨i 2021-01-22 17:12

In llvm::Module there are 2 interesting fields:

typedef SymbolTableList FunctionListType;
typedef SymbolTableList

        
相关标签:
1条回答
  • 2021-01-22 18:19

    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)) {
          ..
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题