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