Convert ConstRules to use annotations to clean it up.
authorChris Lattner <sabre@nondot.org>
Sun, 9 Sep 2001 21:00:23 +0000 (21:00 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 9 Sep 2001 21:00:23 +0000 (21:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@514 91177308-0d34-0410-b5e6-96231b3b80d8

include/Support/Annotation.h
include/llvm/Annotation.h
include/llvm/ConstantHandling.h
include/llvm/Support/Annotation.h
include/llvm/Type.h
lib/VMCore/ConstantFold.h
lib/VMCore/ConstantFolding.h

index 43a379eee1d7ce013854fcbb87922395b8e6d582..99197326928794e51cbda8688d30a5ac5c9ea3ab 100644 (file)
@@ -161,12 +161,17 @@ public:
 // register an annotation handler 
 //
 struct AnnotationManager {
+  typedef Annotation *(*Factory)(AnnotationID, const Annotable *, void*);
+
   //===--------------------------------------------------------------------===//
   // Basic ID <-> Name map functionality
 
   static AnnotationID  getID  (const string &Name);  // Name -> ID
   static const string &getName(AnnotationID ID);     // ID -> Name
 
+  // getID - Name -> ID + registration of a factory function for demand driven
+  // annotation support.
+  static AnnotationID  getID  (const string &Name, Factory Fact, void *Data=0);
 
   //===--------------------------------------------------------------------===//
   // Annotation creation on demand support...
@@ -175,8 +180,7 @@ struct AnnotationManager {
   // function used to create an annotation on demand if it is needed by the 
   // Annotable::getOrCreateAnnotation method.
   //
-  static void registerAnnotationFactory(AnnotationID ID, 
-                    Annotation *(*Func)(AnnotationID, const Annotable *, void *),
+  static void registerAnnotationFactory(AnnotationID ID, Factory Func,
                                        void *ExtraData = 0);
 
   // createAnnotation - Create an annotation of the specified ID for the
index 43a379eee1d7ce013854fcbb87922395b8e6d582..99197326928794e51cbda8688d30a5ac5c9ea3ab 100644 (file)
@@ -161,12 +161,17 @@ public:
 // register an annotation handler 
 //
 struct AnnotationManager {
+  typedef Annotation *(*Factory)(AnnotationID, const Annotable *, void*);
+
   //===--------------------------------------------------------------------===//
   // Basic ID <-> Name map functionality
 
   static AnnotationID  getID  (const string &Name);  // Name -> ID
   static const string &getName(AnnotationID ID);     // ID -> Name
 
+  // getID - Name -> ID + registration of a factory function for demand driven
+  // annotation support.
+  static AnnotationID  getID  (const string &Name, Factory Fact, void *Data=0);
 
   //===--------------------------------------------------------------------===//
   // Annotation creation on demand support...
@@ -175,8 +180,7 @@ struct AnnotationManager {
   // function used to create an annotation on demand if it is needed by the 
   // Annotable::getOrCreateAnnotation method.
   //
-  static void registerAnnotationFactory(AnnotationID ID, 
-                    Annotation *(*Func)(AnnotationID, const Annotable *, void *),
+  static void registerAnnotationFactory(AnnotationID ID, Factory Func,
                                        void *ExtraData = 0);
 
   // createAnnotation - Create an annotation of the specified ID for the
index 453c3e88b186809c9d5b7d0da89d4fce58cedfd8..cbb9789fb0ea11a1819ae992b53e6eeeedde87c9 100644 (file)
@@ -58,10 +58,12 @@ inline ConstPoolBool *operator!=(const ConstPoolVal &V1,
 //  Implement all other operators indirectly through TypeRules system
 //===----------------------------------------------------------------------===//
 
-class ConstRules {
+class ConstRules : public Annotation {
 protected:
-  inline ConstRules() {}  // Can only be subclassed...
+  inline ConstRules() : Annotation(AID) {}  // Can only be subclassed...
 public:
+  static AnnotationID AID;    // AnnotationID for this class
+
   // Unary Operators...
   virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0;
 
@@ -110,12 +112,11 @@ public:
   // we just want to make sure to hit the cache instead of doing it indirectly,
   //  if possible...
   //
-  static inline const ConstRules *get(const ConstPoolVal &V) {
-    const ConstRules *Result = V.getType()->getConstRules();
-    return Result ? Result : find(V.getType());
+  static inline ConstRules *get(const ConstPoolVal &V) {
+    return (ConstRules*)V.getType()->getOrCreateAnnotation(AID);
   }
 private :
-  static const ConstRules *find(const Type *Ty);
+  static Annotation *find(AnnotationID AID, const Annotable *Ty, void *);
 
   ConstRules(const ConstRules &);             // Do not implement
   ConstRules &operator=(const ConstRules &);  // Do not implement
index 43a379eee1d7ce013854fcbb87922395b8e6d582..99197326928794e51cbda8688d30a5ac5c9ea3ab 100644 (file)
@@ -161,12 +161,17 @@ public:
 // register an annotation handler 
 //
 struct AnnotationManager {
+  typedef Annotation *(*Factory)(AnnotationID, const Annotable *, void*);
+
   //===--------------------------------------------------------------------===//
   // Basic ID <-> Name map functionality
 
   static AnnotationID  getID  (const string &Name);  // Name -> ID
   static const string &getName(AnnotationID ID);     // ID -> Name
 
+  // getID - Name -> ID + registration of a factory function for demand driven
+  // annotation support.
+  static AnnotationID  getID  (const string &Name, Factory Fact, void *Data=0);
 
   //===--------------------------------------------------------------------===//
   // Annotation creation on demand support...
@@ -175,8 +180,7 @@ struct AnnotationManager {
   // function used to create an annotation on demand if it is needed by the 
   // Annotable::getOrCreateAnnotation method.
   //
-  static void registerAnnotationFactory(AnnotationID ID, 
-                    Annotation *(*Func)(AnnotationID, const Annotable *, void *),
+  static void registerAnnotationFactory(AnnotationID ID, Factory Func,
                                        void *ExtraData = 0);
 
   // createAnnotation - Create an annotation of the specified ID for the
index 0f8e6a115e701a02891a827526b3d9df381c01e8..d5f57cba04bdd6fc1edfb0d7179efc109a6752ef 100644 (file)
@@ -28,9 +28,6 @@
 
 #include "llvm/Value.h"
 
-namespace opt {
-  class ConstRules;
-}
 class DerivedType;
 class MethodType;
 class ArrayType;
@@ -78,9 +75,6 @@ private:
   bool        Abstract;  // True if type contains an OpaqueType
   bool        Recursive; // True if the type is recursive
 
-  // ConstRulesImpl - See Opt/ConstantHandling.h for more info
-  mutable const opt::ConstRules *ConstRulesImpl;
-
 protected:
   // ctor is protected, so only subclasses can create Type objects...
   Type(const string &Name, PrimitiveID id);
@@ -175,12 +169,6 @@ public:
   static const Type *getPrimitiveType(PrimitiveID IDNumber);
   static const Type *getUniqueIDType(unsigned UID);
 
-  // Methods for dealing with constants uniformly.  See Opt/ConstantHandling.h
-  // for more info on this...
-  //
-  inline const opt::ConstRules *getConstRules() const { return ConstRulesImpl; }
-  inline void setConstRules(const opt::ConstRules *R) const { ConstRulesImpl=R;}
-
   //===--------------------------------------------------------------------===//
   // These are the builtin types that are always available...
   //
index 453c3e88b186809c9d5b7d0da89d4fce58cedfd8..cbb9789fb0ea11a1819ae992b53e6eeeedde87c9 100644 (file)
@@ -58,10 +58,12 @@ inline ConstPoolBool *operator!=(const ConstPoolVal &V1,
 //  Implement all other operators indirectly through TypeRules system
 //===----------------------------------------------------------------------===//
 
-class ConstRules {
+class ConstRules : public Annotation {
 protected:
-  inline ConstRules() {}  // Can only be subclassed...
+  inline ConstRules() : Annotation(AID) {}  // Can only be subclassed...
 public:
+  static AnnotationID AID;    // AnnotationID for this class
+
   // Unary Operators...
   virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0;
 
@@ -110,12 +112,11 @@ public:
   // we just want to make sure to hit the cache instead of doing it indirectly,
   //  if possible...
   //
-  static inline const ConstRules *get(const ConstPoolVal &V) {
-    const ConstRules *Result = V.getType()->getConstRules();
-    return Result ? Result : find(V.getType());
+  static inline ConstRules *get(const ConstPoolVal &V) {
+    return (ConstRules*)V.getType()->getOrCreateAnnotation(AID);
   }
 private :
-  static const ConstRules *find(const Type *Ty);
+  static Annotation *find(AnnotationID AID, const Annotable *Ty, void *);
 
   ConstRules(const ConstRules &);             // Do not implement
   ConstRules &operator=(const ConstRules &);  // Do not implement
index 453c3e88b186809c9d5b7d0da89d4fce58cedfd8..cbb9789fb0ea11a1819ae992b53e6eeeedde87c9 100644 (file)
@@ -58,10 +58,12 @@ inline ConstPoolBool *operator!=(const ConstPoolVal &V1,
 //  Implement all other operators indirectly through TypeRules system
 //===----------------------------------------------------------------------===//
 
-class ConstRules {
+class ConstRules : public Annotation {
 protected:
-  inline ConstRules() {}  // Can only be subclassed...
+  inline ConstRules() : Annotation(AID) {}  // Can only be subclassed...
 public:
+  static AnnotationID AID;    // AnnotationID for this class
+
   // Unary Operators...
   virtual ConstPoolVal *not(const ConstPoolVal *V) const = 0;
 
@@ -110,12 +112,11 @@ public:
   // we just want to make sure to hit the cache instead of doing it indirectly,
   //  if possible...
   //
-  static inline const ConstRules *get(const ConstPoolVal &V) {
-    const ConstRules *Result = V.getType()->getConstRules();
-    return Result ? Result : find(V.getType());
+  static inline ConstRules *get(const ConstPoolVal &V) {
+    return (ConstRules*)V.getType()->getOrCreateAnnotation(AID);
   }
 private :
-  static const ConstRules *find(const Type *Ty);
+  static Annotation *find(AnnotationID AID, const Annotable *Ty, void *);
 
   ConstRules(const ConstRules &);             // Do not implement
   ConstRules &operator=(const ConstRules &);  // Do not implement