mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
[OCaml] Refactor Llvm_target interface
This commit brings the module structure, argument order and primitive names in Llvm_target in order with the rest of the bindings, in preparation for adding TargetMachine API. llvm-svn: 194773
This commit is contained in:
parent
e66ae0045d
commit
5d089306c3
@ -324,10 +324,18 @@ CAMLprim value llvm_ee_free_machine_code(LLVMValueRef F,
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
extern value llvm_alloc_target_data(LLVMTargetDataRef TargetData);
|
||||
extern value llvm_alloc_data_layout(LLVMTargetDataRef TargetData);
|
||||
|
||||
/* ExecutionEngine.t -> Llvm_target.TargetData.t */
|
||||
CAMLprim value llvm_ee_get_target_data(LLVMExecutionEngineRef EE) {
|
||||
LLVMTargetDataRef TD = LLVMGetExecutionEngineTargetData(EE);
|
||||
return llvm_alloc_target_data(TD);
|
||||
/* ExecutionEngine.t -> Llvm_target.DataLayout.t */
|
||||
CAMLprim value llvm_ee_get_data_layout(LLVMExecutionEngineRef EE) {
|
||||
value DataLayout;
|
||||
LLVMTargetDataRef OrigDataLayout;
|
||||
OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);
|
||||
|
||||
char* TargetDataCStr;
|
||||
TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
|
||||
DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
|
||||
LLVMDisposeMessage(TargetDataCStr);
|
||||
|
||||
return DataLayout;
|
||||
}
|
||||
|
@ -83,8 +83,8 @@ module ExecutionEngine = struct
|
||||
external free_machine_code: Llvm.llvalue -> t -> unit
|
||||
= "llvm_ee_free_machine_code"
|
||||
|
||||
external target_data: t -> Llvm_target.DataLayout.t
|
||||
= "llvm_ee_get_target_data"
|
||||
external data_layout : t -> Llvm_target.DataLayout.t
|
||||
= "llvm_ee_get_data_layout"
|
||||
|
||||
(* The following are not bound. Patches are welcome.
|
||||
|
||||
|
@ -147,9 +147,8 @@ module ExecutionEngine: sig
|
||||
used to store the machine code for the function [f]. *)
|
||||
val free_machine_code : Llvm.llvalue -> t -> unit
|
||||
|
||||
(** [target_data ee] is the target data owned by the execution engine
|
||||
[ee]. *)
|
||||
val target_data : t -> Llvm_target.DataLayout.t
|
||||
(** [data_layout ee] is the data layout of the execution engine [ee]. *)
|
||||
val data_layout : t -> Llvm_target.DataLayout.t
|
||||
end
|
||||
|
||||
val initialize_native_target : unit -> bool
|
||||
|
@ -16,32 +16,36 @@ end
|
||||
module DataLayout = struct
|
||||
type t
|
||||
|
||||
external create : string -> t = "llvm_targetdata_create"
|
||||
external add : t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit
|
||||
= "llvm_targetdata_add"
|
||||
external as_string : t -> string = "llvm_targetdata_as_string"
|
||||
external of_string : string -> t = "llvm_datalayout_of_string"
|
||||
external as_string : t -> string = "llvm_datalayout_as_string"
|
||||
external add_to_pass_manager : [<Llvm.PassManager.any]
|
||||
Llvm.PassManager.t -> t -> unit
|
||||
= "llvm_datalayout_add_to_pass_manager"
|
||||
external byte_order : t -> Endian.t = "llvm_datalayout_byte_order"
|
||||
external pointer_size : t -> int = "llvm_datalayout_pointer_size"
|
||||
external intptr_type : Llvm.llcontext -> t -> Llvm.lltype
|
||||
= "llvm_datalayout_intptr_type"
|
||||
external qualified_pointer_size : int -> t -> int
|
||||
= "llvm_datalayout_qualified_pointer_size"
|
||||
external qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
|
||||
= "llvm_datalayout_qualified_intptr_type"
|
||||
external size_in_bits : Llvm.lltype -> t -> Int64.t
|
||||
= "llvm_datalayout_size_in_bits"
|
||||
external store_size : Llvm.lltype -> t -> Int64.t
|
||||
= "llvm_datalayout_store_size"
|
||||
external abi_size : Llvm.lltype -> t -> Int64.t
|
||||
= "llvm_datalayout_abi_size"
|
||||
external abi_align : Llvm.lltype -> t -> int
|
||||
= "llvm_datalayout_abi_align"
|
||||
external stack_align : Llvm.lltype -> t -> int
|
||||
= "llvm_datalayout_stack_align"
|
||||
external preferred_align : Llvm.lltype -> t -> int
|
||||
= "llvm_datalayout_preferred_align"
|
||||
external preferred_align_of_global : Llvm.llvalue -> t -> int
|
||||
= "llvm_datalayout_preferred_align_of_global"
|
||||
external element_at_offset : Llvm.lltype -> Int64.t -> t -> int
|
||||
= "llvm_datalayout_element_at_offset"
|
||||
external offset_of_element : Llvm.lltype -> int -> t -> Int64.t
|
||||
= "llvm_datalayout_offset_of_element"
|
||||
end
|
||||
|
||||
external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
|
||||
external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
|
||||
external intptr_type : DataLayout.t -> Llvm.llcontext -> Llvm.lltype
|
||||
= "llvm_intptr_type"
|
||||
external qualified_pointer_size : DataLayout.t -> int -> int
|
||||
= "llvm_qualified_pointer_size"
|
||||
external qualified_intptr_type : DataLayout.t -> Llvm.llcontext ->
|
||||
int -> Llvm.lltype
|
||||
= "llvm_qualified_intptr_type"
|
||||
external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
|
||||
= "llvm_size_in_bits"
|
||||
external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
|
||||
external abi_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
|
||||
external abi_align : DataLayout.t -> Llvm.lltype -> int = "llvm_abi_align"
|
||||
external stack_align : DataLayout.t -> Llvm.lltype -> int = "llvm_stack_align"
|
||||
external preferred_align : DataLayout.t -> Llvm.lltype -> int
|
||||
= "llvm_preferred_align"
|
||||
external preferred_align_of_global : DataLayout.t -> Llvm.llvalue -> int
|
||||
= "llvm_preferred_align_of_global"
|
||||
external element_at_offset : DataLayout.t -> Llvm.lltype -> Int64.t -> int
|
||||
= "llvm_element_at_offset"
|
||||
external offset_of_element : DataLayout.t -> Llvm.lltype -> int -> Int64.t
|
||||
= "llvm_offset_of_element"
|
||||
|
@ -21,84 +21,75 @@ end
|
||||
module DataLayout : sig
|
||||
type t
|
||||
|
||||
(** [DataLayout.create rep] parses the target data string representation [rep].
|
||||
See the constructor llvm::DataLayout::DataLayout. *)
|
||||
external create : string -> t = "llvm_targetdata_create"
|
||||
(** [of_string rep] parses the data layout string representation [rep].
|
||||
See the constructor [llvm::DataLayout::DataLayout]. *)
|
||||
val of_string : string -> t
|
||||
|
||||
(** [add_target_data td pm] adds the target data [td] to the pass manager [pm].
|
||||
Does not take ownership of the target data.
|
||||
See the method llvm::PassManagerBase::add. *)
|
||||
external add : t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit
|
||||
= "llvm_targetdata_add"
|
||||
(** [as_string dl] is the string representation of the data layout [dl].
|
||||
See the method [llvm::DataLayout::getStringRepresentation]. *)
|
||||
val as_string : t -> string
|
||||
|
||||
(** [as_string td] is the string representation of the target data [td].
|
||||
See the constructor llvm::DataLayout::DataLayout. *)
|
||||
external as_string : t -> string = "llvm_targetdata_as_string"
|
||||
(** [add_to_pass_manager dl pm] adds the target data [dl] to
|
||||
the pass manager [pm].
|
||||
See the method [llvm::PassManagerBase::add]. *)
|
||||
val add_to_pass_manager : [<Llvm.PassManager.any] Llvm.PassManager.t ->
|
||||
t -> unit
|
||||
|
||||
(** Returns the byte order of a target, either [Endian.Big] or
|
||||
[Endian.Little].
|
||||
See the method [llvm::DataLayout::isLittleEndian]. *)
|
||||
val byte_order : t -> Endian.t
|
||||
|
||||
(** Returns the pointer size in bytes for a target.
|
||||
See the method [llvm::DataLayout::getPointerSize]. *)
|
||||
val pointer_size : t -> int
|
||||
|
||||
(** Returns the integer type that is the same size as a pointer on a target.
|
||||
See the method [llvm::DataLayout::getIntPtrType]. *)
|
||||
val intptr_type : Llvm.llcontext -> t -> Llvm.lltype
|
||||
|
||||
(** Returns the pointer size in bytes for a target in a given address space.
|
||||
See the method [llvm::DataLayout::getPointerSize]. *)
|
||||
val qualified_pointer_size : int -> t -> int
|
||||
|
||||
(** Returns the integer type that is the same size as a pointer on a target
|
||||
in a given address space.
|
||||
See the method [llvm::DataLayout::getIntPtrType]. *)
|
||||
val qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
|
||||
|
||||
(** Computes the size of a type in bits for a target.
|
||||
See the method [llvm::DataLayout::getTypeSizeInBits]. *)
|
||||
val size_in_bits : Llvm.lltype -> t -> Int64.t
|
||||
|
||||
(** Computes the storage size of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeStoreSize]. *)
|
||||
val store_size : Llvm.lltype -> t -> Int64.t
|
||||
|
||||
(** Computes the ABI size of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeAllocSize]. *)
|
||||
val abi_size : Llvm.lltype -> t -> Int64.t
|
||||
|
||||
(** Computes the ABI alignment of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeABISize]. *)
|
||||
val abi_align : Llvm.lltype -> t -> int
|
||||
|
||||
(** Computes the call frame alignment of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeABISize]. *)
|
||||
val stack_align : Llvm.lltype -> t -> int
|
||||
|
||||
(** Computes the preferred alignment of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeABISize]. *)
|
||||
val preferred_align : Llvm.lltype -> t -> int
|
||||
|
||||
(** Computes the preferred alignment of a global variable in bytes for
|
||||
a target. See the method [llvm::DataLayout::getPreferredAlignment]. *)
|
||||
val preferred_align_of_global : Llvm.llvalue -> t -> int
|
||||
|
||||
(** Computes the structure element that contains the byte offset for a target.
|
||||
See the method [llvm::StructLayout::getElementContainingOffset]. *)
|
||||
val element_at_offset : Llvm.lltype -> Int64.t -> t -> int
|
||||
|
||||
(** Computes the byte offset of the indexed struct element for a target.
|
||||
See the method [llvm::StructLayout::getElementContainingOffset]. *)
|
||||
val offset_of_element : Llvm.lltype -> int -> t -> Int64.t
|
||||
end
|
||||
|
||||
(** Returns the byte order of a target, either LLVMBigEndian or
|
||||
LLVMLittleEndian.
|
||||
See the method llvm::DataLayout::isLittleEndian. *)
|
||||
external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
|
||||
|
||||
(** Returns the pointer size in bytes for a target.
|
||||
See the method llvm::DataLayout::getPointerSize. *)
|
||||
external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
|
||||
|
||||
(** Returns the integer type that is the same size as a pointer on a target.
|
||||
See the method llvm::DataLayout::getIntPtrType. *)
|
||||
external intptr_type : DataLayout.t -> Llvm.llcontext -> Llvm.lltype
|
||||
= "llvm_intptr_type"
|
||||
|
||||
(** Returns the pointer size in bytes for a target in a given address space.
|
||||
See the method llvm::DataLayout::getPointerSize. *)
|
||||
external qualified_pointer_size : DataLayout.t -> int -> int
|
||||
= "llvm_qualified_pointer_size"
|
||||
|
||||
(** Returns the integer type that is the same size as a pointer on a target
|
||||
in a given address space.
|
||||
See the method llvm::DataLayout::getIntPtrType. *)
|
||||
external qualified_intptr_type : DataLayout.t -> Llvm.llcontext ->
|
||||
int -> Llvm.lltype
|
||||
= "llvm_qualified_intptr_type"
|
||||
|
||||
(** Computes the size of a type in bits for a target.
|
||||
See the method llvm::DataLayout::getTypeSizeInBits. *)
|
||||
external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
|
||||
= "llvm_size_in_bits"
|
||||
|
||||
(** Computes the storage size of a type in bytes for a target.
|
||||
See the method llvm::DataLayout::getTypeStoreSize. *)
|
||||
external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
|
||||
|
||||
(** Computes the ABI size of a type in bytes for a target.
|
||||
See the method llvm::DataLayout::getTypeAllocSize. *)
|
||||
external abi_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
|
||||
|
||||
(** Computes the ABI alignment of a type in bytes for a target.
|
||||
See the method llvm::DataLayout::getTypeABISize. *)
|
||||
external abi_align : DataLayout.t -> Llvm.lltype -> int = "llvm_abi_align"
|
||||
|
||||
(** Computes the call frame alignment of a type in bytes for a target.
|
||||
See the method llvm::DataLayout::getTypeABISize. *)
|
||||
external stack_align : DataLayout.t -> Llvm.lltype -> int = "llvm_stack_align"
|
||||
|
||||
(** Computes the preferred alignment of a type in bytes for a target.
|
||||
See the method llvm::DataLayout::getTypeABISize. *)
|
||||
external preferred_align : DataLayout.t -> Llvm.lltype -> int
|
||||
= "llvm_preferred_align"
|
||||
|
||||
(** Computes the preferred alignment of a global variable in bytes for a target.
|
||||
See the method llvm::DataLayout::getPreferredAlignment. *)
|
||||
external preferred_align_of_global : DataLayout.t -> Llvm.llvalue -> int
|
||||
= "llvm_preferred_align_of_global"
|
||||
|
||||
(** Computes the structure element that contains the byte offset for a target.
|
||||
See the method llvm::StructLayout::getElementContainingOffset. *)
|
||||
external element_at_offset : DataLayout.t -> Llvm.lltype -> Int64.t -> int
|
||||
= "llvm_element_at_offset"
|
||||
|
||||
(** Computes the byte offset of the indexed struct element for a target.
|
||||
See the method llvm::StructLayout::getElementContainingOffset. *)
|
||||
external offset_of_element : DataLayout.t -> Llvm.lltype -> int -> Int64.t
|
||||
= "llvm_offset_of_element"
|
||||
|
@ -19,15 +19,15 @@
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/custom.h"
|
||||
|
||||
#define TargetData_val(v) (*(LLVMTargetDataRef *)(Data_custom_val(v)))
|
||||
#define DataLayout_val(v) (*(LLVMTargetDataRef *)(Data_custom_val(v)))
|
||||
|
||||
static void llvm_finalize_target_data(value TargetData) {
|
||||
LLVMDisposeTargetData(TargetData_val(TargetData));
|
||||
static void llvm_finalize_data_layout(value DataLayout) {
|
||||
LLVMDisposeTargetData(DataLayout_val(DataLayout));
|
||||
}
|
||||
|
||||
static struct custom_operations llvm_target_data_ops = {
|
||||
(char *) "LLVMTargetData",
|
||||
llvm_finalize_target_data,
|
||||
static struct custom_operations llvm_data_layout_ops = {
|
||||
(char *) "LLVMDataLayout",
|
||||
llvm_finalize_data_layout,
|
||||
custom_compare_default,
|
||||
custom_hash_default,
|
||||
custom_serialize_default,
|
||||
@ -37,101 +37,105 @@ static struct custom_operations llvm_target_data_ops = {
|
||||
#endif
|
||||
};
|
||||
|
||||
value llvm_alloc_target_data(LLVMTargetDataRef TargetData) {
|
||||
value V = alloc_custom(&llvm_target_data_ops, sizeof(LLVMTargetDataRef), 0, 1);
|
||||
TargetData_val(V) = TargetData;
|
||||
value llvm_alloc_data_layout(LLVMTargetDataRef DataLayout) {
|
||||
value V = alloc_custom(&llvm_data_layout_ops, sizeof(LLVMTargetDataRef), 0, 1);
|
||||
DataLayout_val(V) = DataLayout;
|
||||
return V;
|
||||
}
|
||||
|
||||
/* string -> DataLayout.t */
|
||||
CAMLprim value llvm_targetdata_create(value StringRep) {
|
||||
return llvm_alloc_target_data(LLVMCreateTargetData(String_val(StringRep)));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_targetdata_add(value TD, LLVMPassManagerRef PM){
|
||||
LLVMAddTargetData(TargetData_val(TD), PM);
|
||||
return Val_unit;
|
||||
CAMLprim value llvm_datalayout_of_string(value StringRep) {
|
||||
return llvm_alloc_data_layout(LLVMCreateTargetData(String_val(StringRep)));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> string */
|
||||
CAMLprim value llvm_targetdata_as_string(value TD) {
|
||||
char *StringRep = LLVMCopyStringRepOfTargetData(TargetData_val(TD));
|
||||
CAMLprim value llvm_datalayout_as_string(value TD) {
|
||||
char *StringRep = LLVMCopyStringRepOfTargetData(DataLayout_val(TD));
|
||||
value Copy = copy_string(StringRep);
|
||||
LLVMDisposeMessage(StringRep);
|
||||
return Copy;
|
||||
}
|
||||
|
||||
/* [<Llvm.PassManager.any] Llvm.PassManager.t -> DataLayout.t -> unit */
|
||||
CAMLprim value llvm_datalayout_add_to_pass_manager(LLVMPassManagerRef PM,
|
||||
value DL) {
|
||||
LLVMAddTargetData(DataLayout_val(DL), PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Endian.t */
|
||||
CAMLprim value llvm_byte_order(value TD) {
|
||||
return Val_int(LLVMByteOrder(TargetData_val(TD)));
|
||||
CAMLprim value llvm_datalayout_byte_order(value DL) {
|
||||
return Val_int(LLVMByteOrder(DataLayout_val(DL)));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> int */
|
||||
CAMLprim value llvm_pointer_size(value TD) {
|
||||
return Val_int(LLVMPointerSize(TargetData_val(TD)));
|
||||
CAMLprim value llvm_datalayout_pointer_size(value DL) {
|
||||
return Val_int(LLVMPointerSize(DataLayout_val(DL)));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.llcontext -> Llvm.lltype */
|
||||
CAMLprim LLVMTypeRef llvm_intptr_type(value TD, LLVMContextRef C) {
|
||||
return LLVMIntPtrTypeInContext(C, TargetData_val(TD));;
|
||||
/* Llvm.llcontext -> DataLayout.t -> Llvm.lltype */
|
||||
CAMLprim LLVMTypeRef llvm_datalayout_intptr_type(LLVMContextRef C, value DL) {
|
||||
return LLVMIntPtrTypeInContext(C, DataLayout_val(DL));;
|
||||
}
|
||||
|
||||
/* DataLayout.t -> int -> int */
|
||||
CAMLprim value llvm_qualified_pointer_size(LLVMTargetDataRef TD, value AS) {
|
||||
return Val_int(LLVMPointerSizeForAS(TargetData_val(TD), Int_val(AS)));
|
||||
/* int -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_qualified_pointer_size(value AS, value DL) {
|
||||
return Val_int(LLVMPointerSizeForAS(DataLayout_val(DL), Int_val(AS)));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> int -> Llvm.lltype */
|
||||
CAMLprim LLVMTypeRef llvm_qualified_intptr_type(LLVMTargetDataRef TD,
|
||||
LLVMContextRef C, value AS) {
|
||||
return LLVMIntPtrTypeForASInContext(C, TargetData_val(TD), Int_val(AS));
|
||||
/* Llvm.llcontext -> int -> DataLayout.t -> Llvm.lltype */
|
||||
CAMLprim LLVMTypeRef llvm_datalayout_qualified_intptr_type(LLVMContextRef C,
|
||||
value AS,
|
||||
value DL) {
|
||||
return LLVMIntPtrTypeForASInContext(C, DataLayout_val(DL), Int_val(AS));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.lltype -> Int64.t */
|
||||
CAMLprim value llvm_size_in_bits(value TD, LLVMTypeRef Ty) {
|
||||
return caml_copy_int64(LLVMSizeOfTypeInBits(TargetData_val(TD), Ty));
|
||||
/* Llvm.lltype -> DataLayout.t -> Int64.t */
|
||||
CAMLprim value llvm_datalayout_size_in_bits(LLVMTypeRef Ty, value DL) {
|
||||
return caml_copy_int64(LLVMSizeOfTypeInBits(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.lltype -> Int64.t */
|
||||
CAMLprim value llvm_store_size(value TD, LLVMTypeRef Ty) {
|
||||
return caml_copy_int64(LLVMStoreSizeOfType(TargetData_val(TD), Ty));
|
||||
/* Llvm.lltype -> DataLayout.t -> Int64.t */
|
||||
CAMLprim value llvm_datalayout_store_size(LLVMTypeRef Ty, value DL) {
|
||||
return caml_copy_int64(LLVMStoreSizeOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.lltype -> Int64.t */
|
||||
CAMLprim value llvm_abi_size(value TD, LLVMTypeRef Ty) {
|
||||
return caml_copy_int64(LLVMABISizeOfType(TargetData_val(TD), Ty));
|
||||
/* Llvm.lltype -> DataLayout.t -> Int64.t */
|
||||
CAMLprim value llvm_datalayout_abi_size(LLVMTypeRef Ty, value DL) {
|
||||
return caml_copy_int64(LLVMABISizeOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.lltype -> int */
|
||||
CAMLprim value llvm_abi_align(value TD, LLVMTypeRef Ty) {
|
||||
return Val_int(LLVMABIAlignmentOfType(TargetData_val(TD), Ty));
|
||||
/* Llvm.lltype -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_abi_align(LLVMTypeRef Ty, value DL) {
|
||||
return Val_int(LLVMABIAlignmentOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.lltype -> int */
|
||||
CAMLprim value llvm_stack_align(value TD, LLVMTypeRef Ty) {
|
||||
return Val_int(LLVMCallFrameAlignmentOfType(TargetData_val(TD), Ty));
|
||||
/* Llvm.lltype -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_stack_align(LLVMTypeRef Ty, value DL) {
|
||||
return Val_int(LLVMCallFrameAlignmentOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.lltype -> int */
|
||||
CAMLprim value llvm_preferred_align(value TD, LLVMTypeRef Ty) {
|
||||
return Val_int(LLVMPreferredAlignmentOfType(TargetData_val(TD), Ty));
|
||||
/* Llvm.lltype -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_preferred_align(LLVMTypeRef Ty, value DL) {
|
||||
return Val_int(LLVMPreferredAlignmentOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.llvalue -> int */
|
||||
CAMLprim value llvm_preferred_align_of_global(value TD,
|
||||
LLVMValueRef GlobalVar) {
|
||||
return Val_int(LLVMPreferredAlignmentOfGlobal(TargetData_val(TD), GlobalVar));
|
||||
/* Llvm.llvalue -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_preferred_align_of_global(LLVMValueRef GlobalVar,
|
||||
value DL) {
|
||||
return Val_int(LLVMPreferredAlignmentOfGlobal(DataLayout_val(DL), GlobalVar));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.lltype -> Int64.t -> int */
|
||||
CAMLprim value llvm_element_at_offset(value TD, LLVMTypeRef Ty,
|
||||
value Offset) {
|
||||
return Val_int(LLVMElementAtOffset(TargetData_val(TD), Ty, Int64_val(Offset)));
|
||||
/* Llvm.lltype -> Int64.t -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_element_at_offset(LLVMTypeRef Ty, value Offset,
|
||||
value DL) {
|
||||
return Val_int(LLVMElementAtOffset(DataLayout_val(DL), Ty,
|
||||
Int64_val(Offset)));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Llvm.lltype -> int -> Int64.t */
|
||||
CAMLprim value llvm_offset_of_element(value TD, LLVMTypeRef Ty,
|
||||
value Index) {
|
||||
return caml_copy_int64(LLVMOffsetOfElement(TargetData_val(TD), Ty, Int_val(Index)));
|
||||
/* Llvm.lltype -> int -> DataLayout.t -> Int64.t */
|
||||
CAMLprim value llvm_datalayout_offset_of_element(LLVMTypeRef Ty, value Index,
|
||||
value DL) {
|
||||
return caml_copy_int64(LLVMOffsetOfElement(DataLayout_val(DL), Ty,
|
||||
Int_val(Index)));
|
||||
}
|
||||
|
@ -103,11 +103,11 @@ let test_executionengine () =
|
||||
(* run_static_dtors *)
|
||||
ExecutionEngine.run_static_dtors ee;
|
||||
|
||||
(* Show that the target data binding links and runs.*)
|
||||
let td = ExecutionEngine.target_data ee in
|
||||
(* Show that the data layout binding links and runs.*)
|
||||
let dl = ExecutionEngine.data_layout ee in
|
||||
|
||||
(* Demonstrate that a garbage pointer wasn't returned. *)
|
||||
let ty = intptr_type td context in
|
||||
let ty = DataLayout.intptr_type context dl in
|
||||
if ty != i32_type && ty != i64_type then bomb "target_data did not work";
|
||||
|
||||
(* dispose *)
|
||||
|
@ -46,10 +46,7 @@ let test_transforms () =
|
||||
ignore (build_ret (build_call fn [| |] "" b) b);
|
||||
end;
|
||||
|
||||
let td = DataLayout.create (target_triple m) in
|
||||
|
||||
ignore (PassManager.create ()
|
||||
++ DataLayout.add td
|
||||
++ add_argument_promotion
|
||||
++ add_constant_merge
|
||||
++ add_dead_arg_elimination
|
||||
|
@ -41,10 +41,7 @@ let test_transforms () =
|
||||
let fn = define_function "fn" fty m in
|
||||
ignore (build_ret_void (builder_at_end context (entry_block fn)));
|
||||
|
||||
let td = DataLayout.create (target_triple m) in
|
||||
|
||||
ignore (PassManager.create_function m
|
||||
++ DataLayout.add td
|
||||
++ add_verifier
|
||||
++ add_constant_propagation
|
||||
++ add_sccp
|
||||
|
@ -37,26 +37,30 @@ let m = create_module context filename
|
||||
(*===-- Target Data -------------------------------------------------------===*)
|
||||
|
||||
let test_target_data () =
|
||||
let module DL = DataLayout in
|
||||
let layout = "e-p:32:32:32-S32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-" ^
|
||||
"f16:16:16-f32:32:32-f64:32:64-f128:128:128-v64:32:64-v128:32:128-" ^
|
||||
"a0:0:64-n32" in
|
||||
let td = DataLayout.create layout in
|
||||
let dl = DL.of_string layout in
|
||||
let sty = struct_type context [| i32_type; i64_type |] in
|
||||
|
||||
assert_equal (DataLayout.as_string td) layout;
|
||||
assert_equal (byte_order td) Endian.Little;
|
||||
assert_equal (pointer_size td) 4;
|
||||
assert_equal (intptr_type td context) i32_type;
|
||||
assert_equal (qualified_pointer_size td 0) 4;
|
||||
assert_equal (qualified_intptr_type td context 0) i32_type;
|
||||
assert_equal (size_in_bits td sty) (Int64.of_int 96);
|
||||
assert_equal (store_size td sty) (Int64.of_int 12);
|
||||
assert_equal (abi_size td sty) (Int64.of_int 12);
|
||||
assert_equal (stack_align td sty) 4;
|
||||
assert_equal (preferred_align td sty) 8;
|
||||
assert_equal (preferred_align_of_global td (declare_global sty "g" m)) 8;
|
||||
assert_equal (element_at_offset td sty (Int64.of_int 1)) 0;
|
||||
assert_equal (offset_of_element td sty 1) (Int64.of_int 4)
|
||||
assert_equal (DL.as_string dl) layout;
|
||||
assert_equal (DL.byte_order dl) Endian.Little;
|
||||
assert_equal (DL.pointer_size dl) 4;
|
||||
assert_equal (DL.intptr_type context dl) i32_type;
|
||||
assert_equal (DL.qualified_pointer_size 0 dl) 4;
|
||||
assert_equal (DL.qualified_intptr_type context 0 dl) i32_type;
|
||||
assert_equal (DL.size_in_bits sty dl) (Int64.of_int 96);
|
||||
assert_equal (DL.store_size sty dl) (Int64.of_int 12);
|
||||
assert_equal (DL.abi_size sty dl) (Int64.of_int 12);
|
||||
assert_equal (DL.stack_align sty dl) 4;
|
||||
assert_equal (DL.preferred_align sty dl) 8;
|
||||
assert_equal (DL.preferred_align_of_global (declare_global sty "g" m) dl) 8;
|
||||
assert_equal (DL.element_at_offset sty (Int64.of_int 1) dl) 0;
|
||||
assert_equal (DL.offset_of_element sty 1 dl) (Int64.of_int 4);
|
||||
|
||||
let pm = PassManager.create () in
|
||||
ignore (DL.add_to_pass_manager pm dl)
|
||||
|
||||
|
||||
(*===-- Driver ------------------------------------------------------------===*)
|
||||
|
@ -41,10 +41,7 @@ let test_transforms () =
|
||||
let fn = define_function "fn" fty m in
|
||||
ignore (build_ret_void (builder_at_end context (entry_block fn)));
|
||||
|
||||
let td = DataLayout.create (target_triple m) in
|
||||
|
||||
ignore (PassManager.create ()
|
||||
++ DataLayout.add td
|
||||
++ add_bb_vectorize
|
||||
++ add_loop_vectorize
|
||||
++ add_slp_vectorize
|
||||
|
Loading…
Reference in New Issue
Block a user