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() 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() 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 largest value for an integer constant of the given type
94 /// @brief Get the maximal value
95 static ConstantIntegral *getMaxValue(const Type *Ty);
97 /// @returns the smallest value for an integer constant of the given type
98 /// @brief Get the minimal value
99 static ConstantIntegral *getMinValue(const Type *Ty);
101 /// @returns the value for an integer constant of the given type that has all
102 /// its bits set to true.
103 /// @brief Get the all ones value
104 static ConstantIntegral *getAllOnesValue(const Type *Ty);
106 /// Methods to support type inquiry through isa, cast, and dyn_cast:
107 static inline bool classof(const ConstantIntegral *) { return true; }
108 static bool classof(const Value *V) {
109 return V->getValueType() == ConstantBoolVal ||
110 V->getValueType() == ConstantIntVal;
115 //===----------------------------------------------------------------------===//
116 /// This concrete class represents constant values of type BoolTy. There are
117 /// only two instances of this class constructed: the True and False static
118 /// members. The constructor is hidden to ensure this invariant.
119 /// @brief Constant Boolean class
120 class ConstantBool : public ConstantIntegral {
121 ConstantBool(bool V);
123 /// getTrue/getFalse - Return the singleton true/false values.
124 static ConstantBool *getTrue();
125 static ConstantBool *getFalse();
127 /// This method is provided mostly for compatibility with the other
128 /// ConstantIntegral subclasses.
129 /// @brief Static factory method for getting a ConstantBool instance.
130 static ConstantBool *get(bool Value) { return Value ? getTrue() : getFalse();}
132 /// This method is provided mostly for compatibility with the other
133 /// ConstantIntegral subclasses.
134 /// @brief Static factory method for getting a ConstantBool instance.
135 static ConstantBool *get(const Type *Ty, bool Value) { return get(Value); }
137 /// Returns the opposite value of this ConstantBool value.
138 /// @brief Get inverse value.
139 inline ConstantBool *inverted() const {
140 return getValue() ? getFalse() : getTrue();
143 /// @returns the value of this ConstantBool
144 /// @brief return the boolean value of this constant.
145 inline bool getValue() const { return static_cast<bool>(getZExtValue()); }
147 /// @see ConstantIntegral for details
148 /// @brief Implement overrides
149 virtual bool isNullValue() const { return getValue() == false; }
150 virtual bool isMaxValue() const { return getValue() == true; }
151 virtual bool isMinValue() const { return getValue() == false; }
152 virtual bool isAllOnesValue() const { return getValue() == true; }
154 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
155 static inline bool classof(const ConstantBool *) { return true; }
156 static bool classof(const Value *V) {
157 return V->getValueType() == ConstantBoolVal;
162 //===----------------------------------------------------------------------===//
163 /// This is concrete integer subclass of ConstantIntegral that represents
164 /// both signed and unsigned integral constants, other than boolean.
165 /// @brief Class for constant integers.
166 class ConstantInt : public ConstantIntegral {
168 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
169 ConstantInt(const Type *Ty, uint64_t V);
170 ConstantInt(const Type *Ty, int64_t V);
171 friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
173 /// A helper method that can be used to determine if the constant contained
174 /// within is equal to a constant. This only works for very small values,
175 /// because this is all that can be represented with all types.
176 /// @brief Determine if this constant's value is same as an unsigned char.
177 bool equalsInt(unsigned char V) const {
179 "equalsInt: Can only be used with very small positive constants!");
183 /// Return a ConstantInt with the specified value for the specified type. The
184 /// value V will be canonicalized to a uint64_t but accessing it with either
185 /// getSExtValue() or getZExtValue() (ConstantIntegral) will yield the correct
186 /// sized/signed value for the type Ty.
187 /// @brief Get a ConstantInt for a specific value.
188 static ConstantInt *get(const Type *Ty, int64_t V);
190 /// This static method returns true if the type Ty is big enough to
191 /// represent the value V. This can be used to avoid having the get method
192 /// assert when V is larger than Ty can represent.
193 /// @returns true if V is a valid value for type Ty
194 /// @brief Determine if the value is in range for the given type.
195 static bool isValueValidForType(const Type *Ty, int64_t V);
197 /// @returns true if this is the null integer value.
198 /// @see ConstantIntegral for details
199 /// @brief Implement override.
200 virtual bool isNullValue() const { return Val == 0; }
202 /// @returns true iff this constant's bits are all set to true.
203 /// @see ConstantIntegral
204 /// @brief Override implementation
205 virtual bool isAllOnesValue() const { return getSExtValue() == -1; }
207 /// @returns true iff this is the largest value that may be represented
209 /// @see ConstantIntegeral
210 /// @brief Override implementation
211 virtual bool isMaxValue() const {
212 if (getType()->isSigned()) {
213 int64_t V = getSExtValue();
214 if (V < 0) return false; // Be careful about wrap-around on 'long's
216 return !isValueValidForType(getType(), V) || V < 0;
218 return isAllOnesValue();
221 /// @returns true if this is the smallest value that may be represented by
223 /// @see ConstantIntegral
224 /// @brief Override implementation
225 virtual bool isMinValue() const {
226 if (getType()->isSigned()) {
227 int64_t V = getSExtValue();
228 if (V > 0) return false; // Be careful about wrap-around on 'long's
230 return !isValueValidForType(getType(), V) || V > 0;
232 return getZExtValue() == 0;
235 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
236 static inline bool classof(const ConstantInt *) { return true; }
237 static bool classof(const Value *V) {
238 return V->getValueType() == ConstantIntVal;
243 //===----------------------------------------------------------------------===//
244 /// ConstantFP - Floating Point Values [float, double]
246 class ConstantFP : public Constant {
248 friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
249 friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
250 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
252 ConstantFP(const Type *Ty, double V);
254 /// get() - Static factory methods - Return objects of the specified value
255 static ConstantFP *get(const Type *Ty, double V);
257 /// isValueValidForType - return true if Ty is big enough to represent V.
258 static bool isValueValidForType(const Type *Ty, double V);
259 inline double getValue() const { return Val; }
261 /// isNullValue - Return true if this is the value that would be returned by
262 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
263 /// considers -0.0 to be null as well as 0.0. :(
264 virtual bool isNullValue() const;
266 /// isExactlyValue - We don't rely on operator== working on double values, as
267 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
268 /// As such, this method can be used to do an exact bit-for-bit comparison of
269 /// two floating point values.
270 bool isExactlyValue(double V) const;
272 /// Methods for support type inquiry through isa, cast, and dyn_cast:
273 static inline bool classof(const ConstantFP *) { return true; }
274 static bool classof(const Value *V) {
275 return V->getValueType() == ConstantFPVal;
279 //===----------------------------------------------------------------------===//
280 /// ConstantAggregateZero - All zero aggregate value
282 class ConstantAggregateZero : public Constant {
283 friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
284 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
286 ConstantAggregateZero(const Type *Ty)
287 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
289 /// get() - static factory method for creating a null aggregate. It is
290 /// illegal to call this method with a non-aggregate type.
291 static Constant *get(const Type *Ty);
293 /// isNullValue - Return true if this is the value that would be returned by
295 virtual bool isNullValue() const { return true; }
297 virtual void destroyConstant();
299 /// Methods for support type inquiry through isa, cast, and dyn_cast:
301 static bool classof(const ConstantAggregateZero *) { return true; }
302 static bool classof(const Value *V) {
303 return V->getValueType() == ConstantAggregateZeroVal;
308 //===----------------------------------------------------------------------===//
309 /// ConstantArray - Constant Array Declarations
311 class ConstantArray : public Constant {
312 friend struct ConstantCreator<ConstantArray, ArrayType,
313 std::vector<Constant*> >;
314 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
316 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
319 /// get() - Static factory methods - Return objects of the specified value
320 static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
322 /// This method constructs a ConstantArray and initializes it with a text
323 /// string. The default behavior (AddNull==true) causes a null terminator to
324 /// be placed at the end of the array. This effectively increases the length
325 /// of the array by one (you've been warned). However, in some situations
326 /// this is not desired so if AddNull==false then the string is copied without
327 /// null termination.
328 static Constant *get(const std::string &Initializer, bool AddNull = true);
330 /// getType - Specialize the getType() method to always return an ArrayType,
331 /// which reduces the amount of casting needed in parts of the compiler.
333 inline const ArrayType *getType() const {
334 return reinterpret_cast<const ArrayType*>(Value::getType());
337 /// isString - This method returns true if the array is an array of sbyte or
338 /// ubyte, and if the elements of the array are all ConstantInt's.
339 bool isString() const;
341 /// isCString - This method returns true if the array is a string (see
342 /// isString) and it ends in a null byte \0 and does not contains any other
343 /// null bytes except its terminator.
344 bool isCString() const;
346 /// getAsString - If this array is isString(), then this method converts the
347 /// array to an std::string and returns it. Otherwise, it asserts out.
349 std::string getAsString() const;
351 /// isNullValue - Return true if this is the value that would be returned by
352 /// getNullValue. This always returns false because zero arrays are always
353 /// created as ConstantAggregateZero objects.
354 virtual bool isNullValue() const { return false; }
356 virtual void destroyConstant();
357 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
359 /// Methods for support type inquiry through isa, cast, and dyn_cast:
360 static inline bool classof(const ConstantArray *) { return true; }
361 static bool classof(const Value *V) {
362 return V->getValueType() == ConstantArrayVal;
367 //===----------------------------------------------------------------------===//
368 // ConstantStruct - Constant Struct Declarations
370 class ConstantStruct : public Constant {
371 friend struct ConstantCreator<ConstantStruct, StructType,
372 std::vector<Constant*> >;
373 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
375 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
378 /// get() - Static factory methods - Return objects of the specified value
380 static Constant *get(const StructType *T, const std::vector<Constant*> &V);
381 static Constant *get(const std::vector<Constant*> &V);
383 /// getType() specialization - Reduce amount of casting...
385 inline const StructType *getType() const {
386 return reinterpret_cast<const StructType*>(Value::getType());
389 /// isNullValue - Return true if this is the value that would be returned by
390 /// getNullValue. This always returns false because zero structs are always
391 /// created as ConstantAggregateZero objects.
392 virtual bool isNullValue() const {
396 virtual void destroyConstant();
397 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
399 /// Methods for support type inquiry through isa, cast, and dyn_cast:
400 static inline bool classof(const ConstantStruct *) { return true; }
401 static bool classof(const Value *V) {
402 return V->getValueType() == ConstantStructVal;
406 //===----------------------------------------------------------------------===//
407 /// ConstantPacked - Constant Packed Declarations
409 class ConstantPacked : public Constant {
410 friend struct ConstantCreator<ConstantPacked, PackedType,
411 std::vector<Constant*> >;
412 ConstantPacked(const ConstantPacked &); // DO NOT IMPLEMENT
414 ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val);
417 /// get() - Static factory methods - Return objects of the specified value
418 static Constant *get(const PackedType *T, const std::vector<Constant*> &);
419 static Constant *get(const std::vector<Constant*> &V);
421 /// getType - Specialize the getType() method to always return an PackedType,
422 /// which reduces the amount of casting needed in parts of the compiler.
424 inline const PackedType *getType() const {
425 return reinterpret_cast<const PackedType*>(Value::getType());
428 /// isNullValue - Return true if this is the value that would be returned by
429 /// getNullValue. This always returns false because zero arrays are always
430 /// created as ConstantAggregateZero objects.
431 virtual bool isNullValue() const { return false; }
433 virtual void destroyConstant();
434 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
436 /// Methods for support type inquiry through isa, cast, and dyn_cast:
437 static inline bool classof(const ConstantPacked *) { return true; }
438 static bool classof(const Value *V) {
439 return V->getValueType() == ConstantPackedVal;
443 //===----------------------------------------------------------------------===//
444 /// ConstantPointerNull - a constant pointer value that points to null
446 class ConstantPointerNull : public Constant {
447 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
448 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
450 ConstantPointerNull(const PointerType *T)
451 : Constant(reinterpret_cast<const Type*>(T),
452 Value::ConstantPointerNullVal, 0, 0) {}
456 /// get() - Static factory methods - Return objects of the specified value
457 static ConstantPointerNull *get(const PointerType *T);
459 /// isNullValue - Return true if this is the value that would be returned by
461 virtual bool isNullValue() const { return true; }
463 virtual void destroyConstant();
465 /// getType - Specialize the getType() method to always return an PointerType,
466 /// which reduces the amount of casting needed in parts of the compiler.
468 inline const PointerType *getType() const {
469 return reinterpret_cast<const PointerType*>(Value::getType());
472 /// Methods for support type inquiry through isa, cast, and dyn_cast:
473 static inline bool classof(const ConstantPointerNull *) { return true; }
474 static bool classof(const Value *V) {
475 return V->getValueType() == ConstantPointerNullVal;
480 /// ConstantExpr - a constant value that is initialized with an expression using
481 /// other constant values.
483 /// This class uses the standard Instruction opcodes to define the various
484 /// constant expressions. The Opcode field for the ConstantExpr class is
485 /// maintained in the Value::SubclassData field.
486 class ConstantExpr : public Constant {
487 friend struct ConstantCreator<ConstantExpr,Type,
488 std::pair<unsigned, std::vector<Constant*> > >;
489 friend struct ConvertConstantType<ConstantExpr, Type>;
492 ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
493 : Constant(Ty, ConstantExprVal, Ops, NumOps) {
494 // Operation type (an Instruction opcode) is stored as the SubclassData.
495 SubclassData = Opcode;
498 // These private methods are used by the type resolution code to create
499 // ConstantExprs in intermediate forms.
500 static Constant *getTy(const Type *Ty, unsigned Opcode,
501 Constant *C1, Constant *C2);
502 static Constant *getCompareTy(unsigned Opcode, unsigned short pred,
503 Constant *C1, Constant *C2);
504 static Constant *getShiftTy(const Type *Ty,
505 unsigned Opcode, Constant *C1, Constant *C2);
506 static Constant *getSelectTy(const Type *Ty,
507 Constant *C1, Constant *C2, Constant *C3);
508 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
509 const std::vector<Value*> &IdxList);
510 static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
512 static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
513 Constant *Elt, Constant *Idx);
514 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
515 Constant *V2, Constant *Mask);
518 // Static methods to construct a ConstantExpr of different kinds. Note that
519 // these methods may return a object that is not an instance of the
520 // ConstantExpr class, because they will attempt to fold the constant
521 // expression into something simpler if possible.
523 /// Cast constant expr
525 static Constant *getTrunc (Constant *C, const Type *Ty);
526 static Constant *getSignExtend (Constant *C, const Type *Ty);
527 static Constant *getZeroExtend (Constant *C, const Type *Ty);
528 static Constant *getFPTrunc (Constant *C, const Type *Ty);
529 static Constant *getFPExtend (Constant *C, const Type *Ty);
530 static Constant *getUIToFP (Constant *C, const Type *Ty);
531 static Constant *getSIToFP (Constant *C, const Type *Ty);
532 static Constant *getFPToUI (Constant *C, const Type *Ty);
533 static Constant *getFPToSI (Constant *C, const Type *Ty);
534 static Constant *getPtrToInt (Constant *C, const Type *Ty);
535 static Constant *getIntToPtr (Constant *C, const Type *Ty);
536 static Constant *getBitCast (Constant *C, const Type *Ty);
538 // @brief Convenience function for getting one of the casting operations
539 // using a CastOps opcode.
540 static Constant *getCast(
541 unsigned ops, ///< The opcode for the conversion
542 Constant *C, ///< The constant to be converted
543 const Type *Ty ///< The type to which the constant is converted
546 // @brief Create a ZExt or BitCast cast constant expression
547 static Constant *getZExtOrBitCast(
548 Constant *C, ///< The constant to zext or bitcast
549 const Type *Ty ///< The type to zext or bitcast C to
552 // @brief Create a SExt or BitCast cast constant expression
553 static Constant *getSExtOrBitCast(
554 Constant *C, ///< The constant to sext or bitcast
555 const Type *Ty ///< The type to sext or bitcast C to
558 // @brief Create a Trunc or BitCast cast constant expression
559 static Constant *getTruncOrBitCast(
560 Constant *C, ///< The constant to trunc or bitcast
561 const Type *Ty ///< The type to trunc or bitcast C to
564 /// @brief Create a BitCast or a PtrToInt cast constant expression
565 static Constant *getPointerCast(
566 Constant *C, ///< The pointer value to be casted (operand 0)
567 const Type *Ty ///< The type to which cast should be made
570 static Constant *getCast(Constant *C, const Type *Ty);
572 /// @brief Return true if this is a convert constant expression
575 /// @brief Return true if this is a compare constant expression
576 bool isCompare() const;
578 /// Select constant expr
580 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
581 return getSelectTy(V1->getType(), C, V1, V2);
584 /// getSizeOf constant expr - computes the size of a type in a target
585 /// independent way (Note: the return type is a ULong).
587 static Constant *getSizeOf(const Type *Ty);
589 /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
590 /// return a pointer to a pointer of the array element type.
591 static Constant *getPtrPtrFromArrayPtr(Constant *C);
593 /// ConstantExpr::get - Return a binary or shift operator constant expression,
594 /// folding if possible.
596 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
598 /// @brief Return an ICmp or FCmp comparison operator constant expression.
599 static Constant *getCompare(unsigned Opcode, unsigned short pred,
600 Constant *C1, Constant *C2);
602 /// ConstantExpr::get* - Return some common constants without having to
603 /// specify the full Instruction::OPCODE identifier.
605 static Constant *getNeg(Constant *C);
606 static Constant *getNot(Constant *C);
607 static Constant *getAdd(Constant *C1, Constant *C2);
608 static Constant *getSub(Constant *C1, Constant *C2);
609 static Constant *getMul(Constant *C1, Constant *C2);
610 static Constant *getUDiv(Constant *C1, Constant *C2);
611 static Constant *getSDiv(Constant *C1, Constant *C2);
612 static Constant *getFDiv(Constant *C1, Constant *C2);
613 static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
614 static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
615 static Constant *getFRem(Constant *C1, Constant *C2);
616 static Constant *getAnd(Constant *C1, Constant *C2);
617 static Constant *getOr(Constant *C1, Constant *C2);
618 static Constant *getXor(Constant *C1, Constant *C2);
619 static Constant *getSetEQ(Constant *C1, Constant *C2);
620 static Constant *getSetNE(Constant *C1, Constant *C2);
621 static Constant *getSetLT(Constant *C1, Constant *C2);
622 static Constant *getSetGT(Constant *C1, Constant *C2);
623 static Constant *getSetLE(Constant *C1, Constant *C2);
624 static Constant *getSetGE(Constant *C1, Constant *C2);
625 static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS);
626 static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS);
627 static Constant *getShl(Constant *C1, Constant *C2);
628 static Constant *getLShr(Constant *C1, Constant *C2);
629 static Constant *getAShr(Constant *C1, Constant *C2);
631 /// Getelementptr form. std::vector<Value*> is only accepted for convenience:
632 /// all elements must be Constant's.
634 static Constant *getGetElementPtr(Constant *C,
635 const std::vector<Constant*> &IdxList);
636 static Constant *getGetElementPtr(Constant *C,
637 const std::vector<Value*> &IdxList);
639 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
640 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
641 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
643 /// isNullValue - Return true if this is the value that would be returned by
645 virtual bool isNullValue() const { return false; }
647 /// getOpcode - Return the opcode at the root of this constant expression
648 unsigned getOpcode() const { return SubclassData; }
650 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
651 /// not an ICMP or FCMP constant expression.
652 unsigned getPredicate() const;
654 /// getOpcodeName - Return a string representation for an opcode.
655 const char *getOpcodeName() const;
657 /// getWithOperandReplaced - Return a constant expression identical to this
658 /// one, but with the specified operand set to the specified value.
659 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
661 /// getWithOperands - This returns the current constant expression with the
662 /// operands replaced with the specified values. The specified operands must
663 /// match count and type with the existing ones.
664 Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
666 virtual void destroyConstant();
667 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
669 /// Override methods to provide more type information...
670 inline Constant *getOperand(unsigned i) {
671 return cast<Constant>(User::getOperand(i));
673 inline Constant *getOperand(unsigned i) const {
674 return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
678 /// Methods for support type inquiry through isa, cast, and dyn_cast:
679 static inline bool classof(const ConstantExpr *) { return true; }
680 static inline bool classof(const Value *V) {
681 return V->getValueType() == ConstantExprVal;
686 //===----------------------------------------------------------------------===//
687 /// UndefValue - 'undef' values are things that do not have specified contents.
688 /// These are used for a variety of purposes, including global variable
689 /// initializers and operands to instructions. 'undef' values can occur with
692 class UndefValue : public Constant {
693 friend struct ConstantCreator<UndefValue, Type, char>;
694 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
696 UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
698 /// get() - Static factory methods - Return an 'undef' object of the specified
701 static UndefValue *get(const Type *T);
703 /// isNullValue - Return true if this is the value that would be returned by
705 virtual bool isNullValue() const { return false; }
707 virtual void destroyConstant();
709 /// Methods for support type inquiry through isa, cast, and dyn_cast:
710 static inline bool classof(const UndefValue *) { return true; }
711 static bool classof(const Value *V) {
712 return V->getValueType() == UndefValueVal;
716 } // End llvm namespace