There are no implicit gep forms of load and store anymore
[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/Annotation.h"
17 #include "Support/DataTypes.h"
18 #include <vector>
19 class Value;
20 class Type;
21 class StructType;
22 class StructLayout;
23
24 class TargetData {
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
35  
36   static Annotation *TypeAnFactory(AnnotationID, const Annotable *, void *);
37 public:
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
46
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; }
57
58   // getTypeSize - Return the number of bytes neccesary to hold the specified
59   // type
60   uint64_t      getTypeSize     (const Type *Ty) const;
61
62   // getTypeAlignment - Return the minimum required alignment for the specified
63   // type
64   unsigned char getTypeAlignment(const Type *Ty) const;
65
66   // getIndexOffset - return the offset from the beginning of the type for the
67   // specified indices.  This is used to implement getelementptr.
68   //
69   uint64_t      getIndexedOffset(const Type *Ty, 
70                                  const std::vector<Value*> &Indices) const;
71   
72   inline const StructLayout *getStructLayout(const StructType *Ty) const {
73     return (const StructLayout*)
74          ((const Annotable*)Ty)->getOrCreateAnnotation(AID);
75   }
76 };
77
78 // This annotation (attached ONLY to StructType classes) is used to lazily
79 // calculate structure layout information for a target machine, based on the
80 // TargetData structure.
81 //
82 struct StructLayout : public Annotation {
83   std::vector<uint64_t> MemberOffsets;
84   uint64_t StructSize;
85   unsigned StructAlignment;
86 private:
87   friend class TargetData;   // Only TargetData can create this class
88   inline StructLayout(const StructType *ST, const TargetData &TD);
89 };
90
91 #endif