summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-23 17:26:39 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-23 17:26:39 +0000
commit1234749853d68a24cc0de6d7ce580fe05807341b (patch)
tree130304024d74f54cec2d7a49812ae3f323e2bac2 /clang/lib
parente591411fd69bb669a5aefe414bb81479ddb1cbb3 (diff)
downloadbcm5719-llvm-1234749853d68a24cc0de6d7ce580fe05807341b.tar.gz
bcm5719-llvm-1234749853d68a24cc0de6d7ce580fe05807341b.zip
Add low level support for generating invoke instead of calls.
- No functionality change. llvm-svn: 65325
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGCall.cpp49
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp2
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h11
3 files changed, 46 insertions, 16 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index db5085aaab8..8f4367c8586 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/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)
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9175d16063c..ccd961ac283 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -25,7 +25,7 @@ using namespace CodeGen;
CodeGenFunction::CodeGenFunction(CodeGenModule &cgm)
: CGM(cgm), Target(CGM.getContext().Target), DebugInfo(0), SwitchInsn(0),
- CaseRangeBlock(0) {
+ CaseRangeBlock(0), InvokeDest(0) {
LLVMIntTy = ConvertType(getContext().IntTy);
LLVMPointerWidth = Target.getPointerWidth(0);
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 8bda453ee72..b3d6a327ebe 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -190,6 +190,10 @@ private:
/// statement range in current switch instruction.
llvm::BasicBlock *CaseRangeBlock;
+ /// InvokeDest - This is the nearest exception target for calls
+ /// which can unwind, when exceptions are being used.
+ llvm::BasicBlock *InvokeDest;
+
// VLASizeMap - This keeps track of the associated size for each VLA type.
// FIXME: Maybe this could be a stack of maps that is pushed/popped as we
// enter/leave scopes.
@@ -233,6 +237,13 @@ public:
ASTContext &getContext() const;
CGDebugInfo *getDebugInfo() { return DebugInfo; }
+ llvm::BasicBlock *getInvokeDest() { return InvokeDest; }
+ void setInvokeDest(llvm::BasicBlock *B) { InvokeDest = B; }
+
+ //===--------------------------------------------------------------------===//
+ // Objective-C
+ //===--------------------------------------------------------------------===//
+
void GenerateObjCMethod(const ObjCMethodDecl *OMD);
void StartObjCMethod(const ObjCMethodDecl *MD,
OpenPOWER on IntegriCloud