1 //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_CONSTANTS_H
21 #define LLVM_CONSTANTS_H
23 #include "llvm/Constant.h"
24 #include "llvm/Type.h"
33 template<class ConstantClass, class TypeClass, class ValType>
34 struct ConstantCreator;
35 template<class ConstantClass, class TypeClass>
36 struct ConvertConstantType;
38 //===----------------------------------------------------------------------===//
39 /// This is the shared class of boolean and integer constants. This class
40 /// represents both boolean and integral constants.
41 /// @brief Class for constant integers.
42 class ConstantInt : public Constant {
46 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
47 ConstantInt(const Type *Ty, uint64_t V);
48 ConstantInt(const Type *Ty, int64_t V);
50 friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
52 /// Return the constant as a 64-bit unsigned integer value after it
53 /// has been zero extended as appropriate for the type of this constant.
54 /// @brief Return the zero extended value.
55 inline uint64_t getZExtValue() const {
59 /// Return the constant as a 64-bit integer value after it has been sign
60 /// sign extended as appropriate for the type of this constant.
61 /// @brief Return the sign extended value.
62 inline int64_t getSExtValue() const {
63 unsigned Size = Value::getType()->getPrimitiveSizeInBits();
64 return (int64_t(Val) << (64-Size)) >> (64-Size);
66 /// A helper method that can be used to determine if the constant contained
67 /// within is equal to a constant. This only works for very small values,
68 /// because this is all that can be represented with all types.
69 /// @brief Determine if this constant's value is same as an unsigned char.
70 bool equalsInt(unsigned char V) const {
72 "equalsInt: Can only be used with very small positive constants!");
76 /// getTrue/getFalse - Return the singleton true/false values.
77 static inline ConstantInt *getTrue() {
78 static ConstantInt *T = 0;
80 return T = new ConstantInt(true);
82 static inline ConstantInt *getFalse() {
83 static ConstantInt *F = 0;
85 return F = new ConstantInt(false);
88 /// Return a ConstantInt with the specified value for the specified type. The
89 /// value V will be canonicalized to a uint64_t but accessing it with either
90 /// getSExtValue() or getZExtValue() (ConstantInt) will yield the correct
91 /// sized/signed value for the type Ty.
92 /// @brief Get a ConstantInt for a specific value.
93 static ConstantInt *get(const Type *Ty, int64_t V);
95 /// getType - Specialize the getType() method to always return an IntegerType,
96 /// which reduces the amount of casting needed in parts of the compiler.
98 inline const IntegerType *getType() const {
99 return reinterpret_cast<const IntegerType*>(Value::getType());
102 /// This static method returns true if the type Ty is big enough to
103 /// represent the value V. This can be used to avoid having the get method
104 /// assert when V is larger than Ty can represent. Note that there are two
105 /// versions of this method, one for unsigned and one for signed integers.
106 /// Although ConstantInt canonicalizes everything to an unsigned integer,
107 /// the signed version avoids callers having to convert a signed quantity
108 /// to the appropriate unsigned type before calling the method.
109 /// @returns true if V is a valid value for type Ty
110 /// @brief Determine if the value is in range for the given type.
111 static bool isValueValidForType(const Type *Ty, uint64_t V);
112 static bool isValueValidForType(const Type *Ty, int64_t V);
114 /// This function will return true iff this constant represents the "null"
115 /// value that would be returned by the getNullValue method.
116 /// @returns true if this is the null integer value.
117 /// @brief Determine if the value is null.
118 virtual bool isNullValue() const {
122 /// This function will return true iff every bit in this constant is set
124 /// @returns true iff this constant's bits are all set to true.
125 /// @brief Determine if the value is all ones.
126 bool isAllOnesValue() const {
127 return getSExtValue() == -1;
130 /// This function will return true iff this constant represents the largest
131 /// value that may be represented by the constant's type.
132 /// @returns true iff this is the largest value that may be represented
134 /// @brief Determine if the value is maximal.
135 bool isMaxValue(bool isSigned) const {
137 int64_t V = getSExtValue();
138 if (V < 0) return false; // Be careful about wrap-around on 'long's
140 return !isValueValidForType(Value::getType(), V) || V < 0;
142 return isAllOnesValue();
145 /// This function will return true iff this constant represents the smallest
146 /// value that may be represented by this constant's type.
147 /// @returns true if this is the smallest value that may be represented by
149 /// @brief Determine if the value is minimal.
150 bool isMinValue(bool isSigned) const {
152 int64_t V = getSExtValue();
153 if (V > 0) return false; // Be careful about wrap-around on 'long's
155 return !isValueValidForType(Value::getType(), V) || V > 0;
157 return getZExtValue() == 0;
160 /// @returns the value for an integer constant of the given type that has all
161 /// its bits set to true.
162 /// @brief Get the all ones value
163 static ConstantInt *getAllOnesValue(const Type *Ty);
165 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
166 static inline bool classof(const ConstantInt *) { return true; }
167 static bool classof(const Value *V) {
168 return V->getValueType() == ConstantIntVal;
173 //===----------------------------------------------------------------------===//
174 /// ConstantFP - Floating Point Values [float, double]
176 class ConstantFP : public Constant {
178 friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
179 friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
180 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
182 ConstantFP(const Type *Ty, double V);
184 /// get() - Static factory methods - Return objects of the specified value
185 static ConstantFP *get(const Type *Ty, double V);
187 /// isValueValidForType - return true if Ty is big enough to represent V.
188 static bool isValueValidForType(const Type *Ty, double V);
189 inline double getValue() const { return Val; }
191 /// isNullValue - Return true if this is the value that would be returned by
192 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
193 /// considers -0.0 to be null as well as 0.0. :(
194 virtual bool isNullValue() const;
196 /// isExactlyValue - We don't rely on operator== working on double values, as
197 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
198 /// As such, this method can be used to do an exact bit-for-bit comparison of
199 /// two floating point values.
200 bool isExactlyValue(double V) const;
202 /// Methods for support type inquiry through isa, cast, and dyn_cast:
203 static inline bool classof(const ConstantFP *) { return true; }
204 static bool classof(const Value *V) {
205 return V->getValueType() == ConstantFPVal;
209 //===----------------------------------------------------------------------===//
210 /// ConstantAggregateZero - All zero aggregate value
212 class ConstantAggregateZero : public Constant {
213 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
214 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
216 ConstantAggregateZero(const Type *Ty)
217 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
219 /// get() - static factory method for creating a null aggregate. It is
220 /// illegal to call this method with a non-aggregate type.
221 static Constant *get(const Type *Ty);
223 /// isNullValue - Return true if this is the value that would be returned by
225 virtual bool isNullValue() const { return true; }
227 virtual void destroyConstant();
229 /// Methods for support type inquiry through isa, cast, and dyn_cast:
231 static bool classof(const ConstantAggregateZero *) { return true; }
232 static bool classof(const Value *V) {
233 return V->getValueType() == ConstantAggregateZeroVal;
238 //===----------------------------------------------------------------------===//
239 /// ConstantArray - Constant Array Declarations
241 class ConstantArray : public Constant {
242 friend struct ConstantCreator<ConstantArray, ArrayType,
243 std::vector<Constant*> >;
244 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
246 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
249 /// get() - Static factory methods - Return objects of the specified value
250 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
251 static Constant *get(const ArrayType *T,
252 Constant*const*Vals, unsigned NumVals) {
253 // FIXME: make this the primary ctor method.
254 return get(T, std::vector<Constant*>(Vals, Vals+NumVals));
257 /// This method constructs a ConstantArray and initializes it with a text
258 /// string. The default behavior (AddNull==true) causes a null terminator to
259 /// be placed at the end of the array. This effectively increases the length
260 /// of the array by one (you've been warned). However, in some situations
261 /// this is not desired so if AddNull==false then the string is copied without
262 /// null termination.
263 static Constant *get(const std::string &Initializer, bool AddNull = true);
265 /// getType - Specialize the getType() method to always return an ArrayType,
266 /// which reduces the amount of casting needed in parts of the compiler.
268 inline const ArrayType *getType() const {
269 return reinterpret_cast<const ArrayType*>(Value::getType());
272 /// isString - This method returns true if the array is an array of sbyte or
273 /// ubyte, and if the elements of the array are all ConstantInt's.
274 bool isString() const;
276 /// isCString - This method returns true if the array is a string (see
277 /// isString) and it ends in a null byte \0 and does not contains any other
278 /// null bytes except its terminator.
279 bool isCString() const;
281 /// getAsString - If this array is isString(), then this method converts the
282 /// array to an std::string and returns it. Otherwise, it asserts out.
284 std::string getAsString() const;
286 /// isNullValue - Return true if this is the value that would be returned by
287 /// getNullValue. This always returns false because zero arrays are always
288 /// created as ConstantAggregateZero objects.
289 virtual bool isNullValue() const { return false; }
291 virtual void destroyConstant();
292 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
294 /// Methods for support type inquiry through isa, cast, and dyn_cast:
295 static inline bool classof(const ConstantArray *) { return true; }
296 static bool classof(const Value *V) {
297 return V->getValueType() == ConstantArrayVal;
302 //===----------------------------------------------------------------------===//
303 // ConstantStruct - Constant Struct Declarations
305 class ConstantStruct : public Constant {
306 friend struct ConstantCreator<ConstantStruct, StructType,
307 std::vector<Constant*> >;
308 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
310 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
313 /// get() - Static factory methods - Return objects of the specified value
315 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
316 static Constant *get(const std::vector<Constant*> &V, bool Packed = false);
317 static Constant *get(Constant*const* Vals, unsigned NumVals,
318 bool Packed = false) {
319 // FIXME: make this the primary ctor method.
320 return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
323 /// getType() specialization - Reduce amount of casting...
325 inline const StructType *getType() const {
326 return reinterpret_cast<const StructType*>(Value::getType());
329 /// isNullValue - Return true if this is the value that would be returned by
330 /// getNullValue. This always returns false because zero structs are always
331 /// created as ConstantAggregateZero objects.
332 virtual bool isNullValue() const {
336 virtual void destroyConstant();
337 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
339 /// Methods for support type inquiry through isa, cast, and dyn_cast:
340 static inline bool classof(const ConstantStruct *) { return true; }
341 static bool classof(const Value *V) {
342 return V->getValueType() == ConstantStructVal;
346 //===----------------------------------------------------------------------===//
347 /// ConstantVector - Constant Vector Declarations
349 class ConstantVector : public Constant {
350 friend struct ConstantCreator<ConstantVector, VectorType,
351 std::vector<Constant*> >;
352 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
354 ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
357 /// get() - Static factory methods - Return objects of the specified value
358 static Constant *get(const VectorType *T, const std::vector<Constant*> &);
359 static Constant *get(const std::vector<Constant*> &V);
360 static Constant *get(Constant*const* Vals, unsigned NumVals) {
361 // FIXME: make this the primary ctor method.
362 return get(std::vector<Constant*>(Vals, Vals+NumVals));
365 /// getType - Specialize the getType() method to always return an VectorType,
366 /// which reduces the amount of casting needed in parts of the compiler.
368 inline const VectorType *getType() const {
369 return reinterpret_cast<const VectorType*>(Value::getType());
372 /// @returns the value for an packed integer constant of the given type that
373 /// has all its bits set to true.
374 /// @brief Get the all ones value
375 static ConstantVector *getAllOnesValue(const VectorType *Ty);
377 /// isNullValue - Return true if this is the value that would be returned by
378 /// getNullValue. This always returns false because zero arrays are always
379 /// created as ConstantAggregateZero objects.
380 virtual bool isNullValue() const { return false; }
382 /// This function will return true iff every element in this packed constant
383 /// is set to all ones.
384 /// @returns true iff this constant's emements are all set to all ones.
385 /// @brief Determine if the value is all ones.
386 bool isAllOnesValue() const;
388 virtual void destroyConstant();
389 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
391 /// Methods for support type inquiry through isa, cast, and dyn_cast:
392 static inline bool classof(const ConstantVector *) { return true; }
393 static bool classof(const Value *V) {
394 return V->getValueType() == ConstantVectorVal;
398 //===----------------------------------------------------------------------===//
399 /// ConstantPointerNull - a constant pointer value that points to null
401 class ConstantPointerNull : public Constant {
402 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
403 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
405 ConstantPointerNull(const PointerType *T)
406 : Constant(reinterpret_cast<const Type*>(T),
407 Value::ConstantPointerNullVal, 0, 0) {}
411 /// get() - Static factory methods - Return objects of the specified value
412 static ConstantPointerNull *get(const PointerType *T);
414 /// isNullValue - Return true if this is the value that would be returned by
416 virtual bool isNullValue() const { return true; }
418 virtual void destroyConstant();
420 /// getType - Specialize the getType() method to always return an PointerType,
421 /// which reduces the amount of casting needed in parts of the compiler.
423 inline const PointerType *getType() const {
424 return reinterpret_cast<const PointerType*>(Value::getType());
427 /// Methods for support type inquiry through isa, cast, and dyn_cast:
428 static inline bool classof(const ConstantPointerNull *) { return true; }
429 static bool classof(const Value *V) {
430 return V->getValueType() == ConstantPointerNullVal;
435 /// ConstantExpr - a constant value that is initialized with an expression using
436 /// other constant values.
438 /// This class uses the standard Instruction opcodes to define the various
439 /// constant expressions. The Opcode field for the ConstantExpr class is
440 /// maintained in the Value::SubclassData field.
441 class ConstantExpr : public Constant {
442 friend struct ConstantCreator<ConstantExpr,Type,
443 std::pair<unsigned, std::vector<Constant*> > >;
444 friend struct ConvertConstantType<ConstantExpr, Type>;
447 ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
448 : Constant(Ty, ConstantExprVal, Ops, NumOps) {
449 // Operation type (an Instruction opcode) is stored as the SubclassData.
450 SubclassData = Opcode;
453 // These private methods are used by the type resolution code to create
454 // ConstantExprs in intermediate forms.
455 static Constant *getTy(const Type *Ty, unsigned Opcode,
456 Constant *C1, Constant *C2);
457 static Constant *getCompareTy(unsigned short pred, Constant *C1,
459 static Constant *getSelectTy(const Type *Ty,
460 Constant *C1, Constant *C2, Constant *C3);
461 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
462 Value* const *Idxs, unsigned NumIdxs);
463 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
465 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
466 Constant *Elt, Constant *Idx);
467 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
468 Constant *V2, Constant *Mask);
471 // Static methods to construct a ConstantExpr of different kinds. Note that
472 // these methods may return a object that is not an instance of the
473 // ConstantExpr class, because they will attempt to fold the constant
474 // expression into something simpler if possible.
476 /// Cast constant expr
478 static Constant *getTrunc (Constant *C, const Type *Ty);
479 static Constant *getSExt (Constant *C, const Type *Ty);
480 static Constant *getZExt (Constant *C, const Type *Ty);
481 static Constant *getFPTrunc (Constant *C, const Type *Ty);
482 static Constant *getFPExtend(Constant *C, const Type *Ty);
483 static Constant *getUIToFP (Constant *C, const Type *Ty);
484 static Constant *getSIToFP (Constant *C, const Type *Ty);
485 static Constant *getFPToUI (Constant *C, const Type *Ty);
486 static Constant *getFPToSI (Constant *C, const Type *Ty);
487 static Constant *getPtrToInt(Constant *C, const Type *Ty);
488 static Constant *getIntToPtr(Constant *C, const Type *Ty);
489 static Constant *getBitCast (Constant *C, const Type *Ty);
491 // @brief Convenience function for getting one of the casting operations
492 // using a CastOps opcode.
493 static Constant *getCast(
494 unsigned ops, ///< The opcode for the conversion
495 Constant *C, ///< The constant to be converted
496 const Type *Ty ///< The type to which the constant is converted
499 // @brief Create a ZExt or BitCast cast constant expression
500 static Constant *getZExtOrBitCast(
501 Constant *C, ///< The constant to zext or bitcast
502 const Type *Ty ///< The type to zext or bitcast C to
505 // @brief Create a SExt or BitCast cast constant expression
506 static Constant *getSExtOrBitCast(
507 Constant *C, ///< The constant to sext or bitcast
508 const Type *Ty ///< The type to sext or bitcast C to
511 // @brief Create a Trunc or BitCast cast constant expression
512 static Constant *getTruncOrBitCast(
513 Constant *C, ///< The constant to trunc or bitcast
514 const Type *Ty ///< The type to trunc or bitcast C to
517 /// @brief Create a BitCast or a PtrToInt cast constant expression
518 static Constant *getPointerCast(
519 Constant *C, ///< The pointer value to be casted (operand 0)
520 const Type *Ty ///< The type to which cast should be made
523 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
524 static Constant *getIntegerCast(
525 Constant *C, ///< The integer constant to be casted
526 const Type *Ty, ///< The integer type to cast to
527 bool isSigned ///< Whether C should be treated as signed or not
530 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
531 static Constant *getFPCast(
532 Constant *C, ///< The integer constant to be casted
533 const Type *Ty ///< The integer type to cast to
536 /// @brief Return true if this is a convert constant expression
539 /// @brief Return true if this is a compare constant expression
540 bool isCompare() const;
542 /// Select constant expr
544 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
545 return getSelectTy(V1->getType(), C, V1, V2);
548 /// getSizeOf constant expr - computes the size of a type in a target
549 /// independent way (Note: the return type is a ULong).
551 static Constant *getSizeOf(const Type *Ty);
553 /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
554 /// return a pointer to a pointer of the array element type.
555 static Constant *getPtrPtrFromArrayPtr(Constant *C);
557 /// ConstantExpr::get - Return a binary or shift operator constant expression,
558 /// folding if possible.
560 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
562 /// @brief Return an ICmp or FCmp comparison operator constant expression.
563 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
565 /// ConstantExpr::get* - Return some common constants without having to
566 /// specify the full Instruction::OPCODE identifier.
568 static Constant *getNeg(Constant *C);
569 static Constant *getNot(Constant *C);
570 static Constant *getAdd(Constant *C1, Constant *C2);
571 static Constant *getSub(Constant *C1, Constant *C2);
572 static Constant *getMul(Constant *C1, Constant *C2);
573 static Constant *getUDiv(Constant *C1, Constant *C2);
574 static Constant *getSDiv(Constant *C1, Constant *C2);
575 static Constant *getFDiv(Constant *C1, Constant *C2);
576 static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
577 static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
578 static Constant *getFRem(Constant *C1, Constant *C2);
579 static Constant *getAnd(Constant *C1, Constant *C2);
580 static Constant *getOr(Constant *C1, Constant *C2);
581 static Constant *getXor(Constant *C1, Constant *C2);
582 static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS);
583 static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS);
584 static Constant *getShl(Constant *C1, Constant *C2);
585 static Constant *getLShr(Constant *C1, Constant *C2);
586 static Constant *getAShr(Constant *C1, Constant *C2);
588 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
589 /// all elements must be Constant's.
591 static Constant *getGetElementPtr(Constant *C,
592 Constant* const *IdxList, unsigned NumIdx);
593 static Constant *getGetElementPtr(Constant *C,
594 Value* const *IdxList, unsigned NumIdx);
596 // FIXME: Remove these.
597 static Constant *getGetElementPtr(Constant *C,
598 const std::vector<Constant*> &IdxList) {
599 return getGetElementPtr(C, &IdxList[0], IdxList.size());
601 static Constant *getGetElementPtr(Constant *C,
602 const std::vector<Value*> &IdxList) {
603 return getGetElementPtr(C, &IdxList[0], IdxList.size());
606 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
607 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
608 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
610 /// Floating point negation must be implemented with f(x) = -0.0 - x. This
611 /// method returns the negative zero constant for floating point or packed
612 /// floating point types; for all other types, it returns the null value.
613 static Constant *getZeroValueForNegationExpr(const Type *Ty);
615 /// isNullValue - Return true if this is the value that would be returned by
617 virtual bool isNullValue() const { return false; }
619 /// getOpcode - Return the opcode at the root of this constant expression
620 unsigned getOpcode() const { return SubclassData; }
622 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
623 /// not an ICMP or FCMP constant expression.
624 unsigned getPredicate() const;
626 /// getOpcodeName - Return a string representation for an opcode.
627 const char *getOpcodeName() const;
629 /// getWithOperandReplaced - Return a constant expression identical to this
630 /// one, but with the specified operand set to the specified value.
631 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
633 /// getWithOperands - This returns the current constant expression with the
634 /// operands replaced with the specified values. The specified operands must
635 /// match count and type with the existing ones.
636 Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
638 virtual void destroyConstant();
639 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
641 /// Override methods to provide more type information...
642 inline Constant *getOperand(unsigned i) {
643 return cast<Constant>(User::getOperand(i));
645 inline Constant *getOperand(unsigned i) const {
646 return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
650 /// Methods for support type inquiry through isa, cast, and dyn_cast:
651 static inline bool classof(const ConstantExpr *) { return true; }
652 static inline bool classof(const Value *V) {
653 return V->getValueType() == ConstantExprVal;
658 //===----------------------------------------------------------------------===//
659 /// UndefValue - 'undef' values are things that do not have specified contents.
660 /// These are used for a variety of purposes, including global variable
661 /// initializers and operands to instructions. 'undef' values can occur with
664 class UndefValue : public Constant {
665 friend struct ConstantCreator<UndefValue, Type, char>;
666 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
668 UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
670 /// get() - Static factory methods - Return an 'undef' object of the specified
673 static UndefValue *get(const Type *T);
675 /// isNullValue - Return true if this is the value that would be returned by
677 virtual bool isNullValue() const { return false; }
679 virtual void destroyConstant();
681 /// Methods for support type inquiry through isa, cast, and dyn_cast:
682 static inline bool classof(const UndefValue *) { return true; }
683 static bool classof(const Value *V) {
684 return V->getValueType() == UndefValueVal;
688 } // End llvm namespace