Skip to content

Commit eb50c96

Browse files
authored
Add intrinsics for OCaml exception handling (#13)
1 parent 34028aa commit eb50c96

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,9 @@ def int_eh_sjlj_setjmp : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty]>;
10461046
def int_eh_sjlj_longjmp : Intrinsic<[], [llvm_ptr_ty], [IntrNoReturn]>;
10471047
def int_eh_sjlj_setup_dispatch : Intrinsic<[], []>;
10481048

1049+
def int_eh_ocaml_try : Intrinsic<[llvm_i32_ty], []>;
1050+
def int_eh_ocaml_touch : Intrinsic<[], [llvm_ptr_ty], [IntrHasSideEffects]>;
1051+
10491052
//===---------------- Generic Variable Attribute Intrinsics----------------===//
10501053
//
10511054
def int_var_annotation : DefaultAttrsIntrinsic<

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6287,6 +6287,20 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
62876287
DAG.setRoot(DAG.getNode(ISD::EH_SJLJ_SETUP_DISPATCH, sdl, MVT::Other,
62886288
getRoot()));
62896289
return;
6290+
case Intrinsic::eh_ocaml_try: {
6291+
// Always returns 0. To be used with the "returns twice" attribute.
6292+
// Acts as a black box value to use to branch either to the try block or
6293+
// handler to give an idea of how control flow would look like to LLVM.
6294+
// (It would be nice to mark the attribute directly in LLVM, but putting
6295+
// it in the IR manually suffices for now.)
6296+
setValue(&I, DAG.getConstant(0, sdl, MVT::i32));
6297+
return;
6298+
}
6299+
case Intrinsic::eh_ocaml_touch: {
6300+
// A no-op that makes sure its alloca'd pointer argument doesn't get
6301+
// lowered to a temporary and stays on the stack.
6302+
return;
6303+
}
62906304
case Intrinsic::masked_gather:
62916305
visitMaskedGather(I);
62926306
return;

0 commit comments

Comments
 (0)