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