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