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