- unsigned int getStorageSize(const TargetMachine& tmi) const {
- if (layoutCache->targetInfo && *layoutCache->targetInfo != tmi) {
- // target machine has changed (hey it could happen). discard cached info.
- ResetCachedInfo();
- layoutCache->targetInfo = &tmi;
- }
-
- if (layoutCache->storageSize < 0) {
- layoutCache->storageSize = tmi.findOptimalStorageSize(this);
- assert(layoutCache->storageSize >= 0);
- }
- return layoutCache->storageSize;
- }
- unsigned int getElementOffset(int i, const TargetMachine& tmi) const {
- // target machine has changed (hey it could happen). discard cached info.
- if (layoutCache->targetInfo && *layoutCache->targetInfo != tmi)
- ResetCachedInfo();
-
- if (layoutCache->memberOffsets[i] < 0) {
- layoutCache->targetInfo = &tmi; // remember which target was used
-
- unsigned int *offsetVec = tmi.findOptimalMemberOffsets(this);
- for (unsigned i=0, N=layoutCache->memberOffsets.size(); i < N; ++i) {
- layoutCache->memberOffsets[i] = offsetVec[i];
- assert(layoutCache->memberOffsets[i] >= 0);
- }
- delete[] offsetVec;
- }
-
- return layoutCache->memberOffsets[i];
+// SequentialType - This is the superclass of the array and pointer type
+// classes. Both of these represent "arrays" in memory. The array type
+// represents a specifically sized array, pointer types are unsized/unknown size
+// arrays. SequentialType holds the common features of both, which stem from
+// the fact that both lay their components out in memory identically.
+//
+class SequentialType : public CompositeType {
+ SequentialType(const SequentialType &); // Do not implement!
+ const SequentialType &operator=(const SequentialType &); // Do not implement!
+protected:
+ PATypeHandle<Type> ElementType;
+
+ SequentialType(PrimitiveID TID, const Type *ElType)
+ : CompositeType(TID), ElementType(PATypeHandle<Type>(ElType, this)) {
+ }
+public:
+
+ inline const Type *getElementType() const { return ElementType; }
+
+ virtual const Type *getContainedType(unsigned i) const {
+ return i == 0 ? ElementType.get() : 0;
+ }
+ virtual unsigned getNumContainedTypes() const { return 1; }
+
+ // getTypeAtIndex - Given an index value into the type, return the type of the
+ // element. For sequential types, there is only one subtype...
+ //
+ virtual const Type *getTypeAtIndex(const Value *V) const {
+ return ElementType.get();
+ }
+ virtual bool indexValid(const Value *V) const {
+ return V->getType() == Type::UIntTy; // Must be an unsigned int index
+ }
+
+ // getIndexType() - Return the type required of indices for this composite.
+ // For structures, this is ubyte, for arrays, this is uint
+ //
+ virtual const Type *getIndexType() const { return Type::UIntTy; }
+
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const SequentialType *T) { return true; }
+ static inline bool classof(const Type *T) {
+ return T->getPrimitiveID() == ArrayTyID ||
+ T->getPrimitiveID() == PointerTyID;
+ }
+ static inline bool classof(const Value *V) {
+ return isa<Type>(V) && classof(cast<const Type>(V));