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"
24 unsigned char ByteAlignment; // Defaults to 1 bytes
25 unsigned char ShortAlignment; // Defaults to 2 bytes
26 unsigned char IntAlignment; // Defaults to 4 bytes
27 unsigned char LongAlignment; // Defaults to 8 bytes
28 unsigned char FloatAlignment; // Defaults to 4 bytes
29 unsigned char DoubleAlignment; // Defaults to 8 bytes
30 unsigned char PointerSize; // Defaults to 8 bytes
31 unsigned char PointerAlignment; // Defaults to 8 bytes
32 AnnotationID AID; // AID for structure layout annotation
34 static Annotation *TypeAnFactory(AnnotationID, const Annotable *, void *);
36 TargetData(const std::string &TargetName, unsigned char PtrSize = 8,
37 unsigned char PtrAl = 8, unsigned char DoubleAl = 8,
38 unsigned char FloatAl = 4, unsigned char LongAl = 8,
39 unsigned char IntAl = 4, unsigned char ShortAl = 2,
40 unsigned char ByteAl = 1);
41 ~TargetData(); // Not virtual, do not subclass this class
43 unsigned char getByteAlignment() const { return ByteAlignment; }
44 unsigned char getShortAlignment() const { return ShortAlignment; }
45 unsigned char getIntAlignment() const { return IntAlignment; }
46 unsigned char getLongAlignment() const { return LongAlignment; }
47 unsigned char getFloatAlignment() const { return FloatAlignment; }
48 unsigned char getDoubleAlignment() const { return DoubleAlignment; }
49 unsigned char getPointerAlignment() const { return PointerAlignment; }
50 unsigned char getPointerSize() const { return PointerSize; }
51 AnnotationID getStructLayoutAID() const { return AID; }
53 // getTypeSize - Return the number of bytes neccesary to hold the specified
55 unsigned getTypeSize (const Type *Ty) const;
57 // getTypeAlignment - Return the minimum required alignment for the specified
59 unsigned char getTypeAlignment(const Type *Ty) const;
61 // getIndexOffset - return the offset from the beginning of the type for the
62 // specified indices. This is used to implement getElementPtr and load and
63 // stores that include the implicit form of getelementptr.
65 unsigned getIndexedOffset(const Type *Ty,
66 const std::vector<Value*> &Indices) const;
68 inline const StructLayout *getStructLayout(const StructType *Ty) const {
69 return (const StructLayout*)
70 ((const Annotable*)Ty)->getOrCreateAnnotation(AID);
74 // This annotation (attached ONLY to StructType classes) is used to lazily
75 // calculate structure layout information for a target machine, based on the
76 // TargetData structure.
78 struct StructLayout : public Annotation {
79 std::vector<unsigned> MemberOffsets;
81 unsigned StructAlignment;
83 friend class TargetData; // Only TargetData can create this class
84 inline StructLayout(const StructType *ST, const TargetData &TD);