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