Revise IRScope refactoring

LLVM already provides suited RAII helper types to restore the IRBuilder
state. [They sadly aren't movable, so I've had to wrap them in a
unique_ptr.]

While at it, also minimally revise debuginfo generation for functions.
This commit is contained in:
Martin Kinkelin 2020-08-25 19:25:19 +02:00
parent 2fb31f84a9
commit 1d969cfcca
10 changed files with 60 additions and 151 deletions

View file

@ -892,12 +892,11 @@ void emitDMDStyleFunctionTrace(IRState &irs, FuncDeclaration *fd,
// Push cleanup block that calls _c_trace_epi at function exit.
{
auto traceEpilogBB = irs.insertBB("trace_epi");
const auto savedInsertPoint = irs.getInsertPoint();
const auto savedInsertPoint = irs.saveInsertPoint();
irs.ir->SetInsertPoint(traceEpilogBB);
irs.ir->CreateCall(
getRuntimeFunction(fd->endloc, irs.module, "_c_trace_epi"));
funcGen.scopes.pushCleanup(traceEpilogBB, irs.scopebb());
irs.setInsertPoint(savedInsertPoint);
}
}
@ -1175,9 +1174,9 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
llvm::BasicBlock::Create(gIR->context(), "", func);
// set up the IRBuilder scope for the function
FunctionIRBuilderScope irBuilderScope(*gIR);
gIR->setInsertPoint(beginbb);
const auto savedIRBuilderScope = gIR->setInsertPoint(beginbb);
gIR->ir->setFastMathFlags(irFunc->FMF);
gIR->DBuilder.EmitFuncStart(fd);
// @naked: emit body and return, no prologue/epilogue
if (func->hasFnAttribute(llvm::Attribute::Naked)) {
@ -1200,9 +1199,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
"alloca_point", beginbb);
funcGen.allocapoint = allocaPoint;
// debug info - after all allocas, but before any llvm.dbg.declare etc
gIR->DBuilder.EmitFuncStart(fd);
emitInstrumentationFnEnter(fd);
if (global.params.trace && fd->emitInstrumentation && !fd->isCMain() &&
@ -1283,11 +1279,10 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
{
auto *vaendBB =
llvm::BasicBlock::Create(gIR->context(), "vaend", gIR->topfunc());
const auto savedInsertPoint = gIR->getInsertPoint();
const auto savedInsertPoint = gIR->saveInsertPoint();
gIR->ir->SetInsertPoint(vaendBB);
gIR->ir->CreateCall(GET_INTRINSIC_DECL(vaend), llAp);
funcGen.scopes.pushCleanup(vaendBB, gIR->scopebb());
gIR->setInsertPoint(savedInsertPoint);
}
}
@ -1328,7 +1323,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
gIR->ir->CreateRet(llvm::UndefValue::get(func->getReturnType()));
}
}
gIR->DBuilder.EmitFuncEnd(fd);
// erase alloca point
if (allocaPoint->getParent()) {