[llvm-commits] CVS: llvm/include/llvm/AbstractTypeUser.h DerivedTypes.h SymbolTable.h

Chris Lattner lattner at cs.uiuc.edu
Fri Oct 3 13:47:02 PDT 2003


Changes in directory llvm/include/llvm:

AbstractTypeUser.h updated: 1.14 -> 1.15
DerivedTypes.h updated: 1.41 -> 1.42
SymbolTable.h updated: 1.24 -> 1.25

---
Log message:

This checkin basically amounts to a complete rewrite of the type-resolution
machinery.  This dramatically simplifies how things works, removes irritating 
little corner cases, and overall improves speed and reliability.

Highlights of this change are:

1. The exponential algorithm built into the code is now gone.  For example
   the time to disassemble one bytecode file from the mesa benchmark went
   from taking 12.5s to taking 0.16s.
2. The linker bugs should be dramatically reduced.  The one remaining bug
   has to do with constant handling, which I actually introduced in
   "union-find" checkins.
3. The code is much easier to follow, as a result of fewer special cases.
   It's probably also smaller.  yaay.



---
Diffs of the changes:

Index: llvm/include/llvm/AbstractTypeUser.h
diff -u llvm/include/llvm/AbstractTypeUser.h:1.14 llvm/include/llvm/AbstractTypeUser.h:1.15
--- llvm/include/llvm/AbstractTypeUser.h:1.14	Thu Oct  2 18:35:45 2003
+++ llvm/include/llvm/AbstractTypeUser.h	Fri Oct  3 13:46:21 2003
@@ -38,24 +38,20 @@
   virtual ~AbstractTypeUser() {}                        // Derive from me
 public:
 
-  // refineAbstractType - The callback method invoked when an abstract type
-  // has been found to be more concrete.  A class must override this method to
-  // update its internal state to reference NewType instead of OldType.  Soon
-  // after this method is invoked, OldType shall be deleted, so referencing it
-  // is quite unwise.
-  //
-  // Another case that is important to consider is when a type is refined, but
-  // stays in the same place in memory.  In this case OldTy will equal NewTy.
-  // This callback just notifies ATU's that the underlying structure of the type
-  // has changed... but any previously used properties are still valid.
-  //
-  // Note that it is possible to refine a type with parameters OldTy==NewTy, and
-  // OldTy is no longer abstract.  In this case, abstract type users should
-  // release their hold on a type, because it went from being abstract to
-  // concrete.
-  //
+  /// refineAbstractType - The callback method invoked when an abstract type is
+  /// resolved to another type.  An object must override this method to update
+  /// its internal state to reference NewType instead of OldType.
+  ///
   virtual void refineAbstractType(const DerivedType *OldTy,
 				  const Type *NewTy) = 0;
+
+  /// The other case which AbstractTypeUsers must be aware of is when a type
+  /// makes the transition from being abstract (where it has clients on it's
+  /// AbstractTypeUsers list) to concrete (where it does not).  This method
+  /// notifies ATU's when this occurs for a type.
+  ///
+  virtual void typeBecameConcrete(const DerivedType *AbsTy) = 0;
+
   // for debugging...
   virtual void dump() const = 0;
 };


Index: llvm/include/llvm/DerivedTypes.h
diff -u llvm/include/llvm/DerivedTypes.h:1.41 llvm/include/llvm/DerivedTypes.h:1.42
--- llvm/include/llvm/DerivedTypes.h:1.41	Thu Oct  2 18:35:45 2003
+++ llvm/include/llvm/DerivedTypes.h	Fri Oct  3 13:46:21 2003
@@ -26,9 +26,6 @@
   ///
   mutable unsigned RefCount;
   
-  // isRefining - Used for recursive types
-  char isRefining;
-
   // AbstractTypeUsers - Implement a list of the users that need to be notified
   // if I am a type, and I get resolved into a more concrete type.
   //
@@ -36,17 +33,17 @@
   mutable std::vector<AbstractTypeUser *> AbstractTypeUsers;
 
 protected:
-  DerivedType(PrimitiveID id) : Type("", id), RefCount(0), isRefining(0) {
+  DerivedType(PrimitiveID id) : Type("", id), RefCount(0) {
   }
   ~DerivedType() {
     assert(AbstractTypeUsers.empty());
   }
 
-  // typeIsRefined - Notify AbstractTypeUsers of this type that the current type
-  // has been refined a bit.  The pointer is still valid and still should be
-  // used, but the subtypes have changed.
-  //
-  void typeIsRefined();
+  /// notifyUsesThatTypeBecameConcrete - Notify AbstractTypeUsers of this type
+  /// that the current type has transitioned from being abstract to being
+  /// concrete.
+  ///
+  void notifyUsesThatTypeBecameConcrete();
 
   // dropAllTypeUses - When this (abstract) type is resolved to be equal to
   // another (more concrete) type, we must eliminate all references to other
@@ -146,6 +143,11 @@
   virtual void dropAllTypeUses(bool inMap);
 
 public:
+  /// FunctionType::get - This static method is the primary way of constructing
+  /// a FunctionType
+  static FunctionType *get(const Type *Result,
+                           const std::vector<const Type*> &Params,
+                           bool isVarArg);
 
   inline bool isVarArg() const { return isVarArgs; }
   inline const Type *getReturnType() const { return ResultType; }
@@ -166,16 +168,10 @@
   }
   virtual unsigned getNumContainedTypes() const { return ParamTys.size()+1; }
 
