Add a new shufflevector instruction
[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
26 namespace llvm {
27
28 class ArrayType;
29 class StructType;
30 class PointerType;
31 class PackedType;
32
33 template<class ConstantClass, class TypeClass, class ValType>
34 struct ConstantCreator;
35 template<class ConstantClass, class TypeClass>
36 struct ConvertConstantType;
37
38 //===----------------------------------------------------------------------===//
39 /// ConstantIntegral - Shared superclass of boolean and integer constants.
40 ///
41 /// This class just defines some common interfaces to be implemented.
42 ///
43 class ConstantIntegral : public Constant {
44 protected:
45   union {
46     int64_t  Signed;
47     uint64_t Unsigned;
48   } Val;
49   ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V);
50 public:
51
52   /// getRawValue - return the underlying value of this constant as a 64-bit
53   /// unsigned integer value.
54   ///
55   inline uint64_t getRawValue() const { return Val.Unsigned; }
56   
57   /// getZExtValue - Return the constant zero extended as appropriate for this
58   /// type.
59   inline uint64_t getZExtValue() const {
60     unsigned Size = getType()->getPrimitiveSizeInBits();
61     return Val.Unsigned & (~0ULL >> (64-Size));
62   }
63
64   /// getSExtValue - Return the constant sign extended as appropriate for this
65   /// type.
66   inline int64_t getSExtValue() const {
67     unsigned Size = getType()->getPrimitiveSizeInBits();
68     return (Val.Signed << (64-Size)) >> (64-Size);
69   }
70   
71   /// isNullValue - Return true if this is the value that would be returned by
72   /// getNullValue.
73   ///
74   virtual bool isNullValue() const = 0;
75
76   /// isMaxValue - Return true if this is the largest value that may be
77   /// represented by this type.
78   ///
79   virtual bool isMaxValue() const = 0;
80
81   /// isMinValue - Return true if this is the smallest value that may be
82   /// represented by this type.
83   ///
84   virtual bool isMinValue() const = 0;
85
86   /// isAllOnesValue - Return true if every bit in this constant is set to true.
87   ///
88   virtual bool isAllOnesValue() const = 0;
89
90   /// Static constructor to get the maximum/minimum/allones constant of
91   /// specified (integral) type...
92   ///
93   static ConstantIntegral *getMaxValue(const Type *Ty);
94   static ConstantIntegral *getMinValue(const Type *Ty);
95   static ConstantIntegral *getAllOnesValue(const Type *Ty);
96
97   /// Methods for support type inquiry through isa, cast, and dyn_cast:
98   static inline bool classof(const ConstantIntegral *) { return true; }
99   static bool classof(const Value *V) {
100     return V->getValueType() == ConstantBoolVal ||
101            V->getValueType() == ConstantSIntVal ||
102            V->getValueType() == ConstantUIntVal;
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->getValueType() == ConstantBoolVal;
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, ValueTy VT, 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() == ConstantSIntVal ||
177            V->getValueType() == ConstantUIntVal;
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() == ConstantSIntVal;
231   }
232 };
233
234 //===----------------------------------------------------------------------===//
235 /// ConstantUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
236 ///
237 class ConstantUInt : public ConstantInt {
238   ConstantUInt(const ConstantUInt &);      // DO NOT IMPLEMENT
239   friend struct ConstantCreator<ConstantUInt, Type, uint64_t>;
240 protected:
241   ConstantUInt(const Type *Ty, uint64_t V);
242 public:
243   /// get() - Static factory methods - Return objects of the specified value
244   ///
245   static ConstantUInt *get(const Type *Ty, uint64_t V);
246
247   /// isValueValidForType - return true if Ty is big enough to represent V.
248   ///
249   static bool isValueValidForType(const Type *Ty, uint64_t V);
250
251   /// getValue - return the underlying value of this constant.
252   ///
253   inline uint64_t getValue() const { return Val.Unsigned; }
254
255   /// isMaxValue - Return true if this is the largest value that may be
256   /// represented by this type.
257   ///
258   virtual bool isAllOnesValue() const;
259   virtual bool isMaxValue() const { return isAllOnesValue(); }
260   virtual bool isMinValue() const { return getValue() == 0; }
261
262   /// Methods for support type inquiry through isa, cast, and dyn_cast:
263   static inline bool classof(const ConstantUInt *) { return true; }
264   static bool classof(const Value *V) {
265     return V->getValueType() == ConstantUIntVal;
266   }
267 };
268
269
270 //===----------------------------------------------------------------------===//
271 /// ConstantFP - Floating Point Values [float, double]
272 ///
273 class ConstantFP : public Constant {
274   double Val;
275   friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
276   friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
277   ConstantFP(const ConstantFP &);      // DO NOT IMPLEMENT
278 protected:
279   ConstantFP(const Type *Ty, double V);
280 public:
281   /// get() - Static factory methods - Return objects of the specified value
282   static ConstantFP *get(const Type *Ty, double V);
283
284   /// isValueValidForType - return true if Ty is big enough to represent V.
285   static bool isValueValidForType(const Type *Ty, double V);
286   inline double getValue() const { return Val; }
287
288   /// isNullValue - Return true if this is the value that would be returned by
289   /// getNullValue.  Don't depend on == for doubles to tell us it's zero, it
290   /// considers -0.0 to be null as well as 0.0.  :(
291   virtual bool isNullValue() const;
292
293   /// isExactlyValue - We don't rely on operator== working on double values, as
294   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
295   /// As such, this method can be used to do an exact bit-for-bit comparison of
296   /// two floating point values.
297   bool isExactlyValue(double V) const;
298
299   /// Methods for support type inquiry through isa, cast, and dyn_cast:
300   static inline bool classof(const ConstantFP *) { return true; }
301   static bool classof(const Value *V) {
302     return V->getValueType() == ConstantFPVal;
303   }
304 };
305
306 //===----------------------------------------------------------------------===//
307 /// ConstantAggregateZero - All zero aggregate value
308 ///
309 class ConstantAggregateZero : public Constant {
310   friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
311   ConstantAggregateZero(const ConstantAggregateZero &);      // DO NOT IMPLEMENT
312 protected:
313   ConstantAggregateZero(const Type *Ty)
314     : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
315 public:
316   /// get() - static factory method for creating a null aggregate.  It is
317   /// illegal to call this method with a non-aggregate type.
318   static Constant *get(const Type *Ty);
319
320   /// isNullValue - Return true if this is the value that would be returned by
321   /// getNullValue.
322   virtual bool isNullValue() const { return true; }
323
324   virtual void destroyConstant();
325
326   /// Methods for support type inquiry through isa, cast, and dyn_cast:
327   ///
328   static bool classof(const ConstantAggregateZero *) { return true; }
329   static bool classof(const Value *V) {
330     return V->getValueType() == ConstantAggregateZeroVal;
331   }
332 };
333
334
335 //===----------------------------------------------------------------------===//
336 /// ConstantArray - Constant Array Declarations
337 ///
338 class ConstantArray : public Constant {
339   friend struct ConstantCreator<ConstantArray, ArrayType,
340                                     std::vector<Constant*> >;
341   ConstantArray(const ConstantArray &);      // DO NOT IMPLEMENT
342 protected:
343   ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
344   ~ConstantArray();
345 public:
346   /// get() - Static factory methods - Return objects of the specified value
347   static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
348   static Constant *get(const std::string &Initializer);
349
350   /// getType - Specialize the getType() method to always return an ArrayType,
351   /// which reduces the amount of casting needed in parts of the compiler.
352   ///
353   inline const ArrayType *getType() const {
354     return reinterpret_cast<const ArrayType*>(Value::getType());
355   }
356
357   /// isString - This method returns true if the array is an array of sbyte or
358   /// ubyte, and if the elements of the array are all ConstantInt's.
359   bool isString() const;
360
361   /// getAsString - If this array is isString(), then this method converts the
362   /// array to an std::string and returns it.  Otherwise, it asserts out.
363   ///
364   std::string getAsString() const;
365
366   /// isNullValue - Return true if this is the value that would be returned by
367   /// getNullValue.  This always returns false because zero arrays are always
368   /// created as ConstantAggregateZero objects.
369   virtual bool isNullValue() const { return false; }
370
371   virtual void destroyConstant();
372   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
373
374   /// Methods for support type inquiry through isa, cast, and dyn_cast:
375   static inline bool classof(const ConstantArray *) { return true; }
376   static bool classof(const Value *V) {
377     return V->getValueType() == ConstantArrayVal;
378   }
379 };
380
381
382 //===----------------------------------------------------------------------===//
383 // ConstantStruct - Constant Struct Declarations
384 //
385 class ConstantStruct : public Constant {
386   friend struct ConstantCreator<ConstantStruct, StructType,
387                                     std::vector<Constant*> >;
388   ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
389 protected:
390   ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
391   ~ConstantStruct();
392 public:
393   /// get() - Static factory methods - Return objects of the specified value
394   ///
395   static Constant *get(const StructType *T, const std::vector<Constant*> &V);
396   static Constant *get(const std::vector<Constant*> &V);
397
398   /// getType() specialization - Reduce amount of casting...
399   ///
400   inline const StructType *getType() const {
401     return reinterpret_cast<const StructType*>(Value::getType());
402   }
403
404   /// isNullValue - Return true if this is the value that would be returned by
405   /// getNullValue.  This always returns false because zero structs are always
406   /// created as ConstantAggregateZero objects.
407   virtual bool isNullValue() const {
408     return false;
409   }
410
411   virtual void destroyConstant();
412   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
413
414   /// Methods for support type inquiry through isa, cast, and dyn_cast:
415   static inline bool classof(const ConstantStruct *) { return true; }
416   static bool classof(const Value *V) {
417     return V->getValueType() == ConstantStructVal;
418   }
419 };
420
421 //===----------------------------------------------------------------------===//
422 /// ConstantPacked - Constant Packed Declarations
423 ///
424 class ConstantPacked : public Constant {
425   friend struct ConstantCreator<ConstantPacked, PackedType,
426                                     std::vector<Constant*> >;
427   ConstantPacked(const ConstantPacked &);      // DO NOT IMPLEMENT
428 protected:
429   ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val);
430   ~ConstantPacked();
431 public:
432   /// get() - Static factory methods - Return objects of the specified value
433   static Constant *get(const PackedType *T, const std::vector<Constant*> &);
434   static Constant *get(const std::vector<Constant*> &V);
435
436   /// getType - Specialize the getType() method to always return an PackedType,
437   /// which reduces the amount of casting needed in parts of the compiler.
438   ///
439   inline const PackedType *getType() const {
440     return reinterpret_cast<const PackedType*>(Value::getType());
441   }
442
443   /// isNullValue - Return true if this is the value that would be returned by
444   /// getNullValue.  This always returns false because zero arrays are always
445   /// created as ConstantAggregateZero objects.
446   virtual bool isNullValue() const { return false; }
447
448   virtual void destroyConstant();
449   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
450
451   /// Methods for support type inquiry through isa, cast, and dyn_cast:
452   static inline bool classof(const ConstantPacked *) { return true; }
453   static bool classof(const Value *V) {
454     return V->getValueType() == ConstantPackedVal;
455   }
456 };
457
458 //===----------------------------------------------------------------------===//
459 /// ConstantPointerNull - a constant pointer value that points to null
460 ///
461 class ConstantPointerNull : public Constant {
462   friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
463   ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
464 protected:
465   ConstantPointerNull(const PointerType *T)
466     : Constant(reinterpret_cast<const Type*>(T),
467                Value::ConstantPointerNullVal, 0, 0) {}
468
469 public:
470
471   /// get() - Static factory methods - Return objects of the specified value
472   static ConstantPointerNull *get(const PointerType *T);
473
474   /// isNullValue - Return true if this is the value that would be returned by
475   /// getNullValue.
476   virtual bool isNullValue() const { return true; }
477
478   virtual void destroyConstant();
479
480   /// getType - Specialize the getType() method to always return an PointerType,
481   /// which reduces the amount of casting needed in parts of the compiler.
482   ///
483   inline const PointerType *getType() const {
484     return reinterpret_cast<const PointerType*>(Value::getType());
485   }
486
487   /// Methods for support type inquiry through isa, cast, and dyn_cast:
488   static inline bool classof(const ConstantPointerNull *) { return true; }
489   static bool classof(const Value *V) {
490     return V->getValueType() == ConstantPointerNullVal;
491   }
492 };
493
494
495 /// ConstantExpr - a constant value that is initialized with an expression using
496 /// other constant values.
497 ///
498 /// This class uses the standard Instruction opcodes to define the various
499 /// constant expressions.  The Opcode field for the ConstantExpr class is
500 /// maintained in the Value::SubclassData field.
501 class ConstantExpr : public Constant {
502   friend struct ConstantCreator<ConstantExpr,Type,
503                             std::pair<unsigned, std::vector<Constant*> > >;
504   friend struct ConvertConstantType<ConstantExpr, Type>;
505
506 protected:
507   ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
508     : Constant(Ty, ConstantExprVal, Ops, NumOps) {
509     // Operation type (an Instruction opcode) is stored as the SubclassData.
510     SubclassData = Opcode;
511   }
512
513   // These private methods are used by the type resolution code to create
514   // ConstantExprs in intermediate forms.
515   static Constant *getTy(const Type *Ty, unsigned Opcode,
516                          Constant *C1, Constant *C2);
517   static Constant *getShiftTy(const Type *Ty,
518                               unsigned Opcode, Constant *C1, Constant *C2);
519   static Constant *getSelectTy(const Type *Ty,
520                                Constant *C1, Constant *C2, Constant *C3);
521   static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
522                                       const std::vector<Value*> &IdxList);
523   static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
524                                        Constant *Idx);
525   static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
526                                       Constant *Elt, Constant *Idx);
527   static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
528                                       Constant *V2, Constant *Mask);
529
530 public:
531   // Static methods to construct a ConstantExpr of different kinds.  Note that
532   // these methods may return a object that is not an instance of the
533   // ConstantExpr class, because they will attempt to fold the constant
534   // expression into something simpler if possible.
535
536   /// Cast constant expr
537   ///
538   static Constant *getCast(Constant *C, const Type *Ty);
539   static Constant *getSignExtend(Constant *C, const Type *Ty);
540   static Constant *getZeroExtend(Constant *C, const Type *Ty);
541
542   /// Select constant expr
543   ///
544   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
545     return getSelectTy(V1->getType(), C, V1, V2);
546   }
547
548   /// getSizeOf constant expr - computes the size of a type in a target
549   /// independent way (Note: the return type is ULong but the object is not
550   /// necessarily a ConstantUInt).
551   ///
552   static Constant *getSizeOf(const Type *Ty);
553
554   /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
555   /// return a pointer to a pointer of the array element type.
556   static Constant *getPtrPtrFromArrayPtr(Constant *C);
557
558   /// ConstantExpr::get - Return a binary or shift operator constant expression,
559   /// folding if possible.
560   ///
561   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
562
563   /// ConstantExpr::get* - Return some common constants without having to
564   /// specify the full Instruction::OPCODE identifier.
565   ///
566   static Constant *getNeg(Constant *C);
567   static Constant *getNot(Constant *C);
568   static Constant *getAdd(Constant *C1, Constant *C2);
569   static Constant *getSub(Constant *C1, Constant *C2);
570   static Constant *getMul(Constant *C1, Constant *C2);
571   static Constant *getDiv(Constant *C1, Constant *C2);
572   static Constant *getRem(Constant *C1, Constant *C2);
573   static Constant *getAnd(Constant *C1, Constant *C2);
574   static Constant *getOr(Constant *C1, Constant *C2);
575   static Constant *getXor(Constant *C1, Constant *C2);
576   static Constant *getSetEQ(Constant *C1, Constant *C2);
577   static Constant *getSetNE(Constant *C1, Constant *C2);
578   static Constant *getSetLT(Constant *C1, Constant *C2);
579   static Constant *getSetGT(Constant *C1, Constant *C2);
580   static Constant *getSetLE(Constant *C1, Constant *C2);
581   static Constant *getSetGE(Constant *C1, Constant *C2);
582   static Constant *getShl(Constant *C1, Constant *C2);
583   static Constant *getShr(Constant *C1, Constant *C2);
584
585   static Constant *getUShr(Constant *C1, Constant *C2); // unsigned shr
586   static Constant *getSShr(Constant *C1, Constant *C2); // signed shr
587
588   /// Getelementptr form.  std::vector<Value*> is only accepted for convenience:
589   /// all elements must be Constant's.
590   ///
591   static Constant *getGetElementPtr(Constant *C,
592                                     const std::vector<Constant*> &IdxList);
593   static Constant *getGetElementPtr(Constant *C,
594                                     const std::vector<Value*> &IdxList);
595
596   static Constant *getExtractElement(Constant *Vec, Constant *Idx);
597   static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
598   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
599   
600   /// isNullValue - Return true if this is the value that would be returned by
601   /// getNullValue.
602   virtual bool isNullValue() const { return false; }
603
604   /// getOpcode - Return the opcode at the root of this constant expression
605   unsigned getOpcode() const { return SubclassData; }
606
607   /// getOpcodeName - Return a string representation for an opcode.
608   const char *getOpcodeName() const;
609
610   virtual void destroyConstant();
611   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
612
613   /// Override methods to provide more type information...
614   inline Constant *getOperand(unsigned i) {
615     return cast<Constant>(User::getOperand(i));
616   }
617   inline Constant *getOperand(unsigned i) const {
618     return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
619   }
620
621
622   /// Methods for support type inquiry through isa, cast, and dyn_cast:
623   static inline bool classof(const ConstantExpr *) { return true; }
624   static inline bool classof(const Value *V) {
625     return V->getValueType() == ConstantExprVal;
626   }
627 };
628
629
630 //===----------------------------------------------------------------------===//
631 /// UndefValue - 'undef' values are things that do not have specified contents.
632 /// These are used for a variety of purposes, including global variable
633 /// initializers and operands to instructions.  'undef' values can occur with
634 /// any type.
635 ///
636 class UndefValue : public Constant {
637   friend struct ConstantCreator<UndefValue, Type, char>;
638   UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
639 protected:
640   UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
641 public:
642   /// get() - Static factory methods - Return an 'undef' object of the specified
643   /// type.
644   ///
645   static UndefValue *get(const Type *T);
646
647   /// isNullValue - Return true if this is the value that would be returned by
648   /// getNullValue.
649   virtual bool isNullValue() const { return false; }
650
651   virtual void destroyConstant();
652
653   /// Methods for support type inquiry through isa, cast, and dyn_cast:
654   static inline bool classof(const UndefValue *) { return true; }
655   static bool classof(const Value *V) {
656     return V->getValueType() == UndefValueVal;
657   }
658 };
659
660 } // End llvm namespace
661
662 #endif