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 /// getTrue/getFalse - Return the singleton true/false values.
97 static inline ConstantInt *getTrue() {
98 if (TheTrueVal) return TheTrueVal;
99 return CreateTrueFalseVals(true);
101 static inline ConstantInt *getFalse() {
102 if (TheFalseVal) return TheFalseVal;
103 return CreateTrueFalseVals(false);
106 /// getType - Specialize the getType() method to always return an IntegerType,
107 /// which reduces the amount of casting needed in parts of the compiler.
109 inline const IntegerType *getType() const {
110 return reinterpret_cast<const IntegerType*>(Value::getType());
113 /// This static method returns true if the type Ty is big enough to
114 /// represent the value V. This can be used to avoid having the get method
115 /// assert when V is larger than Ty can represent. Note that there are two
116 /// versions of this method, one for unsigned and one for signed integers.
117 /// Although ConstantInt canonicalizes everything to an unsigned integer,
118 /// the signed version avoids callers having to convert a signed quantity
119 /// to the appropriate unsigned type before calling the method.
120 /// @returns true if V is a valid value for type Ty
121 /// @brief Determine if the value is in range for the given type.
122 static bool isValueValidForType(const Type *Ty, uint64_t V);
123 static bool isValueValidForType(const Type *Ty, int64_t V);
125 /// This function will return true iff this constant represents the "null"
126 /// value that would be returned by the getNullValue method.
127 /// @returns true if this is the null integer value.
128 /// @brief Determine if the value is null.
129 virtual bool isNullValue() const {
133 /// This is just a convenience method to make client code smaller for a
134 /// common code. It also correctly performs the comparison without the
135 /// potential for an assertion from getZExtValue().
136 bool isZero() const {
140 /// This is just a convenience method to make client code smaller for a
141 /// common case. It also correctly performs the comparison without the
142 /// potential for an assertion from getZExtValue().
143 /// @brief Determine if the value is one.
148 /// This function will return true iff every bit in this constant is set
150 /// @returns true iff this constant's bits are all set to true.
151 /// @brief Determine if the value is all ones.
152 bool isAllOnesValue() const {
153 return Val.isAllOnesValue();
156 /// This function will return true iff this constant represents the largest
157 /// value that may be represented by the constant's type.
158 /// @returns true iff this is the largest value that may be represented
160 /// @brief Determine if the value is maximal.
161 bool isMaxValue(bool isSigned) const {
163 return Val.isMaxSignedValue();
165 return Val.isMaxValue();
168 /// This function will return true iff this constant represents the smallest
169 /// value that may be represented by this constant's type.
170 /// @returns true if this is the smallest value that may be represented by
172 /// @brief Determine if the value is minimal.
173 bool isMinValue(bool isSigned) const {
175 return Val.isMinSignedValue();
177 return Val.isMinValue();
180 /// This function will return true iff this constant represents a value with
181 /// active bits bigger than 64 bits or a value greater than the given uint64_t
183 /// @returns true iff this constant is greater or equal to the given number.
184 /// @brief Determine if the value is greater or equal to the given number.
185 bool uge(uint64_t Num) {
186 return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
189 /// getLimitedValue - If the value is smaller than the specified limit,
190 /// return it, otherwise return the limit value. This causes the value
191 /// to saturate to the limit.
192 /// @returns the min of the value of the constant and the specified value
193 /// @brief Get the constant's value with a saturation limit
194 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
195 return Val.getLimitedValue(Limit);
198 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
199 static inline bool classof(const ConstantInt *) { return true; }
200 static bool classof(const Value *V) {
201 return V->getValueID() == ConstantIntVal;
203 static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
205 static ConstantInt *CreateTrueFalseVals(bool WhichOne);
209 //===----------------------------------------------------------------------===//
210 /// ConstantFP - Floating Point Values [float, double]
212 class ConstantFP : public Constant {
214 void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
215 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
216 friend class LLVMContextImpl;
218 ConstantFP(const Type *Ty, const APFloat& V);
220 // allocate space for exactly zero operands
221 void *operator new(size_t s) {
222 return User::operator new(s, 0);
225 /// isValueValidForType - return true if Ty is big enough to represent V.
226 static bool isValueValidForType(const Type *Ty, const APFloat& V);
227 inline const APFloat& getValueAPF() const { return Val; }
229 /// isNullValue - Return true if this is the value that would be returned by
230 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
231 /// considers -0.0 to be null as well as 0.0. :(
232 virtual bool isNullValue() const;
234 /// isNegativeZeroValue - Return true if the value is what would be returned
235 /// by getZeroValueForNegation.
236 virtual bool isNegativeZeroValue() const {
237 return Val.isZero() && Val.isNegative();
240 /// isExactlyValue - We don't rely on operator== working on double values, as
241 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
242 /// As such, this method can be used to do an exact bit-for-bit comparison of
243 /// two floating point values. The version with a double operand is retained
244 /// because it's so convenient to write isExactlyValue(2.0), but please use
245 /// it only for simple constants.
246 bool isExactlyValue(const APFloat& V) const;
248 bool isExactlyValue(double V) const {
250 // convert is not supported on this type
251 if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
254 FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
255 return isExactlyValue(FV);
257 /// Methods for support type inquiry through isa, cast, and dyn_cast:
258 static inline bool classof(const ConstantFP *) { return true; }
259 static bool classof(const Value *V) {
260 return V->getValueID() == ConstantFPVal;
264 //===----------------------------------------------------------------------===//
265 /// ConstantAggregateZero - All zero aggregate value
267 class ConstantAggregateZero : public Constant {
268 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
269 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
270 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
272 explicit ConstantAggregateZero(const Type *ty)
273 : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
275 // allocate space for exactly zero operands
276 void *operator new(size_t s) {
277 return User::operator new(s, 0);
280 /// get() - static factory method for creating a null aggregate. It is
281 /// illegal to call this method with a non-aggregate type.
282 static ConstantAggregateZero *get(const Type *Ty);
284 /// isNullValue - Return true if this is the value that would be returned by
286 virtual bool isNullValue() const { return true; }
288 virtual void destroyConstant();
290 /// Methods for support type inquiry through isa, cast, and dyn_cast:
292 static bool classof(const ConstantAggregateZero *) { return true; }
293 static bool classof(const Value *V) {
294 return V->getValueID() == ConstantAggregateZeroVal;
299 //===----------------------------------------------------------------------===//
300 /// ConstantArray - Constant Array Declarations
302 class ConstantArray : public Constant {
303 friend struct ConstantCreator<ConstantArray, ArrayType,
304 std::vector<Constant*> >;
305 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
307 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
309 /// get() - Static factory methods - Return objects of the specified value
310 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
312 /// Transparently provide more efficient getOperand methods.
313 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
315 /// getType - Specialize the getType() method to always return an ArrayType,
316 /// which reduces the amount of casting needed in parts of the compiler.
318 inline const ArrayType *getType() const {
319 return reinterpret_cast<const ArrayType*>(Value::getType());
322 /// isString - This method returns true if the array is an array of i8 and
323 /// the elements of the array are all ConstantInt's.
324 bool isString() const;
326 /// isCString - This method returns true if the array is a string (see
328 /// isString) and it ends in a null byte \0 and does not contains any other
330 /// null bytes except its terminator.
331 bool isCString() const;
333 /// getAsString - If this array is isString(), then this method converts the
334 /// array to an std::string and returns it. Otherwise, it asserts out.
336 std::string getAsString() const;
338 /// isNullValue - Return true if this is the value that would be returned by
339 /// getNullValue. This always returns false because zero arrays are always
340 /// created as ConstantAggregateZero objects.
341 virtual bool isNullValue() const { return false; }
343 virtual void destroyConstant();
344 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
346 /// Methods for support type inquiry through isa, cast, and dyn_cast:
347 static inline bool classof(const ConstantArray *) { return true; }
348 static bool classof(const Value *V) {
349 return V->getValueID() == ConstantArrayVal;
354 struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
357 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
359 //===----------------------------------------------------------------------===//
360 // ConstantStruct - Constant Struct Declarations
362 class ConstantStruct : public Constant {
363 friend struct ConstantCreator<ConstantStruct, StructType,
364 std::vector<Constant*> >;
365 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
367 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
369 /// get() - Static factory methods - Return objects of the specified value
371 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
373 /// Transparently provide more efficient getOperand methods.
374 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
376 /// getType() specialization - Reduce amount of casting...
378 inline const StructType *getType() const {
379 return reinterpret_cast<const StructType*>(Value::getType());
382 /// isNullValue - Return true if this is the value that would be returned by
383 /// getNullValue. This always returns false because zero structs are always
384 /// created as ConstantAggregateZero objects.
385 virtual bool isNullValue() const {
389 virtual void destroyConstant();
390 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
392 /// Methods for support type inquiry through isa, cast, and dyn_cast:
393 static inline bool classof(const ConstantStruct *) { return true; }
394 static bool classof(const Value *V) {
395 return V->getValueID() == ConstantStructVal;
400 struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
403 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
405 //===----------------------------------------------------------------------===//
406 /// ConstantVector - Constant Vector Declarations
408 class ConstantVector : public Constant {
409 friend struct ConstantCreator<ConstantVector, VectorType,
410 std::vector<Constant*> >;
411 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
413 ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
415 /// get() - Static factory methods - Return objects of the specified value
416 static Constant *get(const VectorType *T, const std::vector<Constant*> &);
418 /// Transparently provide more efficient getOperand methods.
419 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
421 /// getType - Specialize the getType() method to always return a VectorType,
422 /// which reduces the amount of casting needed in parts of the compiler.
424 inline const VectorType *getType() const {
425 return reinterpret_cast<const VectorType*>(Value::getType());
428 /// isNullValue - Return true if this is the value that would be returned by
429 /// getNullValue. This always returns false because zero vectors are always
430 /// created as ConstantAggregateZero objects.
431 virtual bool isNullValue() const { return false; }
433 /// This function will return true iff every element in this vector constant
434 /// is set to all ones.
435 /// @returns true iff this constant's emements are all set to all ones.
436 /// @brief Determine if the value is all ones.
437 bool isAllOnesValue() const;
439 /// getSplatValue - If this is a splat constant, meaning that all of the
440 /// elements have the same value, return that value. Otherwise return NULL.
441 Constant *getSplatValue();
443 virtual void destroyConstant();
444 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
446 /// Methods for support type inquiry through isa, cast, and dyn_cast:
447 static inline bool classof(const ConstantVector *) { return true; }
448 static bool classof(const Value *V) {
449 return V->getValueID() == ConstantVectorVal;
454 struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
457 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
459 //===----------------------------------------------------------------------===//
460 /// ConstantPointerNull - a constant pointer value that points to null
462 class ConstantPointerNull : public Constant {
463 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
464 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
465 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
467 explicit ConstantPointerNull(const PointerType *T)
468 : Constant(reinterpret_cast<const Type*>(T),
469 Value::ConstantPointerNullVal, 0, 0) {}
472 // allocate space for exactly zero operands
473 void *operator new(size_t s) {
474 return User::operator new(s, 0);
477 /// get() - Static factory methods - Return objects of the specified value
478 static ConstantPointerNull *get(const PointerType *T);
480 /// isNullValue - Return true if this is the value that would be returned by
482 virtual bool isNullValue() const { return true; }
484 virtual void destroyConstant();
486 /// getType - Specialize the getType() method to always return an PointerType,
487 /// which reduces the amount of casting needed in parts of the compiler.
489 inline const PointerType *getType() const {
490 return reinterpret_cast<const PointerType*>(Value::getType());
493 /// Methods for support type inquiry through isa, cast, and dyn_cast:
494 static inline bool classof(const ConstantPointerNull *) { return true; }
495 static bool classof(const Value *V) {
496 return V->getValueID() == ConstantPointerNullVal;
501 /// ConstantExpr - a constant value that is initialized with an expression using
502 /// other constant values.
504 /// This class uses the standard Instruction opcodes to define the various
505 /// constant expressions. The Opcode field for the ConstantExpr class is
506 /// maintained in the Value::SubclassData field.
507 class ConstantExpr : public Constant {
508 friend struct ConstantCreator<ConstantExpr,Type,
509 std::pair<unsigned, std::vector<Constant*> > >;
510 friend struct ConvertConstantType<ConstantExpr, Type>;
513 ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
514 : Constant(ty, ConstantExprVal, Ops, NumOps) {
515 // Operation type (an Instruction opcode) is stored as the SubclassData.
516 SubclassData = Opcode;
519 // These private methods are used by the type resolution code to create
520 // ConstantExprs in intermediate forms.
521 static Constant *getTy(const Type *Ty, unsigned Opcode,
522 Constant *C1, Constant *C2);
523 static Constant *getCompareTy(unsigned short pred, Constant *C1,
525 static Constant *getSelectTy(const Type *Ty,
526 Constant *C1, Constant *C2, Constant *C3);
527 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
528 Value* const *Idxs, unsigned NumIdxs);
529 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
531 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
532 Constant *Elt, Constant *Idx);
533 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
534 Constant *V2, Constant *Mask);
535 static Constant *getExtractValueTy(const Type *Ty, Constant *Agg,
536 const unsigned *Idxs, unsigned NumIdxs);
537 static Constant *getInsertValueTy(const Type *Ty, Constant *Agg,
539 const unsigned *Idxs, unsigned NumIdxs);
542 // Static methods to construct a ConstantExpr of different kinds. Note that
543 // these methods may return a object that is not an instance of the
544 // ConstantExpr class, because they will attempt to fold the constant
545 // expression into something simpler if possible.
547 /// Cast constant expr
549 static Constant *getTrunc (Constant *C, const Type *Ty);
550 static Constant *getSExt (Constant *C, const Type *Ty);
551 static Constant *getZExt (Constant *C, const Type *Ty);
552 static Constant *getFPTrunc (Constant *C, const Type *Ty);
553 static Constant *getFPExtend(Constant *C, const Type *Ty);
554 static Constant *getUIToFP (Constant *C, const Type *Ty);
555 static Constant *getSIToFP (Constant *C, const Type *Ty);
556 static Constant *getFPToUI (Constant *C, const Type *Ty);
557 static Constant *getFPToSI (Constant *C, const Type *Ty);
558 static Constant *getPtrToInt(Constant *C, const Type *Ty);
559 static Constant *getIntToPtr(Constant *C, const Type *Ty);
560 static Constant *getBitCast (Constant *C, const Type *Ty);
562 /// Transparently provide more efficient getOperand methods.
563 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
565 // @brief Convenience function for getting one of the casting operations
566 // using a CastOps opcode.
567 static Constant *getCast(
568 unsigned ops, ///< The opcode for the conversion
569 Constant *C, ///< The constant to be converted
570 const Type *Ty ///< The type to which the constant is converted
573 // @brief Create a ZExt or BitCast cast constant expression
574 static Constant *getZExtOrBitCast(
575 Constant *C, ///< The constant to zext or bitcast
576 const Type *Ty ///< The type to zext or bitcast C to
579 // @brief Create a SExt or BitCast cast constant expression
580 static Constant *getSExtOrBitCast(
581 Constant *C, ///< The constant to sext or bitcast
582 const Type *Ty ///< The type to sext or bitcast C to
585 // @brief Create a Trunc or BitCast cast constant expression
586 static Constant *getTruncOrBitCast(
587 Constant *C, ///< The constant to trunc or bitcast
588 const Type *Ty ///< The type to trunc or bitcast C to
591 /// @brief Create a BitCast or a PtrToInt cast constant expression
592 static Constant *getPointerCast(
593 Constant *C, ///< The pointer value to be casted (operand 0)
594 const Type *Ty ///< The type to which cast should be made
597 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
598 static Constant *getIntegerCast(
599 Constant *C, ///< The integer constant to be casted
600 const Type *Ty, ///< The integer type to cast to
601 bool isSigned ///< Whether C should be treated as signed or not
604 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
605 static Constant *getFPCast(
606 Constant *C, ///< The integer constant to be casted
607 const Type *Ty ///< The integer type to cast to
610 /// @brief Return true if this is a convert constant expression
613 /// @brief Return true if this is a compare constant expression
614 bool isCompare() const;
616 /// @brief Return true if this is an insertvalue or extractvalue expression,
617 /// and the getIndices() method may be used.
618 bool hasIndices() const;
620 /// Select constant expr
622 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
623 return getSelectTy(V1->getType(), C, V1, V2);
626 /// ConstantExpr::get - Return a binary or shift operator constant expression,
627 /// folding if possible.
629 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
631 /// @brief Return an ICmp or FCmp comparison operator constant expression.
632 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
634 /// ConstantExpr::get* - Return some common constants without having to
635 /// specify the full Instruction::OPCODE identifier.
637 static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
638 static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
640 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
641 /// all elements must be Constant's.
643 static Constant *getGetElementPtr(Constant *C,
644 Constant* const *IdxList, unsigned NumIdx);
645 static Constant *getGetElementPtr(Constant *C,
646 Value* const *IdxList, unsigned NumIdx);
648 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
649 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
650 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
651 static Constant *getExtractValue(Constant *Agg,
652 const unsigned *IdxList, unsigned NumIdx);
653 static Constant *getInsertValue(Constant *Agg, Constant *Val,
654 const unsigned *IdxList, unsigned NumIdx);
656 /// isNullValue - Return true if this is the value that would be returned by
658 virtual bool isNullValue() const { return false; }
660 /// getOpcode - Return the opcode at the root of this constant expression
661 unsigned getOpcode() const { return SubclassData; }
663 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
664 /// not an ICMP or FCMP constant expression.
665 unsigned getPredicate() const;
667 /// getIndices - Assert that this is an insertvalue or exactvalue
668 /// expression and return the list of indices.
669 const SmallVector<unsigned, 4> &getIndices() const;
671 /// getOpcodeName - Return a string representation for an opcode.
672 const char *getOpcodeName() const;
674 /// getWithOperandReplaced - Return a constant expression identical to this
675 /// one, but with the specified operand set to the specified value.
676 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
678 /// getWithOperands - This returns the current constant expression with the
679 /// operands replaced with the specified values. The specified operands must
680 /// match count and type with the existing ones.
681 Constant *getWithOperands(const std::vector<Constant*> &Ops) const {
682 return getWithOperands(&Ops[0], (unsigned)Ops.size());
684 Constant *getWithOperands(Constant* const *Ops, unsigned NumOps) const;
686 virtual void destroyConstant();
687 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
689 /// Methods for support type inquiry through isa, cast, and dyn_cast:
690 static inline bool classof(const ConstantExpr *) { return true; }
691 static inline bool classof(const Value *V) {
692 return V->getValueID() == ConstantExprVal;
697 struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
700 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
702 //===----------------------------------------------------------------------===//
703 /// UndefValue - 'undef' values are things that do not have specified contents.
704 /// These are used for a variety of purposes, including global variable
705 /// initializers and operands to instructions. 'undef' values can occur with
708 class UndefValue : public Constant {
709 friend struct ConstantCreator<UndefValue, Type, char>;
710 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
711 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
713 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
715 // allocate space for exactly zero operands
716 void *operator new(size_t s) {
717 return User::operator new(s, 0);
720 /// get() - Static factory methods - Return an 'undef' object of the specified
723 static UndefValue *get(const Type *T);
725 /// isNullValue - Return true if this is the value that would be returned by
727 virtual bool isNullValue() const { return false; }
729 virtual void destroyConstant();
731 /// Methods for support type inquiry through isa, cast, and dyn_cast:
732 static inline bool classof(const UndefValue *) { return true; }
733 static bool classof(const Value *V) {
734 return V->getValueID() == UndefValueVal;
738 //===----------------------------------------------------------------------===//
739 /// MDString - a single uniqued string.
740 /// These are used to efficiently contain a byte sequence for metadata.
742 class MDString : public Constant {
743 MDString(const MDString &); // DO NOT IMPLEMENT
744 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
745 MDString(const char *begin, const char *end);
747 const char *StrBegin, *StrEnd;
748 friend class LLVMContextImpl;
750 // allocate space for exactly zero operands
751 void *operator new(size_t s) {
752 return User::operator new(s, 0);
755 /// size() - The length of this string.
757 intptr_t size() const { return StrEnd - StrBegin; }
759 /// begin() - Pointer to the first byte of the string.
761 const char *begin() const { return StrBegin; }
763 /// end() - Pointer to one byte past the end of the string.
765 const char *end() const { return StrEnd; }
767 /// getType() specialization - Type is always MetadataTy.
769 inline const Type *getType() const {
770 return Type::MetadataTy;
773 /// isNullValue - Return true if this is the value that would be returned by
774 /// getNullValue. This always returns false because getNullValue will never
775 /// produce metadata.
776 virtual bool isNullValue() const {
780 virtual void destroyConstant();
782 /// Methods for support type inquiry through isa, cast, and dyn_cast:
783 static inline bool classof(const MDString *) { return true; }
784 static bool classof(const Value *V) {
785 return V->getValueID() == MDStringVal;
789 } // End llvm namespace