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 /// Return the constant as an APInt value reference. This allows clients to
61 /// obtain a copy of the value, with all its precision in tact.
62 /// @brief Return the constant's value.
63 inline const APInt& getValue() const {
67 /// getBitWidth - Return the bitwidth of this constant.
68 unsigned getBitWidth() const { return Val.getBitWidth(); }
70 /// Return the constant as a 64-bit unsigned integer value after it
71 /// has been zero extended as appropriate for the type of this constant. Note
72 /// that this method can assert if the value does not fit in 64 bits.
74 /// @brief Return the zero extended value.
75 inline uint64_t getZExtValue() const {
76 return Val.getZExtValue();
79 /// Return the constant as a 64-bit integer value after it has been sign
80 /// extended as appropriate for the type of this constant. Note that
81 /// this method can assert if the value does not fit in 64 bits.
83 /// @brief Return the sign extended value.
84 inline int64_t getSExtValue() const {
85 return Val.getSExtValue();
88 /// A helper method that can be used to determine if the constant contained
89 /// within is equal to a constant. This only works for very small values,
90 /// because this is all that can be represented with all types.
91 /// @brief Determine if this constant's value is same as an unsigned char.
92 bool equalsInt(uint64_t V) const {
96 /// getType - Specialize the getType() method to always return an IntegerType,
97 /// which reduces the amount of casting needed in parts of the compiler.
99 inline const IntegerType *getType() const {
100 return reinterpret_cast<const IntegerType*>(Value::getType());
103 /// This static method returns true if the type Ty is big enough to
104 /// represent the value V. This can be used to avoid having the get method
105 /// assert when V is larger than Ty can represent. Note that there are two
106 /// versions of this method, one for unsigned and one for signed integers.
107 /// Although ConstantInt canonicalizes everything to an unsigned integer,
108 /// the signed version avoids callers having to convert a signed quantity
109 /// to the appropriate unsigned type before calling the method.
110 /// @returns true if V is a valid value for type Ty
111 /// @brief Determine if the value is in range for the given type.
112 static bool isValueValidForType(const Type *Ty, uint64_t V);
113 static bool isValueValidForType(const Type *Ty, int64_t V);
115 /// This function will return true iff this constant represents the "null"
116 /// value that would be returned by the getNullValue method.
117 /// @returns true if this is the null integer value.
118 /// @brief Determine if the value is null.
119 virtual bool isNullValue() const {
123 /// This is just a convenience method to make client code smaller for a
124 /// common code. It also correctly performs the comparison without the
125 /// potential for an assertion from getZExtValue().
126 bool isZero() const {
130 /// This is just a convenience method to make client code smaller for a
131 /// common case. It also correctly performs the comparison without the
132 /// potential for an assertion from getZExtValue().
133 /// @brief Determine if the value is one.
138 /// This function will return true iff every bit in this constant is set
140 /// @returns true iff this constant's bits are all set to true.
141 /// @brief Determine if the value is all ones.
142 bool isAllOnesValue() const {
143 return Val.isAllOnesValue();
146 /// This function will return true iff this constant represents the largest
147 /// value that may be represented by the constant's type.
148 /// @returns true iff this is the largest value that may be represented
150 /// @brief Determine if the value is maximal.
151 bool isMaxValue(bool isSigned) const {
153 return Val.isMaxSignedValue();
155 return Val.isMaxValue();
158 /// This function will return true iff this constant represents the smallest
159 /// value that may be represented by this constant's type.
160 /// @returns true if this is the smallest value that may be represented by
162 /// @brief Determine if the value is minimal.
163 bool isMinValue(bool isSigned) const {
165 return Val.isMinSignedValue();
167 return Val.isMinValue();
170 /// This function will return true iff this constant represents a value with
171 /// active bits bigger than 64 bits or a value greater than the given uint64_t
173 /// @returns true iff this constant is greater or equal to the given number.
174 /// @brief Determine if the value is greater or equal to the given number.
175 bool uge(uint64_t Num) {
176 return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
179 /// getLimitedValue - If the value is smaller than the specified limit,
180 /// return it, otherwise return the limit value. This causes the value
181 /// to saturate to the limit.
182 /// @returns the min of the value of the constant and the specified value
183 /// @brief Get the constant's value with a saturation limit
184 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
185 return Val.getLimitedValue(Limit);
188 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
189 static inline bool classof(const ConstantInt *) { return true; }
190 static bool classof(const Value *V) {
191 return V->getValueID() == ConstantIntVal;
196 //===----------------------------------------------------------------------===//
197 /// ConstantFP - Floating Point Values [float, double]
199 class ConstantFP : public Constant {
201 void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
202 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
203 friend class LLVMContextImpl;
205 ConstantFP(const Type *Ty, const APFloat& V);
207 // allocate space for exactly zero operands
208 void *operator new(size_t s) {
209 return User::operator new(s, 0);
212 /// isValueValidForType - return true if Ty is big enough to represent V.
213 static bool isValueValidForType(const Type *Ty, const APFloat& V);
214 inline const APFloat& getValueAPF() const { return Val; }
216 /// isNullValue - Return true if this is the value that would be returned by
217 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
218 /// considers -0.0 to be null as well as 0.0. :(
219 virtual bool isNullValue() const;
221 /// isNegativeZeroValue - Return true if the value is what would be returned
222 /// by getZeroValueForNegation.
223 virtual bool isNegativeZeroValue() const {
224 return Val.isZero() && Val.isNegative();
227 /// isExactlyValue - We don't rely on operator== working on double values, as
228 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
229 /// As such, this method can be used to do an exact bit-for-bit comparison of
230 /// two floating point values. The version with a double operand is retained
231 /// because it's so convenient to write isExactlyValue(2.0), but please use
232 /// it only for simple constants.
233 bool isExactlyValue(const APFloat& V) const;
235 bool isExactlyValue(double V) const {
237 // convert is not supported on this type
238 if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
241 FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
242 return isExactlyValue(FV);
244 /// Methods for support type inquiry through isa, cast, and dyn_cast:
245 static inline bool classof(const ConstantFP *) { return true; }
246 static bool classof(const Value *V) {
247 return V->getValueID() == ConstantFPVal;
251 //===----------------------------------------------------------------------===//
252 /// ConstantAggregateZero - All zero aggregate value
254 class ConstantAggregateZero : public Constant {
255 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
256 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
257 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
259 explicit ConstantAggregateZero(const Type *ty)
260 : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
262 // allocate space for exactly zero operands
263 void *operator new(size_t s) {
264 return User::operator new(s, 0);
267 /// get() - static factory method for creating a null aggregate. It is
268 /// illegal to call this method with a non-aggregate type.
269 static ConstantAggregateZero *get(const Type *Ty);
271 /// isNullValue - Return true if this is the value that would be returned by
273 virtual bool isNullValue() const { return true; }
275 virtual void destroyConstant();
277 /// Methods for support type inquiry through isa, cast, and dyn_cast:
279 static bool classof(const ConstantAggregateZero *) { return true; }
280 static bool classof(const Value *V) {
281 return V->getValueID() == ConstantAggregateZeroVal;
286 //===----------------------------------------------------------------------===//
287 /// ConstantArray - Constant Array Declarations
289 class ConstantArray : public Constant {
290 friend struct ConstantCreator<ConstantArray, ArrayType,
291 std::vector<Constant*> >;
292 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
294 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
296 /// get() - Static factory methods - Return objects of the specified value
297 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
299 /// Transparently provide more efficient getOperand methods.
300 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
302 /// getType - Specialize the getType() method to always return an ArrayType,
303 /// which reduces the amount of casting needed in parts of the compiler.
305 inline const ArrayType *getType() const {
306 return reinterpret_cast<const ArrayType*>(Value::getType());
309 /// isString - This method returns true if the array is an array of i8 and
310 /// the elements of the array are all ConstantInt's.
311 bool isString() const;
313 /// isCString - This method returns true if the array is a string (see
315 /// isString) and it ends in a null byte \0 and does not contains any other
317 /// null bytes except its terminator.
318 bool isCString() const;
320 /// getAsString - If this array is isString(), then this method converts the
321 /// array to an std::string and returns it. Otherwise, it asserts out.
323 std::string getAsString() const;
325 /// isNullValue - Return true if this is the value that would be returned by
326 /// getNullValue. This always returns false because zero arrays are always
327 /// created as ConstantAggregateZero objects.
328 virtual bool isNullValue() const { return false; }
330 virtual void destroyConstant();
331 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
333 /// Methods for support type inquiry through isa, cast, and dyn_cast:
334 static inline bool classof(const ConstantArray *) { return true; }
335 static bool classof(const Value *V) {
336 return V->getValueID() == ConstantArrayVal;
341 struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
344 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
346 //===----------------------------------------------------------------------===//
347 // ConstantStruct - Constant Struct Declarations
349 class ConstantStruct : public Constant {
350 friend struct ConstantCreator<ConstantStruct, StructType,
351 std::vector<Constant*> >;
352 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
354 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
356 /// get() - Static factory methods - Return objects of the specified value
358 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
360 /// Transparently provide more efficient getOperand methods.
361 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
363 /// getType() specialization - Reduce amount of casting...
365 inline const StructType *getType() const {
366 return reinterpret_cast<const StructType*>(Value::getType());
369 /// isNullValue - Return true if this is the value that would be returned by
370 /// getNullValue. This always returns false because zero structs are always
371 /// created as ConstantAggregateZero objects.
372 virtual bool isNullValue() const {
376 virtual void destroyConstant();
377 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
379 /// Methods for support type inquiry through isa, cast, and dyn_cast:
380 static inline bool classof(const ConstantStruct *) { return true; }
381 static bool classof(const Value *V) {
382 return V->getValueID() == ConstantStructVal;
387 struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
390 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
392 //===----------------------------------------------------------------------===//
393 /// ConstantVector - Constant Vector Declarations
395 class ConstantVector : public Constant {
396 friend struct ConstantCreator<ConstantVector, VectorType,
397 std::vector<Constant*> >;
398 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
400 ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
402 /// get() - Static factory methods - Return objects of the specified value
403 static Constant *get(const VectorType *T, const std::vector<Constant*> &);
405 /// Transparently provide more efficient getOperand methods.
406 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
408 /// getType - Specialize the getType() method to always return a VectorType,
409 /// which reduces the amount of casting needed in parts of the compiler.
411 inline const VectorType *getType() const {
412 return reinterpret_cast<const VectorType*>(Value::getType());
415 /// isNullValue - Return true if this is the value that would be returned by
416 /// getNullValue. This always returns false because zero vectors are always
417 /// created as ConstantAggregateZero objects.
418 virtual bool isNullValue() const { return false; }
420 /// This function will return true iff every element in this vector constant
421 /// is set to all ones.
422 /// @returns true iff this constant's emements are all set to all ones.
423 /// @brief Determine if the value is all ones.
424 bool isAllOnesValue() const;
426 /// getSplatValue - If this is a splat constant, meaning that all of the
427 /// elements have the same value, return that value. Otherwise return NULL.
428 Constant *getSplatValue();
430 virtual void destroyConstant();
431 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
433 /// Methods for support type inquiry through isa, cast, and dyn_cast:
434 static inline bool classof(const ConstantVector *) { return true; }
435 static bool classof(const Value *V) {
436 return V->getValueID() == ConstantVectorVal;
441 struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
444 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
446 //===----------------------------------------------------------------------===//
447 /// ConstantPointerNull - a constant pointer value that points to null
449 class ConstantPointerNull : public Constant {
450 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
451 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
452 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
454 explicit ConstantPointerNull(const PointerType *T)
455 : Constant(reinterpret_cast<const Type*>(T),
456 Value::ConstantPointerNullVal, 0, 0) {}
459 // allocate space for exactly zero operands
460 void *operator new(size_t s) {
461 return User::operator new(s, 0);
464 /// get() - Static factory methods - Return objects of the specified value
465 static ConstantPointerNull *get(const PointerType *T);
467 /// isNullValue - Return true if this is the value that would be returned by
469 virtual bool isNullValue() const { return true; }
471 virtual void destroyConstant();
473 /// getType - Specialize the getType() method to always return an PointerType,
474 /// which reduces the amount of casting needed in parts of the compiler.
476 inline const PointerType *getType() const {
477 return reinterpret_cast<const PointerType*>(Value::getType());
480 /// Methods for support type inquiry through isa, cast, and dyn_cast:
481 static inline bool classof(const ConstantPointerNull *) { return true; }
482 static bool classof(const Value *V) {
483 return V->getValueID() == ConstantPointerNullVal;
488 /// ConstantExpr - a constant value that is initialized with an expression using
489 /// other constant values.
491 /// This class uses the standard Instruction opcodes to define the various
492 /// constant expressions. The Opcode field for the ConstantExpr class is
493 /// maintained in the Value::SubclassData field.
494 class ConstantExpr : public Constant {
495 friend struct ConstantCreator<ConstantExpr,Type,
496 std::pair<unsigned, std::vector<Constant*> > >;
497 friend struct ConvertConstantType<ConstantExpr, Type>;
500 ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
501 : Constant(ty, ConstantExprVal, Ops, NumOps) {
502 // Operation type (an Instruction opcode) is stored as the SubclassData.
503 SubclassData = Opcode;
506 // These private methods are used by the type resolution code to create
507 // ConstantExprs in intermediate forms.
508 static Constant *getTy(const Type *Ty, unsigned Opcode,
509 Constant *C1, Constant *C2);
510 static Constant *getCompareTy(unsigned short pred, Constant *C1,
512 static Constant *getSelectTy(const Type *Ty,
513 Constant *C1, Constant *C2, Constant *C3);
514 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
515 Value* const *Idxs, unsigned NumIdxs);
516 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
518 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
519 Constant *Elt, Constant *Idx);
520 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
521 Constant *V2, Constant *Mask);
522 static Constant *getExtractValueTy(const Type *Ty, Constant *Agg,
523 const unsigned *Idxs, unsigned NumIdxs);
524 static Constant *getInsertValueTy(const Type *Ty, Constant *Agg,
526 const unsigned *Idxs, unsigned NumIdxs);
529 // Static methods to construct a ConstantExpr of different kinds. Note that
530 // these methods may return a object that is not an instance of the
531 // ConstantExpr class, because they will attempt to fold the constant
532 // expression into something simpler if possible.
534 /// Cast constant expr
536 static Constant *getTrunc (Constant *C, const Type *Ty);
537 static Constant *getSExt (Constant *C, const Type *Ty);
538 static Constant *getZExt (Constant *C, const Type *Ty);
539 static Constant *getFPTrunc (Constant *C, const Type *Ty);
540 static Constant *getFPExtend(Constant *C, const Type *Ty);
541 static Constant *getUIToFP (Constant *C, const Type *Ty);
542 static Constant *getSIToFP (Constant *C, const Type *Ty);
543 static Constant *getFPToUI (Constant *C, const Type *Ty);
544 static Constant *getFPToSI (Constant *C, const Type *Ty);
545 static Constant *getPtrToInt(Constant *C, const Type *Ty);
546 static Constant *getIntToPtr(Constant *C, const Type *Ty);
547 static Constant *getBitCast (Constant *C, const Type *Ty);
549 /// Transparently provide more efficient getOperand methods.
550 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
552 // @brief Convenience function for getting one of the casting operations
553 // using a CastOps opcode.
554 static Constant *getCast(
555 unsigned ops, ///< The opcode for the conversion
556 Constant *C, ///< The constant to be converted
557 const Type *Ty ///< The type to which the constant is converted
560 // @brief Create a ZExt or BitCast cast constant expression
561 static Constant *getZExtOrBitCast(
562 Constant *C, ///< The constant to zext or bitcast
563 const Type *Ty ///< The type to zext or bitcast C to
566 // @brief Create a SExt or BitCast cast constant expression
567 static Constant *getSExtOrBitCast(
568 Constant *C, ///< The constant to sext or bitcast
569 const Type *Ty ///< The type to sext or bitcast C to
572 // @brief Create a Trunc or BitCast cast constant expression
573 static Constant *getTruncOrBitCast(
574 Constant *C, ///< The constant to trunc or bitcast
575 const Type *Ty ///< The type to trunc or bitcast C to
578 /// @brief Create a BitCast or a PtrToInt cast constant expression
579 static Constant *getPointerCast(
580 Constant *C, ///< The pointer value to be casted (operand 0)
581 const Type *Ty ///< The type to which cast should be made
584 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
585 static Constant *getIntegerCast(
586 Constant *C, ///< The integer constant to be casted
587 const Type *Ty, ///< The integer type to cast to
588 bool isSigned ///< Whether C should be treated as signed or not
591 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
592 static Constant *getFPCast(
593 Constant *C, ///< The integer constant to be casted
594 const Type *Ty ///< The integer type to cast to
597 /// @brief Return true if this is a convert constant expression
600 /// @brief Return true if this is a compare constant expression
601 bool isCompare() const;
603 /// @brief Return true if this is an insertvalue or extractvalue expression,
604 /// and the getIndices() method may be used.
605 bool hasIndices() const;
607 /// Select constant expr
609 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
610 return getSelectTy(V1->getType(), C, V1, V2);
613 /// ConstantExpr::get - Return a binary or shift operator constant expression,
614 /// folding if possible.
616 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
618 /// @brief Return an ICmp or FCmp comparison operator constant expression.
619 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
621 /// ConstantExpr::get* - Return some common constants without having to
622 /// specify the full Instruction::OPCODE identifier.
624 static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
625 static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
627 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
628 /// all elements must be Constant's.
630 static Constant *getGetElementPtr(Constant *C,
631 Constant* const *IdxList, unsigned NumIdx);
632 static Constant *getGetElementPtr(Constant *C,
633 Value* const *IdxList, unsigned NumIdx);
635 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
636 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
637 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
638 static Constant *getExtractValue(Constant *Agg,
639 const unsigned *IdxList, unsigned NumIdx);
640 static Constant *getInsertValue(Constant *Agg, Constant *Val,
641 const unsigned *IdxList, unsigned NumIdx);
643 /// isNullValue - Return true if this is the value that would be returned by
645 virtual bool isNullValue() const { return false; }
647 /// getOpcode - Return the opcode at the root of this constant expression
648 unsigned getOpcode() const { return SubclassData; }
650 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
651 /// not an ICMP or FCMP constant expression.
652 unsigned getPredicate() const;
654 /// getIndices - Assert that this is an insertvalue or exactvalue
655 /// expression and return the list of indices.
656 const SmallVector<unsigned, 4> &getIndices() const;
658 /// getOpcodeName - Return a string representation for an opcode.
659 const char *getOpcodeName() const;
661 /// getWithOperandReplaced - Return a constant expression identical to this
662 /// one, but with the specified operand set to the specified value.
663 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
665 /// getWithOperands - This returns the current constant expression with the
666 /// operands replaced with the specified values. The specified operands must
667 /// match count and type with the existing ones.
668 Constant *getWithOperands(const std::vector<Constant*> &Ops) const {
669 return getWithOperands(&Ops[0], (unsigned)Ops.size());
671 Constant *getWithOperands(Constant* const *Ops, unsigned NumOps) const;
673 virtual void destroyConstant();
674 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
676 /// Methods for support type inquiry through isa, cast, and dyn_cast:
677 static inline bool classof(const ConstantExpr *) { return true; }
678 static inline bool classof(const Value *V) {
679 return V->getValueID() == ConstantExprVal;
684 struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
687 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
689 //===----------------------------------------------------------------------===//
690 /// UndefValue - 'undef' values are things that do not have specified contents.
691 /// These are used for a variety of purposes, including global variable
692 /// initializers and operands to instructions. 'undef' values can occur with
695 class UndefValue : public Constant {
696 friend struct ConstantCreator<UndefValue, Type, char>;
697 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
698 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
700 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
702 // allocate space for exactly zero operands
703 void *operator new(size_t s) {
704 return User::operator new(s, 0);
707 /// get() - Static factory methods - Return an 'undef' object of the specified
710 static UndefValue *get(const Type *T);
712 /// isNullValue - Return true if this is the value that would be returned by
714 virtual bool isNullValue() const { return false; }
716 virtual void destroyConstant();
718 /// Methods for support type inquiry through isa, cast, and dyn_cast:
719 static inline bool classof(const UndefValue *) { return true; }
720 static bool classof(const Value *V) {
721 return V->getValueID() == UndefValueVal;
725 //===----------------------------------------------------------------------===//
726 /// MDString - a single uniqued string.
727 /// These are used to efficiently contain a byte sequence for metadata.
729 class MDString : public Constant {
730 MDString(const MDString &); // DO NOT IMPLEMENT
731 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
732 MDString(const char *begin, const char *end);
734 const char *StrBegin, *StrEnd;
735 friend class LLVMContextImpl;
737 // allocate space for exactly zero operands
738 void *operator new(size_t s) {
739 return User::operator new(s, 0);
742 /// size() - The length of this string.
744 intptr_t size() const { return StrEnd - StrBegin; }
746 /// begin() - Pointer to the first byte of the string.
748 const char *begin() const { return StrBegin; }
750 /// end() - Pointer to one byte past the end of the string.
752 const char *end() const { return StrEnd; }
754 /// getType() specialization - Type is always MetadataTy.
756 inline const Type *getType() const {
757 return Type::MetadataTy;
760 /// isNullValue - Return true if this is the value that would be returned by
761 /// getNullValue. This always returns false because getNullValue will never
762 /// produce metadata.
763 virtual bool isNullValue() const {
767 virtual void destroyConstant();
769 /// Methods for support type inquiry through isa, cast, and dyn_cast:
770 static inline bool classof(const MDString *) { return true; }
771 static bool classof(const Value *V) {
772 return V->getValueID() == MDStringVal;
776 } // End llvm namespace