aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zotov <whitequark@whitequark.org>2014-10-28 19:46:48 +0000
committerPeter Zotov <whitequark@whitequark.org>2014-10-28 19:46:48 +0000
commitfec0486a30817aad5e35674d8649ab8d8990eaa3 (patch)
tree577789c65e97287527e1ba33ddb5d38b51ccdf8c
parent1d98e6ddefe720589acca7138e563dff4f146f96 (diff)
downloadllvm-fec0486a30817aad5e35674d8649ab8d8990eaa3.zip
llvm-fec0486a30817aad5e35674d8649ab8d8990eaa3.tar.gz
llvm-fec0486a30817aad5e35674d8649ab8d8990eaa3.tar.bz2
[OCaml] PR19859: Add Llvm.{fcmp_predicate,float_of_const}.
Patch by Gabriel Radanne <drupyog@zoho.com>. llvm-svn: 220815
-rw-r--r--llvm/bindings/ocaml/llvm/llvm.ml3
-rw-r--r--llvm/bindings/ocaml/llvm/llvm.mli9
-rw-r--r--llvm/bindings/ocaml/llvm/llvm_ocaml.c28
3 files changed, 40 insertions, 0 deletions
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index dae5bda..0c434af 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -466,6 +466,8 @@ external int64_of_const : llvalue -> Int64.t option
external const_int_of_string : lltype -> string -> int -> llvalue
= "llvm_const_int_of_string"
external const_float : lltype -> float -> llvalue = "llvm_const_float"
+external float_of_const : llvalue -> float option
+ = "llvm_float_of_const"
external const_float_of_string : lltype -> string -> llvalue
= "llvm_const_float_of_string"
@@ -955,6 +957,7 @@ external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
external instr_opcode : llvalue -> Opcode.t = "llvm_instr_get_opcode"
external icmp_predicate : llvalue -> Icmp.t option = "llvm_instr_icmp_predicate"
+external fcmp_predicate : llvalue -> Fcmp.t option = "llvm_instr_fcmp_predicate"
external instr_clone : llvalue -> llvalue = "llvm_instr_clone"
let rec iter_instrs_range f i e =
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index 8a205ce..10aa706 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -842,6 +842,11 @@ val const_int_of_string : lltype -> string -> int -> llvalue
value [n]. See the method [llvm::ConstantFP::get]. *)
val const_float : lltype -> float -> llvalue
+(** [float_of_const c] returns the float value of the [c] constant float.
+ None is returned if this is not an float constant.
+ See the method [llvm::ConstantFP::getDoubleValue].*)
+val float_of_const : llvalue -> float option
+
(** [const_float_of_string ty s] returns the floating point constant of type
[ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
val const_float_of_string : lltype -> string -> llvalue
@@ -1699,6 +1704,10 @@ val instr_opcode : llvalue -> Opcode.t
instruction [i]. *)
val icmp_predicate : llvalue -> Icmp.t option
+(** [fcmp_predicate i] returns the [fcmp.t] corresponding to an [fcmp]
+ instruction [i]. *)
+val fcmp_predicate : llvalue -> Fcmp.t option
+
(** [inst_clone i] returns a copy of instruction [i],
The instruction has no parent, and no name.
See the method [llvm::Instruction::clone]. *)
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 93a9972..0210722 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -734,6 +734,22 @@ CAMLprim LLVMValueRef llvm_const_float(LLVMTypeRef RealTy, value N) {
return LLVMConstReal(RealTy, Double_val(N));
}
+
+/* llvalue -> float */
+CAMLprim value llvm_float_of_const(LLVMValueRef Const)
+{
+ if (LLVMIsAConstantFP(Const)) {
+ LLVMBool LosesInfo;
+ double res = LLVMConstRealGetDouble(Const, &LosesInfo);
+ if (LosesInfo)
+ return Val_int(0);
+ value Option = alloc(1, 0);
+ Field(Option, 0) = caml_copy_double(res);
+ return Option;
+ }
+ return Val_int(0);
+}
+
/* lltype -> string -> llvalue */
CAMLprim LLVMValueRef llvm_const_float_of_string(LLVMTypeRef RealTy, value S) {
return LLVMConstRealOfStringAndSize(RealTy, String_val(S),
@@ -1358,6 +1374,18 @@ CAMLprim value llvm_instr_icmp_predicate(LLVMValueRef Val) {
CAMLreturn(Val_int(0));
}
+/* llvalue -> FCmp.t option */
+CAMLprim value llvm_instr_fcmp_predicate(LLVMValueRef Val) {
+ CAMLparam0();
+ int x = LLVMGetFCmpPredicate(Val);
+ if (x) {
+ value Option = alloc(1, 0);
+ Field(Option, 0) = Val_int(x - LLVMRealPredicateFalse);
+ CAMLreturn(Option);
+ }
+ CAMLreturn(Val_int(0));
+}
+
/* llvalue -> llvalue */
CAMLprim LLVMValueRef llvm_instr_clone(LLVMValueRef Inst) {
if (!LLVMIsAInstruction(Inst))