summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorRobert Widmann <devteam.codafi@gmail.com>2018-03-30 17:49:53 +0000
committerRobert Widmann <devteam.codafi@gmail.com>2018-03-30 17:49:53 +0000
commit478fce9ebfa809e0f75741bbcf1de1a7a379f5c4 (patch)
tree400a138835389691a03eb7368aa1847d322daf09 /llvm/lib
parent5f8c3e85aae8f0a34c69053e746af439622bf96e (diff)
downloadbcm5719-llvm-478fce9ebfa809e0f75741bbcf1de1a7a379f5c4.tar.gz
bcm5719-llvm-478fce9ebfa809e0f75741bbcf1de1a7a379f5c4.zip
[LLVM-C] Finish exception instruction bindings - Round 2
Summary: Previous revision caused a leak in the echo test that got caught by the ASAN bots because of missing free of the handlers array and was reverted in r328759. Resubmitting the patch with that correction. Add support for cleanupret, catchret, catchpad, cleanuppad and catchswitch and their associated accessors. Test is modified from SimplifyCFG because it contains many diverse usages of these instructions. Reviewers: whitequark, deadalnix Reviewed By: whitequark Subscribers: llvm-commits, vlad.tsyrklevich Differential Revision: https://reviews.llvm.org/D45100 llvm-svn: 328883
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/Core.cpp94
1 files changed, 92 insertions, 2 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 7430f8c288d..29a82ec6c54 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -2196,12 +2196,15 @@ LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst) {
return nullptr;
}
-/*--.. Call and invoke instructions ........................................--*/
-
unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) {
+ if (FuncletPadInst *FPI = dyn_cast<FuncletPadInst>(unwrap(Instr))) {
+ return FPI->getNumArgOperands();
+ }
return CallSite(unwrap<Instruction>(Instr)).getNumArgOperands();
}
+/*--.. Call and invoke instructions ........................................--*/
+
unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
return CallSite(unwrap<Instruction>(Instr)).getCallingConv();
}
@@ -2284,6 +2287,11 @@ LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef Invoke) {
}
LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef Invoke) {
+ if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(unwrap(Invoke))) {
+ return wrap(CRI->getUnwindDest());
+ } else if (CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(unwrap(Invoke))) {
+ return wrap(CSI->getUnwindDest());
+ }
return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
}
@@ -2292,6 +2300,11 @@ void LLVMSetNormalDest(LLVMValueRef Invoke, LLVMBasicBlockRef B) {
}
void LLVMSetUnwindDest(LLVMValueRef Invoke, LLVMBasicBlockRef B) {
+ if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(unwrap(Invoke))) {
+ return CRI->setUnwindDest(unwrap(B));
+ } else if (CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(unwrap(Invoke))) {
+ return CSI->setUnwindDest(unwrap(B));
+ }
unwrap<InvokeInst>(Invoke)->setUnwindDest(unwrap(B));
}
@@ -2513,10 +2526,53 @@ LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty), NumClauses, Name));
}
+LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
+ LLVMValueRef *Args, unsigned NumArgs,
+ const char *Name) {
+ return wrap(unwrap(B)->CreateCatchPad(unwrap(ParentPad),
+ makeArrayRef(unwrap(Args), NumArgs),
+ Name));
+}
+
+LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
+ LLVMValueRef *Args, unsigned NumArgs,
+ const char *Name) {
+ if (ParentPad == nullptr) {
+ Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
+ ParentPad = wrap(Constant::getNullValue(Ty));
+ }
+ return wrap(unwrap(B)->CreateCleanupPad(unwrap(ParentPad),
+ makeArrayRef(unwrap(Args), NumArgs),
+ Name));
+}
+
LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
}
+LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad,
+ LLVMBasicBlockRef UnwindBB,
+ unsigned NumHandlers, const char *Name) {
+ if (ParentPad == nullptr) {
+ Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
+ ParentPad = wrap(Constant::getNullValue(Ty));
+ }
+ return wrap(unwrap(B)->CreateCatchSwitch(unwrap(ParentPad), unwrap(UnwindBB),
+ NumHandlers, Name));
+}
+
+LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
+ LLVMBasicBlockRef BB) {
+ return wrap(unwrap(B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
+ unwrap(BB)));
+}
+
+LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
+ LLVMBasicBlockRef BB) {
+ return wrap(unwrap(B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
+ unwrap(BB)));
+}
+
LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
return wrap(unwrap(B)->CreateUnreachable());
}
@@ -2551,6 +2607,40 @@ void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
}
+void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest) {
+ unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Dest));
+}
+
+unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch) {
+ return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
+}
+
+void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers) {
+ CatchSwitchInst *CSI = unwrap<CatchSwitchInst>(CatchSwitch);
+ for (CatchSwitchInst::handler_iterator I = CSI->handler_begin(),
+ E = CSI->handler_end(); I != E; ++I)
+ *Handlers++ = wrap(*I);
+}
+
+LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad) {
+ return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
+}
+
+void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch) {
+ unwrap<CatchPadInst>(CatchPad)
+ ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
+}
+
+/*--.. Funclets ...........................................................--*/
+
+LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i) {
+ return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(i));
+}
+
+void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value) {
+ unwrap<FuncletPadInst>(Funclet)->setArgOperand(i, unwrap(value));
+}
+
/*--.. Arithmetic ..........................................................--*/
LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
OpenPOWER on IntegriCloud