For PR950:
[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   /// isCString - This method returns true if the array is a string (see
338   /// isString) and it ends in a null byte \0 and does not contains any other
339   /// null bytes except its terminator.
340   bool isCString() const;
341
342   /// getAsString - If this array is isString(), then this method converts the
343   /// array to an std::string and returns it.  Otherwise, it asserts out.
344   ///
345   std::string getAsString() const;
346
347   /// isNullValue - Return true if this is the value that would be returned by
348   /// getNullValue.  This always returns false because zero arrays are always
349   /// created as ConstantAggregateZero objects.
350   virtual bool isNullValue() const { return false; }
351
352   virtual void destroyConstant();
353   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
354
355   /// Methods for support type inquiry through isa, cast, and dyn_cast:
356   static inline bool classof(const ConstantArray *) { return true; }
357   static bool classof(const Value *V) {
358     return V->getValueType() == ConstantArrayVal;
359   }
360 };
361
362
363 //===----------------------------------------------------------------------===//
364 // ConstantStruct - Constant Struct Declarations
365 //
366 class ConstantStruct : public Constant {
367   friend struct ConstantCreator<ConstantStruct, StructType,
368                                     std::vector<Constant*> >;
369   ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
370 protected:
371   ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
372   ~ConstantStruct();
373 public:
374   /// get() - Static factory methods - Return objects of the specified value
375   ///
376   static Constant *get(const StructType *T, const std::vector<Constant*> &V);
377   static Constant *get(const std::vector<Constant*> &V);
378
379   /// getType() specialization - Reduce amount of casting...
380   ///
381   inline const StructType *getType() const {
382     return reinterpret_cast<const StructType*>(Value::getType());
383   }
384
385   /// isNullValue - Return true if this is the value that would be returned by
386   /// getNullValue.  This always returns false because zero structs are always
387   /// created as ConstantAggregateZero objects.
388   virtual bool isNullValue() const {
389     return false;
390   }
391
392   virtual void destroyConstant();
393   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
394
395   /// Methods for support type inquiry through isa, cast, and dyn_cast:
396   static inline bool classof(const ConstantStruct *) { return true; }
397   static bool classof(const Value *V) {
398     return V->getValueType() == ConstantStructVal;
399   }
400 };
401
402 //===----------------------------------------------------------------------===//
403 /// ConstantPacked - Constant Packed Declarations
404 ///
405 class ConstantPacked : public Constant {
406   friend struct ConstantCreator<ConstantPacked, PackedType,
407                                     std::vector<Constant*> >;
408   ConstantPacked(const ConstantPacked &);      // DO NOT IMPLEMENT
409 protected:
410   ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val);
411   ~ConstantPacked();
412 public:
413   /// get() - Static factory methods - Return objects of the specified value
414   static Constant *get(const PackedType *T, const std::vector<Constant*> &);
415   static Constant *get(const std::vector<Constant*> &V);
416
417   /// getType - Specialize the getType() method to always return an PackedType,
418   /// which reduces the amount of casting needed in parts of the compiler.
419   ///
420   inline const PackedType *getType() const {
421     return reinterpret_cast<const PackedType*>(Value::getType());
422   }
423
424   /// isNullValue - Return true if this is the value that would be returned by
425   /// getNullValue.  This always returns false because zero arrays are always
426   /// created as ConstantAggregateZero objects.
427   virtual bool isNullValue() const { return false; }
428
429   virtual void destroyConstant();
430   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
431
432   /// Methods for support type inquiry through isa, cast, and dyn_cast:
433   static inline bool classof(const ConstantPacked *) { return true; }
434   static bool classof(const Value *V) {
435     return V->getValueType() == ConstantPackedVal;
436   }
437 };
438
439 //===----------------------------------------------------------------------===//
440 /// ConstantPointerNull - a constant pointer value that points to null
441 ///
442 class ConstantPointerNull : public Constant {
443   friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
444   ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
445 protected:
446   ConstantPointerNull(const PointerType *T)
447     : Constant(reinterpret_cast<const Type*>(T),
448                Value::ConstantPointerNullVal, 0, 0) {}
449
450 public:
451
452   /// get() - Static factory methods - Return objects of the specified value
453   static ConstantPointerNull *get(const PointerType *T);
454
455   /// isNullValue - Return true if this is the value that would be returned by
456   /// getNullValue.
457   virtual bool isNullValue() const { return true; }
458
459   virtual void destroyConstant();
460
461   /// getType - Specialize the getType() method to always return an PointerType,
462   /// which reduces the amount of casting needed in parts of the compiler.
463   ///
464   inline const PointerType *getType() const {
465     return reinterpret_cast<const PointerType*>(Value::getType());
466   }
467
468   /// Methods for support type inquiry through isa, cast, and dyn_cast:
469   static inline bool classof(const ConstantPointerNull *) { return true; }
470   static bool classof(const Value *V) {
471     return V->getValueType() == ConstantPointerNullVal;
472   }
473 };
474
475
476 /// ConstantExpr - a constant value that is initialized with an expression using
477 /// other constant values.
478 ///
479 /// This class uses the standard Instruction opcodes to define the various
480 /// constant expressions.  The Opcode field for the ConstantExpr class is
481 /// maintained in the Value::SubclassData field.
482 class ConstantExpr : public Constant {
483   friend struct ConstantCreator<ConstantExpr,Type,
484                             std::pair<unsigned, std::vector<Constant*> > >;
485   friend struct ConvertConstantType<ConstantExpr, Type>;
486
487 protected:
488   ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
489     : Constant(Ty, ConstantExprVal, Ops, NumOps) {
490     // Operation type (an Instruction opcode) is stored as the SubclassData.
491     SubclassData = Opcode;
492   }
493
494   // These private methods are used by the type resolution code to create
495   // ConstantExprs in intermediate forms.
496   static Constant *getTy(const Type *Ty, unsigned Opcode,
497                          Constant *C1, Constant *C2);
498   static Constant *getShiftTy(const Type *Ty,
499                               unsigned Opcode, Constant *C1, Constant *C2);
500   static Constant *getSelectTy(const Type *Ty,
501                                Constant *C1, Constant *C2, Constant *C3);
502   static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
503                                       const std::vector<Value*> &IdxList);
504   static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
505                                        Constant *Idx);
506   static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
507                                       Constant *Elt, Constant *Idx);
508   static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
509                                       Constant *V2, Constant *Mask);
510
511 public:
512   // Static methods to construct a ConstantExpr of different kinds.  Note that
513   // these methods may return a object that is not an instance of the
514   // ConstantExpr class, because they will attempt to fold the constant
515   // expression into something simpler if possible.
516
517   /// Cast constant expr
518   ///
519   static Constant *getCast(Constant *C, const Type *Ty);
520   static Constant *getSignExtend(Constant *C, const Type *Ty);
521   static Constant *getZeroExtend(Constant *C, const Type *Ty);
522
523   /// Select constant expr
524   ///
525   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
526     return getSelectTy(V1->getType(), C, V1, V2);
527   }
528
529   /// getSizeOf constant expr - computes the size of a type in a target
530   /// independent way (Note: the return type is a ULong).
531   ///
532   static Constant *getSizeOf(const Type *Ty);
533
534   /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
535   /// return a pointer to a pointer of the array element type.
536   static Constant *getPtrPtrFromArrayPtr(Constant *C);
537
538   /// ConstantExpr::get - Return a binary or shift operator constant expression,
539   /// folding if possible.
540   ///
541   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
542
543   /// ConstantExpr::get* - Return some common constants without having to
544   /// specify the full Instruction::OPCODE identifier.
545   ///
546   static Constant *getNeg(Constant *C);
547   static Constant *getNot(Constant *C);
548   static Constant *getAdd(Constant *C1, Constant *C2);
549   static Constant *getSub(Constant *C1, Constant *C2);
550   static Constant *getMul(Constant *C1, Constant *C2);
551   static Constant *getUDiv(Constant *C1, Constant *C2);
552   static Constant *getSDiv(Constant *C1, Constant *C2);
553   static Constant *getFDiv(Constant *C1, Constant *C2);
554   static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
555   static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
556   static Constant *getFRem(Constant *C1, Constant *C2);
557   static Constant *getAnd(Constant *C1, Constant *C2);
558   static Constant *getOr(Constant *C1, Constant *C2);
559   static Constant *getXor(Constant *C1, Constant *C2);
560   static Constant *getSetEQ(Constant *C1, Constant *C2);
561   static Constant *getSetNE(Constant *C1, Constant *C2);
562   static Constant *getSetLT(Constant *C1, Constant *C2);
563   static Constant *getSetGT(Constant *C1, Constant *C2);
564   static Constant *getSetLE(Constant *C1, Constant *C2);
565   static Constant *getSetGE(Constant *C1, Constant *C2);
566   static Constant *getShl(Constant *C1, Constant *C2);
567   static Constant *getShr(Constant *C1, Constant *C2);
568
569   static Constant *getUShr(Constant *C1, Constant *C2); // unsigned shr
570   static Constant *getSShr(Constant *C1, Constant *C2); // signed shr
571
572   /// Getelementptr form.  std::vector<Value*> is only accepted for convenience:
573   /// all elements must be Constant's.
574   ///
575   static Constant *getGetElementPtr(Constant *C,
576                                     const std::vector<Constant*> &IdxList);
577   static Constant *getGetElementPtr(Constant *C,
578                                     const std::vector<Value*> &IdxList);
579
580   static Constant *getExtractElement(Constant *Vec, Constant *Idx);
581   static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
582   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
583   
584   /// isNullValue - Return true if this is the value that would be returned by
585   /// getNullValue.
586   virtual bool isNullValue() const { return false; }
587
588   /// getOpcode - Return the opcode at the root of this constant expression
589   unsigned getOpcode() const { return SubclassData; }
590
591   /// getOpcodeName - Return a string representation for an opcode.
592   const char *getOpcodeName() const;
593
594   /// getWithOperandReplaced - Return a constant expression identical to this
595   /// one, but with the specified operand set to the specified value.
596   Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
597   
598   /// getWithOperands - This returns the current constant expression with the
599   /// operands replaced with the specified values.  The specified operands must
600   /// match count and type with the existing ones.
601   Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
602   
603   virtual void destroyConstant();
604   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
605
606   /// Override methods to provide more type information...
607   inline Constant *getOperand(unsigned i) {
608     return cast<Constant>(User::getOperand(i));
609   }
610   inline Constant *getOperand(unsigned i) const {
611     return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
612   }
613
614
615   /// Methods for support type inquiry through isa, cast, and dyn_cast:
616   static inline bool classof(const ConstantExpr *) { return true; }
617   static inline bool classof(const Value *V) {
618     return V->getValueType() == ConstantExprVal;
619   }
620 };
621
622
623 //===----------------------------------------------------------------------===//
624 /// UndefValue - 'undef' values are things that do not have specified contents.
625 /// These are used for a variety of purposes, including global variable
626 /// initializers and operands to instructions.  'undef' values can occur with
627 /// any type.
628 ///
629 class UndefValue : public Constant {
630   friend struct ConstantCreator<UndefValue, Type, char>;
631   UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
632 protected:
633   UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
634 public:
635   /// get() - Static factory methods - Return an 'undef' object of the specified
636   /// type.
637   ///
638   static UndefValue *get(const Type *T);
639
640   /// isNullValue - Return true if this is the value that would be returned by
641   /// getNullValue.
642   virtual bool isNullValue() const { return false; }
643
644   virtual void destroyConstant();
645
646   /// Methods for support type inquiry through isa, cast, and dyn_cast:
647   static inline bool classof(const UndefValue *) { return true; }
648   static bool classof(const Value *V) {
649     return V->getValueType() == UndefValueVal;
650   }
651 };
652
653 } // End llvm namespace
654
655 #endif