mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-14 01:20:40 +00:00
[OCaml] PR19859: Add Llvm.{fcmp_predicate,float_of_const}.
Patch by Gabriel Radanne <drupyog@zoho.com>. llvm-svn: 220815
This commit is contained in:
parent
e9d029fa22
commit
927677ad96
@ -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 =
|
||||
|
@ -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]. *)
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user