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