Changes to build successfully with GCC 3.02
[oota-llvm.git] / include / llvm / Target / TargetData.h
1 //===-- llvm/Target/TargetData.h - Data size & alignment routines-*- C++ -*-==//
2 //
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.
6 //
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.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TARGET_TARGETDATA_H
14 #define LLVM_TARGET_TARGETDATA_H
15
16 #include "llvm/Type.h"
17
18 class StructType;
19 class StructLayout;
20
21 class TargetData {
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
31  
32   static Annotation *TypeAnFactory(AnnotationID, const Annotable *, void *);
33 public:
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
40
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; }
50
51   // getTypeSize - Return the number of bytes neccesary to hold the specified
52   // type
53   unsigned      getTypeSize     (const Type *Ty) const;
54
55   // getTypeAlignment - Return the minimum required alignment for the specified
56   // type
57   unsigned char getTypeAlignment(const Type *Ty) const;
58
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.
62   //
63   unsigned      getIndexedOffset(const Type *Ty, 
64                                  const std::vector<Value*> &Indices) const;
65
66   inline const StructLayout *getStructLayout(const StructType *Ty) const {
67     return (const StructLayout*)((const Type*)Ty)->getOrCreateAnnotation(AID);
68   }
69 };
70
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.
74 //
75 struct StructLayout : public Annotation {
76   std::vector<unsigned> MemberOffsets;
77   unsigned StructSize;
78   unsigned StructAlignment;
79 private:
80   friend class TargetData;   // Only TargetData can create this class
81   inline StructLayout(const StructType *ST, const TargetData &TD);
82 };
83
84 #endif