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