-  // refineAbstractType - Called when a contained type is found to be more
-  // concrete - this could potentially change us from an abstract type to a
-  // concrete type.
-  //
+  // Implement the AbstractTypeUser interface.
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
-
-  static FunctionType *get(const Type *Result,
-                           const std::vector<const Type*> &Params,
-                           bool isVarArg);
-
+  virtual void typeBecameConcrete(const DerivedType *AbsTy);
+  
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const FunctionType *T) { return true; }
   static inline bool classof(const Type *T) {
@@ -244,6 +240,10 @@
   virtual void dropAllTypeUses(bool inMap);
   
 public:
+  /// StructType::get - This static method is the primary way to create a
+  /// StructType.
+  static StructType *get(const std::vector<const Type*> &Params);
+
   inline const ElementTypes &getElementTypes() const { return ETypes; }
 
   virtual const Type *getContainedType(unsigned i) const { 
@@ -262,13 +262,9 @@
   //
   virtual const Type *getIndexType() const { return Type::UByteTy; }
 
-  // refineAbstractType - Called when a contained type is found to be more
-  // concrete - this could potentially change us from an abstract type to a
-  // concrete type.
-  //
+  // Implement the AbstractTypeUser interface.
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
-
-  static StructType *get(const std::vector<const Type*> &Params);
+  virtual void typeBecameConcrete(const DerivedType *AbsTy);
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const StructType *T) { return true; }
@@ -353,15 +349,15 @@
   virtual void dropAllTypeUses(bool inMap);
 
 public:
+  /// ArrayType::get - This static method is the primary way to construct an
+  /// ArrayType
+  static ArrayType *get(const Type *ElementType, unsigned NumElements);
+
   inline unsigned    getNumElements() const { return NumElements; }
 
-  // refineAbstractType - Called when a contained type is found to be more
-  // concrete - this could potentially change us from an abstract type to a
-  // concrete type.
-  //
+  // Implement the AbstractTypeUser interface.
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
-
-  static ArrayType *get(const Type *ElementType, unsigned NumElements);
+  virtual void typeBecameConcrete(const DerivedType *AbsTy);
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ArrayType *T) { return true; }
@@ -393,16 +389,14 @@
   // type from the internal tables of available types.
   virtual void dropAllTypeUses(bool inMap);
 public:
-  // PointerType::get - Named constructor for pointer types...
+  /// PointerType::get - This is the only way to construct a new pointer type.
   static PointerType *get(const Type *ElementType);
 
-  // refineAbstractType - Called when a contained type is found to be more
-  // concrete - this could potentially change us from an abstract type to a
-  // concrete type.
-  //
+  // Implement the AbstractTypeUser interface.
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
+  virtual void typeBecameConcrete(const DerivedType *AbsTy);
 
-  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  // Implement support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const PointerType *T) { return true; }
   static inline bool classof(const Type *T) {
     return T->getPrimitiveID() == PointerTyID;
@@ -430,23 +424,20 @@
   virtual void dropAllTypeUses(bool inMap) {}  // No type uses
 
 public:
-
-  // get - Static factory method for the OpaqueType class...
+  // OpaqueType::get - Static factory method for the OpaqueType class...
   static OpaqueType *get() {
     return new OpaqueType();           // All opaque types are distinct
   }
 
-  // refineAbstractType - Called when a contained type is found to be more
-  // concrete - this could potentially change us from an abstract type to a
-  // concrete type.
-  //
+  // Implement the AbstractTypeUser interface.
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
-    // This class never uses other types!
-    abort();
+    abort();   // FIXME: this is not really an AbstractTypeUser!
+  }
+  virtual void typeBecameConcrete(const DerivedType *AbsTy) {
+    abort();   // FIXME: this is not really an AbstractTypeUser!
   }
 
-
-  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  // Implement support for type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const OpaqueType *T) { return true; }
   static inline bool classof(const Type *T) {
     return T->getPrimitiveID() == OpaqueTyID;


Index: llvm/include/llvm/SymbolTable.h
diff -u llvm/include/llvm/SymbolTable.h:1.24 llvm/include/llvm/SymbolTable.h:1.25
--- llvm/include/llvm/SymbolTable.h:1.24	Tue Sep 30 13:37:37 2003
+++ llvm/include/llvm/SymbolTable.h	Fri Oct  3 13:46:21 2003
@@ -118,6 +118,7 @@
 
   // This function is called when one of the types in the type plane are refined
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
+  virtual void typeBecameConcrete(const DerivedType *AbsTy);
 };
 
 #endif





More information about the llvm-commits mailing list