The big catch/finally rework, part 1

Never generates any landing pads or invoke instructions right now
for simplicity. The code for emitting them will be added back in
the next step.

The "after..." blocks without any precedessors remain for now, as
we need a clean way to suppress any codegen for that block (but
not new blocks, which might resolve labels) before tackling that
one.

Builds druntime/Phobos on OS X x86_64 (albeit without EH, of course).
This commit is contained in:
David Nadlinger 2015-08-19 00:56:33 +02:00
parent bfc20df4c8
commit 4236ae9ce5
12 changed files with 861 additions and 1315 deletions

View file

@ -884,40 +884,41 @@ void DtoDefineFunction(FuncDeclaration* fd)
}
}
FuncGen fg;
irFunc->gen = &fg;
DtoCreateNestedContext(fd);
if (fd->vresult && !
fd->vresult->nestedrefs.dim // FIXME: not sure here :/
)
{
DtoVarDeclaration(fd->vresult);
ScopeStack scopeStack(gIR);
irFunc->scopes = &scopeStack;
DtoCreateNestedContext(fd);
if (fd->vresult && !fd->vresult->nestedrefs.dim) // FIXME: not sure here :/
{
DtoVarDeclaration(fd->vresult);
}
// D varargs: prepare _argptr and _arguments
if (f->linkage == LINKd && f->varargs == 1)
{
// allocate _argptr (of type core.stdc.stdarg.va_list)
LLValue* argptrmem = DtoAlloca(Type::tvalist, "_argptr_mem");
irFunc->_argptr = argptrmem;
// initialize _argptr with a call to the va_start intrinsic
LLValue* vaStartArg = gABI->prepareVaStart(argptrmem);
llvm::CallInst::Create(GET_INTRINSIC_DECL(vastart), vaStartArg, "", gIR->scopebb());
// copy _arguments to a memory location
LLType* argumentsType = irFunc->_arguments->getType();
LLValue* argumentsmem = DtoRawAlloca(argumentsType, 0, "_arguments_mem");
new llvm::StoreInst(irFunc->_arguments, argumentsmem, gIR->scopebb());
irFunc->_arguments = argumentsmem;
}
// output function body
Statement_toIR(fd->fbody, gIR);
irFunc->scopes = 0;
}
// D varargs: prepare _argptr and _arguments
if (f->linkage == LINKd && f->varargs == 1)
{
// allocate _argptr (of type core.stdc.stdarg.va_list)
LLValue* argptrmem = DtoAlloca(Type::tvalist, "_argptr_mem");
irFunc->_argptr = argptrmem;
// initialize _argptr with a call to the va_start intrinsic
LLValue* vaStartArg = gABI->prepareVaStart(argptrmem);
llvm::CallInst::Create(GET_INTRINSIC_DECL(vastart), vaStartArg, "", gIR->scopebb());
// copy _arguments to a memory location
LLType* argumentsType = irFunc->_arguments->getType();
LLValue* argumentsmem = DtoRawAlloca(argumentsType, 0, "_arguments_mem");
new llvm::StoreInst(irFunc->_arguments, argumentsmem, gIR->scopebb());
irFunc->_arguments = argumentsmem;
}
// output function body
codegenFunction(fd->fbody, gIR);
irFunc->gen = 0;
llvm::BasicBlock* bb = gIR->scopebb();
if (pred_begin(bb) == pred_end(bb) && bb != &bb->getParent()->getEntryBlock()) {
// This block is trivially unreachable, so just delete it.