LLVM  13.0.0git
Constants.h
Go to the documentation of this file.
1 //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// @file
10 /// This file contains the declarations for the subclasses of Constant,
11 /// which represent the different flavors of constant values that live in LLVM.
12 /// Note that Constants are immutable (once created they never change) and are
13 /// fully shared by structural equivalence. This means that two structurally
14 /// equivalent constants will always have the same address. Constants are
15 /// created on demand as needed and never deleted: thus clients don't have to
16 /// worry about the lifetime of the objects.
17 //
18 //===----------------------------------------------------------------------===//
19 
20 #ifndef LLVM_IR_CONSTANTS_H
21 #define LLVM_IR_CONSTANTS_H
22 
23 #include "llvm/ADT/APFloat.h"
24 #include "llvm/ADT/APInt.h"
25 #include "llvm/ADT/ArrayRef.h"
26 #include "llvm/ADT/None.h"
27 #include "llvm/ADT/Optional.h"
28 #include "llvm/ADT/STLExtras.h"
29 #include "llvm/ADT/StringRef.h"
30 #include "llvm/IR/Constant.h"
31 #include "llvm/IR/DerivedTypes.h"
32 #include "llvm/IR/OperandTraits.h"
33 #include "llvm/IR/User.h"
34 #include "llvm/IR/Value.h"
35 #include "llvm/Support/Casting.h"
36 #include "llvm/Support/Compiler.h"
38 #include <cassert>
39 #include <cstddef>
40 #include <cstdint>
41 
42 namespace llvm {
43 
44 template <class ConstantClass> struct ConstantAggrKeyType;
45 
46 /// Base class for constants with no operands.
47 ///
48 /// These constants have no operands; they represent their data directly.
49 /// Since they can be in use by unrelated modules (and are never based on
50 /// GlobalValues), it never makes sense to RAUW them.
51 class ConstantData : public Constant {
52  friend class Constant;
53 
54  Value *handleOperandChangeImpl(Value *From, Value *To) {
55  llvm_unreachable("Constant data does not have operands!");
56  }
57 
58 protected:
59  explicit ConstantData(Type *Ty, ValueTy VT) : Constant(Ty, VT, nullptr, 0) {}
60 
61  void *operator new(size_t s) { return User::operator new(s, 0); }
62 
63 public:
64  ConstantData(const ConstantData &) = delete;
65 
66  /// Methods to support type inquiry through isa, cast, and dyn_cast.
67  static bool classof(const Value *V) {
68  return V->getValueID() >= ConstantDataFirstVal &&
69  V->getValueID() <= ConstantDataLastVal;
70  }
71 };
72 
73 //===----------------------------------------------------------------------===//
74 /// This is the shared class of boolean and integer constants. This class
75 /// represents both boolean and integral constants.
76 /// Class for constant integers.
77 class ConstantInt final : public ConstantData {
78  friend class Constant;
79 
80  APInt Val;
81 
82  ConstantInt(IntegerType *Ty, const APInt &V);
83 
84  void destroyConstantImpl();
85 
86 public:
87  ConstantInt(const ConstantInt &) = delete;
88 
91  static ConstantInt *getBool(LLVMContext &Context, bool V);
92  static Constant *getTrue(Type *Ty);
93  static Constant *getFalse(Type *Ty);
94  static Constant *getBool(Type *Ty, bool V);
95 
96  /// If Ty is a vector type, return a Constant with a splat of the given
97  /// value. Otherwise return a ConstantInt for the given value.
98  static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false);
99 
100  /// Return a ConstantInt with the specified integer value for the specified
101  /// type. If the type is wider than 64 bits, the value will be zero-extended
102  /// to fit the type, unless IsSigned is true, in which case the value will
103  /// be interpreted as a 64-bit signed integer and sign-extended to fit
104  /// the type.
105  /// Get a ConstantInt for a specific value.
106  static ConstantInt *get(IntegerType *Ty, uint64_t V, bool IsSigned = false);
107 
108  /// Return a ConstantInt with the specified value for the specified type. The
109  /// value V will be canonicalized to a an unsigned APInt. Accessing it with
110  /// either getSExtValue() or getZExtValue() will yield a correctly sized and
111  /// signed value for the type Ty.
112  /// Get a ConstantInt for a specific signed value.
113  static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
114  static Constant *getSigned(Type *Ty, int64_t V);
115 
116  /// Return a ConstantInt with the specified value and an implied Type. The
117  /// type is the integer type that corresponds to the bit width of the value.
118  static ConstantInt *get(LLVMContext &Context, const APInt &V);
119 
120  /// Return a ConstantInt constructed from the string strStart with the given
121  /// radix.
122  static ConstantInt *get(IntegerType *Ty, StringRef Str, uint8_t Radix);
123 
124  /// If Ty is a vector type, return a Constant with a splat of the given
125  /// value. Otherwise return a ConstantInt for the given value.
126  static Constant *get(Type *Ty, const APInt &V);
127 
128  /// Return the constant as an APInt value reference. This allows clients to
129  /// obtain a full-precision copy of the value.
130  /// Return the constant's value.
131  inline const APInt &getValue() const { return Val; }
132 
133  /// getBitWidth - Return the bitwidth of this constant.
134  unsigned getBitWidth() const { return Val.getBitWidth(); }
135 
136  /// Return the constant as a 64-bit unsigned integer value after it
137  /// has been zero extended as appropriate for the type of this constant. Note
138  /// that this method can assert if the value does not fit in 64 bits.
139  /// Return the zero extended value.
140  inline uint64_t getZExtValue() const { return Val.getZExtValue(); }
141 
142  /// Return the constant as a 64-bit integer value after it has been sign
143  /// extended as appropriate for the type of this constant. Note that
144  /// this method can assert if the value does not fit in 64 bits.
145  /// Return the sign extended value.
146  inline int64_t getSExtValue() const { return Val.getSExtValue(); }
147 
148  /// Return the constant as an llvm::MaybeAlign.
149  /// Note that this method can assert if the value does not fit in 64 bits or
150  /// is not a power of two.
152  return MaybeAlign(getZExtValue());
153  }
154 
155  /// Return the constant as an llvm::Align, interpreting `0` as `Align(1)`.
156  /// Note that this method can assert if the value does not fit in 64 bits or
157  /// is not a power of two.
158  inline Align getAlignValue() const {
159  return getMaybeAlignValue().valueOrOne();
160  }
161 
162  /// A helper method that can be used to determine if the constant contained
163  /// within is equal to a constant. This only works for very small values,
164  /// because this is all that can be represented with all types.
165  /// Determine if this constant's value is same as an unsigned char.
166  bool equalsInt(uint64_t V) const { return Val == V; }
167 
168  /// getType - Specialize the getType() method to always return an IntegerType,
169  /// which reduces the amount of casting needed in parts of the compiler.
170  ///
171  inline IntegerType *getType() const {
172  return cast<IntegerType>(Value::getType());
173  }
174 
175  /// This static method returns true if the type Ty is big enough to
176  /// represent the value V. This can be used to avoid having the get method
177  /// assert when V is larger than Ty can represent. Note that there are two
178  /// versions of this method, one for unsigned and one for signed integers.
179  /// Although ConstantInt canonicalizes everything to an unsigned integer,
180  /// the signed version avoids callers having to convert a signed quantity
181  /// to the appropriate unsigned type before calling the method.
182  /// @returns true if V is a valid value for type Ty
183  /// Determine if the value is in range for the given type.
184  static bool isValueValidForType(Type *Ty, uint64_t V);
185  static bool isValueValidForType(Type *Ty, int64_t V);
186 
187  bool isNegative() const { return Val.isNegative(); }
188 
189  /// This is just a convenience method to make client code smaller for a
190  /// common code. It also correctly performs the comparison without the
191  /// potential for an assertion from getZExtValue().
192  bool isZero() const { return Val.isNullValue(); }
193 
194  /// This is just a convenience method to make client code smaller for a
195  /// common case. It also correctly performs the comparison without the
196  /// potential for an assertion from getZExtValue().
197  /// Determine if the value is one.
198  bool isOne() const { return Val.isOneValue(); }
199 
200  /// This function will return true iff every bit in this constant is set
201  /// to true.
202  /// @returns true iff this constant's bits are all set to true.
203  /// Determine if the value is all ones.
204  bool isMinusOne() const { return Val.isAllOnesValue(); }
205 
206  /// This function will return true iff this constant represents the largest
207  /// value that may be represented by the constant's type.
208  /// @returns true iff this is the largest value that may be represented
209  /// by this type.
210  /// Determine if the value is maximal.
211  bool isMaxValue(bool IsSigned) const {
212  if (IsSigned)
213  return Val.isMaxSignedValue();
214  else
215  return Val.isMaxValue();
216  }
217 
218  /// This function will return true iff this constant represents the smallest
219  /// value that may be represented by this constant's type.
220  /// @returns true if this is the smallest value that may be represented by
221  /// this type.
222  /// Determine if the value is minimal.
223  bool isMinValue(bool IsSigned) const {
224  if (IsSigned)
225  return Val.isMinSignedValue();
226  else
227  return Val.isMinValue();
228  }
229 
230  /// This function will return true iff this constant represents a value with
231  /// active bits bigger than 64 bits or a value greater than the given uint64_t
232  /// value.
233  /// @returns true iff this constant is greater or equal to the given number.
234  /// Determine if the value is greater or equal to the given number.
235  bool uge(uint64_t Num) const { return Val.uge(Num); }
236 
237  /// getLimitedValue - If the value is smaller than the specified limit,
238  /// return it, otherwise return the limit value. This causes the value
239  /// to saturate to the limit.
240  /// @returns the min of the value of the constant and the specified value
241  /// Get the constant's value with a saturation limit
242  uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
243  return Val.getLimitedValue(Limit);
244  }
245 
246  /// Methods to support type inquiry through isa, cast, and dyn_cast.
247  static bool classof(const Value *V) {
248  return V->getValueID() == ConstantIntVal;
249  }
250 };
251 
252 //===----------------------------------------------------------------------===//
253 /// ConstantFP - Floating Point Values [float, double]
254 ///
255 class ConstantFP final : public ConstantData {
256  friend class Constant;
257 
258  APFloat Val;
259 
260  ConstantFP(Type *Ty, const APFloat &V);
261 
262  void destroyConstantImpl();
263 
264 public:
265  ConstantFP(const ConstantFP &) = delete;
266 
267  /// Floating point negation must be implemented with f(x) = -0.0 - x. This
268  /// method returns the negative zero constant for floating point or vector
269  /// floating point types; for all other types, it returns the null value.
271 
272  /// This returns a ConstantFP, or a vector containing a splat of a ConstantFP,
273  /// for the specified value in the specified type. This should only be used
274  /// for simple constant values like 2.0/1.0 etc, that are known-valid both as
275  /// host double and as the target format.
276  static Constant *get(Type *Ty, double V);
277 
278  /// If Ty is a vector type, return a Constant with a splat of the given
279  /// value. Otherwise return a ConstantFP for the given value.
280  static Constant *get(Type *Ty, const APFloat &V);
281 
282  static Constant *get(Type *Ty, StringRef Str);
283  static ConstantFP *get(LLVMContext &Context, const APFloat &V);
284  static Constant *getNaN(Type *Ty, bool Negative = false,
285  uint64_t Payload = 0);
286  static Constant *getQNaN(Type *Ty, bool Negative = false,
287  APInt *Payload = nullptr);
288  static Constant *getSNaN(Type *Ty, bool Negative = false,
289  APInt *Payload = nullptr);
290  static Constant *getNegativeZero(Type *Ty);
291  static Constant *getInfinity(Type *Ty, bool Negative = false);
292 
293  /// Return true if Ty is big enough to represent V.
294  static bool isValueValidForType(Type *Ty, const APFloat &V);
295  inline const APFloat &getValueAPF() const { return Val; }
296  inline const APFloat &getValue() const { return Val; }
297 
298  /// Return true if the value is positive or negative zero.
299  bool isZero() const { return Val.isZero(); }
300 
301  /// Return true if the sign bit is set.
302  bool isNegative() const { return Val.isNegative(); }
303 
304  /// Return true if the value is infinity
305  bool isInfinity() const { return Val.isInfinity(); }
306 
307  /// Return true if the value is a NaN.
308  bool isNaN() const { return Val.isNaN(); }
309 
310  /// We don't rely on operator== working on double values, as it returns true
311  /// for things that are clearly not equal, like -0.0 and 0.0.
312  /// As such, this method can be used to do an exact bit-for-bit comparison of
313  /// two floating point values. The version with a double operand is retained
314  /// because it's so convenient to write isExactlyValue(2.0), but please use
315  /// it only for simple constants.
316  bool isExactlyValue(const APFloat &V) const;
317 
318  bool isExactlyValue(double V) const {
319  bool ignored;
320  APFloat FV(V);
322  return isExactlyValue(FV);
323  }
324 
325  /// Methods for support type inquiry through isa, cast, and dyn_cast:
326  static bool classof(const Value *V) {
327  return V->getValueID() == ConstantFPVal;
328  }
329 };
330 
331 //===----------------------------------------------------------------------===//
332 /// All zero aggregate value
333 ///
334 class ConstantAggregateZero final : public ConstantData {
335  friend class Constant;
336 
337  explicit ConstantAggregateZero(Type *Ty)
338  : ConstantData(Ty, ConstantAggregateZeroVal) {}
339 
340  void destroyConstantImpl();
341 
342 public:
344 
345  static ConstantAggregateZero *get(Type *Ty);
346 
347  /// If this CAZ has array or vector type, return a zero with the right element
348  /// type.
350 
351  /// If this CAZ has struct type, return a zero with the right element type for
352  /// the specified element.
353  Constant *getStructElement(unsigned Elt) const;
354 
355  /// Return a zero of the right value for the specified GEP index if we can,
356  /// otherwise return null (e.g. if C is a ConstantExpr).
358 
359  /// Return a zero of the right value for the specified GEP index.
360  Constant *getElementValue(unsigned Idx) const;
361 
362  /// Return the number of elements in the array, vector, or struct.
364 
365  /// Methods for support type inquiry through isa, cast, and dyn_cast:
366  ///
367  static bool classof(const Value *V) {
368  return V->getValueID() == ConstantAggregateZeroVal;
369  }
370 };
371 
372 /// Base class for aggregate constants (with operands).
373 ///
374 /// These constants are aggregates of other constants, which are stored as
375 /// operands.
376 ///
377 /// Subclasses are \a ConstantStruct, \a ConstantArray, and \a
378 /// ConstantVector.
379 ///
380 /// \note Some subclasses of \a ConstantData are semantically aggregates --
381 /// such as \a ConstantDataArray -- but are not subclasses of this because they
382 /// use operands.
383 class ConstantAggregate : public Constant {
384 protected:
386 
387 public:
388  /// Transparently provide more efficient getOperand methods.
390 
391  /// Methods for support type inquiry through isa, cast, and dyn_cast:
392  static bool classof(const Value *V) {
393  return V->getValueID() >= ConstantAggregateFirstVal &&
394  V->getValueID() <= ConstantAggregateLastVal;
395  }
396 };
397 
398 template <>
400  : public VariadicOperandTraits<ConstantAggregate> {};
401 
403 
404 //===----------------------------------------------------------------------===//
405 /// ConstantArray - Constant Array Declarations
406 ///
407 class ConstantArray final : public ConstantAggregate {
409  friend class Constant;
410 
412 
413  void destroyConstantImpl();
414  Value *handleOperandChangeImpl(Value *From, Value *To);
415 
416 public:
417  // ConstantArray accessors
419 
420 private:
422 
423 public:
424  /// Specialize the getType() method to always return an ArrayType,
425  /// which reduces the amount of casting needed in parts of the compiler.
426  inline ArrayType *getType() const {
427  return cast<ArrayType>(Value::getType());
428  }
429 
430  /// Methods for support type inquiry through isa, cast, and dyn_cast:
431  static bool classof(const Value *V) {
432  return V->getValueID() == ConstantArrayVal;
433  }
434 };
435 
436 //===----------------------------------------------------------------------===//
437 // Constant Struct Declarations
438 //
439 class ConstantStruct final : public ConstantAggregate {
441  friend class Constant;
442 
444 
445  void destroyConstantImpl();
446  Value *handleOperandChangeImpl(Value *From, Value *To);
447 
448 public:
449  // ConstantStruct accessors
451 
452  template <typename... Csts>
453  static std::enable_if_t<are_base_of<Constant, Csts...>::value, Constant *>
454  get(StructType *T, Csts *...Vs) {
455  SmallVector<Constant *, 8> Values({Vs...});
456  return get(T, Values);
457  }
458 
459  /// Return an anonymous struct that has the specified elements.
460  /// If the struct is possibly empty, then you must specify a context.
461  static Constant *getAnon(ArrayRef<Constant *> V, bool Packed = false) {
462  return get(getTypeForElements(V, Packed), V);
463  }
465  bool Packed = false) {
466  return get(getTypeForElements(Ctx, V, Packed), V);
467  }
468 
469  /// Return an anonymous struct type to use for a constant with the specified
470  /// set of elements. The list must not be empty.
472  bool Packed = false);
473  /// This version of the method allows an empty list.
476  bool Packed = false);
477 
478  /// Specialization - reduce amount of casting.
479  inline StructType *getType() const {
480  return cast<StructType>(Value::getType());
481  }
482 
483  /// Methods for support type inquiry through isa, cast, and dyn_cast:
484  static bool classof(const Value *V) {
485  return V->getValueID() == ConstantStructVal;
486  }
487 };
488 
489 //===----------------------------------------------------------------------===//
490 /// Constant Vector Declarations
491 ///
492 class ConstantVector final : public ConstantAggregate {
494  friend class Constant;
495 
497 
498  void destroyConstantImpl();
499  Value *handleOperandChangeImpl(Value *From, Value *To);
500 
501 public:
502  // ConstantVector accessors
503  static Constant *get(ArrayRef<Constant *> V);
504 
505 private:
507 
508 public:
509  /// Return a ConstantVector with the specified constant in each element.
510  /// Note that this might not return an instance of ConstantVector
511  static Constant *getSplat(ElementCount EC, Constant *Elt);
512 
513  /// Specialize the getType() method to always return a FixedVectorType,
514  /// which reduces the amount of casting needed in parts of the compiler.
515  inline FixedVectorType *getType() const {
516  return cast<FixedVectorType>(Value::getType());
517  }
518 
519  /// If all elements of the vector constant have the same value, return that
520  /// value. Otherwise, return nullptr. Ignore undefined elements by setting
521  /// AllowUndefs to true.
522  Constant *getSplatValue(bool AllowUndefs = false) const;
523 
524  /// Methods for support type inquiry through isa, cast, and dyn_cast:
525  static bool classof(const Value *V) {
526  return V->getValueID() == ConstantVectorVal;
527  }
528 };
529 
530 //===----------------------------------------------------------------------===//
531 /// A constant pointer value that points to null
532 ///
533 class ConstantPointerNull final : public ConstantData {
534  friend class Constant;
535 
537  : ConstantData(T, Value::ConstantPointerNullVal) {}
538 
539  void destroyConstantImpl();
540 
541 public:
542  ConstantPointerNull(const ConstantPointerNull &) = delete;
543 
544  /// Static factory methods - Return objects of the specified value
546 
547  /// Specialize the getType() method to always return an PointerType,
548  /// which reduces the amount of casting needed in parts of the compiler.
549  inline PointerType *getType() const {
550  return cast<PointerType>(Value::getType());
551  }
552 
553  /// Methods for support type inquiry through isa, cast, and dyn_cast:
554  static bool classof(const Value *V) {
555  return V->getValueID() == ConstantPointerNullVal;
556  }
557 };
558 
559 //===----------------------------------------------------------------------===//
560 /// ConstantDataSequential - A vector or array constant whose element type is a
561 /// simple 1/2/4/8-byte integer or half/bfloat/float/double, and whose elements
562 /// are just simple data values (i.e. ConstantInt/ConstantFP). This Constant
563 /// node has no operands because it stores all of the elements of the constant
564 /// as densely packed data, instead of as Value*'s.
565 ///
566 /// This is the common base class of ConstantDataArray and ConstantDataVector.
567 ///
569  friend class LLVMContextImpl;
570  friend class Constant;
571 
572  /// A pointer to the bytes underlying this constant (which is owned by the
573  /// uniquing StringMap).
574  const char *DataElements;
575 
576  /// This forms a link list of ConstantDataSequential nodes that have
577  /// the same value but different type. For example, 0,0,0,1 could be a 4
578  /// element array of i8, or a 1-element array of i32. They'll both end up in
579  /// the same StringMap bucket, linked up.
580  std::unique_ptr<ConstantDataSequential> Next;
581 
582  void destroyConstantImpl();
583 
584 protected:
585  explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
586  : ConstantData(ty, VT), DataElements(Data) {}
587 
588  static Constant *getImpl(StringRef Bytes, Type *Ty);
589 
590 public:
592 
593  /// Return true if a ConstantDataSequential can be formed with a vector or
594  /// array of the specified element type.
595  /// ConstantDataArray only works with normal float and int types that are
596  /// stored densely in memory, not with things like i42 or x86_f80.
597  static bool isElementTypeCompatible(Type *Ty);
598 
599  /// If this is a sequential container of integers (of any size), return the
600  /// specified element in the low bits of a uint64_t.
601  uint64_t getElementAsInteger(unsigned i) const;
602 
603  /// If this is a sequential container of integers (of any size), return the
604  /// specified element as an APInt.
605  APInt getElementAsAPInt(unsigned i) const;
606 
607  /// If this is a sequential container of floating point type, return the
608  /// specified element as an APFloat.
609  APFloat getElementAsAPFloat(unsigned i) const;
610 
611  /// If this is an sequential container of floats, return the specified element
612  /// as a float.
613  float getElementAsFloat(unsigned i) const;
614 
615  /// If this is an sequential container of doubles, return the specified
616  /// element as a double.
617  double getElementAsDouble(unsigned i) const;
618 
619  /// Return a Constant for a specified index's element.
620  /// Note that this has to compute a new constant to return, so it isn't as
621  /// efficient as getElementAsInteger/Float/Double.
622  Constant *getElementAsConstant(unsigned i) const;
623 
624  /// Return the element type of the array/vector.
625  Type *getElementType() const;
626 
627  /// Return the number of elements in the array or vector.
628  unsigned getNumElements() const;
629 
630  /// Return the size (in bytes) of each element in the array/vector.
631  /// The size of the elements is known to be a multiple of one byte.
632  uint64_t getElementByteSize() const;
633 
634  /// This method returns true if this is an array of \p CharSize integers.
635  bool isString(unsigned CharSize = 8) const;
636 
637  /// This method returns true if the array "isString", ends with a null byte,
638  /// and does not contains any other null bytes.
639  bool isCString() const;
640 
641  /// If this array is isString(), then this method returns the array as a
642  /// StringRef. Otherwise, it asserts out.
644  assert(isString() && "Not a string");
645  return getRawDataValues();
646  }
647 
648  /// If this array is isCString(), then this method returns the array (without
649  /// the trailing null byte) as a StringRef. Otherwise, it asserts out.
651  assert(isCString() && "Isn't a C string");
652  StringRef Str = getAsString();
653  return Str.substr(0, Str.size() - 1);
654  }
655 
656  /// Return the raw, underlying, bytes of this data. Note that this is an
657  /// extremely tricky thing to work with, as it exposes the host endianness of
658  /// the data elements.
659  StringRef getRawDataValues() const;
660 
661  /// Methods for support type inquiry through isa, cast, and dyn_cast:
662  static bool classof(const Value *V) {
663  return V->getValueID() == ConstantDataArrayVal ||
664  V->getValueID() == ConstantDataVectorVal;
665  }
666 
667 private:
668  const char *getElementPointer(unsigned Elt) const;
669 };
670 
671 //===----------------------------------------------------------------------===//
672 /// An array constant whose element type is a simple 1/2/4/8-byte integer or
673 /// float/double, and whose elements are just simple data values
674 /// (i.e. ConstantInt/ConstantFP). This Constant node has no operands because it
675 /// stores all of the elements of the constant as densely packed data, instead
676 /// of as Value*'s.
679 
680  explicit ConstantDataArray(Type *ty, const char *Data)
681  : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
682 
683 public:
684  ConstantDataArray(const ConstantDataArray &) = delete;
685 
686  /// get() constructor - Return a constant with array type with an element
687  /// count and element type matching the ArrayRef passed in. Note that this
688  /// can return a ConstantAggregateZero object.
689  template <typename ElementTy>
691  const char *Data = reinterpret_cast<const char *>(Elts.data());
692  return getRaw(StringRef(Data, Elts.size() * sizeof(ElementTy)), Elts.size(),
693  Type::getScalarTy<ElementTy>(Context));
694  }
695 
696  /// get() constructor - ArrayTy needs to be compatible with
697  /// ArrayRef<ElementTy>. Calls get(LLVMContext, ArrayRef<ElementTy>).
698  template <typename ArrayTy>
699  static Constant *get(LLVMContext &Context, ArrayTy &Elts) {
701  }
702 
703  /// getRaw() constructor - Return a constant with array type with an element
704  /// count and element type matching the NumElements and ElementTy parameters
705  /// passed in. Note that this can return a ConstantAggregateZero object.
706  /// ElementTy must be one of i8/i16/i32/i64/half/bfloat/float/double. Data is
707  /// the buffer containing the elements. Be careful to make sure Data uses the
708  /// right endianness, the buffer will be used as-is.
709  static Constant *getRaw(StringRef Data, uint64_t NumElements,
710  Type *ElementTy) {
711  Type *Ty = ArrayType::get(ElementTy, NumElements);
712  return getImpl(Data, Ty);
713  }
714 
715  /// getFP() constructors - Return a constant of array type with a float
716  /// element type taken from argument `ElementType', and count taken from
717  /// argument `Elts'. The amount of bits of the contained type must match the
718  /// number of bits of the type contained in the passed in ArrayRef.
719  /// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note
720  /// that this can return a ConstantAggregateZero object.
721  static Constant *getFP(Type *ElementType, ArrayRef<uint16_t> Elts);
722  static Constant *getFP(Type *ElementType, ArrayRef<uint32_t> Elts);
723  static Constant *getFP(Type *ElementType, ArrayRef<uint64_t> Elts);
724 
725  /// This method constructs a CDS and initializes it with a text string.
726  /// The default behavior (AddNull==true) causes a null terminator to
727  /// be placed at the end of the array (increasing the length of the string by
728  /// one more than the StringRef would normally indicate. Pass AddNull=false
729  /// to disable this behavior.
730  static Constant *getString(LLVMContext &Context, StringRef Initializer,
731  bool AddNull = true);
732 
733  /// Specialize the getType() method to always return an ArrayType,
734  /// which reduces the amount of casting needed in parts of the compiler.
735  inline ArrayType *getType() const {
736  return cast<ArrayType>(Value::getType());
737  }
738 
739  /// Methods for support type inquiry through isa, cast, and dyn_cast:
740  static bool classof(const Value *V) {
741  return V->getValueID() == ConstantDataArrayVal;
742  }
743 };
744 
745 //===----------------------------------------------------------------------===//
746 /// A vector constant whose element type is a simple 1/2/4/8-byte integer or
747 /// float/double, and whose elements are just simple data values
748 /// (i.e. ConstantInt/ConstantFP). This Constant node has no operands because it
749 /// stores all of the elements of the constant as densely packed data, instead
750 /// of as Value*'s.
753 
754  explicit ConstantDataVector(Type *ty, const char *Data)
755  : ConstantDataSequential(ty, ConstantDataVectorVal, Data),
756  IsSplatSet(false) {}
757  // Cache whether or not the constant is a splat.
758  mutable bool IsSplatSet : 1;
759  mutable bool IsSplat : 1;
760  bool isSplatData() const;
761 
762 public:
763  ConstantDataVector(const ConstantDataVector &) = delete;
764 
765  /// get() constructors - Return a constant with vector type with an element
766  /// count and element type matching the ArrayRef passed in. Note that this
767  /// can return a ConstantAggregateZero object.
774 
775  /// getRaw() constructor - Return a constant with vector type with an element
776  /// count and element type matching the NumElements and ElementTy parameters
777  /// passed in. Note that this can return a ConstantAggregateZero object.
778  /// ElementTy must be one of i8/i16/i32/i64/half/bfloat/float/double. Data is
779  /// the buffer containing the elements. Be careful to make sure Data uses the
780  /// right endianness, the buffer will be used as-is.
781  static Constant *getRaw(StringRef Data, uint64_t NumElements,
782  Type *ElementTy) {
783  Type *Ty = VectorType::get(ElementTy, ElementCount::getFixed(NumElements));
784  return getImpl(Data, Ty);
785  }
786 
787  /// getFP() constructors - Return a constant of vector type with a float
788  /// element type taken from argument `ElementType', and count taken from
789  /// argument `Elts'. The amount of bits of the contained type must match the
790  /// number of bits of the type contained in the passed in ArrayRef.
791  /// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note
792  /// that this can return a ConstantAggregateZero object.
793  static Constant *getFP(Type *ElementType, ArrayRef<uint16_t> Elts);
794  static Constant *getFP(Type *ElementType, ArrayRef<uint32_t> Elts);
795  static Constant *getFP(Type *ElementType, ArrayRef<uint64_t> Elts);
796 
797  /// Return a ConstantVector with the specified constant in each element.
798  /// The specified constant has to be a of a compatible type (i8/i16/
799  /// i32/i64/half/bfloat/float/double) and must be a ConstantFP or ConstantInt.
800  static Constant *getSplat(unsigned NumElts, Constant *Elt);
801 
802  /// Returns true if this is a splat constant, meaning that all elements have
803  /// the same value.
804  bool isSplat() const;
805 
806  /// If this is a splat constant, meaning that all of the elements have the
807  /// same value, return that value. Otherwise return NULL.
808  Constant *getSplatValue() const;
809 
810  /// Specialize the getType() method to always return a FixedVectorType,
811  /// which reduces the amount of casting needed in parts of the compiler.
812  inline FixedVectorType *getType() const {
813  return cast<FixedVectorType>(Value::getType());
814  }
815 
816  /// Methods for support type inquiry through isa, cast, and dyn_cast:
817  static bool classof(const Value *V) {
818  return V->getValueID() == ConstantDataVectorVal;
819  }
820 };
821 
822 //===----------------------------------------------------------------------===//
823 /// A constant token which is empty
824 ///
825 class ConstantTokenNone final : public ConstantData {
826  friend class Constant;
827 
829  : ConstantData(Type::getTokenTy(Context), ConstantTokenNoneVal) {}
830 
831  void destroyConstantImpl();
832 
833 public:
834  ConstantTokenNone(const ConstantTokenNone &) = delete;
835 
836  /// Return the ConstantTokenNone.
838 
839  /// Methods to support type inquiry through isa, cast, and dyn_cast.
840  static bool classof(const Value *V) {
841  return V->getValueID() == ConstantTokenNoneVal;
842  }
843 };
844 
845 /// The address of a basic block.
846 ///
847 class BlockAddress final : public Constant {
848  friend class Constant;
849 
851 
852  void *operator new(size_t s) { return User::operator new(s, 2); }
853 
854  void destroyConstantImpl();
855  Value *handleOperandChangeImpl(Value *From, Value *To);
856 
857 public:
858  /// Return a BlockAddress for the specified function and basic block.
859  static BlockAddress *get(Function *F, BasicBlock *BB);
860 
861  /// Return a BlockAddress for the specified basic block. The basic
862  /// block must be embedded into a function.
863  static BlockAddress *get(BasicBlock *BB);
864 
865  /// Lookup an existing \c BlockAddress constant for the given BasicBlock.
866  ///
867  /// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
868  static BlockAddress *lookup(const BasicBlock *BB);
869 
870  /// Transparently provide more efficient getOperand methods.
872 
873  Function *getFunction() const { return (Function *)Op<0>().get(); }
874  BasicBlock *getBasicBlock() const { return (BasicBlock *)Op<1>().get(); }
875 
876  /// Methods for support type inquiry through isa, cast, and dyn_cast:
877  static bool classof(const Value *V) {
878  return V->getValueID() == BlockAddressVal;
879  }
880 };
881 
882 template <>
884  : public FixedNumOperandTraits<BlockAddress, 2> {};
885 
887 
888 /// Wrapper for a function that represents a value that
889 /// functionally represents the original function. This can be a function,
890 /// global alias to a function, or an ifunc.
891 class DSOLocalEquivalent final : public Constant {
892  friend class Constant;
893 
895 
896  void *operator new(size_t s) { return User::operator new(s, 1); }
897 
898  void destroyConstantImpl();
899  Value *handleOperandChangeImpl(Value *From, Value *To);
900 
901 public:
902  /// Return a DSOLocalEquivalent for the specified global value.
903  static DSOLocalEquivalent *get(GlobalValue *GV);
904 
905  /// Transparently provide more efficient getOperand methods.
907 
909  return cast<GlobalValue>(Op<0>().get());
910  }
911 
912  /// Methods for support type inquiry through isa, cast, and dyn_cast:
913  static bool classof(const Value *V) {
914  return V->getValueID() == DSOLocalEquivalentVal;
915  }
916 };
917 
918 template <>
920  : public FixedNumOperandTraits<DSOLocalEquivalent, 1> {};
921 
923 
924 //===----------------------------------------------------------------------===//
925 /// A constant value that is initialized with an expression using
926 /// other constant values.
927 ///
928 /// This class uses the standard Instruction opcodes to define the various
929 /// constant expressions. The Opcode field for the ConstantExpr class is
930 /// maintained in the Value::SubclassData field.
931 class ConstantExpr : public Constant {
932  friend struct ConstantExprKeyType;
933  friend class Constant;
934 
935  void destroyConstantImpl();
936  Value *handleOperandChangeImpl(Value *From, Value *To);
937 
938 protected:
939  ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
940  : Constant(ty, ConstantExprVal, Ops, NumOps) {
941  // Operation type (an Instruction opcode) is stored as the SubclassData.
942  setValueSubclassData(Opcode);
943  }
944 
945  ~ConstantExpr() = default;
946 
947 public:
948  // Static methods to construct a ConstantExpr of different kinds. Note that
949  // these methods may return a object that is not an instance of the
950  // ConstantExpr class, because they will attempt to fold the constant
951  // expression into something simpler if possible.
952 
953  /// getAlignOf constant expr - computes the alignment of a type in a target
954  /// independent way (Note: the return type is an i64).
955  static Constant *getAlignOf(Type *Ty);
956 
957  /// getSizeOf constant expr - computes the (alloc) size of a type (in
958  /// address-units, not bits) in a target independent way (Note: the return
959  /// type is an i64).
960  ///
961  static Constant *getSizeOf(Type *Ty);
962 
963  /// getOffsetOf constant expr - computes the offset of a struct field in a
964  /// target independent way (Note: the return type is an i64).
965  ///
966  static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
967 
968  /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
969  /// which supports any aggregate type, and any Constant index.
970  ///
971  static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
972 
973  static Constant *getNeg(Constant *C, bool HasNUW = false,
974  bool HasNSW = false);
975  static Constant *getFNeg(Constant *C);
976  static Constant *getNot(Constant *C);
977  static Constant *getAdd(Constant *C1, Constant *C2, bool HasNUW = false,
978  bool HasNSW = false);
979  static Constant *getFAdd(Constant *C1, Constant *C2);
980  static Constant *getSub(Constant *C1, Constant *C2, bool HasNUW = false,
981  bool HasNSW = false);
982  static Constant *getFSub(Constant *C1, Constant *C2);
983  static Constant *getMul(Constant *C1, Constant *C2, bool HasNUW = false,
984  bool HasNSW = false);
985  static Constant *getFMul(Constant *C1, Constant *C2);
986  static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
987  static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
988  static Constant *getFDiv(Constant *C1, Constant *C2);
989  static Constant *getURem(Constant *C1, Constant *C2);
990  static Constant *getSRem(Constant *C1, Constant *C2);
991  static Constant *getFRem(Constant *C1, Constant *C2);
992  static Constant *getAnd(Constant *C1, Constant *C2);
993  static Constant *getOr(Constant *C1, Constant *C2);
994  static Constant *getXor(Constant *C1, Constant *C2);
995  static Constant *getUMin(Constant *C1, Constant *C2);
996  static Constant *getShl(Constant *C1, Constant *C2, bool HasNUW = false,
997  bool HasNSW = false);
998  static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
999  static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
1000  static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1001  static Constant *getSExt(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1002  static Constant *getZExt(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1003  static Constant *getFPTrunc(Constant *C, Type *Ty,
1004  bool OnlyIfReduced = false);
1005  static Constant *getFPExtend(Constant *C, Type *Ty,
1006  bool OnlyIfReduced = false);
1007  static Constant *getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1008  static Constant *getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1009  static Constant *getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1010  static Constant *getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1011  static Constant *getPtrToInt(Constant *C, Type *Ty,
1012  bool OnlyIfReduced = false);
1013  static Constant *getIntToPtr(Constant *C, Type *Ty,
1014  bool OnlyIfReduced = false);
1015  static Constant *getBitCast(Constant *C, Type *Ty,
1016  bool OnlyIfReduced = false);
1017  static Constant *getAddrSpaceCast(Constant *C, Type *Ty,
1018  bool OnlyIfReduced = false);
1019 
1020  static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
1021  static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
1022 
1024  return getAdd(C1, C2, false, true);
1025  }
1026 
1028  return getAdd(C1, C2, true, false);
1029  }
1030 
1032  return getSub(C1, C2, false, true);
1033  }
1034 
1036  return getSub(C1, C2, true, false);
1037  }
1038 
1040  return getMul(C1, C2, false, true);
1041  }
1042 
1044  return getMul(C1, C2, true, false);
1045  }
1046 
1048  return getShl(C1, C2, false, true);
1049  }
1050 
1052  return getShl(C1, C2, true, false);
1053  }
1054 
1056  return getSDiv(C1, C2, true);
1057  }
1058 
1060  return getUDiv(C1, C2, true);
1061  }
1062 
1064  return getAShr(C1, C2, true);
1065  }
1066 
1068  return getLShr(C1, C2, true);
1069  }
1070 
1071  /// If C is a scalar/fixed width vector of known powers of 2, then this
1072  /// function returns a new scalar/fixed width vector obtained from logBase2
1073  /// of C. Undef vector elements are set to zero.
1074  /// Return a null pointer otherwise.
1075  static Constant *getExactLogBase2(Constant *C);
1076 
1077  /// Return the identity constant for a binary opcode.
1078  /// The identity constant C is defined as X op C = X and C op X = X for every
1079  /// X when the binary operation is commutative. If the binop is not
1080  /// commutative, callers can acquire the operand 1 identity constant by
1081  /// setting AllowRHSConstant to true. For example, any shift has a zero
1082  /// identity constant for operand 1: X shift 0 = X.
1083  /// Return nullptr if the operator does not have an identity constant.
1084  static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty,
1085  bool AllowRHSConstant = false);
1086 
1087  /// Return the absorbing element for the given binary
1088  /// operation, i.e. a constant C such that X op C = C and C op X = C for
1089  /// every X. For example, this returns zero for integer multiplication.
1090  /// It returns null if the operator doesn't have an absorbing element.
1091  static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty);
1092 
1093  /// Transparently provide more efficient getOperand methods.
1095 
1096  /// Convenience function for getting a Cast operation.
1097  ///
1098  /// \param ops The opcode for the conversion
1099  /// \param C The constant to be converted
1100  /// \param Ty The type to which the constant is converted
1101  /// \param OnlyIfReduced see \a getWithOperands() docs.
1102  static Constant *getCast(unsigned ops, Constant *C, Type *Ty,
1103  bool OnlyIfReduced = false);
1104 
1105  // Create a ZExt or BitCast cast constant expression
1106  static Constant *
1107  getZExtOrBitCast(Constant *C, ///< The constant to zext or bitcast
1108  Type *Ty ///< The type to zext or bitcast C to
1109  );
1110 
1111  // Create a SExt or BitCast cast constant expression
1112  static Constant *
1113  getSExtOrBitCast(Constant *C, ///< The constant to sext or bitcast
1114  Type *Ty ///< The type to sext or bitcast C to
1115  );
1116 
1117  // Create a Trunc or BitCast cast constant expression
1118  static Constant *
1119  getTruncOrBitCast(Constant *C, ///< The constant to trunc or bitcast
1120  Type *Ty ///< The type to trunc or bitcast C to
1121  );
1122 
1123  /// Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant
1124  /// expression.
1125  static Constant *
1126  getPointerCast(Constant *C, ///< The pointer value to be casted (operand 0)
1127  Type *Ty ///< The type to which cast should be made
1128  );
1129 
1130  /// Create a BitCast or AddrSpaceCast for a pointer type depending on
1131  /// the address space.
1132  static Constant *getPointerBitCastOrAddrSpaceCast(
1133  Constant *C, ///< The constant to addrspacecast or bitcast
1134  Type *Ty ///< The type to bitcast or addrspacecast C to
1135  );
1136 
1137  /// Create a ZExt, Bitcast or Trunc for integer -> integer casts
1138  static Constant *
1139  getIntegerCast(Constant *C, ///< The integer constant to be casted
1140  Type *Ty, ///< The integer type to cast to
1141  bool IsSigned ///< Whether C should be treated as signed or not
1142  );
1143 
1144  /// Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
1145  static Constant *getFPCast(Constant *C, ///< The integer constant to be casted
1146  Type *Ty ///< The integer type to cast to
1147  );
1148 
1149  /// Return true if this is a convert constant expression
1150  bool isCast() const;
1151 
1152  /// Return true if this is a compare constant expression
1153  bool isCompare() const;
1154 
1155  /// Return true if this is an insertvalue or extractvalue expression,
1156  /// and the getIndices() method may be used.
1157  bool hasIndices() const;
1158 
1159  /// Return true if this is a getelementptr expression and all
1160  /// the index operands are compile-time known integers within the
1161  /// corresponding notional static array extents. Note that this is
1162  /// not equivalant to, a subset of, or a superset of the "inbounds"
1163  /// property.
1164  bool isGEPWithNoNotionalOverIndexing() const;
1165 
1166  /// Select constant expr
1167  ///
1168  /// \param OnlyIfReducedTy see \a getWithOperands() docs.
1169  static Constant *getSelect(Constant *C, Constant *V1, Constant *V2,
1170  Type *OnlyIfReducedTy = nullptr);
1171 
1172  /// get - Return a unary operator constant expression,
1173  /// folding if possible.
1174  ///
1175  /// \param OnlyIfReducedTy see \a getWithOperands() docs.
1176  static Constant *get(unsigned Opcode, Constant *C1, unsigned Flags = 0,
1177  Type *OnlyIfReducedTy = nullptr);
1178 
1179  /// get - Return a binary or shift operator constant expression,
1180  /// folding if possible.
1181  ///
1182  /// \param OnlyIfReducedTy see \a getWithOperands() docs.
1183  static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
1184  unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr);
1185 
1186  /// Return an ICmp or FCmp comparison operator constant expression.
1187  ///
1188  /// \param OnlyIfReduced see \a getWithOperands() docs.
1189  static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2,
1190  bool OnlyIfReduced = false);
1191 
1192  /// get* - Return some common constants without having to
1193  /// specify the full Instruction::OPCODE identifier.
1194  ///
1195  static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS,
1196  bool OnlyIfReduced = false);
1197  static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS,
1198  bool OnlyIfReduced = false);
1199 
1200  /// Getelementptr form. Value* is only accepted for convenience;
1201  /// all elements must be Constants.
1202  ///
1203  /// \param InRangeIndex the inrange index if present or None.
1204  /// \param OnlyIfReducedTy see \a getWithOperands() docs.
1206  ArrayRef<Constant *> IdxList,
1207  bool InBounds = false,
1208  Optional<unsigned> InRangeIndex = None,
1209  Type *OnlyIfReducedTy = nullptr) {
1210  return getGetElementPtr(
1211  Ty, C, makeArrayRef((Value *const *)IdxList.data(), IdxList.size()),
1212  InBounds, InRangeIndex, OnlyIfReducedTy);
1213  }
1215  bool InBounds = false,
1216  Optional<unsigned> InRangeIndex = None,
1217  Type *OnlyIfReducedTy = nullptr) {
1218  // This form of the function only exists to avoid ambiguous overload
1219  // warnings about whether to convert Idx to ArrayRef<Constant *> or
1220  // ArrayRef<Value *>.
1221  return getGetElementPtr(Ty, C, cast<Value>(Idx), InBounds, InRangeIndex,
1222  OnlyIfReducedTy);
1223  }
1224  static Constant *getGetElementPtr(Type *Ty, Constant *C,
1225  ArrayRef<Value *> IdxList,
1226  bool InBounds = false,
1227  Optional<unsigned> InRangeIndex = None,
1228  Type *OnlyIfReducedTy = nullptr);
1229 
1230  /// Create an "inbounds" getelementptr. See the documentation for the
1231  /// "inbounds" flag in LangRef.html for details.
1233  ArrayRef<Constant *> IdxList) {
1234  return getGetElementPtr(Ty, C, IdxList, true);
1235  }
1237  Constant *Idx) {
1238  // This form of the function only exists to avoid ambiguous overload
1239  // warnings about whether to convert Idx to ArrayRef<Constant *> or
1240  // ArrayRef<Value *>.
1241  return getGetElementPtr(Ty, C, Idx, true);
1242  }
1244  ArrayRef<Value *> IdxList) {
1245  return getGetElementPtr(Ty, C, IdxList, true);
1246  }
1247 
1248  static Constant *getExtractElement(Constant *Vec, Constant *Idx,
1249  Type *OnlyIfReducedTy = nullptr);
1250  static Constant *getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx,
1251  Type *OnlyIfReducedTy = nullptr);
1252  static Constant *getShuffleVector(Constant *V1, Constant *V2,
1254  Type *OnlyIfReducedTy = nullptr);
1255  static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs,
1256  Type *OnlyIfReducedTy = nullptr);
1257  static Constant *getInsertValue(Constant *Agg, Constant *Val,
1258  ArrayRef<unsigned> Idxs,
1259  Type *OnlyIfReducedTy = nullptr);
1260 
1261  /// Return the opcode at the root of this constant expression
1262  unsigned getOpcode() const { return getSubclassDataFromValue(); }
1263 
1264  /// Return the ICMP or FCMP predicate value. Assert if this is not an ICMP or
1265  /// FCMP constant expression.
1266  unsigned getPredicate() const;
1267 
1268  /// Assert that this is an insertvalue or exactvalue
1269  /// expression and return the list of indices.
1270  ArrayRef<unsigned> getIndices() const;
1271 
1272  /// Assert that this is a shufflevector and return the mask. See class
1273  /// ShuffleVectorInst for a description of the mask representation.
1274  ArrayRef<int> getShuffleMask() const;
1275 
1276  /// Assert that this is a shufflevector and return the mask.
1277  ///
1278  /// TODO: This is a temporary hack until we update the bitcode format for
1279  /// shufflevector.
1280  Constant *getShuffleMaskForBitcode() const;
1281 
1282  /// Return a string representation for an opcode.
1283  const char *getOpcodeName() const;
1284 
1285  /// Return a constant expression identical to this one, but with the specified
1286  /// operand set to the specified value.
1287  Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
1288 
1289  /// This returns the current constant expression with the operands replaced
1290  /// with the specified values. The specified array must have the same number
1291  /// of operands as our current one.
1293  return getWithOperands(Ops, getType());
1294  }
1295 
1296  /// Get the current expression with the operands replaced.
1297  ///
1298  /// Return the current constant expression with the operands replaced with \c
1299  /// Ops and the type with \c Ty. The new operands must have the same number
1300  /// as the current ones.
1301  ///
1302  /// If \c OnlyIfReduced is \c true, nullptr will be returned unless something
1303  /// gets constant-folded, the type changes, or the expression is otherwise
1304  /// canonicalized. This parameter should almost always be \c false.
1305  Constant *getWithOperands(ArrayRef<Constant *> Ops, Type *Ty,
1306  bool OnlyIfReduced = false,
1307  Type *SrcTy = nullptr) const;
1308 
1309  /// Returns an Instruction which implements the same operation as this
1310  /// ConstantExpr. The instruction is not linked to any basic block.
1311  ///
1312  /// A better approach to this could be to have a constructor for Instruction
1313  /// which would take a ConstantExpr parameter, but that would have spread
1314  /// implementation details of ConstantExpr outside of Constants.cpp, which
1315  /// would make it harder to remove ConstantExprs altogether.
1316  Instruction *getAsInstruction() const;
1317 
1318  /// Methods for support type inquiry through isa, cast, and dyn_cast:
1319  static bool classof(const Value *V) {
1320  return V->getValueID() == ConstantExprVal;
1321  }
1322 
1323 private:
1324  // Shadow Value::setValueSubclassData with a private forwarding method so that
1325  // subclasses cannot accidentally use it.
1326  void setValueSubclassData(unsigned short D) {
1328  }
1329 };
1330 
1331 template <>
1333  : public VariadicOperandTraits<ConstantExpr, 1> {};
1334 
1336 
1337 //===----------------------------------------------------------------------===//
1338 /// 'undef' values are things that do not have specified contents.
1339 /// These are used for a variety of purposes, including global variable
1340 /// initializers and operands to instructions. 'undef' values can occur with
1341 /// any first-class type.
1342 ///
1343 /// Undef values aren't exactly constants; if they have multiple uses, they
1344 /// can appear to have different bit patterns at each use. See
1345 /// LangRef.html#undefvalues for details.
1346 ///
1347 class UndefValue : public ConstantData {
1348  friend class Constant;
1349 
1350  explicit UndefValue(Type *T) : ConstantData(T, UndefValueVal) {}
1351 
1352  void destroyConstantImpl();
1353 
1354 protected:
1355  explicit UndefValue(Type *T, ValueTy vty) : ConstantData(T, vty) {}
1356 
1357 public:
1358  UndefValue(const UndefValue &) = delete;
1359 
1360  /// Static factory methods - Return an 'undef' object of the specified type.
1361  static UndefValue *get(Type *T);
1362 
1363  /// If this Undef has array or vector type, return a undef with the right
1364  /// element type.
1365  UndefValue *getSequentialElement() const;
1366 
1367  /// If this undef has struct type, return a undef with the right element type
1368  /// for the specified element.
1369  UndefValue *getStructElement(unsigned Elt) const;
1370 
1371  /// Return an undef of the right value for the specified GEP index if we can,
1372  /// otherwise return null (e.g. if C is a ConstantExpr).
1373  UndefValue *getElementValue(Constant *C) const;
1374 
1375  /// Return an undef of the right value for the specified GEP index.
1376  UndefValue *getElementValue(unsigned Idx) const;
1377 
1378  /// Return the number of elements in the array, vector, or struct.
1379  unsigned getNumElements() const;
1380 
1381  /// Methods for support type inquiry through isa, cast, and dyn_cast:
1382  static bool classof(const Value *V) {
1383  return V->getValueID() == UndefValueVal ||
1384  V->getValueID() == PoisonValueVal;
1385  }
1386 };
1387 
1388 //===----------------------------------------------------------------------===//
1389 /// In order to facilitate speculative execution, many instructions do not
1390 /// invoke immediate undefined behavior when provided with illegal operands,
1391 /// and return a poison value instead.
1392 ///
1393 /// see LangRef.html#poisonvalues for details.
1394 ///
1395 class PoisonValue final : public UndefValue {
1396  friend class Constant;
1397 
1398  explicit PoisonValue(Type *T) : UndefValue(T, PoisonValueVal) {}
1399 
1400  void destroyConstantImpl();
1401 
1402 public:
1403  PoisonValue(const PoisonValue &) = delete;
1404 
1405  /// Static factory methods - Return an 'poison' object of the specified type.
1406  static PoisonValue *get(Type *T);
1407 
1408  /// If this poison has array or vector type, return a poison with the right
1409  /// element type.
1411 
1412  /// If this poison has struct type, return a poison with the right element
1413  /// type for the specified element.
1414  PoisonValue *getStructElement(unsigned Elt) const;
1415 
1416  /// Return an poison of the right value for the specified GEP index if we can,
1417  /// otherwise return null (e.g. if C is a ConstantExpr).
1419 
1420  /// Return an poison of the right value for the specified GEP index.
1421  PoisonValue *getElementValue(unsigned Idx) const;
1422 
1423  /// Methods for support type inquiry through isa, cast, and dyn_cast:
1424  static bool classof(const Value *V) {
1425  return V->getValueID() == PoisonValueVal;
1426  }
1427 };
1428 
1429 } // end namespace llvm
1430 
1431 #endif // LLVM_IR_CONSTANTS_H
llvm::ConstantDataVector::getRaw
static Constant * getRaw(StringRef Data, uint64_t NumElements, Type *ElementTy)
getRaw() constructor - Return a constant with vector type with an element count and element type matc...
Definition: Constants.h:781
i
i
Definition: README.txt:29
llvm::ConstantDataArray::get
static Constant * get(LLVMContext &Context, ArrayTy &Elts)
get() constructor - ArrayTy needs to be compatible with ArrayRef<ElementTy>.
Definition: Constants.h:699
llvm::APInt::isMaxSignedValue
bool isMaxSignedValue() const
Determine if this is the largest signed value.
Definition: APInt.h:432
llvm::APFloat::isInfinity
bool isInfinity() const
Definition: APFloat.h:1202
llvm::ConstantDataSequential::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:662
llvm
Definition: AllocatorList.h:23
llvm::ConstantDataSequential::getElementByteSize
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
Definition: Constants.cpp:2928
llvm::ConstantInt::getMaybeAlignValue
MaybeAlign getMaybeAlignValue() const
Return the constant as an llvm::MaybeAlign.
Definition: Constants.h:151
llvm::ConstantPointerNull::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:554
Optional.h
llvm::ConstantFP::isValueValidForType
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
Definition: Constants.cpp:1602
llvm::UndefValue::UndefValue
UndefValue(Type *T, ValueTy vty)
Definition: Constants.h:1355
llvm::ConstantInt::getType
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Definition: Constants.h:171
llvm::ConstantExpr::getExactSDiv
static Constant * getExactSDiv(Constant *C1, Constant *C2)
Definition: Constants.h:1055
llvm::ConstantExpr::getNSWNeg
static Constant * getNSWNeg(Constant *C)
Definition: Constants.h:1020
llvm::ConstantAggregateZero::getSequentialElement
Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
Definition: Constants.cpp:1083
llvm::ElementCount
Definition: TypeSize.h:386
llvm::ConstantInt::getBitWidth
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
Definition: Constants.h:134
llvm::ConstantData::ConstantData
ConstantData(Type *Ty, ValueTy VT)
Definition: Constants.h:59
llvm::Function
Definition: Function.h:61
llvm::ISD::ConstantFP
@ ConstantFP
Definition: ISDOpcodes.h:70
StringRef.h
llvm::ConstantStruct::get
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1326
llvm::VariadicOperandTraits
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:68
C1
instcombine should handle this C2 when C1
Definition: README.txt:263
llvm::ConstantExpr::getOpcode
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
Definition: Constants.h:1262
llvm::PoisonValue::getSequentialElement
PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
Definition: Constants.cpp:1153
llvm::ConstantInt::getValue
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:131
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
getImpl
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const Module *M)
This lazily constructs the LazyValueInfoImpl.
Definition: LazyValueInfo.cpp:1488
llvm::ConstantInt::isMinValue
bool isMinValue(bool IsSigned) const
This function will return true iff this constant represents the smallest value that may be represente...
Definition: Constants.h:223
llvm::PoisonValue::getElementValue
PoisonValue * getElementValue(Constant *C) const
Return an poison of the right value for the specified GEP index if we can, otherwise return null (e....
Definition: Constants.cpp:1163
llvm::APInt::getSExtValue
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1643
llvm::ConstantDataSequential::getElementAsInteger
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
Definition: Constants.cpp:3178
ErrorHandling.h
llvm::ConstantDataSequential::getAsCString
StringRef getAsCString() const
If this array is isCString(), then this method returns the array (without the trailing null byte) as ...
Definition: Constants.h:650
llvm::ConstantStruct::getAnon
static Constant * getAnon(LLVMContext &Ctx, ArrayRef< Constant * > V, bool Packed=false)
Definition: Constants.h:464
llvm::ConstantAggregate
Base class for aggregate constants (with operands).
Definition: Constants.h:383
llvm::BlockAddress::getBasicBlock
BasicBlock * getBasicBlock() const
Definition: Constants.h:874
llvm::PoisonValue::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:1424
llvm::ConstantFP::getInfinity
static Constant * getInfinity(Type *Ty, bool Negative=false)
Definition: Constants.cpp:1054
llvm::ConstantExpr::getInBoundsGetElementPtr
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, Constant *Idx)
Definition: Constants.h:1236
llvm::APFloat::isZero
bool isZero() const
Definition: APFloat.h:1201
llvm::ConstantDataVector::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:817
llvm::ConstantDataVector::get
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
Definition: Constants.cpp:3070
llvm::ConstantInt::getLimitedValue
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
Definition: Constants.h:242
APInt.h
llvm::ConstantDataSequential::getElementAsFloat
float getElementAsFloat(unsigned i) const
If this is an sequential container of floats, return the specified element as a float.
Definition: Constants.cpp:3251
llvm::ConstantAggregateZero::getElementCount
ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
Definition: Constants.cpp:1105
llvm::ConstantFP::isZero
bool isZero() const
Return true if the value is positive or negative zero.
Definition: Constants.h:299
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1581
llvm::MaybeAlign::valueOrOne
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition: Alignment.h:134
llvm::ConstantExpr::getNUWMul
static Constant * getNUWMul(Constant *C1, Constant *C2)
Definition: Constants.h:1043
DEFINE_TRANSPARENT_OPERAND_ACCESSORS
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
Definition: OperandTraits.h:125
llvm::ConstantDataSequential::isElementTypeCompatible
static bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
Definition: Constants.cpp:2905
llvm::ConstantExpr::getExactLShr
static Constant * getExactLShr(Constant *C1, Constant *C2)
Definition: Constants.h:1067
llvm::ConstantFP::isNaN
bool isNaN() const
Return true if the value is a NaN.
Definition: Constants.h:308
llvm::ConstantAggregateZero
All zero aggregate value.
Definition: Constants.h:334
llvm::ConstantFP::getValueAPF
const APFloat & getValueAPF() const
Definition: Constants.h:295
llvm::Optional< unsigned >
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::ConstantFP::getValue
const APFloat & getValue() const
Definition: Constants.h:296
llvm::ConstantInt::isMaxValue
bool isMaxValue(bool IsSigned) const
This function will return true iff this constant represents the largest value that may be represented...
Definition: Constants.h:211
llvm::ConstantExpr::getInBoundsGetElementPtr
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
Definition: Constants.h:1232
STLExtras.h
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:359
llvm::ConstantFP::getNegativeZero
static Constant * getNegativeZero(Type *Ty)
Definition: Constants.cpp:1020
llvm::Value::setValueSubclassData
void setValueSubclassData(unsigned short D)
Definition: Value.h:857
llvm::FixedVectorType
Class to represent fixed width SIMD vectors.
Definition: DerivedTypes.h:527
llvm::ConstantDataSequential::isString
bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
Definition: Constants.cpp:3271
llvm::BitmaskEnumDetail::Mask
std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::APFloat::getSemantics
const fltSemantics & getSemantics() const
Definition: APFloat.h:1213
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::APInt::isMinValue
bool isMinValue() const
Determine if this is the smallest unsigned value.
Definition: APInt.h:442
llvm::ConstantDataArray::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:740
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:160
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::ConstantExpr::getWithOperands
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values.
Definition: Constants.h:1292
llvm::ConstantExpr::getGetElementPtr
static Constant * getGetElementPtr(Type *Ty, Constant *C, Constant *Idx, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.h:1214
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::ConstantArray::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:431
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::conjunction
Definition: STLForwardCompat.h:32
llvm::ConstantDataSequential::getElementAsAPFloat
APFloat getElementAsAPFloat(unsigned i) const
If this is a sequential container of floating point type, return the specified element as an APFloat.
Definition: Constants.cpp:3226
llvm::ConstantData
Base class for constants with no operands.
Definition: Constants.h:51
llvm::ConstantPointerNull
A constant pointer value that points to null.
Definition: Constants.h:533
llvm::APInt::uge
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Definition: APInt.h:1313
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:77
llvm::ConstantFP::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:326
llvm::Intrinsic::getType
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:1274
llvm::APInt::isNegative
bool isNegative() const
Determine sign of this APInt.
Definition: APInt.h:364
llvm::ConstantDataSequential
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Definition: Constants.h:568
llvm::OperandTraits
Compile-time customization of User operands.
Definition: User.h:42
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::LLVMContextImpl
Definition: LLVMContextImpl.h:1324
llvm::APFloat::isNaN
bool isNaN() const
Definition: APFloat.h:1203
llvm::APInt::getLimitedValue
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
Definition: APInt.h:487
false
Definition: StackSlotColoring.cpp:142
llvm::ConstantInt::equalsInt
bool equalsInt(uint64_t V) const
A helper method that can be used to determine if the constant contained within is equal to a constant...
Definition: Constants.h:166
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
getOpcodeName
static StringRef getOpcodeName(uint8_t Opcode, uint8_t OpcodeBase)
Definition: DWARFDebugLine.cpp:600
llvm::ConstantExpr::getNSWMul
static Constant * getNSWMul(Constant *C1, Constant *C2)
Definition: Constants.h:1039
llvm::Value::getValueID
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:541
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::ConstantArray
ConstantArray - Constant Array Declarations.
Definition: Constants.h:407
llvm::APFloat::isNegative
bool isNegative() const
Definition: APFloat.h:1205
llvm::Instruction
Definition: Instruction.h:45
llvm::ConstantExpr::getExactUDiv
static Constant * getExactUDiv(Constant *C1, Constant *C2)
Definition: Constants.h:1059
llvm::ConstantDataVector::getSplatValue
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value,...
Definition: Constants.cpp:3308
llvm::ConstantExpr::getNUWNeg
static Constant * getNUWNeg(Constant *C)
Definition: Constants.h:1021
llvm::APInt::getZExtValue
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1631
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:255
llvm::ConstantVector::getSplat
static Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
Definition: Constants.cpp:1411
APFloat.h
This file declares a class to represent arbitrary precision floating point values and provide a varie...
llvm::ConstantFP::isExactlyValue
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
Definition: Constants.cpp:1070
OperandTraits.h
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:899
llvm::ConstantDataArray::getRaw
static Constant * getRaw(StringRef Data, uint64_t NumElements, Type *ElementTy)
getRaw() constructor - Return a constant with array type with an element count and element type match...
Definition: Constants.h:709
llvm::ConstantDataSequential::getImpl
static Constant * getImpl(StringRef Bytes, Type *Ty)
This is the underlying implementation of all of the ConstantDataSequential::get methods.
Definition: Constants.cpp:2951
llvm::PoisonValue::getStructElement
PoisonValue * getStructElement(unsigned Elt) const
If this poison has struct type, return a poison with the right element type for the specified element...
Definition: Constants.cpp:1159
llvm::ConstantStruct::getType
StructType * getType() const
Specialization - reduce amount of casting.
Definition: Constants.h:479
llvm::ConstantAggregate::ConstantAggregate
ConstantAggregate(Type *T, ValueTy VT, ArrayRef< Constant * > V)
Definition: Constants.cpp:1240
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::ConstantFP::getSNaN
static Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition: Constants.cpp:1009
llvm::None
const NoneType None
Definition: None.h:23
llvm::LinearPolySize< ElementCount >::getFixed
static ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:284
llvm::ConstantExpr::getNSWAdd
static Constant * getNSWAdd(Constant *C1, Constant *C2)
Definition: Constants.h:1023
llvm::APInt::isAllOnesValue
bool isAllOnesValue() const
Determine if all bits are set.
Definition: APInt.h:401
llvm::ConstantFP::isExactlyValue
bool isExactlyValue(double V) const
Definition: Constants.h:318
llvm::ConstantDataArray::getType
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
Definition: Constants.h:735
llvm::ConstantDataSequential::isCString
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
Definition: Constants.cpp:3275
llvm::ISD::BlockAddress
@ BlockAddress
Definition: ISDOpcodes.h:77
llvm::ConstantArray::getType
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
Definition: Constants.h:426
llvm::VectorType
Base class of all SIMD vector types.
Definition: DerivedTypes.h:391
llvm::ConstantDataSequential::ConstantDataSequential
ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
Definition: Constants.h:585
llvm::APInt::isOneValue
bool isOneValue() const
Determine if this is a value of 1.
Definition: APInt.h:416
llvm::ConstantDataSequential::getRawDataValues
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
Definition: Constants.cpp:2901
llvm::APFloat
Definition: APFloat.h:701
llvm::ConstantVector::getType
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
Definition: Constants.h:515
llvm::ConstantFP::getQNaN
static Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition: Constants.cpp:998
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::ConstantDataVector::getFP
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of vector type with a float element type taken from argument...
Definition: Constants.cpp:3107
llvm::ConstantAggrKeyType
Definition: Constants.h:44
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::ConstantPointerNull::get
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1770
s
multiplies can be turned into SHL s
Definition: README.txt:370
llvm::ConstantDataArray
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
Definition: Constants.h:677
llvm::ConstantExpr::getInBoundsGetElementPtr
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Value * > IdxList)
Definition: Constants.h:1243
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::DSOLocalEquivalent::getGlobalValue
GlobalValue * getGlobalValue() const
Definition: Constants.h:908
llvm::ConstantDataVector::isSplat
bool isSplat() const
Returns true if this is a splat constant, meaning that all elements have the same value.
Definition: Constants.cpp:3300
llvm::ConstantDataVector
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
Definition: Constants.h:751
llvm::UndefValue
'undef' values are things that do not have specified contents.
Definition: Constants.h:1347
llvm::PointerType
Class to represent pointers.
Definition: DerivedTypes.h:634
llvm::ConstantDataSequential::getElementType
Type * getElementType() const
Return the element type of the array/vector.
Definition: Constants.cpp:2895
ArrayRef.h
llvm::ConstantFP::isInfinity
bool isInfinity() const
Return true if the value is infinity.
Definition: Constants.h:305
llvm::ConstantVector
Constant Vector Declarations.
Definition: Constants.h:492
llvm::BlockAddress::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:877
llvm::ConstantStruct::getAnon
static Constant * getAnon(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct that has the specified elements.
Definition: Constants.h:461
llvm::ConstantFP::isNegative
bool isNegative() const
Return true if the sign bit is set.
Definition: Constants.h:302
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ConstantDataSequential::getElementAsConstant
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
Definition: Constants.cpp:3263
ops
xray Insert XRay ops
Definition: XRayInstrumentation.cpp:268
llvm::ConstantFP::getZeroValueForNegation
static Constant * getZeroValueForNegation(Type *Ty)
Floating point negation must be implemented with f(x) = -0.0 - x.
Definition: Constants.cpp:1032
llvm::ConstantAggregateZero::getElementValue
Constant * getElementValue(Constant *C) const
Return a zero of the right value for the specified GEP index if we can, otherwise return null (e....
Definition: Constants.cpp:1093
llvm::ConstantVector::getSplatValue
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
Definition: Constants.cpp:1731
llvm::ArrayType::get
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:598
llvm::ConstantFP::getNaN
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
Definition: Constants.cpp:987
llvm::ConstantExpr::ConstantExpr
ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
Definition: Constants.h:939
llvm::ConstantAggregate::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:392
llvm::ConstantStruct
Definition: Constants.h:439
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:70
llvm::ConstantTokenNone::classof
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
Definition: Constants.h:840
llvm::ConstantExpr::getNUWAdd
static Constant * getNUWAdd(Constant *C1, Constant *C2)
Definition: Constants.h:1027
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:847
llvm::Value::ValueTy
ValueTy
Concrete subclass of this.
Definition: Value.h:522
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
None.h
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:212
llvm::ConstantExpr::getNUWSub
static Constant * getNUWSub(Constant *C1, Constant *C2)
Definition: Constants.h:1035
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::UndefValue::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:1382
llvm::ConstantDataSequential::getElementAsAPInt
APInt getElementAsAPInt(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element as an APInt...
Definition: Constants.cpp:3198
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
llvm::ConstantInt::isZero
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:192
llvm::ConstantDataArray::get
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition: Constants.h:690
Compiler.h
llvm::ConstantDataArray::getString
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
Definition: Constants.cpp:3054
llvm::ConstantStruct::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:484
llvm::ConstantExpr::getNSWShl
static Constant * getNSWShl(Constant *C1, Constant *C2)
Definition: Constants.h:1047
llvm::ConstantInt::isMinusOne
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
Definition: Constants.h:204
llvm::ConstantAggregate::DECLARE_TRANSPARENT_OPERAND_ACCESSORS
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant)
Transparently provide more efficient getOperand methods.
llvm::ConstantExprKeyType
Definition: ConstantsContext.h:511
llvm::ConstantVector::get
static Constant * get(ArrayRef< Constant * > V)
Definition: Constants.cpp:1368
llvm::ConstantInt::getSExtValue
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Definition: Constants.h:146
llvm::ConstantExpr::getNSWSub
static Constant * getNSWSub(Constant *C1, Constant *C2)
Definition: Constants.h:1031
llvm::ConstantInt::getFalse
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:854
llvm::ConstantInt::getZExtValue
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:140
llvm::ConstantDataArray::getFP
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
Definition: Constants.cpp:3033
llvm::ConstantAggregateZero::getStructElement
Constant * getStructElement(unsigned Elt) const
If this CAZ has struct type, return a zero with the right element type for the specified element.
Definition: Constants.cpp:1089
llvm::BlockAddress::getFunction
Function * getFunction() const
Definition: Constants.h:873
Constant.h
llvm::NVPTX::PTXLdStInstCode::V2
@ V2
Definition: NVPTX.h:123
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:931
llvm::ConstantInt::getTrue
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:847
llvm::PPC::getPredicate
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
Definition: PPCPredicates.h:87
llvm::APInt::isMinSignedValue
bool isMinSignedValue() const
Determine if this is the smallest signed value.
Definition: APInt.h:448
llvm::ConstantExpr::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:1319
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
llvm::ConstantDataSequential::getElementAsDouble
double getElementAsDouble(unsigned i) const
If this is an sequential container of doubles, return the specified element as a double.
Definition: Constants.cpp:3257
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::ConstantInt::getBool
static ConstantInt * getBool(LLVMContext &Context, bool V)
Definition: Constants.cpp:861
llvm::ConstantFP::get
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:946
llvm::ConstantInt::uge
bool uge(uint64_t Num) const
This function will return true iff this constant represents a value with active bits bigger than 64 b...
Definition: Constants.h:235
llvm::ConstantTokenNone::get
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
Definition: Constants.cpp:1441
llvm::ConstantInt::getSigned
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constants.cpp:913
Casting.h
llvm::BlockAddress::DECLARE_TRANSPARENT_OPERAND_ACCESSORS
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
llvm::ConstantData::classof
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
Definition: Constants.h:67
llvm::ConstantExpr::getGetElementPtr
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
Definition: Constants.h:1205
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:474
llvm::APInt::isNullValue
bool isNullValue() const
Determine if all bits are clear.
Definition: APInt.h:411
llvm::ConstantInt::getAlignValue
Align getAlignValue() const
Return the constant as an llvm::Align, interpreting 0 as Align(1).
Definition: Constants.h:158
DECLARE_TRANSPARENT_OPERAND_ACCESSORS
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
Definition: OperandTraits.h:110
llvm::APFloatBase::rmNearestTiesToEven
static constexpr roundingMode rmNearestTiesToEven
Definition: APFloat.h:190
llvm::APFloat::convert
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4818
llvm::ConstantInt::isNegative
bool isNegative() const
Definition: Constants.h:187
User.h
llvm::APInt::isMaxValue
bool isMaxValue() const
Determine if this is the largest unsigned value.
Definition: APInt.h:426
llvm::DSOLocalEquivalent::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:913
llvm::ConstantVector::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:525
llvm::ConstantDataVector::getSplat
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
Definition: Constants.cpp:3131
llvm::ConstantStruct::get
static std::enable_if_t< are_base_of< Constant, Csts... >::value, Constant * > get(StructType *T, Csts *...Vs)
Definition: Constants.h:454
llvm::BlockAddress::get
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1822
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
llvm::ConstantInt::isValueValidForType
static bool isValueValidForType(Type *Ty, uint64_t V)
This static method returns true if the type Ty is big enough to represent the value V.
Definition: Constants.cpp:1588
llvm::FixedNumOperandTraits
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:30
llvm::ConstantStruct::getTypeForElements
static StructType * getTypeForElements(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct type to use for a constant with the specified set of elements.
Definition: Constants.cpp:1312
llvm::ConstantDataVector::getType
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
Definition: Constants.h:812
DerivedTypes.h
pred
hexagon gen pred
Definition: HexagonGenPredicate.cpp:134
llvm::ConstantInt::isOne
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition: Constants.h:198
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::BlockAddress::lookup
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Definition: Constants.cpp:1840
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::ConstantPointerNull::getType
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
Definition: Constants.h:549
llvm::ConstantInt::classof
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
Definition: Constants.h:247
llvm::ConstantExpr::getExactAShr
static Constant * getExactAShr(Constant *C1, Constant *C2)
Definition: Constants.h:1063
llvm::ConstantDataSequential::getAsString
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
Definition: Constants.h:643
llvm::ConstantAggregateZero::get
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1663
llvm::ConstantExpr::getNUWShl
static Constant * getNUWShl(Constant *C1, Constant *C2)
Definition: Constants.h:1051
Value.h
llvm::ConstantTokenNone
A constant token which is empty.
Definition: Constants.h:825
llvm::ConstantStruct::Constant
friend class Constant
Definition: Constants.h:441
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::DSOLocalEquivalent
Wrapper for a function that represents a value that functionally represents the original function.
Definition: Constants.h:891
llvm::VectorType::get
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:628
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:44
llvm::PoisonValue
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
Definition: Constants.h:1395
llvm::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1803
llvm::ConstantDataSequential::getNumElements
unsigned getNumElements() const
Return the number of elements in the array or vector.
Definition: Constants.cpp:2921
llvm::ConstantAggregateZero::classof
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Constants.h:367