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