Move isCriticalEdge & SplitCritical edge out of this file, which is only
[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 class Constant : public User {
20 protected:
21   inline Constant(const Type *Ty) : User(Ty, Value::ConstantVal) {}
22   ~Constant() {}
23
24   void destroyConstantImpl();
25 public:
26   // setName - Specialize setName to handle symbol table majik...
27   virtual void setName(const std::string &name, SymbolTable *ST = 0);
28
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   /// isConstantExpr - Return true if this is a ConstantExpr
40   ///
41   virtual bool isConstantExpr() const { return false; }
42
43
44   /// destroyConstant - Called if some element of this constant is no longer
45   /// valid.  At this point only other constants may be on the use_list for this
46   /// constant.  Any constants on our Use list must also be destroy'd.  The
47   /// implementation must be sure to remove the constant from the list of
48   /// available cached constants.  Implementations should call
49   /// destroyConstantImpl as the last thing they do, to destroy all users and
50   /// delete this.
51   ///
52   /// Note that this call is only valid on non-primitive constants: You cannot
53   /// destroy an integer constant for example.  This API is used to delete
54   /// constants that have ConstantPointerRef's embeded in them when the module
55   /// is deleted, and it is used by GlobalDCE to remove ConstantPointerRefs that
56   /// are unneeded, allowing globals to be DCE'd.
57   ///
58   virtual void destroyConstant() { assert(0 && "Not reached!"); }
59
60   
61   //// Methods for support type inquiry through isa, cast, and dyn_cast:
62   static inline bool classof(const Constant *) { return true; }
63   static inline bool classof(const Value *V) {
64     return V->getValueType() == Value::ConstantVal;
65   }
66
67   /// replaceUsesOfWithOnConstant - This method is a special form of
68   /// User::replaceUsesOfWith (which does not work on constants) that does work
69   /// on constants.  Basically this method goes through the trouble of building
70   /// a new constant that is equivalent to the current one, with all uses of
71   /// From replaced with uses of To.  After this construction is completed, all
72   /// of the users of 'this' are replaced to use the new constant, and then
73   /// 'this' is deleted.  In general, you should not call this method, instead,
74   /// use Value::replaceAllUsesWith, which automatically dispatches to this
75   /// method as needed.
76   ///
77   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
78                                            bool DisableChecking = false) {
79     // Provide a default implementation for constants (like integers) that
80     // cannot use any other values.  This cannot be called at runtime, but needs
81     // to be here to avoid link errors.
82     assert(getNumOperands() == 0 && "replaceUsesOfWithOnConstant must be "
83            "implemented for all constants that have operands!");
84     assert(0 && "Constants that do not have operands cannot be using 'From'!");
85   }
86
87   // WARNING: Only to be used by Bytecode & Assembly Parsers!  USER CODE SHOULD
88   // NOT USE THIS!!
89   // Returns the number of uses of OldV that were replaced.
90   unsigned mutateReferences(Value* OldV, Value *NewV);
91   // END WARNING!!
92 };
93
94 #endif