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