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.

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