Remove trailing whitespace
[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   Constant(const Type *Ty, ValueTy vty, Use *Ops, unsigned NumOps,
24            const std::string& Name = "")
25     : User(Ty, vty, Ops, NumOps, Name) {}
26
27   void destroyConstantImpl();
28 public:
29   /// Static constructor to get a '0' constant of arbitrary type...
30   ///
31   static Constant *getNullValue(const Type *Ty);
32
33   /// isNullValue - Return true if this is the value that would be returned by
34   /// getNullValue.
35   virtual bool isNullValue() const = 0;
36
37   virtual void print(std::ostream &O) const;
38
39   // Specialize get/setOperand for Constant's as their operands are always
40   // constants as well.
41   Constant *getOperand(unsigned i) {
42     return static_cast<Constant*>(User::getOperand(i));
43   }
44   const Constant *getOperand(unsigned i) const {
45     return static_cast<const Constant*>(User::getOperand(i));
46   }
47   void setOperand(unsigned i, Constant *C) {
48     User::setOperand(i, C);
49   }
50
51   /// destroyConstant - Called if some element of this constant is no longer
52   /// valid.  At this point only other constants may be on the use_list for this
53   /// constant.  Any constants on our Use list must also be destroy'd.  The
54   /// implementation must be sure to remove the constant from the list of
55   /// available cached constants.  Implementations should call
56   /// destroyConstantImpl as the last thing they do, to destroy all users and
57   /// delete this.
58   virtual void destroyConstant() { assert(0 && "Not reached!"); }
59
60   //// Methods for support type inquiry through isa, cast, and dyn_cast:
61   static inline bool classof(const Constant *) { return true; }
62   static inline bool classof(const GlobalValue *) { return true; }
63   static inline bool classof(const Value *V) {
64     return V->getValueType() == Value::SimpleConstantVal ||
65            V->getValueType() == Value::ConstantExprVal ||
66            V->getValueType() == Value::ConstantAggregateZeroVal ||
67            V->getValueType() == Value::FunctionVal ||
68            V->getValueType() == Value::GlobalVariableVal ||
69            V->getValueType() == Value::UndefValueVal;
70   }
71
72   /// replaceUsesOfWithOnConstant - This method is a special form of
73   /// User::replaceUsesOfWith (which does not work on constants) that does work
74   /// on constants.  Basically this method goes through the trouble of building
75   /// a new constant that is equivalent to the current one, with all uses of
76   /// From replaced with uses of To.  After this construction is completed, all
77   /// of the users of 'this' are replaced to use the new constant, and then
78   /// 'this' is deleted.  In general, you should not call this method, instead,
79   /// use Value::replaceAllUsesWith, which automatically dispatches to this
80   /// method as needed.
81   ///
82   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
83                                            bool DisableChecking = false) {
84     // Provide a default implementation for constants (like integers) that
85     // cannot use any other values.  This cannot be called at runtime, but needs
86     // to be here to avoid link errors.
87     assert(getNumOperands() == 0 && "replaceUsesOfWithOnConstant must be "
88            "implemented for all constants that have operands!");
89     assert(0 && "Constants that do not have operands cannot be using 'From'!");
90   }
91
92   /// clearAllValueMaps - This method frees all internal memory used by the
93   /// constant subsystem, which can be used in environments where this memory
94   /// is otherwise reported as a leak.
95   static void clearAllValueMaps();
96 };
97
98 } // End llvm namespace
99
100 #endif