1 //===-- llvm/Target/TargetData.h - Data size & alignment info ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines target properties related to datatype size/offset/alignment
11 // information. It uses lazy annotations to cache information about how
12 // structure types are laid out and used.
14 // This structure should be created once, filled in if the defaults are not
15 // correct and then passed around by const&. None of the members functions
16 // require modification to the object.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_TARGET_TARGETDATA_H
21 #define LLVM_TARGET_TARGETDATA_H
23 #include "llvm/Pass.h"
24 #include "Support/DataTypes.h"
35 class TargetData : public ImmutablePass {
36 bool LittleEndian; // Defaults to false
37 unsigned char ByteAlignment; // Defaults to 1 bytes
38 unsigned char ShortAlignment; // Defaults to 2 bytes
39 unsigned char IntAlignment; // Defaults to 4 bytes
40 unsigned char LongAlignment; // Defaults to 8 bytes
41 unsigned char FloatAlignment; // Defaults to 4 bytes
42 unsigned char DoubleAlignment; // Defaults to 8 bytes
43 unsigned char PointerSize; // Defaults to 8 bytes
44 unsigned char PointerAlignment; // Defaults to 8 bytes
47 TargetData(const std::string &TargetName = "",
48 bool LittleEndian = false,
49 unsigned char PtrSize = 8,
50 unsigned char PtrAl = 8, unsigned char DoubleAl = 8,
51 unsigned char FloatAl = 4, unsigned char LongAl = 8,
52 unsigned char IntAl = 4, unsigned char ShortAl = 2,
53 unsigned char ByteAl = 1);
56 TargetData (const TargetData &TD) :
58 LittleEndian (TD.isLittleEndian ()),
59 ByteAlignment (TD.getByteAlignment ()),
60 ShortAlignment (TD.getShortAlignment ()),
61 IntAlignment (TD.getIntAlignment ()),
62 LongAlignment (TD.getLongAlignment ()),
63 FloatAlignment (TD.getFloatAlignment ()),
64 DoubleAlignment (TD.getDoubleAlignment ()),
65 PointerSize (TD.getPointerSize ()),
66 PointerAlignment (TD.getPointerAlignment ()) {
69 TargetData(const std::string &ToolName, const Module *M);
70 ~TargetData(); // Not virtual, do not subclass this class
72 /// Target endianness...
73 bool isLittleEndian() const { return LittleEndian; }
74 bool isBigEndian() const { return !LittleEndian; }
76 /// Target alignment constraints
77 unsigned char getByteAlignment() const { return ByteAlignment; }
78 unsigned char getShortAlignment() const { return ShortAlignment; }
79 unsigned char getIntAlignment() const { return IntAlignment; }
80 unsigned char getLongAlignment() const { return LongAlignment; }
81 unsigned char getFloatAlignment() const { return FloatAlignment; }
82 unsigned char getDoubleAlignment() const { return DoubleAlignment; }
83 unsigned char getPointerAlignment() const { return PointerAlignment; }
84 unsigned char getPointerSize() const { return PointerSize; }
86 /// getTypeSize - Return the number of bytes necessary to hold the specified
88 uint64_t getTypeSize(const Type *Ty) const;
90 /// getTypeAlignment - Return the minimum required alignment for the specified
92 unsigned char getTypeAlignment(const Type *Ty) const;
94 /// getIntPtrType - Return an unsigned integer type that is the same size or
95 /// greater to the host pointer size.
96 const Type *getIntPtrType() const;
98 /// getIndexOffset - return the offset from the beginning of the type for the
99 /// specified indices. This is used to implement getelementptr.
101 uint64_t getIndexedOffset(const Type *Ty,
102 const std::vector<Value*> &Indices) const;
104 const StructLayout *getStructLayout(const StructType *Ty) const;
107 // This object is used to lazily calculate structure layout information for a
108 // target machine, based on the TargetData structure.
110 struct StructLayout {
111 std::vector<uint64_t> MemberOffsets;
113 unsigned StructAlignment;
115 friend class TargetData; // Only TargetData can create this class
116 StructLayout(const StructType *ST, const TargetData &TD);
119 } // End llvm namespace