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