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);
54 // allocate space for exactly zero operands
55 void *operator new(size_t s) {
56 return User::operator new(s, 0);
59 /// Return the constant as an APInt value reference. This allows clients to
60 /// obtain a copy of the value, with all its precision in tact.
61 /// @brief Return the constant's value.
62 inline const APInt& getValue() const {
66 /// getBitWidth - Return the bitwidth of this constant.
67 unsigned getBitWidth() const { return Val.getBitWidth(); }
69 /// Return the constant as a 64-bit unsigned integer value after it
70 /// has been zero extended as appropriate for the type of this constant. Note
71 /// that this method can assert if the value does not fit in 64 bits.
73 /// @brief Return the zero extended value.
74 inline uint64_t getZExtValue() const {
75 return Val.getZExtValue();
78 /// Return the constant as a 64-bit integer value after it has been sign
79 /// extended as appropriate for the type of this constant. Note that
80 /// this method can assert if the value does not fit in 64 bits.
82 /// @brief Return the sign extended value.
83 inline int64_t getSExtValue() const {
84 return Val.getSExtValue();
87 /// A helper method that can be used to determine if the constant contained
88 /// within is equal to a constant. This only works for very small values,
89 /// because this is all that can be represented with all types.
90 /// @brief Determine if this constant's value is same as an unsigned char.
91 bool equalsInt(uint64_t V) const {
95 /// getTrue/getFalse - Return the singleton true/false values.
96 static inline ConstantInt *getTrue() {
97 if (TheTrueVal) return TheTrueVal;
98 return CreateTrueFalseVals(true);
100 static inline ConstantInt *getFalse() {
101 if (TheFalseVal) return TheFalseVal;
102 return CreateTrueFalseVals(false);
105 /// Return a ConstantInt with the specified value and an implied Type. The
106 /// type is the integer type that corresponds to the bit width of the value.
107 static ConstantInt *get(const APInt &V);
109 /// getType - Specialize the getType() method to always return an IntegerType,
110 /// which reduces the amount of casting needed in parts of the compiler.
112 inline const IntegerType *getType() const {
113 return reinterpret_cast<const IntegerType*>(Value::getType());
116 /// This static method returns true if the type Ty is big enough to
117 /// represent the value V. This can be used to avoid having the get method
118 /// assert when V is larger than Ty can represent. Note that there are two
119 /// versions of this method, one for unsigned and one for signed integers.
120 /// Although ConstantInt canonicalizes everything to an unsigned integer,
121 /// the signed version avoids callers having to convert a signed quantity
122 /// to the appropriate unsigned type before calling the method.
123 /// @returns true if V is a valid value for type Ty
124 /// @brief Determine if the value is in range for the given type.
125 static bool isValueValidForType(const Type *Ty, uint64_t V);
126 static bool isValueValidForType(const Type *Ty, int64_t V);
128 /// This function will return true iff this constant represents the "null"
129 /// value that would be returned by the getNullValue method.
130 /// @returns true if this is the null integer value.
131 /// @brief Determine if the value is null.
132 virtual bool isNullValue() const {
136 /// This is just a convenience method to make client code smaller for a
137 /// common code. It also correctly performs the comparison without the
138 /// potential for an assertion from getZExtValue().
139 bool isZero() const {
143 /// This is just a convenience method to make client code smaller for a
144 /// common case. It also correctly performs the comparison without the
145 /// potential for an assertion from getZExtValue().
146 /// @brief Determine if the value is one.
151 /// This function will return true iff every bit in this constant is set
153 /// @returns true iff this constant's bits are all set to true.
154 /// @brief Determine if the value is all ones.
155 bool isAllOnesValue() const {
156 return Val.isAllOnesValue();
159 /// This function will return true iff this constant represents the largest
160 /// value that may be represented by the constant's type.
161 /// @returns true iff this is the largest value that may be represented
163 /// @brief Determine if the value is maximal.
164 bool isMaxValue(bool isSigned) const {
166 return Val.isMaxSignedValue();
168 return Val.isMaxValue();
171 /// This function will return true iff this constant represents the smallest
172 /// value that may be represented by this constant's type.
173 /// @returns true if this is the smallest value that may be represented by
175 /// @brief Determine if the value is minimal.
176 bool isMinValue(bool isSigned) const {
178 return Val.isMinSignedValue();
180 return Val.isMinValue();
183 /// This function will return true iff this constant represents a value with
184 /// active bits bigger than 64 bits or a value greater than the given uint64_t
186 /// @returns true iff this constant is greater or equal to the given number.
187 /// @brief Determine if the value is greater or equal to the given number.
188 bool uge(uint64_t Num) {
189 return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
192 /// getLimitedValue - If the value is smaller than the specified limit,
193 /// return it, otherwise return the limit value. This causes the value
194 /// to saturate to the limit.
195 /// @returns the min of the value of the constant and the specified value
196 /// @brief Get the constant's value with a saturation limit
197 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
198 return Val.getLimitedValue(Limit);
201 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
202 static inline bool classof(const ConstantInt *) { return true; }
203 static bool classof(const Value *V) {
204 return V->getValueID() == ConstantIntVal;
206 static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
208 static ConstantInt *CreateTrueFalseVals(bool WhichOne);
212 //===----------------------------------------------------------------------===//
213 /// ConstantFP - Floating Point Values [float, double]
215 class ConstantFP : public Constant {
217 void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
218 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
220 ConstantFP(const Type *Ty, const APFloat& V);
222 // allocate space for exactly zero operands
223 void *operator new(size_t s) {
224 return User::operator new(s, 0);
227 /// get() - Static factory methods - Return objects of the specified value
228 static ConstantFP *get(const APFloat &V);
230 /// isValueValidForType - return true if Ty is big enough to represent V.
231 static bool isValueValidForType(const Type *Ty, const APFloat& V);
232 inline const APFloat& getValueAPF() const { return Val; }
234 /// isNullValue - Return true if this is the value that would be returned by
235 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
236 /// considers -0.0 to be null as well as 0.0. :(
237 virtual bool isNullValue() const;
239 /// isNegativeZeroValue - Return true if the value is what would be returned
240 /// by getZeroValueForNegation.
241 virtual bool isNegativeZeroValue() const {
242 return Val.isZero() && Val.isNegative();
245 /// isExactlyValue - We don't rely on operator== working on double values, as
246 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
247 /// As such, this method can be used to do an exact bit-for-bit comparison of
248 /// two floating point values. The version with a double operand is retained
249 /// because it's so convenient to write isExactlyValue(2.0), but please use
250 /// it only for simple constants.
251 bool isExactlyValue(const APFloat& V) const;
253 bool isExactlyValue(double V) const {
255 // convert is not supported on this type
256 if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
259 FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
260 return isExactlyValue(FV);
262 /// Methods for support type inquiry through isa, cast, and dyn_cast:
263 static inline bool classof(const ConstantFP *) { return true; }
264 static bool classof(const Value *V) {
265 return V->getValueID() == ConstantFPVal;
269 //===----------------------------------------------------------------------===//
270 /// ConstantAggregateZero - All zero aggregate value
272 class ConstantAggregateZero : public Constant {
273 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
274 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
275 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
277 explicit ConstantAggregateZero(const Type *ty)
278 : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
280 // allocate space for exactly zero operands
281 void *operator new(size_t s) {
282 return User::operator new(s, 0);
285 /// get() - static factory method for creating a null aggregate. It is
286 /// illegal to call this method with a non-aggregate type.
287 static ConstantAggregateZero *get(const Type *Ty);
289 /// isNullValue - Return true if this is the value that would be returned by
291 virtual bool isNullValue() const { return true; }
293 virtual void destroyConstant();
295 /// Methods for support type inquiry through isa, cast, and dyn_cast:
297 static bool classof(const ConstantAggregateZero *) { return true; }
298 static bool classof(const Value *V) {
299 return V->getValueID() == ConstantAggregateZeroVal;
304 //===----------------------------------------------------------------------===//
305 /// ConstantArray - Constant Array Declarations
307 class ConstantArray : public Constant {
308 friend struct ConstantCreator<ConstantArray, ArrayType,
309 std::vector<Constant*> >;
310 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
312 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
314 /// get() - Static factory methods - Return objects of the specified value
315 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
317 /// Transparently provide more efficient getOperand methods.
318 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
320 /// getType - Specialize the getType() method to always return an ArrayType,
321 /// which reduces the amount of casting needed in parts of the compiler.
323 inline const ArrayType *getType() const {
324 return reinterpret_cast<const ArrayType*>(Value::getType());
327 /// isString - This method returns true if the array is an array of i8 and
328 /// the elements of the array are all ConstantInt's.
329 bool isString() const;
331 /// isCString - This method returns true if the array is a string (see
333 /// isString) and it ends in a null byte \0 and does not contains any other
335 /// null bytes except its terminator.
336 bool isCString() const;
338 /// getAsString - If this array is isString(), then this method converts the
339 /// array to an std::string and returns it. Otherwise, it asserts out.
341 std::string getAsString() const;
343 /// isNullValue - Return true if this is the value that would be returned by
344 /// getNullValue. This always returns false because zero arrays are always
345 /// created as ConstantAggregateZero objects.
346 virtual bool isNullValue() const { return false; }
348 virtual void destroyConstant();
349 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
351 /// Methods for support type inquiry through isa, cast, and dyn_cast:
352 static inline bool classof(const ConstantArray *) { return true; }
353 static bool classof(const Value *V) {
354 return V->getValueID() == ConstantArrayVal;
359 struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
362 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
364 //===----------------------------------------------------------------------===//
365 // ConstantStruct - Constant Struct Declarations
367 class ConstantStruct : public Constant {
368 friend struct ConstantCreator<ConstantStruct, StructType,
369 std::vector<Constant*> >;
370 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
372 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
374 /// get() - Static factory methods - Return objects of the specified value
376 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
378 /// Transparently provide more efficient getOperand methods.
379 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
381 /// getType() specialization - Reduce amount of casting...
383 inline const StructType *getType() const {
384 return reinterpret_cast<const StructType*>(Value::getType());
387 /// isNullValue - Return true if this is the value that would be returned by
388 /// getNullValue. This always returns false because zero structs are always
389 /// created as ConstantAggregateZero objects.
390 virtual bool isNullValue() const {
394 virtual void destroyConstant();
395 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
397 /// Methods for support type inquiry through isa, cast, and dyn_cast:
398 static inline bool classof(const ConstantStruct *) { return true; }
399 static bool classof(const Value *V) {
400 return V->getValueID() == ConstantStructVal;
405 struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
408 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
410 //===----------------------------------------------------------------------===//
411 /// ConstantVector - Constant Vector Declarations
413 class ConstantVector : public Constant {
414 friend struct ConstantCreator<ConstantVector, VectorType,
415 std::vector<Constant*> >;
416 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
418 ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
420 /// get() - Static factory methods - Return objects of the specified value
421 static Constant *get(const VectorType *T, const std::vector<Constant*> &);
423 /// Transparently provide more efficient getOperand methods.
424 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
426 /// getType - Specialize the getType() method to always return a VectorType,
427 /// which reduces the amount of casting needed in parts of the compiler.
429 inline const VectorType *getType() const {
430 return reinterpret_cast<const VectorType*>(Value::getType());
433 /// isNullValue - Return true if this is the value that would be returned by
434 /// getNullValue. This always returns false because zero vectors are always
435 /// created as ConstantAggregateZero objects.
436 virtual bool isNullValue() const { return false; }
438 /// This function will return true iff every element in this vector constant
439 /// is set to all ones.
440 /// @returns true iff this constant's emements are all set to all ones.
441 /// @brief Determine if the value is all ones.
442 bool isAllOnesValue() const;
444 /// getSplatValue - If this is a splat constant, meaning that all of the
445 /// elements have the same value, return that value. Otherwise return NULL.
446 Constant *getSplatValue();
448 virtual void destroyConstant();
449 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
451 /// Methods for support type inquiry through isa, cast, and dyn_cast:
452 static inline bool classof(const ConstantVector *) { return true; }
453 static bool classof(const Value *V) {
454 return V->getValueID() == ConstantVectorVal;
459 struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
462 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
464 //===----------------------------------------------------------------------===//
465 /// ConstantPointerNull - a constant pointer value that points to null
467 class ConstantPointerNull : public Constant {
468 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
469 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
470 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
472 explicit ConstantPointerNull(const PointerType *T)
473 : Constant(reinterpret_cast<const Type*>(T),
474 Value::ConstantPointerNullVal, 0, 0) {}
477 // allocate space for exactly zero operands
478 void *operator new(size_t s) {
479 return User::operator new(s, 0);
482 /// get() - Static factory methods - Return objects of the specified value
483 static ConstantPointerNull *get(const PointerType *T);
485 /// isNullValue - Return true if this is the value that would be returned by
487 virtual bool isNullValue() const { return true; }
489 virtual void destroyConstant();
491 /// getType - Specialize the getType() method to always return an PointerType,
492 /// which reduces the amount of casting needed in parts of the compiler.
494 inline const PointerType *getType() const {
495 return reinterpret_cast<const PointerType*>(Value::getType());
498 /// Methods for support type inquiry through isa, cast, and dyn_cast:
499 static inline bool classof(const ConstantPointerNull *) { return true; }
500 static bool classof(const Value *V) {
501 return V->getValueID() == ConstantPointerNullVal;
506 /// ConstantExpr - a constant value that is initialized with an expression using
507 /// other constant values.
509 /// This class uses the standard Instruction opcodes to define the various
510 /// constant expressions. The Opcode field for the ConstantExpr class is
511 /// maintained in the Value::SubclassData field.
512 class ConstantExpr : public Constant {
513 friend struct ConstantCreator<ConstantExpr,Type,
514 std::pair<unsigned, std::vector<Constant*> > >;
515 friend struct ConvertConstantType<ConstantExpr, Type>;
518 ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
519 : Constant(ty, ConstantExprVal, Ops, NumOps) {
520 // Operation type (an Instruction opcode) is stored as the SubclassData.
521 SubclassData = Opcode;
524 // These private methods are used by the type resolution code to create
525 // ConstantExprs in intermediate forms.
526 static Constant *getTy(const Type *Ty, unsigned Opcode,
527 Constant *C1, Constant *C2);
528 static Constant *getCompareTy(unsigned short pred, Constant *C1,
530 static Constant *getSelectTy(const Type *Ty,
531 Constant *C1, Constant *C2, Constant *C3);
532 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
533 Value* const *Idxs, unsigned NumIdxs);
534 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
536 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
537 Constant *Elt, Constant *Idx);
538 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
539 Constant *V2, Constant *Mask);
540 static Constant *getExtractValueTy(const Type *Ty, Constant *Agg,
541 const unsigned *Idxs, unsigned NumIdxs);
542 static Constant *getInsertValueTy(const Type *Ty, Constant *Agg,
544 const unsigned *Idxs, unsigned NumIdxs);
547 // Static methods to construct a ConstantExpr of different kinds. Note that
548 // these methods may return a object that is not an instance of the
549 // ConstantExpr class, because they will attempt to fold the constant
550 // expression into something simpler if possible.
552 /// Cast constant expr
554 static Constant *getTrunc (Constant *C, const Type *Ty);
555 static Constant *getSExt (Constant *C, const Type *Ty);
556 static Constant *getZExt (Constant *C, const Type *Ty);
557 static Constant *getFPTrunc (Constant *C, const Type *Ty);
558 static Constant *getFPExtend(Constant *C, const Type *Ty);
559 static Constant *getUIToFP (Constant *C, const Type *Ty);
560 static Constant *getSIToFP (Constant *C, const Type *Ty);
561 static Constant *getFPToUI (Constant *C, const Type *Ty);
562 static Constant *getFPToSI (Constant *C, const Type *Ty);
563 static Constant *getPtrToInt(Constant *C, const Type *Ty);
564 static Constant *getIntToPtr(Constant *C, const Type *Ty);
565 static Constant *getBitCast (Constant *C, const Type *Ty);
567 /// Transparently provide more efficient getOperand methods.
568 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
570 // @brief Convenience function for getting one of the casting operations
571 // using a CastOps opcode.
572 static Constant *getCast(
573 unsigned ops, ///< The opcode for the conversion
574 Constant *C, ///< The constant to be converted
575 const Type *Ty ///< The type to which the constant is converted
578 // @brief Create a ZExt or BitCast cast constant expression
579 static Constant *getZExtOrBitCast(
580 Constant *C, ///< The constant to zext or bitcast
581 const Type *Ty ///< The type to zext or bitcast C to
584 // @brief Create a SExt or BitCast cast constant expression
585 static Constant *getSExtOrBitCast(
586 Constant *C, ///< The constant to sext or bitcast
587 const Type *Ty ///< The type to sext or bitcast C to
590 // @brief Create a Trunc or BitCast cast constant expression
591 static Constant *getTruncOrBitCast(
592 Constant *C, ///< The constant to trunc or bitcast
593 const Type *Ty ///< The type to trunc or bitcast C to
596 /// @brief Create a BitCast or a PtrToInt cast constant expression
597 static Constant *getPointerCast(
598 Constant *C, ///< The pointer value to be casted (operand 0)
599 const Type *Ty ///< The type to which cast should be made
602 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
603 static Constant *getIntegerCast(
604 Constant *C, ///< The integer constant to be casted
605 const Type *Ty, ///< The integer type to cast to
606 bool isSigned ///< Whether C should be treated as signed or not
609 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
610 static Constant *getFPCast(
611 Constant *C, ///< The integer constant to be casted
612 const Type *Ty ///< The integer type to cast to
615 /// @brief Return true if this is a convert constant expression
618 /// @brief Return true if this is a compare constant expression
619 bool isCompare() const;
621 /// @brief Return true if this is an insertvalue or extractvalue expression,
622 /// and the getIndices() method may be used.
623 bool hasIndices() const;
625 /// Select constant expr
627 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
628 return getSelectTy(V1->getType(), C, V1, V2);
631 /// ConstantExpr::get - Return a binary or shift operator constant expression,
632 /// folding if possible.
634 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
636 /// @brief Return an ICmp or FCmp comparison operator constant expression.
637 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
639 /// ConstantExpr::get* - Return some common constants without having to
640 /// specify the full Instruction::OPCODE identifier.
642 static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
643 static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
645 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
646 /// all elements must be Constant's.
648 static Constant *getGetElementPtr(Constant *C,
649 Constant* const *IdxList, unsigned NumIdx);
650 static Constant *getGetElementPtr(Constant *C,
651 Value* const *IdxList, unsigned NumIdx);
653 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
654 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
655 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
656 static Constant *getExtractValue(Constant *Agg,
657 const unsigned *IdxList, unsigned NumIdx);
658 static Constant *getInsertValue(Constant *Agg, Constant *Val,
659 const unsigned *IdxList, unsigned NumIdx);
661 /// isNullValue - Return true if this is the value that would be returned by
663 virtual bool isNullValue() const { return false; }
665 /// getOpcode - Return the opcode at the root of this constant expression
666 unsigned getOpcode() const { return SubclassData; }
668 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
669 /// not an ICMP or FCMP constant expression.
670 unsigned getPredicate() const;
672 /// getIndices - Assert that this is an insertvalue or exactvalue
673 /// expression and return the list of indices.
674 const SmallVector<unsigned, 4> &getIndices() const;
676 /// getOpcodeName - Return a string representation for an opcode.
677 const char *getOpcodeName() const;
679 /// getWithOperandReplaced - Return a constant expression identical to this
680 /// one, but with the specified operand set to the specified value.
681 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
683 /// getWithOperands - This returns the current constant expression with the
684 /// operands replaced with the specified values. The specified operands must
685 /// match count and type with the existing ones.
686 Constant *getWithOperands(const std::vector<Constant*> &Ops) const {
687 return getWithOperands(&Ops[0], (unsigned)Ops.size());
689 Constant *getWithOperands(Constant* const *Ops, unsigned NumOps) const;
691 virtual void destroyConstant();
692 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
694 /// Methods for support type inquiry through isa, cast, and dyn_cast:
695 static inline bool classof(const ConstantExpr *) { return true; }
696 static inline bool classof(const Value *V) {
697 return V->getValueID() == ConstantExprVal;
702 struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
705 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
707 //===----------------------------------------------------------------------===//
708 /// UndefValue - 'undef' values are things that do not have specified contents.
709 /// These are used for a variety of purposes, including global variable
710 /// initializers and operands to instructions. 'undef' values can occur with
713 class UndefValue : public Constant {
714 friend struct ConstantCreator<UndefValue, Type, char>;
715 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
716 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
718 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
720 // allocate space for exactly zero operands
721 void *operator new(size_t s) {
722 return User::operator new(s, 0);
725 /// get() - Static factory methods - Return an 'undef' object of the specified
728 static UndefValue *get(const Type *T);
730 /// isNullValue - Return true if this is the value that would be returned by
732 virtual bool isNullValue() const { return false; }
734 virtual void destroyConstant();
736 /// Methods for support type inquiry through isa, cast, and dyn_cast:
737 static inline bool classof(const UndefValue *) { return true; }
738 static bool classof(const Value *V) {
739 return V->getValueID() == UndefValueVal;
743 //===----------------------------------------------------------------------===//
744 /// MDString - a single uniqued string.
745 /// These are used to efficiently contain a byte sequence for metadata.
747 class MDString : public Constant {
748 MDString(const MDString &); // DO NOT IMPLEMENT
749 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
750 MDString(const char *begin, const char *end);
752 const char *StrBegin, *StrEnd;
754 // allocate space for exactly zero operands
755 void *operator new(size_t s) {
756 return User::operator new(s, 0);
759 /// get() - Static factory methods - Return objects of the specified value.
761 static MDString *get(const char *StrBegin, const char *StrEnd);
762 static MDString *get(const std::string &Str);
764 /// size() - The length of this string.
766 intptr_t size() const { return StrEnd - StrBegin; }
768 /// begin() - Pointer to the first byte of the string.
770 const char *begin() const { return StrBegin; }
772 /// end() - Pointer to one byte past the end of the string.
774 const char *end() const { return StrEnd; }
776 /// getType() specialization - Type is always MetadataTy.
778 inline const Type *getType() const {
779 return Type::MetadataTy;
782 /// isNullValue - Return true if this is the value that would be returned by
783 /// getNullValue. This always returns false because getNullValue will never
784 /// produce metadata.
785 virtual bool isNullValue() const {
789 virtual void destroyConstant();
791 /// Methods for support type inquiry through isa, cast, and dyn_cast:
792 static inline bool classof(const MDString *) { return true; }
793 static bool classof(const Value *V) {
794 return V->getValueID() == MDStringVal;
798 } // End llvm namespace