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