llvm.org GIT mirror llvm / 04deb49
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194773 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Zotov 7 years ago
11 changed file(s) with 208 addition(s) and 207 deletion(s). Raw diff Collapse all Expand all
323323 return Val_unit;
324324 }
325325
326 extern value llvm_alloc_target_data(LLVMTargetDataRef TargetData);
327
328 /* ExecutionEngine.t -> Llvm_target.TargetData.t */
329 CAMLprim value llvm_ee_get_target_data(LLVMExecutionEngineRef EE) {
330 LLVMTargetDataRef TD = LLVMGetExecutionEngineTargetData(EE);
331 return llvm_alloc_target_data(TD);
332 }
326 extern value llvm_alloc_data_layout(LLVMTargetDataRef TargetData);
327
328 /* ExecutionEngine.t -> Llvm_target.DataLayout.t */
329 CAMLprim value llvm_ee_get_data_layout(LLVMExecutionEngineRef EE) {
330 value DataLayout;
331 LLVMTargetDataRef OrigDataLayout;
332 OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);
333
334 char* TargetDataCStr;
335 TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
336 DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
337 LLVMDisposeMessage(TargetDataCStr);
338
339 return DataLayout;
340 }
8282 external free_machine_code: Llvm.llvalue -> t -> unit
8383 = "llvm_ee_free_machine_code"
8484
85 external target_data: t -> Llvm_target.DataLayout.t
86 = "llvm_ee_get_target_data"
85 external data_layout : t -> Llvm_target.DataLayout.t
86 = "llvm_ee_get_data_layout"
8787
8888 (* The following are not bound. Patches are welcome.
8989
146146 used to store the machine code for the function [f]. *)
147147 val free_machine_code : Llvm.llvalue -> t -> unit
148148
149 (** [target_data ee] is the target data owned by the execution engine
150 [ee]. *)
151 val target_data : t -> Llvm_target.DataLayout.t
149 (** [data_layout ee] is the data layout of the execution engine [ee]. *)
150 val data_layout : t -> Llvm_target.DataLayout.t
152151 end
153152
154153 val initialize_native_target : unit -> bool
1515 module DataLayout = struct
1616 type t
1717
18 external create : string -> t = "llvm_targetdata_create"
19 external add : t -> [ unit
20 = "llvm_targetdata_add"
21 external as_string : t -> string = "llvm_targetdata_as_string"
18 external of_string : string -> t = "llvm_datalayout_of_string"
19 external as_string : t -> string = "llvm_datalayout_as_string"
20 external add_to_pass_manager : [
21 Llvm.PassManager.t -> t -> unit
22 = "llvm_datalayout_add_to_pass_manager"
23 external byte_order : t -> Endian.t = "llvm_datalayout_byte_order"
24 external pointer_size : t -> int = "llvm_datalayout_pointer_size"
25 external intptr_type : Llvm.llcontext -> t -> Llvm.lltype
26 = "llvm_datalayout_intptr_type"
27 external qualified_pointer_size : int -> t -> int
28 = "llvm_datalayout_qualified_pointer_size"
29 external qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
30 = "llvm_datalayout_qualified_intptr_type"
31 external size_in_bits : Llvm.lltype -> t -> Int64.t
32 = "llvm_datalayout_size_in_bits"
33 external store_size : Llvm.lltype -> t -> Int64.t
34 = "llvm_datalayout_store_size"
35 external abi_size : Llvm.lltype -> t -> Int64.t
36 = "llvm_datalayout_abi_size"
37 external abi_align : Llvm.lltype -> t -> int
38 = "llvm_datalayout_abi_align"
39 external stack_align : Llvm.lltype -> t -> int
40 = "llvm_datalayout_stack_align"
41 external preferred_align : Llvm.lltype -> t -> int
42 = "llvm_datalayout_preferred_align"
43 external preferred_align_of_global : Llvm.llvalue -> t -> int
44 = "llvm_datalayout_preferred_align_of_global"
45 external element_at_offset : Llvm.lltype -> Int64.t -> t -> int
46 = "llvm_datalayout_element_at_offset"
47 external offset_of_element : Llvm.lltype -> int -> t -> Int64.t
48 = "llvm_datalayout_offset_of_element"
2249 end
2350
24 external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
25 external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
26 external intptr_type : DataLayout.t -> Llvm.llcontext -> Llvm.lltype
27 = "llvm_intptr_type"
28 external qualified_pointer_size : DataLayout.t -> int -> int
29 = "llvm_qualified_pointer_size"
30 external qualified_intptr_type : DataLayout.t -> Llvm.llcontext ->
31 int -> Llvm.lltype
32 = "llvm_qualified_intptr_type"
33 external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
34 = "llvm_size_in_bits"
35 external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
36 external abi_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
37 external abi_align : DataLayout.t -> Llvm.lltype -> int = "llvm_abi_align"
38 external stack_align : DataLayout.t -> Llvm.lltype -> int = "llvm_stack_align"
39 external preferred_align : DataLayout.t -> Llvm.lltype -> int
40 = "llvm_preferred_align"
41 external preferred_align_of_global : DataLayout.t -> Llvm.llvalue -> int
42 = "llvm_preferred_align_of_global"
43 external element_at_offset : DataLayout.t -> Llvm.lltype -> Int64.t -> int
44 = "llvm_element_at_offset"
45 external offset_of_element : DataLayout.t -> Llvm.lltype -> int -> Int64.t
46 = "llvm_offset_of_element"
2020 module DataLayout : sig
2121 type t
2222
23 (** [DataLayout.create rep] parses the target data string representation [rep].
24 See the constructor llvm::DataLayout::DataLayout. *)
25 external create : string -> t = "llvm_targetdata_create"
23 (** [of_string rep] parses the data layout string representation [rep].
24 See the constructor [llvm::DataLayout::DataLayout]. *)
25 val of_string : string -> t
2626
27 (** [add_target_data td pm] adds the target data [td] to the pass manager [pm].
28 Does not take ownership of the target data.
29 See the method llvm::PassManagerBase::add. *)
30 external add : t -> [ unit
31 = "llvm_targetdata_add"
27 (** [as_string dl] is the string representation of the data layout [dl].
28 See the method [llvm::DataLayout::getStringRepresentation]. *)
29 val as_string : t -> string
3230
33 (** [as_string td] is the string representation of the target data [td].
34 See the constructor llvm::DataLayout::DataLayout. *)
35 external as_string : t -> string = "llvm_targetdata_as_string"
31 (** [add_to_pass_manager dl pm] adds the target data [dl] to
32 the pass manager [pm].
33 See the method [llvm::PassManagerBase::add]. *)
34 val add_to_pass_manager : [
35 t -> unit
36
37 (** Returns the byte order of a target, either [Endian.Big] or
38 [Endian.Little].
39 See the method [llvm::DataLayout::isLittleEndian]. *)
40 val byte_order : t -> Endian.t
41
42 (** Returns the pointer size in bytes for a target.
43 See the method [llvm::DataLayout::getPointerSize]. *)
44 val pointer_size : t -> int
45
46 (** Returns the integer type that is the same size as a pointer on a target.
47 See the method [llvm::DataLayout::getIntPtrType]. *)
48 val intptr_type : Llvm.llcontext -> t -> Llvm.lltype
49
50 (** Returns the pointer size in bytes for a target in a given address space.
51 See the method [llvm::DataLayout::getPointerSize]. *)
52 val qualified_pointer_size : int -> t -> int
53
54 (** Returns the integer type that is the same size as a pointer on a target
55 in a given address space.
56 See the method [llvm::DataLayout::getIntPtrType]. *)
57 val qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
58
59 (** Computes the size of a type in bits for a target.
60 See the method [llvm::DataLayout::getTypeSizeInBits]. *)
61 val size_in_bits : Llvm.lltype -> t -> Int64.t
62
63 (** Computes the storage size of a type in bytes for a target.
64 See the method [llvm::DataLayout::getTypeStoreSize]. *)
65 val store_size : Llvm.lltype -> t -> Int64.t
66
67 (** Computes the ABI size of a type in bytes for a target.
68 See the method [llvm::DataLayout::getTypeAllocSize]. *)
69 val abi_size : Llvm.lltype -> t -> Int64.t
70
71 (** Computes the ABI alignment of a type in bytes for a target.
72 See the method [llvm::DataLayout::getTypeABISize]. *)
73 val abi_align : Llvm.lltype -> t -> int
74
75 (** Computes the call frame alignment of a type in bytes for a target.
76 See the method [llvm::DataLayout::getTypeABISize]. *)
77 val stack_align : Llvm.lltype -> t -> int
78
79 (** Computes the preferred alignment of a type in bytes for a target.
80 See the method [llvm::DataLayout::getTypeABISize]. *)
81 val preferred_align : Llvm.lltype -> t -> int
82
83 (** Computes the preferred alignment of a global variable in bytes for
84 a target. See the method [llvm::DataLayout::getPreferredAlignment]. *)
85 val preferred_align_of_global : Llvm.llvalue -> t -> int
86
87 (** Computes the structure element that contains the byte offset for a target.
88 See the method [llvm::StructLayout::getElementContainingOffset]. *)
89 val element_at_offset : Llvm.lltype -> Int64.t -> t -> int
90
91 (** Computes the byte offset of the indexed struct element for a target.
92 See the method [llvm::StructLayout::getElementContainingOffset]. *)
93 val offset_of_element : Llvm.lltype -> int -> t -> Int64.t
3694 end
37
38 (** Returns the byte order of a target, either LLVMBigEndian or
39 LLVMLittleEndian.
40 See the method llvm::DataLayout::isLittleEndian. *)
41 external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
42
43 (** Returns the pointer size in bytes for a target.
44 See the method llvm::DataLayout::getPointerSize. *)
45 external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
46
47 (** Returns the integer type that is the same size as a pointer on a target.
48 See the method llvm::DataLayout::getIntPtrType. *)
49 external intptr_type : DataLayout.t -> Llvm.llcontext -> Llvm.lltype
50 = "llvm_intptr_type"
51
52 (** Returns the pointer size in bytes for a target in a given address space.
53 See the method llvm::DataLayout::getPointerSize. *)
54 external qualified_pointer_size : DataLayout.t -> int -> int
55 = "llvm_qualified_pointer_size"
56
57 (** Returns the integer type that is the same size as a pointer on a target
58 in a given address space.
59 See the method llvm::DataLayout::getIntPtrType. *)
60 external qualified_intptr_type : DataLayout.t -> Llvm.llcontext ->
61 int -> Llvm.lltype
62 = "llvm_qualified_intptr_type"
63
64 (** Computes the size of a type in bits for a target.
65 See the method llvm::DataLayout::getTypeSizeInBits. *)
66 external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
67 = "llvm_size_in_bits"
68
69 (** Computes the storage size of a type in bytes for a target.
70 See the method llvm::DataLayout::getTypeStoreSize. *)
71 external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
72
73 (** Computes the ABI size of a type in bytes for a target.
74 See the method llvm::DataLayout::getTypeAllocSize. *)
75 external abi_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
76
77 (** Computes the ABI alignment of a type in bytes for a target.
78 See the method llvm::DataLayout::getTypeABISize. *)
79 external abi_align : DataLayout.t -> Llvm.lltype -> int = "llvm_abi_align"
80
81 (** Computes the call frame alignment of a type in bytes for a target.
82 See the method llvm::DataLayout::getTypeABISize. *)
83 external stack_align : DataLayout.t -> Llvm.lltype -> int = "llvm_stack_align"
84
85 (** Computes the preferred alignment of a type in bytes for a target.
86 See the method llvm::DataLayout::getTypeABISize. *)
87 external preferred_align : DataLayout.t -> Llvm.lltype -> int
88 = "llvm_preferred_align"
89
90 (** Computes the preferred alignment of a global variable in bytes for a target.
91 See the method llvm::DataLayout::getPreferredAlignment. *)
92 external preferred_align_of_global : DataLayout.t -> Llvm.llvalue -> int
93 = "llvm_preferred_align_of_global"
94
95 (** Computes the structure element that contains the byte offset for a target.
96 See the method llvm::StructLayout::getElementContainingOffset. *)
97 external element_at_offset : DataLayout.t -> Llvm.lltype -> Int64.t -> int
98 = "llvm_element_at_offset"
99
100 (** Computes the byte offset of the indexed struct element for a target.
101 See the method llvm::StructLayout::getElementContainingOffset. *)
102 external offset_of_element : DataLayout.t -> Llvm.lltype -> int -> Int64.t
103 = "llvm_offset_of_element"
1818 #include "caml/alloc.h"
1919 #include "caml/custom.h"
2020
21 #define TargetData_val(v) (*(LLVMTargetDataRef *)(Data_custom_val(v)))
21 #define DataLayout_val(v) (*(LLVMTargetDataRef *)(Data_custom_val(v)))
2222
23 static void llvm_finalize_target_data(value TargetData) {
24 LLVMDisposeTargetData(TargetData_val(TargetData));
23 static void llvm_finalize_data_layout(value DataLayout) {
24 LLVMDisposeTargetData(DataLayout_val(DataLayout));
2525 }
2626
27 static struct custom_operations llvm_target_data_ops = {
28 (char *) "LLVMTargetData",
29 llvm_finalize_target_data,
27 static struct custom_operations llvm_data_layout_ops = {
28 (char *) "LLVMDataLayout",
29 llvm_finalize_data_layout,
3030 custom_compare_default,
3131 custom_hash_default,
3232 custom_serialize_default,
3636 #endif
3737 };
3838
39 value llvm_alloc_target_data(LLVMTargetDataRef TargetData) {
40 value V = alloc_custom(&llvm_target_data_ops, sizeof(LLVMTargetDataRef), 0, 1);
41 TargetData_val(V) = TargetData;
39 value llvm_alloc_data_layout(LLVMTargetDataRef DataLayout) {
40 value V = alloc_custom(&llvm_data_layout_ops, sizeof(LLVMTargetDataRef), 0, 1);
41 DataLayout_val(V) = DataLayout;
4242 return V;
4343 }
4444
4545 /* string -> DataLayout.t */
46 CAMLprim value llvm_targetdata_create(value StringRep) {
47 return llvm_alloc_target_data(LLVMCreateTargetData(String_val(StringRep)));
48 }
49
50 /* DataLayout.t -> [ unit */
51 CAMLprim value llvm_targetdata_add(value TD, LLVMPassManagerRef PM){
52 LLVMAddTargetData(TargetData_val(TD), PM);
53 return Val_unit;
46 CAMLprim value llvm_datalayout_of_string(value StringRep) {
47 return llvm_alloc_data_layout(LLVMCreateTargetData(String_val(StringRep)));
5448 }
5549
5650 /* DataLayout.t -> string */
57 CAMLprim value llvm_targetdata_as_string(value TD) {
58 char *StringRep = LLVMCopyStringRepOfTargetData(TargetData_val(TD));
51 CAMLprim value llvm_datalayout_as_string(value TD) {
52 char *StringRep = LLVMCopyStringRepOfTargetData(DataLayout_val(TD));
5953 value Copy = copy_string(StringRep);
6054 LLVMDisposeMessage(StringRep);
6155 return Copy;
6256 }
6357
58 /* [ DataLayout.t -> unit */
59 CAMLprim value llvm_datalayout_add_to_pass_manager(LLVMPassManagerRef PM,
60 value DL) {
61 LLVMAddTargetData(DataLayout_val(DL), PM);
62 return Val_unit;
63 }
64
6465 /* DataLayout.t -> Endian.t */
65 CAMLprim value llvm_byte_order(value TD) {
66 return Val_int(LLVMByteOrder(TargetData_val(TD)));
66 CAMLprim value llvm_datalayout_byte_order(value DL) {
67 return Val_int(LLVMByteOrder(DataLayout_val(DL)));
6768 }
6869
6970 /* DataLayout.t -> int */
70 CAMLprim value llvm_pointer_size(value TD) {
71 return Val_int(LLVMPointerSize(TargetData_val(TD)));
71 CAMLprim value llvm_datalayout_pointer_size(value DL) {
72 return Val_int(LLVMPointerSize(DataLayout_val(DL)));
7273 }
7374
74 /* DataLayout.t -> Llvm.llcontext -> Llvm.lltype */
75 CAMLprim LLVMTypeRef llvm_intptr_type(value TD, LLVMContextRef C) {
76 return LLVMIntPtrTypeInContext(C, TargetData_val(TD));;
75 /* Llvm.llcontext -> DataLayout.t -> Llvm.lltype */
76 CAMLprim LLVMTypeRef llvm_datalayout_intptr_type(LLVMContextRef C, value DL) {
77 return LLVMIntPtrTypeInContext(C, DataLayout_val(DL));;
7778 }
7879
79 /* DataLayout.t -> int -> int */
80 CAMLprim value llvm_qualified_pointer_size(LLVMTargetDataRef TD, value AS) {
81 return Val_int(LLVMPointerSizeForAS(TargetData_val(TD), Int_val(AS)));
80 /* int -> DataLayout.t -> int */
81 CAMLprim value llvm_datalayout_qualified_pointer_size(value AS, value DL) {
82 return Val_int(LLVMPointerSizeForAS(DataLayout_val(DL), Int_val(AS)));
8283 }
8384
84 /* DataLayout.t -> int -> Llvm.lltype */
85 CAMLprim LLVMTypeRef llvm_qualified_intptr_type(LLVMTargetDataRef TD,
86 LLVMContextRef C, value AS) {
87 return LLVMIntPtrTypeForASInContext(C, TargetData_val(TD), Int_val(AS));
85 /* Llvm.llcontext -> int -> DataLayout.t -> Llvm.lltype */
86 CAMLprim LLVMTypeRef llvm_datalayout_qualified_intptr_type(LLVMContextRef C,
87 value AS,
88 value DL) {
89 return LLVMIntPtrTypeForASInContext(C, DataLayout_val(DL), Int_val(AS));
8890 }
8991
90 /* DataLayout.t -> Llvm.lltype -> Int64.t */
91 CAMLprim value llvm_size_in_bits(value TD, LLVMTypeRef Ty) {
92 return caml_copy_int64(LLVMSizeOfTypeInBits(TargetData_val(TD), Ty));
92 /* Llvm.lltype -> DataLayout.t -> Int64.t */
93 CAMLprim value llvm_datalayout_size_in_bits(LLVMTypeRef Ty, value DL) {
94 return caml_copy_int64(LLVMSizeOfTypeInBits(DataLayout_val(DL), Ty));
9395 }
9496
95 /* DataLayout.t -> Llvm.lltype -> Int64.t */
96 CAMLprim value llvm_store_size(value TD, LLVMTypeRef Ty) {
97 return caml_copy_int64(LLVMStoreSizeOfType(TargetData_val(TD), Ty));
97 /* Llvm.lltype -> DataLayout.t -> Int64.t */
98 CAMLprim value llvm_datalayout_store_size(LLVMTypeRef Ty, value DL) {
99 return caml_copy_int64(LLVMStoreSizeOfType(DataLayout_val(DL), Ty));
98100 }
99101
100 /* DataLayout.t -> Llvm.lltype -> Int64.t */
101 CAMLprim value llvm_abi_size(value TD, LLVMTypeRef Ty) {
102 return caml_copy_int64(LLVMABISizeOfType(TargetData_val(TD), Ty));
102 /* Llvm.lltype -> DataLayout.t -> Int64.t */
103 CAMLprim value llvm_datalayout_abi_size(LLVMTypeRef Ty, value DL) {
104 return caml_copy_int64(LLVMABISizeOfType(DataLayout_val(DL), Ty));
103105 }
104106
105 /* DataLayout.t -> Llvm.lltype -> int */
106 CAMLprim value llvm_abi_align(value TD, LLVMTypeRef Ty) {
107 return Val_int(LLVMABIAlignmentOfType(TargetData_val(TD), Ty));
107 /* Llvm.lltype -> DataLayout.t -> int */
108 CAMLprim value llvm_datalayout_abi_align(LLVMTypeRef Ty, value DL) {
109 return Val_int(LLVMABIAlignmentOfType(DataLayout_val(DL), Ty));
108110 }
109111
110 /* DataLayout.t -> Llvm.lltype -> int */
111 CAMLprim value llvm_stack_align(value TD, LLVMTypeRef Ty) {
112 return Val_int(LLVMCallFrameAlignmentOfType(TargetData_val(TD), Ty));
112 /* Llvm.lltype -> DataLayout.t -> int */
113 CAMLprim value llvm_datalayout_stack_align(LLVMTypeRef Ty, value DL) {
114 return Val_int(LLVMCallFrameAlignmentOfType(DataLayout_val(DL), Ty));
113115 }
114116
115 /* DataLayout.t -> Llvm.lltype -> int */
116 CAMLprim value llvm_preferred_align(value TD, LLVMTypeRef Ty) {
117 return Val_int(LLVMPreferredAlignmentOfType(TargetData_val(TD), Ty));
117 /* Llvm.lltype -> DataLayout.t -> int */
118 CAMLprim value llvm_datalayout_preferred_align(LLVMTypeRef Ty, value DL) {
119 return Val_int(LLVMPreferredAlignmentOfType(DataLayout_val(DL), Ty));
118120 }
119121
120 /* DataLayout.t -> Llvm.llvalue -> int */
121 CAMLprim value llvm_preferred_align_of_global(value TD,
122 LLVMValueRef GlobalVar) {
123 return Val_int(LLVMPreferredAlignmentOfGlobal(TargetData_val(TD), GlobalVar));
122 /* Llvm.llvalue -> DataLayout.t -> int */
123 CAMLprim value llvm_datalayout_preferred_align_of_global(LLVMValueRef GlobalVar,
124 value DL) {
125 return Val_int(LLVMPreferredAlignmentOfGlobal(DataLayout_val(DL), GlobalVar));
124126 }
125127
126 /* DataLayout.t -> Llvm.lltype -> Int64.t -> int */
127 CAMLprim value llvm_element_at_offset(value TD, LLVMTypeRef Ty,
128 value Offset) {
129 return Val_int(LLVMElementAtOffset(TargetData_val(TD), Ty, Int64_val(Offset)));
128 /* Llvm.lltype -> Int64.t -> DataLayout.t -> int */
129 CAMLprim value llvm_datalayout_element_at_offset(LLVMTypeRef Ty, value Offset,
130 value DL) {
131 return Val_int(LLVMElementAtOffset(DataLayout_val(DL), Ty,
132 Int64_val(Offset)));
130133 }
131134
132 /* DataLayout.t -> Llvm.lltype -> int -> Int64.t */
133 CAMLprim value llvm_offset_of_element(value TD, LLVMTypeRef Ty,
134 value Index) {
135 return caml_copy_int64(LLVMOffsetOfElement(TargetData_val(TD), Ty, Int_val(Index)));
135 /* Llvm.lltype -> int -> DataLayout.t -> Int64.t */
136 CAMLprim value llvm_datalayout_offset_of_element(LLVMTypeRef Ty, value Index,
137 value DL) {
138 return caml_copy_int64(LLVMOffsetOfElement(DataLayout_val(DL), Ty,
139 Int_val(Index)));
136140 }
102102 (* run_static_dtors *)
103103 ExecutionEngine.run_static_dtors ee;
104104
105 (* Show that the target data binding links and runs.*)
106 let td = ExecutionEngine.target_data ee in
105 (* Show that the data layout binding links and runs.*)
106 let dl = ExecutionEngine.data_layout ee in
107107
108108 (* Demonstrate that a garbage pointer wasn't returned. *)
109 let ty = intptr_type td context in
109 let ty = DataLayout.intptr_type context dl in
110110 if ty != i32_type && ty != i64_type then bomb "target_data did not work";
111111
112112 (* dispose *)
4545 ignore (build_ret (build_call fn [| |] "" b) b);
4646 end;
4747
48 let td = DataLayout.create (target_triple m) in
49
5048 ignore (PassManager.create ()
51 ++ DataLayout.add td
5249 ++ add_argument_promotion
5350 ++ add_constant_merge
5451 ++ add_dead_arg_elimination
4040 let fn = define_function "fn" fty m in
4141 ignore (build_ret_void (builder_at_end context (entry_block fn)));
4242
43 let td = DataLayout.create (target_triple m) in
44
4543 ignore (PassManager.create_function m
46 ++ DataLayout.add td
4744 ++ add_verifier
4845 ++ add_constant_propagation
4946 ++ add_sccp
3636 (*===-- Target Data -------------------------------------------------------===*)
3737
3838 let test_target_data () =
39 let module DL = DataLayout in
3940 let layout = "e-p:32:32:32-S32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-" ^
4041 "f16:16:16-f32:32:32-f64:32:64-f128:128:128-v64:32:64-v128:32:128-" ^
4142 "a0:0:64-n32" in
42 let td = DataLayout.create layout in
43 let dl = DL.of_string layout in
4344 let sty = struct_type context [| i32_type; i64_type |] in
4445
45 assert_equal (DataLayout.as_string td) layout;
46 assert_equal (byte_order td) Endian.Little;
47 assert_equal (pointer_size td) 4;
48 assert_equal (intptr_type td context) i32_type;
49 assert_equal (qualified_pointer_size td 0) 4;
50 assert_equal (qualified_intptr_type td context 0) i32_type;
51 assert_equal (size_in_bits td sty) (Int64.of_int 96);
52 assert_equal (store_size td sty) (Int64.of_int 12);
53 assert_equal (abi_size td sty) (Int64.of_int 12);
54 assert_equal (stack_align td sty) 4;
55 assert_equal (preferred_align td sty) 8;
56 assert_equal (preferred_align_of_global td (declare_global sty "g" m)) 8;
57 assert_equal (element_at_offset td sty (Int64.of_int 1)) 0;
58 assert_equal (offset_of_element td sty 1) (Int64.of_int 4)
46 assert_equal (DL.as_string dl) layout;
47 assert_equal (DL.byte_order dl) Endian.Little;
48 assert_equal (DL.pointer_size dl) 4;
49 assert_equal (DL.intptr_type context dl) i32_type;
50 assert_equal (DL.qualified_pointer_size 0 dl) 4;
51 assert_equal (DL.qualified_intptr_type context 0 dl) i32_type;
52 assert_equal (DL.size_in_bits sty dl) (Int64.of_int 96);
53 assert_equal (DL.store_size sty dl) (Int64.of_int 12);
54 assert_equal (DL.abi_size sty dl) (Int64.of_int 12);
55 assert_equal (DL.stack_align sty dl) 4;
56 assert_equal (DL.preferred_align sty dl) 8;
57 assert_equal (DL.preferred_align_of_global (declare_global sty "g" m) dl) 8;
58 assert_equal (DL.element_at_offset sty (Int64.of_int 1) dl) 0;
59 assert_equal (DL.offset_of_element sty 1 dl) (Int64.of_int 4);
60
61 let pm = PassManager.create () in
62 ignore (DL.add_to_pass_manager pm dl)
5963
6064
6165 (*===-- Driver ------------------------------------------------------------===*)
4040 let fn = define_function "fn" fty m in
4141 ignore (build_ret_void (builder_at_end context (entry_block fn)));
4242
43 let td = DataLayout.create (target_triple m) in
44
4543 ignore (PassManager.create ()
46 ++ DataLayout.add td
4744 ++ add_bb_vectorize
4845 ++ add_loop_vectorize
4946 ++ add_slp_vectorize