add binding to read icmp predicate

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141287 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml
index f68ab8d..1f7809e 100644
--- a/bindings/ocaml/llvm/llvm.ml
+++ b/bindings/ocaml/llvm/llvm.ml
@@ -705,6 +705,8 @@
 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
                      = "llvm_instr_pred"
 
+external icmp_predicate : llvalue -> Icmp.t option = "llvm_instr_icmp_predicate"
+
 let rec iter_instrs_range f i e =
   if i = e then () else
   match i with
diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli
index b4b9622..a5e5c85 100644
--- a/bindings/ocaml/llvm/llvm.mli
+++ b/bindings/ocaml/llvm/llvm.mli
@@ -1435,6 +1435,8 @@
 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
 
 
+val icmp_predicate : llvalue -> Icmp.t option
+
 (** {7 Operations on call sites} *)
 
 (** [instruction_call_conv ci] is the calling convention for the call or invoke
diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c
index 14bdbdd..d6849cd 100644
--- a/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/bindings/ocaml/llvm/llvm_ocaml.c
@@ -1010,6 +1010,19 @@
                  LLVMGetInstructionParent)
 
 
+/* llvalue -> ICmp.t */
+CAMLprim value llvm_instr_icmp_predicate(LLVMValueRef Val) {
+    CAMLparam0();
+    int x = LLVMGetICmpPredicate(Val);
+    if (x) {
+	value Option = alloc(1, 0);
+	Field(Option, 0) = Val_int(x - LLVMIntEQ);
+	CAMLreturn(Option);
+    }
+    CAMLreturn(Val_int(0));
+}
+
+
 /*--... Operations on call sites ...........................................--*/
 
 /* llvalue -> int */
diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h
index 3d374b0..83fe89c 100644
--- a/include/llvm-c/Core.h
+++ b/include/llvm-c/Core.h
@@ -783,6 +783,7 @@
 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
+LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
 
 /* Operations on call sites */
 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index a21ec7a..b8d2baf 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -1552,6 +1552,15 @@
   unwrap<Instruction>(Inst)->eraseFromParent();
 }
 
+LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
+    if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
+	return (LLVMIntPredicate)I->getPredicate();
+    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
+	if (CE->getOpcode() == Instruction::ICmp)
+	    return (LLVMIntPredicate)CE->getPredicate();
+    return (LLVMIntPredicate)0;
+}
+
 /*--.. Call and invoke instructions ........................................--*/
 
 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {