LLVM API Documentation
00001 //===-- llvm/Constant.h - Constant class definition -------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the declaration of the Constant class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CONSTANT_H 00015 #define LLVM_CONSTANT_H 00016 00017 #include "llvm/User.h" 00018 00019 namespace llvm { 00020 00021 class Constant : public User { 00022 protected: 00023 inline Constant(const Type *Ty, ValueTy vty = Value::SimpleConstantVal, 00024 const std::string& Name = "") 00025 : User(Ty, vty, Name) {} 00026 ~Constant() {} 00027 00028 void destroyConstantImpl(); 00029 public: 00030 // setName - Specialize setName to handle symbol table majik... 00031 virtual void setName(const std::string &name, SymbolTable *ST = 0); 00032 00033 /// Static constructor to get a '0' constant of arbitrary type... 00034 /// 00035 static Constant *getNullValue(const Type *Ty); 00036 00037 /// isNullValue - Return true if this is the value that would be returned by 00038 /// getNullValue. 00039 virtual bool isNullValue() const = 0; 00040 00041 virtual void print(std::ostream &O) const; 00042 00043 // Specialize get/setOperand for Constant's as their operands are always 00044 // constants as well. 00045 Constant *getOperand(unsigned i) { 00046 return static_cast<Constant*>(User::getOperand(i)); 00047 } 00048 const Constant *getOperand(unsigned i) const { 00049 return static_cast<const Constant*>(User::getOperand(i)); 00050 } 00051 void setOperand(unsigned i, Constant *C) { 00052 User::setOperand(i, C); 00053 } 00054 00055 /// destroyConstant - Called if some element of this constant is no longer 00056 /// valid. At this point only other constants may be on the use_list for this 00057 /// constant. Any constants on our Use list must also be destroy'd. The 00058 /// implementation must be sure to remove the constant from the list of 00059 /// available cached constants. Implementations should call 00060 /// destroyConstantImpl as the last thing they do, to destroy all users and 00061 /// delete this. 00062 virtual void destroyConstant() { assert(0 && "Not reached!"); } 00063 00064 //// Methods for support type inquiry through isa, cast, and dyn_cast: 00065 static inline bool classof(const Constant *) { return true; } 00066 static inline bool classof(const GlobalValue *) { return true; } 00067 static inline bool classof(const Value *V) { 00068 return V->getValueType() == Value::SimpleConstantVal || 00069 V->getValueType() == Value::ConstantExprVal || 00070 V->getValueType() == Value::ConstantAggregateZeroVal || 00071 V->getValueType() == Value::FunctionVal || 00072 V->getValueType() == Value::GlobalVariableVal || 00073 V->getValueType() == Value::UndefValueVal; 00074 } 00075 00076 /// replaceUsesOfWithOnConstant - This method is a special form of 00077 /// User::replaceUsesOfWith (which does not work on constants) that does work 00078 /// on constants. Basically this method goes through the trouble of building 00079 /// a new constant that is equivalent to the current one, with all uses of 00080 /// From replaced with uses of To. After this construction is completed, all 00081 /// of the users of 'this' are replaced to use the new constant, and then 00082 /// 'this' is deleted. In general, you should not call this method, instead, 00083 /// use Value::replaceAllUsesWith, which automatically dispatches to this 00084 /// method as needed. 00085 /// 00086 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, 00087 bool DisableChecking = false) { 00088 // Provide a default implementation for constants (like integers) that 00089 // cannot use any other values. This cannot be called at runtime, but needs 00090 // to be here to avoid link errors. 00091 assert(getNumOperands() == 0 && "replaceUsesOfWithOnConstant must be " 00092 "implemented for all constants that have operands!"); 00093 assert(0 && "Constants that do not have operands cannot be using 'From'!"); 00094 } 00095 00096 /// clearAllValueMaps - This method frees all internal memory used by the 00097 /// constant subsystem, which can be used in environments where this memory 00098 /// is otherwise reported as a leak. 00099 static void clearAllValueMaps(); 00100 }; 00101 00102 } // End llvm namespace 00103 00104 #endif