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.
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 {
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);
346 FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
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///
359class ConstantAggregateZero final : public ConstantData {
360 friend class Constant;
361
362 explicit ConstantAggregateZero(Type *Ty)
363 : ConstantData(Ty, ConstantAggregateZeroVal) {}
364
365 void destroyConstantImpl();
366
367public:
368 ConstantAggregateZero(const ConstantAggregateZero &) = delete;
369
370 LLVM_ABI static ConstantAggregateZero *get(Type *Ty);
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
437 ConstantArray(ArrayType *T, ArrayRef<Constant *> Val, AllocInfo AllocInfo);
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 {
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
469 ConstantStruct(StructType *T, ArrayRef<Constant *> Val, AllocInfo AllocInfo);
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 {
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
521 ConstantVector(VectorType *T, ArrayRef<Constant *> Val, AllocInfo AllocInfo);
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 {
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
561 explicit ConstantPointerNull(PointerType *T)
562 : ConstantData(T, Value::ConstantPointerNullVal) {}
563
564 void destroyConstantImpl();
565
566public:
567 ConstantPointerNull(const ConstantPointerNull &) = delete;
568
569 /// Static factory methods - Return objects of the specified value
570 LLVM_ABI static ConstantPointerNull *get(PointerType *T);
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 {
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.
702class ConstantDataArray final : public ConstantDataSequential {
704
705 explicit ConstantDataArray(Type *ty, const char *Data)
706 : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
707
708public:
709 ConstantDataArray(const ConstantDataArray &) = delete;
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(),
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) {
725 return ConstantDataArray::get(Context, ArrayRef(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 {
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.
776class ConstantDataVector final : public ConstantDataSequential {
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:
788 ConstantDataVector(const ConstantDataVector &) = delete;
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 {
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:
859 ConstantTokenNone(const ConstantTokenNone &) = delete;
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
874 explicit ConstantTargetNone(TargetExtType *T)
875 : ConstantData(T, Value::ConstantTargetNoneVal) {}
876
877 void destroyConstantImpl();
878
879public:
880 ConstantTargetNone(const ConstantTargetNone &) = delete;
881
882 /// Static factory methods - Return objects of the specified value.
883 LLVM_ABI static ConstantTargetNone *get(TargetExtType *T);
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 {
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
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.
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{5};
1037
1039 Constant *AddrDisc, Constant *DeactivationSymbol);
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 Constant *DeactivationSymbol);
1051
1052 /// Produce a new ptrauth expression signing the given value using
1053 /// the same schema as is stored in one.
1054 LLVM_ABI ConstantPtrAuth *getWithSameSchema(Constant *Pointer) const;
1055
1056 /// Transparently provide more efficient getOperand methods.
1058
1059 /// The pointer that is signed in this ptrauth signed pointer.
1060 Constant *getPointer() const { return cast<Constant>(Op<0>().get()); }
1061
1062 /// The Key ID, an i32 constant.
1064
1065 /// The integer discriminator, an i64 constant, or 0.
1067 return cast<ConstantInt>(Op<2>().get());
1068 }
1069
1070 /// The address discriminator if any, or the null constant.
1071 /// If present, this must be a value equivalent to the storage location of
1072 /// the only global-initializer user of the ptrauth signed pointer.
1074 return cast<Constant>(Op<3>().get());
1075 }
1076
1077 /// Whether there is any non-null address discriminator.
1079 return !getAddrDiscriminator()->isNullValue();
1080 }
1081
1083 return cast<Constant>(Op<4>().get());
1084 }
1085
1086 /// A constant value for the address discriminator which has special
1087 /// significance to ctors/dtors lowering. Regular address discrimination can't
1088 /// be applied for them since uses of llvm.global_{c|d}tors are disallowed
1089 /// (see Verifier::visitGlobalVariable) and we can't emit getelementptr
1090 /// expressions referencing these special arrays.
1092
1093 /// Whether the address uses a special address discriminator.
1094 /// These discriminators can't be used in real pointer-auth values; they
1095 /// can only be used in "prototype" values that indicate how some real
1096 /// schema is supposed to be produced.
1097 LLVM_ABI bool hasSpecialAddressDiscriminator(uint64_t Value) const;
1098
1099 /// Check whether an authentication operation with key \p Key and (possibly
1100 /// blended) discriminator \p Discriminator is known to be compatible with
1101 /// this ptrauth signed pointer.
1102 LLVM_ABI bool isKnownCompatibleWith(const Value *Key,
1103 const Value *Discriminator,
1104 const DataLayout &DL) const;
1105
1106 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1107 static bool classof(const Value *V) {
1108 return V->getValueID() == ConstantPtrAuthVal;
1109 }
1110};
1111
1112template <>
1114 : public FixedNumOperandTraits<ConstantPtrAuth, 5> {};
1115
1117
1118//===----------------------------------------------------------------------===//
1119/// A constant value that is initialized with an expression using
1120/// other constant values.
1121///
1122/// This class uses the standard Instruction opcodes to define the various
1123/// constant expressions. The Opcode field for the ConstantExpr class is
1124/// maintained in the Value::SubclassData field.
1125class ConstantExpr : public Constant {
1126 friend struct ConstantExprKeyType;
1127 friend class Constant;
1128
1129 void destroyConstantImpl();
1130 Value *handleOperandChangeImpl(Value *From, Value *To);
1131
1132protected:
1133 ConstantExpr(Type *ty, unsigned Opcode, AllocInfo AllocInfo)
1134 : Constant(ty, ConstantExprVal, AllocInfo) {
1135 // Operation type (an Instruction opcode) is stored as the SubclassData.
1136 setValueSubclassData(Opcode);
1137 }
1138
1139 ~ConstantExpr() = default;
1140
1141public:
1142 // Static methods to construct a ConstantExpr of different kinds. Note that
1143 // these methods may return a object that is not an instance of the
1144 // ConstantExpr class, because they will attempt to fold the constant
1145 // expression into something simpler if possible.
1146
1147 /// getAlignOf constant expr - computes the alignment of a type in a target
1148 /// independent way (Note: the return type is an i64).
1149 LLVM_ABI static Constant *getAlignOf(Type *Ty);
1150
1151 /// getSizeOf constant expr - computes the (alloc) size of a type (in
1152 /// address-units, not bits) in a target independent way (Note: the return
1153 /// type is an i64).
1154 ///
1155 LLVM_ABI static Constant *getSizeOf(Type *Ty);
1156
1157 LLVM_ABI static Constant *getNeg(Constant *C, bool HasNSW = false);
1158 LLVM_ABI static Constant *getNot(Constant *C);
1159 LLVM_ABI static Constant *getAdd(Constant *C1, Constant *C2,
1160 bool HasNUW = false, bool HasNSW = false);
1161 LLVM_ABI static Constant *getSub(Constant *C1, Constant *C2,
1162 bool HasNUW = false, bool HasNSW = false);
1163 LLVM_ABI static Constant *getXor(Constant *C1, Constant *C2);
1164 LLVM_ABI static Constant *getTrunc(Constant *C, Type *Ty,
1165 bool OnlyIfReduced = false);
1167 bool OnlyIfReduced = false);
1169 bool OnlyIfReduced = false);
1171 bool OnlyIfReduced = false);
1172 LLVM_ABI static Constant *getBitCast(Constant *C, Type *Ty,
1173 bool OnlyIfReduced = false);
1175 bool OnlyIfReduced = false);
1176
1177 static Constant *getNSWNeg(Constant *C) { return getNeg(C, /*HasNSW=*/true); }
1178
1180 return getAdd(C1, C2, false, true);
1181 }
1182
1184 return getAdd(C1, C2, true, false);
1185 }
1186
1188 return getSub(C1, C2, false, true);
1189 }
1190
1192 return getSub(C1, C2, true, false);
1193 }
1194
1195 /// If C is a scalar/fixed width vector of known powers of 2, then this
1196 /// function returns a new scalar/fixed width vector obtained from logBase2
1197 /// of C. Undef vector elements are set to zero.
1198 /// Return a null pointer otherwise.
1199 LLVM_ABI static Constant *getExactLogBase2(Constant *C);
1200
1201 /// Return the identity constant for a binary opcode.
1202 /// If the binop is not commutative, callers can acquire the operand 1
1203 /// identity constant by setting AllowRHSConstant to true. For example, any
1204 /// shift has a zero identity constant for operand 1: X shift 0 = X. If this
1205 /// is a fadd/fsub operation and we don't care about signed zeros, then
1206 /// setting NSZ to true returns the identity +0.0 instead of -0.0. Return
1207 /// nullptr if the operator does not have an identity constant.
1208 LLVM_ABI static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty,
1209 bool AllowRHSConstant = false,
1210 bool NSZ = false);
1211
1212 LLVM_ABI static Constant *getIntrinsicIdentity(Intrinsic::ID, Type *Ty);
1213
1214 /// Return the identity constant for a binary or intrinsic Instruction.
1215 /// The identity constant C is defined as X op C = X and C op X = X where C
1216 /// and X are the first two operands, and the operation is commutative.
1217 LLVM_ABI static Constant *getIdentity(Instruction *I, Type *Ty,
1218 bool AllowRHSConstant = false,
1219 bool NSZ = false);
1220
1221 /// Return the absorbing element for the given binary
1222 /// operation, i.e. a constant C such that X op C = C and C op X = C for
1223 /// every X. For example, this returns zero for integer multiplication.
1224 /// If AllowLHSConstant is true, the LHS operand is a constant C that must be
1225 /// defined as C op X = C. It returns null if the operator doesn't have
1226 /// an absorbing element.
1227 LLVM_ABI static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty,
1228 bool AllowLHSConstant = false);
1229
1230 /// Transparently provide more efficient getOperand methods.
1232
1233 /// Convenience function for getting a Cast operation.
1234 ///
1235 /// \param ops The opcode for the conversion
1236 /// \param C The constant to be converted
1237 /// \param Ty The type to which the constant is converted
1238 /// \param OnlyIfReduced see \a getWithOperands() docs.
1239 LLVM_ABI static Constant *getCast(unsigned ops, Constant *C, Type *Ty,
1240 bool OnlyIfReduced = false);
1241
1242 // Create a Trunc or BitCast cast constant expression
1243 LLVM_ABI static Constant *
1244 getTruncOrBitCast(Constant *C, ///< The constant to trunc or bitcast
1245 Type *Ty ///< The type to trunc or bitcast C to
1246 );
1247
1248 /// Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant
1249 /// expression.
1250 LLVM_ABI static Constant *
1251 getPointerCast(Constant *C, ///< The pointer value to be casted (operand 0)
1252 Type *Ty ///< The type to which cast should be made
1253 );
1254
1255 /// Create a BitCast or AddrSpaceCast for a pointer type depending on
1256 /// the address space.
1258 Constant *C, ///< The constant to addrspacecast or bitcast
1259 Type *Ty ///< The type to bitcast or addrspacecast C to
1260 );
1261
1262 /// Return true if this is a convert constant expression
1263 LLVM_ABI bool isCast() const;
1264
1265 /// get - Return a binary or shift operator constant expression,
1266 /// folding if possible.
1267 ///
1268 /// \param OnlyIfReducedTy see \a getWithOperands() docs.
1269 LLVM_ABI static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
1270 unsigned Flags = 0,
1271 Type *OnlyIfReducedTy = nullptr);
1272
1273 /// Getelementptr form. Value* is only accepted for convenience;
1274 /// all elements must be Constants.
1275 ///
1276 /// \param InRange the inrange range if present or std::nullopt.
1277 /// \param OnlyIfReducedTy see \a getWithOperands() docs.
1278 static Constant *
1281 std::optional<ConstantRange> InRange = std::nullopt,
1282 Type *OnlyIfReducedTy = nullptr) {
1283 return getGetElementPtr(
1284 Ty, C, ArrayRef((Value *const *)IdxList.data(), IdxList.size()), NW,
1285 InRange, OnlyIfReducedTy);
1286 }
1287 static Constant *
1290 std::optional<ConstantRange> InRange = std::nullopt,
1291 Type *OnlyIfReducedTy = nullptr) {
1292 // This form of the function only exists to avoid ambiguous overload
1293 // warnings about whether to convert Idx to ArrayRef<Constant *> or
1294 // ArrayRef<Value *>.
1295 return getGetElementPtr(Ty, C, cast<Value>(Idx), NW, InRange,
1296 OnlyIfReducedTy);
1297 }
1298 LLVM_ABI static Constant *
1299 getGetElementPtr(Type *Ty, Constant *C, ArrayRef<Value *> IdxList,
1301 std::optional<ConstantRange> InRange = std::nullopt,
1302 Type *OnlyIfReducedTy = nullptr);
1303
1304 /// Create an "inbounds" getelementptr. See the documentation for the
1305 /// "inbounds" flag in LangRef.html for details.
1307 ArrayRef<Constant *> IdxList) {
1308 return getGetElementPtr(Ty, C, IdxList, GEPNoWrapFlags::inBounds());
1309 }
1311 Constant *Idx) {
1312 // This form of the function only exists to avoid ambiguous overload
1313 // warnings about whether to convert Idx to ArrayRef<Constant *> or
1314 // ArrayRef<Value *>.
1315 return getGetElementPtr(Ty, C, Idx, GEPNoWrapFlags::inBounds());
1316 }
1318 ArrayRef<Value *> IdxList) {
1319 return getGetElementPtr(Ty, C, IdxList, GEPNoWrapFlags::inBounds());
1320 }
1321
1322 LLVM_ABI static Constant *getExtractElement(Constant *Vec, Constant *Idx,
1323 Type *OnlyIfReducedTy = nullptr);
1324 LLVM_ABI static Constant *getInsertElement(Constant *Vec, Constant *Elt,
1325 Constant *Idx,
1326 Type *OnlyIfReducedTy = nullptr);
1327 LLVM_ABI static Constant *getShuffleVector(Constant *V1, Constant *V2,
1328 ArrayRef<int> Mask,
1329 Type *OnlyIfReducedTy = nullptr);
1330
1331 /// Return the opcode at the root of this constant expression
1332 unsigned getOpcode() const { return getSubclassDataFromValue(); }
1333
1334 /// Assert that this is a shufflevector and return the mask. See class
1335 /// ShuffleVectorInst for a description of the mask representation.
1336 LLVM_ABI ArrayRef<int> getShuffleMask() const;
1337
1338 /// Assert that this is a shufflevector and return the mask.
1339 ///
1340 /// TODO: This is a temporary hack until we update the bitcode format for
1341 /// shufflevector.
1342 LLVM_ABI Constant *getShuffleMaskForBitcode() const;
1343
1344 /// Return a string representation for an opcode.
1345 LLVM_ABI const char *getOpcodeName() const;
1346
1347 /// This returns the current constant expression with the operands replaced
1348 /// with the specified values. The specified array must have the same number
1349 /// of operands as our current one.
1353
1354 /// Get the current expression with the operands replaced.
1355 ///
1356 /// Return the current constant expression with the operands replaced with \c
1357 /// Ops and the type with \c Ty. The new operands must have the same number
1358 /// as the current ones.
1359 ///
1360 /// If \c OnlyIfReduced is \c true, nullptr will be returned unless something
1361 /// gets constant-folded, the type changes, or the expression is otherwise
1362 /// canonicalized. This parameter should almost always be \c false.
1363 LLVM_ABI Constant *getWithOperands(ArrayRef<Constant *> Ops, Type *Ty,
1364 bool OnlyIfReduced = false,
1365 Type *SrcTy = nullptr) const;
1366
1367 /// Returns an Instruction which implements the same operation as this
1368 /// ConstantExpr. It is not inserted into any basic block.
1369 ///
1370 /// A better approach to this could be to have a constructor for Instruction
1371 /// which would take a ConstantExpr parameter, but that would have spread
1372 /// implementation details of ConstantExpr outside of Constants.cpp, which
1373 /// would make it harder to remove ConstantExprs altogether.
1374 LLVM_ABI Instruction *getAsInstruction() const;
1375
1376 /// Whether creating a constant expression for this binary operator is
1377 /// desirable.
1378 LLVM_ABI static bool isDesirableBinOp(unsigned Opcode);
1379
1380 /// Whether creating a constant expression for this binary operator is
1381 /// supported.
1382 LLVM_ABI static bool isSupportedBinOp(unsigned Opcode);
1383
1384 /// Whether creating a constant expression for this cast is desirable.
1385 LLVM_ABI static bool isDesirableCastOp(unsigned Opcode);
1386
1387 /// Whether creating a constant expression for this cast is supported.
1388 LLVM_ABI static bool isSupportedCastOp(unsigned Opcode);
1389
1390 /// Whether creating a constant expression for this getelementptr type is
1391 /// supported.
1392 static bool isSupportedGetElementPtr(const Type *SrcElemTy) {
1393 return !SrcElemTy->isScalableTy();
1394 }
1395
1396 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1397 static bool classof(const Value *V) {
1398 return V->getValueID() == ConstantExprVal;
1399 }
1400
1401private:
1402 // Shadow Value::setValueSubclassData with a private forwarding method so that
1403 // subclasses cannot accidentally use it.
1404 void setValueSubclassData(unsigned short D) {
1406 }
1407};
1408
1409template <>
1411 : public VariadicOperandTraits<ConstantExpr> {};
1412
1414
1415//===----------------------------------------------------------------------===//
1416/// 'undef' values are things that do not have specified contents.
1417/// These are used for a variety of purposes, including global variable
1418/// initializers and operands to instructions. 'undef' values can occur with
1419/// any first-class type.
1420///
1421/// Undef values aren't exactly constants; if they have multiple uses, they
1422/// can appear to have different bit patterns at each use. See
1423/// LangRef.html#undefvalues for details.
1424///
1425class UndefValue : public ConstantData {
1426 friend class Constant;
1427
1428 explicit UndefValue(Type *T) : ConstantData(T, UndefValueVal) {}
1429
1430 void destroyConstantImpl();
1431
1432protected:
1433 explicit UndefValue(Type *T, ValueTy vty) : ConstantData(T, vty) {}
1434
1435public:
1436 UndefValue(const UndefValue &) = delete;
1437
1438 /// Static factory methods - Return an 'undef' object of the specified type.
1439 LLVM_ABI static UndefValue *get(Type *T);
1440
1441 /// If this Undef has array or vector type, return a undef with the right
1442 /// element type.
1443 LLVM_ABI UndefValue *getSequentialElement() const;
1444
1445 /// If this undef has struct type, return a undef with the right element type
1446 /// for the specified element.
1447 LLVM_ABI UndefValue *getStructElement(unsigned Elt) const;
1448
1449 /// Return an undef of the right value for the specified GEP index if we can,
1450 /// otherwise return null (e.g. if C is a ConstantExpr).
1451 LLVM_ABI UndefValue *getElementValue(Constant *C) const;
1452
1453 /// Return an undef of the right value for the specified GEP index.
1454 LLVM_ABI UndefValue *getElementValue(unsigned Idx) const;
1455
1456 /// Return the number of elements in the array, vector, or struct.
1457 LLVM_ABI unsigned getNumElements() const;
1458
1459 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1460 static bool classof(const Value *V) {
1461 return V->getValueID() == UndefValueVal ||
1462 V->getValueID() == PoisonValueVal;
1463 }
1464};
1465
1466//===----------------------------------------------------------------------===//
1467/// In order to facilitate speculative execution, many instructions do not
1468/// invoke immediate undefined behavior when provided with illegal operands,
1469/// and return a poison value instead.
1470///
1471/// see LangRef.html#poisonvalues for details.
1472///
1473class PoisonValue final : public UndefValue {
1474 friend class Constant;
1475
1476 explicit PoisonValue(Type *T) : UndefValue(T, PoisonValueVal) {}
1477
1478 void destroyConstantImpl();
1479
1480public:
1481 PoisonValue(const PoisonValue &) = delete;
1482
1483 /// Static factory methods - Return an 'poison' object of the specified type.
1484 LLVM_ABI static PoisonValue *get(Type *T);
1485
1486 /// If this poison has array or vector type, return a poison with the right
1487 /// element type.
1488 LLVM_ABI PoisonValue *getSequentialElement() const;
1489
1490 /// If this poison has struct type, return a poison with the right element
1491 /// type for the specified element.
1492 LLVM_ABI PoisonValue *getStructElement(unsigned Elt) const;
1493
1494 /// Return an poison of the right value for the specified GEP index if we can,
1495 /// otherwise return null (e.g. if C is a ConstantExpr).
1496 LLVM_ABI PoisonValue *getElementValue(Constant *C) const;
1497
1498 /// Return an poison of the right value for the specified GEP index.
1499 LLVM_ABI PoisonValue *getElementValue(unsigned Idx) const;
1500
1501 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1502 static bool classof(const Value *V) {
1503 return V->getValueID() == PoisonValueVal;
1504 }
1505};
1506
1507} // end namespace llvm
1508
1509#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
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)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
#define T
#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
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:344
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition APFloat.cpp:6053
Class for arbitrary precision integers.
Definition APInt.h:78
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
const T * data() const
Definition ArrayRef.h:139
Class to represent array types.
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.
friend class Constant
Definition Constants.h:900
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.
LLVM_ABI ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
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.
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....
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.
static LLVM_ABI ConstantAggregateZero * get(Type *Ty)
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
LLVM_ABI ConstantAggregate(Type *T, ValueTy VT, ArrayRef< Constant * > V, AllocInfo AllocInfo)
friend class Constant
Definition Constants.h:435
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
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.
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 ...
friend class ConstantDataSequential
Definition Constants.h:703
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
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.
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 ...
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.
LLVM_ABI uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
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.
LLVM_ABI bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
LLVM_ABI uint64_t getNumElements() const
Return the number of elements in the array or vector.
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...
static LLVM_ABI Constant * getImpl(StringRef Bytes, Type *Ty)
This is the underlying implementation of all of the ConstantDataSequential::get methods.
LLVM_ABI double getElementAsDouble(uint64_t i) const
If this is an sequential container of doubles, return the specified element as a double.
LLVM_ABI Type * getElementType() const
Return the element type of the array/vector.
LLVM_ABI bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
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.
static LLVM_ABI bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
Definition Constants.h:610
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,...
static LLVM_ABI Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
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.
friend class ConstantDataSequential
Definition Constants.h:777
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...
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...
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
Definition Constants.h:76
friend class Constant
Definition Constants.h:59
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:1125
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ConstantExpr(Type *ty, unsigned Opcode, AllocInfo AllocInfo)
Definition Constants.h:1133
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition Constants.h:1397
static LLVM_ABI Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
static Constant * getNUWSub(Constant *C1, Constant *C2)
Definition Constants.h:1191
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
Definition Constants.h:1306
friend struct ConstantExprKeyType
Definition Constants.h:1126
static LLVM_ABI Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static LLVM_ABI Constant * getTruncOrBitCast(Constant *C, Type *Ty)
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
LLVM_ABI bool isCast() const
Return true if this is a convert constant expression.
static Constant * getNSWAdd(Constant *C1, Constant *C2)
Definition Constants.h:1179
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant)
Transparently provide more efficient getOperand methods.
static LLVM_ABI Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static LLVM_ABI Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getNot(Constant *C)
friend class Constant
Definition Constants.h:1127
static LLVM_ABI Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getPtrToAddr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
Definition Constants.h:1392
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:1288
static LLVM_ABI Constant * getXor(Constant *C1, Constant *C2)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Value * > IdxList)
Definition Constants.h:1317
static Constant * getNSWNeg(Constant *C)
Definition Constants.h:1177
static Constant * getNSWSub(Constant *C1, Constant *C2)
Definition Constants.h:1187
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, Constant *Idx)
Definition Constants.h:1310
static Constant * getNUWAdd(Constant *C1, Constant *C2)
Definition Constants.h:1183
static LLVM_ABI Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
~ConstantExpr()=default
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
Definition Constants.h:1332
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:1279
static LLVM_ABI Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getNeg(Constant *C, bool HasNSW=false)
static LLVM_ABI Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values.
Definition Constants.h:1350
ConstantFP(const ConstantFP &)=delete
const APFloat & getValue() const
Definition Constants.h:321
friend class ConstantVector
Definition Constants.h:279
static LLVM_ABI Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
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
friend class Constant
Definition Constants.h:278
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)
static LLVM_ABI Constant * getZero(Type *Ty, bool Negative=false)
static Constant * getNegativeZero(Type *Ty)
Definition Constants.h:315
static LLVM_ABI Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
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 ...
static LLVM_ABI bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
static LLVM_ABI Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
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
friend class ConstantVector
Definition Constants.h:89
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.
friend class Constant
Definition Constants.h:88
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)
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)
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)
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.
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:1073
friend struct ConstantPtrAuthKeyType
Definition Constants.h:1033
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:1060
friend class Constant
Definition Constants.h:1034
ConstantInt * getKey() const
The Key ID, an i32 constant.
Definition Constants.h:1063
Constant * getDeactivationSymbol() const
Definition Constants.h:1082
bool hasAddressDiscriminator() const
Whether there is any non-null address discriminator.
Definition Constants.h:1078
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
Definition Constants.h:1066
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition Constants.h:1107
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)
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.
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
static LLVM_ABI ConstantTargetNone * get(TargetExtType *T)
Static factory methods - Return objects of the specified value.
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
ConstantTokenNone(const ConstantTokenNone &)=delete
friend class Constant
Definition Constants.h:851
static LLVM_ABI ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
static bool classof(const Value *V)
Methods to support type inquiry through isa, cast, and dyn_cast.
Definition Constants.h:865
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition Constants.h:550
friend class Constant
Definition Constants.h:519
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.
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
Definition Constant.h:43
Constant(Type *ty, ValueTy vty, AllocInfo AllocInfo)
Definition Constant.h:45
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.
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:309
Class to represent fixed width SIMD vectors.
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags inBounds()
static GEPNoWrapFlags none()
Class to represent integer types.
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
friend class Constant
Definition Constants.h:992
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.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
PoisonValue(const PoisonValue &)=delete
friend class Constant
Definition Constants.h:1474
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition Constants.h:1502
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...
LLVM_ABI PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
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....
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Class to represent struct types.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
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.
Definition Type.cpp:61
static Type * getScalarTy(LLVMContext &C)
Definition Type.h:461
LLVM_ABI UndefValue * getElementValue(Constant *C) const
Return an undef of the right value for the specified GEP index if we can, otherwise return null (e....
LLVM_ABI UndefValue * getStructElement(unsigned Elt) const
If this undef has struct type, return a undef with the right element type for the specified element.
UndefValue(const UndefValue &)=delete
friend class Constant
Definition Constants.h:1426
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition Constants.h:1460
UndefValue(Type *T, ValueTy vty)
Definition Constants.h:1433
LLVM_ABI UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
unsigned short getSubclassDataFromValue() const
Definition Value.h:889
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.
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.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
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:115
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...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition Alignment.h:130
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...