LLVM 20.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 {
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 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 static ConstantInt *getBool(Context &Ctx, bool V);
82 static Constant *getTrue(Type *Ty);
83 static Constant *getFalse(Type *Ty);
84 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 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.
96 static ConstantInt *get(IntegerType *Ty, uint64_t V, bool IsSigned = false);
97
98 /// Return a ConstantInt with the specified value for the specified type. The
99 /// value V will be canonicalized to a an unsigned APInt. Accessing it with
100 /// either getSExtValue() or getZExtValue() will yield a correctly sized and
101 /// signed value for the type Ty.
102 /// Get a ConstantInt for a specific signed value.
103 static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
104 static Constant *getSigned(Type *Ty, int64_t V);
105
106 /// Return a ConstantInt with the specified value and an implied Type. The
107 /// type is the integer type that corresponds to the bit width of the value.
108 static ConstantInt *get(Context &Ctx, const APInt &V);
109
110 /// Return a ConstantInt constructed from the string strStart with the given
111 /// radix.
112 static ConstantInt *get(IntegerType *Ty, StringRef Str, uint8_t Radix);
113
114 /// If Ty is a vector type, return a Constant with a splat of the given
115 /// value. Otherwise return a ConstantInt for the given value.
116 static Constant *get(Type *Ty, const APInt &V);
117
118 /// Return the constant as an APInt value reference. This allows clients to
119 /// obtain a full-precision copy of the value.
120 /// Return the constant's value.
121 inline const APInt &getValue() const {
122 return cast<llvm::ConstantInt>(Val)->getValue();
123 }
124
125 /// getBitWidth - Return the scalar bitwidth of this constant.
126 unsigned getBitWidth() const {
127 return cast<llvm::ConstantInt>(Val)->getBitWidth();
128 }
129 /// Return the constant as a 64-bit unsigned integer value after it
130 /// has been zero extended as appropriate for the type of this constant. Note
131 /// that this method can assert if the value does not fit in 64 bits.
132 /// Return the zero extended value.
133 inline uint64_t getZExtValue() const {
134 return cast<llvm::ConstantInt>(Val)->getZExtValue();
135 }
136
137 /// Return the constant as a 64-bit integer value after it has been sign
138 /// extended as appropriate for the type of this constant. Note that
139 /// this method can assert if the value does not fit in 64 bits.
140 /// Return the sign extended value.
141 inline int64_t getSExtValue() const {
142 return cast<llvm::ConstantInt>(Val)->getSExtValue();
143 }
144
145 /// Return the constant as an llvm::MaybeAlign.
146 /// Note that this method can assert if the value does not fit in 64 bits or
147 /// is not a power of two.
149 return cast<llvm::ConstantInt>(Val)->getMaybeAlignValue();
150 }
151
152 /// Return the constant as an llvm::Align, interpreting `0` as `Align(1)`.
153 /// Note that this method can assert if the value does not fit in 64 bits or
154 /// is not a power of two.
155 inline Align getAlignValue() const {
156 return cast<llvm::ConstantInt>(Val)->getAlignValue();
157 }
158
159 /// A helper method that can be used to determine if the constant contained
160 /// within is equal to a constant. This only works for very small values,
161 /// because this is all that can be represented with all types.
162 /// Determine if this constant's value is same as an unsigned char.
163 bool equalsInt(uint64_t V) const {
164 return cast<llvm::ConstantInt>(Val)->equalsInt(V);
165 }
166
167 /// Variant of the getType() method to always return an IntegerType, which
168 /// reduces the amount of casting needed in parts of the compiler.
170
171 /// This static method returns true if the type Ty is big enough to
172 /// represent the value V. This can be used to avoid having the get method
173 /// assert when V is larger than Ty can represent. Note that there are two
174 /// versions of this method, one for unsigned and one for signed integers.
175 /// Although ConstantInt canonicalizes everything to an unsigned integer,
176 /// the signed version avoids callers having to convert a signed quantity
177 /// to the appropriate unsigned type before calling the method.
178 /// @returns true if V is a valid value for type Ty
179 /// Determine if the value is in range for the given type.
180 static bool isValueValidForType(Type *Ty, uint64_t V);
181 static bool isValueValidForType(Type *Ty, int64_t V);
182
183 bool isNegative() const { return cast<llvm::ConstantInt>(Val)->isNegative(); }
184
185 /// This is just a convenience method to make client code smaller for a
186 /// common code. It also correctly performs the comparison without the
187 /// potential for an assertion from getZExtValue().
188 bool isZero() const { return cast<llvm::ConstantInt>(Val)->isZero(); }
189
190 /// This is just a convenience method to make client code smaller for a
191 /// common case. It also correctly performs the comparison without the
192 /// potential for an assertion from getZExtValue().
193 /// Determine if the value is one.
194 bool isOne() const { return cast<llvm::ConstantInt>(Val)->isOne(); }
195
196 /// This function will return true iff every bit in this constant is set
197 /// to true.
198 /// @returns true iff this constant's bits are all set to true.
199 /// Determine if the value is all ones.
200 bool isMinusOne() const { return cast<llvm::ConstantInt>(Val)->isMinusOne(); }
201
202 /// This function will return true iff this constant represents the largest
203 /// value that may be represented by the constant's type.
204 /// @returns true iff this is the largest value that may be represented
205 /// by this type.
206 /// Determine if the value is maximal.
207 bool isMaxValue(bool IsSigned) const {
208 return cast<llvm::ConstantInt>(Val)->isMaxValue(IsSigned);
209 }
210
211 /// This function will return true iff this constant represents the smallest
212 /// value that may be represented by this constant's type.
213 /// @returns true if this is the smallest value that may be represented by
214 /// this type.
215 /// Determine if the value is minimal.
216 bool isMinValue(bool IsSigned) const {
217 return cast<llvm::ConstantInt>(Val)->isMinValue(IsSigned);
218 }
219
220 /// This function will return true iff this constant represents a value with
221 /// active bits bigger than 64 bits or a value greater than the given uint64_t
222 /// value.
223 /// @returns true iff this constant is greater or equal to the given number.
224 /// Determine if the value is greater or equal to the given number.
225 bool uge(uint64_t Num) const {
226 return cast<llvm::ConstantInt>(Val)->uge(Num);
227 }
228
229 /// getLimitedValue - If the value is smaller than the specified limit,
230 /// return it, otherwise return the limit value. This causes the value
231 /// to saturate to the limit.
232 /// @returns the min of the value of the constant and the specified value
233 /// Get the constant's value with a saturation limit
234 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
235 return cast<llvm::ConstantInt>(Val)->getLimitedValue(Limit);
236 }
237
238 /// For isa/dyn_cast.
239 static bool classof(const sandboxir::Value *From) {
240 return From->getSubclassID() == ClassID::ConstantInt;
241 }
242 unsigned getUseOperandNo(const Use &Use) const override {
243 llvm_unreachable("ConstantInt has no operands!");
244 }
245#ifndef NDEBUG
246 void verify() const override {
247 assert(isa<llvm::ConstantInt>(Val) && "Expected a ConstantInst!");
248 }
249 void dumpOS(raw_ostream &OS) const override {
252 }
253#endif
254};
255
256// TODO: This should inherit from ConstantData.
257class ConstantFP final : public Constant {
259 : Constant(ClassID::ConstantFP, C, Ctx) {}
260 friend class Context; // For constructor.
261
262public:
263 /// This returns a ConstantFP, or a vector containing a splat of a ConstantFP,
264 /// for the specified value in the specified type. This should only be used
265 /// for simple constant values like 2.0/1.0 etc, that are known-valid both as
266 /// host double and as the target format.
267 static Constant *get(Type *Ty, double V);
268
269 /// If Ty is a vector type, return a Constant with a splat of the given
270 /// value. Otherwise return a ConstantFP for the given value.
271 static Constant *get(Type *Ty, const APFloat &V);
272
273 static Constant *get(Type *Ty, StringRef Str);
274
275 static ConstantFP *get(const APFloat &V, Context &Ctx);
276
277 static Constant *getNaN(Type *Ty, bool Negative = false,
278 uint64_t Payload = 0);
279 static Constant *getQNaN(Type *Ty, bool Negative = false,
280 APInt *Payload = nullptr);
281 static Constant *getSNaN(Type *Ty, bool Negative = false,
282 APInt *Payload = nullptr);
283 static Constant *getZero(Type *Ty, bool Negative = false);
284
285 static Constant *getNegativeZero(Type *Ty);
286 static Constant *getInfinity(Type *Ty, bool Negative = false);
287
288 /// Return true if Ty is big enough to represent V.
289 static bool isValueValidForType(Type *Ty, const APFloat &V);
290
291 inline const APFloat &getValueAPF() const {
292 return cast<llvm::ConstantFP>(Val)->getValueAPF();
293 }
294 inline const APFloat &getValue() const {
295 return cast<llvm::ConstantFP>(Val)->getValue();
296 }
297
298 /// Return true if the value is positive or negative zero.
299 bool isZero() const { return cast<llvm::ConstantFP>(Val)->isZero(); }
300
301 /// Return true if the sign bit is set.
302 bool isNegative() const { return cast<llvm::ConstantFP>(Val)->isNegative(); }
303
304 /// Return true if the value is infinity
305 bool isInfinity() const { return cast<llvm::ConstantFP>(Val)->isInfinity(); }
306
307 /// Return true if the value is a NaN.
308 bool isNaN() const { return cast<llvm::ConstantFP>(Val)->isNaN(); }
309
310 /// We don't rely on operator== working on double values, as it returns true
311 /// for things that are clearly not equal, like -0.0 and 0.0.
312 /// As such, this method can be used to do an exact bit-for-bit comparison of
313 /// two floating point values. The version with a double operand is retained
314 /// because it's so convenient to write isExactlyValue(2.0), but please use
315 /// it only for simple constants.
316 bool isExactlyValue(const APFloat &V) const {
317 return cast<llvm::ConstantFP>(Val)->isExactlyValue(V);
318 }
319
320 bool isExactlyValue(double V) const {
321 return cast<llvm::ConstantFP>(Val)->isExactlyValue(V);
322 }
323
324 /// For isa/dyn_cast.
325 static bool classof(const sandboxir::Value *From) {
326 return From->getSubclassID() == ClassID::ConstantFP;
327 }
328
329 // TODO: Better name: getOperandNo(const Use&). Should be private.
330 unsigned getUseOperandNo(const Use &Use) const final {
331 llvm_unreachable("ConstantFP has no operands!");
332 }
333#ifndef NDEBUG
334 void verify() const override {
335 assert(isa<llvm::ConstantFP>(Val) && "Expected a ConstantFP!");
336 }
337 void dumpOS(raw_ostream &OS) const override {
340 }
341#endif
342};
343
344/// Base class for aggregate constants (with operands).
346protected:
348 : Constant(ID, C, Ctx) {}
349
350public:
351 /// For isa/dyn_cast.
352 static bool classof(const sandboxir::Value *From) {
353 auto ID = From->getSubclassID();
354 return ID == ClassID::ConstantVector || ID == ClassID::ConstantStruct ||
355 ID == ClassID::ConstantArray;
356 }
357};
358
359class ConstantArray final : public ConstantAggregate {
361 : ConstantAggregate(ClassID::ConstantArray, C, Ctx) {}
362 friend class Context; // For constructor.
363
364public:
366 ArrayType *getType() const;
367
368 // TODO: Missing functions: getType(), getTypeForElements(), getAnon(), get().
369
370 /// For isa/dyn_cast.
371 static bool classof(const Value *From) {
372 return From->getSubclassID() == ClassID::ConstantArray;
373 }
374};
375
376class ConstantStruct final : public ConstantAggregate {
378 : ConstantAggregate(ClassID::ConstantStruct, C, Ctx) {}
379 friend class Context; // For constructor.
380
381public:
383
384 template <typename... Csts>
385 static std::enable_if_t<are_base_of<Constant, Csts...>::value, Constant *>
386 get(StructType *T, Csts *...Vs) {
387 return get(T, ArrayRef<Constant *>({Vs...}));
388 }
389 /// Return an anonymous struct that has the specified elements.
390 /// If the struct is possibly empty, then you must specify a context.
391 static Constant *getAnon(ArrayRef<Constant *> V, bool Packed = false) {
392 return get(getTypeForElements(V, Packed), V);
393 }
395 bool Packed = false) {
396 return get(getTypeForElements(Ctx, V, Packed), V);
397 }
398 /// This version of the method allows an empty list.
400 bool Packed = false);
401 /// Return an anonymous struct type to use for a constant with the specified
402 /// set of elements. The list must not be empty.
404 bool Packed = false) {
405 assert(!V.empty() &&
406 "ConstantStruct::getTypeForElements cannot be called on empty list");
407 return getTypeForElements(V[0]->getContext(), V, Packed);
408 }
409
410 /// Specialization - reduce amount of casting.
411 inline StructType *getType() const {
412 return cast<StructType>(Value::getType());
413 }
414
415 /// For isa/dyn_cast.
416 static bool classof(const Value *From) {
417 return From->getSubclassID() == ClassID::ConstantStruct;
418 }
419};
420
421class ConstantVector final : public ConstantAggregate {
423 : ConstantAggregate(ClassID::ConstantVector, C, Ctx) {}
424 friend class Context; // For constructor.
425
426public:
427 // TODO: Missing functions: getSplat(), getType(), getSplatValue(), get().
428
429 /// For isa/dyn_cast.
430 static bool classof(const Value *From) {
431 return From->getSubclassID() == ClassID::ConstantVector;
432 }
433};
434
435// TODO: Inherit from ConstantData.
436class ConstantAggregateZero final : public Constant {
438 : Constant(ClassID::ConstantAggregateZero, C, Ctx) {}
439 friend class Context; // For constructor.
440
441public:
442 static ConstantAggregateZero *get(Type *Ty);
443 /// If this CAZ has array or vector type, return a zero with the right element
444 /// type.
446 /// If this CAZ has struct type, return a zero with the right element type for
447 /// the specified element.
448 Constant *getStructElement(unsigned Elt) const;
449 /// Return a zero of the right value for the specified GEP index if we can,
450 /// otherwise return null (e.g. if C is a ConstantExpr).
452 /// Return a zero of the right value for the specified GEP index.
453 Constant *getElementValue(unsigned Idx) const;
454 /// Return the number of elements in the array, vector, or struct.
456 return cast<llvm::ConstantAggregateZero>(Val)->getElementCount();
457 }
458
459 /// For isa/dyn_cast.
460 static bool classof(const sandboxir::Value *From) {
461 return From->getSubclassID() == ClassID::ConstantAggregateZero;
462 }
463 unsigned getUseOperandNo(const Use &Use) const final {
464 llvm_unreachable("ConstantAggregateZero has no operands!");
465 }
466#ifndef NDEBUG
467 void verify() const override {
468 assert(isa<llvm::ConstantAggregateZero>(Val) && "Expected a CAZ!");
469 }
470 void dumpOS(raw_ostream &OS) const override {
473 }
474#endif
475};
476
477// TODO: Inherit from ConstantData.
478class ConstantPointerNull final : public Constant {
480 : Constant(ClassID::ConstantPointerNull, C, Ctx) {}
481 friend class Context; // For constructor.
482
483public:
485
486 PointerType *getType() const;
487
488 /// For isa/dyn_cast.
489 static bool classof(const sandboxir::Value *From) {
490 return From->getSubclassID() == ClassID::ConstantPointerNull;
491 }
492 unsigned getUseOperandNo(const Use &Use) const final {
493 llvm_unreachable("ConstantPointerNull has no operands!");
494 }
495#ifndef NDEBUG
496 void verify() const override {
497 assert(isa<llvm::ConstantPointerNull>(Val) && "Expected a CPNull!");
498 }
499 void dumpOS(raw_ostream &OS) const override {
502 }
503#endif
504};
505
506// TODO: Inherit from ConstantData.
507class UndefValue : public Constant {
508protected:
512 : Constant(ID, C, Ctx) {}
513 friend class Context; // For constructor.
514
515public:
516 /// Static factory methods - Return an 'undef' object of the specified type.
517 static UndefValue *get(Type *T);
518
519 /// If this Undef has array or vector type, return a undef with the right
520 /// element type.
522
523 /// If this undef has struct type, return a undef with the right element type
524 /// for the specified element.
525 UndefValue *getStructElement(unsigned Elt) const;
526
527 /// Return an undef of the right value for the specified GEP index if we can,
528 /// otherwise return null (e.g. if C is a ConstantExpr).
530
531 /// Return an undef of the right value for the specified GEP index.
532 UndefValue *getElementValue(unsigned Idx) const;
533
534 /// Return the number of elements in the array, vector, or struct.
535 unsigned getNumElements() const {
536 return cast<llvm::UndefValue>(Val)->getNumElements();
537 }
538
539 /// For isa/dyn_cast.
540 static bool classof(const sandboxir::Value *From) {
541 return From->getSubclassID() == ClassID::UndefValue ||
542 From->getSubclassID() == ClassID::PoisonValue;
543 }
544 unsigned getUseOperandNo(const Use &Use) const final {
545 llvm_unreachable("UndefValue has no operands!");
546 }
547#ifndef NDEBUG
548 void verify() const override {
549 assert(isa<llvm::UndefValue>(Val) && "Expected an UndefValue!");
550 }
551 void dumpOS(raw_ostream &OS) const override {
554 }
555#endif
556};
557
558class PoisonValue final : public UndefValue {
560 : UndefValue(ClassID::PoisonValue, C, Ctx) {}
561 friend class Context; // For constructor.
562
563public:
564 /// Static factory methods - Return an 'poison' object of the specified type.
565 static PoisonValue *get(Type *T);
566
567 /// If this poison has array or vector type, return a poison with the right
568 /// element type.
570
571 /// If this poison has struct type, return a poison with the right element
572 /// type for the specified element.
573 PoisonValue *getStructElement(unsigned Elt) const;
574
575 /// Return an poison of the right value for the specified GEP index if we can,
576 /// otherwise return null (e.g. if C is a ConstantExpr).
578
579 /// Return an poison of the right value for the specified GEP index.
580 PoisonValue *getElementValue(unsigned Idx) const;
581
582 /// For isa/dyn_cast.
583 static bool classof(const sandboxir::Value *From) {
584 return From->getSubclassID() == ClassID::PoisonValue;
585 }
586#ifndef NDEBUG
587 void verify() const override {
588 assert(isa<llvm::PoisonValue>(Val) && "Expected a PoisonValue!");
589 }
590 void dumpOS(raw_ostream &OS) const override {
593 }
594#endif
595};
596
597class GlobalValue : public Constant {
598protected:
600 : Constant(ID, C, Ctx) {}
601 friend class Context; // For constructor.
602
603public:
605 /// For isa/dyn_cast.
606 static bool classof(const sandboxir::Value *From) {
607 switch (From->getSubclassID()) {
608 case ClassID::Function:
609 case ClassID::GlobalVariable:
610 case ClassID::GlobalAlias:
611 case ClassID::GlobalIFunc:
612 return true;
613 default:
614 return false;
615 }
616 }
617
618 unsigned getAddressSpace() const {
619 return cast<llvm::GlobalValue>(Val)->getAddressSpace();
620 }
621 bool hasGlobalUnnamedAddr() const {
622 return cast<llvm::GlobalValue>(Val)->hasGlobalUnnamedAddr();
623 }
624
625 /// Returns true if this value's address is not significant in this module.
626 /// This attribute is intended to be used only by the code generator and LTO
627 /// to allow the linker to decide whether the global needs to be in the symbol
628 /// table. It should probably not be used in optimizations, as the value may
629 /// have uses outside the module; use hasGlobalUnnamedAddr() instead.
631 return cast<llvm::GlobalValue>(Val)->hasAtLeastLocalUnnamedAddr();
632 }
633
635
637 return cast<llvm::GlobalValue>(Val)->getUnnamedAddr();
638 }
640
643 }
644
645 bool hasComdat() const { return cast<llvm::GlobalValue>(Val)->hasComdat(); }
646
647 // TODO: We need a SandboxIR Comdat if we want to implement getComdat().
650 return cast<llvm::GlobalValue>(Val)->getVisibility();
651 }
652 bool hasDefaultVisibility() const {
653 return cast<llvm::GlobalValue>(Val)->hasDefaultVisibility();
654 }
655 bool hasHiddenVisibility() const {
656 return cast<llvm::GlobalValue>(Val)->hasHiddenVisibility();
657 }
659 return cast<llvm::GlobalValue>(Val)->hasProtectedVisibility();
660 }
662
663 // TODO: Add missing functions.
664};
665
666class GlobalObject : public GlobalValue {
667protected:
669 : GlobalValue(ID, C, Ctx) {}
670 friend class Context; // For constructor.
671 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
672 return getOperandUseDefault(OpIdx, Verify);
673 }
674
675public:
676 unsigned getUseOperandNo(const Use &Use) const final {
678 }
679 /// For isa/dyn_cast.
680 static bool classof(const sandboxir::Value *From) {
681 switch (From->getSubclassID()) {
682 case ClassID::Function:
683 case ClassID::GlobalVariable:
684 case ClassID::GlobalIFunc:
685 return true;
686 default:
687 return false;
688 }
689 }
690
691 /// FIXME: Remove this function once transition to Align is over.
693 return cast<llvm::GlobalObject>(Val)->getAlignment();
694 }
695
696 /// Returns the alignment of the given variable or function.
697 ///
698 /// Note that for functions this is the alignment of the code, not the
699 /// alignment of a function pointer.
701 return cast<llvm::GlobalObject>(Val)->getAlign();
702 }
703
704 // TODO: Add missing: setAlignment(Align)
705
706 /// Sets the alignment attribute of the GlobalObject.
707 /// This method will be deprecated as the alignment property should always be
708 /// defined.
710
712 return cast<llvm::GlobalObject>(Val)->getGlobalObjectSubClassData();
713 }
714
715 void setGlobalObjectSubClassData(unsigned V);
716
717 /// Check if this global has a custom object file section.
718 ///
719 /// This is more efficient than calling getSection() and checking for an empty
720 /// string.
721 bool hasSection() const {
722 return cast<llvm::GlobalObject>(Val)->hasSection();
723 }
724
725 /// Get the custom section of this global if it has one.
726 ///
727 /// If this global does not have a custom section, this will be empty and the
728 /// default object file section (.text, .data, etc) will be used.
730 return cast<llvm::GlobalObject>(Val)->getSection();
731 }
732
733 /// Change the section for this global.
734 ///
735 /// Setting the section to the empty string tells LLVM to choose an
736 /// appropriate default object file section.
737 void setSection(StringRef S);
738
739 bool hasComdat() const { return cast<llvm::GlobalObject>(Val)->hasComdat(); }
740
741 // TODO: implement get/setComdat(), etc. once we have a sandboxir::Comdat.
742
743 // TODO: We currently don't support Metadata in sandboxir so all
744 // Metadata-related functions are missing.
745
747
749 return cast<llvm::GlobalObject>(Val)->getVCallVisibility();
750 }
751
752 /// Returns true if the alignment of the value can be unilaterally
753 /// increased.
754 ///
755 /// Note that for functions this is the alignment of the code, not the
756 /// alignment of a function pointer.
757 bool canIncreaseAlignment() const {
758 return cast<llvm::GlobalObject>(Val)->canIncreaseAlignment();
759 }
760};
761
762/// Provides API functions, like getIterator() and getReverseIterator() to
763/// GlobalIFunc, Function, GlobalVariable and GlobalAlias. In LLVM IR these are
764/// provided by ilist_node.
765template <typename GlobalT, typename LLVMGlobalT, typename ParentT,
766 typename LLVMParentT>
768 /// Helper for mapped_iterator.
769 struct LLVMGVToGV {
770 Context &Ctx;
771 LLVMGVToGV(Context &Ctx) : Ctx(Ctx) {}
772 GlobalT &operator()(LLVMGlobalT &LLVMGV) const;
773 };
774
775public:
777 : ParentT(ID, C, Ctx) {}
778
779 Module *getParent() const {
780 llvm::Module *LLVMM = cast<LLVMGlobalT>(this->Val)->getParent();
781 return this->Ctx.getModule(LLVMM);
782 }
783
785 decltype(static_cast<LLVMGlobalT *>(nullptr)->getIterator()), LLVMGVToGV>;
787 decltype(static_cast<LLVMGlobalT *>(nullptr)->getReverseIterator()),
788 LLVMGVToGV>;
790 auto *LLVMGV = cast<LLVMGlobalT>(this->Val);
791 LLVMGVToGV ToGV(this->Ctx);
792 return map_iterator(LLVMGV->getIterator(), ToGV);
793 }
795 auto *LLVMGV = cast<LLVMGlobalT>(this->Val);
796 LLVMGVToGV ToGV(this->Ctx);
797 return map_iterator(LLVMGV->getReverseIterator(), ToGV);
798 }
799};
800
801// These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB
802extern template LLVM_TEMPLATE_ABI GlobalIFunc &
803GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
804 llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
805 &LLVMGV)
806 const;
807extern template LLVM_TEMPLATE_ABI Function &
808GlobalWithNodeAPI<Function, llvm::Function, GlobalObject, llvm::GlobalObject>::
809 LLVMGVToGV::operator()(llvm::Function &LLVMGV) const;
810
811extern template LLVM_TEMPLATE_ABI GlobalVariable &GlobalWithNodeAPI<
813 llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalVariable &LLVMGV)
814 const;
815extern template LLVM_TEMPLATE_ABI GlobalAlias &
816GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
817 llvm::GlobalValue>::LLVMGVToGV::operator()(llvm::GlobalAlias
818 &LLVMGV) const;
819
820class GlobalIFunc final
821 : public GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
822 llvm::GlobalObject> {
824 : GlobalWithNodeAPI(ClassID::GlobalIFunc, C, Ctx) {}
825 friend class Context; // For constructor.
826
827public:
828 /// For isa/dyn_cast.
829 static bool classof(const sandboxir::Value *From) {
830 return From->getSubclassID() == ClassID::GlobalIFunc;
831 }
832
833 // TODO: Missing create() because we don't have a sandboxir::Module yet.
834
835 // TODO: Missing functions: copyAttributesFrom(), removeFromParent(),
836 // eraseFromParent()
837
839
840 Constant *getResolver() const;
841
842 // Return the resolver function after peeling off potential ConstantExpr
843 // indirection.
846 return const_cast<GlobalIFunc *>(this)->getResolverFunction();
847 }
848
851 }
852
853 // TODO: Missing applyAlongResolverPath().
854
855#ifndef NDEBUG
856 void verify() const override {
857 assert(isa<llvm::GlobalIFunc>(Val) && "Expected a GlobalIFunc!");
858 }
859 void dumpOS(raw_ostream &OS) const override {
862 }
863#endif
864};
865
866class GlobalVariable final
867 : public GlobalWithNodeAPI<GlobalVariable, llvm::GlobalVariable,
868 GlobalObject, llvm::GlobalObject> {
870 : GlobalWithNodeAPI(ClassID::GlobalVariable, C, Ctx) {}
871 friend class Context; // For constructor.
872
873 /// Helper for mapped_iterator.
874 struct LLVMGVToGV {
875 Context &Ctx;
876 LLVMGVToGV(Context &Ctx) : Ctx(Ctx) {}
877 GlobalVariable &operator()(llvm::GlobalVariable &LLVMGV) const;
878 };
879
880public:
881 /// For isa/dyn_cast.
882 static bool classof(const sandboxir::Value *From) {
883 return From->getSubclassID() == ClassID::GlobalVariable;
884 }
885
886 /// Definitions have initializers, declarations don't.
887 ///
888 inline bool hasInitializer() const {
889 return cast<llvm::GlobalVariable>(Val)->hasInitializer();
890 }
891
892 /// hasDefinitiveInitializer - Whether the global variable has an initializer,
893 /// and any other instances of the global (this can happen due to weak
894 /// linkage) are guaranteed to have the same initializer.
895 ///
896 /// Note that if you want to transform a global, you must use
897 /// hasUniqueInitializer() instead, because of the *_odr linkage type.
898 ///
899 /// Example:
900 ///
901 /// @a = global SomeType* null - Initializer is both definitive and unique.
902 ///
903 /// @b = global weak SomeType* null - Initializer is neither definitive nor
904 /// unique.
905 ///
906 /// @c = global weak_odr SomeType* null - Initializer is definitive, but not
907 /// unique.
908 inline bool hasDefinitiveInitializer() const {
909 return cast<llvm::GlobalVariable>(Val)->hasDefinitiveInitializer();
910 }
911
912 /// hasUniqueInitializer - Whether the global variable has an initializer, and
913 /// any changes made to the initializer will turn up in the final executable.
914 inline bool hasUniqueInitializer() const {
915 return cast<llvm::GlobalVariable>(Val)->hasUniqueInitializer();
916 }
917
918 /// getInitializer - Return the initializer for this global variable. It is
919 /// illegal to call this method if the global is external, because we cannot
920 /// tell what the value is initialized to!
921 ///
922 Constant *getInitializer() const;
923 /// setInitializer - Sets the initializer for this global variable, removing
924 /// any existing initializer if InitVal==NULL. The initializer must have the
925 /// type getValueType().
926 void setInitializer(Constant *InitVal);
927
928 // TODO: Add missing replaceInitializer(). Requires special tracker
929
930 /// If the value is a global constant, its value is immutable throughout the
931 /// runtime execution of the program. Assigning a value into the constant
932 /// leads to undefined behavior.
933 ///
934 bool isConstant() const {
935 return cast<llvm::GlobalVariable>(Val)->isConstant();
936 }
937 void setConstant(bool V);
938
940 return cast<llvm::GlobalVariable>(Val)->isExternallyInitialized();
941 }
942 void setExternallyInitialized(bool Val);
943
944 // TODO: Missing copyAttributesFrom()
945
946 // TODO: Missing removeFromParent(), eraseFromParent(), dropAllReferences()
947
948 // TODO: Missing addDebugInfo(), getDebugInfo()
949
950 // TODO: Missing attribute setter functions: addAttribute(), setAttributes().
951 // There seems to be no removeAttribute() so we can't undo them.
952
953 /// Return true if the attribute exists.
955 return cast<llvm::GlobalVariable>(Val)->hasAttribute(Kind);
956 }
957
958 /// Return true if the attribute exists.
959 bool hasAttribute(StringRef Kind) const {
960 return cast<llvm::GlobalVariable>(Val)->hasAttribute(Kind);
961 }
962
963 /// Return true if any attributes exist.
964 bool hasAttributes() const {
965 return cast<llvm::GlobalVariable>(Val)->hasAttributes();
966 }
967
968 /// Return the attribute object.
970 return cast<llvm::GlobalVariable>(Val)->getAttribute(Kind);
971 }
972
973 /// Return the attribute object.
975 return cast<llvm::GlobalVariable>(Val)->getAttribute(Kind);
976 }
977
978 /// Return the attribute set for this global
980 return cast<llvm::GlobalVariable>(Val)->getAttributes();
981 }
982
983 /// Return attribute set as list with index.
984 /// FIXME: This may not be required once ValueEnumerators
985 /// in bitcode-writer can enumerate attribute-set.
987 return cast<llvm::GlobalVariable>(Val)->getAttributesAsList(Index);
988 }
989
990 /// Check if section name is present
991 bool hasImplicitSection() const {
992 return cast<llvm::GlobalVariable>(Val)->hasImplicitSection();
993 }
994
995 /// Get the custom code model raw value of this global.
996 ///
997 unsigned getCodeModelRaw() const {
998 return cast<llvm::GlobalVariable>(Val)->getCodeModelRaw();
999 }
1000
1001 /// Get the custom code model of this global if it has one.
1002 ///
1003 /// If this global does not have a custom code model, the empty instance
1004 /// will be returned.
1005 std::optional<CodeModel::Model> getCodeModel() const {
1006 return cast<llvm::GlobalVariable>(Val)->getCodeModel();
1007 }
1008
1009 // TODO: Missing setCodeModel(). Requires custom tracker.
1010
1011#ifndef NDEBUG
1012 void verify() const override {
1013 assert(isa<llvm::GlobalVariable>(Val) && "Expected a GlobalVariable!");
1014 }
1015 void dumpOS(raw_ostream &OS) const override {
1018 }
1019#endif
1020};
1021
1022class GlobalAlias final
1023 : public GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
1024 llvm::GlobalValue> {
1026 : GlobalWithNodeAPI(ClassID::GlobalAlias, C, Ctx) {}
1027 friend class Context; // For constructor.
1028
1029public:
1030 /// For isa/dyn_cast.
1031 static bool classof(const sandboxir::Value *From) {
1032 return From->getSubclassID() == ClassID::GlobalAlias;
1033 }
1034
1035 // TODO: Missing create() due to unimplemented sandboxir::Module.
1036
1037 // TODO: Missing copyAttributresFrom().
1038 // TODO: Missing removeFromParent(), eraseFromParent().
1039
1040 void setAliasee(Constant *Aliasee);
1041 Constant *getAliasee() const;
1042
1043 const GlobalObject *getAliaseeObject() const;
1045 return const_cast<GlobalObject *>(
1046 static_cast<const GlobalAlias *>(this)->getAliaseeObject());
1047 }
1048
1051 }
1052};
1053
1054class NoCFIValue final : public Constant {
1056 : Constant(ClassID::NoCFIValue, C, Ctx) {}
1057 friend class Context; // For constructor.
1058
1059 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
1060 return getOperandUseDefault(OpIdx, Verify);
1061 }
1062
1063public:
1064 /// Return a NoCFIValue for the specified function.
1065 static NoCFIValue *get(GlobalValue *GV);
1066
1067 GlobalValue *getGlobalValue() const;
1068
1069 /// NoCFIValue is always a pointer.
1070 PointerType *getType() const;
1071 /// For isa/dyn_cast.
1072 static bool classof(const sandboxir::Value *From) {
1073 return From->getSubclassID() == ClassID::NoCFIValue;
1074 }
1075
1076 unsigned getUseOperandNo(const Use &Use) const final {
1078 }
1079
1080#ifndef NDEBUG
1081 void verify() const override {
1082 assert(isa<llvm::NoCFIValue>(Val) && "Expected a NoCFIValue!");
1083 }
1084 void dumpOS(raw_ostream &OS) const override {
1087 }
1088#endif
1089};
1090
1091class ConstantPtrAuth final : public Constant {
1093 : Constant(ClassID::ConstantPtrAuth, C, Ctx) {}
1094 friend class Context; // For constructor.
1095
1096public:
1097 /// Return a pointer signed with the specified parameters.
1099 ConstantInt *Disc, Constant *AddrDisc);
1100 /// The pointer that is signed in this ptrauth signed pointer.
1101 Constant *getPointer() const;
1102
1103 /// The Key ID, an i32 constant.
1104 ConstantInt *getKey() const;
1105
1106 /// The integer discriminator, an i64 constant, or 0.
1108
1109 /// The address discriminator if any, or the null constant.
1110 /// If present, this must be a value equivalent to the storage location of
1111 /// the only global-initializer user of the ptrauth signed pointer.
1113
1114 /// Whether there is any non-null address discriminator.
1116 return cast<llvm::ConstantPtrAuth>(Val)->hasAddressDiscriminator();
1117 }
1118
1119 /// Whether the address uses a special address discriminator.
1120 /// These discriminators can't be used in real pointer-auth values; they
1121 /// can only be used in "prototype" values that indicate how some real
1122 /// schema is supposed to be produced.
1124 return cast<llvm::ConstantPtrAuth>(Val)->hasSpecialAddressDiscriminator(
1125 Value);
1126 }
1127
1128 /// Check whether an authentication operation with key \p Key and (possibly
1129 /// blended) discriminator \p Discriminator is known to be compatible with
1130 /// this ptrauth signed pointer.
1131 bool isKnownCompatibleWith(const Value *Key, const Value *Discriminator,
1132 const DataLayout &DL) const {
1133 return cast<llvm::ConstantPtrAuth>(Val)->isKnownCompatibleWith(
1134 Key->Val, Discriminator->Val, DL);
1135 }
1136
1137 /// Produce a new ptrauth expression signing the given value using
1138 /// the same schema as is stored in one.
1140
1141 /// For isa/dyn_cast.
1142 static bool classof(const sandboxir::Value *From) {
1143 return From->getSubclassID() == ClassID::ConstantPtrAuth;
1144 }
1145};
1146
1147class ConstantExpr : public Constant {
1149 : Constant(ClassID::ConstantExpr, C, Ctx) {}
1150 friend class Context; // For constructor.
1151
1152public:
1153 /// For isa/dyn_cast.
1154 static bool classof(const sandboxir::Value *From) {
1155 return From->getSubclassID() == ClassID::ConstantExpr;
1156 }
1157 // TODO: Missing functions.
1158};
1159
1160class BlockAddress final : public Constant {
1162 : Constant(ClassID::BlockAddress, C, Ctx) {}
1163 friend class Context; // For constructor.
1164
1165public:
1166 /// Return a BlockAddress for the specified function and basic block.
1167 static BlockAddress *get(Function *F, BasicBlock *BB);
1168
1169 /// Return a BlockAddress for the specified basic block. The basic
1170 /// block must be embedded into a function.
1171 static BlockAddress *get(BasicBlock *BB);
1172
1173 /// Lookup an existing \c BlockAddress constant for the given BasicBlock.
1174 ///
1175 /// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
1176 static BlockAddress *lookup(const BasicBlock *BB);
1177
1178 Function *getFunction() const;
1179 BasicBlock *getBasicBlock() const;
1180
1181 /// For isa/dyn_cast.
1182 static bool classof(const sandboxir::Value *From) {
1183 return From->getSubclassID() == ClassID::BlockAddress;
1184 }
1185};
1186
1187class DSOLocalEquivalent final : public Constant {
1189 : Constant(ClassID::DSOLocalEquivalent, C, Ctx) {}
1190 friend class Context; // For constructor.
1191
1192public:
1193 /// Return a DSOLocalEquivalent for the specified global value.
1194 static DSOLocalEquivalent *get(GlobalValue *GV);
1195
1196 GlobalValue *getGlobalValue() const;
1197
1198 /// For isa/dyn_cast.
1199 static bool classof(const sandboxir::Value *From) {
1200 return From->getSubclassID() == ClassID::DSOLocalEquivalent;
1201 }
1202
1203 unsigned getUseOperandNo(const Use &Use) const final {
1204 llvm_unreachable("DSOLocalEquivalent has no operands!");
1205 }
1206
1207#ifndef NDEBUG
1208 void verify() const override {
1209 assert(isa<llvm::DSOLocalEquivalent>(Val) &&
1210 "Expected a DSOLocalEquivalent!");
1211 }
1212 void dumpOS(raw_ostream &OS) const override {
1215 }
1216#endif
1217};
1218
1219// TODO: This should inherit from ConstantData.
1220class ConstantTokenNone final : public Constant {
1222 : Constant(ClassID::ConstantTokenNone, C, Ctx) {}
1223 friend class Context; // For constructor.
1224
1225public:
1226 /// Return the ConstantTokenNone.
1227 static ConstantTokenNone *get(Context &Ctx);
1228
1229 /// For isa/dyn_cast.
1230 static bool classof(const sandboxir::Value *From) {
1231 return From->getSubclassID() == ClassID::ConstantTokenNone;
1232 }
1233
1234 unsigned getUseOperandNo(const Use &Use) const final {
1235 llvm_unreachable("ConstantTokenNone has no operands!");
1236 }
1237
1238#ifndef NDEBUG
1239 void verify() const override {
1240 assert(isa<llvm::ConstantTokenNone>(Val) &&
1241 "Expected a ConstantTokenNone!");
1242 }
1243 void dumpOS(raw_ostream &OS) const override {
1246 }
1247#endif
1248};
1249
1250} // namespace llvm::sandboxir
1251
1252#endif // LLVM_SANDBOXIR_CONSTANT_H
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")
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
ppc ctr loops PowerPC CTR Loops Verify
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:86
The address of a basic block.
Definition: Constants.h:893
All zero aggregate value.
Definition: Constants.h:353
ConstantArray - Constant Array Declarations.
Definition: Constants.h:427
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1108
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:271
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
A constant pointer value that points to null.
Definition: Constants.h:552
A signed pointer, in the ptrauth sense.
Definition: Constants.h:1021
A constant token which is empty.
Definition: Constants.h:844
Constant Vector Declarations.
Definition: Constants.h:511
This is an important base class in LLVM.
Definition: Constant.h:42
Wrapper for a function that represents a value that functionally represents the original function.
Definition: Constants.h:941
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:97
static bool isValidLinkage(LinkageTypes L)
Definition: GlobalIFunc.h:85
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
Definition: GlobalValue.h:233
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:66
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:51
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Wrapper for a value that won't be replaced with a CFI jump table pointer in LowerTypeTestsModule.
Definition: Constants.h:980
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
Definition: Constants.h:1460
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2203
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
'undef' values are things that do not have specified contents.
Definition: Constants.h:1412
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Contains a list of sandboxir::Instruction's.
Definition: BasicBlock.h:67
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Definition: Constant.cpp:468
Function * getFunction() const
Definition: Constant.cpp:473
BasicBlock * getBasicBlock() const
Definition: Constant.cpp:478
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constant.cpp:457
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:1182
static ConstantAggregateZero * get(Type *Ty)
Definition: Constant.cpp:177
ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
Definition: Constant.h:455
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Constant.h:463
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:460
Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
Definition: Constant.cpp:183
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:467
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:187
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:191
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:470
Base class for aggregate constants (with operands).
Definition: Constant.h:345
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:352
ConstantAggregate(ClassID ID, llvm::Constant *C, Context &Ctx)
Definition: Constant.h:347
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: Constant.h:371
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition: Constant.cpp:139
ArrayType * getType() const
Definition: Constant.cpp:150
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:1154
static Constant * getInfinity(Type *Ty, bool Negative=false)
Definition: Constant.cpp:131
const APFloat & getValue() const
Definition: Constant.h:294
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
Definition: Constant.cpp:111
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:316
bool isNegative() const
Return true if the sign bit is set.
Definition: Constant.h:302
static Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition: Constant.cpp:119
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constant.cpp:91
bool isZero() const
Return true if the value is positive or negative zero.
Definition: Constant.h:299
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:334
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:337
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:325
bool isNaN() const
Return true if the value is a NaN.
Definition: Constant.h:308
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
Definition: Constant.cpp:135
static Constant * getZero(Type *Ty, bool Negative=false)
Definition: Constant.cpp:123
const APFloat & getValueAPF() const
Definition: Constant.h:291
static Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition: Constant.cpp:115
bool isInfinity() const
Return true if the value is infinity.
Definition: Constant.h:305
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Constant.h:330
static Constant * getNegativeZero(Type *Ty)
Definition: Constant.cpp:127
bool isExactlyValue(double V) const
Definition: Constant.h:320
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
Definition: Constant.h:200
static ConstantInt * getTrue(Context &Ctx)
Definition: Constant.cpp:25
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
Definition: Constant.h:126
MaybeAlign getMaybeAlignValue() const
Return the constant as an llvm::MaybeAlign.
Definition: Constant.h:148
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constant.h:121
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constant.h:188
bool isMaxValue(bool IsSigned) const
This function will return true iff this constant represents the largest value that may be represented...
Definition: Constant.h:207
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:225
static ConstantInt * getBool(Context &Ctx, bool V)
Definition: Constant.cpp:33
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition: Constant.h:194
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:246
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:141
static ConstantInt * getFalse(Context &Ctx)
Definition: Constant.cpp:29
bool isMinValue(bool IsSigned) const
This function will return true iff this constant represents the smallest value that may be represente...
Definition: Constant.h:216
IntegerType * getIntegerType() const
Variant of the getType() method to always return an IntegerType, which reduces the amount of casting ...
Definition: Constant.cpp:79
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:163
unsigned getUseOperandNo(const Use &Use) const override
\Returns the operand index of Use.
Definition: Constant.h:242
static 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:49
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:249
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constant.cpp:57
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:234
static bool isValueValidForType(Type *Ty, uint64_t V)
This static method returns true if the type Ty is big enough to represent the value V.
Definition: Constant.cpp:84
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:239
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:133
Align getAlignValue() const
Return the constant as an llvm::Align, interpreting 0 as Align(1).
Definition: Constant.h:155
static ConstantPointerNull * get(PointerType *Ty)
Definition: Constant.cpp:201
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:496
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:499
PointerType * getType() const
Definition: Constant.cpp:207
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:489
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Constant.h:492
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:451
Constant * getPointer() const
The pointer that is signed in this ptrauth signed pointer.
Definition: Constant.cpp:431
Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
Definition: Constant.cpp:446
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
Definition: Constant.cpp:441
bool hasAddressDiscriminator() const
Whether there is any non-null address discriminator.
Definition: Constant.h:1115
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:1131
ConstantInt * getKey() const
The Key ID, an i32 constant.
Definition: Constant.cpp:436
bool hasSpecialAddressDiscriminator(uint64_t Value) const
Whether the address uses a special address discriminator.
Definition: Constant.h:1123
static ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc)
Return a pointer signed with the specified parameters.
Definition: Constant.cpp:423
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:1142
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constant.cpp:155
static std::enable_if_t< are_base_of< Constant, Csts... >::value, Constant * > get(StructType *T, Csts *...Vs)
Definition: Constant.h:386
static Constant * getAnon(Context &Ctx, ArrayRef< Constant * > V, bool Packed=false)
Definition: Constant.h:394
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:403
static Constant * getAnon(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct that has the specified elements.
Definition: Constant.h:391
StructType * getType() const
Specialization - reduce amount of casting.
Definition: Constant.h:411
static StructType * getTypeForElements(Context &Ctx, ArrayRef< Constant * > V, bool Packed=false)
This version of the method allows an empty list.
Definition: Constant.cpp:166
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: Constant.h:416
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:1243
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Constant.h:1234
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:1239
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:1230
static ConstantTokenNone * get(Context &Ctx)
Return the ConstantTokenNone.
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: Constant.h:430
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:19
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
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:1199
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
Definition: Constant.cpp:483
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Constant.h:1203
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:1208
GlobalValue * getGlobalValue() const
Definition: Constant.cpp:488
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:1212
static bool isValidLinkage(LinkageTypes L)
Definition: Constant.h:1049
Constant * getAliasee() const
Definition: Constant.cpp:385
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:1031
const GlobalObject * getAliaseeObject() const
Definition: Constant.cpp:390
void setAliasee(Constant *Aliasee)
Definition: Constant.cpp:377
GlobalObject * getAliaseeObject()
Definition: Constant.h:1044
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:856
static bool isValidLinkage(LinkageTypes L)
Definition: Constant.h:849
const Function * getResolverFunction() const
Definition: Constant.h:845
Constant * getResolver() const
Definition: Constant.cpp:335
void setResolver(Constant *Resolver)
Definition: Constant.cpp:326
Function * getResolverFunction()
Definition: Constant.cpp:339
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:829
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:859
Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final
\Returns the Use for the OpIdx'th operand.
Definition: Constant.h:671
unsigned getGlobalObjectSubClassData() const
Definition: Constant.h:711
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: Constant.h:700
void setAlignment(MaybeAlign Align)
Sets the alignment attribute of the GlobalObject.
Definition: Constant.cpp:264
VCallVisibility getVCallVisibility() const
Definition: Constant.h:748
bool hasSection() const
Check if this global has a custom object file section.
Definition: Constant.h:721
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: Constant.h:729
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:680
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Constant.h:676
void setGlobalObjectSubClassData(unsigned V)
Definition: Constant.cpp:272
uint64_t getAlignment() const
FIXME: Remove this function once transition to Align is over.
Definition: Constant.h:692
void setSection(StringRef S)
Change the section for this global.
Definition: Constant.cpp:280
GlobalObject(ClassID ID, llvm::GlobalObject *C, Context &Ctx)
Definition: Constant.h:668
bool canIncreaseAlignment() const
Returns true if the alignment of the value can be unilaterally increased.
Definition: Constant.h:757
UnnamedAddr getUnnamedAddr() const
Definition: Constant.h:636
bool hasDefaultVisibility() const
Definition: Constant.h:652
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
Definition: Constant.h:630
llvm::GlobalValue::UnnamedAddr UnnamedAddr
Definition: Constant.h:634
void setUnnamedAddr(UnnamedAddr V)
Definition: Constant.cpp:395
bool hasHiddenVisibility() const
Definition: Constant.h:655
VisibilityTypes getVisibility() const
Definition: Constant.h:649
unsigned getAddressSpace() const
Definition: Constant.h:618
bool hasGlobalUnnamedAddr() const
Definition: Constant.h:621
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:606
llvm::GlobalValue::VisibilityTypes VisibilityTypes
Definition: Constant.h:648
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
Definition: Constant.h:641
bool hasProtectedVisibility() const
Definition: Constant.h:658
GlobalValue(ClassID ID, llvm::GlobalValue *C, Context &Ctx)
Definition: Constant.h:599
void setVisibility(VisibilityTypes V)
Definition: Constant.cpp:402
Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: Constant.cpp:349
AttributeSet getAttributes() const
Return the attribute set for this global.
Definition: Constant.h:979
bool isExternallyInitialized() const
Definition: Constant.h:939
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
Definition: Constant.h:969
AttributeList getAttributesAsList(unsigned Index) const
Return attribute set as list with index.
Definition: Constant.h:986
unsigned getCodeModelRaw() const
Get the custom code model raw value of this global.
Definition: Constant.h:997
bool hasImplicitSection() const
Check if section name is present.
Definition: Constant.h:991
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
Definition: Constant.h:908
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition: Constant.h:888
Attribute getAttribute(StringRef Kind) const
Return the attribute object.
Definition: Constant.h:974
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:882
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:1012
void setExternallyInitialized(bool Val)
Definition: Constant.cpp:369
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists.
Definition: Constant.h:954
bool hasAttribute(StringRef Kind) const
Return true if the attribute exists.
Definition: Constant.h:959
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition: Constant.cpp:354
bool hasAttributes() const
Return true if any attributes exist.
Definition: Constant.h:964
std::optional< CodeModel::Model > getCodeModel() const
Get the custom code model of this global if it has one.
Definition: Constant.h:1005
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Definition: Constant.h:934
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:1015
bool hasUniqueInitializer() const
hasUniqueInitializer - Whether the global variable has an initializer, and any changes made to the in...
Definition: Constant.h:914
Provides API functions, like getIterator() and getReverseIterator() to GlobalIFunc,...
Definition: Constant.h:767
GlobalWithNodeAPI(Value::ClassID ID, LLVMParentT *C, Context &Ctx)
Definition: Constant.h:776
reverse_iterator getReverseIterator() const
Definition: Constant.h:794
Class to represent integer types.
Definition: Type.h:462
In SandboxIR the Module is mainly used to access the list of global objects.
Definition: Module.h:31
PointerType * getType() const
NoCFIValue is always a pointer.
Definition: Constant.cpp:419
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:1072
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:1084
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:1081
GlobalValue * getGlobalValue() const
Definition: Constant.cpp:414
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Constant.h:1076
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
Definition: Constant.cpp:409
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:590
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:587
PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
Definition: Constant.cpp:243
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:248
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constant.cpp:238
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:253
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:583
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition: Type.h:43
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Constant.h:544
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: Constant.h:548
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:227
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constant.cpp:212
void dumpOS(raw_ostream &OS) const override
Definition: Constant.h:551
UndefValue(ClassID ID, llvm::Constant *C, Context &Ctx)
Definition: Constant.h:511
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Constant.h:540
UndefValue(llvm::UndefValue *C, Context &Ctx)
Definition: Constant.h:509
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
Definition: Constant.h:535
UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
Definition: Constant.cpp:217
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:222
Represents a Def-use/Use-def edge in SandboxIR.
Definition: Use.h:32
A sandboxir::User has operands.
Definition: User.h:58
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:75
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:63
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition: Value.h:103
void dumpCommonSuffix(raw_ostream &OS) const
Definition: Value.cpp:105
Context & Ctx
All values point to the context.
Definition: Value.h:172
Type * getType() const
Definition: Value.cpp:46
Context & getContext() const
Definition: Value.h:256
void dumpCommonPrefix(raw_ostream &OS) const
Definition: Value.cpp:98
#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:71
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:372
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