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 & (~uint64_t(0UL) >> (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 00349 /// This method constructs a ConstantArray and initializes it with a text 00350 /// string. The default behavior (AddNull==true) causes a null terminator to 00351 /// be placed at the end of the array. This effectively increases the length 00352 /// of the array by one (you've been warned). However, in some situations 00353 /// this is not desired so if AddNull==false then the string is copied without 00354 /// null termination. 00355 static Constant *get(const std::string &Initializer, bool AddNull = true); 00356 00357 /// getType - Specialize the getType() method to always return an ArrayType, 00358 /// which reduces the amount of casting needed in parts of the compiler. 00359 /// 00360 inline const ArrayType *getType() const { 00361 return reinterpret_cast<const ArrayType*>(Value::getType()); 00362 } 00363 00364 /// isString - This method returns true if the array is an array of sbyte or 00365 /// ubyte, and if the elements of the array are all ConstantInt's. 00366 bool isString() const; 00367 00368 /// getAsString - If this array is isString(), then this method converts the 00369 /// array to an std::string and returns it. Otherwise, it asserts out. 00370 /// 00371 std::string getAsString() const; 00372 00373 /// isNullValue - Return true if this is the value that would be returned by 00374 /// getNullValue. This always returns false because zero arrays are always 00375 /// created as ConstantAggregateZero objects. 00376 virtual bool isNullValue() const { return false; } 00377 00378 virtual void destroyConstant(); 00379 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 00380 00381 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00382 static inline bool classof(const ConstantArray *) { return true; } 00383 static bool classof(const Value *V) { 00384 return V->getValueType() == ConstantArrayVal; 00385 } 00386 }; 00387 00388 00389 //===----------------------------------------------------------------------===// 00390 // ConstantStruct - Constant Struct Declarations 00391 // 00392 class ConstantStruct : public Constant { 00393 friend struct ConstantCreator<ConstantStruct, StructType, 00394 std::vector<Constant*> >; 00395 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT 00396 protected: 00397 ConstantStruct(const StructType *T, const std::vector<Constant*> &Val); 00398 ~ConstantStruct(); 00399 public: 00400 /// get() - Static factory methods - Return objects of the specified value 00401 /// 00402 static Constant *get(const StructType *T, const std::vector<Constant*> &V); 00403 static Constant *get(const std::vector<Constant*> &V); 00404 00405 /// getType() specialization - Reduce amount of casting... 00406 /// 00407 inline const StructType *getType() const { 00408 return reinterpret_cast<const StructType*>(Value::getType()); 00409 } 00410 00411 /// isNullValue - Return true if this is the value that would be returned by 00412 /// getNullValue. This always returns false because zero structs are always 00413 /// created as ConstantAggregateZero objects. 00414 virtual bool isNullValue() const { 00415 return false; 00416 } 00417 00418 virtual void destroyConstant(); 00419 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 00420 00421 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00422 static inline bool classof(const ConstantStruct *) { return true; } 00423 static bool classof(const Value *V) { 00424 return V->getValueType() == ConstantStructVal; 00425 } 00426 }; 00427 00428 //===----------------------------------------------------------------------===// 00429 /// ConstantPacked - Constant Packed Declarations 00430 /// 00431 class ConstantPacked : public Constant { 00432 friend struct ConstantCreator<ConstantPacked, PackedType, 00433 std::vector<Constant*> >; 00434 ConstantPacked(const ConstantPacked &); // DO NOT IMPLEMENT 00435 protected: 00436 ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val); 00437 ~ConstantPacked(); 00438 public: 00439 /// get() - Static factory methods - Return objects of the specified value 00440 static Constant *get(const PackedType *T, const std::vector<Constant*> &); 00441 static Constant *get(const std::vector<Constant*> &V); 00442 00443 /// getType - Specialize the getType() method to always return an PackedType, 00444 /// which reduces the amount of casting needed in parts of the compiler. 00445 /// 00446 inline const PackedType *getType() const { 00447 return reinterpret_cast<const PackedType*>(Value::getType()); 00448 } 00449 00450 /// isNullValue - Return true if this is the value that would be returned by 00451 /// getNullValue. This always returns false because zero arrays are always 00452 /// created as ConstantAggregateZero objects. 00453 virtual bool isNullValue() const { return false; } 00454 00455 virtual void destroyConstant(); 00456 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 00457 00458 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00459 static inline bool classof(const ConstantPacked *) { return true; } 00460 static bool classof(const Value *V) { 00461 return V->getValueType() == ConstantPackedVal; 00462 } 00463 }; 00464 00465 //===----------------------------------------------------------------------===// 00466 /// ConstantPointerNull - a constant pointer value that points to null 00467 /// 00468 class ConstantPointerNull : public Constant { 00469 friend struct ConstantCreator<ConstantPointerNull, PointerType, char>; 00470 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT 00471 protected: 00472 ConstantPointerNull(const PointerType *T) 00473 : Constant(reinterpret_cast<const Type*>(T), 00474 Value::ConstantPointerNullVal, 0, 0) {} 00475 00476 public: 00477 00478 /// get() - Static factory methods - Return objects of the specified value 00479 static ConstantPointerNull *get(const PointerType *T); 00480 00481 /// isNullValue - Return true if this is the value that would be returned by 00482 /// getNullValue. 00483 virtual bool isNullValue() const { return true; } 00484 00485 virtual void destroyConstant(); 00486 00487 /// getType - Specialize the getType() method to always return an PointerType, 00488 /// which reduces the amount of casting needed in parts of the compiler. 00489 /// 00490 inline const PointerType *getType() const { 00491 return reinterpret_cast<const PointerType*>(Value::getType()); 00492 } 00493 00494 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00495 static inline bool classof(const ConstantPointerNull *) { return true; } 00496 static bool classof(const Value *V) { 00497 return V->getValueType() == ConstantPointerNullVal; 00498 } 00499 }; 00500 00501 00502 /// ConstantExpr - a constant value that is initialized with an expression using 00503 /// other constant values. 00504 /// 00505 /// This class uses the standard Instruction opcodes to define the various 00506 /// constant expressions. The Opcode field for the ConstantExpr class is 00507 /// maintained in the Value::SubclassData field. 00508 class ConstantExpr : public Constant { 00509 friend struct ConstantCreator<ConstantExpr,Type, 00510 std::pair<unsigned, std::vector<Constant*> > >; 00511 friend struct ConvertConstantType<ConstantExpr, Type>; 00512 00513 protected: 00514 ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps) 00515 : Constant(Ty, ConstantExprVal, Ops, NumOps) { 00516 // Operation type (an Instruction opcode) is stored as the SubclassData. 00517 SubclassData = Opcode; 00518 } 00519 00520 // These private methods are used by the type resolution code to create 00521 // ConstantExprs in intermediate forms. 00522 static Constant *getTy(const Type *Ty, unsigned Opcode, 00523 Constant *C1, Constant *C2); 00524 static Constant *getShiftTy(const Type *Ty, 00525 unsigned Opcode, Constant *C1, Constant *C2); 00526 static Constant *getSelectTy(const Type *Ty, 00527 Constant *C1, Constant *C2, Constant *C3); 00528 static Constant *getGetElementPtrTy(const Type *Ty, Constant *C, 00529 const std::vector<Value*> &IdxList); 00530 static Constant *getExtractElementTy(const Type *Ty, Constant *Val, 00531 Constant *Idx); 00532 static Constant *getInsertElementTy(const Type *Ty, Constant *Val, 00533 Constant *Elt, Constant *Idx); 00534 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1, 00535 Constant *V2, Constant *Mask); 00536 00537 public: 00538 // Static methods to construct a ConstantExpr of different kinds. Note that 00539 // these methods may return a object that is not an instance of the 00540 // ConstantExpr class, because they will attempt to fold the constant 00541 // expression into something simpler if possible. 00542 00543 /// Cast constant expr 00544 /// 00545 static Constant *getCast(Constant *C, const Type *Ty); 00546 static Constant *getSignExtend(Constant *C, const Type *Ty); 00547 static Constant *getZeroExtend(Constant *C, const Type *Ty); 00548 00549 /// Select constant expr 00550 /// 00551 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) { 00552 return getSelectTy(V1->getType(), C, V1, V2); 00553 } 00554 00555 /// getSizeOf constant expr - computes the size of a type in a target 00556 /// independent way (Note: the return type is ULong but the object is not 00557 /// necessarily a ConstantUInt). 00558 /// 00559 static Constant *getSizeOf(const Type *Ty); 00560 00561 /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array, 00562 /// return a pointer to a pointer of the array element type. 00563 static Constant *getPtrPtrFromArrayPtr(Constant *C); 00564 00565 /// ConstantExpr::get - Return a binary or shift operator constant expression, 00566 /// folding if possible. 00567 /// 00568 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2); 00569 00570 /// ConstantExpr::get* - Return some common constants without having to 00571 /// specify the full Instruction::OPCODE identifier. 00572 /// 00573 static Constant *getNeg(Constant *C); 00574 static Constant *getNot(Constant *C); 00575 static Constant *getAdd(Constant *C1, Constant *C2); 00576 static Constant *getSub(Constant *C1, Constant *C2); 00577 static Constant *getMul(Constant *C1, Constant *C2); 00578 static Constant *getDiv(Constant *C1, Constant *C2); 00579 static Constant *getRem(Constant *C1, Constant *C2); 00580 static Constant *getAnd(Constant *C1, Constant *C2); 00581 static Constant *getOr(Constant *C1, Constant *C2); 00582 static Constant *getXor(Constant *C1, Constant *C2); 00583 static Constant *getSetEQ(Constant *C1, Constant *C2); 00584 static Constant *getSetNE(Constant *C1, Constant *C2); 00585 static Constant *getSetLT(Constant *C1, Constant *C2); 00586 static Constant *getSetGT(Constant *C1, Constant *C2); 00587 static Constant *getSetLE(Constant *C1, Constant *C2); 00588 static Constant *getSetGE(Constant *C1, Constant *C2); 00589 static Constant *getShl(Constant *C1, Constant *C2); 00590 static Constant *getShr(Constant *C1, Constant *C2); 00591 00592 static Constant *getUShr(Constant *C1, Constant *C2); // unsigned shr 00593 static Constant *getSShr(Constant *C1, Constant *C2); // signed shr 00594 00595 /// Getelementptr form. std::vector<Value*> is only accepted for convenience: 00596 /// all elements must be Constant's. 00597 /// 00598 static Constant *getGetElementPtr(Constant *C, 00599 const std::vector<Constant*> &IdxList); 00600 static Constant *getGetElementPtr(Constant *C, 00601 const std::vector<Value*> &IdxList); 00602 00603 static Constant *getExtractElement(Constant *Vec, Constant *Idx); 00604 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx); 00605 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask); 00606 00607 /// isNullValue - Return true if this is the value that would be returned by 00608 /// getNullValue. 00609 virtual bool isNullValue() const { return false; } 00610 00611 /// getOpcode - Return the opcode at the root of this constant expression 00612 unsigned getOpcode() const { return SubclassData; } 00613 00614 /// getOpcodeName - Return a string representation for an opcode. 00615 const char *getOpcodeName() const; 00616 00617 /// getWithOperandReplaced - Return a constant expression identical to this 00618 /// one, but with the specified operand set to the specified value. 00619 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const; 00620 00621 /// getWithOperands - This returns the current constant expression with the 00622 /// operands replaced with the specified values. The specified operands must 00623 /// match count and type with the existing ones. 00624 Constant *getWithOperands(const std::vector<Constant*> &Ops) const; 00625 00626 virtual void destroyConstant(); 00627 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 00628 00629 /// Override methods to provide more type information... 00630 inline Constant *getOperand(unsigned i) { 00631 return cast<Constant>(User::getOperand(i)); 00632 } 00633 inline Constant *getOperand(unsigned i) const { 00634 return const_cast<Constant*>(cast<Constant>(User::getOperand(i))); 00635 } 00636 00637 00638 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00639 static inline bool classof(const ConstantExpr *) { return true; } 00640 static inline bool classof(const Value *V) { 00641 return V->getValueType() == ConstantExprVal; 00642 } 00643 }; 00644 00645 00646 //===----------------------------------------------------------------------===// 00647 /// UndefValue - 'undef' values are things that do not have specified contents. 00648 /// These are used for a variety of purposes, including global variable 00649 /// initializers and operands to instructions. 'undef' values can occur with 00650 /// any type. 00651 /// 00652 class UndefValue : public Constant { 00653 friend struct ConstantCreator<UndefValue, Type, char>; 00654 UndefValue(const UndefValue &); // DO NOT IMPLEMENT 00655 protected: 00656 UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {} 00657 public: 00658 /// get() - Static factory methods - Return an 'undef' object of the specified 00659 /// type. 00660 /// 00661 static UndefValue *get(const Type *T); 00662 00663 /// isNullValue - Return true if this is the value that would be returned by 00664 /// getNullValue. 00665 virtual bool isNullValue() const { return false; } 00666 00667 virtual void destroyConstant(); 00668 00669 /// Methods for support type inquiry through isa, cast, and dyn_cast: 00670 static inline bool classof(const UndefValue *) { return true; } 00671 static bool classof(const Value *V) { 00672 return V->getValueType() == UndefValueVal; 00673 } 00674 }; 00675 00676 } // End llvm namespace 00677 00678 #endif