cleanup some long-dead code
[oota-llvm.git] / include / llvm / Constant.h
1 //===-- llvm/Constant.h - Constant class definition -------------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the Constant class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CONSTANT_H
15 #define LLVM_CONSTANT_H
16
17 #include "llvm/User.h"
18
19 namespace llvm {
20
21 class Constant : public User {
22 protected:
23   inline Constant(const Type *Ty) : User(Ty, Value::ConstantVal) {}
24   ~Constant() {}
25
26   void destroyConstantImpl();
27 public:
28   // setName - Specialize setName to handle symbol table majik...
29   virtual void setName(const std::string &name, SymbolTable *ST = 0);
30
31   /// Static constructor to get a '0' constant of arbitrary type...
32   ///
33   static Constant *getNullValue(const Type *Ty);
34
35   /// isNullValue - Return true if this is the value that would be returned by
36   /// getNullValue.
37   virtual bool isNullValue() const = 0;
38
39   virtual void print(std::ostream &O) const;
40
41   /// isConstantExpr - Return true if this is a ConstantExpr
42   ///
43   virtual bool isConstantExpr() const { return false; }
44
45
46   /// destroyConstant - Called if some element of this constant is no longer
47   /// valid.  At this point only other constants may be on the use_list for this
48   /// constant.  Any constants on our Use list must also be destroy'd.  The
49   /// implementation must be sure to remove the constant from the list of
50   /// available cached constants.  Implementations should call
51   /// destroyConstantImpl as the last thing they do, to destroy all users and
52   /// delete this.
53   ///
54   /// Note that this call is only valid on non-primitive constants: You cannot
55   /// destroy an integer constant for example.  This API is used to delete
56   /// constants that have ConstantPointerRef's embeded in them when the module
57   /// is deleted, and it is used by GlobalDCE to remove ConstantPointerRefs that
58   /// are unneeded, allowing globals to be DCE'd.
59   ///
60   virtual void destroyConstant() { assert(0 && "Not reached!"); }
61
62   
63   //// Methods for support type inquiry through isa, cast, and dyn_cast:
64   static inline bool classof(const Constant *) { return true; }
65   static inline bool classof(const Value *V) {
66     return V->getValueType() == Value::ConstantVal;
67   }
68
69   /// replaceUsesOfWithOnConstant - This method is a special form of
70   /// User::replaceUsesOfWith (which does not work on constants) that does work
71   /// on constants.  Basically this method goes through the trouble of building
72   /// a new constant that is equivalent to the current one, with all uses of
73   /// From replaced with uses of To.  After this construction is completed, all
74   /// of the users of 'this' are replaced to use the new constant, and then
75   /// 'this' is deleted.  In general, you should not call this method, instead,
76   /// use Value::replaceAllUsesWith, which automatically dispatches to this
77   /// method as needed.
78   ///
79   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
80                                            bool DisableChecking = false) {
81     // Provide a default implementation for constants (like integers) that
82     // cannot use any other values.  This cannot be called at runtime, but needs
83     // to be here to avoid link errors.
84     assert(getNumOperands() == 0 && "replaceUsesOfWithOnConstant must be "
85            "implemented for all constants that have operands!");
86     assert(0 && "Constants that do not have operands cannot be using 'From'!");
87   }
88 };
89
90 } // End llvm namespace
91
92 #endif