1 //===-- llvm/Target/TargetData.h - Data size & alignment routines-*- C++ -*-==//
3 // This file defines target properties related to datatype size/offset/alignment
4 // information. It uses lazy annotations to cache information about how
5 // structure types are laid out and used.
7 // This structure should be created once, filled in if the defaults are not
8 // correct and then passed around by const&. None of the members functions
9 // require modification to the object.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TARGET_TARGETDATA_H
14 #define LLVM_TARGET_TARGETDATA_H
16 #include "llvm/Annotation.h"
25 unsigned char ByteAlignment; // Defaults to 1 bytes
26 unsigned char ShortAlignment; // Defaults to 2 bytes
27 unsigned char IntAlignment; // Defaults to 4 bytes
28 unsigned char LongAlignment; // Defaults to 8 bytes
29 unsigned char FloatAlignment; // Defaults to 4 bytes
30 unsigned char DoubleAlignment; // Defaults to 8 bytes
31 unsigned char PointerSize; // Defaults to 8 bytes
32 unsigned char IntegerRegSize; // Defaults to PointerSize = 8 bytes
33 unsigned char PointerAlignment; // Defaults to 8 bytes
34 AnnotationID AID; // AID for structure layout annotation
36 static Annotation *TypeAnFactory(AnnotationID, const Annotable *, void *);
38 TargetData(const std::string &TargetName,
39 unsigned char IntRegSize = 8,
40 unsigned char PtrSize = 8,
41 unsigned char PtrAl = 8, unsigned char DoubleAl = 8,
42 unsigned char FloatAl = 4, unsigned char LongAl = 8,
43 unsigned char IntAl = 4, unsigned char ShortAl = 2,
44 unsigned char ByteAl = 1);
45 ~TargetData(); // Not virtual, do not subclass this class
47 unsigned char getByteAlignment() const { return ByteAlignment; }
48 unsigned char getShortAlignment() const { return ShortAlignment; }
49 unsigned char getIntAlignment() const { return IntAlignment; }
50 unsigned char getLongAlignment() const { return LongAlignment; }
51 unsigned char getFloatAlignment() const { return FloatAlignment; }
52 unsigned char getDoubleAlignment() const { return DoubleAlignment; }
53 unsigned char getPointerAlignment() const { return PointerAlignment; }
54 unsigned char getPointerSize() const { return PointerSize; }
55 unsigned char getIntegerRegize() const { return IntegerRegSize; }
56 AnnotationID getStructLayoutAID() const { return AID; }
58 // getTypeSize - Return the number of bytes neccesary to hold the specified
60 uint64_t getTypeSize (const Type *Ty) const;
62 // getTypeAlignment - Return the minimum required alignment for the specified
64 unsigned char getTypeAlignment(const Type *Ty) const;
66 // getIndexOffset - return the offset from the beginning of the type for the
67 // specified indices. This is used to implement getElementPtr and load and
68 // stores that include the implicit form of getelementptr.
70 uint64_t getIndexedOffset(const Type *Ty,
71 const std::vector<Value*> &Indices) const;
73 inline const StructLayout *getStructLayout(const StructType *Ty) const {
74 return (const StructLayout*)
75 ((const Annotable*)Ty)->getOrCreateAnnotation(AID);
79 // This annotation (attached ONLY to StructType classes) is used to lazily
80 // calculate structure layout information for a target machine, based on the
81 // TargetData structure.
83 struct StructLayout : public Annotation {
84 std::vector<uint64_t> MemberOffsets;
86 unsigned StructAlignment;
88 friend class TargetData; // Only TargetData can create this class
89 inline StructLayout(const StructType *ST, const TargetData &TD);