Remove two fields from TargetData which are target specific.
[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/Pass.h"
17 #include "Support/Annotation.h"
18 #include "Support/DataTypes.h"
19 #include <vector>
20 class Value;
21 class Type;
22 class StructType;
23 class StructLayout;
24
25 class TargetData : public ImmutablePass {
26   bool          LittleEndian;          // Defaults to false
27   unsigned char ByteAlignment;         // Defaults to 1 bytes
28   unsigned char ShortAlignment;        // Defaults to 2 bytes
29   unsigned char IntAlignment;          // Defaults to 4 bytes
30   unsigned char LongAlignment;         // Defaults to 8 bytes
31   unsigned char FloatAlignment;        // Defaults to 4 bytes
32   unsigned char DoubleAlignment;       // Defaults to 8 bytes
33   unsigned char PointerSize;           // Defaults to 8 bytes
34   unsigned char PointerAlignment;      // Defaults to 8 bytes
35   AnnotationID  AID;                   // AID for structure layout annotation
36  
37   static Annotation *TypeAnFactory(AnnotationID, const Annotable *, void *);
38 public:
39   TargetData(const std::string &TargetName = "",
40              bool LittleEndian = false,
41              unsigned char PtrSize = 8,
42              unsigned char PtrAl = 8, unsigned char DoubleAl = 8,
43              unsigned char FloatAl = 4, unsigned char LongAl = 8, 
44              unsigned char IntAl = 4, unsigned char ShortAl = 2,
45              unsigned char ByteAl = 1);
46   TargetData(const std::string &ToolName, const Module *M);
47   ~TargetData();  // Not virtual, do not subclass this class
48
49   /// Target endianness...
50   bool          isLittleEndian()      const { return     LittleEndian; }
51   bool          isBigEndian()         const { return    !LittleEndian; }
52
53   /// Target alignment constraints
54   unsigned char getByteAlignment()    const { return    ByteAlignment; }
55   unsigned char getShortAlignment()   const { return   ShortAlignment; }
56   unsigned char getIntAlignment()     const { return     IntAlignment; }
57   unsigned char getLongAlignment()    const { return    LongAlignment; }
58   unsigned char getFloatAlignment()   const { return   FloatAlignment; }
59   unsigned char getDoubleAlignment()  const { return  DoubleAlignment; }
60   unsigned char getPointerAlignment() const { return PointerAlignment; }
61   unsigned char getPointerSize()      const { return      PointerSize; }
62   AnnotationID  getStructLayoutAID()  const { return AID; }
63
64   // getTypeSize - Return the number of bytes neccesary to hold the specified
65   // type
66   uint64_t      getTypeSize     (const Type *Ty) const;
67
68   // getTypeAlignment - Return the minimum required alignment for the specified
69   // type
70   unsigned char getTypeAlignment(const Type *Ty) const;
71
72   // getIndexOffset - return the offset from the beginning of the type for the
73   // specified indices.  This is used to implement getelementptr.
74   //
75   uint64_t      getIndexedOffset(const Type *Ty, 
76                                  const std::vector<Value*> &Indices) const;
77   
78   inline const StructLayout *getStructLayout(const StructType *Ty) const {
79     return (const StructLayout*)
80          ((const Annotable*)Ty)->getOrCreateAnnotation(AID);
81   }
82 };
83
84 // This annotation (attached ONLY to StructType classes) is used to lazily
85 // calculate structure layout information for a target machine, based on the
86 // TargetData structure.
87 //
88 struct StructLayout : public Annotation {
89   std::vector<uint64_t> MemberOffsets;
90   uint64_t StructSize;
91   unsigned StructAlignment;
92 private:
93   friend class TargetData;   // Only TargetData can create this class
94   inline StructLayout(const StructType *ST, const TargetData &TD);
95 };
96
97 #endif