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 {
45 ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V);
48 /// ConstantIntegral::get - Return a bool or integer constant.
49 static ConstantIntegral *get(const Type *Ty, int64_t V);
51 /// Return the constant as a 64-bit unsigned integer value after it
52 /// has been zero extended as appropriate for the type of this constant.
53 /// @brief Return the zero extended value.
54 inline uint64_t getZExtValue() const {
58 /// Return the constant as a 64-bit integer value after it has been sign
59 /// sign extended as appropriate for the type of this constant.
60 /// @brief Return the sign extended value.
61 inline int64_t getSExtValue() const {
62 unsigned Size = getType()->getPrimitiveSizeInBits();
63 return (int64_t(Val) << (64-Size)) >> (64-Size);
66 /// This function is implemented by subclasses and will return true iff this
67 /// constant represents the the "null" value that would be returned by the
68 /// getNullValue method.
69 /// @returns true if the constant's value is 0.
70 /// @brief Determine if the value is null.
71 virtual bool isNullValue() const = 0;
73 /// This function is implemented by sublcasses and will return true iff this
74 /// constant represents the the largest value that may be represented by this
76 /// @returns true if the constant's value is maximal.
77 /// @brief Determine if the value is maximal.
78 virtual bool isMaxValue(bool isSigned) const = 0;
80 /// This function is implemented by subclasses and will return true iff this
81 /// constant represents the smallest value that may be represented by this
83 /// @returns true if the constant's value is minimal
84 /// @brief Determine if the value is minimal.
85 virtual bool isMinValue(bool isSigned) const = 0;
87 /// This function is implemented by subclasses and will return true iff every
88 /// bit in this constant is set to true.
89 /// @returns true if all bits of the constant are ones.
90 /// @brief Determine if the value is all ones.
91 virtual bool isAllOnesValue() const = 0;
93 /// @returns the value for an integer constant of the given type that has all
94 /// its bits set to true.
95 /// @brief Get the all ones value
96 static ConstantIntegral *getAllOnesValue(const Type *Ty);
98 /// Methods to support type inquiry through isa, cast, and dyn_cast:
99 static inline bool classof(const ConstantIntegral *) { return true; }
100 static bool classof(const Value *V) {
101 return V->getValueType() == ConstantBoolVal ||
102 V->getValueType() == ConstantIntVal;
107 //===----------------------------------------------------------------------===//
108 /// This concrete class represents constant values of type BoolTy. There are
109 /// only two instances of this class constructed: the True and False static
110 /// members. The constructor is hidden to ensure this invariant.
111 /// @brief Constant Boolean class
112 class ConstantBool : public ConstantIntegral {
113 ConstantBool(bool V);
115 /// getTrue/getFalse - Return the singleton true/false values.
116 static ConstantBool *getTrue();
117 static ConstantBool *getFalse();
119 /// This method is provided mostly for compatibility with the other
120 /// ConstantIntegral subclasses.
121 /// @brief Static factory method for getting a ConstantBool instance.
122 static ConstantBool *get(bool Value) { return Value ? getTrue() : getFalse();}
124 /// This method is provided mostly for compatibility with the other
125 /// ConstantIntegral subclasses.
126 /// @brief Static factory method for getting a ConstantBool instance.
127 static ConstantBool *get(const Type *Ty, bool Value) { return get(Value); }
129 /// Returns the opposite value of this ConstantBool value.
130 /// @brief Get inverse value.
131 inline ConstantBool *inverted() const {
132 return getValue() ? getFalse() : getTrue();
135 /// @returns the value of this ConstantBool
136 /// @brief return the boolean value of this constant.
137 inline bool getValue() const { return static_cast<bool>(getZExtValue()); }
139 /// @see ConstantIntegral for details
140 /// @brief Implement overrides
141 virtual bool isNullValue() const { return getValue() == false; }
142 virtual bool isMaxValue(bool isSigned) const { return getValue() == true; }
143 virtual bool isMinValue(bool isSigned) const { return getValue() == false; }
144 virtual bool isAllOnesValue() const { return getValue() == true; }
146 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
147 static inline bool classof(const ConstantBool *) { return true; }
148 static bool classof(const Value *V) {
149 return V->getValueType() == ConstantBoolVal;
154 //===----------------------------------------------------------------------===//
155 /// This is concrete integer subclass of ConstantIntegral that represents
156 /// both signed and unsigned integral constants, other than boolean.
157 /// @brief Class for constant integers.
158 class ConstantInt : public ConstantIntegral {
160 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
161 ConstantInt(const Type *Ty, uint64_t V);
162 ConstantInt(const Type *Ty, int64_t V);
163 friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
165 /// A helper method that can be used to determine if the constant contained
166 /// within is equal to a constant. This only works for very small values,
167 /// because this is all that can be represented with all types.
168 /// @brief Determine if this constant's value is same as an unsigned char.
169 bool equalsInt(unsigned char V) const {
171 "equalsInt: Can only be used with very small positive constants!");
175 /// Return a ConstantInt with the specified value for the specified type. The
176 /// value V will be canonicalized to a uint64_t but accessing it with either
177 /// getSExtValue() or getZExtValue() (ConstantIntegral) will yield the correct
178 /// sized/signed value for the type Ty.
179 /// @brief Get a ConstantInt for a specific value.
180 static ConstantInt *get(const Type *Ty, int64_t V);
182 /// This static method returns true if the type Ty is big enough to
183 /// represent the value V. This can be used to avoid having the get method
184 /// assert when V is larger than Ty can represent.
185 /// @returns true if V is a valid value for type Ty
186 /// @brief Determine if the value is in range for the given type.
187 static bool isValueValidForType(const Type *Ty, int64_t V);
189 /// @returns true if this is the null integer value.
190 /// @see ConstantIntegral for details
191 /// @brief Implement override.
192 virtual bool isNullValue() const { return Val == 0; }
194 /// @returns true iff this constant's bits are all set to true.
195 /// @see ConstantIntegral
196 /// @brief Override implementation
197 virtual bool isAllOnesValue() const { return getSExtValue() == -1; }
199 /// @returns true iff this is the largest value that may be represented
201 /// @see ConstantIntegeral
202 /// @brief Override implementation
203 virtual bool isMaxValue(bool isSigned) const {
205 int64_t V = getSExtValue();
206 if (V < 0) return false; // Be careful about wrap-around on 'long's
208 return !isValueValidForType(getType()->getSignedVersion(), V) || V < 0;
210 return isAllOnesValue();
213 /// @returns true if this is the smallest value that may be represented by
215 /// @see ConstantIntegral
216 /// @brief Override implementation
217 virtual bool isMinValue(bool isSigned) const {
219 int64_t V = getSExtValue();
220 if (V > 0) return false; // Be careful about wrap-around on 'long's
222 return !isValueValidForType(getType()->getSignedVersion(), V) || V > 0;
224 return getZExtValue() == 0;
227 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
228 static inline bool classof(const ConstantInt *) { return true; }
229 static bool classof(const Value *V) {
230 return V->getValueType() == ConstantIntVal;
235 //===----------------------------------------------------------------------===//
236 /// ConstantFP - Floating Point Values [float, double]
238 class ConstantFP : public Constant {
240 friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
241 friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
242 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
244 ConstantFP(const Type *Ty, double V);
246 /// get() - Static factory methods - Return objects of the specified value
247 static ConstantFP *get(const Type *Ty, double V);
249 /// isValueValidForType - return true if Ty is big enough to represent V.
250 static bool isValueValidForType(const Type *Ty, double V);
251 inline double getValue() const { return Val; }
253 /// isNullValue - Return true if this is the value that would be returned by
254 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
255 /// considers -0.0 to be null as well as 0.0. :(
256 virtual bool isNullValue() const;
258 /// isExactlyValue - We don't rely on operator== working on double values, as
259 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
260 /// As such, this method can be used to do an exact bit-for-bit comparison of
261 /// two floating point values.
262 bool isExactlyValue(double V) const;
264 /// Methods for support type inquiry through isa, cast, and dyn_cast:
265 static inline bool classof(const ConstantFP *) { return true; }
266 static bool classof(const Value *V) {
267 return V->getValueType() == ConstantFPVal;
271 //===----------------------------------------------------------------------===//
272 /// ConstantAggregateZero - All zero aggregate value
274 class ConstantAggregateZero : public Constant {
275 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
276 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
278 ConstantAggregateZero(const Type *Ty)
279 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
281 /// get() - static factory method for creating a null aggregate. It is
282 /// illegal to call this method with a non-aggregate type.
283 static Constant *get(const Type *Ty);
285 /// isNullValue - Return true if this is the value that would be returned by
287 virtual bool isNullValue() const { return true; }
289 virtual void destroyConstant();
291 /// Methods for support type inquiry through isa, cast, and dyn_cast:
293 static bool classof(const ConstantAggregateZero *) { return true; }
294 static bool classof(const Value *V) {
295 return V->getValueType() == ConstantAggregateZeroVal;
300 //===----------------------------------------------------------------------===//
301 /// ConstantArray - Constant Array Declarations
303 class ConstantArray : public Constant {
304 friend struct ConstantCreator<ConstantArray, ArrayType,
305 std::vector<Constant*> >;
306 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
308 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
311 /// get() - Static factory methods - Return objects of the specified value
312 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
314 /// This method constructs a ConstantArray and initializes it with a text
315 /// string. The default behavior (AddNull==true) causes a null terminator to
316 /// be placed at the end of the array. This effectively increases the length
317 /// of the array by one (you've been warned). However, in some situations
318 /// this is not desired so if AddNull==false then the string is copied without
319 /// null termination.
320 static Constant *get(const std::string &Initializer, bool AddNull = true);
322 /// getType - Specialize the getType() method to always return an ArrayType,
323 /// which reduces the amount of casting needed in parts of the compiler.
325 inline const ArrayType *getType() const {
326 return reinterpret_cast<const ArrayType*>(Value::getType());
329 /// isString - This method returns true if the array is an array of sbyte or
330 /// ubyte, and if the elements of the array are all ConstantInt's.
331 bool isString() const;
333 /// isCString - This method returns true if the array is a string (see
334 /// isString) and it ends in a null byte \0 and does not contains any other
335 /// null bytes except its terminator.
336 bool isCString() const;
338 /// getAsString - If this array is isString(), then this method converts the
339 /// array to an std::string and returns it. Otherwise, it asserts out.
341 std::string getAsString() const;
343 /// isNullValue - Return true if this is the value that would be returned by
344 /// getNullValue. This always returns false because zero arrays are always
345 /// created as ConstantAggregateZero objects.
346 virtual bool isNullValue() const { return false; }
348 virtual void destroyConstant();
349 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
351 /// Methods for support type inquiry through isa, cast, and dyn_cast:
352 static inline bool classof(const ConstantArray *) { return true; }
353 static bool classof(const Value *V) {
354 return V->getValueType() == ConstantArrayVal;
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);
370 /// get() - Static factory methods - Return objects of the specified value
372 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
373 static Constant *get(const std::vector<Constant*> &V, bool packed = false);
375 /// getType() specialization - Reduce amount of casting...
377 inline const StructType *getType() const {
378 return reinterpret_cast<const StructType*>(Value::getType());
381 /// isNullValue - Return true if this is the value that would be returned by
382 /// getNullValue. This always returns false because zero structs are always
383 /// created as ConstantAggregateZero objects.
384 virtual bool isNullValue() const {
388 virtual void destroyConstant();
389 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
391 /// Methods for support type inquiry through isa, cast, and dyn_cast:
392 static inline bool classof(const ConstantStruct *) { return true; }
393 static bool classof(const Value *V) {
394 return V->getValueType() == ConstantStructVal;
398 //===----------------------------------------------------------------------===//
399 /// ConstantPacked - Constant Packed Declarations
401 class ConstantPacked : public Constant {
402 friend struct ConstantCreator<ConstantPacked, PackedType,
403 std::vector<Constant*> >;
404 ConstantPacked(const ConstantPacked &); // DO NOT IMPLEMENT
406 ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val);
409 /// get() - Static factory methods - Return objects of the specified value
410 static Constant *get(const PackedType *T, const std::vector<Constant*> &);
411 static Constant *get(const std::vector<Constant*> &V);
413 /// getType - Specialize the getType() method to always return an PackedType,
414 /// which reduces the amount of casting needed in parts of the compiler.
416 inline const PackedType *getType() const {
417 return reinterpret_cast<const PackedType*>(Value::getType());
420 /// isNullValue - Return true if this is the value that would be returned by
421 /// getNullValue. This always returns false because zero arrays are always
422 /// created as ConstantAggregateZero objects.
423 virtual bool isNullValue() const { return false; }
425 virtual void destroyConstant();
426 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
428 /// Methods for support type inquiry through isa, cast, and dyn_cast:
429 static inline bool classof(const ConstantPacked *) { return true; }
430 static bool classof(const Value *V) {
431 return V->getValueType() == ConstantPackedVal;
435 //===----------------------------------------------------------------------===//
436 /// ConstantPointerNull - a constant pointer value that points to null
438 class ConstantPointerNull : public Constant {
439 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
440 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
442 ConstantPointerNull(const PointerType *T)
443 : Constant(reinterpret_cast<const Type*>(T),
444 Value::ConstantPointerNullVal, 0, 0) {}
448 /// get() - Static factory methods - Return objects of the specified value
449 static ConstantPointerNull *get(const PointerType *T);
451 /// isNullValue - Return true if this is the value that would be returned by
453 virtual bool isNullValue() const { return true; }
455 virtual void destroyConstant();
457 /// getType - Specialize the getType() method to always return an PointerType,
458 /// which reduces the amount of casting needed in parts of the compiler.
460 inline const PointerType *getType() const {
461 return reinterpret_cast<const PointerType*>(Value::getType());
464 /// Methods for support type inquiry through isa, cast, and dyn_cast:
465 static inline bool classof(const ConstantPointerNull *) { return true; }
466 static bool classof(const Value *V) {
467 return V->getValueType() == ConstantPointerNullVal;
472 /// ConstantExpr - a constant value that is initialized with an expression using
473 /// other constant values.
475 /// This class uses the standard Instruction opcodes to define the various
476 /// constant expressions. The Opcode field for the ConstantExpr class is
477 /// maintained in the Value::SubclassData field.
478 class ConstantExpr : public Constant {
479 friend struct ConstantCreator<ConstantExpr,Type,
480 std::pair<unsigned, std::vector<Constant*> > >;
481 friend struct ConvertConstantType<ConstantExpr, Type>;
484 ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
485 : Constant(Ty, ConstantExprVal, Ops, NumOps) {
486 // Operation type (an Instruction opcode) is stored as the SubclassData.
487 SubclassData = Opcode;
490 // These private methods are used by the type resolution code to create
491 // ConstantExprs in intermediate forms.
492 static Constant *getTy(const Type *Ty, unsigned Opcode,
493 Constant *C1, Constant *C2);
494 static Constant *getCompareTy(unsigned Opcode, unsigned short pred,
495 Constant *C1, Constant *C2);
496 static Constant *getShiftTy(const Type *Ty,
497 unsigned Opcode, Constant *C1, Constant *C2);
498 static Constant *getSelectTy(const Type *Ty,
499 Constant *C1, Constant *C2, Constant *C3);
500 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
501 const std::vector<Value*> &IdxList);
502 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
504 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
505 Constant *Elt, Constant *Idx);
506 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
507 Constant *V2, Constant *Mask);
510 // Static methods to construct a ConstantExpr of different kinds. Note that
511 // these methods may return a object that is not an instance of the
512 // ConstantExpr class, because they will attempt to fold the constant
513 // expression into something simpler if possible.
515 /// Cast constant expr
517 static Constant *getTrunc (Constant *C, const Type *Ty);
518 static Constant *getSExt (Constant *C, const Type *Ty);
519 static Constant *getZExt (Constant *C, const Type *Ty);
520 static Constant *getFPTrunc (Constant *C, const Type *Ty);
521 static Constant *getFPExtend(Constant *C, const Type *Ty);
522 static Constant *getUIToFP (Constant *C, const Type *Ty);
523 static Constant *getSIToFP (Constant *C, const Type *Ty);
524 static Constant *getFPToUI (Constant *C, const Type *Ty);
525 static Constant *getFPToSI (Constant *C, const Type *Ty);
526 static Constant *getPtrToInt(Constant *C, const Type *Ty);
527 static Constant *getIntToPtr(Constant *C, const Type *Ty);
528 static Constant *getBitCast (Constant *C, const Type *Ty);
530 // @brief Convenience function for getting one of the casting operations
531 // using a CastOps opcode.
532 static Constant *getCast(
533 unsigned ops, ///< The opcode for the conversion
534 Constant *C, ///< The constant to be converted
535 const Type *Ty ///< The type to which the constant is converted
538 // @brief Create a ZExt or BitCast cast constant expression
539 static Constant *getZExtOrBitCast(
540 Constant *C, ///< The constant to zext or bitcast
541 const Type *Ty ///< The type to zext or bitcast C to
544 // @brief Create a SExt or BitCast cast constant expression
545 static Constant *getSExtOrBitCast(
546 Constant *C, ///< The constant to sext or bitcast
547 const Type *Ty ///< The type to sext or bitcast C to
550 // @brief Create a Trunc or BitCast cast constant expression
551 static Constant *getTruncOrBitCast(
552 Constant *C, ///< The constant to trunc or bitcast
553 const Type *Ty ///< The type to trunc or bitcast C to
556 /// @brief Create a BitCast or a PtrToInt cast constant expression
557 static Constant *getPointerCast(
558 Constant *C, ///< The pointer value to be casted (operand 0)
559 const Type *Ty ///< The type to which cast should be made
562 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
563 static Constant *getIntegerCast(
564 Constant *C, ///< The integer constant to be casted
565 const Type *Ty, ///< The integer type to cast to
566 bool isSigned ///< Whether C should be treated as signed or not
569 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
570 static Constant *getFPCast(
571 Constant *C, ///< The integer constant to be casted
572 const Type *Ty ///< The integer type to cast to
575 /// @brief Return true if this is a convert constant expression
578 /// @brief Return true if this is a compare constant expression
579 bool isCompare() const;
581 /// Select constant expr
583 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
584 return getSelectTy(V1->getType(), C, V1, V2);
587 /// getSizeOf constant expr - computes the size of a type in a target
588 /// independent way (Note: the return type is a ULong).
590 static Constant *getSizeOf(const Type *Ty);
592 /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
593 /// return a pointer to a pointer of the array element type.
594 static Constant *getPtrPtrFromArrayPtr(Constant *C);
596 /// ConstantExpr::get - Return a binary or shift operator constant expression,
597 /// folding if possible.
599 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
601 /// @brief Return an ICmp or FCmp comparison operator constant expression.
602 static Constant *getCompare(unsigned Opcode, unsigned short pred,
603 Constant *C1, Constant *C2);
605 /// ConstantExpr::get* - Return some common constants without having to
606 /// specify the full Instruction::OPCODE identifier.
608 static Constant *getNeg(Constant *C);
609 static Constant *getNot(Constant *C);
610 static Constant *getAdd(Constant *C1, Constant *C2);
611 static Constant *getSub(Constant *C1, Constant *C2);
612 static Constant *getMul(Constant *C1, Constant *C2);
613 static Constant *getUDiv(Constant *C1, Constant *C2);
614 static Constant *getSDiv(Constant *C1, Constant *C2);
615 static Constant *getFDiv(Constant *C1, Constant *C2);
616 static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
617 static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
618 static Constant *getFRem(Constant *C1, Constant *C2);
619 static Constant *getAnd(Constant *C1, Constant *C2);
620 static Constant *getOr(Constant *C1, Constant *C2);
621 static Constant *getXor(Constant *C1, Constant *C2);
622 static Constant *getSetEQ(Constant *C1, Constant *C2);
623 static Constant *getSetNE(Constant *C1, Constant *C2);
624 static Constant *getSetLT(Constant *C1, Constant *C2);
625 static Constant *getSetGT(Constant *C1, Constant *C2);
626 static Constant *getSetLE(Constant *C1, Constant *C2);
627 static Constant *getSetGE(Constant *C1, Constant *C2);
628 static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS);
629 static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS);
630 static Constant *getShl(Constant *C1, Constant *C2);
631 static Constant *getLShr(Constant *C1, Constant *C2);
632 static Constant *getAShr(Constant *C1, Constant *C2);
634 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
635 /// all elements must be Constant's.
637 static Constant *getGetElementPtr(Constant *C,
638 const std::vector<Constant*> &IdxList);
639 static Constant *getGetElementPtr(Constant *C,
640 const std::vector<Value*> &IdxList);
642 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
643 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
644 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
646 /// isNullValue - Return true if this is the value that would be returned by
648 virtual bool isNullValue() const { return false; }
650 /// getOpcode - Return the opcode at the root of this constant expression
651 unsigned getOpcode() const { return SubclassData; }
653 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
654 /// not an ICMP or FCMP constant expression.
655 unsigned getPredicate() const;
657 /// getOpcodeName - Return a string representation for an opcode.
658 const char *getOpcodeName() const;
660 /// getWithOperandReplaced - Return a constant expression identical to this
661 /// one, but with the specified operand set to the specified value.
662 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
664 /// getWithOperands - This returns the current constant expression with the
665 /// operands replaced with the specified values. The specified operands must
666 /// match count and type with the existing ones.
667 Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
669 virtual void destroyConstant();
670 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
672 /// Override methods to provide more type information...
673 inline Constant *getOperand(unsigned i) {
674 return cast<Constant>(User::getOperand(i));
676 inline Constant *getOperand(unsigned i) const {
677 return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
681 /// Methods for support type inquiry through isa, cast, and dyn_cast:
682 static inline bool classof(const ConstantExpr *) { return true; }
683 static inline bool classof(const Value *V) {
684 return V->getValueType() == ConstantExprVal;
689 //===----------------------------------------------------------------------===//
690 /// UndefValue - 'undef' values are things that do not have specified contents.
691 /// These are used for a variety of purposes, including global variable
692 /// initializers and operands to instructions. 'undef' values can occur with
695 class UndefValue : public Constant {
696 friend struct ConstantCreator<UndefValue, Type, char>;
697 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
699 UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
701 /// get() - Static factory methods - Return an 'undef' object of the specified
704 static UndefValue *get(const Type *T);
706 /// isNullValue - Return true if this is the value that would be returned by
708 virtual bool isNullValue() const { return false; }
710 virtual void destroyConstant();
712 /// Methods for support type inquiry through isa, cast, and dyn_cast:
713 static inline bool classof(const UndefValue *) { return true; }
714 static bool classof(const Value *V) {
715 return V->getValueType() == UndefValueVal;
719 } // End llvm namespace