708573874d61d1062692e17f19fb6a6ecd7bcb83
[oota-llvm.git] / include / llvm / Constant.h
1 //===-- llvm/Constant.h - Constant class definition --------------*- C++ -*--=//
2 //
3 // This file contains the declaration of the Constant class.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_CONSTANT_H
8 #define LLVM_CONSTANT_H
9
10 #include "llvm/User.h"
11
12 class Constant : public User {
13 protected:
14   inline Constant(const Type *Ty) : User(Ty, Value::ConstantVal) {}
15   ~Constant() {}
16
17   void destroyConstantImpl();
18 public:
19   /// setName - Specialize setName to handle symbol table majik...
20   virtual void setName(const std::string &name, SymbolTable *ST = 0);
21
22   /// Static constructor to get a '0' constant of arbitrary type...
23   static Constant *getNullValue(const Type *Ty);
24
25   /// isNullValue - Return true if this is the value that would be returned by
26   /// getNullValue.
27   virtual bool isNullValue() const = 0;
28
29   virtual void print(std::ostream &O) const;
30
31   /// isConstantExpr - Return true if this is a ConstantExpr
32   virtual bool isConstantExpr() const { return false; }
33
34
35   /// destroyConstant - Called if some element of this constant is no longer
36   /// valid.  At this point only other constants may be on the use_list for this
37   /// constant.  Any constants on our Use list must also be destroy'd.  The
38   /// implementation must be sure to remove the constant from the list of
39   /// available cached constants.  Implementations should call
40   /// destroyConstantImpl as the last thing they do, to destroy all users and
41   /// delete this.
42   ///
43   /// Note that this call is only valid on non-primitive constants: You cannot
44   /// destroy an integer constant for example.  This API is used to delete
45   /// constants that have ConstantPointerRef's embeded in them when the module
46   /// is deleted, and it is used by GlobalDCE to remove ConstantPointerRefs that
47   /// are unneeded, allowing globals to be DCE'd.
48   ///
49   virtual void destroyConstant() { assert(0 && "Not reached!"); }
50
51   
52   /// Methods for support type inquiry through isa, cast, and dyn_cast:
53   static inline bool classof(const Constant *) { return true; }
54   static inline bool classof(const Value *V) {
55     return V->getValueType() == Value::ConstantVal;
56   }
57
58   // WARNING: Only to be used by Bytecode & Assembly Parsers!  USER CODE SHOULD
59   // NOT USE THIS!!
60   // Returns the number of uses of OldV that were replaced.
61   virtual unsigned mutateReferences(Value* OldV, Value *NewV) { return 0; }
62   // END WARNING!!
63 };
64
65 #endif