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