LLVM API Documentation
00001 //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the declarations for the subclasses of Constant, which 00011 // represent the different flavors of constant values that live in LLVM. Note 00012 // that Constants are immutable (once created they never change) and are fully 00013 // shared by structural equivalence. This means that two structurally 00014 // equivalent constants will always have the same address. Constant's are 00015 // created on demand as needed and never deleted: thus clients don't have to 00016 // worry about the lifetime of the objects. 00017 // 00018 //===----------------------------------------------------------------------===// 00019 00020 #ifndef LLVM_CONSTANTS_H 00021 #define LLVM_CONSTANTS_H 00022 00023 #include "llvm/Constant.h" 00024 #include "llvm/Type.h" 00025 00026 namespace llvm { 00027 00028 class ArrayType; 00029 class StructType; 00030 class PointerType; 00031 class PackedType; 00032 00033 template<class ConstantClass, class TypeClass, class ValType> 00034 struct ConstantCreator; 00035 template<class ConstantClass, class TypeClass> 00036 struct ConvertConstantType; 00037 00038 //===----------------------------------------------------------------------===// 00039 /// ConstantIntegral - Shared superclass of boolean and integer constants. 00040 /// 00041 /// This class just defines some common interfaces to be implemented. 00042 /// 00043 class ConstantIntegral : public Constant { 00044 protected: 00045 union { 00046 int64_t Signed; 00047 uint64_t Unsigned; 00048 } Val; 00049 ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V); 00050 public: 00051 00052 /// getRawValue - return the underlying value of this constant as a 64-bit 00053 /// unsigned integer value. 00054 /// 00055 inline uint64_t getRawValue() const { return Val.Unsigned; } 00056 00057 /// getZExtValue - Return the constant zero extended as appropriate for this 00058 /// type. 00059 inline uint64_t getZExtValue() const { 00060 unsigned Size = getType()->getPrimitiveSizeInBits(); 00061 return Val.Unsigned & (~0ULL >> (64-Size)); 00062 } 00063 00064 /// getSExtValue - Return the constant sign extended as appropriate for this 00065 /// type. 00066 inline int64_t getSExtValue() const { 00067 unsigned Size = getType()->getPrimitiveSizeInBits(); 00068 return (Val.Signed << (64-Size)) >> (64-Size); 00069 } 00070 00071 /// isNullValue - Return true if this is the value that would be returned by 00072 /// getNullValue. 00073 /// 00074 virtual bool isNullValue() const = 0; 00075 00076 /// isMaxValue - Return true if this is the largest value that may be 00077 /// represented by this type. 00078 /// 00079 virtual bool isMaxValue() const = 0; 00080 00081 /// isMinValue - Return true if this is the smallest value that may be 00082 /// represented by this type. 00083 /// 00084 virtual bool isMinValue() const = 0; 00085 00086 /// isAllOnesValue - Return true if every bit in this constant is set to true. 00087 /// 00088 virtual bool isAllOnesValue() const = 0; 00089 00090 /// Static constructor to get the maximum/minimum/allones constant of 00091 /// specified (integral) type... 00092 /// 00093 static ConstantIntegral *getMaxValue(const Type *Ty); 00094 static ConstantIntegral *getMinValue(const Type *Ty); 00095 static ConstantIntegral *getAllOnesValue(const Type *Ty); 00096 00097 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00098 static inline bool classof(const ConstantIntegral *) { return true; } 00099 static bool classof(const Value *V) { 00100 return V->getValueType() == ConstantBoolVal || 00101 V->getValueType() == ConstantSIntVal || 00102 V->getValueType() == ConstantUIntVal; 00103 } 00104 }; 00105 00106 00107 //===----------------------------------------------------------------------===// 00108 /// ConstantBool - Boolean Values 00109 /// 00110 class ConstantBool : public ConstantIntegral { 00111 ConstantBool(bool V); 00112 public: 00113 static ConstantBool *True, *False; // The True & False values 00114 00115 /// get() - Static factory methods - Return objects of the specified value 00116 static ConstantBool *get(bool Value) { return Value ? True : False; } 00117 static ConstantBool *get(const Type *Ty, bool Value) { return get(Value); } 00118 00119 /// inverted - Return the opposite value of the current value. 00120 inline ConstantBool *inverted() const { return (this==True) ? False : True; } 00121 00122 /// getValue - return the boolean value of this constant. 00123 /// 00124 inline bool getValue() const { return static_cast<bool>(getRawValue()); } 00125 00126 /// isNullValue - Return true if this is the value that would be returned by 00127 /// getNullValue. 00128 /// 00129 virtual bool isNullValue() const { return this == False; } 00130 virtual bool isMaxValue() const { return this == True; } 00131 virtual bool isMinValue() const { return this == False; } 00132 virtual bool isAllOnesValue() const { return this == True; } 00133 00134 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00135 static inline bool classof(const ConstantBool *) { return true; } 00136 static bool classof(const Value *V) { 00137 return V->getValueType() == ConstantBoolVal; 00138 } 00139 }; 00140 00141 00142 //===----------------------------------------------------------------------===// 00143 /// ConstantInt - Superclass of ConstantSInt & ConstantUInt, to make dealing 00144 /// with integral constants easier. 00145 /// 00146 class ConstantInt : public ConstantIntegral { 00147 protected: 00148 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT 00149 ConstantInt(const Type *Ty, ValueTy VT, uint64_t V); 00150 public: 00151 /// equalsInt - Provide a helper method that can be used to determine if the 00152 /// constant contained within is equal to a constant. This only works for 00153 /// very small values, because this is all that can be represented with all 00154 /// types. 00155 /// 00156 bool equalsInt(unsigned char V) const { 00157 assert(V <= 127 && 00158 "equalsInt: Can only be used with very small positive constants!"); 00159 return Val.Unsigned == V; 00160 } 00161 00162 /// ConstantInt::get static method: return a ConstantInt with the specified 00163 /// value. as above, we work only with very small values here. 00164 /// 00165 static ConstantInt *get(const Type *Ty, unsigned char V); 00166 00167 /// isNullValue - Return true if this is the value that would be returned by 00168 /// getNullValue. 00169 virtual bool isNullValue() const { return Val.Unsigned == 0; } 00170 virtual bool isMaxValue() const = 0; 00171 virtual bool isMinValue() const = 0; 00172 00173 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00174 static inline bool classof(const ConstantInt *) { return true; } 00175 static bool classof(const Value *V) { 00176 return V->getValueType() == ConstantSIntVal || 00177 V->getValueType() == ConstantUIntVal; 00178 } 00179 }; 00180 00181 00182 //===----------------------------------------------------------------------===// 00183 /// ConstantSInt - Signed Integer Values [sbyte, short, int, long] 00184 /// 00185 class ConstantSInt : public ConstantInt { 00186 ConstantSInt(const ConstantSInt &); // DO NOT IMPLEMENT 00187 friend struct ConstantCreator<ConstantSInt, Type, int64_t>; 00188 00189 protected: 00190 ConstantSInt(const Type *Ty, int64_t V); 00191 public: 00192 /// get() - Static factory methods - Return objects of the specified value 00193 /// 00194 static ConstantSInt *get(const Type *Ty, int64_t V); 00195 00196 /// isValueValidForType - return true if Ty is big enough to represent V. 00197 /// 00198 static bool isValueValidForType(const Type *Ty, int64_t V); 00199 00200 /// getValue - return the underlying value of this constant. 00201 /// 00202 inline int64_t getValue() const { return Val.Signed; } 00203 00204 virtual bool isAllOnesValue() const { return getValue() == -1; } 00205 00206 /// isMaxValue - Return true if this is the largest value that may be 00207 /// represented by this type. 00208 /// 00209 virtual bool isMaxValue() const { 00210 int64_t V = getValue(); 00211 if (V < 0) return false; // Be careful about wrap-around on 'long's 00212 ++V; 00213 return !isValueValidForType(getType(), V) || V < 0; 00214 } 00215 00216 /// isMinValue - Return true if this is the smallest value that may be 00217 /// represented by this type. 00218 /// 00219 virtual bool isMinValue() const { 00220 int64_t V = getValue(); 00221 if (V > 0) return false; // Be careful about wrap-around on 'long's 00222 --V; 00223 return !isValueValidForType(getType(), V) || V > 0; 00224 } 00225 00226 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00227 /// 00228 static inline bool classof(const ConstantSInt *) { return true; } 00229 static bool classof(const Value *V) { 00230 return V->getValueType() == ConstantSIntVal; 00231 } 00232 }; 00233 00234 //===----------------------------------------------------------------------===// 00235 /// ConstantUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong] 00236 /// 00237 class ConstantUInt : public ConstantInt { 00238 ConstantUInt(const ConstantUInt &); // DO NOT IMPLEMENT 00239 friend struct ConstantCreator<ConstantUInt, Type, uint64_t>; 00240 protected: 00241 ConstantUInt(const Type *Ty, uint64_t V); 00242 public: 00243 /// get() - Static factory methods - Return objects of the specified value 00244 /// 00245 static ConstantUInt *get(const Type *Ty, uint64_t V); 00246 00247 /// isValueValidForType - return true if Ty is big enough to represent V. 00248 /// 00249 static bool isValueValidForType(const Type *Ty, uint64_t V); 00250 00251 /// getValue - return the underlying value of this constant. 00252 /// 00253 inline uint64_t getValue() const { return Val.Unsigned; } 00254 00255 /// isMaxValue - Return true if this is the largest value that may be 00256 /// represented by this type. 00257 /// 00258 virtual bool isAllOnesValue() const; 00259 virtual bool isMaxValue() const { return isAllOnesValue(); } 00260 virtual bool isMinValue() const { return getValue() == 0; } 00261 00262 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00263 static inline bool classof(const ConstantUInt *) { return true; } 00264 static bool classof(const Value *V) { 00265 return V->getValueType() == ConstantUIntVal; 00266 } 00267 }; 00268 00269 00270 //===----------------------------------------------------------------------===// 00271 /// ConstantFP - Floating Point Values [float, double] 00272 /// 00273 class ConstantFP : public Constant { 00274 double Val; 00275 friend struct ConstantCreator<ConstantFP, Type, uint64_t>; 00276 friend struct ConstantCreator<ConstantFP, Type, uint32_t>; 00277 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT 00278 protected: 00279 ConstantFP(const Type *Ty, double V); 00280 public: 00281 /// get() - Static factory methods - Return objects of the specified value 00282 static ConstantFP *get(const Type *Ty, double V); 00283 00284 /// isValueValidForType - return true if Ty is big enough to represent V. 00285 static bool isValueValidForType(const Type *Ty, double V); 00286 inline double getValue() const { return Val; } 00287 00288 /// isNullValue - Return true if this is the value that would be returned by 00289 /// getNullValue. Don't depend on == for doubles to tell us it's zero, it 00290 /// considers -0.0 to be null as well as 0.0. :( 00291 virtual bool isNullValue() const; 00292 00293 /// isExactlyValue - We don't rely on operator== working on double values, as 00294 /// it returns true for things that are clearly not equal, like -0.0 and 0.0. 00295 /// As such, this method can be used to do an exact bit-for-bit comparison of 00296 /// two floating point values. 00297 bool isExactlyValue(double V) const; 00298 00299 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00300 static inline bool classof(const ConstantFP *) { return true; } 00301 static bool classof(const Value *V) { 00302 return V->getValueType() == ConstantFPVal; 00303 } 00304 }; 00305 00306 //===----------------------------------------------------------------------===// 00307 /// ConstantAggregateZero - All zero aggregate value 00308 /// 00309 class ConstantAggregateZero : public Constant { 00310 friend struct ConstantCreator<ConstantAggregateZero, Type, char>; 00311 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT 00312 protected: 00313 ConstantAggregateZero(const Type *Ty) 00314 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {} 00315 public: 00316 /// get() - static factory method for creating a null aggregate. It is 00317 /// illegal to call this method with a non-aggregate type. 00318 static Constant *get(const Type *Ty); 00319 00320 /// isNullValue - Return true if this is the value that would be returned by 00321 /// getNullValue. 00322 virtual bool isNullValue() const { return true; } 00323 00324 virtual void destroyConstant(); 00325 00326 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00327 /// 00328 static bool classof(const ConstantAggregateZero *) { return true; } 00329 static bool classof(const Value *V) { 00330 return V->getValueType() == ConstantAggregateZeroVal; 00331 } 00332 }; 00333 00334 00335 //===----------------------------------------------------------------------===// 00336 /// ConstantArray - Constant Array Declarations 00337 /// 00338 class ConstantArray : public Constant { 00339 friend struct ConstantCreator<ConstantArray, ArrayType, 00340 std::vector<Constant*> >; 00341 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT 00342 protected: 00343 ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val); 00344 ~ConstantArray(); 00345 public: 00346 /// get() - Static factory methods - Return objects of the specified value 00347 static Constant *get(const ArrayType *T, const std::vector<Constant*> &); 00348 static Constant *get(const std::string &Initializer); 00349 00350 /// getType - Specialize the getType() method to always return an ArrayType, 00351 /// which reduces the amount of casting needed in parts of the compiler. 00352 /// 00353 inline const ArrayType *getType() const { 00354 return reinterpret_cast<const ArrayType*>(Value::getType()); 00355 } 00356 00357 /// isString - This method returns true if the array is an array of sbyte or 00358 /// ubyte, and if the elements of the array are all ConstantInt's. 00359 bool isString() const; 00360 00361 /// getAsString - If this array is isString(), then this method converts the 00362 /// array to an std::string and returns it. Otherwise, it asserts out. 00363 /// 00364 std::string getAsString() const; 00365 00366 /// isNullValue - Return true if this is the value that would be returned by 00367 /// getNullValue. This always returns false because zero arrays are always 00368 /// created as ConstantAggregateZero objects. 00369 virtual bool isNullValue() const { return false; } 00370 00371 virtual void destroyConstant(); 00372 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 00373 00374 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00375 static inline bool classof(const ConstantArray *) { return true; } 00376 static bool classof(const Value *V) { 00377 return V->getValueType() == ConstantArrayVal; 00378 } 00379 }; 00380 00381 00382 //===----------------------------------------------------------------------===// 00383 // ConstantStruct - Constant Struct Declarations 00384 // 00385 class ConstantStruct : public Constant { 00386 friend struct ConstantCreator<ConstantStruct, StructType, 00387 std::vector<Constant*> >; 00388 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT 00389 protected: 00390 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val); 00391 ~ConstantStruct(); 00392 public: 00393 /// get() - Static factory methods - Return objects of the specified value 00394 /// 00395 static Constant *get(const StructType *T, const std::vector<Constant*> &V); 00396 static Constant *get(const std::vector<Constant*> &V); 00397 00398 /// getType() specialization - Reduce amount of casting... 00399 /// 00400 inline const StructType *getType() const { 00401 return reinterpret_cast<const StructType*>(Value::getType()); 00402 } 00403 00404 /// isNullValue - Return true if this is the value that would be returned by 00405 /// getNullValue. This always returns false because zero structs are always 00406 /// created as ConstantAggregateZero objects. 00407 virtual bool isNullValue() const { 00408 return false; 00409 } 00410 00411 virtual void destroyConstant(); 00412 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 00413 00414 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00415 static inline bool classof(const ConstantStruct *) { return true; } 00416 static bool classof(const Value *V) { 00417 return V->getValueType() == ConstantStructVal; 00418 } 00419 }; 00420 00421 //===----------------------------------------------------------------------===// 00422 /// ConstantPacked - Constant Packed Declarations 00423 /// 00424 class ConstantPacked : public Constant { 00425 friend struct ConstantCreator<ConstantPacked, PackedType, 00426 std::vector<Constant*> >; 00427 ConstantPacked(const ConstantPacked &); // DO NOT IMPLEMENT 00428 protected: 00429 ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val); 00430 ~ConstantPacked(); 00431 public: 00432 /// get() - Static factory methods - Return objects of the specified value 00433 static Constant *get(const PackedType *T, const std::vector<Constant*> &); 00434 static Constant *get(const std::vector<Constant*> &V); 00435 00436 /// getType - Specialize the getType() method to always return an PackedType, 00437 /// which reduces the amount of casting needed in parts of the compiler. 00438 /// 00439 inline const PackedType *getType() const { 00440 return reinterpret_cast<const PackedType*>(Value::getType()); 00441 } 00442 00443 /// isNullValue - Return true if this is the value that would be returned by 00444 /// getNullValue. This always returns false because zero arrays are always 00445 /// created as ConstantAggregateZero objects. 00446 virtual bool isNullValue() const { return false; } 00447 00448 virtual void destroyConstant(); 00449 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 00450 00451 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00452 static inline bool classof(const ConstantPacked *) { return true; } 00453 static bool classof(const Value *V) { 00454 return V->getValueType() == ConstantPackedVal; 00455 } 00456 }; 00457 00458 //===----------------------------------------------------------------------===// 00459 /// ConstantPointerNull - a constant pointer value that points to null 00460 /// 00461 class ConstantPointerNull : public Constant { 00462 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>; 00463 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT 00464 protected: 00465 ConstantPointerNull(const PointerType *T) 00466 : Constant(reinterpret_cast<const Type*>(T), 00467 Value::ConstantPointerNullVal, 0, 0) {} 00468 00469 public: 00470 00471 /// get() - Static factory methods - Return objects of the specified value 00472 static ConstantPointerNull *get(const PointerType *T); 00473 00474 /// isNullValue - Return true if this is the value that would be returned by 00475 /// getNullValue. 00476 virtual bool isNullValue() const { return true; } 00477 00478 virtual void destroyConstant(); 00479 00480 /// getType - Specialize the getType() method to always return an PointerType, 00481 /// which reduces the amount of casting needed in parts of the compiler. 00482 /// 00483 inline const PointerType *getType() const { 00484 return reinterpret_cast<const PointerType*>(Value::getType()); 00485 } 00486 00487 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00488 static inline bool classof(const ConstantPointerNull *) { return true; } 00489 static bool classof(const Value *V) { 00490 return V->getValueType() == ConstantPointerNullVal; 00491 } 00492 }; 00493 00494 00495 /// ConstantExpr - a constant value that is initialized with an expression using 00496 /// other constant values. 00497 /// 00498 /// This class uses the standard Instruction opcodes to define the various 00499 /// constant expressions. The Opcode field for the ConstantExpr class is 00500 /// maintained in the Value::SubclassData field. 00501 class ConstantExpr : public Constant { 00502 friend struct ConstantCreator<ConstantExpr,Type, 00503 std::pair<unsigned, std::vector<Constant*> > >; 00504 friend struct ConvertConstantType<ConstantExpr, Type>; 00505 00506 protected: 00507 ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps) 00508 : Constant(Ty, ConstantExprVal, Ops, NumOps) { 00509 // Operation type (an Instruction opcode) is stored as the SubclassData. 00510 SubclassData = Opcode; 00511 } 00512 00513 // These private methods are used by the type resolution code to create 00514 // ConstantExprs in intermediate forms. 00515 static Constant *getTy(const Type *Ty, unsigned Opcode, 00516 Constant *C1, Constant *C2); 00517 static Constant *getShiftTy(const Type *Ty, 00518 unsigned Opcode, Constant *C1, Constant *C2); 00519 static Constant *getSelectTy(const Type *Ty, 00520 Constant *C1, Constant *C2, Constant *C3); 00521 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C, 00522 const std::vector<Value*> &IdxList); 00523 static Constant *getExtractElementTy(const Type *Ty, Constant *Val, 00524 Constant *Idx); 00525 static Constant *getInsertElementTy(const Type *Ty, Constant *Val, 00526 Constant *Elt, Constant *Idx); 00527 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1, 00528 Constant *V2, Constant *Mask); 00529 00530 public: 00531 // Static methods to construct a ConstantExpr of different kinds. Note that 00532 // these methods may return a object that is not an instance of the 00533 // ConstantExpr class, because they will attempt to fold the constant 00534 // expression into something simpler if possible. 00535 00536 /// Cast constant expr 00537 /// 00538 static Constant *getCast(Constant *C, const Type *Ty); 00539 static Constant *getSignExtend(Constant *C, const Type *Ty); 00540 static Constant *getZeroExtend(Constant *C, const Type *Ty); 00541 00542 /// Select constant expr 00543 /// 00544 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) { 00545 return getSelectTy(V1->getType(), C, V1, V2); 00546 } 00547 00548 /// getSizeOf constant expr - computes the size of a type in a target 00549 /// independent way (Note: the return type is ULong but the object is not 00550 /// necessarily a ConstantUInt). 00551 /// 00552 static Constant *getSizeOf(const Type *Ty); 00553 00554 /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array, 00555 /// return a pointer to a pointer of the array element type. 00556 static Constant *getPtrPtrFromArrayPtr(Constant *C); 00557 00558 /// ConstantExpr::get - Return a binary or shift operator constant expression, 00559 /// folding if possible. 00560 /// 00561 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2); 00562 00563 /// ConstantExpr::get* - Return some common constants without having to 00564 /// specify the full Instruction::OPCODE identifier. 00565 /// 00566 static Constant *getNeg(Constant *C); 00567 static Constant *getNot(Constant *C); 00568 static Constant *getAdd(Constant *C1, Constant *C2); 00569 static Constant *getSub(Constant *C1, Constant *C2); 00570 static Constant *getMul(Constant *C1, Constant *C2); 00571 static Constant *getDiv(Constant *C1, Constant *C2); 00572 static Constant *getRem(Constant *C1, Constant *C2); 00573 static Constant *getAnd(Constant *C1, Constant *C2); 00574 static Constant *getOr(Constant *C1, Constant *C2); 00575 static Constant *getXor(Constant *C1, Constant *C2); 00576 static Constant *getSetEQ(Constant *C1, Constant *C2); 00577 static Constant *getSetNE(Constant *C1, Constant *C2); 00578 static Constant *getSetLT(Constant *C1, Constant *C2); 00579 static Constant *getSetGT(Constant *C1, Constant *C2); 00580 static Constant *getSetLE(Constant *C1, Constant *C2); 00581 static Constant *getSetGE(Constant *C1, Constant *C2); 00582 static Constant *getShl(Constant *C1, Constant *C2); 00583 static Constant *getShr(Constant *C1, Constant *C2); 00584 00585 static Constant *getUShr(Constant *C1, Constant *C2); // unsigned shr 00586 static Constant *getSShr(Constant *C1, Constant *C2); // signed shr 00587 00588 /// Getelementptr form. std::vector<Value*> is only accepted for convenience: 00589 /// all elements must be Constant's. 00590 /// 00591 static Constant *getGetElementPtr(Constant *C, 00592 const std::vector<Constant*> &IdxList); 00593 static Constant *getGetElementPtr(Constant *C, 00594 const std::vector<Value*> &IdxList); 00595 00596 static Constant *getExtractElement(Constant *Vec, Constant *Idx); 00597 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx); 00598 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask); 00599 00600 /// isNullValue - Return true if this is the value that would be returned by 00601 /// getNullValue. 00602 virtual bool isNullValue() const { return false; } 00603 00604 /// getOpcode - Return the opcode at the root of this constant expression 00605 unsigned getOpcode() const { return SubclassData; } 00606 00607 /// getOpcodeName - Return a string representation for an opcode. 00608 const char *getOpcodeName() const; 00609 00610 virtual void destroyConstant(); 00611 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 00612 00613 /// Override methods to provide more type information... 00614 inline Constant *getOperand(unsigned i) { 00615 return cast<Constant>(User::getOperand(i)); 00616 } 00617 inline Constant *getOperand(unsigned i) const { 00618 return const_cast<Constant*>(cast<Constant>(User::getOperand(i))); 00619 } 00620 00621 00622 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00623 static inline bool classof(const ConstantExpr *) { return true; } 00624 static inline bool classof(const Value *V) { 00625 return V->getValueType() == ConstantExprVal; 00626 } 00627 }; 00628 00629 00630 //===----------------------------------------------------------------------===// 00631 /// UndefValue - 'undef' values are things that do not have specified contents. 00632 /// These are used for a variety of purposes, including global variable 00633 /// initializers and operands to instructions. 'undef' values can occur with 00634 /// any type. 00635 /// 00636 class UndefValue : public Constant { 00637 friend struct ConstantCreator<UndefValue, Type, char>; 00638 UndefValue(const UndefValue &); // DO NOT IMPLEMENT 00639 protected: 00640 UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {} 00641 public: 00642 /// get() - Static factory methods - Return an 'undef' object of the specified 00643 /// type. 00644 /// 00645 static UndefValue *get(const Type *T); 00646 00647 /// isNullValue - Return true if this is the value that would be returned by 00648 /// getNullValue. 00649 virtual bool isNullValue() const { return false; } 00650 00651 virtual void destroyConstant(); 00652 00653 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00654 static inline bool classof(const UndefValue *) { return true; } 00655 static bool classof(const Value *V) { 00656 return V->getValueType() == UndefValueVal; 00657 } 00658 }; 00659 00660 } // End llvm namespace 00661 00662 #endif