add binding to read icmp predicate
authorTorok Edwin <edwintorok@gmail.com>
Thu, 6 Oct 2011 12:13:20 +0000 (12:13 +0000)
committerTorok Edwin <edwintorok@gmail.com>
Thu, 6 Oct 2011 12:13:20 +0000 (12:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141287 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/ocaml/llvm/llvm.ml
bindings/ocaml/llvm/llvm.mli
bindings/ocaml/llvm/llvm_ocaml.c
include/llvm-c/Core.h
lib/VMCore/Core.cpp

index f68ab8d842af3cff9e2508fa31c35f38f8ca3683..1f7809e4daee0af3e8851f999b0800a886709e94 100644 (file)
@@ -705,6 +705,8 @@ external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
 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
index b4b9622b630bb10ea8fb8bb1c4c73e8c9e9ea8fa..a5e5c850d6f5901bc3ba7c8dfb1dc3d651e82282 100644 (file)
@@ -1435,6 +1435,8 @@ val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
 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
index 14bdbdd068ac6b9e03c1063c0321108020e0ef90..d6849cd193a544da70ecbdae00d734969f4a8729 100644 (file)
@@ -1010,6 +1010,19 @@ DEFINE_ITERATORS(instr, Instruction, LLVMBasicBlockRef, LLVMValueRef,
                  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 */
index 3d374b062ce9acd80b9c55f00f115476053bab3f..83fe89cbcfe0ba0d73b0451be53d92bc6b72125d 100644 (file)
@@ -783,6 +783,7 @@ LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
 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);
index a21ec7a3f3ef61df58a26debf08ecbd8ff0607ff..b8d2baf1e36ffb21c118ce178823185053a576a7 100644 (file)
@@ -1552,6 +1552,15 @@ void LLVMInstructionEraseFromParent(LLVMValueRef Inst) {
   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) {