Eliminate the explicit opcode field in ConstantExpr, using the SubclassData
[oota-llvm.git] / include / llvm / Constants.h
1 //===-- llvm/Constants.h - Constant class subclass definitions --*- 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 declarations for the subclasses of Constant, which
11 // represent the different flavors of constant values that live in LLVM.  Note
12 // that Constants are immutable (once created they never change) and are fully
13 // shared by structural equivalence.  This means that two structurally
14 // equivalent constants will always have the same address.  Constant's are
15 // created on demand as needed and never deleted: thus clients don't have to
16 // worry about the lifetime of the objects.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_CONSTANTS_H
21 #define LLVM_CONSTANTS_H
22
23 #include "llvm/Constant.h"
24 #include "llvm/Type.h"
25 #include "llvm/Support/DataTypes.h"
26
27 namespace llvm {
28
29 class ArrayType;
30 class StructType;
31 class PointerType;
32 class PackedType;
33
34 template<class ConstantClass, class TypeClass, class ValType>
35 struct ConstantCreator;
36 template<class ConstantClass, class TypeClass>
37 struct ConvertConstantType;
38
39 //===----------------------------------------------------------------------===//
40 /// ConstantIntegral - Shared superclass of boolean and integer constants.
41 ///
42 /// This class just defines some common interfaces to be implemented.
43 ///
44 class ConstantIntegral : public Constant {
45 protected:
46   union {
47     int64_t  Signed;
48     uint64_t Unsigned;
49   } Val;
50   ConstantIntegral(const Type *Ty, uint64_t V);
51 public:
52
53   /// getRawValue - return the underlying value of this constant as a 64-bit
54   /// unsigned integer value.
55   ///
56   inline uint64_t getRawValue() const { return Val.Unsigned; }
57
58   /// isNullValue - Return true if this is the value that would be returned by
59   /// getNullValue.
60   ///
61   virtual bool isNullValue() const = 0;
62
63   /// isMaxValue - Return true if this is the largest value that may be
64   /// represented by this type.
65   ///
66   virtual bool isMaxValue() const = 0;
67
68   /// isMinValue - Return true if this is the smallest value that may be
69   /// represented by this type.
70   ///
71   virtual bool isMinValue() const = 0;
72
73   /// isAllOnesValue - Return true if every bit in this constant is set to true.
74   ///
75   virtual bool isAllOnesValue() const = 0;
76
77   /// Static constructor to get the maximum/minimum/allones constant of
78   /// specified (integral) type...
79   ///
80   static ConstantIntegral *getMaxValue(const Type *Ty);
81   static ConstantIntegral *getMinValue(const Type *Ty);
82   static ConstantIntegral *getAllOnesValue(const Type *Ty);
83
84   /// Methods for support type inquiry through isa, cast, and dyn_cast:
85   static inline bool classof(const ConstantIntegral *) { return true; }
86   static bool classof(const Value *V) {
87     return V->getValueType() == SimpleConstantVal &&
88            V->getType()->isIntegral();
89   }
90 };
91
92
93 //===----------------------------------------------------------------------===//
94 /// ConstantBool - Boolean Values
95 ///
96 class ConstantBool : public ConstantIntegral {
97   ConstantBool(bool V);
98 public:
99   static ConstantBool *True, *False;  // The True & False values
100
101   /// get() - Static factory methods - Return objects of the specified value
102   static ConstantBool *get(bool Value) { return Value ? True : False; }
103   static ConstantBool *get(const Type *Ty, bool Value) { return get(Value); }
104
105   /// inverted - Return the opposite value of the current value.
106   inline ConstantBool *inverted() const { return (this==True) ? False : True; }
107
108   /// getValue - return the boolean value of this constant.
109   ///
110   inline bool getValue() const { return static_cast<bool>(getRawValue()); }
111
112   /// isNullValue - Return true if this is the value that would be returned by
113   /// getNullValue.
114   ///
115   virtual bool isNullValue() const { return this == False; }
116   virtual bool isMaxValue() const { return this == True; }
117   virtual bool isMinValue() const { return this == False; }
118   virtual bool isAllOnesValue() const { return this == True; }
119
120   /// Methods for support type inquiry through isa, cast, and dyn_cast:
121   static inline bool classof(const ConstantBool *) { return true; }
122   static bool classof(const Value *V) {
123     return (V == True) | (V == False);
124   }
125 };
126
127
128 //===----------------------------------------------------------------------===//
129 /// ConstantInt - Superclass of ConstantSInt & ConstantUInt, to make dealing
130 /// with integral constants easier.
131 ///
132 class ConstantInt : public ConstantIntegral {
133 protected:
134   ConstantInt(const ConstantInt &);      // DO NOT IMPLEMENT
135   ConstantInt(const Type *Ty, uint64_t V);
136 public:
137   /// equalsInt - Provide a helper method that can be used to determine if the
138   /// constant contained within is equal to a constant.  This only works for
139   /// very small values, because this is all that can be represented with all
140   /// types.
141   ///
142   bool equalsInt(unsigned char V) const {
143     assert(V <= 127 &&
144            "equalsInt: Can only be used with very small positive constants!");
145     return Val.Unsigned == V;
146   }
147
148   /// ConstantInt::get static method: return a ConstantInt with the specified
149   /// value.  as above, we work only with very small values here.
150   ///
151   static ConstantInt *get(const Type *Ty, unsigned char V);
152
153   /// isNullValue - Return true if this is the value that would be returned by
154   /// getNullValue.
155   virtual bool isNullValue() const { return Val.Unsigned == 0; }
156   virtual bool isMaxValue() const = 0;
157   virtual bool isMinValue() const = 0;
158
159   /// Methods for support type inquiry through isa, cast, and dyn_cast:
160   static inline bool classof(const ConstantInt *) { return true; }
161   static bool classof(const Value *V) {
162     return V->getValueType() == SimpleConstantVal &&
163            V->getType()->isInteger();
164   }
165 };
166
167
168 //===----------------------------------------------------------------------===//
169 /// ConstantSInt - Signed Integer Values [sbyte, short, int, long]
170 ///
171 class ConstantSInt : public ConstantInt {
172   ConstantSInt(const ConstantSInt &);      // DO NOT IMPLEMENT
173   friend struct ConstantCreator<ConstantSInt, Type, int64_t>;
174
175 protected:
176   ConstantSInt(const Type *Ty, int64_t V);
177 public:
178   /// get() - Static factory methods - Return objects of the specified value
179   ///
180   static ConstantSInt *get(const Type *Ty, int64_t V);
181
182   /// isValueValidForType - return true if Ty is big enough to represent V.
183   ///
184   static bool isValueValidForType(const Type *Ty, int64_t V);
185
186   /// getValue - return the underlying value of this constant.
187   ///
188   inline int64_t getValue() const { return Val.Signed; }
189
190   virtual bool isAllOnesValue() const { return getValue() == -1; }
191
192   /// isMaxValue - Return true if this is the largest value that may be
193   /// represented by this type.
194   ///
195   virtual bool isMaxValue() const {
196     int64_t V = getValue();
197     if (V < 0) return false;    // Be careful about wrap-around on 'long's
198     ++V;
199     return !isValueValidForType(getType(), V) || V < 0;
200   }
201
202   /// isMinValue - Return true if this is the smallest value that may be
203   /// represented by this type.
204   ///
205   virtual bool isMinValue() const {
206     int64_t V = getValue();
207     if (V > 0) return false;    // Be careful about wrap-around on 'long's
208     --V;
209     return !isValueValidForType(getType(), V) || V > 0;
210   }
211
212   /// Methods for support type inquiry through isa, cast, and dyn_cast:
213   ///
214   static inline bool classof(const ConstantSInt *) { return true; }
215   static bool classof(const Value *V) {
216     return V->getValueType() == SimpleConstantVal &&
217            V->getType()->isSigned();
218   }
219 };
220
221 //===----------------------------------------------------------------------===//
222 /// ConstantUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
223 ///
224 class ConstantUInt : public ConstantInt {
225   ConstantUInt(const ConstantUInt &);      // DO NOT IMPLEMENT
226   friend struct ConstantCreator<ConstantUInt, Type, uint64_t>;
227 protected:
228   ConstantUInt(const Type *Ty, uint64_t V);
229 public:
230   /// get() - Static factory methods - Return objects of the specified value
231   ///
232   static ConstantUInt *get(const Type *Ty, uint64_t V);
233
234   /// isValueValidForType - return true if Ty is big enough to represent V.
235   ///
236   static bool isValueValidForType(const Type *Ty, uint64_t V);
237
238   /// getValue - return the underlying value of this constant.
239   ///
240   inline uint64_t getValue() const { return Val.Unsigned; }
241
242   /// isMaxValue - Return true if this is the largest value that may be
243   /// represented by this type.
244   ///
245   virtual bool isAllOnesValue() const;
246   virtual bool isMaxValue() const { return isAllOnesValue(); }
247   virtual bool isMinValue() const { return getValue() == 0; }
248
249   /// Methods for support type inquiry through isa, cast, and dyn_cast:
250   static inline bool classof(const ConstantUInt *) { return true; }
251   static bool classof(const Value *V) {
252     return V->getValueType() == SimpleConstantVal &&
253            V->getType()->isUnsigned();
254   }
255 };
256
257
258 //===----------------------------------------------------------------------===//
259 /// ConstantFP - Floating Point Values [float, double]
260 ///
261 class ConstantFP : public Constant {
262   double Val;
263   friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
264   friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
265   ConstantFP(const ConstantFP &);      // DO NOT IMPLEMENT
266 protected:
267   ConstantFP(const Type *Ty, double V);
268 public:
269   /// get() - Static factory methods - Return objects of the specified value
270   static ConstantFP *get(const Type *Ty, double V);
271
272   /// isValueValidForType - return true if Ty is big enough to represent V.
273   static bool isValueValidForType(const Type *Ty, double V);
274   inline double getValue() const { return Val; }
275
276   /// isNullValue - Return true if this is the value that would be returned by
277   /// getNullValue.  Don't depend on == for doubles to tell us it's zero, it
278   /// considers -0.0 to be null as well as 0.0.  :(
279   virtual bool isNullValue() const {
280     union {
281       double V;
282       uint64_t I;
283     } T;
284     T.V = Val;
285     return T.I == 0;
286   }
287
288   /// isExactlyValue - We don't rely on operator== working on double values, as
289   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
290   /// As such, this method can be used to do an exact bit-for-bit comparison of
291   /// two floating point values.
292   bool isExactlyValue(double V) const {
293     union {
294       double V;
295       uint64_t I;
296     } T1;
297     T1.V = Val;
298     union {
299       double V;
300       uint64_t I;
301     } T2;
302     T2.V = V;
303     return T1.I == T2.I;
304   }
305
306   /// Methods for support type inquiry through isa, cast, and dyn_cast:
307   static inline bool classof(const ConstantFP *) { return true; }
308   static bool classof(const Value *V) {
309     return V->getValueType() == SimpleConstantVal &&
310            V->getType()->isFloatingPoint();
311   }
312 };
313
314 //===----------------------------------------------------------------------===//
315 /// ConstantAggregateZero - All zero aggregate value
316 ///
317 class ConstantAggregateZero : public Constant {
318   friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
319   ConstantAggregateZero(const ConstantAggregateZero &);      // DO NOT IMPLEMENT
320 protected:
321   ConstantAggregateZero(const Type *Ty)
322     : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
323 public:
324   /// get() - static factory method for creating a null aggregate.  It is
325   /// illegal to call this method with a non-aggregate type.
326   static Constant *get(const Type *Ty);
327
328   /// isNullValue - Return true if this is the value that would be returned by
329   /// getNullValue.
330   virtual bool isNullValue() const { return true; }
331
332   virtual void destroyConstant();
333   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
334                                            bool DisableChecking = false);
335
336   /// Methods for support type inquiry through isa, cast, and dyn_cast:
337   ///
338   static bool classof(const ConstantAggregateZero *) { return true; }
339   static bool classof(const Value *V) {
340     return V->getValueType() == ConstantAggregateZeroVal;
341   }
342 };
343
344
345 //===----------------------------------------------------------------------===//
346 /// ConstantArray - Constant Array Declarations
347 ///
348 class ConstantArray : public Constant {
349   friend struct ConstantCreator<ConstantArray, ArrayType,
350                                     std::vector<Constant*> >;
351   ConstantArray(const ConstantArray &);      // DO NOT IMPLEMENT
352 protected:
353   ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
354   ~ConstantArray();
355 public:
356   /// get() - Static factory methods - Return objects of the specified value
357   static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
358   static Constant *get(const std::string &Initializer);
359   
360   /// getType - Specialize the getType() method to always return an ArrayType,
361   /// which reduces the amount of casting needed in parts of the compiler.
362   ///
363   inline const ArrayType *getType() const {
364     return reinterpret_cast<const ArrayType*>(Value::getType());
365   }
366
367   /// isString - This method returns true if the array is an array of sbyte or
368   /// ubyte, and if the elements of the array are all ConstantInt's.
369   bool isString() const;
370
371   /// getAsString - If this array is isString(), then this method converts the
372   /// array to an std::string and returns it.  Otherwise, it asserts out.
373   ///
374   std::string getAsString() const;
375
376   /// isNullValue - Return true if this is the value that would be returned by
377   /// getNullValue.  This always returns false because zero arrays are always
378   /// created as ConstantAggregateZero objects.
379   virtual bool isNullValue() const { return false; }
380
381   virtual void destroyConstant();
382   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
383                                            bool DisableChecking = false);
384
385   /// Methods for support type inquiry through isa, cast, and dyn_cast:
386   static inline bool classof(const ConstantArray *) { return true; }
387   static bool classof(const Value *V) {
388     return V->getValueType() == SimpleConstantVal &&
389            V->getType()->getTypeID() == Type::ArrayTyID;
390   }
391 };
392
393
394 //===----------------------------------------------------------------------===//
395 // ConstantStruct - Constant Struct Declarations
396 //
397 class ConstantStruct : public Constant {
398   friend struct ConstantCreator<ConstantStruct, StructType,
399                                     std::vector<Constant*> >;
400   ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
401 protected:
402   ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
403   ~ConstantStruct();
404 public:
405   /// get() - Static factory methods - Return objects of the specified value
406   ///
407   static Constant *get(const StructType *T, const std::vector<Constant*> &V);
408   static Constant *get(const std::vector<Constant*> &V);
409
410   /// getType() specialization - Reduce amount of casting...
411   ///
412   inline const StructType *getType() const {
413     return reinterpret_cast<const StructType*>(Value::getType());
414   }
415
416   /// isNullValue - Return true if this is the value that would be returned by
417   /// getNullValue.  This always returns false because zero structs are always
418   /// created as ConstantAggregateZero objects.
419   virtual bool isNullValue() const {
420     return false;
421   }
422
423   virtual void destroyConstant();
424   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
425                                            bool DisableChecking = false);
426   
427   /// Methods for support type inquiry through isa, cast, and dyn_cast:
428   static inline bool classof(const ConstantStruct *) { return true; }
429   static bool classof(const Value *V) {
430     return V->getValueType() == SimpleConstantVal &&
431            V->getType()->getTypeID() == Type::StructTyID;
432   }
433 };
434
435 //===----------------------------------------------------------------------===//
436 /// ConstantPacked - Constant Packed Declarations
437 ///
438 class ConstantPacked : public Constant {
439   friend struct ConstantCreator<ConstantPacked, PackedType,
440                                     std::vector<Constant*> >;
441   ConstantPacked(const ConstantPacked &);      // DO NOT IMPLEMENT
442 protected:
443   ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val);
444   ~ConstantPacked();
445 public:
446   /// get() - Static factory methods - Return objects of the specified value
447   static Constant *get(const PackedType *T, const std::vector<Constant*> &);
448   static Constant *get(const std::vector<Constant*> &V);
449   
450   /// getType - Specialize the getType() method to always return an PackedType,
451   /// which reduces the amount of casting needed in parts of the compiler.
452   ///
453   inline const PackedType *getType() const {
454     return reinterpret_cast<const PackedType*>(Value::getType());
455   }
456
457   /// isNullValue - Return true if this is the value that would be returned by
458   /// getNullValue.  This always returns false because zero arrays are always
459   /// created as ConstantAggregateZero objects.
460   virtual bool isNullValue() const { return false; }
461
462   virtual void destroyConstant();
463   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
464                                            bool DisableChecking = false);
465
466   /// Methods for support type inquiry through isa, cast, and dyn_cast:
467   static inline bool classof(const ConstantPacked *) { return true; }
468   static bool classof(const Value *V) {
469     return V->getValueType() == SimpleConstantVal &&
470            V->getType()->getTypeID() == Type::PackedTyID;
471   }
472 };
473
474 //===----------------------------------------------------------------------===//
475 /// ConstantPointerNull - a constant pointer value that points to null
476 ///
477 class ConstantPointerNull : public Constant {
478   friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
479   ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
480 protected:
481   ConstantPointerNull(const PointerType *T)
482     : Constant(reinterpret_cast<const Type*>(T),
483                Value::SimpleConstantVal, 0, 0) {}
484
485 public:
486
487   /// get() - Static factory methods - Return objects of the specified value
488   static ConstantPointerNull *get(const PointerType *T);
489
490   /// isNullValue - Return true if this is the value that would be returned by
491   /// getNullValue.
492   virtual bool isNullValue() const { return true; }
493
494   virtual void destroyConstant();
495
496   /// getType - Specialize the getType() method to always return an PointerType,
497   /// which reduces the amount of casting needed in parts of the compiler.
498   ///
499   inline const PointerType *getType() const {
500     return reinterpret_cast<const PointerType*>(Value::getType());
501   }
502
503   /// Methods for support type inquiry through isa, cast, and dyn_cast:
504   static inline bool classof(const ConstantPointerNull *) { return true; }
505   static bool classof(const Value *V) {
506     return V->getValueType() == SimpleConstantVal &&
507            isa<PointerType>(V->getType());
508   }
509 };
510
511
512 /// ConstantExpr - a constant value that is initialized with an expression using
513 /// other constant values.
514 ///
515 /// This class uses the standard Instruction opcodes to define the various
516 /// constant expressions.  The Opcode field for the ConstantExpr class is
517 /// maintained in the Value::SubclassData field.
518 class ConstantExpr : public Constant {
519   friend struct ConstantCreator<ConstantExpr,Type,
520                             std::pair<unsigned, std::vector<Constant*> > >;
521   friend struct ConvertConstantType<ConstantExpr, Type>;
522   
523 protected:
524   ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
525     : Constant(Ty, ConstantExprVal, Ops, NumOps) {
526     // Operation type (an Instruction opcode) is stored as the SubclassData.
527     SubclassData = Opcode; 
528   }
529
530   // These private methods are used by the type resolution code to create
531   // ConstantExprs in intermediate forms.
532   static Constant *getTy(const Type *Ty, unsigned Opcode,
533                          Constant *C1, Constant *C2);
534   static Constant *getShiftTy(const Type *Ty,
535                               unsigned Opcode, Constant *C1, Constant *C2);
536   static Constant *getSelectTy(const Type *Ty,
537                                Constant *C1, Constant *C2, Constant *C3);
538   static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
539                                       const std::vector<Value*> &IdxList);
540   
541 public:
542   // Static methods to construct a ConstantExpr of different kinds.  Note that
543   // these methods may return a object that is not an instance of the
544   // ConstantExpr class, because they will attempt to fold the constant
545   // expression into something simpler if possible.
546   
547   /// Cast constant expr
548   ///
549   static Constant *getCast(Constant *C, const Type *Ty);
550   static Constant *getSignExtend(Constant *C, const Type *Ty);
551   static Constant *getZeroExtend(Constant *C, const Type *Ty);
552
553   /// Select constant expr
554   ///
555   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
556     return getSelectTy(V1->getType(), C, V1, V2);
557   }
558
559   /// getSizeOf constant expr - computes the size of a type in a target
560   /// independent way (Note: the return type is ULong but the object is not
561   /// necessarily a ConstantUInt).
562   ///
563   static Constant *getSizeOf(const Type *Ty);
564
565   /// ConstantExpr::get - Return a binary or shift operator constant expression,
566   /// folding if possible.
567   ///
568   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
569
570   /// ConstantExpr::get* - Return some common constants without having to
571   /// specify the full Instruction::OPCODE identifier.
572   ///
573   static Constant *getNeg(Constant *C);
574   static Constant *getNot(Constant *C);
575   static Constant *getAdd(Constant *C1, Constant *C2);
576   static Constant *getSub(Constant *C1, Constant *C2);
577   static Constant *getMul(Constant *C1, Constant *C2);
578   static Constant *getDiv(Constant *C1, Constant *C2);
579   static Constant *getRem(Constant *C1, Constant *C2);
580   static Constant *getAnd(Constant *C1, Constant *C2);
581   static Constant *getOr(Constant *C1, Constant *C2);
582   static Constant *getXor(Constant *C1, Constant *C2);
583   static Constant *getSetEQ(Constant *C1, Constant *C2);
584   static Constant *getSetNE(Constant *C1, Constant *C2);
585   static Constant *getSetLT(Constant *C1, Constant *C2);
586   static Constant *getSetGT(Constant *C1, Constant *C2);
587   static Constant *getSetLE(Constant *C1, Constant *C2);
588   static Constant *getSetGE(Constant *C1, Constant *C2);
589   static Constant *getShl(Constant *C1, Constant *C2);
590   static Constant *getShr(Constant *C1, Constant *C2);
591
592   static Constant *getUShr(Constant *C1, Constant *C2); // unsigned shr
593   static Constant *getSShr(Constant *C1, Constant *C2); // signed shr
594
595   /// Getelementptr form.  std::vector<Value*> is only accepted for convenience:
596   /// all elements must be Constant's.
597   ///
598   static Constant *getGetElementPtr(Constant *C,
599                                     const std::vector<Constant*> &IdxList);
600   static Constant *getGetElementPtr(Constant *C,
601                                     const std::vector<Value*> &IdxList);
602   
603   /// isNullValue - Return true if this is the value that would be returned by
604   /// getNullValue.
605   virtual bool isNullValue() const { return false; }
606   
607   /// getOpcode - Return the opcode at the root of this constant expression
608   unsigned getOpcode() const { return SubclassData; }
609
610   /// getOpcodeName - Return a string representation for an opcode.
611   const char *getOpcodeName() const;
612   
613   virtual void destroyConstant();
614   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
615                                            bool DisableChecking = false);
616     
617   /// Override methods to provide more type information...
618   inline Constant *getOperand(unsigned i) { 
619     return cast<Constant>(User::getOperand(i));
620   }
621   inline Constant *getOperand(unsigned i) const {
622     return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
623   }
624   
625
626   /// Methods for support type inquiry through isa, cast, and dyn_cast:
627   static inline bool classof(const ConstantExpr *) { return true; }
628   static inline bool classof(const Value *V) {
629     return V->getValueType() == ConstantExprVal;
630   }
631 };
632
633
634 //===----------------------------------------------------------------------===//
635 /// UndefValue - 'undef' values are things that do not have specified contents.
636 /// These are used for a variety of purposes, including global variable
637 /// initializers and operands to instructions.  'undef' values can occur with
638 /// any type.
639 ///
640 class UndefValue : public Constant {
641   friend struct ConstantCreator<UndefValue, Type, char>;
642   UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
643 protected:
644   UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
645 public:
646   /// get() - Static factory methods - Return an 'undef' object of the specified
647   /// type.
648   ///
649   static UndefValue *get(const Type *T);
650
651   /// isNullValue - Return true if this is the value that would be returned by
652   /// getNullValue.
653   virtual bool isNullValue() const { return false; }
654
655   virtual void destroyConstant();
656
657   /// Methods for support type inquiry through isa, cast, and dyn_cast:
658   static inline bool classof(const UndefValue *) { return true; }
659   static bool classof(const Value *V) {
660     return V->getValueType() == UndefValueVal;
661   }
662 };
663
664 } // End llvm namespace
665
666 #endif