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"
25 #include "llvm/ADT/APInt.h"
34 template<class ConstantClass, class TypeClass, class ValType>
35 struct ConstantCreator;
36 template<class ConstantClass, class TypeClass>
37 struct ConvertConstantType;
39 //===----------------------------------------------------------------------===//
40 /// This is the shared class of boolean and integer constants. This class
41 /// represents both boolean and integral constants.
42 /// @brief Class for constant integers.
43 class ConstantInt : public Constant {
44 static ConstantInt *TheTrueVal, *TheFalseVal;
45 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
46 ConstantInt(const IntegerType *Ty, const APInt& V);
49 /// Return the constant as an APInt value reference. This allows clients to
50 /// obtain a copy of the value, with all its precision in tact.
51 /// @brief Return the constant's value.
52 inline const APInt& getValue() const {
56 /// Return the constant as a 64-bit unsigned integer value after it
57 /// has been zero extended as appropriate for the type of this constant. Note
58 /// that this method can assert if the value does not fit in 64 bits.
60 /// @brief Return the zero extended value.
61 inline uint64_t getZExtValue() const {
62 return Val.getZExtValue();
65 /// Return the constant as a 64-bit integer value after it has been sign
66 /// sign extended as appropriate for the type of this constant. Note that
67 /// this method can assert if the value does not fit in 64 bits.
69 /// @brief Return the sign extended value.
70 inline int64_t getSExtValue() const {
71 return Val.getSExtValue();
74 /// A helper method that can be used to determine if the constant contained
75 /// within is equal to a constant. This only works for very small values,
76 /// because this is all that can be represented with all types.
77 /// @brief Determine if this constant's value is same as an unsigned char.
78 bool equalsInt(uint64_t V) const {
82 /// getTrue/getFalse - Return the singleton true/false values.
83 static inline ConstantInt *getTrue() {
84 if (TheTrueVal) return TheTrueVal;
85 return CreateTrueFalseVals(true);
87 static inline ConstantInt *getFalse() {
88 if (TheFalseVal) return TheFalseVal;
89 return CreateTrueFalseVals(false);
92 /// Return a ConstantInt with the specified value for the specified type. The
93 /// value V will be canonicalized to a an unsigned APInt. Accessing it with
94 /// either getSExtValue() or getZExtValue() will yield a correctly sized and
95 /// signed value for the type Ty.
96 /// @brief Get a ConstantInt for a specific value.
97 static ConstantInt *get(const Type *Ty, uint64_t V, bool isSigned = false);
99 /// Return a ConstantInt with the specified value and an implied Type. The
100 /// type is the integer type that corresponds to the bit width of the value.
101 static ConstantInt *get(const APInt &V);
103 /// getType - Specialize the getType() method to always return an IntegerType,
104 /// which reduces the amount of casting needed in parts of the compiler.
106 inline const IntegerType *getType() const {
107 return reinterpret_cast<const IntegerType*>(Value::getType());
110 /// This static method returns true if the type Ty is big enough to
111 /// represent the value V. This can be used to avoid having the get method
112 /// assert when V is larger than Ty can represent. Note that there are two
113 /// versions of this method, one for unsigned and one for signed integers.
114 /// Although ConstantInt canonicalizes everything to an unsigned integer,
115 /// the signed version avoids callers having to convert a signed quantity
116 /// to the appropriate unsigned type before calling the method.
117 /// @returns true if V is a valid value for type Ty
118 /// @brief Determine if the value is in range for the given type.
119 static bool isValueValidForType(const Type *Ty, uint64_t V);
120 static bool isValueValidForType(const Type *Ty, int64_t V);
122 /// This function will return true iff this constant represents the "null"
123 /// value that would be returned by the getNullValue method.
124 /// @returns true if this is the null integer value.
125 /// @brief Determine if the value is null.
126 virtual bool isNullValue() const {
130 /// This is just a convenience method to make client code smaller for a
131 /// common code. It also correctly performs the comparison without the
132 /// potential for an assertion from getZExtValue().
133 bool isZero() const {
137 /// This is just a convenience method to make client code smaller for a
138 /// common case. It also correctly performs the comparison without the
139 /// potential for an assertion from getZExtValue().
140 /// @brief Determine if the value is one.
145 /// This function will return true iff every bit in this constant is set
147 /// @returns true iff this constant's bits are all set to true.
148 /// @brief Determine if the value is all ones.
149 bool isAllOnesValue() const {
150 return Val.isAllOnesValue();
153 /// This function will return true iff this constant represents the largest
154 /// value that may be represented by the constant's type.
155 /// @returns true iff this is the largest value that may be represented
157 /// @brief Determine if the value is maximal.
158 bool isMaxValue(bool isSigned) const {
160 return Val.isMaxSignedValue();
162 return Val.isMaxValue();
165 /// This function will return true iff this constant represents the smallest
166 /// value that may be represented by this constant's type.
167 /// @returns true if this is the smallest value that may be represented by
169 /// @brief Determine if the value is minimal.
170 bool isMinValue(bool isSigned) const {
172 return Val.isMinSignedValue();
174 return Val.isMinValue();
177 /// This function will return true iff this constant represents a value with
178 /// active bits bigger than 64 bits or a value greater than the given uint64_t
180 /// @returns true iff this constant is greater or equal to the given number.
181 /// @brief Determine if the value is greater or equal to the given number.
182 bool uge(uint64_t Num) {
183 return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
186 /// @returns the 64-bit value of this constant if its active bits number is
187 /// not greater than 64, otherwise, just return the given uint64_t number.
188 /// @brief Get the constant's value if possible.
189 uint64_t getLimitedValue(uint64_t Limit) {
190 return (Val.getActiveBits() > 64 || Val.getZExtValue() > Limit) ?
191 Limit : Val.getZExtValue();
194 /// @returns the value for an integer constant of the given type that has all
195 /// its bits set to true.
196 /// @brief Get the all ones value
197 static ConstantInt *getAllOnesValue(const Type *Ty);
199 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
200 static inline bool classof(const ConstantInt *) { return true; }
201 static bool classof(const Value *V) {
202 return V->getValueType() == ConstantIntVal;
204 static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
206 static ConstantInt *CreateTrueFalseVals(bool WhichOne);
210 //===----------------------------------------------------------------------===//
211 /// ConstantFP - Floating Point Values [float, double]
213 class ConstantFP : public Constant {
215 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
217 ConstantFP(const Type *Ty, double V);
219 /// get() - Static factory methods - Return objects of the specified value
220 static ConstantFP *get(const Type *Ty, double V);
222 /// isValueValidForType - return true if Ty is big enough to represent V.
223 static bool isValueValidForType(const Type *Ty, double V);
224 inline double getValue() const { return Val; }
226 /// isNullValue - Return true if this is the value that would be returned by
227 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
228 /// considers -0.0 to be null as well as 0.0. :(
229 virtual bool isNullValue() const;
231 /// isExactlyValue - We don't rely on operator== working on double values, as
232 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
233 /// As such, this method can be used to do an exact bit-for-bit comparison of
234 /// two floating point values.
235 bool isExactlyValue(double V) const;
237 /// Methods for support type inquiry through isa, cast, and dyn_cast:
238 static inline bool classof(const ConstantFP *) { return true; }
239 static bool classof(const Value *V) {
240 return V->getValueType() == ConstantFPVal;
244 //===----------------------------------------------------------------------===//
245 /// ConstantAggregateZero - All zero aggregate value
247 class ConstantAggregateZero : public Constant {
248 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
249 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
251 explicit ConstantAggregateZero(const Type *Ty)
252 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
254 /// get() - static factory method for creating a null aggregate. It is
255 /// illegal to call this method with a non-aggregate type.
256 static Constant *get(const Type *Ty);
258 /// isNullValue - Return true if this is the value that would be returned by
260 virtual bool isNullValue() const { return true; }
262 virtual void destroyConstant();
264 /// Methods for support type inquiry through isa, cast, and dyn_cast:
266 static bool classof(const ConstantAggregateZero *) { return true; }
267 static bool classof(const Value *V) {
268 return V->getValueType() == ConstantAggregateZeroVal;
273 //===----------------------------------------------------------------------===//
274 /// ConstantArray - Constant Array Declarations
276 class ConstantArray : public Constant {
277 friend struct ConstantCreator<ConstantArray, ArrayType,
278 std::vector<Constant*> >;
279 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
281 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
284 /// get() - Static factory methods - Return objects of the specified value
285 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
286 static Constant *get(const ArrayType *T,
287 Constant*const*Vals, unsigned NumVals) {
288 // FIXME: make this the primary ctor method.
289 return get(T, std::vector<Constant*>(Vals, Vals+NumVals));
292 /// This method constructs a ConstantArray and initializes it with a text
293 /// string. The default behavior (AddNull==true) causes a null terminator to
294 /// be placed at the end of the array. This effectively increases the length
295 /// of the array by one (you've been warned). However, in some situations
296 /// this is not desired so if AddNull==false then the string is copied without
297 /// null termination.
298 static Constant *get(const std::string &Initializer, bool AddNull = true);
300 /// getType - Specialize the getType() method to always return an ArrayType,
301 /// which reduces the amount of casting needed in parts of the compiler.
303 inline const ArrayType *getType() const {
304 return reinterpret_cast<const ArrayType*>(Value::getType());
307 /// isString - This method returns true if the array is an array of sbyte or
308 /// ubyte, and if the elements of the array are all ConstantInt's.
309 bool isString() const;
311 /// isCString - This method returns true if the array is a string (see
312 /// isString) and it ends in a null byte \0 and does not contains any other
313 /// null bytes except its terminator.
314 bool isCString() const;
316 /// getAsString - If this array is isString(), then this method converts the
317 /// array to an std::string and returns it. Otherwise, it asserts out.
319 std::string getAsString() const;
321 /// isNullValue - Return true if this is the value that would be returned by
322 /// getNullValue. This always returns false because zero arrays are always
323 /// created as ConstantAggregateZero objects.
324 virtual bool isNullValue() const { return false; }
326 virtual void destroyConstant();
327 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
329 /// Methods for support type inquiry through isa, cast, and dyn_cast:
330 static inline bool classof(const ConstantArray *) { return true; }
331 static bool classof(const Value *V) {
332 return V->getValueType() == ConstantArrayVal;
337 //===----------------------------------------------------------------------===//
338 // ConstantStruct - Constant Struct Declarations
340 class ConstantStruct : public Constant {
341 friend struct ConstantCreator<ConstantStruct, StructType,
342 std::vector<Constant*> >;
343 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
345 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
348 /// get() - Static factory methods - Return objects of the specified value
350 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
351 static Constant *get(const std::vector<Constant*> &V, bool Packed = false);
352 static Constant *get(Constant*const* Vals, unsigned NumVals,
353 bool Packed = false) {
354 // FIXME: make this the primary ctor method.
355 return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
358 /// getType() specialization - Reduce amount of casting...
360 inline const StructType *getType() const {
361 return reinterpret_cast<const StructType*>(Value::getType());
364 /// isNullValue - Return true if this is the value that would be returned by
365 /// getNullValue. This always returns false because zero structs are always
366 /// created as ConstantAggregateZero objects.
367 virtual bool isNullValue() const {
371 virtual void destroyConstant();
372 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
374 /// Methods for support type inquiry through isa, cast, and dyn_cast:
375 static inline bool classof(const ConstantStruct *) { return true; }
376 static bool classof(const Value *V) {
377 return V->getValueType() == ConstantStructVal;
381 //===----------------------------------------------------------------------===//
382 /// ConstantVector - Constant Vector Declarations
384 class ConstantVector : public Constant {
385 friend struct ConstantCreator<ConstantVector, VectorType,
386 std::vector<Constant*> >;
387 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
389 ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
392 /// get() - Static factory methods - Return objects of the specified value
393 static Constant *get(const VectorType *T, const std::vector<Constant*> &);
394 static Constant *get(const std::vector<Constant*> &V);
395 static Constant *get(Constant*const* Vals, unsigned NumVals) {
396 // FIXME: make this the primary ctor method.
397 return get(std::vector<Constant*>(Vals, Vals+NumVals));
400 /// getType - Specialize the getType() method to always return an VectorType,
401 /// which reduces the amount of casting needed in parts of the compiler.
403 inline const VectorType *getType() const {
404 return reinterpret_cast<const VectorType*>(Value::getType());
407 /// @returns the value for an packed integer constant of the given type that
408 /// has all its bits set to true.
409 /// @brief Get the all ones value
410 static ConstantVector *getAllOnesValue(const VectorType *Ty);
412 /// isNullValue - Return true if this is the value that would be returned by
413 /// getNullValue. This always returns false because zero arrays are always
414 /// created as ConstantAggregateZero objects.
415 virtual bool isNullValue() const { return false; }
417 /// This function will return true iff every element in this packed constant
418 /// is set to all ones.
419 /// @returns true iff this constant's emements are all set to all ones.
420 /// @brief Determine if the value is all ones.
421 bool isAllOnesValue() const;
423 virtual void destroyConstant();
424 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
426 /// Methods for support type inquiry through isa, cast, and dyn_cast:
427 static inline bool classof(const ConstantVector *) { return true; }
428 static bool classof(const Value *V) {
429 return V->getValueType() == ConstantVectorVal;
433 //===----------------------------------------------------------------------===//
434 /// ConstantPointerNull - a constant pointer value that points to null
436 class ConstantPointerNull : public Constant {
437 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
438 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
440 explicit ConstantPointerNull(const PointerType *T)
441 : Constant(reinterpret_cast<const Type*>(T),
442 Value::ConstantPointerNullVal, 0, 0) {}
446 /// get() - Static factory methods - Return objects of the specified value
447 static ConstantPointerNull *get(const PointerType *T);
449 /// isNullValue - Return true if this is the value that would be returned by
451 virtual bool isNullValue() const { return true; }
453 virtual void destroyConstant();
455 /// getType - Specialize the getType() method to always return an PointerType,
456 /// which reduces the amount of casting needed in parts of the compiler.
458 inline const PointerType *getType() const {
459 return reinterpret_cast<const PointerType*>(Value::getType());
462 /// Methods for support type inquiry through isa, cast, and dyn_cast:
463 static inline bool classof(const ConstantPointerNull *) { return true; }
464 static bool classof(const Value *V) {
465 return V->getValueType() == ConstantPointerNullVal;
470 /// ConstantExpr - a constant value that is initialized with an expression using
471 /// other constant values.
473 /// This class uses the standard Instruction opcodes to define the various
474 /// constant expressions. The Opcode field for the ConstantExpr class is
475 /// maintained in the Value::SubclassData field.
476 class ConstantExpr : public Constant {
477 friend struct ConstantCreator<ConstantExpr,Type,
478 std::pair<unsigned, std::vector<Constant*> > >;
479 friend struct ConvertConstantType<ConstantExpr, Type>;
482 ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
483 : Constant(Ty, ConstantExprVal, Ops, NumOps) {
484 // Operation type (an Instruction opcode) is stored as the SubclassData.
485 SubclassData = Opcode;
488 // These private methods are used by the type resolution code to create
489 // ConstantExprs in intermediate forms.
490 static Constant *getTy(const Type *Ty, unsigned Opcode,
491 Constant *C1, Constant *C2);
492 static Constant *getCompareTy(unsigned short pred, Constant *C1,
494 static Constant *getSelectTy(const Type *Ty,
495 Constant *C1, Constant *C2, Constant *C3);
496 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
497 Value* const *Idxs, unsigned NumIdxs);
498 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
500 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
501 Constant *Elt, Constant *Idx);
502 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
503 Constant *V2, Constant *Mask);
506 // Static methods to construct a ConstantExpr of different kinds. Note that
507 // these methods may return a object that is not an instance of the
508 // ConstantExpr class, because they will attempt to fold the constant
509 // expression into something simpler if possible.
511 /// Cast constant expr
513 static Constant *getTrunc (Constant *C, const Type *Ty);
514 static Constant *getSExt (Constant *C, const Type *Ty);
515 static Constant *getZExt (Constant *C, const Type *Ty);
516 static Constant *getFPTrunc (Constant *C, const Type *Ty);
517 static Constant *getFPExtend(Constant *C, const Type *Ty);
518 static Constant *getUIToFP (Constant *C, const Type *Ty);
519 static Constant *getSIToFP (Constant *C, const Type *Ty);
520 static Constant *getFPToUI (Constant *C, const Type *Ty);
521 static Constant *getFPToSI (Constant *C, const Type *Ty);
522 static Constant *getPtrToInt(Constant *C, const Type *Ty);
523 static Constant *getIntToPtr(Constant *C, const Type *Ty);
524 static Constant *getBitCast (Constant *C, const Type *Ty);
526 // @brief Convenience function for getting one of the casting operations
527 // using a CastOps opcode.
528 static Constant *getCast(
529 unsigned ops, ///< The opcode for the conversion
530 Constant *C, ///< The constant to be converted
531 const Type *Ty ///< The type to which the constant is converted
534 // @brief Create a ZExt or BitCast cast constant expression
535 static Constant *getZExtOrBitCast(
536 Constant *C, ///< The constant to zext or bitcast
537 const Type *Ty ///< The type to zext or bitcast C to
540 // @brief Create a SExt or BitCast cast constant expression
541 static Constant *getSExtOrBitCast(
542 Constant *C, ///< The constant to sext or bitcast
543 const Type *Ty ///< The type to sext or bitcast C to
546 // @brief Create a Trunc or BitCast cast constant expression
547 static Constant *getTruncOrBitCast(
548 Constant *C, ///< The constant to trunc or bitcast
549 const Type *Ty ///< The type to trunc or bitcast C to
552 /// @brief Create a BitCast or a PtrToInt cast constant expression
553 static Constant *getPointerCast(
554 Constant *C, ///< The pointer value to be casted (operand 0)
555 const Type *Ty ///< The type to which cast should be made
558 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
559 static Constant *getIntegerCast(
560 Constant *C, ///< The integer constant to be casted
561 const Type *Ty, ///< The integer type to cast to
562 bool isSigned ///< Whether C should be treated as signed or not
565 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
566 static Constant *getFPCast(
567 Constant *C, ///< The integer constant to be casted
568 const Type *Ty ///< The integer type to cast to
571 /// @brief Return true if this is a convert constant expression
574 /// @brief Return true if this is a compare constant expression
575 bool isCompare() const;
577 /// Select constant expr
579 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
580 return getSelectTy(V1->getType(), C, V1, V2);
583 /// getSizeOf constant expr - computes the size of a type in a target
584 /// independent way (Note: the return type is a ULong).
586 static Constant *getSizeOf(const Type *Ty);
588 /// ConstantExpr::get - Return a binary or shift operator constant expression,
589 /// folding if possible.
591 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
593 /// @brief Return an ICmp or FCmp comparison operator constant expression.
594 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
596 /// ConstantExpr::get* - Return some common constants without having to
597 /// specify the full Instruction::OPCODE identifier.
599 static Constant *getNeg(Constant *C);
600 static Constant *getNot(Constant *C);
601 static Constant *getAdd(Constant *C1, Constant *C2);
602 static Constant *getSub(Constant *C1, Constant *C2);
603 static Constant *getMul(Constant *C1, Constant *C2);
604 static Constant *getUDiv(Constant *C1, Constant *C2);
605 static Constant *getSDiv(Constant *C1, Constant *C2);
606 static Constant *getFDiv(Constant *C1, Constant *C2);
607 static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
608 static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
609 static Constant *getFRem(Constant *C1, Constant *C2);
610 static Constant *getAnd(Constant *C1, Constant *C2);
611 static Constant *getOr(Constant *C1, Constant *C2);
612 static Constant *getXor(Constant *C1, Constant *C2);
613 static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS);
614 static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS);
615 static Constant *getShl(Constant *C1, Constant *C2);
616 static Constant *getLShr(Constant *C1, Constant *C2);
617 static Constant *getAShr(Constant *C1, Constant *C2);
619 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
620 /// all elements must be Constant's.
622 static Constant *getGetElementPtr(Constant *C,
623 Constant* const *IdxList, unsigned NumIdx);
624 static Constant *getGetElementPtr(Constant *C,
625 Value* const *IdxList, unsigned NumIdx);
627 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
628 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
629 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
631 /// Floating point negation must be implemented with f(x) = -0.0 - x. This
632 /// method returns the negative zero constant for floating point or packed
633 /// floating point types; for all other types, it returns the null value.
634 static Constant *getZeroValueForNegationExpr(const Type *Ty);
636 /// isNullValue - Return true if this is the value that would be returned by
638 virtual bool isNullValue() const { return false; }
640 /// getOpcode - Return the opcode at the root of this constant expression
641 unsigned getOpcode() const { return SubclassData; }
643 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
644 /// not an ICMP or FCMP constant expression.
645 unsigned getPredicate() const;
647 /// getOpcodeName - Return a string representation for an opcode.
648 const char *getOpcodeName() const;
650 /// getWithOperandReplaced - Return a constant expression identical to this
651 /// one, but with the specified operand set to the specified value.
652 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
654 /// getWithOperands - This returns the current constant expression with the
655 /// operands replaced with the specified values. The specified operands must
656 /// match count and type with the existing ones.
657 Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
659 virtual void destroyConstant();
660 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
662 /// Override methods to provide more type information...
663 inline Constant *getOperand(unsigned i) {
664 return cast<Constant>(User::getOperand(i));
666 inline Constant *getOperand(unsigned i) const {
667 return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
671 /// Methods for support type inquiry through isa, cast, and dyn_cast:
672 static inline bool classof(const ConstantExpr *) { return true; }
673 static inline bool classof(const Value *V) {
674 return V->getValueType() == ConstantExprVal;
679 //===----------------------------------------------------------------------===//
680 /// UndefValue - 'undef' values are things that do not have specified contents.
681 /// These are used for a variety of purposes, including global variable
682 /// initializers and operands to instructions. 'undef' values can occur with
685 class UndefValue : public Constant {
686 friend struct ConstantCreator<UndefValue, Type, char>;
687 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
689 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
691 /// get() - Static factory methods - Return an 'undef' object of the specified
694 static UndefValue *get(const Type *T);
696 /// isNullValue - Return true if this is the value that would be returned by
698 virtual bool isNullValue() const { return false; }
700 virtual void destroyConstant();
702 /// Methods for support type inquiry through isa, cast, and dyn_cast:
703 static inline bool classof(const UndefValue *) { return true; }
704 static bool classof(const Value *V) {
705 return V->getValueType() == UndefValueVal;
709 } // End llvm namespace