Function *FunctionAST::codegen(){ ... Builder->SetInsertPoint(BB);
// Record the function arguments in the NamedValues map. NamedValues.clear(); for (auto &Arg : TheFunction->args()) { // Create an alloca for this variable. AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, Arg.getName());
// Store the initial value into the alloca. Builder->CreateStore(&Arg, Alloca);
// Add arguments to variable symbol table. NamedValues[std::string(Arg.getName())] = Alloca; }
if (Value *RetVal = Body->codegen()) { ...
并用PromoteMemoryToRegisterPass实现 Mem2Reg 的优化
1 2
// Promote allocas to registers. functionPassManager->add(createPromoteMemoryToRegisterPass());