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