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