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