Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1163 lines
46 KiB

  1. //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. /// @file
  11. /// This file contains the declarations for the subclasses of Constant,
  12. /// which represent the different flavors of constant values that live in LLVM.
  13. /// Note that Constants are immutable (once created they never change) and are
  14. /// fully shared by structural equivalence. This means that two structurally
  15. /// equivalent constants will always have the same address. Constant's are
  16. /// created on demand as needed and never deleted: thus clients don't have to
  17. /// worry about the lifetime of the objects.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_IR_CONSTANTS_H
  21. #define LLVM_IR_CONSTANTS_H
  22. #include "llvm/ADT/APFloat.h"
  23. #include "llvm/ADT/APInt.h"
  24. #include "llvm/ADT/ArrayRef.h"
  25. #include "llvm/IR/Constant.h"
  26. #include "llvm/IR/OperandTraits.h"
  27. namespace llvm {
  28. class ArrayType;
  29. class IntegerType;
  30. class StructType;
  31. class PointerType;
  32. class VectorType;
  33. class SequentialType;
  34. template<class ConstantClass, class TypeClass, class ValType>
  35. struct ConstantCreator;
  36. template<class ConstantClass, class TypeClass>
  37. struct ConstantArrayCreator;
  38. template<class ConstantClass, class TypeClass>
  39. struct ConvertConstantType;
  40. //===----------------------------------------------------------------------===//
  41. /// This is the shared class of boolean and integer constants. This class
  42. /// represents both boolean and integral constants.
  43. /// @brief Class for constant integers.
  44. class ConstantInt : public Constant {
  45. virtual void anchor();
  46. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  47. ConstantInt(const ConstantInt &) LLVM_DELETED_FUNCTION;
  48. ConstantInt(IntegerType *Ty, const APInt& V);
  49. APInt Val;
  50. protected:
  51. // allocate space for exactly zero operands
  52. void *operator new(size_t s) {
  53. return User::operator new(s, 0);
  54. }
  55. public:
  56. static ConstantInt *getTrue(LLVMContext &Context);
  57. static ConstantInt *getFalse(LLVMContext &Context);
  58. static Constant *getTrue(Type *Ty);
  59. static Constant *getFalse(Type *Ty);
  60. /// If Ty is a vector type, return a Constant with a splat of the given
  61. /// value. Otherwise return a ConstantInt for the given value.
  62. static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
  63. /// Return a ConstantInt with the specified integer value for the specified
  64. /// type. If the type is wider than 64 bits, the value will be zero-extended
  65. /// to fit the type, unless isSigned is true, in which case the value will
  66. /// be interpreted as a 64-bit signed integer and sign-extended to fit
  67. /// the type.
  68. /// @brief Get a ConstantInt for a specific value.
  69. static ConstantInt *get(IntegerType *Ty, uint64_t V,
  70. bool isSigned = false);
  71. /// Return a ConstantInt with the specified value for the specified type. The
  72. /// value V will be canonicalized to a an unsigned APInt. Accessing it with
  73. /// either getSExtValue() or getZExtValue() will yield a correctly sized and
  74. /// signed value for the type Ty.
  75. /// @brief Get a ConstantInt for a specific signed value.
  76. static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
  77. static Constant *getSigned(Type *Ty, int64_t V);
  78. /// Return a ConstantInt with the specified value and an implied Type. The
  79. /// type is the integer type that corresponds to the bit width of the value.
  80. static ConstantInt *get(LLVMContext &Context, const APInt &V);
  81. /// Return a ConstantInt constructed from the string strStart with the given
  82. /// radix.
  83. static ConstantInt *get(IntegerType *Ty, StringRef Str,
  84. uint8_t radix);
  85. /// If Ty is a vector type, return a Constant with a splat of the given
  86. /// value. Otherwise return a ConstantInt for the given value.
  87. static Constant *get(Type* Ty, const APInt& V);
  88. /// Return the constant as an APInt value reference. This allows clients to
  89. /// obtain a copy of the value, with all its precision in tact.
  90. /// @brief Return the constant's value.
  91. inline const APInt &getValue() const {
  92. return Val;
  93. }
  94. /// getBitWidth - Return the bitwidth of this constant.
  95. unsigned getBitWidth() const { return Val.getBitWidth(); }
  96. /// Return the constant as a 64-bit unsigned integer value after it
  97. /// has been zero extended as appropriate for the type of this constant. Note
  98. /// that this method can assert if the value does not fit in 64 bits.
  99. /// @deprecated
  100. /// @brief Return the zero extended value.
  101. inline uint64_t getZExtValue() const {
  102. return Val.getZExtValue();
  103. }
  104. /// Return the constant as a 64-bit integer value after it has been sign
  105. /// extended as appropriate for the type of this constant. Note that
  106. /// this method can assert if the value does not fit in 64 bits.
  107. /// @deprecated
  108. /// @brief Return the sign extended value.
  109. inline int64_t getSExtValue() const {
  110. return Val.getSExtValue();
  111. }
  112. /// A helper method that can be used to determine if the constant contained
  113. /// within is equal to a constant. This only works for very small values,
  114. /// because this is all that can be represented with all types.
  115. /// @brief Determine if this constant's value is same as an unsigned char.
  116. bool equalsInt(uint64_t V) const {
  117. return Val == V;
  118. }
  119. /// getType - Specialize the getType() method to always return an IntegerType,
  120. /// which reduces the amount of casting needed in parts of the compiler.
  121. ///
  122. inline IntegerType *getType() const {
  123. return reinterpret_cast<IntegerType*>(Value::getType());
  124. }
  125. /// This static method returns true if the type Ty is big enough to
  126. /// represent the value V. This can be used to avoid having the get method
  127. /// assert when V is larger than Ty can represent. Note that there are two
  128. /// versions of this method, one for unsigned and one for signed integers.
  129. /// Although ConstantInt canonicalizes everything to an unsigned integer,
  130. /// the signed version avoids callers having to convert a signed quantity
  131. /// to the appropriate unsigned type before calling the method.
  132. /// @returns true if V is a valid value for type Ty
  133. /// @brief Determine if the value is in range for the given type.
  134. static bool isValueValidForType(Type *Ty, uint64_t V);
  135. static bool isValueValidForType(Type *Ty, int64_t V);
  136. bool isNegative() const { return Val.isNegative(); }
  137. /// This is just a convenience method to make client code smaller for a
  138. /// common code. It also correctly performs the comparison without the
  139. /// potential for an assertion from getZExtValue().
  140. bool isZero() const {
  141. return Val == 0;
  142. }
  143. /// This is just a convenience method to make client code smaller for a
  144. /// common case. It also correctly performs the comparison without the
  145. /// potential for an assertion from getZExtValue().
  146. /// @brief Determine if the value is one.
  147. bool isOne() const {
  148. return Val == 1;
  149. }
  150. /// This function will return true iff every bit in this constant is set
  151. /// to true.
  152. /// @returns true iff this constant's bits are all set to true.
  153. /// @brief Determine if the value is all ones.
  154. bool isMinusOne() const {
  155. return Val.isAllOnesValue();
  156. }
  157. /// This function will return true iff this constant represents the largest
  158. /// value that may be represented by the constant's type.
  159. /// @returns true iff this is the largest value that may be represented
  160. /// by this type.
  161. /// @brief Determine if the value is maximal.
  162. bool isMaxValue(bool isSigned) const {
  163. if (isSigned)
  164. return Val.isMaxSignedValue();
  165. else
  166. return Val.isMaxValue();
  167. }
  168. /// This function will return true iff this constant represents the smallest
  169. /// value that may be represented by this constant's type.
  170. /// @returns true if this is the smallest value that may be represented by
  171. /// this type.
  172. /// @brief Determine if the value is minimal.
  173. bool isMinValue(bool isSigned) const {
  174. if (isSigned)
  175. return Val.isMinSignedValue();
  176. else
  177. return Val.isMinValue();
  178. }
  179. /// This function will return true iff this constant represents a value with
  180. /// active bits bigger than 64 bits or a value greater than the given uint64_t
  181. /// value.
  182. /// @returns true iff this constant is greater or equal to the given number.
  183. /// @brief Determine if the value is greater or equal to the given number.
  184. bool uge(uint64_t Num) const {
  185. return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
  186. }
  187. /// getLimitedValue - If the value is smaller than the specified limit,
  188. /// return it, otherwise return the limit value. This causes the value
  189. /// to saturate to the limit.
  190. /// @returns the min of the value of the constant and the specified value
  191. /// @brief Get the constant's value with a saturation limit
  192. uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
  193. return Val.getLimitedValue(Limit);
  194. }
  195. /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
  196. static bool classof(const Value *V) {
  197. return V->getValueID() == ConstantIntVal;
  198. }
  199. };
  200. //===----------------------------------------------------------------------===//
  201. /// ConstantFP - Floating Point Values [float, double]
  202. ///
  203. class ConstantFP : public Constant {
  204. APFloat Val;
  205. virtual void anchor();
  206. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  207. ConstantFP(const ConstantFP &) LLVM_DELETED_FUNCTION;
  208. friend class LLVMContextImpl;
  209. protected:
  210. ConstantFP(Type *Ty, const APFloat& V);
  211. protected:
  212. // allocate space for exactly zero operands
  213. void *operator new(size_t s) {
  214. return User::operator new(s, 0);
  215. }
  216. public:
  217. /// Floating point negation must be implemented with f(x) = -0.0 - x. This
  218. /// method returns the negative zero constant for floating point or vector
  219. /// floating point types; for all other types, it returns the null value.
  220. static Constant *getZeroValueForNegation(Type *Ty);
  221. /// get() - This returns a ConstantFP, or a vector containing a splat of a
  222. /// ConstantFP, for the specified value in the specified type. This should
  223. /// only be used for simple constant values like 2.0/1.0 etc, that are
  224. /// known-valid both as host double and as the target format.
  225. static Constant *get(Type* Ty, double V);
  226. static Constant *get(Type* Ty, StringRef Str);
  227. static ConstantFP *get(LLVMContext &Context, const APFloat &V);
  228. static ConstantFP *getNegativeZero(Type* Ty);
  229. static ConstantFP *getInfinity(Type *Ty, bool Negative = false);
  230. /// isValueValidForType - return true if Ty is big enough to represent V.
  231. static bool isValueValidForType(Type *Ty, const APFloat &V);
  232. inline const APFloat &getValueAPF() const { return Val; }
  233. /// isZero - Return true if the value is positive or negative zero.
  234. bool isZero() const { return Val.isZero(); }
  235. /// isNegative - Return true if the sign bit is set.
  236. bool isNegative() const { return Val.isNegative(); }
  237. /// isNaN - Return true if the value is a NaN.
  238. bool isNaN() const { return Val.isNaN(); }
  239. /// isExactlyValue - We don't rely on operator== working on double values, as
  240. /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
  241. /// As such, this method can be used to do an exact bit-for-bit comparison of
  242. /// two floating point values. The version with a double operand is retained
  243. /// because it's so convenient to write isExactlyValue(2.0), but please use
  244. /// it only for simple constants.
  245. bool isExactlyValue(const APFloat &V) const;
  246. bool isExactlyValue(double V) const {
  247. bool ignored;
  248. APFloat FV(V);
  249. FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
  250. return isExactlyValue(FV);
  251. }
  252. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  253. static bool classof(const Value *V) {
  254. return V->getValueID() == ConstantFPVal;
  255. }
  256. };
  257. //===----------------------------------------------------------------------===//
  258. /// ConstantAggregateZero - All zero aggregate value
  259. ///
  260. class ConstantAggregateZero : public Constant {
  261. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  262. ConstantAggregateZero(const ConstantAggregateZero &) LLVM_DELETED_FUNCTION;
  263. protected:
  264. explicit ConstantAggregateZero(Type *ty)
  265. : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
  266. protected:
  267. // allocate space for exactly zero operands
  268. void *operator new(size_t s) {
  269. return User::operator new(s, 0);
  270. }
  271. public:
  272. static ConstantAggregateZero *get(Type *Ty);
  273. virtual void destroyConstant();
  274. /// getSequentialElement - If this CAZ has array or vector type, return a zero
  275. /// with the right element type.
  276. Constant *getSequentialElement() const;
  277. /// getStructElement - If this CAZ has struct type, return a zero with the
  278. /// right element type for the specified element.
  279. Constant *getStructElement(unsigned Elt) const;
  280. /// getElementValue - Return a zero of the right value for the specified GEP
  281. /// index.
  282. Constant *getElementValue(Constant *C) const;
  283. /// getElementValue - Return a zero of the right value for the specified GEP
  284. /// index.
  285. Constant *getElementValue(unsigned Idx) const;
  286. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  287. ///
  288. static bool classof(const Value *V) {
  289. return V->getValueID() == ConstantAggregateZeroVal;
  290. }
  291. };
  292. //===----------------------------------------------------------------------===//
  293. /// ConstantArray - Constant Array Declarations
  294. ///
  295. class ConstantArray : public Constant {
  296. friend struct ConstantArrayCreator<ConstantArray, ArrayType>;
  297. ConstantArray(const ConstantArray &) LLVM_DELETED_FUNCTION;
  298. protected:
  299. ConstantArray(ArrayType *T, ArrayRef<Constant *> Val);
  300. public:
  301. // ConstantArray accessors
  302. static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
  303. /// Transparently provide more efficient getOperand methods.
  304. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
  305. /// getType - Specialize the getType() method to always return an ArrayType,
  306. /// which reduces the amount of casting needed in parts of the compiler.
  307. ///
  308. inline ArrayType *getType() const {
  309. return reinterpret_cast<ArrayType*>(Value::getType());
  310. }
  311. virtual void destroyConstant();
  312. virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
  313. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  314. static bool classof(const Value *V) {
  315. return V->getValueID() == ConstantArrayVal;
  316. }
  317. };
  318. template <>
  319. struct OperandTraits<ConstantArray> :
  320. public VariadicOperandTraits<ConstantArray> {
  321. };
  322. DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant)
  323. //===----------------------------------------------------------------------===//
  324. // ConstantStruct - Constant Struct Declarations
  325. //
  326. class ConstantStruct : public Constant {
  327. friend struct ConstantArrayCreator<ConstantStruct, StructType>;
  328. ConstantStruct(const ConstantStruct &) LLVM_DELETED_FUNCTION;
  329. protected:
  330. ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
  331. public:
  332. // ConstantStruct accessors
  333. static Constant *get(StructType *T, ArrayRef<Constant*> V);
  334. static Constant *get(StructType *T, ...) END_WITH_NULL;
  335. /// getAnon - Return an anonymous struct that has the specified
  336. /// elements. If the struct is possibly empty, then you must specify a
  337. /// context.
  338. static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) {
  339. return get(getTypeForElements(V, Packed), V);
  340. }
  341. static Constant *getAnon(LLVMContext &Ctx,
  342. ArrayRef<Constant*> V, bool Packed = false) {
  343. return get(getTypeForElements(Ctx, V, Packed), V);
  344. }
  345. /// getTypeForElements - Return an anonymous struct type to use for a constant
  346. /// with the specified set of elements. The list must not be empty.
  347. static StructType *getTypeForElements(ArrayRef<Constant*> V,
  348. bool Packed = false);
  349. /// getTypeForElements - This version of the method allows an empty list.
  350. static StructType *getTypeForElements(LLVMContext &Ctx,
  351. ArrayRef<Constant*> V,
  352. bool Packed = false);
  353. /// Transparently provide more efficient getOperand methods.
  354. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
  355. /// getType() specialization - Reduce amount of casting...
  356. ///
  357. inline StructType *getType() const {
  358. return reinterpret_cast<StructType*>(Value::getType());
  359. }
  360. virtual void destroyConstant();
  361. virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
  362. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  363. static bool classof(const Value *V) {
  364. return V->getValueID() == ConstantStructVal;
  365. }
  366. };
  367. template <>
  368. struct OperandTraits<ConstantStruct> :
  369. public VariadicOperandTraits<ConstantStruct> {
  370. };
  371. DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant)
  372. //===----------------------------------------------------------------------===//
  373. /// ConstantVector - Constant Vector Declarations
  374. ///
  375. class ConstantVector : public Constant {
  376. friend struct ConstantArrayCreator<ConstantVector, VectorType>;
  377. ConstantVector(const ConstantVector &) LLVM_DELETED_FUNCTION;
  378. protected:
  379. ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
  380. public:
  381. // ConstantVector accessors
  382. static Constant *get(ArrayRef<Constant*> V);
  383. /// getSplat - Return a ConstantVector with the specified constant in each
  384. /// element.
  385. static Constant *getSplat(unsigned NumElts, Constant *Elt);
  386. /// Transparently provide more efficient getOperand methods.
  387. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
  388. /// getType - Specialize the getType() method to always return a VectorType,
  389. /// which reduces the amount of casting needed in parts of the compiler.
  390. ///
  391. inline VectorType *getType() const {
  392. return reinterpret_cast<VectorType*>(Value::getType());
  393. }
  394. /// getSplatValue - If this is a splat constant, meaning that all of the
  395. /// elements have the same value, return that value. Otherwise return NULL.
  396. Constant *getSplatValue() const;
  397. virtual void destroyConstant();
  398. virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
  399. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  400. static bool classof(const Value *V) {
  401. return V->getValueID() == ConstantVectorVal;
  402. }
  403. };
  404. template <>
  405. struct OperandTraits<ConstantVector> :
  406. public VariadicOperandTraits<ConstantVector> {
  407. };
  408. DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant)
  409. //===----------------------------------------------------------------------===//
  410. /// ConstantPointerNull - a constant pointer value that points to null
  411. ///
  412. class ConstantPointerNull : public Constant {
  413. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  414. ConstantPointerNull(const ConstantPointerNull &) LLVM_DELETED_FUNCTION;
  415. protected:
  416. explicit ConstantPointerNull(PointerType *T)
  417. : Constant(reinterpret_cast<Type*>(T),
  418. Value::ConstantPointerNullVal, 0, 0) {}
  419. protected:
  420. // allocate space for exactly zero operands
  421. void *operator new(size_t s) {
  422. return User::operator new(s, 0);
  423. }
  424. public:
  425. /// get() - Static factory methods - Return objects of the specified value
  426. static ConstantPointerNull *get(PointerType *T);
  427. virtual void destroyConstant();
  428. /// getType - Specialize the getType() method to always return an PointerType,
  429. /// which reduces the amount of casting needed in parts of the compiler.
  430. ///
  431. inline PointerType *getType() const {
  432. return reinterpret_cast<PointerType*>(Value::getType());
  433. }
  434. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  435. static bool classof(const Value *V) {
  436. return V->getValueID() == ConstantPointerNullVal;
  437. }
  438. };
  439. //===----------------------------------------------------------------------===//
  440. /// ConstantDataSequential - A vector or array constant whose element type is a
  441. /// simple 1/2/4/8-byte integer or float/double, and whose elements are just
  442. /// simple data values (i.e. ConstantInt/ConstantFP). This Constant node has no
  443. /// operands because it stores all of the elements of the constant as densely
  444. /// packed data, instead of as Value*'s.
  445. ///
  446. /// This is the common base class of ConstantDataArray and ConstantDataVector.
  447. ///
  448. class ConstantDataSequential : public Constant {
  449. friend class LLVMContextImpl;
  450. /// DataElements - A pointer to the bytes underlying this constant (which is
  451. /// owned by the uniquing StringMap).
  452. const char *DataElements;
  453. /// Next - This forms a link list of ConstantDataSequential nodes that have
  454. /// the same value but different type. For example, 0,0,0,1 could be a 4
  455. /// element array of i8, or a 1-element array of i32. They'll both end up in
  456. /// the same StringMap bucket, linked up.
  457. ConstantDataSequential *Next;
  458. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  459. ConstantDataSequential(const ConstantDataSequential &) LLVM_DELETED_FUNCTION;
  460. protected:
  461. explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
  462. : Constant(ty, VT, 0, 0), DataElements(Data), Next(0) {}
  463. ~ConstantDataSequential() { delete Next; }
  464. static Constant *getImpl(StringRef Bytes, Type *Ty);
  465. protected:
  466. // allocate space for exactly zero operands.
  467. void *operator new(size_t s) {
  468. return User::operator new(s, 0);
  469. }
  470. public:
  471. /// isElementTypeCompatible - Return true if a ConstantDataSequential can be
  472. /// formed with a vector or array of the specified element type.
  473. /// ConstantDataArray only works with normal float and int types that are
  474. /// stored densely in memory, not with things like i42 or x86_f80.
  475. static bool isElementTypeCompatible(const Type *Ty);
  476. /// getElementAsInteger - If this is a sequential container of integers (of
  477. /// any size), return the specified element in the low bits of a uint64_t.
  478. uint64_t getElementAsInteger(unsigned i) const;
  479. /// getElementAsAPFloat - If this is a sequential container of floating point
  480. /// type, return the specified element as an APFloat.
  481. APFloat getElementAsAPFloat(unsigned i) const;
  482. /// getElementAsFloat - If this is an sequential container of floats, return
  483. /// the specified element as a float.
  484. float getElementAsFloat(unsigned i) const;
  485. /// getElementAsDouble - If this is an sequential container of doubles, return
  486. /// the specified element as a double.
  487. double getElementAsDouble(unsigned i) const;
  488. /// getElementAsConstant - Return a Constant for a specified index's element.
  489. /// Note that this has to compute a new constant to return, so it isn't as
  490. /// efficient as getElementAsInteger/Float/Double.
  491. Constant *getElementAsConstant(unsigned i) const;
  492. /// getType - Specialize the getType() method to always return a
  493. /// SequentialType, which reduces the amount of casting needed in parts of the
  494. /// compiler.
  495. inline SequentialType *getType() const {
  496. return reinterpret_cast<SequentialType*>(Value::getType());
  497. }
  498. /// getElementType - Return the element type of the array/vector.
  499. Type *getElementType() const;
  500. /// getNumElements - Return the number of elements in the array or vector.
  501. unsigned getNumElements() const;
  502. /// getElementByteSize - Return the size (in bytes) of each element in the
  503. /// array/vector. The size of the elements is known to be a multiple of one
  504. /// byte.
  505. uint64_t getElementByteSize() const;
  506. /// isString - This method returns true if this is an array of i8.
  507. bool isString() const;
  508. /// isCString - This method returns true if the array "isString", ends with a
  509. /// nul byte, and does not contains any other nul bytes.
  510. bool isCString() const;
  511. /// getAsString - If this array is isString(), then this method returns the
  512. /// array as a StringRef. Otherwise, it asserts out.
  513. ///
  514. StringRef getAsString() const {
  515. assert(isString() && "Not a string");
  516. return getRawDataValues();
  517. }
  518. /// getAsCString - If this array is isCString(), then this method returns the
  519. /// array (without the trailing null byte) as a StringRef. Otherwise, it
  520. /// asserts out.
  521. ///
  522. StringRef getAsCString() const {
  523. assert(isCString() && "Isn't a C string");
  524. StringRef Str = getAsString();
  525. return Str.substr(0, Str.size()-1);
  526. }
  527. /// getRawDataValues - Return the raw, underlying, bytes of this data. Note
  528. /// that this is an extremely tricky thing to work with, as it exposes the
  529. /// host endianness of the data elements.
  530. StringRef getRawDataValues() const;
  531. virtual void destroyConstant();
  532. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  533. ///
  534. static bool classof(const Value *V) {
  535. return V->getValueID() == ConstantDataArrayVal ||
  536. V->getValueID() == ConstantDataVectorVal;
  537. }
  538. private:
  539. const char *getElementPointer(unsigned Elt) const;
  540. };
  541. //===----------------------------------------------------------------------===//
  542. /// ConstantDataArray - An array constant whose element type is a simple
  543. /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
  544. /// data values (i.e. ConstantInt/ConstantFP). This Constant node has no
  545. /// operands because it stores all of the elements of the constant as densely
  546. /// packed data, instead of as Value*'s.
  547. class ConstantDataArray : public ConstantDataSequential {
  548. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  549. ConstantDataArray(const ConstantDataArray &) LLVM_DELETED_FUNCTION;
  550. virtual void anchor();
  551. friend class ConstantDataSequential;
  552. explicit ConstantDataArray(Type *ty, const char *Data)
  553. : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
  554. protected:
  555. // allocate space for exactly zero operands.
  556. void *operator new(size_t s) {
  557. return User::operator new(s, 0);
  558. }
  559. public:
  560. /// get() constructors - Return a constant with array type with an element
  561. /// count and element type matching the ArrayRef passed in. Note that this
  562. /// can return a ConstantAggregateZero object.
  563. static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
  564. static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
  565. static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
  566. static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
  567. static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
  568. static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
  569. /// getString - This method constructs a CDS and initializes it with a text
  570. /// string. The default behavior (AddNull==true) causes a null terminator to
  571. /// be placed at the end of the array (increasing the length of the string by
  572. /// one more than the StringRef would normally indicate. Pass AddNull=false
  573. /// to disable this behavior.
  574. static Constant *getString(LLVMContext &Context, StringRef Initializer,
  575. bool AddNull = true);
  576. /// getType - Specialize the getType() method to always return an ArrayType,
  577. /// which reduces the amount of casting needed in parts of the compiler.
  578. ///
  579. inline ArrayType *getType() const {
  580. return reinterpret_cast<ArrayType*>(Value::getType());
  581. }
  582. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  583. ///
  584. static bool classof(const Value *V) {
  585. return V->getValueID() == ConstantDataArrayVal;
  586. }
  587. };
  588. //===----------------------------------------------------------------------===//
  589. /// ConstantDataVector - A vector constant whose element type is a simple
  590. /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
  591. /// data values (i.e. ConstantInt/ConstantFP). This Constant node has no
  592. /// operands because it stores all of the elements of the constant as densely
  593. /// packed data, instead of as Value*'s.
  594. class ConstantDataVector : public ConstantDataSequential {
  595. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  596. ConstantDataVector(const ConstantDataVector &) LLVM_DELETED_FUNCTION;
  597. virtual void anchor();
  598. friend class ConstantDataSequential;
  599. explicit ConstantDataVector(Type *ty, const char *Data)
  600. : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
  601. protected:
  602. // allocate space for exactly zero operands.
  603. void *operator new(size_t s) {
  604. return User::operator new(s, 0);
  605. }
  606. public:
  607. /// get() constructors - Return a constant with vector type with an element
  608. /// count and element type matching the ArrayRef passed in. Note that this
  609. /// can return a ConstantAggregateZero object.
  610. static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
  611. static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
  612. static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
  613. static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
  614. static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
  615. static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
  616. /// getSplat - Return a ConstantVector with the specified constant in each
  617. /// element. The specified constant has to be a of a compatible type (i8/i16/
  618. /// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
  619. static Constant *getSplat(unsigned NumElts, Constant *Elt);
  620. /// getSplatValue - If this is a splat constant, meaning that all of the
  621. /// elements have the same value, return that value. Otherwise return NULL.
  622. Constant *getSplatValue() const;
  623. /// getType - Specialize the getType() method to always return a VectorType,
  624. /// which reduces the amount of casting needed in parts of the compiler.
  625. ///
  626. inline VectorType *getType() const {
  627. return reinterpret_cast<VectorType*>(Value::getType());
  628. }
  629. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  630. ///
  631. static bool classof(const Value *V) {
  632. return V->getValueID() == ConstantDataVectorVal;
  633. }
  634. };
  635. /// BlockAddress - The address of a basic block.
  636. ///
  637. class BlockAddress : public Constant {
  638. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  639. void *operator new(size_t s) { return User::operator new(s, 2); }
  640. BlockAddress(Function *F, BasicBlock *BB);
  641. public:
  642. /// get - Return a BlockAddress for the specified function and basic block.
  643. static BlockAddress *get(Function *F, BasicBlock *BB);
  644. /// get - Return a BlockAddress for the specified basic block. The basic
  645. /// block must be embedded into a function.
  646. static BlockAddress *get(BasicBlock *BB);
  647. /// Transparently provide more efficient getOperand methods.
  648. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
  649. Function *getFunction() const { return (Function*)Op<0>().get(); }
  650. BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
  651. virtual void destroyConstant();
  652. virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
  653. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  654. static inline bool classof(const Value *V) {
  655. return V->getValueID() == BlockAddressVal;
  656. }
  657. };
  658. template <>
  659. struct OperandTraits<BlockAddress> :
  660. public FixedNumOperandTraits<BlockAddress, 2> {
  661. };
  662. DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
  663. //===----------------------------------------------------------------------===//
  664. /// ConstantExpr - a constant value that is initialized with an expression using
  665. /// other constant values.
  666. ///
  667. /// This class uses the standard Instruction opcodes to define the various
  668. /// constant expressions. The Opcode field for the ConstantExpr class is
  669. /// maintained in the Value::SubclassData field.
  670. class ConstantExpr : public Constant {
  671. friend struct ConstantCreator<ConstantExpr,Type,
  672. std::pair<unsigned, std::vector<Constant*> > >;
  673. friend struct ConvertConstantType<ConstantExpr, Type>;
  674. protected:
  675. ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
  676. : Constant(ty, ConstantExprVal, Ops, NumOps) {
  677. // Operation type (an Instruction opcode) is stored as the SubclassData.
  678. setValueSubclassData(Opcode);
  679. }
  680. public:
  681. // Static methods to construct a ConstantExpr of different kinds. Note that
  682. // these methods may return a object that is not an instance of the
  683. // ConstantExpr class, because they will attempt to fold the constant
  684. // expression into something simpler if possible.
  685. /// getAlignOf constant expr - computes the alignment of a type in a target
  686. /// independent way (Note: the return type is an i64).
  687. static Constant *getAlignOf(Type *Ty);
  688. /// getSizeOf constant expr - computes the (alloc) size of a type (in
  689. /// address-units, not bits) in a target independent way (Note: the return
  690. /// type is an i64).
  691. ///
  692. static Constant *getSizeOf(Type *Ty);
  693. /// getOffsetOf constant expr - computes the offset of a struct field in a
  694. /// target independent way (Note: the return type is an i64).
  695. ///
  696. static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
  697. /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
  698. /// which supports any aggregate type, and any Constant index.
  699. ///
  700. static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
  701. static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
  702. static Constant *getFNeg(Constant *C);
  703. static Constant *getNot(Constant *C);
  704. static Constant *getAdd(Constant *C1, Constant *C2,
  705. bool HasNUW = false, bool HasNSW = false);
  706. static Constant *getFAdd(Constant *C1, Constant *C2);
  707. static Constant *getSub(Constant *C1, Constant *C2,
  708. bool HasNUW = false, bool HasNSW = false);
  709. static Constant *getFSub(Constant *C1, Constant *C2);
  710. static Constant *getMul(Constant *C1, Constant *C2,
  711. bool HasNUW = false, bool HasNSW = false);
  712. static Constant *getFMul(Constant *C1, Constant *C2);
  713. static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
  714. static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
  715. static Constant *getFDiv(Constant *C1, Constant *C2);
  716. static Constant *getURem(Constant *C1, Constant *C2);
  717. static Constant *getSRem(Constant *C1, Constant *C2);
  718. static Constant *getFRem(Constant *C1, Constant *C2);
  719. static Constant *getAnd(Constant *C1, Constant *C2);
  720. static Constant *getOr(Constant *C1, Constant *C2);
  721. static Constant *getXor(Constant *C1, Constant *C2);
  722. static Constant *getShl(Constant *C1, Constant *C2,
  723. bool HasNUW = false, bool HasNSW = false);
  724. static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
  725. static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
  726. static Constant *getTrunc (Constant *C, Type *Ty);
  727. static Constant *getSExt (Constant *C, Type *Ty);
  728. static Constant *getZExt (Constant *C, Type *Ty);
  729. static Constant *getFPTrunc (Constant *C, Type *Ty);
  730. static Constant *getFPExtend(Constant *C, Type *Ty);
  731. static Constant *getUIToFP (Constant *C, Type *Ty);
  732. static Constant *getSIToFP (Constant *C, Type *Ty);
  733. static Constant *getFPToUI (Constant *C, Type *Ty);
  734. static Constant *getFPToSI (Constant *C, Type *Ty);
  735. static Constant *getPtrToInt(Constant *C, Type *Ty);
  736. static Constant *getIntToPtr(Constant *C, Type *Ty);
  737. static Constant *getBitCast (Constant *C, Type *Ty);
  738. static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
  739. static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
  740. static Constant *getNSWAdd(Constant *C1, Constant *C2) {
  741. return getAdd(C1, C2, false, true);
  742. }
  743. static Constant *getNUWAdd(Constant *C1, Constant *C2) {
  744. return getAdd(C1, C2, true, false);
  745. }
  746. static Constant *getNSWSub(Constant *C1, Constant *C2) {
  747. return getSub(C1, C2, false, true);
  748. }
  749. static Constant *getNUWSub(Constant *C1, Constant *C2) {
  750. return getSub(C1, C2, true, false);
  751. }
  752. static Constant *getNSWMul(Constant *C1, Constant *C2) {
  753. return getMul(C1, C2, false, true);
  754. }
  755. static Constant *getNUWMul(Constant *C1, Constant *C2) {
  756. return getMul(C1, C2, true, false);
  757. }
  758. static Constant *getNSWShl(Constant *C1, Constant *C2) {
  759. return getShl(C1, C2, false, true);
  760. }
  761. static Constant *getNUWShl(Constant *C1, Constant *C2) {
  762. return getShl(C1, C2, true, false);
  763. }
  764. static Constant *getExactSDiv(Constant *C1, Constant *C2) {
  765. return getSDiv(C1, C2, true);
  766. }
  767. static Constant *getExactUDiv(Constant *C1, Constant *C2) {
  768. return getUDiv(C1, C2, true);
  769. }
  770. static Constant *getExactAShr(Constant *C1, Constant *C2) {
  771. return getAShr(C1, C2, true);
  772. }
  773. static Constant *getExactLShr(Constant *C1, Constant *C2) {
  774. return getLShr(C1, C2, true);
  775. }
  776. /// getBinOpIdentity - Return the identity for the given binary operation,
  777. /// i.e. a constant C such that X op C = X and C op X = X for every X. It
  778. /// returns null if the operator doesn't have an identity.
  779. static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty);
  780. /// getBinOpAbsorber - Return the absorbing element for the given binary
  781. /// operation, i.e. a constant C such that X op C = C and C op X = C for
  782. /// every X. For example, this returns zero for integer multiplication.
  783. /// It returns null if the operator doesn't have an absorbing element.
  784. static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty);
  785. /// Transparently provide more efficient getOperand methods.
  786. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
  787. // @brief Convenience function for getting one of the casting operations
  788. // using a CastOps opcode.
  789. static Constant *getCast(
  790. unsigned ops, ///< The opcode for the conversion
  791. Constant *C, ///< The constant to be converted
  792. Type *Ty ///< The type to which the constant is converted
  793. );
  794. // @brief Create a ZExt or BitCast cast constant expression
  795. static Constant *getZExtOrBitCast(
  796. Constant *C, ///< The constant to zext or bitcast
  797. Type *Ty ///< The type to zext or bitcast C to
  798. );
  799. // @brief Create a SExt or BitCast cast constant expression
  800. static Constant *getSExtOrBitCast(
  801. Constant *C, ///< The constant to sext or bitcast
  802. Type *Ty ///< The type to sext or bitcast C to
  803. );
  804. // @brief Create a Trunc or BitCast cast constant expression
  805. static Constant *getTruncOrBitCast(
  806. Constant *C, ///< The constant to trunc or bitcast
  807. Type *Ty ///< The type to trunc or bitcast C to
  808. );
  809. /// @brief Create a BitCast or a PtrToInt cast constant expression
  810. static Constant *getPointerCast(
  811. Constant *C, ///< The pointer value to be casted (operand 0)
  812. Type *Ty ///< The type to which cast should be made
  813. );
  814. /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
  815. static Constant *getIntegerCast(
  816. Constant *C, ///< The integer constant to be casted
  817. Type *Ty, ///< The integer type to cast to
  818. bool isSigned ///< Whether C should be treated as signed or not
  819. );
  820. /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
  821. static Constant *getFPCast(
  822. Constant *C, ///< The integer constant to be casted
  823. Type *Ty ///< The integer type to cast to
  824. );
  825. /// @brief Return true if this is a convert constant expression
  826. bool isCast() const;
  827. /// @brief Return true if this is a compare constant expression
  828. bool isCompare() const;
  829. /// @brief Return true if this is an insertvalue or extractvalue expression,
  830. /// and the getIndices() method may be used.
  831. bool hasIndices() const;
  832. /// @brief Return true if this is a getelementptr expression and all
  833. /// the index operands are compile-time known integers within the
  834. /// corresponding notional static array extents. Note that this is
  835. /// not equivalant to, a subset of, or a superset of the "inbounds"
  836. /// property.
  837. bool isGEPWithNoNotionalOverIndexing() const;
  838. /// Select constant expr
  839. ///
  840. static Constant *getSelect(Constant *C, Constant *V1, Constant *V2);
  841. /// get - Return a binary or shift operator constant expression,
  842. /// folding if possible.
  843. ///
  844. static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
  845. unsigned Flags = 0);
  846. /// @brief Return an ICmp or FCmp comparison operator constant expression.
  847. static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
  848. /// get* - Return some common constants without having to
  849. /// specify the full Instruction::OPCODE identifier.
  850. ///
  851. static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
  852. static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
  853. /// Getelementptr form. Value* is only accepted for convenience;
  854. /// all elements must be Constant's.
  855. ///
  856. static Constant *getGetElementPtr(Constant *C,
  857. ArrayRef<Constant *> IdxList,
  858. bool InBounds = false) {
  859. return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(),
  860. IdxList.size()),
  861. InBounds);
  862. }
  863. static Constant *getGetElementPtr(Constant *C,
  864. Constant *Idx,
  865. bool InBounds = false) {
  866. // This form of the function only exists to avoid ambiguous overload
  867. // warnings about whether to convert Idx to ArrayRef<Constant *> or
  868. // ArrayRef<Value *>.
  869. return getGetElementPtr(C, cast<Value>(Idx), InBounds);
  870. }
  871. static Constant *getGetElementPtr(Constant *C,
  872. ArrayRef<Value *> IdxList,
  873. bool InBounds = false);
  874. /// Create an "inbounds" getelementptr. See the documentation for the
  875. /// "inbounds" flag in LangRef.html for details.
  876. static Constant *getInBoundsGetElementPtr(Constant *C,
  877. ArrayRef<Constant *> IdxList) {
  878. return getGetElementPtr(C, IdxList, true);
  879. }
  880. static Constant *getInBoundsGetElementPtr(Constant *C,
  881. Constant *Idx) {
  882. // This form of the function only exists to avoid ambiguous overload
  883. // warnings about whether to convert Idx to ArrayRef<Constant *> or
  884. // ArrayRef<Value *>.
  885. return getGetElementPtr(C, Idx, true);
  886. }
  887. static Constant *getInBoundsGetElementPtr(Constant *C,
  888. ArrayRef<Value *> IdxList) {
  889. return getGetElementPtr(C, IdxList, true);
  890. }
  891. static Constant *getExtractElement(Constant *Vec, Constant *Idx);
  892. static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
  893. static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
  894. static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs);
  895. static Constant *getInsertValue(Constant *Agg, Constant *Val,
  896. ArrayRef<unsigned> Idxs);
  897. /// getOpcode - Return the opcode at the root of this constant expression
  898. unsigned getOpcode() const { return getSubclassDataFromValue(); }
  899. /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
  900. /// not an ICMP or FCMP constant expression.
  901. unsigned getPredicate() const;
  902. /// getIndices - Assert that this is an insertvalue or exactvalue
  903. /// expression and return the list of indices.
  904. ArrayRef<unsigned> getIndices() const;
  905. /// getOpcodeName - Return a string representation for an opcode.
  906. const char *getOpcodeName() const;
  907. /// getWithOperandReplaced - Return a constant expression identical to this
  908. /// one, but with the specified operand set to the specified value.
  909. Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
  910. /// getWithOperands - This returns the current constant expression with the
  911. /// operands replaced with the specified values. The specified array must
  912. /// have the same number of operands as our current one.
  913. Constant *getWithOperands(ArrayRef<Constant*> Ops) const {
  914. return getWithOperands(Ops, getType());
  915. }
  916. /// getWithOperands - This returns the current constant expression with the
  917. /// operands replaced with the specified values and with the specified result
  918. /// type. The specified array must have the same number of operands as our
  919. /// current one.
  920. Constant *getWithOperands(ArrayRef<Constant*> Ops, Type *Ty) const;
  921. /// getAsInstruction - Returns an Instruction which implements the same operation
  922. /// as this ConstantExpr. The instruction is not linked to any basic block.
  923. ///
  924. /// A better approach to this could be to have a constructor for Instruction
  925. /// which would take a ConstantExpr parameter, but that would have spread
  926. /// implementation details of ConstantExpr outside of Constants.cpp, which
  927. /// would make it harder to remove ConstantExprs altogether.
  928. Instruction *getAsInstruction();
  929. virtual void destroyConstant();
  930. virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
  931. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  932. static inline bool classof(const Value *V) {
  933. return V->getValueID() == ConstantExprVal;
  934. }
  935. private:
  936. // Shadow Value::setValueSubclassData with a private forwarding method so that
  937. // subclasses cannot accidentally use it.
  938. void setValueSubclassData(unsigned short D) {
  939. Value::setValueSubclassData(D);
  940. }
  941. };
  942. template <>
  943. struct OperandTraits<ConstantExpr> :
  944. public VariadicOperandTraits<ConstantExpr, 1> {
  945. };
  946. DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
  947. //===----------------------------------------------------------------------===//
  948. /// UndefValue - 'undef' values are things that do not have specified contents.
  949. /// These are used for a variety of purposes, including global variable
  950. /// initializers and operands to instructions. 'undef' values can occur with
  951. /// any first-class type.
  952. ///
  953. /// Undef values aren't exactly constants; if they have multiple uses, they
  954. /// can appear to have different bit patterns at each use. See
  955. /// LangRef.html#undefvalues for details.
  956. ///
  957. class UndefValue : public Constant {
  958. void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
  959. UndefValue(const UndefValue &) LLVM_DELETED_FUNCTION;
  960. protected:
  961. explicit UndefValue(Type *T) : Constant(T, UndefValueVal, 0, 0) {}
  962. protected:
  963. // allocate space for exactly zero operands
  964. void *operator new(size_t s) {
  965. return User::operator new(s, 0);
  966. }
  967. public:
  968. /// get() - Static factory methods - Return an 'undef' object of the specified
  969. /// type.
  970. ///
  971. static UndefValue *get(Type *T);
  972. /// getSequentialElement - If this Undef has array or vector type, return a
  973. /// undef with the right element type.
  974. UndefValue *getSequentialElement() const;
  975. /// getStructElement - If this undef has struct type, return a undef with the
  976. /// right element type for the specified element.
  977. UndefValue *getStructElement(unsigned Elt) const;
  978. /// getElementValue - Return an undef of the right value for the specified GEP
  979. /// index.
  980. UndefValue *getElementValue(Constant *C) const;
  981. /// getElementValue - Return an undef of the right value for the specified GEP
  982. /// index.
  983. UndefValue *getElementValue(unsigned Idx) const;
  984. virtual void destroyConstant();
  985. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  986. static bool classof(const Value *V) {
  987. return V->getValueID() == UndefValueVal;
  988. }
  989. };
  990. } // End llvm namespace
  991. #endif