Privatize the ConstantStruct table.
[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 is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// @file
11 /// This file contains the declarations for the subclasses of Constant, 
12 /// which represent the different flavors of constant values that live in LLVM.
13 /// Note that Constants are immutable (once created they never change) and are 
14 /// fully shared by structural equivalence.  This means that two structurally
15 /// equivalent constants will always have the same address.  Constant's are
16 /// created on demand as needed and never deleted: thus clients don't have to
17 /// worry about the lifetime of the objects.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef LLVM_CONSTANTS_H
22 #define LLVM_CONSTANTS_H
23
24 #include "llvm/Constant.h"
25 #include "llvm/Type.h"
26 #include "llvm/OperandTraits.h"
27 #include "llvm/ADT/APInt.h"
28 #include "llvm/ADT/APFloat.h"
29 #include "llvm/ADT/SmallVector.h"
30
31 namespace llvm {
32
33 class ArrayType;
34 class StructType;
35 class PointerType;
36 class VectorType;
37
38 template<class ConstantClass, class TypeClass, class ValType>
39 struct ConstantCreator;
40 template<class ConstantClass, class TypeClass>
41 struct ConvertConstantType;
42
43 //===----------------------------------------------------------------------===//
44 /// This is the shared class of boolean and integer constants. This class 
45 /// represents both boolean and integral constants.
46 /// @brief Class for constant integers.
47 class ConstantInt : public Constant {
48   static ConstantInt *TheTrueVal, *TheFalseVal;
49   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
50   ConstantInt(const ConstantInt &);      // DO NOT IMPLEMENT
51   ConstantInt(const IntegerType *Ty, const APInt& V);
52   APInt Val;
53   friend class LLVMContextImpl;
54 protected:
55   // allocate space for exactly zero operands
56   void *operator new(size_t s) {
57     return User::operator new(s, 0);
58   }
59 public:
60   /// Return the constant as an APInt value reference. This allows clients to
61   /// obtain a copy of the value, with all its precision in tact.
62   /// @brief Return the constant's value.
63   inline const APInt& getValue() const {
64     return Val;
65   }
66   
67   /// getBitWidth - Return the bitwidth of this constant.
68   unsigned getBitWidth() const { return Val.getBitWidth(); }
69
70   /// Return the constant as a 64-bit unsigned integer value after it
71   /// has been zero extended as appropriate for the type of this constant. Note
72   /// that this method can assert if the value does not fit in 64 bits.
73   /// @deprecated
74   /// @brief Return the zero extended value.
75   inline uint64_t getZExtValue() const {
76     return Val.getZExtValue();
77   }
78
79   /// Return the constant as a 64-bit integer value after it has been sign
80   /// extended as appropriate for the type of this constant. Note that
81   /// this method can assert if the value does not fit in 64 bits.
82   /// @deprecated
83   /// @brief Return the sign extended value.
84   inline int64_t getSExtValue() const {
85     return Val.getSExtValue();
86   }
87
88   /// A helper method that can be used to determine if the constant contained 
89   /// within is equal to a constant.  This only works for very small values, 
90   /// because this is all that can be represented with all types.
91   /// @brief Determine if this constant's value is same as an unsigned char.
92   bool equalsInt(uint64_t V) const {
93     return Val == V;
94   }
95
96   /// getType - Specialize the getType() method to always return an IntegerType,
97   /// which reduces the amount of casting needed in parts of the compiler.
98   ///
99   inline const IntegerType *getType() const {
100     return reinterpret_cast<const IntegerType*>(Value::getType());
101   }
102
103   /// This static method returns true if the type Ty is big enough to 
104   /// represent the value V. This can be used to avoid having the get method 
105   /// assert when V is larger than Ty can represent. Note that there are two
106   /// versions of this method, one for unsigned and one for signed integers.
107   /// Although ConstantInt canonicalizes everything to an unsigned integer, 
108   /// the signed version avoids callers having to convert a signed quantity
109   /// to the appropriate unsigned type before calling the method.
110   /// @returns true if V is a valid value for type Ty
111   /// @brief Determine if the value is in range for the given type.
112   static bool isValueValidForType(const Type *Ty, uint64_t V);
113   static bool isValueValidForType(const Type *Ty, int64_t V);
114
115   /// This function will return true iff this constant represents the "null"
116   /// value that would be returned by the getNullValue method.
117   /// @returns true if this is the null integer value.
118   /// @brief Determine if the value is null.
119   virtual bool isNullValue() const { 
120     return Val == 0; 
121   }
122
123   /// This is just a convenience method to make client code smaller for a
124   /// common code. It also correctly performs the comparison without the
125   /// potential for an assertion from getZExtValue().
126   bool isZero() const {
127     return Val == 0;
128   }
129
130   /// This is just a convenience method to make client code smaller for a 
131   /// common case. It also correctly performs the comparison without the
132   /// potential for an assertion from getZExtValue().
133   /// @brief Determine if the value is one.
134   bool isOne() const {
135     return Val == 1;
136   }
137
138   /// This function will return true iff every bit in this constant is set
139   /// to true.
140   /// @returns true iff this constant's bits are all set to true.
141   /// @brief Determine if the value is all ones.
142   bool isAllOnesValue() const { 
143     return Val.isAllOnesValue();
144   }
145
146   /// This function will return true iff this constant represents the largest
147   /// value that may be represented by the constant's type.
148   /// @returns true iff this is the largest value that may be represented 
149   /// by this type.
150   /// @brief Determine if the value is maximal.
151   bool isMaxValue(bool isSigned) const {
152     if (isSigned) 
153       return Val.isMaxSignedValue();
154     else
155       return Val.isMaxValue();
156   }
157
158   /// This function will return true iff this constant represents the smallest
159   /// value that may be represented by this constant's type.
160   /// @returns true if this is the smallest value that may be represented by 
161   /// this type.
162   /// @brief Determine if the value is minimal.
163   bool isMinValue(bool isSigned) const {
164     if (isSigned) 
165       return Val.isMinSignedValue();
166     else
167       return Val.isMinValue();
168   }
169
170   /// This function will return true iff this constant represents a value with
171   /// active bits bigger than 64 bits or a value greater than the given uint64_t
172   /// value.
173   /// @returns true iff this constant is greater or equal to the given number.
174   /// @brief Determine if the value is greater or equal to the given number.
175   bool uge(uint64_t Num) {
176     return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
177   }
178
179   /// getLimitedValue - If the value is smaller than the specified limit,
180   /// return it, otherwise return the limit value.  This causes the value
181   /// to saturate to the limit.
182   /// @returns the min of the value of the constant and the specified value
183   /// @brief Get the constant's value with a saturation limit
184   uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
185     return Val.getLimitedValue(Limit);
186   }
187
188   /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
189   static inline bool classof(const ConstantInt *) { return true; }
190   static bool classof(const Value *V) {
191     return V->getValueID() == ConstantIntVal;
192   }
193 };
194
195
196 //===----------------------------------------------------------------------===//
197 /// ConstantFP - Floating Point Values [float, double]
198 ///
199 class ConstantFP : public Constant {
200   APFloat Val;
201   void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
202   ConstantFP(const ConstantFP &);      // DO NOT IMPLEMENT
203   friend class LLVMContextImpl;
204 protected:
205   ConstantFP(const Type *Ty, const APFloat& V);
206 protected:
207   // allocate space for exactly zero operands
208   void *operator new(size_t s) {
209     return User::operator new(s, 0);
210   }
211 public:
212   /// isValueValidForType - return true if Ty is big enough to represent V.
213   static bool isValueValidForType(const Type *Ty, const APFloat& V);
214   inline const APFloat& getValueAPF() const { return Val; }
215
216   /// isNullValue - Return true if this is the value that would be returned by
217   /// getNullValue.  Don't depend on == for doubles to tell us it's zero, it
218   /// considers -0.0 to be null as well as 0.0.  :(
219   virtual bool isNullValue() const;
220   
221   /// isNegativeZeroValue - Return true if the value is what would be returned 
222   /// by getZeroValueForNegation.
223   virtual bool isNegativeZeroValue() const {
224     return Val.isZero() && Val.isNegative();
225   }
226
227   /// isExactlyValue - We don't rely on operator== working on double values, as
228   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
229   /// As such, this method can be used to do an exact bit-for-bit comparison of
230   /// two floating point values.  The version with a double operand is retained
231   /// because it's so convenient to write isExactlyValue(2.0), but please use
232   /// it only for simple constants.
233   bool isExactlyValue(const APFloat& V) const;
234
235   bool isExactlyValue(double V) const {
236     bool ignored;
237     // convert is not supported on this type
238     if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
239       return false;
240     APFloat FV(V);
241     FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
242     return isExactlyValue(FV);
243   }
244   /// Methods for support type inquiry through isa, cast, and dyn_cast:
245   static inline bool classof(const ConstantFP *) { return true; }
246   static bool classof(const Value *V) {
247     return V->getValueID() == ConstantFPVal;
248   }
249 };
250
251 //===----------------------------------------------------------------------===//
252 /// ConstantAggregateZero - All zero aggregate value
253 ///
254 class ConstantAggregateZero : public Constant {
255   friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
256   void *operator new(size_t, unsigned);                      // DO NOT IMPLEMENT
257   ConstantAggregateZero(const ConstantAggregateZero &);      // DO NOT IMPLEMENT
258 protected:
259   explicit ConstantAggregateZero(const Type *ty)
260     : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
261 protected:
262   // allocate space for exactly zero operands
263   void *operator new(size_t s) {
264     return User::operator new(s, 0);
265   }
266 public:
267   /// isNullValue - Return true if this is the value that would be returned by
268   /// getNullValue.
269   virtual bool isNullValue() const { return true; }
270
271   virtual void destroyConstant();
272
273   /// Methods for support type inquiry through isa, cast, and dyn_cast:
274   ///
275   static bool classof(const ConstantAggregateZero *) { return true; }
276   static bool classof(const Value *V) {
277     return V->getValueID() == ConstantAggregateZeroVal;
278   }
279 };
280
281
282 //===----------------------------------------------------------------------===//
283 /// ConstantArray - Constant Array Declarations
284 ///
285 class ConstantArray : public Constant {
286   friend struct ConstantCreator<ConstantArray, ArrayType,
287                                     std::vector<Constant*> >;
288   ConstantArray(const ConstantArray &);      // DO NOT IMPLEMENT
289   friend class LLVMContextImpl;
290 protected:
291   ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
292 public:
293   /// Transparently provide more efficient getOperand methods.
294   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
295
296   /// getType - Specialize the getType() method to always return an ArrayType,
297   /// which reduces the amount of casting needed in parts of the compiler.
298   ///
299   inline const ArrayType *getType() const {
300     return reinterpret_cast<const ArrayType*>(Value::getType());
301   }
302
303   /// isString - This method returns true if the array is an array of i8 and
304   /// the elements of the array are all ConstantInt's.
305   bool isString() const;
306
307   /// isCString - This method returns true if the array is a string (see
308   /// @verbatim
309   /// isString) and it ends in a null byte \0 and does not contains any other
310   /// @endverbatim
311   /// null bytes except its terminator.
312   bool isCString() const;
313
314   /// getAsString - If this array is isString(), then this method converts the
315   /// array to an std::string and returns it.  Otherwise, it asserts out.
316   ///
317   std::string getAsString() const;
318
319   /// isNullValue - Return true if this is the value that would be returned by
320   /// getNullValue.  This always returns false because zero arrays are always
321   /// created as ConstantAggregateZero objects.
322   virtual bool isNullValue() const { return false; }
323
324   virtual void destroyConstant();
325   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
326
327   /// Methods for support type inquiry through isa, cast, and dyn_cast:
328   static inline bool classof(const ConstantArray *) { return true; }
329   static bool classof(const Value *V) {
330     return V->getValueID() == ConstantArrayVal;
331   }
332 };
333
334 template <>
335 struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
336 };
337
338 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
339
340 //===----------------------------------------------------------------------===//
341 // ConstantStruct - Constant Struct Declarations
342 //
343 class ConstantStruct : public Constant {
344   friend struct ConstantCreator<ConstantStruct, StructType,
345                                     std::vector<Constant*> >;
346   ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
347   friend class LLVMContextImpl;
348 protected:
349   ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
350 public:
351   /// Transparently provide more efficient getOperand methods.
352   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
353
354   /// getType() specialization - Reduce amount of casting...
355   ///
356   inline const StructType *getType() const {
357     return reinterpret_cast<const StructType*>(Value::getType());
358   }
359
360   /// isNullValue - Return true if this is the value that would be returned by
361   /// getNullValue.  This always returns false because zero structs are always
362   /// created as ConstantAggregateZero objects.
363   virtual bool isNullValue() const {
364     return false;
365   }
366
367   virtual void destroyConstant();
368   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
369
370   /// Methods for support type inquiry through isa, cast, and dyn_cast:
371   static inline bool classof(const ConstantStruct *) { return true; }
372   static bool classof(const Value *V) {
373     return V->getValueID() == ConstantStructVal;
374   }
375 };
376
377 template <>
378 struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
379 };
380
381 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
382
383 //===----------------------------------------------------------------------===//
384 /// ConstantVector - Constant Vector Declarations
385 ///
386 class ConstantVector : public Constant {
387   friend struct ConstantCreator<ConstantVector, VectorType,
388                                     std::vector<Constant*> >;
389   ConstantVector(const ConstantVector &);      // DO NOT IMPLEMENT
390 protected:
391   ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
392 public:
393   /// get() - Static factory methods - Return objects of the specified value
394   static Constant *get(const VectorType *T, const std::vector<Constant*> &);
395   
396   /// Transparently provide more efficient getOperand methods.
397   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
398
399   /// getType - Specialize the getType() method to always return a VectorType,
400   /// which reduces the amount of casting needed in parts of the compiler.
401   ///
402   inline const VectorType *getType() const {
403     return reinterpret_cast<const VectorType*>(Value::getType());
404   }
405   
406   /// isNullValue - Return true if this is the value that would be returned by
407   /// getNullValue.  This always returns false because zero vectors are always
408   /// created as ConstantAggregateZero objects.
409   virtual bool isNullValue() const { return false; }
410
411   /// This function will return true iff every element in this vector constant
412   /// is set to all ones.
413   /// @returns true iff this constant's emements are all set to all ones.
414   /// @brief Determine if the value is all ones.
415   bool isAllOnesValue() const;
416
417   /// getSplatValue - If this is a splat constant, meaning that all of the
418   /// elements have the same value, return that value. Otherwise return NULL.
419   Constant *getSplatValue();
420
421   virtual void destroyConstant();
422   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
423
424   /// Methods for support type inquiry through isa, cast, and dyn_cast:
425   static inline bool classof(const ConstantVector *) { return true; }
426   static bool classof(const Value *V) {
427     return V->getValueID() == ConstantVectorVal;
428   }
429 };
430
431 template <>
432 struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
433 };
434
435 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
436
437 //===----------------------------------------------------------------------===//
438 /// ConstantPointerNull - a constant pointer value that points to null
439 ///
440 class ConstantPointerNull : public Constant {
441   friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
442   void *operator new(size_t, unsigned);                  // DO NOT IMPLEMENT
443   ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
444 protected:
445   explicit ConstantPointerNull(const PointerType *T)
446     : Constant(reinterpret_cast<const Type*>(T),
447                Value::ConstantPointerNullVal, 0, 0) {}
448
449 protected:
450   // allocate space for exactly zero operands
451   void *operator new(size_t s) {
452     return User::operator new(s, 0);
453   }
454 public:
455   /// get() - Static factory methods - Return objects of the specified value
456   static ConstantPointerNull *get(const PointerType *T);
457
458   /// isNullValue - Return true if this is the value that would be returned by
459   /// getNullValue.
460   virtual bool isNullValue() const { return true; }
461
462   virtual void destroyConstant();
463
464   /// getType - Specialize the getType() method to always return an PointerType,
465   /// which reduces the amount of casting needed in parts of the compiler.
466   ///
467   inline const PointerType *getType() const {
468     return reinterpret_cast<const PointerType*>(Value::getType());
469   }
470
471   /// Methods for support type inquiry through isa, cast, and dyn_cast:
472   static inline bool classof(const ConstantPointerNull *) { return true; }
473   static bool classof(const Value *V) {
474     return V->getValueID() == ConstantPointerNullVal;
475   }
476 };
477
478
479 /// ConstantExpr - a constant value that is initialized with an expression using
480 /// other constant values.
481 ///
482 /// This class uses the standard Instruction opcodes to define the various
483 /// constant expressions.  The Opcode field for the ConstantExpr class is
484 /// maintained in the Value::SubclassData field.
485 class ConstantExpr : public Constant {
486   friend struct ConstantCreator<ConstantExpr,Type,
487                             std::pair<unsigned, std::vector<Constant*> > >;
488   friend struct ConvertConstantType<ConstantExpr, Type>;
489
490 protected:
491   ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
492     : Constant(ty, ConstantExprVal, Ops, NumOps) {
493     // Operation type (an Instruction opcode) is stored as the SubclassData.
494     SubclassData = Opcode;
495   }
496
497   // These private methods are used by the type resolution code to create
498   // ConstantExprs in intermediate forms.
499   static Constant *getTy(const Type *Ty, unsigned Opcode,
500                          Constant *C1, Constant *C2);
501   static Constant *getCompareTy(unsigned short pred, Constant *C1,
502                                 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                                       Value* const *Idxs, unsigned NumIdxs);
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   static Constant *getExtractValueTy(const Type *Ty, Constant *Agg,
514                                      const unsigned *Idxs, unsigned NumIdxs);
515   static Constant *getInsertValueTy(const Type *Ty, Constant *Agg,
516                                     Constant *Val,
517                                     const unsigned *Idxs, unsigned NumIdxs);
518
519 public:
520   // Static methods to construct a ConstantExpr of different kinds.  Note that
521   // these methods may return a object that is not an instance of the
522   // ConstantExpr class, because they will attempt to fold the constant
523   // expression into something simpler if possible.
524
525   /// Cast constant expr
526   ///
527   static Constant *getTrunc   (Constant *C, const Type *Ty);
528   static Constant *getSExt    (Constant *C, const Type *Ty);
529   static Constant *getZExt    (Constant *C, const Type *Ty);
530   static Constant *getFPTrunc (Constant *C, const Type *Ty);
531   static Constant *getFPExtend(Constant *C, const Type *Ty);
532   static Constant *getUIToFP  (Constant *C, const Type *Ty);
533   static Constant *getSIToFP  (Constant *C, const Type *Ty);
534   static Constant *getFPToUI  (Constant *C, const Type *Ty);
535   static Constant *getFPToSI  (Constant *C, const Type *Ty);
536   static Constant *getPtrToInt(Constant *C, const Type *Ty);
537   static Constant *getIntToPtr(Constant *C, const Type *Ty);
538   static Constant *getBitCast (Constant *C, const Type *Ty);
539
540   /// Transparently provide more efficient getOperand methods.
541   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
542
543   // @brief Convenience function for getting one of the casting operations
544   // using a CastOps opcode.
545   static Constant *getCast(
546     unsigned ops,  ///< The opcode for the conversion
547     Constant *C,   ///< The constant to be converted
548     const Type *Ty ///< The type to which the constant is converted
549   );
550
551   // @brief Create a ZExt or BitCast cast constant expression
552   static Constant *getZExtOrBitCast(
553     Constant *C,   ///< The constant to zext or bitcast
554     const Type *Ty ///< The type to zext or bitcast C to
555   );
556
557   // @brief Create a SExt or BitCast cast constant expression 
558   static Constant *getSExtOrBitCast(
559     Constant *C,   ///< The constant to sext or bitcast
560     const Type *Ty ///< The type to sext or bitcast C to
561   );
562
563   // @brief Create a Trunc or BitCast cast constant expression
564   static Constant *getTruncOrBitCast(
565     Constant *C,   ///< The constant to trunc or bitcast
566     const Type *Ty ///< The type to trunc or bitcast C to
567   );
568
569   /// @brief Create a BitCast or a PtrToInt cast constant expression
570   static Constant *getPointerCast(
571     Constant *C,   ///< The pointer value to be casted (operand 0)
572     const Type *Ty ///< The type to which cast should be made
573   );
574
575   /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
576   static Constant *getIntegerCast(
577     Constant *C,    ///< The integer constant to be casted 
578     const Type *Ty, ///< The integer type to cast to
579     bool isSigned   ///< Whether C should be treated as signed or not
580   );
581
582   /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
583   static Constant *getFPCast(
584     Constant *C,    ///< The integer constant to be casted 
585     const Type *Ty ///< The integer type to cast to
586   );
587
588   /// @brief Return true if this is a convert constant expression
589   bool isCast() const;
590
591   /// @brief Return true if this is a compare constant expression
592   bool isCompare() const;
593
594   /// @brief Return true if this is an insertvalue or extractvalue expression,
595   /// and the getIndices() method may be used.
596   bool hasIndices() const;
597
598   /// Select constant expr
599   ///
600   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
601     return getSelectTy(V1->getType(), C, V1, V2);
602   }
603
604   /// ConstantExpr::get - Return a binary or shift operator constant expression,
605   /// folding if possible.
606   ///
607   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
608
609   /// @brief Return an ICmp or FCmp comparison operator constant expression.
610   static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
611
612   /// ConstantExpr::get* - Return some common constants without having to
613   /// specify the full Instruction::OPCODE identifier.
614   ///
615   static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
616   static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
617
618   /// Getelementptr form.  std::vector<Value*> is only accepted for convenience:
619   /// all elements must be Constant's.
620   ///
621   static Constant *getGetElementPtr(Constant *C,
622                                     Constant* const *IdxList, unsigned NumIdx);
623   static Constant *getGetElementPtr(Constant *C,
624                                     Value* const *IdxList, unsigned NumIdx);
625   
626   static Constant *getExtractElement(Constant *Vec, Constant *Idx);
627   static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
628   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
629   static Constant *getExtractValue(Constant *Agg,
630                                    const unsigned *IdxList, unsigned NumIdx);
631   static Constant *getInsertValue(Constant *Agg, Constant *Val,
632                                   const unsigned *IdxList, unsigned NumIdx);
633
634   /// isNullValue - Return true if this is the value that would be returned by
635   /// getNullValue.
636   virtual bool isNullValue() const { return false; }
637
638   /// getOpcode - Return the opcode at the root of this constant expression
639   unsigned getOpcode() const { return SubclassData; }
640
641   /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
642   /// not an ICMP or FCMP constant expression.
643   unsigned getPredicate() const;
644
645   /// getIndices - Assert that this is an insertvalue or exactvalue
646   /// expression and return the list of indices.
647   const SmallVector<unsigned, 4> &getIndices() const;
648
649   /// getOpcodeName - Return a string representation for an opcode.
650   const char *getOpcodeName() const;
651
652   /// getWithOperandReplaced - Return a constant expression identical to this
653   /// one, but with the specified operand set to the specified value.
654   Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
655   
656   /// getWithOperands - This returns the current constant expression with the
657   /// operands replaced with the specified values.  The specified operands must
658   /// match count and type with the existing ones.
659   Constant *getWithOperands(const std::vector<Constant*> &Ops) const {
660     return getWithOperands(&Ops[0], (unsigned)Ops.size());
661   }
662   Constant *getWithOperands(Constant* const *Ops, unsigned NumOps) const;
663   
664   virtual void destroyConstant();
665   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
666
667   /// Methods for support type inquiry through isa, cast, and dyn_cast:
668   static inline bool classof(const ConstantExpr *) { return true; }
669   static inline bool classof(const Value *V) {
670     return V->getValueID() == ConstantExprVal;
671   }
672 };
673
674 template <>
675 struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
676 };
677
678 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
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   void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
689   UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
690 protected:
691   explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
692 protected:
693   // allocate space for exactly zero operands
694   void *operator new(size_t s) {
695     return User::operator new(s, 0);
696   }
697 public:
698   /// get() - Static factory methods - Return an 'undef' object of the specified
699   /// type.
700   ///
701   static UndefValue *get(const Type *T);
702
703   /// isNullValue - Return true if this is the value that would be returned by
704   /// getNullValue.
705   virtual bool isNullValue() const { return false; }
706
707   virtual void destroyConstant();
708
709   /// Methods for support type inquiry through isa, cast, and dyn_cast:
710   static inline bool classof(const UndefValue *) { return true; }
711   static bool classof(const Value *V) {
712     return V->getValueID() == UndefValueVal;
713   }
714 };
715 } // End llvm namespace
716
717 #endif