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 /// If Ty is a vector type, return a Constant with a splat of the given
60 /// value. Otherwise return a ConstantInt for the given value.
61 static Constant* get(const Type* Ty, uint64_t V, bool isSigned = false);
63 /// Return a ConstantInt with the specified integer value for the specified
64 /// type. If the type is wider than 64 bits, the value will be zero-extended
65 /// to fit the type, unless isSigned is true, in which case the value will
66 /// be interpreted as a 64-bit signed integer and sign-extended to fit
68 /// @brief Get a ConstantInt for a specific value.
69 static ConstantInt* get(const IntegerType* Ty, uint64_t V,
70 bool isSigned = false);
72 /// Return a ConstantInt with the specified value for the specified type. The
73 /// value V will be canonicalized to a an unsigned APInt. Accessing it with
74 /// either getSExtValue() or getZExtValue() will yield a correctly sized and
75 /// signed value for the type Ty.
76 /// @brief Get a ConstantInt for a specific signed value.
77 static ConstantInt* getSigned(const IntegerType* Ty, int64_t V);
78 static Constant *getSigned(const Type *Ty, int64_t V);
80 /// Return a ConstantInt with the specified value and an implied Type. The
81 /// type is the integer type that corresponds to the bit width of the value.
82 static ConstantInt* get(LLVMContext &Context, const APInt& V);
84 /// If Ty is a vector type, return a Constant with a splat of the given
85 /// value. Otherwise return a ConstantInt for the given value.
86 static Constant* get(const Type* Ty, const APInt& V);
88 /// Return the constant as an APInt value reference. This allows clients to
89 /// obtain a copy of the value, with all its precision in tact.
90 /// @brief Return the constant's value.
91 inline const APInt& getValue() const {
95 /// getBitWidth - Return the bitwidth of this constant.
96 unsigned getBitWidth() const { return Val.getBitWidth(); }
98 /// Return the constant as a 64-bit unsigned integer value after it
99 /// has been zero extended as appropriate for the type of this constant. Note
100 /// that this method can assert if the value does not fit in 64 bits.
102 /// @brief Return the zero extended value.
103 inline uint64_t getZExtValue() const {
104 return Val.getZExtValue();
107 /// Return the constant as a 64-bit integer value after it has been sign
108 /// extended as appropriate for the type of this constant. Note that
109 /// this method can assert if the value does not fit in 64 bits.
111 /// @brief Return the sign extended value.
112 inline int64_t getSExtValue() const {
113 return Val.getSExtValue();
116 /// A helper method that can be used to determine if the constant contained
117 /// within is equal to a constant. This only works for very small values,
118 /// because this is all that can be represented with all types.
119 /// @brief Determine if this constant's value is same as an unsigned char.
120 bool equalsInt(uint64_t V) const {
124 /// getType - Specialize the getType() method to always return an IntegerType,
125 /// which reduces the amount of casting needed in parts of the compiler.
127 inline const IntegerType *getType() const {
128 return reinterpret_cast<const IntegerType*>(Value::getType());
131 /// This static method returns true if the type Ty is big enough to
132 /// represent the value V. This can be used to avoid having the get method
133 /// assert when V is larger than Ty can represent. Note that there are two
134 /// versions of this method, one for unsigned and one for signed integers.
135 /// Although ConstantInt canonicalizes everything to an unsigned integer,
136 /// the signed version avoids callers having to convert a signed quantity
137 /// to the appropriate unsigned type before calling the method.
138 /// @returns true if V is a valid value for type Ty
139 /// @brief Determine if the value is in range for the given type.
140 static bool isValueValidForType(const Type *Ty, uint64_t V);
141 static bool isValueValidForType(const Type *Ty, int64_t V);
143 /// This function will return true iff this constant represents the "null"
144 /// value that would be returned by the getNullValue method.
145 /// @returns true if this is the null integer value.
146 /// @brief Determine if the value is null.
147 virtual bool isNullValue() const {
151 /// This is just a convenience method to make client code smaller for a
152 /// common code. It also correctly performs the comparison without the
153 /// potential for an assertion from getZExtValue().
154 bool isZero() const {
158 /// This is just a convenience method to make client code smaller for a
159 /// common case. It also correctly performs the comparison without the
160 /// potential for an assertion from getZExtValue().
161 /// @brief Determine if the value is one.
166 /// This function will return true iff every bit in this constant is set
168 /// @returns true iff this constant's bits are all set to true.
169 /// @brief Determine if the value is all ones.
170 bool isAllOnesValue() const {
171 return Val.isAllOnesValue();
174 /// This function will return true iff this constant represents the largest
175 /// value that may be represented by the constant's type.
176 /// @returns true iff this is the largest value that may be represented
178 /// @brief Determine if the value is maximal.
179 bool isMaxValue(bool isSigned) const {
181 return Val.isMaxSignedValue();
183 return Val.isMaxValue();
186 /// This function will return true iff this constant represents the smallest
187 /// value that may be represented by this constant's type.
188 /// @returns true if this is the smallest value that may be represented by
190 /// @brief Determine if the value is minimal.
191 bool isMinValue(bool isSigned) const {
193 return Val.isMinSignedValue();
195 return Val.isMinValue();
198 /// This function will return true iff this constant represents a value with
199 /// active bits bigger than 64 bits or a value greater than the given uint64_t
201 /// @returns true iff this constant is greater or equal to the given number.
202 /// @brief Determine if the value is greater or equal to the given number.
203 bool uge(uint64_t Num) {
204 return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
207 /// getLimitedValue - If the value is smaller than the specified limit,
208 /// return it, otherwise return the limit value. This causes the value
209 /// to saturate to the limit.
210 /// @returns the min of the value of the constant and the specified value
211 /// @brief Get the constant's value with a saturation limit
212 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
213 return Val.getLimitedValue(Limit);
216 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
217 static inline bool classof(const ConstantInt *) { return true; }
218 static bool classof(const Value *V) {
219 return V->getValueID() == ConstantIntVal;
224 //===----------------------------------------------------------------------===//
225 /// ConstantFP - Floating Point Values [float, double]
227 class ConstantFP : public Constant {
229 void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
230 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
231 friend class LLVMContextImpl;
233 ConstantFP(const Type *Ty, const APFloat& V);
235 // allocate space for exactly zero operands
236 void *operator new(size_t s) {
237 return User::operator new(s, 0);
240 /// Floating point negation must be implemented with f(x) = -0.0 - x. This
241 /// method returns the negative zero constant for floating point or vector
242 /// floating point types; for all other types, it returns the null value.
243 static Constant* getZeroValueForNegation(const Type* Ty);
245 /// get() - This returns a ConstantFP, or a vector containing a splat of a
246 /// ConstantFP, for the specified value in the specified type. This should
247 /// only be used for simple constant values like 2.0/1.0 etc, that are
248 /// known-valid both as host double and as the target format.
249 static Constant* get(const Type* Ty, double V);
250 static ConstantFP* get(LLVMContext &Context, const APFloat& V);
251 static ConstantFP* getNegativeZero(const Type* Ty);
253 /// isValueValidForType - return true if Ty is big enough to represent V.
254 static bool isValueValidForType(const Type *Ty, const APFloat& V);
255 inline const APFloat& getValueAPF() const { return Val; }
257 /// isNullValue - Return true if this is the value that would be returned by
258 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
259 /// considers -0.0 to be null as well as 0.0. :(
260 virtual bool isNullValue() const;
262 /// isNegativeZeroValue - Return true if the value is what would be returned
263 /// by getZeroValueForNegation.
264 virtual bool isNegativeZeroValue() const {
265 return Val.isZero() && Val.isNegative();
268 /// isExactlyValue - We don't rely on operator== working on double values, as
269 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
270 /// As such, this method can be used to do an exact bit-for-bit comparison of
271 /// two floating point values. The version with a double operand is retained
272 /// because it's so convenient to write isExactlyValue(2.0), but please use
273 /// it only for simple constants.
274 bool isExactlyValue(const APFloat& V) const;
276 bool isExactlyValue(double V) const {
278 // convert is not supported on this type
279 if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
282 FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
283 return isExactlyValue(FV);
285 /// Methods for support type inquiry through isa, cast, and dyn_cast:
286 static inline bool classof(const ConstantFP *) { return true; }
287 static bool classof(const Value *V) {
288 return V->getValueID() == ConstantFPVal;
292 //===----------------------------------------------------------------------===//
293 /// ConstantAggregateZero - All zero aggregate value
295 class ConstantAggregateZero : public Constant {
296 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
297 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
298 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
300 explicit ConstantAggregateZero(const Type *ty)
301 : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
303 // allocate space for exactly zero operands
304 void *operator new(size_t s) {
305 return User::operator new(s, 0);
308 /// isNullValue - Return true if this is the value that would be returned by
310 virtual bool isNullValue() const { return true; }
312 virtual void destroyConstant();
314 /// Methods for support type inquiry through isa, cast, and dyn_cast:
316 static bool classof(const ConstantAggregateZero *) { return true; }
317 static bool classof(const Value *V) {
318 return V->getValueID() == ConstantAggregateZeroVal;
323 //===----------------------------------------------------------------------===//
324 /// ConstantArray - Constant Array Declarations
326 class ConstantArray : public Constant {
327 friend struct ConstantCreator<ConstantArray, ArrayType,
328 std::vector<Constant*> >;
329 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
330 friend class LLVMContextImpl;
332 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
334 /// Transparently provide more efficient getOperand methods.
335 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
337 /// getType - Specialize the getType() method to always return an ArrayType,
338 /// which reduces the amount of casting needed in parts of the compiler.
340 inline const ArrayType *getType() const {
341 return reinterpret_cast<const ArrayType*>(Value::getType());
344 /// isString - This method returns true if the array is an array of i8 and
345 /// the elements of the array are all ConstantInt's.
346 bool isString() const;
348 /// isCString - This method returns true if the array is a string (see
350 /// isString) and it ends in a null byte \0 and does not contains any other
352 /// null bytes except its terminator.
353 bool isCString() const;
355 /// getAsString - If this array is isString(), then this method converts the
356 /// array to an std::string and returns it. Otherwise, it asserts out.
358 std::string getAsString() const;
360 /// isNullValue - Return true if this is the value that would be returned by
361 /// getNullValue. This always returns false because zero arrays are always
362 /// created as ConstantAggregateZero objects.
363 virtual bool isNullValue() const { return false; }
365 virtual void destroyConstant();
366 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
368 /// Methods for support type inquiry through isa, cast, and dyn_cast:
369 static inline bool classof(const ConstantArray *) { return true; }
370 static bool classof(const Value *V) {
371 return V->getValueID() == ConstantArrayVal;
376 struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
379 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
381 //===----------------------------------------------------------------------===//
382 // ConstantStruct - Constant Struct Declarations
384 class ConstantStruct : public Constant {
385 friend struct ConstantCreator<ConstantStruct, StructType,
386 std::vector<Constant*> >;
387 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
388 friend class LLVMContextImpl;
390 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
392 /// Transparently provide more efficient getOperand methods.
393 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
395 /// getType() specialization - Reduce amount of casting...
397 inline const StructType *getType() const {
398 return reinterpret_cast<const StructType*>(Value::getType());
401 /// isNullValue - Return true if this is the value that would be returned by
402 /// getNullValue. This always returns false because zero structs are always
403 /// created as ConstantAggregateZero objects.
404 virtual bool isNullValue() const {
408 virtual void destroyConstant();
409 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
411 /// Methods for support type inquiry through isa, cast, and dyn_cast:
412 static inline bool classof(const ConstantStruct *) { return true; }
413 static bool classof(const Value *V) {
414 return V->getValueID() == ConstantStructVal;
419 struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
422 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
424 //===----------------------------------------------------------------------===//
425 /// ConstantVector - Constant Vector Declarations
427 class ConstantVector : public Constant {
428 friend struct ConstantCreator<ConstantVector, VectorType,
429 std::vector<Constant*> >;
430 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
432 ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
434 /// Transparently provide more efficient getOperand methods.
435 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
437 /// getType - Specialize the getType() method to always return a VectorType,
438 /// which reduces the amount of casting needed in parts of the compiler.
440 inline const VectorType *getType() const {
441 return reinterpret_cast<const VectorType*>(Value::getType());
444 /// isNullValue - Return true if this is the value that would be returned by
445 /// getNullValue. This always returns false because zero vectors are always
446 /// created as ConstantAggregateZero objects.
447 virtual bool isNullValue() const { return false; }
449 /// This function will return true iff every element in this vector constant
450 /// is set to all ones.
451 /// @returns true iff this constant's emements are all set to all ones.
452 /// @brief Determine if the value is all ones.
453 bool isAllOnesValue() const;
455 /// getSplatValue - If this is a splat constant, meaning that all of the
456 /// elements have the same value, return that value. Otherwise return NULL.
457 Constant *getSplatValue();
459 virtual void destroyConstant();
460 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
462 /// Methods for support type inquiry through isa, cast, and dyn_cast:
463 static inline bool classof(const ConstantVector *) { return true; }
464 static bool classof(const Value *V) {
465 return V->getValueID() == ConstantVectorVal;
470 struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
473 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
475 //===----------------------------------------------------------------------===//
476 /// ConstantPointerNull - a constant pointer value that points to null
478 class ConstantPointerNull : public Constant {
479 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
480 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
481 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
483 explicit ConstantPointerNull(const PointerType *T)
484 : Constant(reinterpret_cast<const Type*>(T),
485 Value::ConstantPointerNullVal, 0, 0) {}
488 // allocate space for exactly zero operands
489 void *operator new(size_t s) {
490 return User::operator new(s, 0);
493 /// get() - Static factory methods - Return objects of the specified value
494 static ConstantPointerNull *get(const PointerType *T);
496 /// isNullValue - Return true if this is the value that would be returned by
498 virtual bool isNullValue() const { return true; }
500 virtual void destroyConstant();
502 /// getType - Specialize the getType() method to always return an PointerType,
503 /// which reduces the amount of casting needed in parts of the compiler.
505 inline const PointerType *getType() const {
506 return reinterpret_cast<const PointerType*>(Value::getType());
509 /// Methods for support type inquiry through isa, cast, and dyn_cast:
510 static inline bool classof(const ConstantPointerNull *) { return true; }
511 static bool classof(const Value *V) {
512 return V->getValueID() == ConstantPointerNullVal;
517 /// ConstantExpr - a constant value that is initialized with an expression using
518 /// other constant values.
520 /// This class uses the standard Instruction opcodes to define the various
521 /// constant expressions. The Opcode field for the ConstantExpr class is
522 /// maintained in the Value::SubclassData field.
523 class ConstantExpr : public Constant {
524 friend struct ConstantCreator<ConstantExpr,Type,
525 std::pair<unsigned, std::vector<Constant*> > >;
526 friend struct ConvertConstantType<ConstantExpr, Type>;
529 ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
530 : Constant(ty, ConstantExprVal, Ops, NumOps) {
531 // Operation type (an Instruction opcode) is stored as the SubclassData.
532 SubclassData = Opcode;
535 // These private methods are used by the type resolution code to create
536 // ConstantExprs in intermediate forms.
537 static Constant *getTy(const Type *Ty, unsigned Opcode,
538 Constant *C1, Constant *C2);
539 static Constant *getCompareTy(unsigned short pred, Constant *C1,
541 static Constant *getSelectTy(const Type *Ty,
542 Constant *C1, Constant *C2, Constant *C3);
543 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
544 Value* const *Idxs, unsigned NumIdxs);
545 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
547 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
548 Constant *Elt, Constant *Idx);
549 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
550 Constant *V2, Constant *Mask);
551 static Constant *getExtractValueTy(const Type *Ty, Constant *Agg,
552 const unsigned *Idxs, unsigned NumIdxs);
553 static Constant *getInsertValueTy(const Type *Ty, Constant *Agg,
555 const unsigned *Idxs, unsigned NumIdxs);
558 // Static methods to construct a ConstantExpr of different kinds. Note that
559 // these methods may return a object that is not an instance of the
560 // ConstantExpr class, because they will attempt to fold the constant
561 // expression into something simpler if possible.
563 /// Cast constant expr
565 static Constant *getTrunc (Constant *C, const Type *Ty);
566 static Constant *getSExt (Constant *C, const Type *Ty);
567 static Constant *getZExt (Constant *C, const Type *Ty);
568 static Constant *getFPTrunc (Constant *C, const Type *Ty);
569 static Constant *getFPExtend(Constant *C, const Type *Ty);
570 static Constant *getUIToFP (Constant *C, const Type *Ty);
571 static Constant *getSIToFP (Constant *C, const Type *Ty);
572 static Constant *getFPToUI (Constant *C, const Type *Ty);
573 static Constant *getFPToSI (Constant *C, const Type *Ty);
574 static Constant *getPtrToInt(Constant *C, const Type *Ty);
575 static Constant *getIntToPtr(Constant *C, const Type *Ty);
576 static Constant *getBitCast (Constant *C, const Type *Ty);
578 /// Transparently provide more efficient getOperand methods.
579 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
581 // @brief Convenience function for getting one of the casting operations
582 // using a CastOps opcode.
583 static Constant *getCast(
584 unsigned ops, ///< The opcode for the conversion
585 Constant *C, ///< The constant to be converted
586 const Type *Ty ///< The type to which the constant is converted
589 // @brief Create a ZExt or BitCast cast constant expression
590 static Constant *getZExtOrBitCast(
591 Constant *C, ///< The constant to zext or bitcast
592 const Type *Ty ///< The type to zext or bitcast C to
595 // @brief Create a SExt or BitCast cast constant expression
596 static Constant *getSExtOrBitCast(
597 Constant *C, ///< The constant to sext or bitcast
598 const Type *Ty ///< The type to sext or bitcast C to
601 // @brief Create a Trunc or BitCast cast constant expression
602 static Constant *getTruncOrBitCast(
603 Constant *C, ///< The constant to trunc or bitcast
604 const Type *Ty ///< The type to trunc or bitcast C to
607 /// @brief Create a BitCast or a PtrToInt cast constant expression
608 static Constant *getPointerCast(
609 Constant *C, ///< The pointer value to be casted (operand 0)
610 const Type *Ty ///< The type to which cast should be made
613 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
614 static Constant *getIntegerCast(
615 Constant *C, ///< The integer constant to be casted
616 const Type *Ty, ///< The integer type to cast to
617 bool isSigned ///< Whether C should be treated as signed or not
620 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
621 static Constant *getFPCast(
622 Constant *C, ///< The integer constant to be casted
623 const Type *Ty ///< The integer type to cast to
626 /// @brief Return true if this is a convert constant expression
629 /// @brief Return true if this is a compare constant expression
630 bool isCompare() const;
632 /// @brief Return true if this is an insertvalue or extractvalue expression,
633 /// and the getIndices() method may be used.
634 bool hasIndices() const;
636 /// Select constant expr
638 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
639 return getSelectTy(V1->getType(), C, V1, V2);
642 /// ConstantExpr::get - Return a binary or shift operator constant expression,
643 /// folding if possible.
645 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
647 /// @brief Return an ICmp or FCmp comparison operator constant expression.
648 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
650 /// ConstantExpr::get* - Return some common constants without having to
651 /// specify the full Instruction::OPCODE identifier.
653 static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
654 static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
656 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
657 /// all elements must be Constant's.
659 static Constant *getGetElementPtr(Constant *C,
660 Constant* const *IdxList, unsigned NumIdx);
661 static Constant *getGetElementPtr(Constant *C,
662 Value* const *IdxList, unsigned NumIdx);
664 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
665 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
666 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
667 static Constant *getExtractValue(Constant *Agg,
668 const unsigned *IdxList, unsigned NumIdx);
669 static Constant *getInsertValue(Constant *Agg, Constant *Val,
670 const unsigned *IdxList, unsigned NumIdx);
672 /// isNullValue - Return true if this is the value that would be returned by
674 virtual bool isNullValue() const { return false; }
676 /// getOpcode - Return the opcode at the root of this constant expression
677 unsigned getOpcode() const { return SubclassData; }
679 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
680 /// not an ICMP or FCMP constant expression.
681 unsigned getPredicate() const;
683 /// getIndices - Assert that this is an insertvalue or exactvalue
684 /// expression and return the list of indices.
685 const SmallVector<unsigned, 4> &getIndices() const;
687 /// getOpcodeName - Return a string representation for an opcode.
688 const char *getOpcodeName() const;
690 /// getWithOperandReplaced - Return a constant expression identical to this
691 /// one, but with the specified operand set to the specified value.
692 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
694 /// getWithOperands - This returns the current constant expression with the
695 /// operands replaced with the specified values. The specified operands must
696 /// match count and type with the existing ones.
697 Constant *getWithOperands(const std::vector<Constant*> &Ops) const {
698 return getWithOperands(&Ops[0], (unsigned)Ops.size());
700 Constant *getWithOperands(Constant* const *Ops, unsigned NumOps) const;
702 virtual void destroyConstant();
703 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
705 /// Methods for support type inquiry through isa, cast, and dyn_cast:
706 static inline bool classof(const ConstantExpr *) { return true; }
707 static inline bool classof(const Value *V) {
708 return V->getValueID() == ConstantExprVal;
713 struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
716 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
718 //===----------------------------------------------------------------------===//
719 /// UndefValue - 'undef' values are things that do not have specified contents.
720 /// These are used for a variety of purposes, including global variable
721 /// initializers and operands to instructions. 'undef' values can occur with
724 class UndefValue : public Constant {
725 friend struct ConstantCreator<UndefValue, Type, char>;
726 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
727 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
729 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
731 // allocate space for exactly zero operands
732 void *operator new(size_t s) {
733 return User::operator new(s, 0);
736 /// get() - Static factory methods - Return an 'undef' object of the specified
739 static UndefValue *get(const Type *T);
741 /// isNullValue - Return true if this is the value that would be returned by
743 virtual bool isNullValue() const { return false; }
745 virtual void destroyConstant();
747 /// Methods for support type inquiry through isa, cast, and dyn_cast:
748 static inline bool classof(const UndefValue *) { return true; }
749 static bool classof(const Value *V) {
750 return V->getValueID() == UndefValueVal;
753 } // End llvm namespace