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 //===----------------------------------------------------------------------===//
10 /// @file This file contains the declarations for the subclasses of Constant,
11 /// which represent the different flavors of constant values that live in LLVM.
12 /// Note that Constants are immutable (once created they never change) and are
13 /// fully shared by structural equivalence. This means that two structurally
14 /// equivalent constants will always have the same address. Constant's are
15 /// created on demand as needed and never deleted: thus clients don't have to
16 /// worry about the lifetime of the objects.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_CONSTANTS_H
21 #define LLVM_CONSTANTS_H
23 #include "llvm/Constant.h"
24 #include "llvm/Type.h"
25 #include "llvm/ADT/APInt.h"
26 #include "llvm/ADT/APFloat.h"
35 template<class ConstantClass, class TypeClass, class ValType>
36 struct ConstantCreator;
37 template<class ConstantClass, class TypeClass>
38 struct ConvertConstantType;
40 //===----------------------------------------------------------------------===//
41 /// This is the shared class of boolean and integer constants. This class
42 /// represents both boolean and integral constants.
43 /// @brief Class for constant integers.
44 class ConstantInt : public Constant {
45 static ConstantInt *TheTrueVal, *TheFalseVal;
46 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
47 ConstantInt(const IntegerType *Ty, const APInt& V);
50 /// Return the constant as an APInt value reference. This allows clients to
51 /// obtain a copy of the value, with all its precision in tact.
52 /// @brief Return the constant's value.
53 inline const APInt& getValue() const {
57 /// getBitWidth - Return the bitwidth of this constant.
58 unsigned getBitWidth() const { return Val.getBitWidth(); }
60 /// Return the constant as a 64-bit unsigned integer value after it
61 /// has been zero extended as appropriate for the type of this constant. Note
62 /// that this method can assert if the value does not fit in 64 bits.
64 /// @brief Return the zero extended value.
65 inline uint64_t getZExtValue() const {
66 return Val.getZExtValue();
69 /// Return the constant as a 64-bit integer value after it has been sign
70 /// sign extended as appropriate for the type of this constant. Note that
71 /// this method can assert if the value does not fit in 64 bits.
73 /// @brief Return the sign extended value.
74 inline int64_t getSExtValue() const {
75 return Val.getSExtValue();
78 /// A helper method that can be used to determine if the constant contained
79 /// within is equal to a constant. This only works for very small values,
80 /// because this is all that can be represented with all types.
81 /// @brief Determine if this constant's value is same as an unsigned char.
82 bool equalsInt(uint64_t V) const {
86 /// getTrue/getFalse - Return the singleton true/false values.
87 static inline ConstantInt *getTrue() {
88 if (TheTrueVal) return TheTrueVal;
89 return CreateTrueFalseVals(true);
91 static inline ConstantInt *getFalse() {
92 if (TheFalseVal) return TheFalseVal;
93 return CreateTrueFalseVals(false);
96 /// Return a ConstantInt with the specified value for the specified type. The
97 /// value V will be canonicalized to a an unsigned APInt. Accessing it with
98 /// either getSExtValue() or getZExtValue() will yield a correctly sized and
99 /// signed value for the type Ty.
100 /// @brief Get a ConstantInt for a specific value.
101 static ConstantInt *get(const Type *Ty, uint64_t V, bool isSigned = false);
103 /// Return a ConstantInt with the specified value and an implied Type. The
104 /// type is the integer type that corresponds to the bit width of the value.
105 static ConstantInt *get(const APInt &V);
107 /// getType - Specialize the getType() method to always return an IntegerType,
108 /// which reduces the amount of casting needed in parts of the compiler.
110 inline const IntegerType *getType() const {
111 return reinterpret_cast<const IntegerType*>(Value::getType());
114 /// This static method returns true if the type Ty is big enough to
115 /// represent the value V. This can be used to avoid having the get method
116 /// assert when V is larger than Ty can represent. Note that there are two
117 /// versions of this method, one for unsigned and one for signed integers.
118 /// Although ConstantInt canonicalizes everything to an unsigned integer,
119 /// the signed version avoids callers having to convert a signed quantity
120 /// to the appropriate unsigned type before calling the method.
121 /// @returns true if V is a valid value for type Ty
122 /// @brief Determine if the value is in range for the given type.
123 static bool isValueValidForType(const Type *Ty, uint64_t V);
124 static bool isValueValidForType(const Type *Ty, int64_t V);
126 /// This function will return true iff this constant represents the "null"
127 /// value that would be returned by the getNullValue method.
128 /// @returns true if this is the null integer value.
129 /// @brief Determine if the value is null.
130 virtual bool isNullValue() const {
134 /// This is just a convenience method to make client code smaller for a
135 /// common code. It also correctly performs the comparison without the
136 /// potential for an assertion from getZExtValue().
137 bool isZero() const {
141 /// This is just a convenience method to make client code smaller for a
142 /// common case. It also correctly performs the comparison without the
143 /// potential for an assertion from getZExtValue().
144 /// @brief Determine if the value is one.
149 /// This function will return true iff every bit in this constant is set
151 /// @returns true iff this constant's bits are all set to true.
152 /// @brief Determine if the value is all ones.
153 bool isAllOnesValue() const {
154 return Val.isAllOnesValue();
157 /// This function will return true iff this constant represents the largest
158 /// value that may be represented by the constant's type.
159 /// @returns true iff this is the largest value that may be represented
161 /// @brief Determine if the value is maximal.
162 bool isMaxValue(bool isSigned) const {
164 return Val.isMaxSignedValue();
166 return Val.isMaxValue();
169 /// This function will return true iff this constant represents the smallest
170 /// value that may be represented by this constant's type.
171 /// @returns true if this is the smallest value that may be represented by
173 /// @brief Determine if the value is minimal.
174 bool isMinValue(bool isSigned) const {
176 return Val.isMinSignedValue();
178 return Val.isMinValue();
181 /// This function will return true iff this constant represents a value with
182 /// active bits bigger than 64 bits or a value greater than the given uint64_t
184 /// @returns true iff this constant is greater or equal to the given number.
185 /// @brief Determine if the value is greater or equal to the given number.
186 bool uge(uint64_t Num) {
187 return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
190 /// @returns the 64-bit value of this constant if its active bits number is
191 /// not greater than 64, otherwise, just return the given uint64_t number.
192 /// @brief Get the constant's value if possible.
193 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
194 return Val.getLimitedValue(Limit);
197 /// @returns the value for an integer constant of the given type that has all
198 /// its bits set to true.
199 /// @brief Get the all ones value
200 static ConstantInt *getAllOnesValue(const Type *Ty);
202 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
203 static inline bool classof(const ConstantInt *) { return true; }
204 static bool classof(const Value *V) {
205 return V->getValueID() == ConstantIntVal;
207 static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
209 static ConstantInt *CreateTrueFalseVals(bool WhichOne);
213 //===----------------------------------------------------------------------===//
214 /// ConstantFP - Floating Point Values [float, double]
216 class ConstantFP : public Constant {
218 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
220 ConstantFP(const Type *Ty, const APFloat& V);
222 /// get() - Static factory methods - Return objects of the specified value
223 static ConstantFP *get(const Type *Ty, const APFloat& V);
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 // Get a negative zero.
235 static ConstantFP *getNegativeZero(const Type* Ty);
237 /// isExactlyValue - We don't rely on operator== working on double values, as
238 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
239 /// As such, this method can be used to do an exact bit-for-bit comparison of
240 /// two floating point values. The version with a double operand is retained
241 /// because it's so convenient to write isExactlyValue(2.0), but please use
242 /// it only for constants.
243 bool isExactlyValue(const APFloat& V) const;
245 bool isExactlyValue(double V) const {
246 if (&Val.getSemantics() == &APFloat::IEEEdouble)
247 return isExactlyValue(APFloat(V));
248 else if (&Val.getSemantics() == &APFloat::IEEEsingle)
249 return isExactlyValue(APFloat((float)V));
253 /// Methods for support type inquiry through isa, cast, and dyn_cast:
254 static inline bool classof(const ConstantFP *) { return true; }
255 static bool classof(const Value *V) {
256 return V->getValueID() == ConstantFPVal;
260 //===----------------------------------------------------------------------===//
261 /// ConstantAggregateZero - All zero aggregate value
263 class ConstantAggregateZero : public Constant {
264 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
265 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
267 explicit ConstantAggregateZero(const Type *Ty)
268 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
270 /// get() - static factory method for creating a null aggregate. It is
271 /// illegal to call this method with a non-aggregate type.
272 static Constant *get(const Type *Ty);
274 /// isNullValue - Return true if this is the value that would be returned by
276 virtual bool isNullValue() const { return true; }
278 virtual void destroyConstant();
280 /// Methods for support type inquiry through isa, cast, and dyn_cast:
282 static bool classof(const ConstantAggregateZero *) { return true; }
283 static bool classof(const Value *V) {
284 return V->getValueID() == ConstantAggregateZeroVal;
289 //===----------------------------------------------------------------------===//
290 /// ConstantArray - Constant Array Declarations
292 class ConstantArray : public Constant {
293 friend struct ConstantCreator<ConstantArray, ArrayType,
294 std::vector<Constant*> >;
295 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
297 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
300 /// get() - Static factory methods - Return objects of the specified value
301 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
302 static Constant *get(const ArrayType *T,
303 Constant*const*Vals, unsigned NumVals) {
304 // FIXME: make this the primary ctor method.
305 return get(T, std::vector<Constant*>(Vals, Vals+NumVals));
308 /// This method constructs a ConstantArray and initializes it with a text
309 /// string. The default behavior (AddNull==true) causes a null terminator to
310 /// be placed at the end of the array. This effectively increases the length
311 /// of the array by one (you've been warned). However, in some situations
312 /// this is not desired so if AddNull==false then the string is copied without
313 /// null termination.
314 static Constant *get(const std::string &Initializer, bool AddNull = true);
316 /// getType - Specialize the getType() method to always return an ArrayType,
317 /// which reduces the amount of casting needed in parts of the compiler.
319 inline const ArrayType *getType() const {
320 return reinterpret_cast<const ArrayType*>(Value::getType());
323 /// isString - This method returns true if the array is an array of sbyte or
324 /// ubyte, and if the elements of the array are all ConstantInt's.
325 bool isString() const;
327 /// isCString - This method returns true if the array is a string (see
329 /// isString) and it ends in a null byte \0 and does not contains any other
331 /// null bytes except its terminator.
332 bool isCString() const;
334 /// getAsString - If this array is isString(), then this method converts the
335 /// array to an std::string and returns it. Otherwise, it asserts out.
337 std::string getAsString() const;
339 /// isNullValue - Return true if this is the value that would be returned by
340 /// getNullValue. This always returns false because zero arrays are always
341 /// created as ConstantAggregateZero objects.
342 virtual bool isNullValue() const { return false; }
344 virtual void destroyConstant();
345 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
347 /// Methods for support type inquiry through isa, cast, and dyn_cast:
348 static inline bool classof(const ConstantArray *) { return true; }
349 static bool classof(const Value *V) {
350 return V->getValueID() == ConstantArrayVal;
355 //===----------------------------------------------------------------------===//
356 // ConstantStruct - Constant Struct Declarations
358 class ConstantStruct : public Constant {
359 friend struct ConstantCreator<ConstantStruct, StructType,
360 std::vector<Constant*> >;
361 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
363 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
366 /// get() - Static factory methods - Return objects of the specified value
368 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
369 static Constant *get(const std::vector<Constant*> &V, bool Packed = false);
370 static Constant *get(Constant*const* Vals, unsigned NumVals,
371 bool Packed = false) {
372 // FIXME: make this the primary ctor method.
373 return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
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;
399 //===----------------------------------------------------------------------===//
400 /// ConstantVector - Constant Vector Declarations
402 class ConstantVector : public Constant {
403 friend struct ConstantCreator<ConstantVector, VectorType,
404 std::vector<Constant*> >;
405 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
407 ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
410 /// get() - Static factory methods - Return objects of the specified value
411 static Constant *get(const VectorType *T, const std::vector<Constant*> &);
412 static Constant *get(const std::vector<Constant*> &V);
413 static Constant *get(Constant*const* Vals, unsigned NumVals) {
414 // FIXME: make this the primary ctor method.
415 return get(std::vector<Constant*>(Vals, Vals+NumVals));
418 /// getType - Specialize the getType() method to always return a VectorType,
419 /// which reduces the amount of casting needed in parts of the compiler.
421 inline const VectorType *getType() const {
422 return reinterpret_cast<const VectorType*>(Value::getType());
425 /// @returns the value for a vector integer constant of the given type that
426 /// has all its bits set to true.
427 /// @brief Get the all ones value
428 static ConstantVector *getAllOnesValue(const VectorType *Ty);
430 /// isNullValue - Return true if this is the value that would be returned by
431 /// getNullValue. This always returns false because zero vectors are always
432 /// created as ConstantAggregateZero objects.
433 virtual bool isNullValue() const { return false; }
435 /// This function will return true iff every element in this vector constant
436 /// is set to all ones.
437 /// @returns true iff this constant's emements are all set to all ones.
438 /// @brief Determine if the value is all ones.
439 bool isAllOnesValue() const;
441 /// getSplatValue - If this is a splat constant, meaning that all of the
442 /// elements have the same value, return that value. Otherwise return NULL.
443 Constant *getSplatValue();
445 virtual void destroyConstant();
446 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
448 /// Methods for support type inquiry through isa, cast, and dyn_cast:
449 static inline bool classof(const ConstantVector *) { return true; }
450 static bool classof(const Value *V) {
451 return V->getValueID() == ConstantVectorVal;
455 //===----------------------------------------------------------------------===//
456 /// ConstantPointerNull - a constant pointer value that points to null
458 class ConstantPointerNull : public Constant {
459 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
460 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
462 explicit ConstantPointerNull(const PointerType *T)
463 : Constant(reinterpret_cast<const Type*>(T),
464 Value::ConstantPointerNullVal, 0, 0) {}
468 /// get() - Static factory methods - Return objects of the specified value
469 static ConstantPointerNull *get(const PointerType *T);
471 /// isNullValue - Return true if this is the value that would be returned by
473 virtual bool isNullValue() const { return true; }
475 virtual void destroyConstant();
477 /// getType - Specialize the getType() method to always return an PointerType,
478 /// which reduces the amount of casting needed in parts of the compiler.
480 inline const PointerType *getType() const {
481 return reinterpret_cast<const PointerType*>(Value::getType());
484 /// Methods for support type inquiry through isa, cast, and dyn_cast:
485 static inline bool classof(const ConstantPointerNull *) { return true; }
486 static bool classof(const Value *V) {
487 return V->getValueID() == ConstantPointerNullVal;
492 /// ConstantExpr - a constant value that is initialized with an expression using
493 /// other constant values.
495 /// This class uses the standard Instruction opcodes to define the various
496 /// constant expressions. The Opcode field for the ConstantExpr class is
497 /// maintained in the Value::SubclassData field.
498 class ConstantExpr : public Constant {
499 friend struct ConstantCreator<ConstantExpr,Type,
500 std::pair<unsigned, std::vector<Constant*> > >;
501 friend struct ConvertConstantType<ConstantExpr, Type>;
504 ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
505 : Constant(Ty, ConstantExprVal, Ops, NumOps) {
506 // Operation type (an Instruction opcode) is stored as the SubclassData.
507 SubclassData = Opcode;
510 // These private methods are used by the type resolution code to create
511 // ConstantExprs in intermediate forms.
512 static Constant *getTy(const Type *Ty, unsigned Opcode,
513 Constant *C1, Constant *C2);
514 static Constant *getCompareTy(unsigned short pred, Constant *C1,
516 static Constant *getSelectTy(const Type *Ty,
517 Constant *C1, Constant *C2, Constant *C3);
518 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
519 Value* const *Idxs, unsigned NumIdxs);
520 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
522 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
523 Constant *Elt, Constant *Idx);
524 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
525 Constant *V2, Constant *Mask);
528 // Static methods to construct a ConstantExpr of different kinds. Note that
529 // these methods may return a object that is not an instance of the
530 // ConstantExpr class, because they will attempt to fold the constant
531 // expression into something simpler if possible.
533 /// Cast constant expr
535 static Constant *getTrunc (Constant *C, const Type *Ty);
536 static Constant *getSExt (Constant *C, const Type *Ty);
537 static Constant *getZExt (Constant *C, const Type *Ty);
538 static Constant *getFPTrunc (Constant *C, const Type *Ty);
539 static Constant *getFPExtend(Constant *C, const Type *Ty);
540 static Constant *getUIToFP (Constant *C, const Type *Ty);
541 static Constant *getSIToFP (Constant *C, const Type *Ty);
542 static Constant *getFPToUI (Constant *C, const Type *Ty);
543 static Constant *getFPToSI (Constant *C, const Type *Ty);
544 static Constant *getPtrToInt(Constant *C, const Type *Ty);
545 static Constant *getIntToPtr(Constant *C, const Type *Ty);
546 static Constant *getBitCast (Constant *C, const Type *Ty);
548 // @brief Convenience function for getting one of the casting operations
549 // using a CastOps opcode.
550 static Constant *getCast(
551 unsigned ops, ///< The opcode for the conversion
552 Constant *C, ///< The constant to be converted
553 const Type *Ty ///< The type to which the constant is converted
556 // @brief Create a ZExt or BitCast cast constant expression
557 static Constant *getZExtOrBitCast(
558 Constant *C, ///< The constant to zext or bitcast
559 const Type *Ty ///< The type to zext or bitcast C to
562 // @brief Create a SExt or BitCast cast constant expression
563 static Constant *getSExtOrBitCast(
564 Constant *C, ///< The constant to sext or bitcast
565 const Type *Ty ///< The type to sext or bitcast C to
568 // @brief Create a Trunc or BitCast cast constant expression
569 static Constant *getTruncOrBitCast(
570 Constant *C, ///< The constant to trunc or bitcast
571 const Type *Ty ///< The type to trunc or bitcast C to
574 /// @brief Create a BitCast or a PtrToInt cast constant expression
575 static Constant *getPointerCast(
576 Constant *C, ///< The pointer value to be casted (operand 0)
577 const Type *Ty ///< The type to which cast should be made
580 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
581 static Constant *getIntegerCast(
582 Constant *C, ///< The integer constant to be casted
583 const Type *Ty, ///< The integer type to cast to
584 bool isSigned ///< Whether C should be treated as signed or not
587 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
588 static Constant *getFPCast(
589 Constant *C, ///< The integer constant to be casted
590 const Type *Ty ///< The integer type to cast to
593 /// @brief Return true if this is a convert constant expression
596 /// @brief Return true if this is a compare constant expression
597 bool isCompare() const;
599 /// Select constant expr
601 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
602 return getSelectTy(V1->getType(), C, V1, V2);
605 /// getSizeOf constant expr - computes the size of a type in a target
606 /// independent way (Note: the return type is an i64).
608 static Constant *getSizeOf(const Type *Ty);
610 /// ConstantExpr::get - Return a binary or shift operator constant expression,
611 /// folding if possible.
613 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
615 /// @brief Return an ICmp or FCmp comparison operator constant expression.
616 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
618 /// ConstantExpr::get* - Return some common constants without having to
619 /// specify the full Instruction::OPCODE identifier.
621 static Constant *getNeg(Constant *C);
622 static Constant *getNot(Constant *C);
623 static Constant *getAdd(Constant *C1, Constant *C2);
624 static Constant *getSub(Constant *C1, Constant *C2);
625 static Constant *getMul(Constant *C1, Constant *C2);
626 static Constant *getUDiv(Constant *C1, Constant *C2);
627 static Constant *getSDiv(Constant *C1, Constant *C2);
628 static Constant *getFDiv(Constant *C1, Constant *C2);
629 static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
630 static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
631 static Constant *getFRem(Constant *C1, Constant *C2);
632 static Constant *getAnd(Constant *C1, Constant *C2);
633 static Constant *getOr(Constant *C1, Constant *C2);
634 static Constant *getXor(Constant *C1, Constant *C2);
635 static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
636 static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
637 static Constant *getShl(Constant *C1, Constant *C2);
638 static Constant *getLShr(Constant *C1, Constant *C2);
639 static Constant *getAShr(Constant *C1, Constant *C2);
641 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
642 /// all elements must be Constant's.
644 static Constant *getGetElementPtr(Constant *C,
645 Constant* const *IdxList, unsigned NumIdx);
646 static Constant *getGetElementPtr(Constant *C,
647 Value* const *IdxList, unsigned NumIdx);
649 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
650 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
651 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
653 /// Floating point negation must be implemented with f(x) = -0.0 - x. This
654 /// method returns the negative zero constant for floating point or vector
655 /// floating point types; for all other types, it returns the null value.
656 static Constant *getZeroValueForNegationExpr(const Type *Ty);
658 /// isNullValue - Return true if this is the value that would be returned by
660 virtual bool isNullValue() const { return false; }
662 /// getOpcode - Return the opcode at the root of this constant expression
663 unsigned getOpcode() const { return SubclassData; }
665 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
666 /// not an ICMP or FCMP constant expression.
667 unsigned getPredicate() const;
669 /// getOpcodeName - Return a string representation for an opcode.
670 const char *getOpcodeName() const;
672 /// getWithOperandReplaced - Return a constant expression identical to this
673 /// one, but with the specified operand set to the specified value.
674 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
676 /// getWithOperands - This returns the current constant expression with the
677 /// operands replaced with the specified values. The specified operands must
678 /// match count and type with the existing ones.
679 Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
681 virtual void destroyConstant();
682 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
684 /// Override methods to provide more type information...
685 inline Constant *getOperand(unsigned i) {
686 return cast<Constant>(User::getOperand(i));
688 inline Constant *getOperand(unsigned i) const {
689 return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
693 /// Methods for support type inquiry through isa, cast, and dyn_cast:
694 static inline bool classof(const ConstantExpr *) { return true; }
695 static inline bool classof(const Value *V) {
696 return V->getValueID() == ConstantExprVal;
701 //===----------------------------------------------------------------------===//
702 /// UndefValue - 'undef' values are things that do not have specified contents.
703 /// These are used for a variety of purposes, including global variable
704 /// initializers and operands to instructions. 'undef' values can occur with
707 class UndefValue : public Constant {
708 friend struct ConstantCreator<UndefValue, Type, char>;
709 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
711 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
713 /// get() - Static factory methods - Return an 'undef' object of the specified
716 static UndefValue *get(const Type *T);
718 /// isNullValue - Return true if this is the value that would be returned by
720 virtual bool isNullValue() const { return false; }
722 virtual void destroyConstant();
724 /// Methods for support type inquiry through isa, cast, and dyn_cast:
725 static inline bool classof(const UndefValue *) { return true; }
726 static bool classof(const Value *V) {
727 return V->getValueID() == UndefValueVal;
731 } // End llvm namespace