Add cast creation functions for Pointer Casts, either BitCast or PtrToInt
[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 *getCompareTy(unsigned Opcode, unsigned short pred, 
503                                 Constant *C1, Constant *C2);
504   static Constant *getShiftTy(const Type *Ty,
505                               unsigned Opcode, Constant *C1, Constant *C2);
506   static Constant *getSelectTy(const Type *Ty,
507                                Constant *C1, Constant *C2, Constant *C3);
508   static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
509                                       const std::vector<Value*> &IdxList);
510   static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
511                                        Constant *Idx);
512   static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
513                                       Constant *Elt, Constant *Idx);
514   static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
515                                       Constant *V2, Constant *Mask);
516
517 public:
518   // Static methods to construct a ConstantExpr of different kinds.  Note that
519   // these methods may return a object that is not an instance of the
520   // ConstantExpr class, because they will attempt to fold the constant
521   // expression into something simpler if possible.
522
523   /// Cast constant expr
524   ///
525   static Constant *getTrunc      (Constant *C, const Type *Ty);
526   static Constant *getSignExtend (Constant *C, const Type *Ty);
527   static Constant *getZeroExtend (Constant *C, const Type *Ty);
528   static Constant *getFPTrunc    (Constant *C, const Type *Ty);
529   static Constant *getFPExtend   (Constant *C, const Type *Ty);
530   static Constant *getUIToFP     (Constant *C, const Type *Ty);
531   static Constant *getSIToFP     (Constant *C, const Type *Ty);
532   static Constant *getFPToUI     (Constant *C, const Type *Ty);
533   static Constant *getFPToSI     (Constant *C, const Type *Ty);
534   static Constant *getPtrToInt   (Constant *C, const Type *Ty);
535   static Constant *getIntToPtr   (Constant *C, const Type *Ty);
536   static Constant *getBitCast    (Constant *C, const Type *Ty);
537
538   // @brief Convenience function for getting one of the casting operations
539   // using a CastOps opcode.
540   static Constant *getCast(
541     unsigned ops,  ///< The opcode for the conversion
542     Constant *C,   ///< The constant to be converted
543     const Type *Ty ///< The type to which the constant is converted
544   );
545
546   // @brief Create a ZExt or BitCast cast constant expression
547   static Constant *getZExtOrBitCast(
548     Constant *C,   ///< The constant to zext or bitcast
549     const Type *Ty ///< The type to zext or bitcast C to
550   );
551
552   // @brief Create a SExt or BitCast cast constant expression 
553   static Constant *getSExtOrBitCast(
554     Constant *C,   ///< The constant to sext or bitcast
555     const Type *Ty ///< The type to sext or bitcast C to
556   );
557
558   // @brief Create a Trunc or BitCast cast constant expression
559   static Constant *getTruncOrBitCast(
560     Constant *C,   ///< The constant to trunc or bitcast
561     const Type *Ty ///< The type to trunc or bitcast C to
562   );
563
564   /// @brief Create a BitCast or a PtrToInt cast constant expression
565   static Constant *getPointerCast(
566     Constant *C,   ///< The pointer value to be casted (operand 0)
567     const Type *Ty ///< The type to which cast should be made
568   );
569
570   // This method uses the CastInst::getCastOpcode method to infer the
571   // cast opcode to use. 
572   // @brief Get a ConstantExpr Conversion operator that casts C to Ty
573   static Constant *getInferredCast(Constant *C, bool SrcIsSigned, 
574                                    const Type *Ty, bool DestIsSigned);
575
576   static Constant *getCast(Constant *C, const Type *Ty) {
577     return getInferredCast(C, C->getType()->isSigned(), Ty, Ty->isSigned());
578   }
579
580   /// @brief Return true if this is a convert constant expression
581   bool isCast() const;
582
583   /// @brief Return true if this is a compare constant expression
584   bool isCompare() const;
585
586   /// Select constant expr
587   ///
588   static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
589     return getSelectTy(V1->getType(), C, V1, V2);
590   }
591
592   /// getSizeOf constant expr - computes the size of a type in a target
593   /// independent way (Note: the return type is a ULong).
594   ///
595   static Constant *getSizeOf(const Type *Ty);
596
597   /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
598   /// return a pointer to a pointer of the array element type.
599   static Constant *getPtrPtrFromArrayPtr(Constant *C);
600
601   /// ConstantExpr::get - Return a binary or shift operator constant expression,
602   /// folding if possible.
603   ///
604   static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
605
606   /// @brief Return an ICmp or FCmp comparison operator constant expression.
607   static Constant *getCompare(unsigned Opcode, unsigned short pred, 
608                               Constant *C1, Constant *C2);
609
610   /// ConstantExpr::get* - Return some common constants without having to
611   /// specify the full Instruction::OPCODE identifier.
612   ///
613   static Constant *getNeg(Constant *C);
614   static Constant *getNot(Constant *C);
615   static Constant *getAdd(Constant *C1, Constant *C2);
616   static Constant *getSub(Constant *C1, Constant *C2);
617   static Constant *getMul(Constant *C1, Constant *C2);
618   static Constant *getUDiv(Constant *C1, Constant *C2);
619   static Constant *getSDiv(Constant *C1, Constant *C2);
620   static Constant *getFDiv(Constant *C1, Constant *C2);
621   static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
622   static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
623   static Constant *getFRem(Constant *C1, Constant *C2);
624   static Constant *getAnd(Constant *C1, Constant *C2);
625   static Constant *getOr(Constant *C1, Constant *C2);
626   static Constant *getXor(Constant *C1, Constant *C2);
627   static Constant *getSetEQ(Constant *C1, Constant *C2);
628   static Constant *getSetNE(Constant *C1, Constant *C2);
629   static Constant *getSetLT(Constant *C1, Constant *C2);
630   static Constant *getSetGT(Constant *C1, Constant *C2);
631   static Constant *getSetLE(Constant *C1, Constant *C2);
632   static Constant *getSetGE(Constant *C1, Constant *C2);
633   static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS);
634   static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS);
635   static Constant *getShl(Constant *C1, Constant *C2);
636   static Constant *getLShr(Constant *C1, Constant *C2);
637   static Constant *getAShr(Constant *C1, Constant *C2);
638
639   /// Getelementptr form.  std::vector<Value*> is only accepted for convenience:
640   /// all elements must be Constant's.
641   ///
642   static Constant *getGetElementPtr(Constant *C,
643                                     const std::vector<Constant*> &IdxList);
644   static Constant *getGetElementPtr(Constant *C,
645                                     const std::vector<Value*> &IdxList);
646
647   static Constant *getExtractElement(Constant *Vec, Constant *Idx);
648   static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
649   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
650
651   /// isNullValue - Return true if this is the value that would be returned by
652   /// getNullValue.
653   virtual bool isNullValue() const { return false; }
654
655   /// getOpcode - Return the opcode at the root of this constant expression
656   unsigned getOpcode() const { return SubclassData; }
657
658   /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
659   /// not an ICMP or FCMP constant expression.
660   unsigned getPredicate() const;
661
662   /// getOpcodeName - Return a string representation for an opcode.
663   const char *getOpcodeName() const;
664
665   /// getWithOperandReplaced - Return a constant expression identical to this
666   /// one, but with the specified operand set to the specified value.
667   Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
668   
669   /// getWithOperands - This returns the current constant expression with the
670   /// operands replaced with the specified values.  The specified operands must
671   /// match count and type with the existing ones.
672   Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
673   
674   virtual void destroyConstant();
675   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
676
677   /// Override methods to provide more type information...
678   inline Constant *getOperand(unsigned i) {
679     return cast<Constant>(User::getOperand(i));
680   }
681   inline Constant *getOperand(unsigned i) const {
682     return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
683   }
684
685
686   /// Methods for support type inquiry through isa, cast, and dyn_cast:
687   static inline bool classof(const ConstantExpr *) { return true; }
688   static inline bool classof(const Value *V) {
689     return V->getValueType() == ConstantExprVal;
690   }
691 };
692
693
694 //===----------------------------------------------------------------------===//
695 /// UndefValue - 'undef' values are things that do not have specified contents.
696 /// These are used for a variety of purposes, including global variable
697 /// initializers and operands to instructions.  'undef' values can occur with
698 /// any type.
699 ///
700 class UndefValue : public Constant {
701   friend struct ConstantCreator<UndefValue, Type, char>;
702   UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
703 protected:
704   UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
705 public:
706   /// get() - Static factory methods - Return an 'undef' object of the specified
707   /// type.
708   ///
709   static UndefValue *get(const Type *T);
710
711   /// isNullValue - Return true if this is the value that would be returned by
712   /// getNullValue.
713   virtual bool isNullValue() const { return false; }
714
715   virtual void destroyConstant();
716
717   /// Methods for support type inquiry through isa, cast, and dyn_cast:
718   static inline bool classof(const UndefValue *) { return true; }
719   static bool classof(const Value *V) {
720     return V->getValueType() == UndefValueVal;
721   }
722 };
723
724 } // End llvm namespace
725
726 #endif