1 //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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"
33 template<class ConstantClass, class TypeClass, class ValType>
34 struct ConstantCreator;
35 template<class ConstantClass, class TypeClass>
36 struct ConvertConstantType;
38 //===----------------------------------------------------------------------===//
39 /// This is the shared superclass of boolean and integer constants. This class
40 /// just defines some common interfaces to be implemented by the subclasses.
41 /// @brief An abstract class for integer constants.
42 class ConstantIntegral : public Constant {
48 ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V);
51 /// @brief Return the raw value of the constant as a 64-bit integer value.
52 inline uint64_t getRawValue() const { return Val.Unsigned; }
54 /// Return the constant as a 64-bit unsigned integer value after it
55 /// has been zero extended as appropriate for the type of this constant.
56 /// @brief Return the zero extended value.
57 inline uint64_t getZExtValue() const {
58 unsigned Size = getType()->getPrimitiveSizeInBits();
59 return Val.Unsigned & (~uint64_t(0UL) >> (64-Size));
62 /// Return the constant as a 64-bit integer value after it has been sign
63 /// sign extended as appropriate for the type of this constant.
64 /// @brief Return the sign extended value.
65 inline int64_t getSExtValue() const {
66 unsigned Size = getType()->getPrimitiveSizeInBits();
67 return (Val.Signed << (64-Size)) >> (64-Size);
70 /// This function is implemented by subclasses and will return true iff this
71 /// constant represents the the "null" value that would be returned by the
72 /// getNullValue method.
73 /// @returns true if the constant's value is 0.
74 /// @brief Determine if the value is null.
75 virtual bool isNullValue() const = 0;
77 /// This function is implemented by sublcasses and will return true iff this
78 /// constant represents the the largest value that may be represented by this
80 /// @returns true if the constant's value is maximal.
81 /// @brief Determine if the value is maximal.
82 virtual bool isMaxValue() const = 0;
84 /// This function is implemented by subclasses and will return true iff this
85 /// constant represents the smallest value that may be represented by this
87 /// @returns true if the constant's value is minimal
88 /// @brief Determine if the value is minimal.
89 virtual bool isMinValue() const = 0;
91 /// This function is implemented by subclasses and will return true iff every
92 /// bit in this constant is set to true.
93 /// @returns true if all bits of the constant are ones.
94 /// @brief Determine if the value is all ones.
95 virtual bool isAllOnesValue() const = 0;
97 /// @returns the largest value for an integer constant of the given type
98 /// @brief Get the maximal value
99 static ConstantIntegral *getMaxValue(const Type *Ty);
101 /// @returns the smallest value for an integer constant of the given type
102 /// @brief Get the minimal value
103 static ConstantIntegral *getMinValue(const Type *Ty);
105 /// @returns the value for an integer constant of the given type that has all
106 /// its bits set to true.
107 /// @brief Get the all ones value
108 static ConstantIntegral *getAllOnesValue(const Type *Ty);
110 /// Methods to support type inquiry through isa, cast, and dyn_cast:
111 static inline bool classof(const ConstantIntegral *) { return true; }
112 static bool classof(const Value *V) {
113 return V->getValueType() == ConstantBoolVal ||
114 V->getValueType() == ConstantSIntVal ||
115 V->getValueType() == ConstantUIntVal;
120 //===----------------------------------------------------------------------===//
121 /// This concrete class represents constant values of type BoolTy. There are
122 /// only two instances of this class constructed: the True and False static
123 /// members. The constructor is hidden to ensure this invariant.
124 /// @brief Constant Boolean class
125 class ConstantBool : public ConstantIntegral {
126 ConstantBool(bool V);
128 static ConstantBool *True, *False; ///< The True & False values
130 /// This method is provided mostly for compatibility with the other
131 /// ConstantIntegral subclasses.
132 /// @brief Static factory method for getting a ConstantBool instance.
133 static ConstantBool *get(bool Value) { return Value ? True : False; }
135 /// This method is provided mostly for compatibility with the other
136 /// ConstantIntegral subclasses.
137 /// @brief Static factory method for getting a ConstantBool instance.
138 static ConstantBool *get(const Type *Ty, bool Value) { return get(Value); }
140 /// Returns the opposite value of this ConstantBool value.
141 /// @brief Get inverse value.
142 inline ConstantBool *inverted() const { return (this==True) ? False : True; }
144 /// @returns the value of this ConstantBool
145 /// @brief return the boolean value of this constant.
146 inline bool getValue() const { return static_cast<bool>(getRawValue()); }
148 /// @see ConstantIntegral for details
149 /// @brief Implement overrides
150 virtual bool isNullValue() const { return this == False; }
151 virtual bool isMaxValue() const { return this == True; }
152 virtual bool isMinValue() const { return this == False; }
153 virtual bool isAllOnesValue() const { return this == True; }
155 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
156 static inline bool classof(const ConstantBool *) { return true; }
157 static bool classof(const Value *V) {
158 return V->getValueType() == ConstantBoolVal;
163 //===----------------------------------------------------------------------===//
164 /// This is the abstract superclass of ConstantSInt & ConstantUInt, to make
165 /// dealing with integral constants easier when sign is irrelevant.
166 /// @brief Abstract clas for constant integers.
167 class ConstantInt : public ConstantIntegral {
169 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
170 ConstantInt(const Type *Ty, ValueTy VT, uint64_t V);
172 /// A helper method that can be used to determine if the constant contained
173 /// within is equal to a constant. This only works for very small values,
174 /// because this is all that can be represented with all types.
175 /// @brief Determine if this constant's value is same as an unsigned char.
176 bool equalsInt(unsigned char V) const {
178 "equalsInt: Can only be used with very small positive constants!");
179 return Val.Unsigned == V;
182 /// Return a ConstantInt with the specified value for the specified type.
183 /// This only works for very small values, because this is all that can be
184 /// represented with all types integer types.
185 /// @brief Get a ConstantInt for a specific value.
186 static ConstantInt *get(const Type *Ty, unsigned char V);
188 /// @returns true if this is the null integer value.
189 /// @see ConstantIntegral for details
190 /// @brief Implement override.
191 virtual bool isNullValue() const { return Val.Unsigned == 0; }
193 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
194 static inline bool classof(const ConstantInt *) { return true; }
195 static bool classof(const Value *V) {
196 return V->getValueType() == ConstantSIntVal ||
197 V->getValueType() == ConstantUIntVal;
202 //===----------------------------------------------------------------------===//
203 /// A concrete class to represent constant signed integer values for the types
204 /// sbyte, short, int, and long.
205 /// @brief Constant Signed Integer Class.
206 class ConstantSInt : public ConstantInt {
207 ConstantSInt(const ConstantSInt &); // DO NOT IMPLEMENT
208 friend struct ConstantCreator<ConstantSInt, Type, int64_t>;
211 ConstantSInt(const Type *Ty, int64_t V);
213 /// This static factory methods returns objects of the specified value. Note
214 /// that repeated calls with the same operands return the same object.
215 /// @returns A ConstantSInt instant for the type and value requested.
216 /// @brief Get a signed integer constant.
217 static ConstantSInt *get(
218 const Type *Ty, ///< The type of constant (SByteTy, IntTy, ShortTy, LongTy)
219 int64_t V ///< The value for the constant integer.
222 /// This static method returns true if the type Ty is big enough to
223 /// represent the value V. This can be used to avoid having the get method
224 /// assert when V is larger than Ty can represent.
225 /// @returns true if V is a valid value for type Ty
226 /// @brief Determine if the value is in range for the given type.
227 static bool isValueValidForType(const Type *Ty, int64_t V);
229 /// @returns the underlying value of this constant.
230 /// @brief Get the constant value.
231 inline int64_t getValue() const { return Val.Signed; }
233 /// @returns true iff this constant's bits are all set to true.
234 /// @see ConstantIntegral
235 /// @brief Override implementation
236 virtual bool isAllOnesValue() const { return getValue() == -1; }
238 /// @returns true iff this is the largest value that may be represented
240 /// @see ConstantIntegeral
241 /// @brief Override implementation
242 virtual bool isMaxValue() const {
243 int64_t V = getValue();
244 if (V < 0) return false; // Be careful about wrap-around on 'long's
246 return !isValueValidForType(getType(), V) || V < 0;
249 /// @returns true if this is the smallest value that may be represented by
251 /// @see ConstantIntegral
252 /// @brief Override implementation
253 virtual bool isMinValue() const {
254 int64_t V = getValue();
255 if (V > 0) return false; // Be careful about wrap-around on 'long's
257 return !isValueValidForType(getType(), V) || V > 0;
260 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
261 static inline bool classof(const ConstantSInt *) { return true; }
262 static bool classof(const Value *V) {
263 return V->getValueType() == ConstantSIntVal;
267 //===----------------------------------------------------------------------===//
268 /// A concrete class that represents constant unsigned integer values of type
269 /// Type::UByteTy, Type::UShortTy, Type::UIntTy, or Type::ULongTy.
270 /// @brief Constant Unsigned Integer Class
271 class ConstantUInt : public ConstantInt {
272 ConstantUInt(const ConstantUInt &); // DO NOT IMPLEMENT
273 friend struct ConstantCreator<ConstantUInt, Type, uint64_t>;
275 ConstantUInt(const Type *Ty, uint64_t V);
277 /// get() - Static factory methods - Return objects of the specified value
279 static ConstantUInt *get(const Type *Ty, uint64_t V);
281 /// isValueValidForType - return true if Ty is big enough to represent V.
283 static bool isValueValidForType(const Type *Ty, uint64_t V);
285 /// getValue - return the underlying value of this constant.
287 inline uint64_t getValue() const { return Val.Unsigned; }
289 /// isMaxValue - Return true if this is the largest value that may be
290 /// represented by this type.
292 virtual bool isAllOnesValue() const;
293 virtual bool isMaxValue() const { return isAllOnesValue(); }
294 virtual bool isMinValue() const { return getValue() == 0; }
296 /// Methods for support type inquiry through isa, cast, and dyn_cast:
297 static inline bool classof(const ConstantUInt *) { return true; }
298 static bool classof(const Value *V) {
299 return V->getValueType() == ConstantUIntVal;
304 //===----------------------------------------------------------------------===//
305 /// ConstantFP - Floating Point Values [float, double]
307 class ConstantFP : public Constant {
309 friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
310 friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
311 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
313 ConstantFP(const Type *Ty, double V);
315 /// get() - Static factory methods - Return objects of the specified value
316 static ConstantFP *get(const Type *Ty, double V);
318 /// isValueValidForType - return true if Ty is big enough to represent V.
319 static bool isValueValidForType(const Type *Ty, double V);
320 inline double getValue() const { return Val; }
322 /// isNullValue - Return true if this is the value that would be returned by
323 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
324 /// considers -0.0 to be null as well as 0.0. :(
325 virtual bool isNullValue() const;
327 /// isExactlyValue - We don't rely on operator== working on double values, as
328 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
329 /// As such, this method can be used to do an exact bit-for-bit comparison of
330 /// two floating point values.
331 bool isExactlyValue(double V) const;
333 /// Methods for support type inquiry through isa, cast, and dyn_cast:
334 static inline bool classof(const ConstantFP *) { return true; }
335 static bool classof(const Value *V) {
336 return V->getValueType() == ConstantFPVal;
340 //===----------------------------------------------------------------------===//
341 /// ConstantAggregateZero - All zero aggregate value
343 class ConstantAggregateZero : public Constant {
344 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
345 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
347 ConstantAggregateZero(const Type *Ty)
348 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
350 /// get() - static factory method for creating a null aggregate. It is
351 /// illegal to call this method with a non-aggregate type.
352 static Constant *get(const Type *Ty);
354 /// isNullValue - Return true if this is the value that would be returned by
356 virtual bool isNullValue() const { return true; }
358 virtual void destroyConstant();
360 /// Methods for support type inquiry through isa, cast, and dyn_cast:
362 static bool classof(const ConstantAggregateZero *) { return true; }
363 static bool classof(const Value *V) {
364 return V->getValueType() == ConstantAggregateZeroVal;
369 //===----------------------------------------------------------------------===//
370 /// ConstantArray - Constant Array Declarations
372 class ConstantArray : public Constant {
373 friend struct ConstantCreator<ConstantArray, ArrayType,
374 std::vector<Constant*> >;
375 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
377 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
380 /// get() - Static factory methods - Return objects of the specified value
381 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
383 /// This method constructs a ConstantArray and initializes it with a text
384 /// string. The default behavior (AddNull==true) causes a null terminator to
385 /// be placed at the end of the array. This effectively increases the length
386 /// of the array by one (you've been warned). However, in some situations
387 /// this is not desired so if AddNull==false then the string is copied without
388 /// null termination.
389 static Constant *get(const std::string &Initializer, bool AddNull = true);
391 /// getType - Specialize the getType() method to always return an ArrayType,
392 /// which reduces the amount of casting needed in parts of the compiler.
394 inline const ArrayType *getType() const {
395 return reinterpret_cast<const ArrayType*>(Value::getType());
398 /// isString - This method returns true if the array is an array of sbyte or
399 /// ubyte, and if the elements of the array are all ConstantInt's.
400 bool isString() const;
402 /// getAsString - If this array is isString(), then this method converts the
403 /// array to an std::string and returns it. Otherwise, it asserts out.
405 std::string getAsString() const;
407 /// isNullValue - Return true if this is the value that would be returned by
408 /// getNullValue. This always returns false because zero arrays are always
409 /// created as ConstantAggregateZero objects.
410 virtual bool isNullValue() const { return false; }
412 virtual void destroyConstant();
413 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
415 /// Methods for support type inquiry through isa, cast, and dyn_cast:
416 static inline bool classof(const ConstantArray *) { return true; }
417 static bool classof(const Value *V) {
418 return V->getValueType() == ConstantArrayVal;
423 //===----------------------------------------------------------------------===//
424 // ConstantStruct - Constant Struct Declarations
426 class ConstantStruct : public Constant {
427 friend struct ConstantCreator<ConstantStruct, StructType,
428 std::vector<Constant*> >;
429 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
431 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
434 /// get() - Static factory methods - Return objects of the specified value
436 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
437 static Constant *get(const std::vector<Constant*> &V);
439 /// getType() specialization - Reduce amount of casting...
441 inline const StructType *getType() const {
442 return reinterpret_cast<const StructType*>(Value::getType());
445 /// isNullValue - Return true if this is the value that would be returned by
446 /// getNullValue. This always returns false because zero structs are always
447 /// created as ConstantAggregateZero objects.
448 virtual bool isNullValue() const {
452 virtual void destroyConstant();
453 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
455 /// Methods for support type inquiry through isa, cast, and dyn_cast:
456 static inline bool classof(const ConstantStruct *) { return true; }
457 static bool classof(const Value *V) {
458 return V->getValueType() == ConstantStructVal;
462 //===----------------------------------------------------------------------===//
463 /// ConstantPacked - Constant Packed Declarations
465 class ConstantPacked : public Constant {
466 friend struct ConstantCreator<ConstantPacked, PackedType,
467 std::vector<Constant*> >;
468 ConstantPacked(const ConstantPacked &); // DO NOT IMPLEMENT
470 ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val);
473 /// get() - Static factory methods - Return objects of the specified value
474 static Constant *get(const PackedType *T, const std::vector<Constant*> &);
475 static Constant *get(const std::vector<Constant*> &V);
477 /// getType - Specialize the getType() method to always return an PackedType,
478 /// which reduces the amount of casting needed in parts of the compiler.
480 inline const PackedType *getType() const {
481 return reinterpret_cast<const PackedType*>(Value::getType());
484 /// isNullValue - Return true if this is the value that would be returned by
485 /// getNullValue. This always returns false because zero arrays are always
486 /// created as ConstantAggregateZero objects.
487 virtual bool isNullValue() const { return false; }
489 virtual void destroyConstant();
490 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
492 /// Methods for support type inquiry through isa, cast, and dyn_cast:
493 static inline bool classof(const ConstantPacked *) { return true; }
494 static bool classof(const Value *V) {
495 return V->getValueType() == ConstantPackedVal;
499 //===----------------------------------------------------------------------===//
500 /// ConstantPointerNull - a constant pointer value that points to null
502 class ConstantPointerNull : public Constant {
503 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
504 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
506 ConstantPointerNull(const PointerType *T)
507 : Constant(reinterpret_cast<const Type*>(T),
508 Value::ConstantPointerNullVal, 0, 0) {}
512 /// get() - Static factory methods - Return objects of the specified value
513 static ConstantPointerNull *get(const PointerType *T);
515 /// isNullValue - Return true if this is the value that would be returned by
517 virtual bool isNullValue() const { return true; }
519 virtual void destroyConstant();
521 /// getType - Specialize the getType() method to always return an PointerType,
522 /// which reduces the amount of casting needed in parts of the compiler.
524 inline const PointerType *getType() const {
525 return reinterpret_cast<const PointerType*>(Value::getType());
528 /// Methods for support type inquiry through isa, cast, and dyn_cast:
529 static inline bool classof(const ConstantPointerNull *) { return true; }
530 static bool classof(const Value *V) {
531 return V->getValueType() == ConstantPointerNullVal;
536 /// ConstantExpr - a constant value that is initialized with an expression using
537 /// other constant values.
539 /// This class uses the standard Instruction opcodes to define the various
540 /// constant expressions. The Opcode field for the ConstantExpr class is
541 /// maintained in the Value::SubclassData field.
542 class ConstantExpr : public Constant {
543 friend struct ConstantCreator<ConstantExpr,Type,
544 std::pair<unsigned, std::vector<Constant*> > >;
545 friend struct ConvertConstantType<ConstantExpr, Type>;
548 ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
549 : Constant(Ty, ConstantExprVal, Ops, NumOps) {
550 // Operation type (an Instruction opcode) is stored as the SubclassData.
551 SubclassData = Opcode;
554 // These private methods are used by the type resolution code to create
555 // ConstantExprs in intermediate forms.
556 static Constant *getTy(const Type *Ty, unsigned Opcode,
557 Constant *C1, Constant *C2);
558 static Constant *getShiftTy(const Type *Ty,
559 unsigned Opcode, Constant *C1, Constant *C2);
560 static Constant *getSelectTy(const Type *Ty,
561 Constant *C1, Constant *C2, Constant *C3);
562 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
563 const std::vector<Value*> &IdxList);
564 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
566 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
567 Constant *Elt, Constant *Idx);
568 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
569 Constant *V2, Constant *Mask);
572 // Static methods to construct a ConstantExpr of different kinds. Note that
573 // these methods may return a object that is not an instance of the
574 // ConstantExpr class, because they will attempt to fold the constant
575 // expression into something simpler if possible.
577 /// Cast constant expr
579 static Constant *getCast(Constant *C, const Type *Ty);
580 static Constant *getSignExtend(Constant *C, const Type *Ty);
581 static Constant *getZeroExtend(Constant *C, const Type *Ty);
583 /// Select constant expr
585 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
586 return getSelectTy(V1->getType(), C, V1, V2);
589 /// getSizeOf constant expr - computes the size of a type in a target
590 /// independent way (Note: the return type is ULong but the object is not
591 /// necessarily a ConstantUInt).
593 static Constant *getSizeOf(const Type *Ty);
595 /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
596 /// return a pointer to a pointer of the array element type.
597 static Constant *getPtrPtrFromArrayPtr(Constant *C);
599 /// ConstantExpr::get - Return a binary or shift operator constant expression,
600 /// folding if possible.
602 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
604 /// ConstantExpr::get* - Return some common constants without having to
605 /// specify the full Instruction::OPCODE identifier.
607 static Constant *getNeg(Constant *C);
608 static Constant *getNot(Constant *C);
609 static Constant *getAdd(Constant *C1, Constant *C2);
610 static Constant *getSub(Constant *C1, Constant *C2);
611 static Constant *getMul(Constant *C1, Constant *C2);
612 static Constant *getDiv(Constant *C1, Constant *C2);
613 static Constant *getRem(Constant *C1, Constant *C2);
614 static Constant *getAnd(Constant *C1, Constant *C2);
615 static Constant *getOr(Constant *C1, Constant *C2);
616 static Constant *getXor(Constant *C1, Constant *C2);
617 static Constant *getSetEQ(Constant *C1, Constant *C2);
618 static Constant *getSetNE(Constant *C1, Constant *C2);
619 static Constant *getSetLT(Constant *C1, Constant *C2);
620 static Constant *getSetGT(Constant *C1, Constant *C2);
621 static Constant *getSetLE(Constant *C1, Constant *C2);
622 static Constant *getSetGE(Constant *C1, Constant *C2);
623 static Constant *getShl(Constant *C1, Constant *C2);
624 static Constant *getShr(Constant *C1, Constant *C2);
626 static Constant *getUShr(Constant *C1, Constant *C2); // unsigned shr
627 static Constant *getSShr(Constant *C1, Constant *C2); // signed shr
629 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
630 /// all elements must be Constant's.
632 static Constant *getGetElementPtr(Constant *C,
633 const std::vector<Constant*> &IdxList);
634 static Constant *getGetElementPtr(Constant *C,
635 const std::vector<Value*> &IdxList);
637 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
638 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
639 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
641 /// isNullValue - Return true if this is the value that would be returned by
643 virtual bool isNullValue() const { return false; }
645 /// getOpcode - Return the opcode at the root of this constant expression
646 unsigned getOpcode() const { return SubclassData; }
648 /// getOpcodeName - Return a string representation for an opcode.
649 const char *getOpcodeName() const;
651 /// getWithOperandReplaced - Return a constant expression identical to this
652 /// one, but with the specified operand set to the specified value.
653 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
655 /// getWithOperands - This returns the current constant expression with the
656 /// operands replaced with the specified values. The specified operands must
657 /// match count and type with the existing ones.
658 Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
660 virtual void destroyConstant();
661 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
663 /// Override methods to provide more type information...
664 inline Constant *getOperand(unsigned i) {
665 return cast<Constant>(User::getOperand(i));
667 inline Constant *getOperand(unsigned i) const {
668 return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
672 /// Methods for support type inquiry through isa, cast, and dyn_cast:
673 static inline bool classof(const ConstantExpr *) { return true; }
674 static inline bool classof(const Value *V) {
675 return V->getValueType() == ConstantExprVal;
680 //===----------------------------------------------------------------------===//
681 /// UndefValue - 'undef' values are things that do not have specified contents.
682 /// These are used for a variety of purposes, including global variable
683 /// initializers and operands to instructions. 'undef' values can occur with
686 class UndefValue : public Constant {
687 friend struct ConstantCreator<UndefValue, Type, char>;
688 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
690 UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
692 /// get() - Static factory methods - Return an 'undef' object of the specified
695 static UndefValue *get(const Type *T);
697 /// isNullValue - Return true if this is the value that would be returned by
699 virtual bool isNullValue() const { return false; }
701 virtual void destroyConstant();
703 /// Methods for support type inquiry through isa, cast, and dyn_cast:
704 static inline bool classof(const UndefValue *) { return true; }
705 static bool classof(const Value *V) {
706 return V->getValueType() == UndefValueVal;
710 } // End llvm namespace