* Add destroyConstant stuff to handle module local constants
* Add classof implementations for more ConstPoolVal subclasses * Pull null pointer implementation stuff out of ConstPoolPointer into a subclass ConstPoolPointerNull * Implement ConstPoolPointerReference correctly and completely llvm-svn: 732
This commit is contained in:
		
							parent
							
								
									0b6c38d98f
								
							
						
					
					
						commit
						b7420043d6
					
				| 
						 | 
					@ -24,6 +24,16 @@ protected:
 | 
				
			||||||
  inline ConstPoolVal(const Type *Ty) : User(Ty, Value::ConstantVal) {}
 | 
					  inline ConstPoolVal(const Type *Ty) : User(Ty, Value::ConstantVal) {}
 | 
				
			||||||
  ~ConstPoolVal() {}
 | 
					  ~ConstPoolVal() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // destroyConstant - Called if some element of this constant is no longer
 | 
				
			||||||
 | 
					  // valid.  At this point only other constants may be on the use_list for this
 | 
				
			||||||
 | 
					  // constant.  Any constants on our Use list must also be destroy'd.  The
 | 
				
			||||||
 | 
					  // implementation must be sure to remove the constant from the list of
 | 
				
			||||||
 | 
					  // available cached constants.  Implementations should call
 | 
				
			||||||
 | 
					  // destroyConstantImpl as the last thing they do, to destroy all users and
 | 
				
			||||||
 | 
					  // delete this.
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  virtual void destroyConstant() { assert(0 && "Not reached!"); }
 | 
				
			||||||
 | 
					  void destroyConstantImpl();
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  // Specialize setName to handle symbol table majik...
 | 
					  // Specialize setName to handle symbol table majik...
 | 
				
			||||||
  virtual void setName(const string &name, SymbolTable *ST = 0);
 | 
					  virtual void setName(const string &name, SymbolTable *ST = 0);
 | 
				
			||||||
| 
						 | 
					@ -131,6 +141,13 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static bool isValueValidForType(const Type *Ty, int64_t V);
 | 
					  static bool isValueValidForType(const Type *Ty, int64_t V);
 | 
				
			||||||
  inline int64_t getValue() const { return Val.Signed; }
 | 
					  inline int64_t getValue() const { return Val.Signed; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Methods for support type inquiry through isa, cast, and dyn_cast:
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolSInt *) { return true; }
 | 
				
			||||||
 | 
					  static bool classof(const ConstPoolVal *CPV);  // defined in CPV.cpp
 | 
				
			||||||
 | 
					  static inline bool classof(const Value *V) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//===---------------------------------------------------------------------------
 | 
					//===---------------------------------------------------------------------------
 | 
				
			||||||
