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