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