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