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