| 
						 | 
					@ -148,6 +165,13 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static bool isValueValidForType(const Type *Ty, uint64_t V);
 | 
					  static bool isValueValidForType(const Type *Ty, uint64_t V);
 | 
				
			||||||
  inline uint64_t getValue() const { return Val.Unsigned; }
 | 
					  inline uint64_t getValue() const { return Val.Unsigned; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Methods for support type inquiry through isa, cast, and dyn_cast:
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolUInt *) { return true; }
 | 
				
			||||||
 | 
					  static bool classof(const ConstPoolVal *CPV);  // defined in CPV.cpp
 | 
				
			||||||
 | 
					  static inline bool classof(const Value *V) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,6 +191,13 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static bool isValueValidForType(const Type *Ty, double V);
 | 
					  static bool isValueValidForType(const Type *Ty, double V);
 | 
				
			||||||
  inline double getValue() const { return Val; }
 | 
					  inline double getValue() const { return Val; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Methods for support type inquiry through isa, cast, and dyn_cast:
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolFP *) { return true; }
 | 
				
			||||||
 | 
					  static bool classof(const ConstPoolVal *CPV);  // defined in CPV.cpp
 | 
				
			||||||
 | 
					  static inline bool classof(const Value *V) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -178,12 +209,21 @@ class ConstPoolArray : public ConstPoolVal {
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
  ConstPoolArray(const ArrayType *T, const vector<ConstPoolVal*> &Val);
 | 
					  ConstPoolArray(const ArrayType *T, const vector<ConstPoolVal*> &Val);
 | 
				
			||||||
  ~ConstPoolArray() {}
 | 
					  ~ConstPoolArray() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void destroyConstant();
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  static ConstPoolArray *get(const ArrayType *T, const vector<ConstPoolVal*> &);
 | 
					  static ConstPoolArray *get(const ArrayType *T, const vector<ConstPoolVal*> &);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  virtual string getStrValue() const;
 | 
					  virtual string getStrValue() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  inline const vector<Use> &getValues() const { return Operands; }
 | 
					  inline const vector<Use> &getValues() const { return Operands; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Methods for support type inquiry through isa, cast, and dyn_cast:
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolArray *) { return true; }
 | 
				
			||||||
 | 
					  static bool classof(const ConstPoolVal *CPV);  // defined in CPV.cpp
 | 
				
			||||||
 | 
					  static inline bool classof(const Value *V) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -195,6 +235,8 @@ class ConstPoolStruct : public ConstPoolVal {
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
  ConstPoolStruct(const StructType *T, const vector<ConstPoolVal*> &Val);
 | 
					  ConstPoolStruct(const StructType *T, const vector<ConstPoolVal*> &Val);
 | 
				
			||||||
  ~ConstPoolStruct() {}
 | 
					  ~ConstPoolStruct() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void destroyConstant();
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  static ConstPoolStruct *get(const StructType *T,
 | 
					  static ConstPoolStruct *get(const StructType *T,
 | 
				
			||||||
			      const vector<ConstPoolVal*> &V);
 | 
								      const vector<ConstPoolVal*> &V);
 | 
				
			||||||
| 
						 | 
					@ -202,6 +244,13 @@ public:
 | 
				
			||||||
  virtual string getStrValue() const;
 | 
					  virtual string getStrValue() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  inline const vector<Use> &getValues() const { return Operands; }
 | 
					  inline const vector<Use> &getValues() const { return Operands; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Methods for support type inquiry through isa, cast, and dyn_cast:
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolStruct *) { return true; }
 | 
				
			||||||
 | 
					  static bool classof(const ConstPoolVal *CPV);  // defined in CPV.cpp
 | 
				
			||||||
 | 
					  static inline bool classof(const Value *V) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//===---------------------------------------------------------------------------
 | 
					//===---------------------------------------------------------------------------
 | 
				
			||||||
| 
						 | 
					@ -211,15 +260,46 @@ public:
 | 
				
			||||||
// a more specific/useful instance, a subclass of ConstPoolPointer should be
 | 
					// a more specific/useful instance, a subclass of ConstPoolPointer should be
 | 
				
			||||||
// used.
 | 
					// used.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
					class ConstPoolPointerNull;
 | 
				
			||||||
class ConstPoolPointer : public ConstPoolVal {
 | 
					class ConstPoolPointer : public ConstPoolVal {
 | 
				
			||||||
  ConstPoolPointer(const ConstPoolPointer &);      // DO NOT IMPLEMENT
 | 
					  ConstPoolPointer(const ConstPoolPointer &);      // DO NOT IMPLEMENT
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
  ConstPoolPointer(const PointerType *T);
 | 
					  inline ConstPoolPointer(const PointerType *T) : ConstPoolVal((const Type*)T){}
 | 
				
			||||||
  ~ConstPoolPointer() {}
 | 
					  ~ConstPoolPointer() {}
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  static ConstPoolPointer *getNull(const PointerType *T);
 | 
					  virtual string getStrValue() const = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Methods for support type inquiry through isa, cast, and dyn_cast:
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolPointer *) { return true; }
 | 
				
			||||||
 | 
					  static bool classof(const ConstPoolVal *CPV);  // defined in CPV.cpp
 | 
				
			||||||
 | 
					  static inline bool classof(const Value *V) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ConstPoolPointerNull - a constant pointer value that points to null
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					class ConstPoolPointerNull : public ConstPoolPointer {
 | 
				
			||||||
 | 
					  ConstPoolPointerNull(const ConstPoolPointerNull &);      // DO NOT IMPLEMENT
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
 | 
					  inline ConstPoolPointerNull(const PointerType *T) : ConstPoolPointer(T) {}
 | 
				
			||||||
 | 
					  inline ~ConstPoolPointerNull() {}
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
  virtual string getStrValue() const;
 | 
					  virtual string getStrValue() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  static ConstPoolPointerNull *get(const PointerType *T);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Methods for support type inquiry through isa, cast, and dyn_cast:
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolPointerNull *) { return true; }
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolPointer *P) {
 | 
				
			||||||
 | 
					    return P->getNumOperands() == 0;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolVal *CPV) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolPointer>(CPV) && classof(cast<ConstPoolPointer>(CPV));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  static inline bool classof(const Value *V) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolPointer>(V) && classof(cast<ConstPoolPointer>(V));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -227,10 +307,14 @@ public:
 | 
				
			||||||
// point to a global value, which lies at a constant, fixed address.
 | 
					// point to a global value, which lies at a constant, fixed address.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
class ConstPoolPointerReference : public ConstPoolPointer {
 | 
					class ConstPoolPointerReference : public ConstPoolPointer {
 | 
				
			||||||
 | 
					  friend class Module;   // Modules maintain these references
 | 
				
			||||||
  ConstPoolPointerReference(const ConstPoolPointerReference &); // DNI!
 | 
					  ConstPoolPointerReference(const ConstPoolPointerReference &); // DNI!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
  ConstPoolPointerReference(GlobalValue *GV);
 | 
					  ConstPoolPointerReference(GlobalValue *GV);
 | 
				
			||||||
  ~ConstPoolPointerReference() {}
 | 
					  ~ConstPoolPointerReference() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void destroyConstant() { destroyConstantImpl(); }
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  static ConstPoolPointerReference *get(GlobalValue *GV);
 | 
					  static ConstPoolPointerReference *get(GlobalValue *GV);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -242,6 +326,23 @@ public:
 | 
				
			||||||
  GlobalValue *getValue() {
 | 
					  GlobalValue *getValue() {
 | 
				
			||||||
    return cast<GlobalValue>(Operands[0].get());
 | 
					    return cast<GlobalValue>(Operands[0].get());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Methods for support type inquiry through isa, cast, and dyn_cast:
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolPointerReference *) { return true; }
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolPointer *CPV) {
 | 
				
			||||||
 | 
					    return CPV->getNumOperands() == 1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  static inline bool classof(const ConstPoolVal *CPV) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolPointer>(CPV) && classof(cast<ConstPoolPointer>(CPV));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  static inline bool classof(const Value *V) {
 | 
				
			||||||
 | 
					    return isa<ConstPoolPointer>(V) && classof(cast<ConstPoolPointer>(V));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // WARNING: Only to be used by Bytecode & Assembly Parsers!  USER CODE SHOULD
 | 
				
			||||||
 | 
					  // NOT USE THIS!!
 | 
				
			||||||
 | 
					  void mutateReference(GlobalValue *NewGV);
 | 
				
			||||||
 | 
					  // END WARNING!!
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue