Make the PATypeHolder use a simple union-find implementation to handle
[oota-llvm.git] / include / llvm / Type.h
index e2ee9545bdaafac2a1bf02e6340f6628b96cc97c..5900b402dcc4931e278388d21bfd679a4fb4badf 100644 (file)
@@ -1,4 +1,4 @@
-//===-- llvm/Type.h - Classes for handling data types ------------*- C++ -*--=//
+//===-- llvm/Type.h - Classes for handling data types -----------*- C++ -*-===//
 //
 // This file contains the declaration of the Type class.  For more "Type" type
 // stuff, look in DerivedTypes.h.
@@ -37,8 +37,7 @@ class PointerType;
 class StructType;
 class OpaqueType;
 
-class Type : public Value {
-public:
+struct Type : public Value {
   ///===-------------------------------------------------------------------===//
   /// Definitions of all of the base types for the Type system.  Based on this
   /// value, you can cast to a "DerivedType" subclass (see DerivedTypes.h)
@@ -74,6 +73,7 @@ private:
   unsigned    UID;       // The unique ID number for this class
   bool        Abstract;  // True if type contains an OpaqueType
 
+  const Type *getForwardedTypeInternal() const;
 protected:
   /// ctor is protected, so only subclasses can create Type objects...
   Type(const std::string &Name, PrimitiveID id);
@@ -88,6 +88,15 @@ protected:
   ///
   inline void setAbstract(bool Val) { Abstract = Val; }
 
+  /// isTypeAbstract - This method is used to calculate the Abstract bit.
+  ///
+  bool isTypeAbstract();
+
+  /// ForwardType - This field is used to implement the union find scheme for
+  /// abstract types.  When types are refined to other types, this field is set
+  /// to the more refined type.  Only abstract types can be forwarded.
+  mutable const Type *ForwardType;
+
 public:
   virtual void print(std::ostream &O) const;
 
@@ -175,6 +184,13 @@ public:
   ///
   unsigned getPrimitiveSize() const;
 
+  /// getForwaredType - Return the type that this type has been resolved to if
+  /// it has been resolved to anything.  This is used to implement the
+  /// union-find algorithm for type resolution.
+  const Type *getForwardedType() const {
+    if (!ForwardType) return 0;
+    return getForwardedTypeInternal();
+  }
 
   //===--------------------------------------------------------------------===//
   // Type Iteration support