LLVM 23.0.0git
Constant.h
Go to the documentation of this file.
1//===- Constant.h -----------------------------------------------*- 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#ifndef LLVM_SANDBOXIR_CONSTANT_H
10#define LLVM_SANDBOXIR_CONSTANT_H
11
12#include "llvm/IR/BasicBlock.h"
13#include "llvm/IR/Constant.h"
14#include "llvm/IR/Constants.h"
15#include "llvm/IR/GlobalAlias.h"
16#include "llvm/IR/GlobalIFunc.h"
18#include "llvm/IR/GlobalValue.h"
23#include "llvm/SandboxIR/Type.h"
24#include "llvm/SandboxIR/User.h"
26
27namespace llvm::sandboxir {
28
29class BasicBlock;
30class Function;
31
32class Constant : public sandboxir::User {
33protected:
38 friend class ConstantInt; // For constructor.
39 friend class Function; // For constructor
40 friend class Context; // For constructor.
41 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const override {
43 }
44
45public:
46 /// For isa/dyn_cast.
47 static bool classof(const sandboxir::Value *From) {
48 switch (From->getSubclassID()) {
49#define DEF_CONST(ID, CLASS) case ClassID::ID:
50#include "llvm/SandboxIR/Values.def"
51 return true;
52 default:
53 return false;
54 }
55 }
57 unsigned getUseOperandNo(const Use &Use) const override {
59 }
60#ifndef NDEBUG
61 void verify() const override {
62 assert(isa<llvm::Constant>(Val) && "Expected Constant!");
63 }
64 void dumpOS(raw_ostream &OS) const override;
65#endif
66};
67
68// TODO: This should inherit from ConstantData.
69class ConstantInt : public Constant {
71 : Constant(ClassID::ConstantInt, C, Ctx) {}
72 friend class Context; // For constructor.
73
74 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
75 llvm_unreachable("ConstantInt has no operands!");
76 }
77
78public:
79 LLVM_ABI static ConstantInt *getTrue(Context &Ctx);
81 LLVM_ABI static ConstantInt *getBool(Context &Ctx, bool V);
82 LLVM_ABI static Constant *getTrue(Type *Ty);
83 LLVM_ABI static Constant *getFalse(Type *Ty);
84 LLVM_ABI static Constant *getBool(Type *Ty, bool V);
85
86 /// If Ty is a vector type, return a Constant with a splat of the given
87 /// value. Otherwise return a ConstantInt for the given value.
88 LLVM_ABI static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false);
89
90 /// Return a ConstantInt with the specified integer value for the specified
91 /// type. If the type is wider than 64 bits, the value will be zero-extended
92 /// to fit the type, unless IsSigned is true, in which case the value will
93 /// be interpreted as a 64-bit signed integer and sign-extended to fit
94 /// the type.
95 /// Get a ConstantInt for a specific value.
97 bool IsSigned = false);
98
99 /// Return a ConstantInt with the specified value for the specified type. The
100 /// value V will be canonicalized to a an unsigned APInt. Accessing it with
101 /// either getSExtValue() or getZExtValue() will yield a correctly sized and
102 /// signed value for the type Ty.
103 /// Get a ConstantInt for a specific signed value.
104 LLVM_ABI static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
105 LLVM_ABI static Constant *getSigned(Type *Ty, int64_t V);
106
107 /// Return a ConstantInt with the specified value and an implied Type. The
108 /// type is the integer type that corresponds to the bit width of the value.
109 LLVM_ABI static ConstantInt *get(Context &Ctx, const APInt &V);
110
111 /// Return a ConstantInt constructed from the string strStart with the given
112 /// radix.
114 uint8_t Radix);
115
116 /// If Ty is a vector type, return a Constant with a splat of the given
117 /// value. Otherwise return a ConstantInt for the given value.
118 LLVM_ABI static Constant *get(Type *Ty, const APInt &V);
119
120 /// Return the constant as an APInt value reference. This allows clients to
121 /// obtain a full-precision copy of the value.
122 /// Return the constant's value.
123 inline const APInt &getValue() const {
124 return cast<llvm::ConstantInt>(Val)->getValue();
125 }
126
127 /// getBitWidth - Return the scalar bitwidth of this constant.
128 unsigned getBitWidth() const {
129 return cast<llvm::ConstantInt>(Val)->getBitWidth();
130 }
131 /// Return the constant as a 64-bit unsigned integer value after it
132 /// has been zero extended as appropriate for the type of this constant. Note
133 /// that this method can assert if the value does not fit in 64 bits.
134 /// Return the zero extended value.
135 inline uint64_t getZExtValue() const {
136 return cast<llvm::ConstantInt>(Val)->getZExtValue();
137 }
138
139 /// Return the constant as a 64-bit integer value after it has been sign
140 /// extended as appropriate for the type of this constant. Note that
141 /// this method can assert if the value does not fit in 64 bits.
142 /// Return the sign extended value.
143 inline int64_t getSExtValue() const {
144 return cast<llvm::ConstantInt>(Val)->getSExtValue();
145 }
146
147 /// Return the constant as an llvm::MaybeAlign.
148 /// Note that this method can assert if the value does not fit in 64 bits or
149 /// is not a power of two.
151 return cast<llvm::ConstantInt>(Val)->getMaybeAlignValue();
152 }
153
154 /// Return the constant as an llvm::Align, interpreting `0` as `Align(1)`.
155 /// Note that this method can assert if the value does not fit in 64 bits or
156 /// is not a power of two.
157 inline Align getAlignValue() const {
158 return cast<llvm::ConstantInt>(Val)->getAlignValue();
159 }
160
161 /// A helper method that can be used to determine if the constant contained
162 /// within is equal to a constant. This only works for very small values,
163 /// because this is all that can be represented with all types.
164 /// Determine if this constant's value is same as an unsigned char.
165 bool equalsInt(uint64_t V) const {
166 return cast<llvm::ConstantInt>(Val)->equalsInt(V);
167 }
168
169 /// Variant of the getType() method to always return an IntegerType, which
170 /// reduces the amount of casting needed in parts of the compiler.
172
173 /// This static method returns true if the type Ty is big enough to
174 /// represent the value V. This can be used to avoid having the get method
175 /// assert when V is larger than Ty can represent. Note that there are two
176 /// versions of this method, one for unsigned and one for signed integers.
177 /// Although ConstantInt canonicalizes everything to an unsigned integer,
178 /// the signed version avoids callers having to convert a signed quantity
179 /// to the appropriate unsigned type before calling the method.
180 /// @returns true if V is a valid value for type Ty
181 /// Determine if the value is in range for the given type.
182 LLVM_ABI static bool isValueValidForType(Type *Ty, uint64_t V);
183 LLVM_ABI static bool isValueValidForType(Type *Ty, int64_t V);
184
185 bool isNegative() const { return cast<llvm::ConstantInt>(Val)->isNegative(); }
186
187 /// This is just a convenience method to make client code smaller for a
188 /// common code. It also correctly performs the comparison without the
189 /// potential for an assertion from getZExtValue().
190 bool isZero() const { return cast<llvm::ConstantInt>(Val)->isZero(); }
191
192 /// This is just a convenience method to make client code smaller for a
193 /// common case. It also correctly performs the comparison without the
194 /// potential for an assertion from getZExtValue().
195 /// Determine if the value is one.
196 bool isOne() const { return cast<llvm::ConstantInt>(Val)->isOne(); }
197
198 /// This function will return true iff every bit in this constant is set
199 /// to true.
200 /// @returns true iff this constant's bits are all set to true.
201 /// Determine if the value is all ones.
202 bool isMinusOne() const { return cast<llvm::ConstantInt>(Val)->isMinusOne(); }
203
204 /// This function will return true iff this constant represents the largest
205 /// value that may be represented by the constant's type.
206 /// @returns true iff this is the largest value that may be represented
207 /// by this type.
208 /// Determine if the value is maximal.
209 bool isMaxValue(bool IsSigned) const {
210 return cast<llvm::ConstantInt>(Val)->isMaxValue(IsSigned);
211 }
212
213 /// This function will return true iff this constant represents the smallest
214 /// value that may be represented by this constant's type.
215 /// @returns true if this is the smallest value that may be represented by
216 /// this type.
217 /// Determine if the value is minimal.
218 bool isMinValue(bool IsSigned) const {
219 return cast<llvm::ConstantInt>(Val)->isMinValue(IsSigned);
220 }
221
222 /// This function will return true iff this constant represents a value with
223 /// active bits bigger than 64 bits or a value greater than the given uint64_t
224 /// value.
225 /// @returns true iff this constant is greater or equal to the given number.
226 /// Determine if the value is greater or equal to the given number.
227 bool uge(uint64_t Num) const {
228 return cast<llvm::ConstantInt>(Val)->uge(Num);
229 }
230
231 /// getLimitedValue - If the value is smaller than the specified limit,
232 /// return it, otherwise return the limit value. This causes the value
233 /// to saturate to the limit.
234 /// @returns the min of the value of the constant and the specified value
235 /// Get the constant's value with a saturation limit
236 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
237 return cast<llvm::ConstantInt>(Val)->getLimitedValue(Limit);
238 }
239
240 /// For isa/dyn_cast.
241 static bool classof(const sandboxir::Value *From) {
242 return From->getSubclassID() == ClassID::ConstantInt;
243 }
244 unsigned getUseOperandNo(const Use &Use) const override {
245 llvm_unreachable("ConstantInt has no operands!");
246 }
247#ifndef NDEBUG
248 void verify() const override {
249 assert(isa<llvm::ConstantInt>(Val) && "Expected a ConstantInst!");
250 }
251 void dumpOS(raw_ostream &OS) const override {
254 }
255#endif
256};
257
258// TODO: This should inherit from ConstantData.
259class ConstantFP final : public Constant {
260 ConstantFP(llvm::ConstantFP *C, Context &Ctx)
261 : Constant(ClassID::ConstantFP, C, Ctx) {}
262 friend class Context; // For constructor.
263
264public:
265 /// This returns a ConstantFP, or a vector containing a splat of a ConstantFP,
266 /// for the specified value in the specified type. This should only be used
267 /// for simple constant values like 2.0/1.0 etc, that are known-valid both as
268 /// host double and as the target format.
269 LLVM_ABI static Constant *get(Type *Ty, double V);
270
271 /// If Ty is a vector type, return a Constant with a splat of the given
272 /// value. Otherwise return a ConstantFP for the given value.
273 LLVM_ABI static Constant *get(Type *Ty, const APFloat &V);
274
275 LLVM_ABI static Constant *get(Type *Ty, StringRef Str);
276
277 LLVM_ABI static ConstantFP *get(const APFloat &V, Context &Ctx);
278
279 LLVM_ABI static Constant *getNaN(Type *Ty, bool Negative = false,
280 uint64_t Payload = 0);
281 LLVM_ABI static Constant *getQNaN(Type *Ty, bool Negative = false,
282 APInt *Payload = nullptr);
283 LLVM_ABI static Constant *getSNaN(Type *Ty, bool Negative = false,
284 APInt *Payload = nullptr);
285 LLVM_ABI static Constant *getZero(Type *Ty, bool Negative = false);
286
288 LLVM_ABI static Constant *getInfinity(Type *Ty, bool Negative = false);
289
290 /// Return true if Ty is big enough to represent V.
291 LLVM_ABI static bool isValueValidForType(Type *Ty, const APFloat &V);
292
293 inline const APFloat &getValueAPF() const {
294 return cast<llvm::ConstantFP>(Val)->getValueAPF();
295 }
296 inline const APFloat &getValue() const {
297 return cast<llvm::ConstantFP>(Val)->getValue();
298 }
299
300 /// Return true if the value is positive or negative zero.
301 bool isZero() const { return cast<llvm::ConstantFP>(Val)->isZero(); }
302
303 /// Return true if the sign bit is set.
304 bool isNegative() const { return cast<llvm::ConstantFP>(Val)->isNegative(); }
305
306 /// Return true if the value is infinity
307 bool isInfinity() const { return cast<llvm::ConstantFP>(Val)->isInfinity(); }
308
309 /// Return true if the value is a NaN.
310 bool isNaN() const { return cast<llvm::ConstantFP>(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 return cast<llvm::ConstantFP>(Val)->isExactlyValue(V);
320 }
321
322 bool isExactlyValue(double V) const {
323 return cast<llvm::ConstantFP>(Val)->isExactlyValue(V);
324 }
325
326 /// For isa/dyn_cast.
327 static bool classof(const sandboxir::Value *From) {
328 return From->getSubclassID() == ClassID::ConstantFP;
329 }
330
331 // TODO: Better name: getOperandNo(const Use&). Should be private.
332 unsigned getUseOperandNo(const Use &Use) const final {
333 llvm_unreachable("ConstantFP has no operands!");
334 }
335#ifndef NDEBUG
336 void verify() const override {
337 assert(isa<llvm::ConstantFP>(Val) && "Expected a ConstantFP!");
338 }
339 void dumpOS(raw_ostream &OS) const override {
342 }
343#endif
344};
345
346/// Base class for aggregate constants (with operands).
348protected:
351
352public:
353 /// For isa/dyn_cast.
354 static bool classof(const sandboxir::Value *From) {
355 auto ID = From->getSubclassID();
356 return ID == ClassID::ConstantVector || ID == ClassID::ConstantStruct ||
357 ID == ClassID::ConstantArray;
358 }
359};
360
361class ConstantArray final : public ConstantAggregate {
363 : ConstantAggregate(ClassID::ConstantArray, C, Ctx) {}
364 friend class Context; // For constructor.
365
366public:
368 LLVM_ABI ArrayType *getType() const;
369
370 // TODO: Missing functions: getType(), getTypeForElements(), getAnon(), get().
371
372 /// For isa/dyn_cast.
373 static bool classof(const Value *From) {
374 return From->getSubclassID() == ClassID::ConstantArray;
375 }
376};
377
378class ConstantStruct final : public ConstantAggregate {
380 : ConstantAggregate(ClassID::ConstantStruct, C, Ctx) {}
381 friend class Context; // For constructor.
382
383public:
385
386 template <typename... Csts>
387 static std::enable_if_t<are_base_of<Constant, Csts...>::value, Constant *>
388 get(StructType *T, Csts *...Vs) {
389 return get(T, ArrayRef<Constant *>({Vs...}));
390 }
391 /// Return an anonymous struct that has the specified elements.
392 /// If the struct is possibly empty, then you must specify a context.
393 static Constant *getAnon(ArrayRef<Constant *> V, bool Packed = false) {
394 return get(getTypeForElements(V, Packed), V);
395 }
397 bool Packed = false) {
398 return get(getTypeForElements(Ctx, V, Packed), V);
399 }
400 /// This version of the method allows an empty list.
401 LLVM_ABI static StructType *
402 getTypeForElements(Context &Ctx, ArrayRef<Constant *> V, bool Packed = false);
403 /// Return an anonymous struct type to use for a constant with the specified
404 /// set of elements. The list must not be empty.
406 bool Packed = false) {
407 assert(!V.empty() &&
408 "ConstantStruct::getTypeForElements cannot be called on empty list");
409 return getTypeForElements(V[0]->getContext(), V, Packed);
410 }
411
412 /// Specialization - reduce amount of casting.
413 inline StructType *getType() const {
415 }
416
417 /// For isa/dyn_cast.
418 static bool classof(const Value *From) {
419 return From->getSubclassID() == ClassID::ConstantStruct;
420 }
421};
422
423class ConstantVector final : public ConstantAggregate {
425 : ConstantAggregate(ClassID::ConstantVector, C, Ctx) {}
426 friend class Context; // For constructor.
427
428public:
430 /// Return a ConstantVector with the specified constant in each element.
431 /// Note that this might not return an instance of ConstantVector
433 /// Specialize the getType() method to always return a FixedVectorType,
434 /// which reduces the amount of casting needed in parts of the compiler.
435 inline FixedVectorType *getType() const {
437 }
438 /// If all elements of the vector constant have the same value, return that
439 /// value. Otherwise, return nullptr. Ignore poison elements by setting
440 /// AllowPoison to true.
441 LLVM_ABI Constant *getSplatValue(bool AllowPoison = false) const;
442
443 /// For isa/dyn_cast.
444 static bool classof(const Value *From) {
445 return From->getSubclassID() == ClassID::ConstantVector;
446 }
447};
448
449// TODO: Inherit from ConstantData.
450class ConstantAggregateZero final : public Constant {
452 : Constant(ClassID::ConstantAggregateZero, C, Ctx) {}
453 friend class Context; // For constructor.
454
455public:
456 LLVM_ABI static ConstantAggregateZero *get(Type *Ty);
457 /// If this CAZ has array or vector type, return a zero with the right element
458 /// type.
460 /// If this CAZ has struct type, return a zero with the right element type for
461 /// the specified element.
462 LLVM_ABI Constant *getStructElement(unsigned Elt) const;
463 /// Return a zero of the right value for the specified GEP index if we can,
464 /// otherwise return null (e.g. if C is a ConstantExpr).
466 /// Return a zero of the right value for the specified GEP index.
467 LLVM_ABI Constant *getElementValue(unsigned Idx) const;
468 /// Return the number of elements in the array, vector, or struct.
470 return cast<llvm::ConstantAggregateZero>(Val)->getElementCount();
471 }
472
473 /// For isa/dyn_cast.
474 static bool classof(const sandboxir::Value *From) {
475 return From->getSubclassID() == ClassID::ConstantAggregateZero;
476 }
477 unsigned getUseOperandNo(const Use &Use) const final {
478 llvm_unreachable("ConstantAggregateZero has no operands!");
479 }
480#ifndef NDEBUG
481 void verify() const override {
482 assert(isa<llvm::ConstantAggregateZero>(Val) && "Expected a CAZ!");
483 }
484 void dumpOS(raw_ostream &OS) const override {
487 }
488#endif
489};
490
491/// ConstantDataSequential - A vector or array constant whose element type is a
492/// simple 1/2/4/8-byte integer or half/bfloat/float/double, and whose elements
493/// are just simple data values (i.e. ConstantInt/ConstantFP). This Constant
494/// node has no operands because it stores all of the elements of the constant
495/// as densely packed data, instead of as Value*'s.
496///
497/// This is the common base class of ConstantDataArray and ConstantDataVector.
499protected:
503
504public:
505 /// Return true if a ConstantDataSequential can be formed with a vector or
506 /// array of the specified element type.
507 /// ConstantDataArray only works with normal float and int types that are
508 /// stored densely in memory, not with things like i42 or x86_f80.
512 /// If this is a sequential container of integers (of any size), return the
513 /// specified element in the low bits of a uint64_t.
514 uint64_t getElementAsInteger(unsigned ElmIdx) const {
515 return cast<llvm::ConstantDataSequential>(Val)->getElementAsInteger(ElmIdx);
516 }
517 /// If this is a sequential container of integers (of any size), return the
518 /// specified element as an APInt.
519 APInt getElementAsAPInt(unsigned ElmIdx) const {
520 return cast<llvm::ConstantDataSequential>(Val)->getElementAsAPInt(ElmIdx);
521 }
522 /// If this is a sequential container of floating point type, return the
523 /// specified element as an APFloat.
524 APFloat getElementAsAPFloat(unsigned ElmIdx) const {
525 return cast<llvm::ConstantDataSequential>(Val)->getElementAsAPFloat(ElmIdx);
526 }
527 /// If this is an sequential container of floats, return the specified element
528 /// as a float.
529 float getElementAsFloat(unsigned ElmIdx) const {
530 return cast<llvm::ConstantDataSequential>(Val)->getElementAsFloat(ElmIdx);
531 }
532 /// If this is an sequential container of doubles, return the specified
533 /// element as a double.
534 double getElementAsDouble(unsigned ElmIdx) const {
535 return cast<llvm::ConstantDataSequential>(Val)->getElementAsDouble(ElmIdx);
536 }
537 /// Return a Constant for a specified index's element.
538 /// Note that this has to compute a new constant to return, so it isn't as
539 /// efficient as getElementAsInteger/Float/Double.
540 Constant *getElementAsConstant(unsigned ElmIdx) const {
541 return Ctx.getOrCreateConstant(
543 }
544 /// Return the element type of the array/vector.
546 return Ctx.getType(
548 }
549 /// Return the number of elements in the array or vector.
550 unsigned getNumElements() const {
551 return cast<llvm::ConstantDataSequential>(Val)->getNumElements();
552 }
553 /// Return the size (in bytes) of each element in the array/vector.
554 /// The size of the elements is known to be a multiple of one byte.
556 return cast<llvm::ConstantDataSequential>(Val)->getElementByteSize();
557 }
558 /// This method returns true if this is an array of \p CharSize integers.
559 bool isString(unsigned CharSize = 8) const {
560 return cast<llvm::ConstantDataSequential>(Val)->isString(CharSize);
561 }
562 /// This method returns true if the array "isString", ends with a null byte,
563 /// and does not contains any other null bytes.
564 bool isCString() const {
565 return cast<llvm::ConstantDataSequential>(Val)->isCString();
566 }
567 /// If this array is isString(), then this method returns the array as a
568 /// StringRef. Otherwise, it asserts out.
570 return cast<llvm::ConstantDataSequential>(Val)->getAsString();
571 }
572 /// If this array is isCString(), then this method returns the array (without
573 /// the trailing null byte) as a StringRef. Otherwise, it asserts out.
575 return cast<llvm::ConstantDataSequential>(Val)->getAsCString();
576 }
577 /// Return the raw, underlying, bytes of this data. Note that this is an
578 /// extremely tricky thing to work with, as it exposes the host endianness of
579 /// the data elements.
581 return cast<llvm::ConstantDataSequential>(Val)->getRawDataValues();
582 }
583
584 static bool classof(const Value *From) {
585 return From->getSubclassID() == ClassID::ConstantDataArray ||
586 From->getSubclassID() == ClassID::ConstantDataVector;
587 }
588};
589
590class ConstantDataArray final : public ConstantDataSequential {
592 : ConstantDataSequential(ClassID::ConstantDataArray, C, Ctx) {}
593 friend class Context;
594
595public:
596 static bool classof(const Value *From) {
597 return From->getSubclassID() == ClassID::ConstantDataArray;
598 }
599 /// get() constructor - Return a constant with array type with an element
600 /// count and element type matching the ArrayRef passed in. Note that this
601 /// can return a ConstantAggregateZero object.
602 template <typename ElementTy>
604 auto *NewLLVMC = llvm::ConstantDataArray::get(Ctx.LLVMCtx, Elts);
605 return Ctx.getOrCreateConstant(NewLLVMC);
606 }
607
608 /// get() constructor - ArrayTy needs to be compatible with
609 /// ArrayRef<ElementTy>.
610 template <typename ArrayTy>
611 static Constant *get(Context &Ctx, ArrayTy &Elts) {
612 return ConstantDataArray::get(Ctx, ArrayRef(Elts));
613 }
614
615 /// getRaw() constructor - Return a constant with array type with an element
616 /// count and element type matching the NumElements and ElementTy parameters
617 /// passed in. Note that this can return a ConstantAggregateZero object.
618 /// ElementTy must be one of i8/i16/i32/i64/half/bfloat/float/double. Data is
619 /// the buffer containing the elements. Be careful to make sure Data uses the
620 /// right endianness, the buffer will be used as-is.
621 static Constant *getRaw(StringRef Data, uint64_t NumElements,
622 Type *ElementTy) {
623 auto *LLVMC =
624 llvm::ConstantDataArray::getRaw(Data, NumElements, ElementTy->LLVMTy);
625 return ElementTy->getContext().getOrCreateConstant(LLVMC);
626 }
627 /// getFP() constructors - Return a constant of array type with a float
628 /// element type taken from argument `ElementType', and count taken from
629 /// argument `Elts'. The amount of bits of the contained type must match the
630 /// number of bits of the type contained in the passed in ArrayRef.
631 /// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note
632 /// that this can return a ConstantAggregateZero object.
633 static Constant *getFP(Type *ElementType, ArrayRef<uint16_t> Elts) {
634 auto *LLVMC = llvm::ConstantDataArray::getFP(ElementType->LLVMTy, Elts);
635 return ElementType->getContext().getOrCreateConstant(LLVMC);
636 }
637 static Constant *getFP(Type *ElementType, ArrayRef<uint32_t> Elts) {
638 auto *LLVMC = llvm::ConstantDataArray::getFP(ElementType->LLVMTy, Elts);
639 return ElementType->getContext().getOrCreateConstant(LLVMC);
640 }
641 static Constant *getFP(Type *ElementType, ArrayRef<uint64_t> Elts) {
642 auto *LLVMC = llvm::ConstantDataArray::getFP(ElementType->LLVMTy, Elts);
643 return ElementType->getContext().getOrCreateConstant(LLVMC);
644 }
645 /// This method constructs a CDS and initializes it with a text string.
646 /// The default behavior (AddNull==true) causes a null terminator to
647 /// be placed at the end of the array (increasing the length of the string by
648 /// one more than the StringRef would normally indicate. Pass AddNull=false
649 /// to disable this behavior.
650 static Constant *getString(Context &Ctx, StringRef Initializer,
651 bool AddNull = true) {
652 auto *LLVMC =
653 llvm::ConstantDataArray::getString(Ctx.LLVMCtx, Initializer, AddNull);
654 return Ctx.getOrCreateConstant(LLVMC);
655 }
656
657 /// Specialize the getType() method to always return an ArrayType,
658 /// which reduces the amount of casting needed in parts of the compiler.
659 inline ArrayType *getType() const {
661 }
662};
663
664/// A vector constant whose element type is a simple 1/2/4/8-byte integer or
665/// float/double, and whose elements are just simple data values
666/// (i.e. ConstantInt/ConstantFP). This Constant node has no operands because it
667/// stores all of the elements of the constant as densely packed data, instead
668/// of as Value*'s.
669class ConstantDataVector final : public ConstantDataSequential {
671 : ConstantDataSequential(ClassID::ConstantDataVector, C, Ctx) {}
672 friend class Context;
673
674public:
675 /// Methods for support type inquiry through isa, cast, and dyn_cast:
676 static bool classof(const Value *From) {
677 return From->getSubclassID() == ClassID::ConstantDataVector;
678 }
679 /// get() constructors - Return a constant with vector type with an element
680 /// count and element type matching the ArrayRef passed in. Note that this
681 /// can return a ConstantAggregateZero object.
683 auto *NewLLVMC = llvm::ConstantDataVector::get(Ctx.LLVMCtx, Elts);
684 return Ctx.getOrCreateConstant(NewLLVMC);
685 }
687 auto *NewLLVMC = llvm::ConstantDataVector::get(Ctx.LLVMCtx, Elts);
688 return Ctx.getOrCreateConstant(NewLLVMC);
689 }
691 auto *NewLLVMC = llvm::ConstantDataVector::get(Ctx.LLVMCtx, Elts);
692 return Ctx.getOrCreateConstant(NewLLVMC);
693 }
695 auto *NewLLVMC = llvm::ConstantDataVector::get(Ctx.LLVMCtx, Elts);
696 return Ctx.getOrCreateConstant(NewLLVMC);
697 }
699 auto *NewLLVMC = llvm::ConstantDataVector::get(Ctx.LLVMCtx, Elts);
700 return Ctx.getOrCreateConstant(NewLLVMC);
701 }
703 auto *NewLLVMC = llvm::ConstantDataVector::get(Ctx.LLVMCtx, Elts);
704 return Ctx.getOrCreateConstant(NewLLVMC);
705 }
706
707 /// getRaw() constructor - Return a constant with vector type with an element
708 /// count and element type matching the NumElements and ElementTy parameters
709 /// passed in. Note that this can return a ConstantAggregateZero object.
710 /// ElementTy must be one of i8/i16/i32/i64/half/bfloat/float/double. Data is
711 /// the buffer containing the elements. Be careful to make sure Data uses the
712 /// right endianness, the buffer will be used as-is.
713 static Constant *getRaw(StringRef Data, uint64_t NumElements,
714 Type *ElementTy) {
715 auto *NewLLVMC =
716 llvm::ConstantDataVector::getRaw(Data, NumElements, ElementTy->LLVMTy);
717 return ElementTy->getContext().getOrCreateConstant(NewLLVMC);
718 }
719 /// getFP() constructors - Return a constant of vector type with a float
720 /// element type taken from argument `ElementType', and count taken from
721 /// argument `Elts'. The amount of bits of the contained type must match the
722 /// number of bits of the type contained in the passed in ArrayRef.
723 /// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note
724 /// that this can return a ConstantAggregateZero object.
725 static Constant *getFP(Type *ElementType, ArrayRef<uint16_t> Elts) {
726 auto *NewLLVMC = llvm::ConstantDataVector::getFP(ElementType->LLVMTy, Elts);
727 return ElementType->getContext().getOrCreateConstant(NewLLVMC);
728 }
729 static Constant *getFP(Type *ElementType, ArrayRef<uint32_t> Elts) {
730 auto *NewLLVMC = llvm::ConstantDataVector::getFP(ElementType->LLVMTy, Elts);
731 return ElementType->getContext().getOrCreateConstant(NewLLVMC);
732 }
733 static Constant *getFP(Type *ElementType, ArrayRef<uint64_t> Elts) {
734 auto *NewLLVMC = llvm::ConstantDataVector::getFP(ElementType->LLVMTy, Elts);
735 return ElementType->getContext().getOrCreateConstant(NewLLVMC);
736 }
737
738 /// Return a ConstantVector with the specified constant in each element.
739 /// The specified constant has to be a of a compatible type (i8/i16/
740 /// i32/i64/half/bfloat/float/double) and must be a ConstantFP or ConstantInt.
741 static Constant *getSplat(unsigned NumElts, Constant *Elt) {
742 auto *NewLLVMC = llvm::ConstantDataVector::getSplat(
743 NumElts, cast<llvm::Constant>(Elt->Val));
744 return Elt->getContext().getOrCreateConstant(NewLLVMC);
745 }
746
747 /// Returns true if this is a splat constant, meaning that all elements have
748 /// the same value.
749 bool isSplat() const {
750 return cast<llvm::ConstantDataVector>(Val)->isSplat();
751 }
752
753 /// If this is a splat constant, meaning that all of the elements have the
754 /// same value, return that value. Otherwise return NULL.
756 return Ctx.getOrCreateConstant(
758 }
759
760 /// Specialize the getType() method to always return a FixedVectorType,
761 /// which reduces the amount of casting needed in parts of the compiler.
762 inline FixedVectorType *getType() const {
764 }
765};
766
767// TODO: Inherit from ConstantData.
768class ConstantPointerNull final : public Constant {
770 : Constant(ClassID::ConstantPointerNull, C, Ctx) {}
771 friend class Context; // For constructor.
772
773public:
774 LLVM_ABI static ConstantPointerNull *get(PointerType *Ty);
775
776 LLVM_ABI Type *getType() const;
778
779 /// For isa/dyn_cast.
780 static bool classof(const sandboxir::Value *From) {
781 return From->getSubclassID() == ClassID::ConstantPointerNull;
782 }
783 unsigned getUseOperandNo(const Use &Use) const final {
784 llvm_unreachable("ConstantPointerNull has no operands!");
785 }
786#ifndef NDEBUG
787 void verify() const override {
788 assert(isa<llvm::ConstantPointerNull>(Val) && "Expected a CPNull!");
789 }
790 void dumpOS(raw_ostream &OS) const override {
793 }
794#endif
795};
796
797// TODO: Inherit from ConstantData.
798class UndefValue : public Constant {
799protected:
804 friend class Context; // For constructor.
805
806public:
807 /// Static factory methods - Return an 'undef' object of the specified type.
808 LLVM_ABI static UndefValue *get(Type *T);
809
810 /// If this Undef has array or vector type, return a undef with the right
811 /// element type.
813
814 /// If this undef has struct type, return a undef with the right element type
815 /// for the specified element.
816 LLVM_ABI UndefValue *getStructElement(unsigned Elt) const;
817
818 /// Return an undef of the right value for the specified GEP index if we can,
819 /// otherwise return null (e.g. if C is a ConstantExpr).
821
822 /// Return an undef of the right value for the specified GEP index.
823 LLVM_ABI UndefValue *getElementValue(unsigned Idx) const;
824
825 /// Return the number of elements in the array, vector, or struct.
826 unsigned getNumElements() const {
827 return cast<llvm::UndefValue>(Val)->getNumElements();
828 }
829
830 /// For isa/dyn_cast.
831 static bool classof(const sandboxir::Value *From) {
832 return From->getSubclassID() == ClassID::UndefValue ||
833 From->getSubclassID() == ClassID::PoisonValue;
834 }
835 unsigned getUseOperandNo(const Use &Use) const final {
836 llvm_unreachable("UndefValue has no operands!");
837 }
838#ifndef NDEBUG
839 void verify() const override {
840 assert(isa<llvm::UndefValue>(Val) && "Expected an UndefValue!");
841 }
842 void dumpOS(raw_ostream &OS) const override {
845 }
846#endif
847};
848
849class PoisonValue final : public UndefValue {
851 : UndefValue(ClassID::PoisonValue, C, Ctx) {}
852 friend class Context; // For constructor.
853
854public:
855 /// Static factory methods - Return an 'poison' object of the specified type.
856 LLVM_ABI static PoisonValue *get(Type *T);
857
858 /// If this poison has array or vector type, return a poison with the right
859 /// element type.
860 LLVM_ABI PoisonValue *getSequentialElement() const;
861
862 /// If this poison has struct type, return a poison with the right element
863 /// type for the specified element.
864 LLVM_ABI PoisonValue *getStructElement(unsigned Elt) const;
865
866 /// Return an poison of the right value for the specified GEP index if we can,
867 /// otherwise return null (e.g. if C is a ConstantExpr).
868 LLVM_ABI PoisonValue *getElementValue(Constant *C) const;
869
870 /// Return an poison of the right value for the specified GEP index.
871 LLVM_ABI PoisonValue *getElementValue(unsigned Idx) const;
872
873 /// For isa/dyn_cast.
874 static bool classof(const sandboxir::Value *From) {
875 return From->getSubclassID() == ClassID::PoisonValue;
876 }
877#ifndef NDEBUG
878 void verify() const override {
879 assert(isa<llvm::PoisonValue>(Val) && "Expected a PoisonValue!");
880 }
881 void dumpOS(raw_ostream &OS) const override {
884 }
885#endif
886};
887
888class GlobalValue : public Constant {
889protected:
892 friend class Context; // For constructor.
893
894public:
896 /// For isa/dyn_cast.
897 static bool classof(const sandboxir::Value *From) {
898 switch (From->getSubclassID()) {
899 case ClassID::Function:
900 case ClassID::GlobalVariable:
901 case ClassID::GlobalAlias:
902 case ClassID::GlobalIFunc:
903 return true;
904 default:
905 return false;
906 }
907 }
908
909 unsigned getAddressSpace() const {
910 return cast<llvm::GlobalValue>(Val)->getAddressSpace();
911 }
912 bool hasGlobalUnnamedAddr() const {
913 return cast<llvm::GlobalValue>(Val)->hasGlobalUnnamedAddr();
914 }
915
916 /// Returns true if this value's address is not significant in this module.
917 /// This attribute is intended to be used only by the code generator and LTO
918 /// to allow the linker to decide whether the global needs to be in the symbol
919 /// table. It should probably not be used in optimizations, as the value may
920 /// have uses outside the module; use hasGlobalUnnamedAddr() instead.
922 return cast<llvm::GlobalValue>(Val)->hasAtLeastLocalUnnamedAddr();
923 }
924
926
928 return cast<llvm::GlobalValue>(Val)->getUnnamedAddr();
929 }
931
935
936 bool hasComdat() const { return cast<llvm::GlobalValue>(Val)->hasComdat(); }
937
938 // TODO: We need a SandboxIR Comdat if we want to implement getComdat().
941 return cast<llvm::GlobalValue>(Val)->getVisibility();
942 }
943 bool hasDefaultVisibility() const {
944 return cast<llvm::GlobalValue>(Val)->hasDefaultVisibility();
945 }
946 bool hasHiddenVisibility() const {
947 return cast<llvm::GlobalValue>(Val)->hasHiddenVisibility();
948 }
950 return cast<llvm::GlobalValue>(Val)->hasProtectedVisibility();
951 }
953
954 // TODO: Add missing functions.
955};
956
957class GlobalObject : public GlobalValue {
958protected:
961 friend class Context; // For constructor.
962 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
964 }
965
966public:
967 unsigned getUseOperandNo(const Use &Use) const final {
969 }
970 /// For isa/dyn_cast.
971 static bool classof(const sandboxir::Value *From) {
972 switch (From->getSubclassID()) {
973 case ClassID::Function:
974 case ClassID::GlobalVariable:
975 case ClassID::GlobalIFunc:
976 return true;
977 default:
978 return false;
979 }
980 }
981
982 /// Check if this global has a custom object file section.
983 ///
984 /// This is more efficient than calling getSection() and checking for an empty
985 /// string.
986 bool hasSection() const {
987 return cast<llvm::GlobalObject>(Val)->hasSection();
988 }
989
990 /// Get the custom section of this global if it has one.
991 ///
992 /// If this global does not have a custom section, this will be empty and the
993 /// default object file section (.text, .data, etc) will be used.
995 return cast<llvm::GlobalObject>(Val)->getSection();
996 }
997
998 /// Change the section for this global.
999 ///
1000 /// Setting the section to the empty string tells LLVM to choose an
1001 /// appropriate default object file section.
1003
1004 bool hasComdat() const { return cast<llvm::GlobalObject>(Val)->hasComdat(); }
1005
1006 // TODO: implement get/setComdat(), etc. once we have a sandboxir::Comdat.
1007
1008 // TODO: We currently don't support Metadata in sandboxir so all
1009 // Metadata-related functions are missing.
1010
1012
1014 return cast<llvm::GlobalObject>(Val)->getVCallVisibility();
1015 }
1016
1017 /// Returns true if the alignment of the value can be unilaterally
1018 /// increased.
1019 ///
1020 /// Note that for functions this is the alignment of the code, not the
1021 /// alignment of a function pointer.
1023 return cast<llvm::GlobalObject>(Val)->canIncreaseAlignment();
1024 }
1025};
1026
1027/// Provides API functions, like getIterator() and getReverseIterator() to
1028/// GlobalIFunc, Function, GlobalVariable and GlobalAlias. In LLVM IR these are
1029/// provided by ilist_node.
1030template <typename GlobalT, typename LLVMGlobalT, typename ParentT,
1031 typename LLVMParentT>
1033 /// Helper for mapped_iterator.
1034 struct LLVMGVToGV {
1035 Context &Ctx;
1036 LLVMGVToGV(Context &Ctx) : Ctx(Ctx) {}
1037 LLVM_ABI GlobalT &operator()(LLVMGlobalT &LLVMGV) const;
1038 };
1039
1040public:
1042 : ParentT(ID, C, Ctx) {}
1043
1045 llvm::Module *LLVMM = cast<LLVMGlobalT>(this->Val)->getParent();
1046 return this->Ctx.getModule(LLVMM);
1047 }
1048
1050 decltype(static_cast<LLVMGlobalT *>(nullptr)->getIterator()), LLVMGVToGV>;
1052 decltype(static_cast<LLVMGlobalT *>(nullptr)->getReverseIterator()),
1053 LLVMGVToGV>;
1055 auto *LLVMGV = cast<LLVMGlobalT>(this->Val);
1056 LLVMGVToGV ToGV(this->Ctx);
1057 return map_iterator(LLVMGV->getIterator(), ToGV);
1058 }
1060 auto *LLVMGV = cast<LLVMGlobalT>(this->Val);
1061 LLVMGVToGV ToGV(this->Ctx);
1062 return map_iterator(LLVMGV->getReverseIterator(), ToGV);
1063 }
1064};
1065
1066// Explicit instantiations.
1067extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
1069extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
1071extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
1073extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
1075
1076class GlobalIFunc final
1077 : public GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
1078 llvm::GlobalObject> {
1080 : GlobalWithNodeAPI(ClassID::GlobalIFunc, C, Ctx) {}
1081 friend class Context; // For constructor.
1082
1083public:
1084 /// For isa/dyn_cast.
1085 static bool classof(const sandboxir::Value *From) {
1086 return From->getSubclassID() == ClassID::GlobalIFunc;
1087 }
1088
1089 // TODO: Missing create() because we don't have a sandboxir::Module yet.
1090
1091 // TODO: Missing functions: copyAttributesFrom(), removeFromParent(),
1092 // eraseFromParent()
1093
1095
1096 LLVM_ABI Constant *getResolver() const;
1097
1098 // Return the resolver function after peeling off potential ConstantExpr
1099 // indirection.
1102 return const_cast<GlobalIFunc *>(this)->getResolverFunction();
1103 }
1104
1107 }
1108
1109 // TODO: Missing applyAlongResolverPath().
1110
1111#ifndef NDEBUG
1112 void verify() const override {
1113 assert(isa<llvm::GlobalIFunc>(Val) && "Expected a GlobalIFunc!");
1114 }
1115 void dumpOS(raw_ostream &OS) const override {
1116 dumpCommonPrefix(OS);
1117 dumpCommonSuffix(OS);
1118 }
1119#endif
1120};
1121
1122class GlobalVariable final
1123 : public GlobalWithNodeAPI<GlobalVariable, llvm::GlobalVariable,
1124 GlobalObject, llvm::GlobalObject> {
1126 : GlobalWithNodeAPI(ClassID::GlobalVariable, C, Ctx) {}
1127 friend class Context; // For constructor.
1128
1129 /// Helper for mapped_iterator.
1130 struct LLVMGVToGV {
1131 Context &Ctx;
1132 LLVMGVToGV(Context &Ctx) : Ctx(Ctx) {}
1133 LLVM_ABI GlobalVariable &operator()(llvm::GlobalVariable &LLVMGV) const;
1134 };
1135
1136public:
1137 /// For isa/dyn_cast.
1138 static bool classof(const sandboxir::Value *From) {
1139 return From->getSubclassID() == ClassID::GlobalVariable;
1140 }
1141
1142 /// Definitions have initializers, declarations don't.
1143 ///
1144 inline bool hasInitializer() const {
1145 return cast<llvm::GlobalVariable>(Val)->hasInitializer();
1146 }
1147
1148 /// hasDefinitiveInitializer - Whether the global variable has an initializer,
1149 /// and any other instances of the global (this can happen due to weak
1150 /// linkage) are guaranteed to have the same initializer.
1151 ///
1152 /// Note that if you want to transform a global, you must use
1153 /// hasUniqueInitializer() instead, because of the *_odr linkage type.
1154 ///
1155 /// Example:
1156 ///
1157 /// @a = global SomeType* null - Initializer is both definitive and unique.
1158 ///
1159 /// @b = global weak SomeType* null - Initializer is neither definitive nor
1160 /// unique.
1161 ///
1162 /// @c = global weak_odr SomeType* null - Initializer is definitive, but not
1163 /// unique.
1164 inline bool hasDefinitiveInitializer() const {
1165 return cast<llvm::GlobalVariable>(Val)->hasDefinitiveInitializer();
1166 }
1167
1168 /// hasUniqueInitializer - Whether the global variable has an initializer, and
1169 /// any changes made to the initializer will turn up in the final executable.
1170 inline bool hasUniqueInitializer() const {
1171 return cast<llvm::GlobalVariable>(Val)->hasUniqueInitializer();
1172 }
1173
1174 /// getInitializer - Return the initializer for this global variable. It is
1175 /// illegal to call this method if the global is external, because we cannot
1176 /// tell what the value is initialized to!
1177 ///
1179 /// setInitializer - Sets the initializer for this global variable, removing
1180 /// any existing initializer if InitVal==NULL. The initializer must have the
1181 /// type getValueType().
1182 LLVM_ABI void setInitializer(Constant *InitVal);
1183
1184 // TODO: Add missing replaceInitializer(). Requires special tracker
1185
1186 /// If the value is a global constant, its value is immutable throughout the
1187 /// runtime execution of the program. Assigning a value into the constant
1188 /// leads to undefined behavior.
1189 ///
1190 bool isConstant() const {
1191 return cast<llvm::GlobalVariable>(Val)->isConstant();
1192 }
1193 LLVM_ABI void setConstant(bool V);
1194
1196 return cast<llvm::GlobalVariable>(Val)->isExternallyInitialized();
1197 }
1199
1200 // TODO: Missing copyAttributesFrom()
1201
1202 // TODO: Missing removeFromParent(), eraseFromParent(), dropAllReferences()
1203
1204 // TODO: Missing addDebugInfo(), getDebugInfo()
1205
1206 // TODO: Missing attribute setter functions: addAttribute(), setAttributes().
1207 // There seems to be no removeAttribute() so we can't undo them.
1208
1209 /// Return true if the attribute exists.
1211 return cast<llvm::GlobalVariable>(Val)->hasAttribute(Kind);
1212 }
1213
1214 /// Return true if the attribute exists.
1215 bool hasAttribute(StringRef Kind) const {
1216 return cast<llvm::GlobalVariable>(Val)->hasAttribute(Kind);
1217 }
1218
1219 /// Return true if any attributes exist.
1220 bool hasAttributes() const {
1221 return cast<llvm::GlobalVariable>(Val)->hasAttributes();
1222 }
1223
1224 /// Return the attribute object.
1226 return cast<llvm::GlobalVariable>(Val)->getAttribute(Kind);
1227 }
1228
1229 /// Return the attribute object.
1231 return cast<llvm::GlobalVariable>(Val)->getAttribute(Kind);
1232 }
1233
1234 /// Return the attribute set for this global
1236 return cast<llvm::GlobalVariable>(Val)->getAttributes();
1237 }
1238
1239 /// Return attribute set as list with index.
1240 /// FIXME: This may not be required once ValueEnumerators
1241 /// in bitcode-writer can enumerate attribute-set.
1242 AttributeList getAttributesAsList(unsigned Index) const {
1243 return cast<llvm::GlobalVariable>(Val)->getAttributesAsList(Index);
1244 }
1245
1246 /// Check if section name is present
1247 bool hasImplicitSection() const {
1248 return cast<llvm::GlobalVariable>(Val)->hasImplicitSection();
1249 }
1250
1251 /// Get the custom code model raw value of this global.
1252 ///
1253 unsigned getCodeModelRaw() const {
1254 return cast<llvm::GlobalVariable>(Val)->getCodeModelRaw();
1255 }
1256
1257 /// Get the custom code model of this global if it has one.
1258 ///
1259 /// If this global does not have a custom code model, the empty instance
1260 /// will be returned.
1261 std::optional<CodeModel::Model> getCodeModel() const {
1262 return cast<llvm::GlobalVariable>(Val)->getCodeModel();
1263 }
1264
1265 /// Returns the alignment of the given variable.
1267 return cast<llvm::GlobalVariable>(Val)->getAlign();
1268 }
1269
1270 // TODO: Add missing: setAligment(Align)
1271
1272 /// Sets the alignment attribute of the GlobalVariable.
1273 /// This method will be deprecated as the alignment property should always be
1274 /// defined.
1276
1277 // TODO: Missing setCodeModel(). Requires custom tracker.
1278
1279#ifndef NDEBUG
1280 void verify() const override {
1281 assert(isa<llvm::GlobalVariable>(Val) && "Expected a GlobalVariable!");
1282 }
1283 void dumpOS(raw_ostream &OS) const override {
1284 dumpCommonPrefix(OS);
1285 dumpCommonSuffix(OS);
1286 }
1287#endif
1288};
1289
1290class GlobalAlias final
1291 : public GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
1292 llvm::GlobalValue> {
1294 : GlobalWithNodeAPI(ClassID::GlobalAlias, C, Ctx) {}
1295 friend class Context; // For constructor.
1296
1297public:
1298 /// For isa/dyn_cast.
1299 static bool classof(const sandboxir::Value *From) {
1300 return From->getSubclassID() == ClassID::GlobalAlias;
1301 }
1302
1303 // TODO: Missing create() due to unimplemented sandboxir::Module.
1304
1305 // TODO: Missing copyAttributresFrom().
1306 // TODO: Missing removeFromParent(), eraseFromParent().
1307
1308 LLVM_ABI void setAliasee(Constant *Aliasee);
1309 LLVM_ABI Constant *getAliasee() const;
1310
1311 LLVM_ABI const GlobalObject *getAliaseeObject() const;
1313 return const_cast<GlobalObject *>(
1314 static_cast<const GlobalAlias *>(this)->getAliaseeObject());
1315 }
1316
1319 }
1320};
1321
1322class NoCFIValue final : public Constant {
1324 : Constant(ClassID::NoCFIValue, C, Ctx) {}
1325 friend class Context; // For constructor.
1326
1327 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
1329 }
1330
1331public:
1332 /// Return a NoCFIValue for the specified function.
1333 LLVM_ABI static NoCFIValue *get(GlobalValue *GV);
1334
1336
1337 /// NoCFIValue is always a pointer.
1338 LLVM_ABI PointerType *getType() const;
1339 /// For isa/dyn_cast.
1340 static bool classof(const sandboxir::Value *From) {
1341 return From->getSubclassID() == ClassID::NoCFIValue;
1342 }
1343
1344 unsigned getUseOperandNo(const Use &Use) const final {
1346 }
1347
1348#ifndef NDEBUG
1349 void verify() const override {
1350 assert(isa<llvm::NoCFIValue>(Val) && "Expected a NoCFIValue!");
1351 }
1352 void dumpOS(raw_ostream &OS) const override {
1353 dumpCommonPrefix(OS);
1354 dumpCommonSuffix(OS);
1355 }
1356#endif
1357};
1358
1359class ConstantPtrAuth final : public Constant {
1361 : Constant(ClassID::ConstantPtrAuth, C, Ctx) {}
1362 friend class Context; // For constructor.
1363
1364public:
1365 /// Return a pointer signed with the specified parameters.
1366 LLVM_ABI static ConstantPtrAuth *get(Constant *Ptr, ConstantInt *Key,
1367 ConstantInt *Disc, Constant *AddrDisc,
1368 Constant *DeactivationSymbol);
1369 /// The pointer that is signed in this ptrauth signed pointer.
1370 LLVM_ABI Constant *getPointer() const;
1371
1372 /// The Key ID, an i32 constant.
1373 LLVM_ABI ConstantInt *getKey() const;
1374
1375 /// The integer discriminator, an i64 constant, or 0.
1377
1378 /// The address discriminator if any, or the null constant.
1379 /// If present, this must be a value equivalent to the storage location of
1380 /// the only global-initializer user of the ptrauth signed pointer.
1382
1384
1385 /// Whether there is any non-null address discriminator.
1387 return cast<llvm::ConstantPtrAuth>(Val)->hasAddressDiscriminator();
1388 }
1389
1390 /// Whether the address uses a special address discriminator.
1391 /// These discriminators can't be used in real pointer-auth values; they
1392 /// can only be used in "prototype" values that indicate how some real
1393 /// schema is supposed to be produced.
1395 return cast<llvm::ConstantPtrAuth>(Val)->hasSpecialAddressDiscriminator(
1396 Value);
1397 }
1398
1399 /// Check whether an authentication operation with key \p Key and (possibly
1400 /// blended) discriminator \p Discriminator is known to be compatible with
1401 /// this ptrauth signed pointer.
1402 bool isKnownCompatibleWith(const Value *Key, const Value *Discriminator,
1403 const DataLayout &DL) const {
1404 return cast<llvm::ConstantPtrAuth>(Val)->isKnownCompatibleWith(
1405 Key->Val, Discriminator->Val, DL);
1406 }
1407
1408 /// Produce a new ptrauth expression signing the given value using
1409 /// the same schema as is stored in one.
1411
1412 /// For isa/dyn_cast.
1413 static bool classof(const sandboxir::Value *From) {
1414 return From->getSubclassID() == ClassID::ConstantPtrAuth;
1415 }
1416};
1417
1418class ConstantExpr : public Constant {
1420 : Constant(ClassID::ConstantExpr, C, Ctx) {}
1421 friend class Context; // For constructor.
1422
1423public:
1424 /// For isa/dyn_cast.
1425 static bool classof(const sandboxir::Value *From) {
1426 return From->getSubclassID() == ClassID::ConstantExpr;
1427 }
1428 // TODO: Missing functions.
1429};
1430
1431class BlockAddress final : public Constant {
1433 : Constant(ClassID::BlockAddress, C, Ctx) {}
1434 friend class Context; // For constructor.
1435
1436public:
1437 /// Return a BlockAddress for the specified function and basic block.
1438 LLVM_ABI static BlockAddress *get(Function *F, BasicBlock *BB);
1439
1440 /// Return a BlockAddress for the specified basic block. The basic
1441 /// block must be embedded into a function.
1442 LLVM_ABI static BlockAddress *get(BasicBlock *BB);
1443
1444 /// Lookup an existing \c BlockAddress constant for the given BasicBlock.
1445 ///
1446 /// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
1447 LLVM_ABI static BlockAddress *lookup(const BasicBlock *BB);
1448
1449 LLVM_ABI Function *getFunction() const;
1451
1452 /// For isa/dyn_cast.
1453 static bool classof(const sandboxir::Value *From) {
1454 return From->getSubclassID() == ClassID::BlockAddress;
1455 }
1456};
1457
1458class DSOLocalEquivalent final : public Constant {
1460 : Constant(ClassID::DSOLocalEquivalent, C, Ctx) {}
1461 friend class Context; // For constructor.
1462
1463public:
1464 /// Return a DSOLocalEquivalent for the specified global value.
1465 LLVM_ABI static DSOLocalEquivalent *get(GlobalValue *GV);
1466
1468
1469 /// For isa/dyn_cast.
1470 static bool classof(const sandboxir::Value *From) {
1471 return From->getSubclassID() == ClassID::DSOLocalEquivalent;
1472 }
1473
1474 unsigned getUseOperandNo(const Use &Use) const final {
1475 llvm_unreachable("DSOLocalEquivalent has no operands!");
1476 }
1477
1478#ifndef NDEBUG
1479 void verify() const override {
1481 "Expected a DSOLocalEquivalent!");
1482 }
1483 void dumpOS(raw_ostream &OS) const override {
1484 dumpCommonPrefix(OS);
1485 dumpCommonSuffix(OS);
1486 }
1487#endif
1488};
1489
1490// TODO: This should inherit from ConstantData.
1491class ConstantTokenNone final : public Constant {
1492 ConstantTokenNone(llvm::ConstantTokenNone *C, Context &Ctx)
1493 : Constant(ClassID::ConstantTokenNone, C, Ctx) {}
1494 friend class Context; // For constructor.
1495
1496public:
1497 /// Return the ConstantTokenNone.
1498 LLVM_ABI static ConstantTokenNone *get(Context &Ctx);
1499
1500 /// For isa/dyn_cast.
1501 static bool classof(const sandboxir::Value *From) {
1502 return From->getSubclassID() == ClassID::ConstantTokenNone;
1503 }
1504
1505 unsigned getUseOperandNo(const Use &Use) const final {
1506 llvm_unreachable("ConstantTokenNone has no operands!");
1507 }
1508
1509#ifndef NDEBUG
1510 void verify() const override {
1512 "Expected a ConstantTokenNone!");
1513 }
1514 void dumpOS(raw_ostream &OS) const override {
1515 dumpCommonPrefix(OS);
1516 dumpCommonSuffix(OS);
1517 }
1518#endif
1519};
1520
1521} // namespace llvm::sandboxir
1522
1523#endif // LLVM_SANDBOXIR_CONSTANT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_TEMPLATE_ABI
Definition Compiler.h:214
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
#define F(x, y, z)
Definition MD5.cpp:54
#define T
MachineInstr unsigned OpIdx
ppc ctr loops PowerPC CTR Loops Verify
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
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:407
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:124
The address of a basic block.
Definition Constants.h:1071
All zero aggregate value.
Definition Constants.h:505
ConstantArray - Constant Array Declarations.
Definition Constants.h:579
An array constant whose element type is a simple 1/2/4/8-byte integer, bytes or float/double,...
Definition Constants.h:852
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:865
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 ...
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.
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:884
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Definition Constants.h:742
static LLVM_ABI bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
Definition Constants.h:938
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:968
static LLVM_ABI Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
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...
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1297
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
This is the shared class of boolean and integer constants.
Definition Constants.h:87
A constant pointer value that points to null.
Definition Constants.h:705
A signed pointer, in the ptrauth sense.
Definition Constants.h:1204
A constant token which is empty.
Definition Constants.h:1022
Constant Vector Declarations.
Definition Constants.h:663
This is an important base class in LLVM.
Definition Constant.h:43
Wrapper for a function that represents a value that functionally represents the original function.
Definition Constants.h:1124
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
static bool isValidLinkage(LinkageTypes L)
Definition GlobalAlias.h:98
static bool isValidLinkage(LinkageTypes L)
Definition GlobalIFunc.h:86
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition GlobalValue.h:67
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition GlobalValue.h:52
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Wrapper for a value that won't be replaced with a CFI jump table pointer in LowerTypeTestsModule.
Definition Constants.h:1163
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
Definition Constants.h:1660
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition Record.h:2199
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
'undef' values are things that do not have specified contents.
Definition Constants.h:1612
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Definition Constant.cpp:470
LLVM_ABI Function * getFunction() const
Definition Constant.cpp:475
LLVM_ABI BasicBlock * getBasicBlock() const
Definition Constant.cpp:480
static LLVM_ABI BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition Constant.cpp:459
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1453
static LLVM_ABI ConstantAggregateZero * get(Type *Ty)
Definition Constant.cpp:198
ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
Definition Constant.h:469
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition Constant.h:477
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:474
LLVM_ABI Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
Definition Constant.cpp:204
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:481
LLVM_ABI Constant * getStructElement(unsigned Elt) const
If this CAZ has struct type, return a zero with the right element type for the specified element.
Definition Constant.cpp:208
LLVM_ABI Constant * getElementValue(Constant *C) const
Return a zero of the right value for the specified GEP index if we can, otherwise return null (e....
Definition Constant.cpp:212
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:484
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:354
ConstantAggregate(ClassID ID, llvm::Constant *C, Context &Ctx)
Definition Constant.h:349
static bool classof(const Value *From)
For isa/dyn_cast.
Definition Constant.h:373
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition Constant.cpp:138
LLVM_ABI ArrayType * getType() const
Definition Constant.cpp:149
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 Constant.h:633
static Constant * getFP(Type *ElementType, ArrayRef< uint64_t > Elts)
Definition Constant.h:641
static bool classof(const Value *From)
Definition Constant.h:596
static Constant * getFP(Type *ElementType, ArrayRef< uint32_t > Elts)
Definition Constant.h:637
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
Definition Constant.h:659
static Constant * getString(Context &Ctx, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
Definition Constant.h:650
static Constant * get(Context &Ctx, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition Constant.h:603
static Constant * get(Context &Ctx, ArrayTy &Elts)
get() constructor - ArrayTy needs to be compatible with ArrayRef<ElementTy>.
Definition Constant.h:611
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 Constant.h:621
uint64_t getElementAsInteger(unsigned ElmIdx) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
Definition Constant.h:514
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
Definition Constant.h:580
StringRef getAsCString() const
If this array is isCString(), then this method returns the array (without the trailing null byte) as ...
Definition Constant.h:574
Type * getElementType() const
Return the element type of the array/vector.
Definition Constant.h:545
static bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
Definition Constant.h:509
unsigned getNumElements() const
Return the number of elements in the array or vector.
Definition Constant.h:550
APFloat getElementAsAPFloat(unsigned ElmIdx) const
If this is a sequential container of floating point type, return the specified element as an APFloat.
Definition Constant.h:524
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
Definition Constant.h:564
static bool classof(const Value *From)
Definition Constant.h:584
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
Definition Constant.h:569
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
Definition Constant.h:555
bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
Definition Constant.h:559
float getElementAsFloat(unsigned ElmIdx) const
If this is an sequential container of floats, return the specified element as a float.
Definition Constant.h:529
double getElementAsDouble(unsigned ElmIdx) const
If this is an sequential container of doubles, return the specified element as a double.
Definition Constant.h:534
Constant * getElementAsConstant(unsigned ElmIdx) const
Return a Constant for a specified index's element.
Definition Constant.h:540
ConstantDataSequential(ClassID ID, llvm::ConstantDataSequential *C, Context &Ctx)
Definition Constant.h:500
APInt getElementAsAPInt(unsigned ElmIdx) const
If this is a sequential container of integers (of any size), return the specified element as an APInt...
Definition Constant.h:519
static Constant * get(Context &Ctx, ArrayRef< uint32_t > Elts)
Definition Constant.h:690
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
Definition Constant.h:741
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 Constant.h:725
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
Definition Constant.h:762
static Constant * get(Context &Ctx, ArrayRef< uint64_t > Elts)
Definition Constant.h:694
static bool classof(const Value *From)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition Constant.h:676
static Constant * get(Context &Ctx, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
Definition Constant.h:682
static Constant * get(Context &Ctx, ArrayRef< float > Elts)
Definition Constant.h:698
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 Constant.h:713
static Constant * get(Context &Ctx, ArrayRef< uint16_t > Elts)
Definition Constant.h:686
static Constant * get(Context &Ctx, ArrayRef< double > Elts)
Definition Constant.h:702
static Constant * getFP(Type *ElementType, ArrayRef< uint64_t > Elts)
Definition Constant.h:733
static Constant * getFP(Type *ElementType, ArrayRef< uint32_t > Elts)
Definition Constant.h:729
bool isSplat() const
Returns true if this is a splat constant, meaning that all elements have the same value.
Definition Constant.h:749
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value,...
Definition Constant.h:755
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1425
static LLVM_ABI Constant * getInfinity(Type *Ty, bool Negative=false)
Definition Constant.cpp:130
const APFloat & getValue() const
Definition Constant.h:296
static LLVM_ABI Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
Definition Constant.cpp:110
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 Constant.h:318
bool isNegative() const
Return true if the sign bit is set.
Definition Constant.h:304
static LLVM_ABI Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition Constant.cpp:118
static LLVM_ABI 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 Constant.cpp:90
bool isZero() const
Return true if the value is positive or negative zero.
Definition Constant.h:301
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:336
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:339
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:327
bool isNaN() const
Return true if the value is a NaN.
Definition Constant.h:310
static LLVM_ABI bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
Definition Constant.cpp:134
static LLVM_ABI Constant * getZero(Type *Ty, bool Negative=false)
Definition Constant.cpp:122
const APFloat & getValueAPF() const
Definition Constant.h:293
static LLVM_ABI Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition Constant.cpp:114
bool isInfinity() const
Return true if the value is infinity.
Definition Constant.h:307
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition Constant.h:332
static LLVM_ABI Constant * getNegativeZero(Type *Ty)
Definition Constant.cpp:126
bool isExactlyValue(double V) const
Definition Constant.h:322
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
Definition Constant.h:202
static LLVM_ABI ConstantInt * getTrue(Context &Ctx)
Definition Constant.cpp:24
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
Definition Constant.h:128
MaybeAlign getMaybeAlignValue() const
Return the constant as an llvm::MaybeAlign.
Definition Constant.h:150
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition Constant.h:123
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition Constant.h:190
bool isMaxValue(bool IsSigned) const
This function will return true iff this constant represents the largest value that may be represented...
Definition Constant.h:209
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 Constant.h:227
static LLVM_ABI ConstantInt * getBool(Context &Ctx, bool V)
Definition Constant.cpp:32
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition Constant.h:196
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:248
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Definition Constant.h:143
static LLVM_ABI ConstantInt * getFalse(Context &Ctx)
Definition Constant.cpp:28
bool isMinValue(bool IsSigned) const
This function will return true iff this constant represents the smallest value that may be represente...
Definition Constant.h:218
LLVM_ABI IntegerType * getIntegerType() const
Variant of the getType() method to always return an IntegerType, which reduces the amount of casting ...
Definition Constant.cpp:78
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 Constant.h:165
unsigned getUseOperandNo(const Use &Use) const override
\Returns the operand index of Use.
Definition Constant.h:244
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:251
static LLVM_ABI 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 Constant.cpp:48
static LLVM_ABI ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition Constant.cpp:56
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 Constant.h:236
static LLVM_ABI bool isValueValidForType(Type *Ty, uint64_t V)
This static method returns true if the type Ty is big enough to represent the value V.
Definition Constant.cpp:83
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:241
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition Constant.h:135
Align getAlignValue() const
Return the constant as an llvm::Align, interpreting 0 as Align(1).
Definition Constant.h:157
static LLVM_ABI ConstantPointerNull * get(PointerType *Ty)
Definition Constant.cpp:222
LLVM_ABI Type * getType() const
Definition Constant.cpp:228
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:787
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:790
LLVM_ABI PointerType * getPointerType() const
Definition Constant.cpp:232
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:780
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition Constant.h:783
LLVM_ABI ConstantPtrAuth * getWithSameSchema(Constant *Pointer) const
Produce a new ptrauth expression signing the given value using the same schema as is stored in one.
Definition Constant.cpp:453
LLVM_ABI Constant * getPointer() const
The pointer that is signed in this ptrauth signed pointer.
Definition Constant.cpp:428
LLVM_ABI Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
Definition Constant.cpp:443
LLVM_ABI ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
Definition Constant.cpp:438
static LLVM_ABI ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc, Constant *DeactivationSymbol)
Return a pointer signed with the specified parameters.
Definition Constant.cpp:418
bool hasAddressDiscriminator() const
Whether there is any non-null address discriminator.
Definition Constant.h:1386
bool isKnownCompatibleWith(const Value *Key, const Value *Discriminator, const DataLayout &DL) const
Check whether an authentication operation with key Key and (possibly blended) discriminator Discrimin...
Definition Constant.h:1402
LLVM_ABI ConstantInt * getKey() const
The Key ID, an i32 constant.
Definition Constant.cpp:433
bool hasSpecialAddressDiscriminator(uint64_t Value) const
Whether the address uses a special address discriminator.
Definition Constant.h:1394
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1413
LLVM_ABI Constant * getDeactivationSymbol() const
Definition Constant.cpp:448
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition Constant.cpp:154
static std::enable_if_t< are_base_of< Constant, Csts... >::value, Constant * > get(StructType *T, Csts *...Vs)
Definition Constant.h:388
static Constant * getAnon(Context &Ctx, ArrayRef< Constant * > V, bool Packed=false)
Definition Constant.h:396
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 Constant.h:405
static Constant * getAnon(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct that has the specified elements.
Definition Constant.h:393
StructType * getType() const
Specialization - reduce amount of casting.
Definition Constant.h:413
static LLVM_ABI StructType * getTypeForElements(Context &Ctx, ArrayRef< Constant * > V, bool Packed=false)
This version of the method allows an empty list.
Definition Constant.cpp:165
static bool classof(const Value *From)
For isa/dyn_cast.
Definition Constant.h:418
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:1514
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition Constant.h:1505
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:1510
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1501
static LLVM_ABI ConstantTokenNone * get(Context &Ctx)
Return the ConstantTokenNone.
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
Definition Constant.cpp:186
static bool classof(const Value *From)
For isa/dyn_cast.
Definition Constant.h:444
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
Definition Constant.cpp:176
LLVM_ABI Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
Definition Constant.cpp:192
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
Definition Constant.h:435
sandboxir::Context & getParent() const
Definition Constant.h:56
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:61
void dumpOS(raw_ostream &OS) const override
Definition Constant.cpp:18
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:47
Constant(llvm::Constant *C, sandboxir::Context &SBCtx)
Definition Constant.h:34
Constant(ClassID ID, llvm::Constant *C, sandboxir::Context &SBCtx)
Definition Constant.h:36
friend class Function
Definition Constant.h:39
unsigned getUseOperandNo(const Use &Use) const override
\Returns the operand index of Use.
Definition Constant.h:57
friend class ConstantInt
Definition Constant.h:38
Use getOperandUseInternal(unsigned OpIdx, bool Verify) const override
\Returns the Use for the OpIdx'th operand.
Definition Constant.h:41
LLVM_ABI Constant * getOrCreateConstant(llvm::Constant *LLVMC)
Get or create a sandboxir::Constant from an existing LLVM IR LLVMC.
Definition Context.cpp:451
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1470
static LLVM_ABI DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
Definition Constant.cpp:485
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition Constant.h:1474
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:1479
LLVM_ABI GlobalValue * getGlobalValue() const
Definition Constant.cpp:490
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:1483
static bool isValidLinkage(LinkageTypes L)
Definition Constant.h:1317
LLVM_ABI Constant * getAliasee() const
Definition Constant.cpp:380
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1299
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Constant.cpp:385
LLVM_ABI void setAliasee(Constant *Aliasee)
Definition Constant.cpp:372
GlobalObject * getAliaseeObject()
Definition Constant.h:1312
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:1112
static bool isValidLinkage(LinkageTypes L)
Definition Constant.h:1105
const Function * getResolverFunction() const
Definition Constant.h:1101
LLVM_ABI Constant * getResolver() const
Definition Constant.cpp:330
LLVM_ABI void setResolver(Constant *Resolver)
Definition Constant.cpp:321
LLVM_ABI Function * getResolverFunction()
Definition Constant.cpp:334
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1085
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:1115
Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final
\Returns the Use for the OpIdx'th operand.
Definition Constant.h:962
VCallVisibility getVCallVisibility() const
Definition Constant.h:1013
bool hasSection() const
Check if this global has a custom object file section.
Definition Constant.h:986
StringRef getSection() const
Get the custom section of this global if it has one.
Definition Constant.h:994
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:971
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition Constant.h:967
llvm::GlobalObject::VCallVisibility VCallVisibility
Definition Constant.h:1011
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
Definition Constant.cpp:296
GlobalObject(ClassID ID, llvm::GlobalObject *C, Context &Ctx)
Definition Constant.h:959
bool canIncreaseAlignment() const
Returns true if the alignment of the value can be unilaterally increased.
Definition Constant.h:1022
UnnamedAddr getUnnamedAddr() const
Definition Constant.h:927
bool hasDefaultVisibility() const
Definition Constant.h:943
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
Definition Constant.h:921
llvm::GlobalValue::UnnamedAddr UnnamedAddr
Definition Constant.h:925
LLVM_ABI void setUnnamedAddr(UnnamedAddr V)
Definition Constant.cpp:390
bool hasHiddenVisibility() const
Definition Constant.h:946
VisibilityTypes getVisibility() const
Definition Constant.h:940
unsigned getAddressSpace() const
Definition Constant.h:909
bool hasGlobalUnnamedAddr() const
Definition Constant.h:912
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:897
llvm::GlobalValue::VisibilityTypes VisibilityTypes
Definition Constant.h:939
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
Definition Constant.h:932
llvm::GlobalValue::LinkageTypes LinkageTypes
Definition Constant.h:895
bool hasProtectedVisibility() const
Definition Constant.h:949
GlobalValue(ClassID ID, llvm::GlobalValue *C, Context &Ctx)
Definition Constant.h:890
LLVM_ABI void setVisibility(VisibilityTypes V)
Definition Constant.cpp:397
LLVM_ABI Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition Constant.cpp:344
AttributeSet getAttributes() const
Return the attribute set for this global.
Definition Constant.h:1235
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
Definition Constant.h:1225
AttributeList getAttributesAsList(unsigned Index) const
Return attribute set as list with index.
Definition Constant.h:1242
unsigned getCodeModelRaw() const
Get the custom code model raw value of this global.
Definition Constant.h:1253
bool hasImplicitSection() const
Check if section name is present.
Definition Constant.h:1247
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
Definition Constant.h:1164
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition Constant.h:1144
Attribute getAttribute(StringRef Kind) const
Return the attribute object.
Definition Constant.h:1230
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1138
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:1280
LLVM_ABI void setExternallyInitialized(bool Val)
Definition Constant.cpp:364
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists.
Definition Constant.h:1210
bool hasAttribute(StringRef Kind) const
Return true if the attribute exists.
Definition Constant.h:1215
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition Constant.cpp:349
LLVM_ABI void setAlignment(MaybeAlign Align)
Sets the alignment attribute of the GlobalVariable.
Definition Constant.cpp:289
LLVM_ABI void setConstant(bool V)
Definition Constant.cpp:357
bool hasAttributes() const
Return true if any attributes exist.
Definition Constant.h:1220
std::optional< CodeModel::Model > getCodeModel() const
Get the custom code model of this global if it has one.
Definition Constant.h:1261
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Definition Constant.h:1190
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:1283
MaybeAlign getAlign() const
Returns the alignment of the given variable.
Definition Constant.h:1266
bool hasUniqueInitializer() const
hasUniqueInitializer - Whether the global variable has an initializer, and any changes made to the in...
Definition Constant.h:1170
GlobalWithNodeAPI(Value::ClassID ID, LLVMParentT *C, Context &Ctx)
Definition Constant.h:1041
mapped_iterator< decltype(static_cast< LLVMGlobalT * >(nullptr) ->getReverseIterator()), LLVMGVToGV > reverse_iterator
Definition Constant.h:1051
reverse_iterator getReverseIterator() const
Definition Constant.h:1059
mapped_iterator< decltype(static_cast< LLVMGlobalT * >(nullptr) ->getIterator()), LLVMGVToGV > iterator
Definition Constant.h:1049
Class to represent integer types.
Definition Type.h:470
In SandboxIR the Module is mainly used to access the list of global objects.
Definition Module.h:32
LLVM_ABI PointerType * getType() const
NoCFIValue is always a pointer.
Definition Constant.cpp:414
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:1340
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:1352
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:1349
LLVM_ABI GlobalValue * getGlobalValue() const
Definition Constant.cpp:409
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition Constant.h:1344
static LLVM_ABI NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
Definition Constant.cpp:404
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:881
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:878
LLVM_ABI PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
Definition Constant.cpp:268
LLVM_ABI PoisonValue * getStructElement(unsigned Elt) const
If this poison has struct type, return a poison with the right element type for the specified element...
Definition Constant.cpp:273
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition Constant.cpp:263
LLVM_ABI PoisonValue * getElementValue(Constant *C) const
Return an poison of the right value for the specified GEP index if we can, otherwise return null (e....
Definition Constant.cpp:278
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:874
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition Type.h:48
llvm::Type * LLVMTy
Definition Type.h:50
Context & getContext() const
Definition Type.h:98
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition Constant.h:835
void verify() const override
Should crash if there is something wrong with the instruction.
Definition Constant.h:839
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....
Definition Constant.cpp:252
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition Constant.cpp:237
void dumpOS(raw_ostream &OS) const override
Definition Constant.h:842
UndefValue(ClassID ID, llvm::Constant *C, Context &Ctx)
Definition Constant.h:802
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition Constant.h:831
UndefValue(llvm::UndefValue *C, Context &Ctx)
Definition Constant.h:800
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
Definition Constant.h:826
LLVM_ABI UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
Definition Constant.cpp:242
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.
Definition Constant.cpp:247
Represents a Def-use/Use-def edge in SandboxIR.
Definition Use.h:33
A sandboxir::User has operands.
Definition User.h:59
unsigned getUseOperandNoDefault(const Use &Use) const
The default implementation works only for single-LLVMIR-instruction Users and only if they match exac...
Definition User.h:76
Use getOperandUseDefault(unsigned OpIdx, bool Verify) const
\Returns the Use edge that corresponds to OpIdx.
Definition User.cpp:58
User(ClassID ID, llvm::Value *V, Context &Ctx)
Definition User.h:61
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition Value.h:122
friend class ConstantStruct
Definition Value.h:166
friend class ConstantVector
Definition Value.h:167
ClassID getSubclassID() const
Definition Value.h:213
friend class ConstantDataVector
Definition Value.h:193
void dumpCommonSuffix(raw_ostream &OS) const
Definition Value.cpp:107
Context & Ctx
All values point to the context.
Definition Value.h:201
friend class ConstantPointerNull
Definition Value.h:169
friend class ConstantPtrAuth
Definition Value.h:180
LLVM_ABI Type * getType() const
Definition Value.cpp:46
friend class GlobalAlias
Definition Value.h:178
friend class ConstantExpr
Definition Value.h:181
Context & getContext() const
Definition Value.h:285
friend class PoisonValue
Definition Value.h:171
friend class GlobalVariable
Definition Value.h:177
friend class BlockAddress
Definition Value.h:172
friend class ConstantArray
Definition Value.h:165
friend class GlobalIFunc
Definition Value.h:176
friend class ConstantDataArray
Definition Value.h:192
void dumpCommonPrefix(raw_ostream &OS) const
Definition Value.cpp:100
friend class NoCFIValue
Definition Value.h:179
friend class ConstantAggregateZero
Definition Value.h:168
friend class UndefValue
Definition Value.h:170
friend class DSOLocalEquivalent
Definition Value.h:174
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
Context & getContext() const
Definition BasicBlock.h:99
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
Definition BasicBlock.h:75
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
Definition STLExtras.h:358
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
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
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106