llvm.org GIT mirror llvm / 791cfc2
Move TargetData to DataLayout. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165403 91177308-0d34-0410-b5e6-96231b3b80d8 Micah Villmow 6 years ago
32 changed file(s) with 158 addition(s) and 158 deletion(s). Raw diff Collapse all Expand all
8282 external free_machine_code: Llvm.llvalue -> t -> unit
8383 = "llvm_ee_free_machine_code"
8484
85 external target_data: t -> Llvm_target.TargetData.t
86 = "LLVMGetExecutionEngineTargetData"
85 external target_data: t -> Llvm_target.DataLayout.t
86 = "LLVMGetExecutionEngineDataLayout"
8787
8888 (* The following are not bound. Patches are welcome.
8989
154154
155155 (** [target_data ee] is the target data owned by the execution engine
156156 [ee]. *)
157 val target_data : t -> Llvm_target.TargetData.t
157 val target_data : t -> Llvm_target.DataLayout.t
158158
159159 end
160160
374374 val classify_type : lltype -> TypeKind.t
375375
376376 (** [type_is_sized ty] returns whether the type has a size or not.
377 * If it doesn't then it is not safe to call the [TargetData::] methods on it.
377 * If it doesn't then it is not safe to call the [DataLayout::] methods on it.
378378 * *)
379379 val type_is_sized : lltype -> bool
380380
1212 | Little
1313 end
1414
15 module TargetData = struct
15 module DataLayout = struct
1616 type t
1717
1818 external create : string -> t = "llvm_targetdata_create"
2222 external dispose : t -> unit = "llvm_targetdata_dispose"
2323 end
2424
25 external byte_order : TargetData.t -> Endian.t = "llvm_byte_order"
26 external pointer_size : TargetData.t -> int = "llvm_pointer_size"
27 external intptr_type : TargetData.t -> Llvm.lltype = "LLVMIntPtrType"
28 external size_in_bits : TargetData.t -> Llvm.lltype -> Int64.t
25 external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
26 external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
27 external intptr_type : DataLayout.t -> Llvm.lltype = "LLVMIntPtrType"
28 external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
2929 = "llvm_size_in_bits"
30 external store_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
31 external abi_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
32 external abi_align : TargetData.t -> Llvm.lltype -> int = "llvm_abi_align"
33 external stack_align : TargetData.t -> Llvm.lltype -> int = "llvm_stack_align"
34 external preferred_align : TargetData.t -> Llvm.lltype -> int
30 external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
31 external abi_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
32 external abi_align : DataLayout.t -> Llvm.lltype -> int = "llvm_abi_align"
33 external stack_align : DataLayout.t -> Llvm.lltype -> int = "llvm_stack_align"
34 external preferred_align : DataLayout.t -> Llvm.lltype -> int
3535 = "llvm_preferred_align"
36 external preferred_align_of_global : TargetData.t -> Llvm.llvalue -> int
36 external preferred_align_of_global : DataLayout.t -> Llvm.llvalue -> int
3737 = "llvm_preferred_align_of_global"
38 external element_at_offset : TargetData.t -> Llvm.lltype -> Int64.t -> int
38 external element_at_offset : DataLayout.t -> Llvm.lltype -> Int64.t -> int
3939 = "llvm_element_at_offset"
40 external offset_of_element : TargetData.t -> Llvm.lltype -> int -> Int64.t
40 external offset_of_element : DataLayout.t -> Llvm.lltype -> int -> Int64.t
4141 = "llvm_offset_of_element"
1717 | Little
1818 end
1919
20 module TargetData : sig
20 module DataLayout : sig
2121 type t
2222
23 (** [TargetData.create rep] parses the target data string representation [rep].
24 See the constructor llvm::TargetData::TargetData. *)
23 (** [DataLayout.create rep] parses the target data string representation [rep].
24 See the constructor llvm::DataLayout::DataLayout. *)
2525 external create : string -> t = "llvm_targetdata_create"
2626
2727 (** [add_target_data td pm] adds the target data [td] to the pass manager [pm].
3131 = "llvm_targetdata_add"
3232
3333 (** [as_string td] is the string representation of the target data [td].
34 See the constructor llvm::TargetData::TargetData. *)
34 See the constructor llvm::DataLayout::DataLayout. *)
3535 external as_string : t -> string = "llvm_targetdata_as_string"
3636
37 (** Deallocates a TargetData.
38 See the destructor llvm::TargetData::~TargetData. *)
37 (** Deallocates a DataLayout.
38 See the destructor llvm::DataLayout::~DataLayout. *)
3939 external dispose : t -> unit = "llvm_targetdata_dispose"
4040 end
4141
4242 (** Returns the byte order of a target, either LLVMBigEndian or
4343 LLVMLittleEndian.
44 See the method llvm::TargetData::isLittleEndian. *)
45 external byte_order : TargetData.t -> Endian.t = "llvm_byte_order"
44 See the method llvm::DataLayout::isLittleEndian. *)
45 external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
4646
4747 (** Returns the pointer size in bytes for a target.
48 See the method llvm::TargetData::getPointerSize. *)
49 external pointer_size : TargetData.t -> int = "llvm_pointer_size"
48 See the method llvm::DataLayout::getPointerSize. *)
49 external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
5050
5151 (** Returns the integer type that is the same size as a pointer on a target.
52 See the method llvm::TargetData::getIntPtrType. *)
53 external intptr_type : TargetData.t -> Llvm.lltype = "LLVMIntPtrType"
52 See the method llvm::DataLayout::getIntPtrType. *)
53 external intptr_type : DataLayout.t -> Llvm.lltype = "LLVMIntPtrType"
5454
5555 (** Computes the size of a type in bytes for a target.
56 See the method llvm::TargetData::getTypeSizeInBits. *)
57 external size_in_bits : TargetData.t -> Llvm.lltype -> Int64.t
56 See the method llvm::DataLayout::getTypeSizeInBits. *)
57 external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
5858 = "llvm_size_in_bits"
5959
6060 (** Computes the storage size of a type in bytes for a target.
61 See the method llvm::TargetData::getTypeStoreSize. *)
62 external store_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
61 See the method llvm::DataLayout::getTypeStoreSize. *)
62 external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
6363
6464 (** Computes the ABI size of a type in bytes for a target.
65 See the method llvm::TargetData::getTypeAllocSize. *)
66 external abi_size : TargetData.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
65 See the method llvm::DataLayout::getTypeAllocSize. *)
66 external abi_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
6767
6868 (** Computes the ABI alignment of a type in bytes for a target.
69 See the method llvm::TargetData::getTypeABISize. *)
70 external abi_align : TargetData.t -> Llvm.lltype -> int = "llvm_abi_align"
69 See the method llvm::DataLayout::getTypeABISize. *)
70 external abi_align : DataLayout.t -> Llvm.lltype -> int = "llvm_abi_align"
7171
7272 (** Computes the call frame alignment of a type in bytes for a target.
73 See the method llvm::TargetData::getTypeABISize. *)
74 external stack_align : TargetData.t -> Llvm.lltype -> int = "llvm_stack_align"
73 See the method llvm::DataLayout::getTypeABISize. *)
74 external stack_align : DataLayout.t -> Llvm.lltype -> int = "llvm_stack_align"
7575
7676 (** Computes the preferred alignment of a type in bytes for a target.
77 See the method llvm::TargetData::getTypeABISize. *)
78 external preferred_align : TargetData.t -> Llvm.lltype -> int
77 See the method llvm::DataLayout::getTypeABISize. *)
78 external preferred_align : DataLayout.t -> Llvm.lltype -> int
7979 = "llvm_preferred_align"
8080
8181 (** Computes the preferred alignment of a global variable in bytes for a target.
82 See the method llvm::TargetData::getPreferredAlignment. *)
83 external preferred_align_of_global : TargetData.t -> Llvm.llvalue -> int
82 See the method llvm::DataLayout::getPreferredAlignment. *)
83 external preferred_align_of_global : DataLayout.t -> Llvm.llvalue -> int
8484 = "llvm_preferred_align_of_global"
8585
8686 (** Computes the structure element that contains the byte offset for a target.
8787 See the method llvm::StructLayout::getElementContainingOffset. *)
88 external element_at_offset : TargetData.t -> Llvm.lltype -> Int64.t -> int
88 external element_at_offset : DataLayout.t -> Llvm.lltype -> Int64.t -> int
8989 = "llvm_element_at_offset"
9090
9191 (** Computes the byte offset of the indexed struct element for a target.
9292 See the method llvm::StructLayout::getElementContainingOffset. *)
93 external offset_of_element : TargetData.t -> Llvm.lltype -> int -> Int64.t
93 external offset_of_element : DataLayout.t -> Llvm.lltype -> int -> Int64.t
9494 = "llvm_offset_of_element"
1717 #include "llvm-c/Target.h"
1818 #include "caml/alloc.h"
1919
20 /* string -> TargetData.t */
21 CAMLprim LLVMTargetDataRef llvm_targetdata_create(value StringRep) {
22 return LLVMCreateTargetData(String_val(StringRep));
20 /* string -> DataLayout.t */
21 CAMLprim LLVMDataLayoutRef llvm_targetdata_create(value StringRep) {
22 return LLVMCreateDataLayout(String_val(StringRep));
2323 }
2424
25 /* TargetData.t -> [ unit */
26 CAMLprim value llvm_targetdata_add(LLVMTargetDataRef TD, LLVMPassManagerRef PM){
27 LLVMAddTargetData(TD, PM);
25 /* DataLayout.t -> [ unit */
26 CAMLprim value llvm_targetdata_add(LLVMDataLayoutRef TD, LLVMPassManagerRef PM){
27 LLVMAddDataLayout(TD, PM);
2828 return Val_unit;
2929 }
3030
31 /* TargetData.t -> string */
32 CAMLprim value llvm_targetdata_as_string(LLVMTargetDataRef TD) {
33 char *StringRep = LLVMCopyStringRepOfTargetData(TD);
31 /* DataLayout.t -> string */
32 CAMLprim value llvm_targetdata_as_string(LLVMDataLayoutRef TD) {
33 char *StringRep = LLVMCopyStringRepOfDataLayout(TD);
3434 value Copy = copy_string(StringRep);
3535 LLVMDisposeMessage(StringRep);
3636 return Copy;
3737 }
3838
39 /* TargetData.t -> unit */
40 CAMLprim value llvm_targetdata_dispose(LLVMTargetDataRef TD) {
41 LLVMDisposeTargetData(TD);
39 /* DataLayout.t -> unit */
40 CAMLprim value llvm_targetdata_dispose(LLVMDataLayoutRef TD) {
41 LLVMDisposeDataLayout(TD);
4242 return Val_unit;
4343 }
4444
45 /* TargetData.t -> Endian.t */
46 CAMLprim value llvm_byte_order(LLVMTargetDataRef TD) {
45 /* DataLayout.t -> Endian.t */
46 CAMLprim value llvm_byte_order(LLVMDataLayoutRef TD) {
4747 return Val_int(LLVMByteOrder(TD));
4848 }
4949
50 /* TargetData.t -> int */
51 CAMLprim value llvm_pointer_size(LLVMTargetDataRef TD) {
50 /* DataLayout.t -> int */
51 CAMLprim value llvm_pointer_size(LLVMDataLayoutRef TD) {
5252 return Val_int(LLVMPointerSize(TD));
5353 }
5454
55 /* TargetData.t -> Llvm.lltype -> Int64.t */
56 CAMLprim value llvm_size_in_bits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
55 /* DataLayout.t -> Llvm.lltype -> Int64.t */
56 CAMLprim value llvm_size_in_bits(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
5757 return caml_copy_int64(LLVMSizeOfTypeInBits(TD, Ty));
5858 }
5959
60 /* TargetData.t -> Llvm.lltype -> Int64.t */
61 CAMLprim value llvm_store_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
60 /* DataLayout.t -> Llvm.lltype -> Int64.t */
61 CAMLprim value llvm_store_size(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
6262 return caml_copy_int64(LLVMStoreSizeOfType(TD, Ty));
6363 }
6464
65 /* TargetData.t -> Llvm.lltype -> Int64.t */
66 CAMLprim value llvm_abi_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
65 /* DataLayout.t -> Llvm.lltype -> Int64.t */
66 CAMLprim value llvm_abi_size(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
6767 return caml_copy_int64(LLVMABISizeOfType(TD, Ty));
6868 }
6969
70 /* TargetData.t -> Llvm.lltype -> int */
71 CAMLprim value llvm_abi_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
70 /* DataLayout.t -> Llvm.lltype -> int */
71 CAMLprim value llvm_abi_align(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
7272 return Val_int(LLVMABIAlignmentOfType(TD, Ty));
7373 }
7474
75 /* TargetData.t -> Llvm.lltype -> int */
76 CAMLprim value llvm_stack_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
75 /* DataLayout.t -> Llvm.lltype -> int */
76 CAMLprim value llvm_stack_align(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
7777 return Val_int(LLVMCallFrameAlignmentOfType(TD, Ty));
7878 }
7979
80 /* TargetData.t -> Llvm.lltype -> int */
81 CAMLprim value llvm_preferred_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
80 /* DataLayout.t -> Llvm.lltype -> int */
81 CAMLprim value llvm_preferred_align(LLVMDataLayoutRef TD, LLVMTypeRef Ty) {
8282 return Val_int(LLVMPreferredAlignmentOfType(TD, Ty));
8383 }
8484
85 /* TargetData.t -> Llvm.llvalue -> int */
86 CAMLprim value llvm_preferred_align_of_global(LLVMTargetDataRef TD,
85 /* DataLayout.t -> Llvm.llvalue -> int */
86 CAMLprim value llvm_preferred_align_of_global(LLVMDataLayoutRef TD,
8787 LLVMValueRef GlobalVar) {
8888 return Val_int(LLVMPreferredAlignmentOfGlobal(TD, GlobalVar));
8989 }
9090
91 /* TargetData.t -> Llvm.lltype -> Int64.t -> int */
92 CAMLprim value llvm_element_at_offset(LLVMTargetDataRef TD, LLVMTypeRef Ty,
91 /* DataLayout.t -> Llvm.lltype -> Int64.t -> int */
92 CAMLprim value llvm_element_at_offset(LLVMDataLayoutRef TD, LLVMTypeRef Ty,
9393 value Offset) {
9494 return Val_int(LLVMElementAtOffset(TD, Ty, Int_val(Offset)));
9595 }
9696
97 /* TargetData.t -> Llvm.lltype -> int -> Int64.t */
98 CAMLprim value llvm_offset_of_element(LLVMTargetDataRef TD, LLVMTypeRef Ty,
97 /* DataLayout.t -> Llvm.lltype -> int -> Int64.t */
98 CAMLprim value llvm_offset_of_element(LLVMDataLayoutRef TD, LLVMTypeRef Ty,
9999 value Index) {
100100 return caml_copy_int64(LLVMOffsetOfElement(TD, Ty, Int_val(Index)));
101101 }
8080 The two pieces of the LLVM code generator are the high-level interface to the
8181 code generator and the set of reusable components that can be used to build
8282 target-specific backends. The two most important interfaces (:raw-html:``
83 `TargetMachine`_ :raw-html:`` and :raw-html:`` `TargetData`_
83 `TargetMachine`_ :raw-html:`` and :raw-html:`` `DataLayout`_
8484 :raw-html:``) are the only ones that are required to be defined for a
8585 backend to fit into the LLVM system, but the others must be defined if the
8686 reusable code generator components are going to be used.
196196 properties of the target (such as the instructions and registers it has), and do
197197 not incorporate any particular pieces of code generation algorithms.
198198
199 All of the target description classes (except the :raw-html:`` `TargetData`_
199 All of the target description classes (except the :raw-html:`` `DataLayout`_
200200 :raw-html:`` class) are designed to be subclassed by the concrete target
201201 implementation, and have virtual methods implemented. To get to these
202202 implementations, the :raw-html:`` `TargetMachine`_ :raw-html:`` class
213213 ``getFrameInfo``, etc.). This class is designed to be specialized by a concrete
214214 target implementation (e.g., ``X86TargetMachine``) which implements the various
215215 virtual methods. The only required target description class is the
216 :raw-html:`` `TargetData`_ :raw-html:`` class, but if the code
216 :raw-html:`` `DataLayout`_ :raw-html:`` class, but if the code
217217 generator components are to be used, the other interfaces should be implemented
218218 as well.
219219
220 .. _TargetData:
221
222 The ``TargetData`` class
220 .. _DataLayout:
221
222 The ``DataLayout`` class
223223 ------------------------
224224
225 The ``TargetData`` class is the only required target description class, and it
225 The ``DataLayout`` class is the only required target description class, and it
226226 is the only class that is not extensible (you cannot derived a new class from
227 it). ``TargetData`` specifies information about how the target lays out memory
227 it). ``DataLayout`` specifies information about how the target lays out memory
228228 for structures, the alignment requirements for various data types, the size of
229229 pointers in the target, and whether the target is little-endian or
230230 big-endian.
12521252 >#include "llvm/CodeGen/AsmPrinter.h"
12531253 #include "llvm/Function.h"
12541254 #include "llvm/Target/TargetMachine.h"
1255 #include "llvm/Target/TargetData.h"
1255 #include "llvm/DataLayout.h"
12561256 #include "llvm/Target/TargetAsmInfo.h"
12571257
12581258 void MyGCPrinter::beginAssembly(std::ostream &OS, AsmPrinter &AP,
12651265 // Set up for emitting addresses.
12661266 const char *AddressDirective;
12671267 int AddressAlignLog;
1268 if (AP.TM.getTargetData()->getPointerSize() == sizeof(int32_t)) {
1268 if (AP.TM.getDataLayout()->getPointerSize() == sizeof(int32_t)) {
12691269 AddressDirective = TAI.getData32bitsDirective();
12701270 AddressAlignLog = 2;
12711271 } else {
21032103

Structures may optionally be "packed" structures, which indicate that the

21042104 alignment of the struct is one byte, and that there is no padding between
21052105 the elements. In non-packed structs, padding between field types is inserted
2106 as defined by the TargetData string in the module, which is required to match
2106 as defined by the DataLayout string in the module, which is required to match
21072107 what the underlying code generator expects.

21082108
21092109

Structures can either be "literal" or "identified". A literal structure is

313313 intended to obtain the instruction set (getInstrInfo), register set
314314 (getRegisterInfo), stack frame layout (getFrameInfo), and
315315 similar information. XXXTargetMachine must also implement the
316 getTargetData method to access an object with target-specific data
316 getDataLayout method to access an object with target-specific data
317317 characteristics, such as data type size and alignment requirements.
318318

319319
320320

321321 For instance, for the SPARC target, the header file
322322 SparcTargetMachine.h declares prototypes for several get*Info
323 and getTargetData methods that simply return a class member.
323 and getDataLayout methods that simply return a class member.
324324

325325
326326
330330 class Module;
331331
332332 class SparcTargetMachine : public LLVMTargetMachine {
333 const TargetData DataLayout; // Calculates type size & alignment
333 const DataLayout DataLayout; // Calculates type size & alignment
334334 SparcSubtarget Subtarget;
335335 SparcInstrInfo InstrInfo;
336336 TargetFrameInfo FrameInfo;
347347 virtual const TargetRegisterInfo *getRegisterInfo() const {
348348 return &InstrInfo.getRegisterInfo();
349349 }
350 virtual const TargetData *getTargetData() const { return &DataLayout; }
350 virtual const DataLayout *getDataLayout() const { return &DataLayout; }
351351 static unsigned getModuleMatchQuality(const Module &M);
352352
353353 // Pass Pipeline Configuration
363363
  • getInstrInfo()
  • 364364
  • getRegisterInfo()
  • 365365
  • getFrameInfo()
  • 366
  • getTargetData()
  • 366
  • getDataLayout()
  • 367367
  • getSubtargetImpl()
  • 368368
    369369
    172172
    173173 // Set up the optimizer pipeline. Start with registering info about how the
    174174 // target lays out data structures.
    175 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
    175 OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout()));
    176176 // Provide basic AliasAnalysis support for GVN.
    177177 OurFPM.add(createBasicAliasAnalysisPass());
    178178 // Do simple "peephole" optimizations and bit-twiddling optzns.
    522522 #include "llvm/PassManager.h"
    523523 #include "llvm/Analysis/Verifier.h"
    524524 #include "llvm/Analysis/Passes.h"
    525 #include "llvm/Target/TargetData.h"
    525 #include "llvm/DataLayout.h"
    526526 #include "llvm/Transforms/Scalar.h"
    527527 #include "llvm/Support/TargetSelect.h"
    528528 #include <cstdio>
    11021102
    11031103 // Set up the optimizer pipeline. Start with registering info about how the
    11041104 // target lays out data structures.
    1105 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
    1105 OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout()));
    11061106 // Provide basic AliasAnalysis support for GVN.
    11071107 OurFPM.add(createBasicAliasAnalysisPass());
    11081108 // Do simple "peephole" optimizations and bit-twiddling optzns.
    900900 #include "llvm/PassManager.h"
    901901 #include "llvm/Analysis/Verifier.h"
    902902 #include "llvm/Analysis/Passes.h"
    903 #include "llvm/Target/TargetData.h"
    903 #include "llvm/DataLayout.h"
    904904 #include "llvm/Transforms/Scalar.h"
    905905 #include "llvm/Support/TargetSelect.h"
    906906 #include <cstdio>
    17221722
    17231723 // Set up the optimizer pipeline. Start with registering info about how the
    17241724 // target lays out data structures.
    1725 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
    1725 OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout()));
    17261726 // Provide basic AliasAnalysis support for GVN.
    17271727 OurFPM.add(createBasicAliasAnalysisPass());
    17281728 // Do simple "peephole" optimizations and bit-twiddling optzns.
    839839 #include "llvm/PassManager.h"
    840840 #include "llvm/Analysis/Verifier.h"
    841841 #include "llvm/Analysis/Passes.h"
    842 #include "llvm/Target/TargetData.h"
    842 #include "llvm/DataLayout.h"
    843843 #include "llvm/Transforms/Scalar.h"
    844844 #include "llvm/Support/TargetSelect.h"
    845845 #include <cstdio>
    17791779
    17801780 // Set up the optimizer pipeline. Start with registering info about how the
    17811781 // target lays out data structures.
    1782 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
    1782 OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout()));
    17831783 // Provide basic AliasAnalysis support for GVN.
    17841784 OurFPM.add(createBasicAliasAnalysisPass());
    17851785 // Do simple "peephole" optimizations and bit-twiddling optzns.
    523523
    
                      
                    
    524524 // Set up the optimizer pipeline. Start with registering info about how the
    525525 // target lays out data structures.
    526 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
    526 OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout()));
    527527 // Promote allocas to registers.
    528528 OurFPM.add(createPromoteMemoryToRegisterPass());
    529529 // Do simple "peephole" optimizations and bit-twiddling optzns.
    10071007 #include "llvm/PassManager.h"
    10081008 #include "llvm/Analysis/Verifier.h"
    10091009 #include "llvm/Analysis/Passes.h"
    1010 #include "llvm/Target/TargetData.h"
    1010 #include "llvm/DataLayout.h"
    10111011 #include "llvm/Transforms/Scalar.h"
    10121012 #include "llvm/Support/TargetSelect.h"
    10131013 #include <cstdio>
    21122112
    21132113 // Set up the optimizer pipeline. Start with registering info about how the
    21142114 // target lays out data structures.
    2115 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
    2115 OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout()));
    21162116 // Provide basic AliasAnalysis support for GVN.
    21172117 OurFPM.add(createBasicAliasAnalysisPass());
    21182118 // Promote allocas to registers.
    188188
    189189 (* Set up the optimizer pipeline. Start with registering info about how the
    190190 * target lays out data structures. *)
    191 TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    191 DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    192192
    193193 (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
    194194 add_instruction_combining the_fpm;
    964964
    965965 (* Set up the optimizer pipeline. Start with registering info about how the
    966966 * target lays out data structures. *)
    967 TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    967 DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    968968
    969969 (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
    970970 add_instruction_combination the_fpm;
    14971497
    14981498 (* Set up the optimizer pipeline. Start with registering info about how the
    14991499 * target lays out data structures. *)
    1500 TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    1500 DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    15011501
    15021502 (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
    15031503 add_instruction_combination the_fpm;
    15051505
    15061506 (* Set up the optimizer pipeline. Start with registering info about how the
    15071507 * target lays out data structures. *)
    1508 TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    1508 DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    15091509
    15101510 (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
    15111511 add_instruction_combination the_fpm;
    544544
    545545 (* Set up the optimizer pipeline. Start with registering info about how the
    546546 * target lays out data structures. *)
    547 TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    547 DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    548548
    549549 (* Promote allocas to registers. *)
    550550 add_memory_to_register_promotion the_fpm;
    18331833
    18341834 (* Set up the optimizer pipeline. Start with registering info about how the
    18351835 * target lays out data structures. *)
    1836 TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    1836 DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
    18371837
    18381838 (* Promote allocas to registers. *)
    18391839 add_memory_to_register_promotion the_fpm;
    4242 ignore (build_ret (build_call fn [| |] "" b) b);
    4343 end;
    4444
    45 let td = TargetData.create (target_triple m) in
    45 let td = DataLayout.create (target_triple m) in
    4646
    4747 ignore (PassManager.create ()
    48 ++ TargetData.add td
    48 ++ DataLayout.add td
    4949 ++ add_argument_promotion
    5050 ++ add_constant_merge
    5151 ++ add_dead_arg_elimination
    6262 ++ PassManager.run_module m
    6363 ++ PassManager.dispose);
    6464
    65 TargetData.dispose td
    65 DataLayout.dispose td
    6666
    6767
    6868 (*===-- Driver ------------------------------------------------------------===*)
    3737 let fn = define_function "fn" fty m in
    3838 ignore (build_ret_void (builder_at_end context (entry_block fn)));
    3939
    40 let td = TargetData.create (target_triple m) in
    40 let td = DataLayout.create (target_triple m) in
    4141
    4242 ignore (PassManager.create_function m
    43 ++ TargetData.add td
    43 ++ DataLayout.add td
    4444 ++ add_verifier
    4545 ++ add_constant_propagation
    4646 ++ add_sccp
    7777 ++ PassManager.finalize
    7878 ++ PassManager.dispose);
    7979
    80 TargetData.dispose td
    80 DataLayout.dispose td
    8181
    8282
    8383 (*===-- Driver ------------------------------------------------------------===*)
    3232 (*===-- Target Data -------------------------------------------------------===*)
    3333
    3434 let test_target_data () =
    35 let td = TargetData.create (target_triple m) in
    35 let td = DataLayout.create (target_triple m) in
    3636 let sty = struct_type context [| i32_type; i64_type |] in
    3737
    38 ignore (TargetData.as_string td);
    38 ignore (DataLayout.as_string td);
    3939 ignore (byte_order td);
    4040 ignore (pointer_size td);
    4141 ignore (intptr_type td);
    4848 ignore (element_at_offset td sty (Int64.of_int 1));
    4949 ignore (offset_of_element td sty 1);
    5050
    51 TargetData.dispose td
    51 DataLayout.dispose td
    5252
    5353
    5454 (*===-- Driver ------------------------------------------------------------===*)
    3838 %"struct.llvm::SymbolTable" = type opaque
    3939 %"struct.llvm::SymbolTableListTraits >" = type { %"struct.llvm::Function"*, %"struct.llvm::Function"* }
    4040 %"struct.llvm::SymbolTableListTraits >" = type { %"struct.llvm::Function"*, %"struct.llvm::BasicBlock"* }
    41 %"struct.llvm::TargetData" = type { %"struct.llvm::FunctionPass", i1, i8, i8, i8, i8, i8, i8, i8, i8 }
    41 %"struct.llvm::DataLayout" = type { %"struct.llvm::FunctionPass", i1, i8, i8, i8, i8, i8, i8, i8, i8 }
    4242 %"struct.llvm::TargetFrameInfo" = type { i32 (...)**, i32, i32, i32 }
    4343 %"struct.llvm::TargetInstrDescriptor" = type { i8*, i32, i32, i32, i1, i32, i32, i32, i32, i32, i32*, i32* }
    4444 %"struct.llvm::TargetInstrInfo" = type { i32 (...)**, %"struct.llvm::TargetInstrDescriptor"*, i32, i32 }
    45 %"struct.llvm::TargetMachine" = type { i32 (...)**, %"struct.std::basic_string,std::allocator >", %"struct.llvm::TargetData", %"struct.llvm::IntrinsicLowering"* }
    45 %"struct.llvm::TargetMachine" = type { i32 (...)**, %"struct.std::basic_string,std::allocator >", %"struct.llvm::DataLayout", %"struct.llvm::IntrinsicLowering"* }
    4646 %"struct.llvm::TargetRegClassInfo" = type { i32 (...)**, i32, i32, i32 }
    4747 %"struct.llvm::TargetRegInfo" = type { i32 (...)**, %"struct.std::vector >", %"struct.llvm::TargetMachine"* }
    4848 %"struct.llvm::Type" = type { %"struct.llvm::Value", i32, i32, i1, i32, %"struct.llvm::Type"*, %"struct.std::vector >" }
    1313
    1414 #include "BugDriver.h"
    1515 #include "llvm/Constants.h"
    16 #include "llvm/DataLayout.h"
    1617 #include "llvm/DerivedTypes.h"
    1718 #include "llvm/LLVMContext.h"
    1819 #include "llvm/Module.h"
    2425 #include "llvm/Transforms/Scalar.h"
    2526 #include "llvm/Transforms/Utils/Cloning.h"
    2627 #include "llvm/Transforms/Utils/CodeExtractor.h"
    27 #include "llvm/Target/TargetData.h"
    2828 #include "llvm/Support/CommandLine.h"
    2929 #include "llvm/Support/Debug.h"
    3030 #include "llvm/Support/FileUtilities.h"
    1515 //===----------------------------------------------------------------------===//
    1616
    1717 #include "BugDriver.h"
    18 #include "llvm/DataLayout.h"
    1819 #include "llvm/Module.h"
    1920 #include "llvm/PassManager.h"
    2021 #include "llvm/Analysis/Verifier.h"
    2122 #include "llvm/Bitcode/ReaderWriter.h"
    22 #include "llvm/Target/TargetData.h"
    2323 #include "llvm/Support/FileUtilities.h"
    2424 #include "llvm/Support/CommandLine.h"
    2525 #include "llvm/Support/SystemUtils.h"
    1313 //===----------------------------------------------------------------------===//
    1414
    1515 #include "llvm/LLVMContext.h"
    16 #include "llvm/DataLayout.h"
    1617 #include "llvm/Module.h"
    1718 #include "llvm/PassManager.h"
    1819 #include "llvm/Pass.h"
    3334 #include "llvm/Support/Signals.h"
    3435 #include "llvm/Support/TargetRegistry.h"
    3536 #include "llvm/Support/TargetSelect.h"
    36 #include "llvm/Target/TargetData.h"
    3737 #include "llvm/Target/TargetLibraryInfo.h"
    3838 #include "llvm/Target/TargetMachine.h"
    3939 #include
    505505 PM.add(TLI);
    506506
    507507 // Add the target data from the target machine, if it exists, or the module.
    508 if (const TargetData *TD = Target.getTargetData())
    509 PM.add(new TargetData(*TD));
    508 if (const DataLayout *TD = Target.getDataLayout())
    509 PM.add(new DataLayout(*TD));
    510510 else
    511 PM.add(new TargetData(mod));
    511 PM.add(new DataLayout(mod));
    512512
    513513 // Override default to generate verbose assembly.
    514514 Target.setAsmVerbosityDefault(true);
    1717 #include "llvm/Assembly/PrintModulePass.h"
    1818 #include "llvm/Bitcode/ReaderWriter.h"
    1919 #include "llvm/Transforms/IPO.h"
    20 #include "llvm/Target/TargetData.h"
    20 #include "llvm/DataLayout.h"
    2121 #include "llvm/Support/CommandLine.h"
    2222 #include "llvm/Support/IRReader.h"
    2323 #include "llvm/Support/ManagedStatic.h"
    205205 // In addition to deleting all other functions, we also want to spiff it
    206206 // up a little bit. Do this now.
    207207 PassManager Passes;
    208 Passes.add(new TargetData(M.get())); // Use correct TargetData
    208 Passes.add(new DataLayout(M.get())); // Use correct DataLayout
    209209
    210210 std::vector Gvs(GVs.begin(), GVs.end());
    211211
    1414 #include "LTOCodeGenerator.h"
    1515 #include "LTOModule.h"
    1616 #include "llvm/Constants.h"
    17 #include "llvm/DataLayout.h"
    1718 #include "llvm/DerivedTypes.h"
    1819 #include "llvm/Linker.h"
    1920 #include "llvm/LLVMContext.h"
    2829 #include "llvm/MC/SubtargetFeature.h"
    2930 #include "llvm/Target/Mangler.h"
    3031 #include "llvm/Target/TargetOptions.h"
    31 #include "llvm/Target/TargetData.h"
    3232 #include "llvm/Target/TargetMachine.h"
    3333 #include "llvm/Target/TargetRegisterInfo.h"
    3434 #include "llvm/Transforms/IPO.h"
    292292
    293293 // mark which symbols can not be internalized
    294294 MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL);
    295 Mangler mangler(Context, *_target->getTargetData());
    295 Mangler mangler(Context, *_target->getDataLayout());
    296296 std::vector mustPreserveList;
    297297 SmallPtrSet asmUsed;
    298298
    360360 // Start off with a verification pass.
    361361 passes.add(createVerifierPass());
    362362
    363 // Add an appropriate TargetData instance for this module...
    364 passes.add(new TargetData(*_target->getTargetData()));
    363 // Add an appropriate DataLayout instance for this module...
    364 passes.add(new DataLayout(*_target->getDataLayout()));
    365365
    366366 // Enabling internalize here would use its AllButMain variant. It
    367367 // keeps only main if it exists and does nothing for libraries. Instead
    375375
    376376 FunctionPassManager *codeGenPasses = new FunctionPassManager(mergedModule);
    377377
    378 codeGenPasses->add(new TargetData(*_target->getTargetData()));
    378 codeGenPasses->add(new DataLayout(*_target->getDataLayout()));
    379379
    380380 formatted_raw_ostream Out(out);
    381381
    157157 LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
    158158 : _module(m), _target(t),
    159159 _context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL),
    160 _mangler(_context, *_target->getTargetData()) {}
    160 _mangler(_context, *_target->getDataLayout()) {}
    161161
    162162 /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
    163163 /// bitcode.
    1212 //===----------------------------------------------------------------------===//
    1313
    1414 #include "llvm/LLVMContext.h"
    15 #include "llvm/DataLayout.h"
    1516 #include "llvm/DebugInfo.h"
    1617 #include "llvm/Module.h"
    1718 #include "llvm/PassManager.h"
    2223 #include "llvm/Analysis/LoopPass.h"
    2324 #include "llvm/Analysis/RegionPass.h"
    2425 #include "llvm/Analysis/CallGraph.h"
    25 #include "llvm/Target/TargetData.h"
    2626 #include "llvm/Target/TargetLibraryInfo.h"
    2727 #include "llvm/Target/TargetMachine.h"
    2828 #include "llvm/ADT/StringSet.h"
    567567 TLI->disableAllFunctions();
    568568 Passes.add(TLI);
    569569
    570 // Add an appropriate TargetData instance for this module.
    571 TargetData *TD = 0;
    570 // Add an appropriate DataLayout instance for this module.
    571 DataLayout *TD = 0;
    572572 const std::string &ModuleDataLayout = M.get()->getDataLayout();
    573573 if (!ModuleDataLayout.empty())
    574 TD = new TargetData(ModuleDataLayout);
    574 TD = new DataLayout(ModuleDataLayout);
    575575 else if (!DefaultDataLayout.empty())
    576 TD = new TargetData(DefaultDataLayout);
    576 TD = new DataLayout(DefaultDataLayout);
    577577
    578578 if (TD)
    579579 Passes.add(TD);
    582582 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
    583583 FPasses.reset(new FunctionPassManager(M.get()));
    584584 if (TD)
    585 FPasses->add(new TargetData(*TD));
    585 FPasses->add(new DataLayout(*TD));
    586586 }
    587587
    588588 if (PrintBreakpoints) {
    88
    99 #include "llvm/BasicBlock.h"
    1010 #include "llvm/Constants.h"
    11 #include "llvm/DataLayout.h"
    1112 #include "llvm/DerivedTypes.h"
    1213 #include "llvm/IRBuilder.h"
    1314 #include "llvm/Instructions.h"
    1617 #include "llvm/Operator.h"
    1718 #include "llvm/ADT/STLExtras.h"
    1819 #include "llvm/Analysis/ValueTracking.h"
    19 #include "llvm/Target/TargetData.h"
    2020 #include "gtest/gtest.h"
    2121
    2222 namespace llvm {
    182182 EXPECT_NE(S3, Gep3);
    183183
    184184 int64_t Offset;
    185 TargetData TD("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3"
    185 DataLayout TD("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3"
    186186 "2:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80"
    187187 ":128:128-n8:16:32:64-S128");
    188188 // Make sure we don't crash
    1313 #include "llvm/Pass.h"
    1414 #include "llvm/Analysis/LoopPass.h"
    1515 #include "llvm/CallGraphSCCPass.h"
    16 #include "llvm/Target/TargetData.h"
    16 #include "llvm/DataLayout.h"
    1717 #include "llvm/Support/raw_ostream.h"
    1818 #include "llvm/DerivedTypes.h"
    1919 #include "llvm/Constants.h"
    9393 initializeModuleNDMPass(*PassRegistry::getPassRegistry());
    9494 }
    9595 virtual bool runOnModule(Module &M) {
    96 EXPECT_TRUE(getAnalysisIfAvailable<TargetData>());
    96 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
    9797 run++;
    9898 return false;
    9999 }
    166166 initializeCGPassPass(*PassRegistry::getPassRegistry());
    167167 }
    168168 virtual bool runOnSCC(CallGraphSCC &SCMM) {
    169 EXPECT_TRUE(getAnalysisIfAvailable<TargetData>());
    169 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
    170170 run();
    171171 return false;
    172172 }
    176176 public:
    177177 virtual bool runOnFunction(Function &F) {
    178178 // FIXME: PR4112
    179 // EXPECT_TRUE(getAnalysisIfAvailable<TargetData>());
    179 // EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
    180180 run();
    181181 return false;
    182182 }
    203203 return false;
    204204 }
    205205 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
    206 EXPECT_TRUE(getAnalysisIfAvailable<TargetData>());
    206 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
    207207 run();
    208208 return false;
    209209 }
    240240 return false;
    241241 }
    242242 virtual bool runOnBasicBlock(BasicBlock &BB) {
    243 EXPECT_TRUE(getAnalysisIfAvailable<TargetData>());
    243 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
    244244 run();
    245245 return false;
    246246 }
    265265 initializeFPassPass(*PassRegistry::getPassRegistry());
    266266 }
    267267 virtual bool runOnModule(Module &M) {
    268 EXPECT_TRUE(getAnalysisIfAvailable<TargetData>());
    268 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
    269269 for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
    270270 Function &F = *I;
    271271 {
    291291 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
    292292
    293293 PassManager Passes;
    294 Passes.add(new TargetData(&M));
    294 Passes.add(new DataLayout(&M));
    295295 Passes.add(mNDM2);
    296296 Passes.add(mNDM);
    297297 Passes.add(mNDNM);
    315315 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
    316316
    317317 PassManager Passes;
    318 Passes.add(new TargetData(&M));
    318 Passes.add(new DataLayout(&M));
    319319 Passes.add(mNDM);
    320320 Passes.add(mNDNM);
    321321 Passes.add(mNDM2);// invalidates mNDM needed by mDNM
    337337 OwningPtr M(makeLLVMModule());
    338338 T *P = new T();
    339339 PassManager Passes;
    340 Passes.add(new TargetData(M.get()));
    340 Passes.add(new DataLayout(M.get()));
    341341 Passes.add(P);
    342342 Passes.run(*M);
    343343 T::finishedOK(run);
    348348 Module *M = makeLLVMModule();
    349349 T *P = new T();
    350350 PassManager Passes;
    351 Passes.add(new TargetData(M));
    351 Passes.add(new DataLayout(M));
    352352 Passes.add(P);
    353353 Passes.run(*M);
    354354 T::finishedOK(run, N);
    386386 SCOPED_TRACE("Running OnTheFlyTest");
    387387 struct OnTheFlyTest *O = new OnTheFlyTest();
    388388 PassManager Passes;
    389 Passes.add(new TargetData(M));
    389 Passes.add(new DataLayout(M));
    390390 Passes.add(O);
    391391 Passes.run(*M);
    392392
    176176 if (Size)
    177177 O << Size << ", ";
    178178 else
    179 O << "\n" << IndentStr << " State.getTarget().getTargetData()"
    179 O << "\n" << IndentStr << " State.getTarget().getDataLayout()"
    180180 "->getTypeAllocSize(EVT(LocVT).getTypeForEVT(State.getContext())), ";
    181181 if (Align)
    182182 O << Align;
    183183 else
    184 O << "\n" << IndentStr << " State.getTarget().getTargetData()"
    184 O << "\n" << IndentStr << " State.getTarget().getDataLayout()"
    185185 "->getABITypeAlignment(EVT(LocVT).getTypeForEVT(State.getContext()))";
    186186 if (Action->isSubClassOf("CCAssignToStackWithShadow"))
    187187 O << ", " << getQualifiedName(Action->getValueAsDef("ShadowReg"));