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