diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-23 17:26:39 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-23 17:26:39 +0000 |
commit | 9834ffbe54788239c8361d3cfe5826fd277ddfb2 (patch) | |
tree | cd5c2a3bbdefed102e290884940fb4fafa807ade /lib/CodeGen/CGCall.cpp | |
parent | 4634735e0aeb2371c3f75578978ec89f87651ad4 (diff) |
Add low level support for generating invoke instead of calls.
- No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65325 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCall.cpp')
-rw-r--r-- | lib/CodeGen/CGCall.cpp | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index db5085aaab..8f4367c858 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1517,7 +1517,6 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, } if (FuncAttrs) PAL.push_back(llvm::AttributeWithIndex::get(~0, FuncAttrs)); - } void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, @@ -1763,26 +1762,46 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, break; } } - - llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size()); + llvm::BasicBlock *InvokeDest = getInvokeDest(); CodeGen::AttributeListType AttributeList; CGM.ConstructAttributeList(CallInfo, TargetDecl, AttributeList); - CI->setAttributes(llvm::AttrListPtr::get(AttributeList.begin(), - AttributeList.size())); + llvm::AttrListPtr Attrs = llvm::AttrListPtr::get(AttributeList.begin(), + AttributeList.end()); - if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee)) - CI->setCallingConv(F->getCallingConv()); + llvm::Instruction *CI; + if (!InvokeDest || Attrs.getFnAttributes() & (llvm::Attribute::NoUnwind || + llvm::Attribute::NoReturn)) { + llvm::CallInst *CallInstr = + Builder.CreateCall(Callee, &Args[0], &Args[0]+Args.size()); + CI = CallInstr; + + CallInstr->setAttributes(Attrs); + if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee)) + CallInstr->setCallingConv(F->getCallingConv()); + + // If the call doesn't return, finish the basic block and clear the + // insertion point; this allows the rest of IRgen to discard + // unreachable code. + if (CallInstr->doesNotReturn()) { + Builder.CreateUnreachable(); + Builder.ClearInsertionPoint(); + + // Return a reasonable RValue. + return GetUndefRValue(RetTy); + } + } else { + llvm::BasicBlock *Cont = createBasicBlock("invoke.cont"); + llvm::InvokeInst *InvokeInstr = + Builder.CreateInvoke(Callee, Cont, InvokeDest, + &Args[0], &Args[0]+Args.size()); + CI = InvokeInstr; - // If the call doesn't return, finish the basic block and clear the - // insertion point; this allows the rest of IRgen to discard - // unreachable code. - if (CI->doesNotReturn()) { - Builder.CreateUnreachable(); - Builder.ClearInsertionPoint(); + InvokeInstr->setAttributes(Attrs); + if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee)) + InvokeInstr->setCallingConv(F->getCallingConv()); - // Return a reasonable RValue. - return GetUndefRValue(RetTy); + EmitBlock(Cont); } if (CI->getType() != llvm::Type::VoidTy) |