Index: bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml =================================================================== --- bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml +++ bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml @@ -121,3 +121,6 @@ external add_basic_alias_analysis : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit = "llvm_add_basic_alias_analysis" +external add_merge_return + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_merge_return" Index: bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli =================================================================== --- bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli +++ bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli @@ -201,3 +201,8 @@ external add_basic_alias_analysis : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit = "llvm_add_basic_alias_analysis" + +(** See the [llvm::createUnifyFunctionExitNodesPass] function. *) +external add_merge_return + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_merge_return" Index: bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c =================================================================== --- bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c +++ bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c @@ -247,3 +247,9 @@ LLVMAddBasicAliasAnalysisPass(PM); return Val_unit; } + +/* [ unit */ +CAMLprim value llvm_add_merge_return(LLVMPassManagerRef PM) { + LLVMAddUnifyFunctionExitNodesPass(PM); + return Val_unit; +} Index: include/llvm-c/Transforms/Scalar.h =================================================================== --- include/llvm-c/Transforms/Scalar.h +++ include/llvm-c/Transforms/Scalar.h @@ -153,6 +153,9 @@ /** See llvm::createBasicAliasAnalysisPass function */ void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM); +/** See llvm::createUnifyFunctionExitNodesPass function */ +void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM); + /** * @} */ Index: lib/Transforms/Scalar/Scalar.cpp =================================================================== --- lib/Transforms/Scalar/Scalar.cpp +++ lib/Transforms/Scalar/Scalar.cpp @@ -26,6 +26,7 @@ #include "llvm/InitializePasses.h" #include "llvm/Transforms/Scalar/GVN.h" #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h" +#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h" using namespace llvm; @@ -278,3 +279,7 @@ void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) { unwrap(PM)->add(createLowerExpectIntrinsicPass()); } + +void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM) { + unwrap(PM)->add(createUnifyFunctionExitNodesPass()); +}