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