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