1 //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
19 //===----------------------------------------------------------------------===//
21 #ifndef LLVM_CONSTANTS_H
22 #define LLVM_CONSTANTS_H
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"
38 template<class ConstantClass, class TypeClass, class ValType>
39 struct ConstantCreator;
40 template<class ConstantClass, class TypeClass>
41 struct ConvertConstantType;
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);
53 friend class LLVMContextImpl;
55 // allocate space for exactly zero operands
56 void *operator new(size_t s) {
57 return User::operator new(s, 0);
60 /// If Ty is a vector type, return a Constant with a splat of the given
61 /// value. Otherwise return a ConstantInt for the given value.
62 static Constant* get(const Type* Ty, uint64_t V, bool isSigned = false);
64 /// Return a ConstantInt with the specified integer value for the specified
65 /// type. If the type is wider than 64 bits, the value will be zero-extended
66 /// to fit the type, unless isSigned is true, in which case the value will
67 /// be interpreted as a 64-bit signed integer and sign-extended to fit
69 /// @brief Get a ConstantInt for a specific value.
70 static ConstantInt* get(const IntegerType* Ty, uint64_t V,
71 bool isSigned = false);
73 /// Return a ConstantInt with the specified value for the specified type. The
74 /// value V will be canonicalized to a an unsigned APInt. Accessing it with
75 /// either getSExtValue() or getZExtValue() will yield a correctly sized and
76 /// signed value for the type Ty.
77 /// @brief Get a ConstantInt for a specific signed value.
78 static ConstantInt* getSigned(const IntegerType* Ty, int64_t V);
79 static Constant *getSigned(const Type *Ty, int64_t V);
81 /// Return a ConstantInt with the specified value and an implied Type. The
82 /// type is the integer type that corresponds to the bit width of the value.
83 static ConstantInt* get(LLVMContext &Context, const APInt& V);
85 /// If Ty is a vector type, return a Constant with a splat of the given
86 /// value. Otherwise return a ConstantInt for the given value.
87 static Constant* get(const Type* Ty, const APInt& V);
89 /// Return the constant as an APInt value reference. This allows clients to
90 /// obtain a copy of the value, with all its precision in tact.
91 /// @brief Return the constant's value.
92 inline const APInt& getValue() const {
96 /// getBitWidth - Return the bitwidth of this constant.
97 unsigned getBitWidth() const { return Val.getBitWidth(); }
99 /// Return the constant as a 64-bit unsigned integer value after it
100 /// has been zero extended as appropriate for the type of this constant. Note
101 /// that this method can assert if the value does not fit in 64 bits.
103 /// @brief Return the zero extended value.
104 inline uint64_t getZExtValue() const {
105 return Val.getZExtValue();
108 /// Return the constant as a 64-bit integer value after it has been sign
109 /// extended as appropriate for the type of this constant. Note that
110 /// this method can assert if the value does not fit in 64 bits.
112 /// @brief Return the sign extended value.
113 inline int64_t getSExtValue() const {
114 return Val.getSExtValue();
117 /// A helper method that can be used to determine if the constant contained
118 /// within is equal to a constant. This only works for very small values,
119 /// because this is all that can be represented with all types.
120 /// @brief Determine if this constant's value is same as an unsigned char.
121 bool equalsInt(uint64_t V) const {
125 /// getType - Specialize the getType() method to always return an IntegerType,
126 /// which reduces the amount of casting needed in parts of the compiler.
128 inline const IntegerType *getType() const {
129 return reinterpret_cast<const IntegerType*>(Value::getType());
132 /// This static method returns true if the type Ty is big enough to
133 /// represent the value V. This can be used to avoid having the get method
134 /// assert when V is larger than Ty can represent. Note that there are two
135 /// versions of this method, one for unsigned and one for signed integers.
136 /// Although ConstantInt canonicalizes everything to an unsigned integer,
137 /// the signed version avoids callers having to convert a signed quantity
138 /// to the appropriate unsigned type before calling the method.
139 /// @returns true if V is a valid value for type Ty
140 /// @brief Determine if the value is in range for the given type.
141 static bool isValueValidForType(const Type *Ty, uint64_t V);
142 static bool isValueValidForType(const Type *Ty, int64_t V);
144 /// This function will return true iff this constant represents the "null"
145 /// value that would be returned by the getNullValue method.
146 /// @returns true if this is the null integer value.
147 /// @brief Determine if the value is null.
148 virtual bool isNullValue() const {
152 /// This is just a convenience method to make client code smaller for a
153 /// common code. It also correctly performs the comparison without the
154 /// potential for an assertion from getZExtValue().
155 bool isZero() const {
159 /// This is just a convenience method to make client code smaller for a
160 /// common case. It also correctly performs the comparison without the
161 /// potential for an assertion from getZExtValue().
162 /// @brief Determine if the value is one.
167 /// This function will return true iff every bit in this constant is set
169 /// @returns true iff this constant's bits are all set to true.
170 /// @brief Determine if the value is all ones.
171 bool isAllOnesValue() const {
172 return Val.isAllOnesValue();
175 /// This function will return true iff this constant represents the largest
176 /// value that may be represented by the constant's type.
177 /// @returns true iff this is the largest value that may be represented
179 /// @brief Determine if the value is maximal.
180 bool isMaxValue(bool isSigned) const {
182 return Val.isMaxSignedValue();
184 return Val.isMaxValue();
187 /// This function will return true iff this constant represents the smallest
188 /// value that may be represented by this constant's type.
189 /// @returns true if this is the smallest value that may be represented by
191 /// @brief Determine if the value is minimal.
192 bool isMinValue(bool isSigned) const {
194 return Val.isMinSignedValue();
196 return Val.isMinValue();
199 /// This function will return true iff this constant represents a value with
200 /// active bits bigger than 64 bits or a value greater than the given uint64_t
202 /// @returns true iff this constant is greater or equal to the given number.
203 /// @brief Determine if the value is greater or equal to the given number.
204 bool uge(uint64_t Num) {
205 return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
208 /// getLimitedValue - If the value is smaller than the specified limit,
209 /// return it, otherwise return the limit value. This causes the value
210 /// to saturate to the limit.
211 /// @returns the min of the value of the constant and the specified value
212 /// @brief Get the constant's value with a saturation limit
213 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
214 return Val.getLimitedValue(Limit);
217 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
218 static inline bool classof(const ConstantInt *) { return true; }
219 static bool classof(const Value *V) {
220 return V->getValueID() == ConstantIntVal;
225 //===----------------------------------------------------------------------===//
226 /// ConstantFP - Floating Point Values [float, double]
228 class ConstantFP : public Constant {
230 void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
231 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
232 friend class LLVMContextImpl;
234 ConstantFP(const Type *Ty, const APFloat& V);
236 // allocate space for exactly zero operands
237 void *operator new(size_t s) {
238 return User::operator new(s, 0);
241 /// isValueValidForType - return true if Ty is big enough to represent V.
242 static bool isValueValidForType(const Type *Ty, const APFloat& V);
243 inline const APFloat& getValueAPF() const { return Val; }
245 /// isNullValue - Return true if this is the value that would be returned by
246 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
247 /// considers -0.0 to be null as well as 0.0. :(
248 virtual bool isNullValue() const;
250 /// isNegativeZeroValue - Return true if the value is what would be returned
251 /// by getZeroValueForNegation.
252 virtual bool isNegativeZeroValue() const {
253 return Val.isZero() && Val.isNegative();
256 /// isExactlyValue - We don't rely on operator== working on double values, as
257 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
258 /// As such, this method can be used to do an exact bit-for-bit comparison of
259 /// two floating point values. The version with a double operand is retained
260 /// because it's so convenient to write isExactlyValue(2.0), but please use
261 /// it only for simple constants.
262 bool isExactlyValue(const APFloat& V) const;
264 bool isExactlyValue(double V) const {
266 // convert is not supported on this type
267 if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
270 FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
271 return isExactlyValue(FV);
273 /// Methods for support type inquiry through isa, cast, and dyn_cast:
274 static inline bool classof(const ConstantFP *) { return true; }
275 static bool classof(const Value *V) {
276 return V->getValueID() == ConstantFPVal;
280 //===----------------------------------------------------------------------===//
281 /// ConstantAggregateZero - All zero aggregate value
283 class ConstantAggregateZero : public Constant {
284 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
285 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
286 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
288 explicit ConstantAggregateZero(const Type *ty)
289 : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
291 // allocate space for exactly zero operands
292 void *operator new(size_t s) {
293 return User::operator new(s, 0);
296 /// isNullValue - Return true if this is the value that would be returned by
298 virtual bool isNullValue() const { return true; }
300 virtual void destroyConstant();
302 /// Methods for support type inquiry through isa, cast, and dyn_cast:
304 static bool classof(const ConstantAggregateZero *) { return true; }
305 static bool classof(const Value *V) {
306 return V->getValueID() == ConstantAggregateZeroVal;
311 //===----------------------------------------------------------------------===//
312 /// ConstantArray - Constant Array Declarations
314 class ConstantArray : public Constant {
315 friend struct ConstantCreator<ConstantArray, ArrayType,
316 std::vector<Constant*> >;
317 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
318 friend class LLVMContextImpl;
320 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
322 /// Transparently provide more efficient getOperand methods.
323 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
325 /// getType - Specialize the getType() method to always return an ArrayType,
326 /// which reduces the amount of casting needed in parts of the compiler.
328 inline const ArrayType *getType() const {
329 return reinterpret_cast<const ArrayType*>(Value::getType());
332 /// isString - This method returns true if the array is an array of i8 and
333 /// the elements of the array are all ConstantInt's.
334 bool isString() const;
336 /// isCString - This method returns true if the array is a string (see
338 /// isString) and it ends in a null byte \0 and does not contains any other
340 /// null bytes except its terminator.
341 bool isCString() const;
343 /// getAsString - If this array is isString(), then this method converts the
344 /// array to an std::string and returns it. Otherwise, it asserts out.
346 std::string getAsString() const;
348 /// isNullValue - Return true if this is the value that would be returned by
349 /// getNullValue. This always returns false because zero arrays are always
350 /// created as ConstantAggregateZero objects.
351 virtual bool isNullValue() const { return false; }
353 virtual void destroyConstant();
354 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
356 /// Methods for support type inquiry through isa, cast, and dyn_cast:
357 static inline bool classof(const ConstantArray *) { return true; }
358 static bool classof(const Value *V) {
359 return V->getValueID() == ConstantArrayVal;
364 struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
367 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
369 //===----------------------------------------------------------------------===//
370 // ConstantStruct - Constant Struct Declarations
372 class ConstantStruct : public Constant {
373 friend struct ConstantCreator<ConstantStruct, StructType,
374 std::vector<Constant*> >;
375 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
376 friend class LLVMContextImpl;
378 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
380 /// Transparently provide more efficient getOperand methods.
381 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
383 /// getType() specialization - Reduce amount of casting...
385 inline const StructType *getType() const {
386 return reinterpret_cast<const StructType*>(Value::getType());
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 {
396 virtual void destroyConstant();
397 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
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->getValueID() == ConstantStructVal;
407 struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
410 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
412 //===----------------------------------------------------------------------===//
413 /// ConstantVector - Constant Vector Declarations
415 class ConstantVector : public Constant {
416 friend struct ConstantCreator<ConstantVector, VectorType,
417 std::vector<Constant*> >;
418 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
420 ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
422 /// Transparently provide more efficient getOperand methods.
423 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
425 /// getType - Specialize the getType() method to always return a VectorType,
426 /// which reduces the amount of casting needed in parts of the compiler.
428 inline const VectorType *getType() const {
429 return reinterpret_cast<const VectorType*>(Value::getType());
432 /// isNullValue - Return true if this is the value that would be returned by
433 /// getNullValue. This always returns false because zero vectors are always
434 /// created as ConstantAggregateZero objects.
435 virtual bool isNullValue() const { return false; }
437 /// This function will return true iff every element in this vector constant
438 /// is set to all ones.
439 /// @returns true iff this constant's emements are all set to all ones.
440 /// @brief Determine if the value is all ones.
441 bool isAllOnesValue() const;
443 /// getSplatValue - If this is a splat constant, meaning that all of the
444 /// elements have the same value, return that value. Otherwise return NULL.
445 Constant *getSplatValue();
447 virtual void destroyConstant();
448 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
450 /// Methods for support type inquiry through isa, cast, and dyn_cast:
451 static inline bool classof(const ConstantVector *) { return true; }
452 static bool classof(const Value *V) {
453 return V->getValueID() == ConstantVectorVal;
458 struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
461 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
463 //===----------------------------------------------------------------------===//
464 /// ConstantPointerNull - a constant pointer value that points to null
466 class ConstantPointerNull : public Constant {
467 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
468 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
469 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
471 explicit ConstantPointerNull(const PointerType *T)
472 : Constant(reinterpret_cast<const Type*>(T),
473 Value::ConstantPointerNullVal, 0, 0) {}
476 // allocate space for exactly zero operands
477 void *operator new(size_t s) {
478 return User::operator new(s, 0);
481 /// get() - Static factory methods - Return objects of the specified value
482 static ConstantPointerNull *get(const PointerType *T);
484 /// isNullValue - Return true if this is the value that would be returned by
486 virtual bool isNullValue() const { return true; }
488 virtual void destroyConstant();
490 /// getType - Specialize the getType() method to always return an PointerType,
491 /// which reduces the amount of casting needed in parts of the compiler.
493 inline const PointerType *getType() const {
494 return reinterpret_cast<const PointerType*>(Value::getType());
497 /// Methods for support type inquiry through isa, cast, and dyn_cast:
498 static inline bool classof(const ConstantPointerNull *) { return true; }
499 static bool classof(const Value *V) {
500 return V->getValueID() == ConstantPointerNullVal;
505 /// ConstantExpr - a constant value that is initialized with an expression using
506 /// other constant values.
508 /// This class uses the standard Instruction opcodes to define the various
509 /// constant expressions. The Opcode field for the ConstantExpr class is
510 /// maintained in the Value::SubclassData field.
511 class ConstantExpr : public Constant {
512 friend struct ConstantCreator<ConstantExpr,Type,
513 std::pair<unsigned, std::vector<Constant*> > >;
514 friend struct ConvertConstantType<ConstantExpr, Type>;
517 ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
518 : Constant(ty, ConstantExprVal, Ops, NumOps) {
519 // Operation type (an Instruction opcode) is stored as the SubclassData.
520 SubclassData = Opcode;
523 // These private methods are used by the type resolution code to create
524 // ConstantExprs in intermediate forms.
525 static Constant *getTy(const Type *Ty, unsigned Opcode,
526 Constant *C1, Constant *C2);
527 static Constant *getCompareTy(unsigned short pred, Constant *C1,
529 static Constant *getSelectTy(const Type *Ty,
530 Constant *C1, Constant *C2, Constant *C3);
531 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
532 Value* const *Idxs, unsigned NumIdxs);
533 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
535 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
536 Constant *Elt, Constant *Idx);
537 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
538 Constant *V2, Constant *Mask);
539 static Constant *getExtractValueTy(const Type *Ty, Constant *Agg,
540 const unsigned *Idxs, unsigned NumIdxs);
541 static Constant *getInsertValueTy(const Type *Ty, Constant *Agg,
543 const unsigned *Idxs, unsigned NumIdxs);
546 // Static methods to construct a ConstantExpr of different kinds. Note that
547 // these methods may return a object that is not an instance of the
548 // ConstantExpr class, because they will attempt to fold the constant
549 // expression into something simpler if possible.
551 /// Cast constant expr
553 static Constant *getTrunc (Constant *C, const Type *Ty);
554 static Constant *getSExt (Constant *C, const Type *Ty);
555 static Constant *getZExt (Constant *C, const Type *Ty);
556 static Constant *getFPTrunc (Constant *C, const Type *Ty);
557 static Constant *getFPExtend(Constant *C, const Type *Ty);
558 static Constant *getUIToFP (Constant *C, const Type *Ty);
559 static Constant *getSIToFP (Constant *C, const Type *Ty);
560 static Constant *getFPToUI (Constant *C, const Type *Ty);
561 static Constant *getFPToSI (Constant *C, const Type *Ty);
562 static Constant *getPtrToInt(Constant *C, const Type *Ty);
563 static Constant *getIntToPtr(Constant *C, const Type *Ty);
564 static Constant *getBitCast (Constant *C, const Type *Ty);
566 /// Transparently provide more efficient getOperand methods.
567 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
569 // @brief Convenience function for getting one of the casting operations
570 // using a CastOps opcode.
571 static Constant *getCast(
572 unsigned ops, ///< The opcode for the conversion
573 Constant *C, ///< The constant to be converted
574 const Type *Ty ///< The type to which the constant is converted
577 // @brief Create a ZExt or BitCast cast constant expression
578 static Constant *getZExtOrBitCast(
579 Constant *C, ///< The constant to zext or bitcast
580 const Type *Ty ///< The type to zext or bitcast C to
583 // @brief Create a SExt or BitCast cast constant expression
584 static Constant *getSExtOrBitCast(
585 Constant *C, ///< The constant to sext or bitcast
586 const Type *Ty ///< The type to sext or bitcast C to
589 // @brief Create a Trunc or BitCast cast constant expression
590 static Constant *getTruncOrBitCast(
591 Constant *C, ///< The constant to trunc or bitcast
592 const Type *Ty ///< The type to trunc or bitcast C to
595 /// @brief Create a BitCast or a PtrToInt cast constant expression
596 static Constant *getPointerCast(
597 Constant *C, ///< The pointer value to be casted (operand 0)
598 const Type *Ty ///< The type to which cast should be made
601 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
602 static Constant *getIntegerCast(
603 Constant *C, ///< The integer constant to be casted
604 const Type *Ty, ///< The integer type to cast to
605 bool isSigned ///< Whether C should be treated as signed or not
608 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
609 static Constant *getFPCast(
610 Constant *C, ///< The integer constant to be casted
611 const Type *Ty ///< The integer type to cast to
614 /// @brief Return true if this is a convert constant expression
617 /// @brief Return true if this is a compare constant expression
618 bool isCompare() const;
620 /// @brief Return true if this is an insertvalue or extractvalue expression,
621 /// and the getIndices() method may be used.
622 bool hasIndices() const;
624 /// Select constant expr
626 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
627 return getSelectTy(V1->getType(), C, V1, V2);
630 /// ConstantExpr::get - Return a binary or shift operator constant expression,
631 /// folding if possible.
633 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
635 /// @brief Return an ICmp or FCmp comparison operator constant expression.
636 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
638 /// ConstantExpr::get* - Return some common constants without having to
639 /// specify the full Instruction::OPCODE identifier.
641 static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
642 static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
644 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
645 /// all elements must be Constant's.
647 static Constant *getGetElementPtr(Constant *C,
648 Constant* const *IdxList, unsigned NumIdx);
649 static Constant *getGetElementPtr(Constant *C,
650 Value* const *IdxList, unsigned NumIdx);
652 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
653 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
654 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
655 static Constant *getExtractValue(Constant *Agg,
656 const unsigned *IdxList, unsigned NumIdx);
657 static Constant *getInsertValue(Constant *Agg, Constant *Val,
658 const unsigned *IdxList, unsigned NumIdx);
660 /// isNullValue - Return true if this is the value that would be returned by
662 virtual bool isNullValue() const { return false; }
664 /// getOpcode - Return the opcode at the root of this constant expression
665 unsigned getOpcode() const { return SubclassData; }
667 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
668 /// not an ICMP or FCMP constant expression.
669 unsigned getPredicate() const;
671 /// getIndices - Assert that this is an insertvalue or exactvalue
672 /// expression and return the list of indices.
673 const SmallVector<unsigned, 4> &getIndices() const;
675 /// getOpcodeName - Return a string representation for an opcode.
676 const char *getOpcodeName() const;
678 /// getWithOperandReplaced - Return a constant expression identical to this
679 /// one, but with the specified operand set to the specified value.
680 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
682 /// getWithOperands - This returns the current constant expression with the
683 /// operands replaced with the specified values. The specified operands must
684 /// match count and type with the existing ones.
685 Constant *getWithOperands(const std::vector<Constant*> &Ops) const {
686 return getWithOperands(&Ops[0], (unsigned)Ops.size());
688 Constant *getWithOperands(Constant* const *Ops, unsigned NumOps) const;
690 virtual void destroyConstant();
691 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
693 /// Methods for support type inquiry through isa, cast, and dyn_cast:
694 static inline bool classof(const ConstantExpr *) { return true; }
695 static inline bool classof(const Value *V) {
696 return V->getValueID() == ConstantExprVal;
701 struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
704 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
706 //===----------------------------------------------------------------------===//
707 /// UndefValue - 'undef' values are things that do not have specified contents.
708 /// These are used for a variety of purposes, including global variable
709 /// initializers and operands to instructions. 'undef' values can occur with
712 class UndefValue : public Constant {
713 friend struct ConstantCreator<UndefValue, Type, char>;
714 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
715 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
717 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
719 // allocate space for exactly zero operands
720 void *operator new(size_t s) {
721 return User::operator new(s, 0);
724 /// get() - Static factory methods - Return an 'undef' object of the specified
727 static UndefValue *get(const Type *T);
729 /// isNullValue - Return true if this is the value that would be returned by
731 virtual bool isNullValue() const { return false; }
733 virtual void destroyConstant();
735 /// Methods for support type inquiry through isa, cast, and dyn_cast:
736 static inline bool classof(const UndefValue *) { return true; }
737 static bool classof(const Value *V) {
738 return V->getValueID() == UndefValueVal;
741 } // End llvm namespace