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