File indexing completed on 2026-05-10 08:44:25
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_SANDBOXIR_CONSTANT_H
0010 #define LLVM_SANDBOXIR_CONSTANT_H
0011
0012 #include "llvm/IR/BasicBlock.h"
0013 #include "llvm/IR/Constant.h"
0014 #include "llvm/IR/Constants.h"
0015 #include "llvm/IR/GlobalAlias.h"
0016 #include "llvm/IR/GlobalIFunc.h"
0017 #include "llvm/IR/GlobalObject.h"
0018 #include "llvm/IR/GlobalValue.h"
0019 #include "llvm/IR/GlobalVariable.h"
0020 #include "llvm/SandboxIR/Argument.h"
0021 #include "llvm/SandboxIR/BasicBlock.h"
0022 #include "llvm/SandboxIR/Context.h"
0023 #include "llvm/SandboxIR/Type.h"
0024 #include "llvm/SandboxIR/User.h"
0025 #include "llvm/Support/Compiler.h"
0026
0027 namespace llvm::sandboxir {
0028
0029 class BasicBlock;
0030 class Function;
0031
0032 class Constant : public sandboxir::User {
0033 protected:
0034 Constant(llvm::Constant *C, sandboxir::Context &SBCtx)
0035 : sandboxir::User(ClassID::Constant, C, SBCtx) {}
0036 Constant(ClassID ID, llvm::Constant *C, sandboxir::Context &SBCtx)
0037 : sandboxir::User(ID, C, SBCtx) {}
0038 friend class ConstantInt;
0039 friend class Function;
0040 friend class Context;
0041 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const override {
0042 return getOperandUseDefault(OpIdx, Verify);
0043 }
0044
0045 public:
0046
0047 static bool classof(const sandboxir::Value *From) {
0048 switch (From->getSubclassID()) {
0049 #define DEF_CONST(ID, CLASS) case ClassID::ID:
0050 #include "llvm/SandboxIR/Values.def"
0051 return true;
0052 default:
0053 return false;
0054 }
0055 }
0056 sandboxir::Context &getParent() const { return getContext(); }
0057 unsigned getUseOperandNo(const Use &Use) const override {
0058 return getUseOperandNoDefault(Use);
0059 }
0060 #ifndef NDEBUG
0061 void verify() const override {
0062 assert(isa<llvm::Constant>(Val) && "Expected Constant!");
0063 }
0064 void dumpOS(raw_ostream &OS) const override;
0065 #endif
0066 };
0067
0068
0069 class ConstantInt : public Constant {
0070 ConstantInt(llvm::ConstantInt *C, Context &Ctx)
0071 : Constant(ClassID::ConstantInt, C, Ctx) {}
0072 friend class Context;
0073
0074 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
0075 llvm_unreachable("ConstantInt has no operands!");
0076 }
0077
0078 public:
0079 static ConstantInt *getTrue(Context &Ctx);
0080 static ConstantInt *getFalse(Context &Ctx);
0081 static ConstantInt *getBool(Context &Ctx, bool V);
0082 static Constant *getTrue(Type *Ty);
0083 static Constant *getFalse(Type *Ty);
0084 static Constant *getBool(Type *Ty, bool V);
0085
0086
0087
0088 static ConstantInt *get(Type *Ty, uint64_t V, bool IsSigned = false);
0089
0090
0091
0092
0093
0094
0095
0096 static ConstantInt *get(IntegerType *Ty, uint64_t V, bool IsSigned = false);
0097
0098
0099
0100
0101
0102
0103 static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
0104 static Constant *getSigned(Type *Ty, int64_t V);
0105
0106
0107
0108 static ConstantInt *get(Context &Ctx, const APInt &V);
0109
0110
0111
0112 static ConstantInt *get(IntegerType *Ty, StringRef Str, uint8_t Radix);
0113
0114
0115
0116 static Constant *get(Type *Ty, const APInt &V);
0117
0118
0119
0120
0121 inline const APInt &getValue() const {
0122 return cast<llvm::ConstantInt>(Val)->getValue();
0123 }
0124
0125
0126 unsigned getBitWidth() const {
0127 return cast<llvm::ConstantInt>(Val)->getBitWidth();
0128 }
0129
0130
0131
0132
0133 inline uint64_t getZExtValue() const {
0134 return cast<llvm::ConstantInt>(Val)->getZExtValue();
0135 }
0136
0137
0138
0139
0140
0141 inline int64_t getSExtValue() const {
0142 return cast<llvm::ConstantInt>(Val)->getSExtValue();
0143 }
0144
0145
0146
0147
0148 inline MaybeAlign getMaybeAlignValue() const {
0149 return cast<llvm::ConstantInt>(Val)->getMaybeAlignValue();
0150 }
0151
0152
0153
0154
0155 inline Align getAlignValue() const {
0156 return cast<llvm::ConstantInt>(Val)->getAlignValue();
0157 }
0158
0159
0160
0161
0162
0163 bool equalsInt(uint64_t V) const {
0164 return cast<llvm::ConstantInt>(Val)->equalsInt(V);
0165 }
0166
0167
0168
0169 IntegerType *getIntegerType() const;
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 static bool isValueValidForType(Type *Ty, uint64_t V);
0181 static bool isValueValidForType(Type *Ty, int64_t V);
0182
0183 bool isNegative() const { return cast<llvm::ConstantInt>(Val)->isNegative(); }
0184
0185
0186
0187
0188 bool isZero() const { return cast<llvm::ConstantInt>(Val)->isZero(); }
0189
0190
0191
0192
0193
0194 bool isOne() const { return cast<llvm::ConstantInt>(Val)->isOne(); }
0195
0196
0197
0198
0199
0200 bool isMinusOne() const { return cast<llvm::ConstantInt>(Val)->isMinusOne(); }
0201
0202
0203
0204
0205
0206
0207 bool isMaxValue(bool IsSigned) const {
0208 return cast<llvm::ConstantInt>(Val)->isMaxValue(IsSigned);
0209 }
0210
0211
0212
0213
0214
0215
0216 bool isMinValue(bool IsSigned) const {
0217 return cast<llvm::ConstantInt>(Val)->isMinValue(IsSigned);
0218 }
0219
0220
0221
0222
0223
0224
0225 bool uge(uint64_t Num) const {
0226 return cast<llvm::ConstantInt>(Val)->uge(Num);
0227 }
0228
0229
0230
0231
0232
0233
0234 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
0235 return cast<llvm::ConstantInt>(Val)->getLimitedValue(Limit);
0236 }
0237
0238
0239 static bool classof(const sandboxir::Value *From) {
0240 return From->getSubclassID() == ClassID::ConstantInt;
0241 }
0242 unsigned getUseOperandNo(const Use &Use) const override {
0243 llvm_unreachable("ConstantInt has no operands!");
0244 }
0245 #ifndef NDEBUG
0246 void verify() const override {
0247 assert(isa<llvm::ConstantInt>(Val) && "Expected a ConstantInst!");
0248 }
0249 void dumpOS(raw_ostream &OS) const override {
0250 dumpCommonPrefix(OS);
0251 dumpCommonSuffix(OS);
0252 }
0253 #endif
0254 };
0255
0256
0257 class ConstantFP final : public Constant {
0258 ConstantFP(llvm::ConstantFP *C, Context &Ctx)
0259 : Constant(ClassID::ConstantFP, C, Ctx) {}
0260 friend class Context;
0261
0262 public:
0263
0264
0265
0266
0267 static Constant *get(Type *Ty, double V);
0268
0269
0270
0271 static Constant *get(Type *Ty, const APFloat &V);
0272
0273 static Constant *get(Type *Ty, StringRef Str);
0274
0275 static ConstantFP *get(const APFloat &V, Context &Ctx);
0276
0277 static Constant *getNaN(Type *Ty, bool Negative = false,
0278 uint64_t Payload = 0);
0279 static Constant *getQNaN(Type *Ty, bool Negative = false,
0280 APInt *Payload = nullptr);
0281 static Constant *getSNaN(Type *Ty, bool Negative = false,
0282 APInt *Payload = nullptr);
0283 static Constant *getZero(Type *Ty, bool Negative = false);
0284
0285 static Constant *getNegativeZero(Type *Ty);
0286 static Constant *getInfinity(Type *Ty, bool Negative = false);
0287
0288
0289 static bool isValueValidForType(Type *Ty, const APFloat &V);
0290
0291 inline const APFloat &getValueAPF() const {
0292 return cast<llvm::ConstantFP>(Val)->getValueAPF();
0293 }
0294 inline const APFloat &getValue() const {
0295 return cast<llvm::ConstantFP>(Val)->getValue();
0296 }
0297
0298
0299 bool isZero() const { return cast<llvm::ConstantFP>(Val)->isZero(); }
0300
0301
0302 bool isNegative() const { return cast<llvm::ConstantFP>(Val)->isNegative(); }
0303
0304
0305 bool isInfinity() const { return cast<llvm::ConstantFP>(Val)->isInfinity(); }
0306
0307
0308 bool isNaN() const { return cast<llvm::ConstantFP>(Val)->isNaN(); }
0309
0310
0311
0312
0313
0314
0315
0316 bool isExactlyValue(const APFloat &V) const {
0317 return cast<llvm::ConstantFP>(Val)->isExactlyValue(V);
0318 }
0319
0320 bool isExactlyValue(double V) const {
0321 return cast<llvm::ConstantFP>(Val)->isExactlyValue(V);
0322 }
0323
0324
0325 static bool classof(const sandboxir::Value *From) {
0326 return From->getSubclassID() == ClassID::ConstantFP;
0327 }
0328
0329
0330 unsigned getUseOperandNo(const Use &Use) const final {
0331 llvm_unreachable("ConstantFP has no operands!");
0332 }
0333 #ifndef NDEBUG
0334 void verify() const override {
0335 assert(isa<llvm::ConstantFP>(Val) && "Expected a ConstantFP!");
0336 }
0337 void dumpOS(raw_ostream &OS) const override {
0338 dumpCommonPrefix(OS);
0339 dumpCommonSuffix(OS);
0340 }
0341 #endif
0342 };
0343
0344
0345 class ConstantAggregate : public Constant {
0346 protected:
0347 ConstantAggregate(ClassID ID, llvm::Constant *C, Context &Ctx)
0348 : Constant(ID, C, Ctx) {}
0349
0350 public:
0351
0352 static bool classof(const sandboxir::Value *From) {
0353 auto ID = From->getSubclassID();
0354 return ID == ClassID::ConstantVector || ID == ClassID::ConstantStruct ||
0355 ID == ClassID::ConstantArray;
0356 }
0357 };
0358
0359 class ConstantArray final : public ConstantAggregate {
0360 ConstantArray(llvm::ConstantArray *C, Context &Ctx)
0361 : ConstantAggregate(ClassID::ConstantArray, C, Ctx) {}
0362 friend class Context;
0363
0364 public:
0365 static Constant *get(ArrayType *T, ArrayRef<Constant *> V);
0366 ArrayType *getType() const;
0367
0368
0369
0370
0371 static bool classof(const Value *From) {
0372 return From->getSubclassID() == ClassID::ConstantArray;
0373 }
0374 };
0375
0376 class ConstantStruct final : public ConstantAggregate {
0377 ConstantStruct(llvm::ConstantStruct *C, Context &Ctx)
0378 : ConstantAggregate(ClassID::ConstantStruct, C, Ctx) {}
0379 friend class Context;
0380
0381 public:
0382 static Constant *get(StructType *T, ArrayRef<Constant *> V);
0383
0384 template <typename... Csts>
0385 static std::enable_if_t<are_base_of<Constant, Csts...>::value, Constant *>
0386 get(StructType *T, Csts *...Vs) {
0387 return get(T, ArrayRef<Constant *>({Vs...}));
0388 }
0389
0390
0391 static Constant *getAnon(ArrayRef<Constant *> V, bool Packed = false) {
0392 return get(getTypeForElements(V, Packed), V);
0393 }
0394 static Constant *getAnon(Context &Ctx, ArrayRef<Constant *> V,
0395 bool Packed = false) {
0396 return get(getTypeForElements(Ctx, V, Packed), V);
0397 }
0398
0399 static StructType *getTypeForElements(Context &Ctx, ArrayRef<Constant *> V,
0400 bool Packed = false);
0401
0402
0403 static StructType *getTypeForElements(ArrayRef<Constant *> V,
0404 bool Packed = false) {
0405 assert(!V.empty() &&
0406 "ConstantStruct::getTypeForElements cannot be called on empty list");
0407 return getTypeForElements(V[0]->getContext(), V, Packed);
0408 }
0409
0410
0411 inline StructType *getType() const {
0412 return cast<StructType>(Value::getType());
0413 }
0414
0415
0416 static bool classof(const Value *From) {
0417 return From->getSubclassID() == ClassID::ConstantStruct;
0418 }
0419 };
0420
0421 class ConstantVector final : public ConstantAggregate {
0422 ConstantVector(llvm::ConstantVector *C, Context &Ctx)
0423 : ConstantAggregate(ClassID::ConstantVector, C, Ctx) {}
0424 friend class Context;
0425
0426 public:
0427
0428
0429
0430 static bool classof(const Value *From) {
0431 return From->getSubclassID() == ClassID::ConstantVector;
0432 }
0433 };
0434
0435
0436 class ConstantAggregateZero final : public Constant {
0437 ConstantAggregateZero(llvm::ConstantAggregateZero *C, Context &Ctx)
0438 : Constant(ClassID::ConstantAggregateZero, C, Ctx) {}
0439 friend class Context;
0440
0441 public:
0442 static ConstantAggregateZero *get(Type *Ty);
0443
0444
0445 Constant *getSequentialElement() const;
0446
0447
0448 Constant *getStructElement(unsigned Elt) const;
0449
0450
0451 Constant *getElementValue(Constant *C) const;
0452
0453 Constant *getElementValue(unsigned Idx) const;
0454
0455 ElementCount getElementCount() const {
0456 return cast<llvm::ConstantAggregateZero>(Val)->getElementCount();
0457 }
0458
0459
0460 static bool classof(const sandboxir::Value *From) {
0461 return From->getSubclassID() == ClassID::ConstantAggregateZero;
0462 }
0463 unsigned getUseOperandNo(const Use &Use) const final {
0464 llvm_unreachable("ConstantAggregateZero has no operands!");
0465 }
0466 #ifndef NDEBUG
0467 void verify() const override {
0468 assert(isa<llvm::ConstantAggregateZero>(Val) && "Expected a CAZ!");
0469 }
0470 void dumpOS(raw_ostream &OS) const override {
0471 dumpCommonPrefix(OS);
0472 dumpCommonSuffix(OS);
0473 }
0474 #endif
0475 };
0476
0477
0478 class ConstantPointerNull final : public Constant {
0479 ConstantPointerNull(llvm::ConstantPointerNull *C, Context &Ctx)
0480 : Constant(ClassID::ConstantPointerNull, C, Ctx) {}
0481 friend class Context;
0482
0483 public:
0484 static ConstantPointerNull *get(PointerType *Ty);
0485
0486 PointerType *getType() const;
0487
0488
0489 static bool classof(const sandboxir::Value *From) {
0490 return From->getSubclassID() == ClassID::ConstantPointerNull;
0491 }
0492 unsigned getUseOperandNo(const Use &Use) const final {
0493 llvm_unreachable("ConstantPointerNull has no operands!");
0494 }
0495 #ifndef NDEBUG
0496 void verify() const override {
0497 assert(isa<llvm::ConstantPointerNull>(Val) && "Expected a CPNull!");
0498 }
0499 void dumpOS(raw_ostream &OS) const override {
0500 dumpCommonPrefix(OS);
0501 dumpCommonSuffix(OS);
0502 }
0503 #endif
0504 };
0505
0506
0507 class UndefValue : public Constant {
0508 protected:
0509 UndefValue(llvm::UndefValue *C, Context &Ctx)
0510 : Constant(ClassID::UndefValue, C, Ctx) {}
0511 UndefValue(ClassID ID, llvm::Constant *C, Context &Ctx)
0512 : Constant(ID, C, Ctx) {}
0513 friend class Context;
0514
0515 public:
0516
0517 static UndefValue *get(Type *T);
0518
0519
0520
0521 UndefValue *getSequentialElement() const;
0522
0523
0524
0525 UndefValue *getStructElement(unsigned Elt) const;
0526
0527
0528
0529 UndefValue *getElementValue(Constant *C) const;
0530
0531
0532 UndefValue *getElementValue(unsigned Idx) const;
0533
0534
0535 unsigned getNumElements() const {
0536 return cast<llvm::UndefValue>(Val)->getNumElements();
0537 }
0538
0539
0540 static bool classof(const sandboxir::Value *From) {
0541 return From->getSubclassID() == ClassID::UndefValue ||
0542 From->getSubclassID() == ClassID::PoisonValue;
0543 }
0544 unsigned getUseOperandNo(const Use &Use) const final {
0545 llvm_unreachable("UndefValue has no operands!");
0546 }
0547 #ifndef NDEBUG
0548 void verify() const override {
0549 assert(isa<llvm::UndefValue>(Val) && "Expected an UndefValue!");
0550 }
0551 void dumpOS(raw_ostream &OS) const override {
0552 dumpCommonPrefix(OS);
0553 dumpCommonSuffix(OS);
0554 }
0555 #endif
0556 };
0557
0558 class PoisonValue final : public UndefValue {
0559 PoisonValue(llvm::PoisonValue *C, Context &Ctx)
0560 : UndefValue(ClassID::PoisonValue, C, Ctx) {}
0561 friend class Context;
0562
0563 public:
0564
0565 static PoisonValue *get(Type *T);
0566
0567
0568
0569 PoisonValue *getSequentialElement() const;
0570
0571
0572
0573 PoisonValue *getStructElement(unsigned Elt) const;
0574
0575
0576
0577 PoisonValue *getElementValue(Constant *C) const;
0578
0579
0580 PoisonValue *getElementValue(unsigned Idx) const;
0581
0582
0583 static bool classof(const sandboxir::Value *From) {
0584 return From->getSubclassID() == ClassID::PoisonValue;
0585 }
0586 #ifndef NDEBUG
0587 void verify() const override {
0588 assert(isa<llvm::PoisonValue>(Val) && "Expected a PoisonValue!");
0589 }
0590 void dumpOS(raw_ostream &OS) const override {
0591 dumpCommonPrefix(OS);
0592 dumpCommonSuffix(OS);
0593 }
0594 #endif
0595 };
0596
0597 class GlobalValue : public Constant {
0598 protected:
0599 GlobalValue(ClassID ID, llvm::GlobalValue *C, Context &Ctx)
0600 : Constant(ID, C, Ctx) {}
0601 friend class Context;
0602
0603 public:
0604 using LinkageTypes = llvm::GlobalValue::LinkageTypes;
0605
0606 static bool classof(const sandboxir::Value *From) {
0607 switch (From->getSubclassID()) {
0608 case ClassID::Function:
0609 case ClassID::GlobalVariable:
0610 case ClassID::GlobalAlias:
0611 case ClassID::GlobalIFunc:
0612 return true;
0613 default:
0614 return false;
0615 }
0616 }
0617
0618 unsigned getAddressSpace() const {
0619 return cast<llvm::GlobalValue>(Val)->getAddressSpace();
0620 }
0621 bool hasGlobalUnnamedAddr() const {
0622 return cast<llvm::GlobalValue>(Val)->hasGlobalUnnamedAddr();
0623 }
0624
0625
0626
0627
0628
0629
0630 bool hasAtLeastLocalUnnamedAddr() const {
0631 return cast<llvm::GlobalValue>(Val)->hasAtLeastLocalUnnamedAddr();
0632 }
0633
0634 using UnnamedAddr = llvm::GlobalValue::UnnamedAddr;
0635
0636 UnnamedAddr getUnnamedAddr() const {
0637 return cast<llvm::GlobalValue>(Val)->getUnnamedAddr();
0638 }
0639 void setUnnamedAddr(UnnamedAddr V);
0640
0641 static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B) {
0642 return llvm::GlobalValue::getMinUnnamedAddr(A, B);
0643 }
0644
0645 bool hasComdat() const { return cast<llvm::GlobalValue>(Val)->hasComdat(); }
0646
0647
0648 using VisibilityTypes = llvm::GlobalValue::VisibilityTypes;
0649 VisibilityTypes getVisibility() const {
0650 return cast<llvm::GlobalValue>(Val)->getVisibility();
0651 }
0652 bool hasDefaultVisibility() const {
0653 return cast<llvm::GlobalValue>(Val)->hasDefaultVisibility();
0654 }
0655 bool hasHiddenVisibility() const {
0656 return cast<llvm::GlobalValue>(Val)->hasHiddenVisibility();
0657 }
0658 bool hasProtectedVisibility() const {
0659 return cast<llvm::GlobalValue>(Val)->hasProtectedVisibility();
0660 }
0661 void setVisibility(VisibilityTypes V);
0662
0663
0664 };
0665
0666 class GlobalObject : public GlobalValue {
0667 protected:
0668 GlobalObject(ClassID ID, llvm::GlobalObject *C, Context &Ctx)
0669 : GlobalValue(ID, C, Ctx) {}
0670 friend class Context;
0671 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
0672 return getOperandUseDefault(OpIdx, Verify);
0673 }
0674
0675 public:
0676 unsigned getUseOperandNo(const Use &Use) const final {
0677 return getUseOperandNoDefault(Use);
0678 }
0679
0680 static bool classof(const sandboxir::Value *From) {
0681 switch (From->getSubclassID()) {
0682 case ClassID::Function:
0683 case ClassID::GlobalVariable:
0684 case ClassID::GlobalIFunc:
0685 return true;
0686 default:
0687 return false;
0688 }
0689 }
0690
0691
0692 uint64_t getAlignment() const {
0693 return cast<llvm::GlobalObject>(Val)->getAlignment();
0694 }
0695
0696
0697
0698
0699
0700 MaybeAlign getAlign() const {
0701 return cast<llvm::GlobalObject>(Val)->getAlign();
0702 }
0703
0704
0705
0706
0707
0708
0709 void setAlignment(MaybeAlign Align);
0710
0711 unsigned getGlobalObjectSubClassData() const {
0712 return cast<llvm::GlobalObject>(Val)->getGlobalObjectSubClassData();
0713 }
0714
0715 void setGlobalObjectSubClassData(unsigned V);
0716
0717
0718
0719
0720
0721 bool hasSection() const {
0722 return cast<llvm::GlobalObject>(Val)->hasSection();
0723 }
0724
0725
0726
0727
0728
0729 StringRef getSection() const {
0730 return cast<llvm::GlobalObject>(Val)->getSection();
0731 }
0732
0733
0734
0735
0736
0737 void setSection(StringRef S);
0738
0739 bool hasComdat() const { return cast<llvm::GlobalObject>(Val)->hasComdat(); }
0740
0741
0742
0743
0744
0745
0746 using VCallVisibility = llvm::GlobalObject::VCallVisibility;
0747
0748 VCallVisibility getVCallVisibility() const {
0749 return cast<llvm::GlobalObject>(Val)->getVCallVisibility();
0750 }
0751
0752
0753
0754
0755
0756
0757 bool canIncreaseAlignment() const {
0758 return cast<llvm::GlobalObject>(Val)->canIncreaseAlignment();
0759 }
0760 };
0761
0762
0763
0764
0765 template <typename GlobalT, typename LLVMGlobalT, typename ParentT,
0766 typename LLVMParentT>
0767 class GlobalWithNodeAPI : public ParentT {
0768
0769 struct LLVMGVToGV {
0770 Context &Ctx;
0771 LLVMGVToGV(Context &Ctx) : Ctx(Ctx) {}
0772 GlobalT &operator()(LLVMGlobalT &LLVMGV) const;
0773 };
0774
0775 public:
0776 GlobalWithNodeAPI(Value::ClassID ID, LLVMParentT *C, Context &Ctx)
0777 : ParentT(ID, C, Ctx) {}
0778
0779 Module *getParent() const {
0780 llvm::Module *LLVMM = cast<LLVMGlobalT>(this->Val)->getParent();
0781 return this->Ctx.getModule(LLVMM);
0782 }
0783
0784 using iterator = mapped_iterator<
0785 decltype(static_cast<LLVMGlobalT *>(nullptr)->getIterator()), LLVMGVToGV>;
0786 using reverse_iterator = mapped_iterator<
0787 decltype(static_cast<LLVMGlobalT *>(nullptr)->getReverseIterator()),
0788 LLVMGVToGV>;
0789 iterator getIterator() const {
0790 auto *LLVMGV = cast<LLVMGlobalT>(this->Val);
0791 LLVMGVToGV ToGV(this->Ctx);
0792 return map_iterator(LLVMGV->getIterator(), ToGV);
0793 }
0794 reverse_iterator getReverseIterator() const {
0795 auto *LLVMGV = cast<LLVMGlobalT>(this->Val);
0796 LLVMGVToGV ToGV(this->Ctx);
0797 return map_iterator(LLVMGV->getReverseIterator(), ToGV);
0798 }
0799 };
0800
0801
0802 extern template LLVM_TEMPLATE_ABI GlobalIFunc &
0803 GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
0804 llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
0805 &LLVMGV)
0806 const;
0807 extern template LLVM_TEMPLATE_ABI Function &
0808 GlobalWithNodeAPI<Function, llvm::Function, GlobalObject, llvm::GlobalObject>::
0809 LLVMGVToGV::operator()(llvm::Function &LLVMGV) const;
0810
0811 extern template LLVM_TEMPLATE_ABI GlobalVariable &GlobalWithNodeAPI<
0812 GlobalVariable, llvm::GlobalVariable, GlobalObject,
0813 llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalVariable &LLVMGV)
0814 const;
0815 extern template LLVM_TEMPLATE_ABI GlobalAlias &
0816 GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
0817 llvm::GlobalValue>::LLVMGVToGV::operator()(llvm::GlobalAlias
0818 &LLVMGV) const;
0819
0820 class GlobalIFunc final
0821 : public GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
0822 llvm::GlobalObject> {
0823 GlobalIFunc(llvm::GlobalObject *C, Context &Ctx)
0824 : GlobalWithNodeAPI(ClassID::GlobalIFunc, C, Ctx) {}
0825 friend class Context;
0826
0827 public:
0828
0829 static bool classof(const sandboxir::Value *From) {
0830 return From->getSubclassID() == ClassID::GlobalIFunc;
0831 }
0832
0833
0834
0835
0836
0837
0838 void setResolver(Constant *Resolver);
0839
0840 Constant *getResolver() const;
0841
0842
0843
0844 Function *getResolverFunction();
0845 const Function *getResolverFunction() const {
0846 return const_cast<GlobalIFunc *>(this)->getResolverFunction();
0847 }
0848
0849 static bool isValidLinkage(LinkageTypes L) {
0850 return llvm::GlobalIFunc::isValidLinkage(L);
0851 }
0852
0853
0854
0855 #ifndef NDEBUG
0856 void verify() const override {
0857 assert(isa<llvm::GlobalIFunc>(Val) && "Expected a GlobalIFunc!");
0858 }
0859 void dumpOS(raw_ostream &OS) const override {
0860 dumpCommonPrefix(OS);
0861 dumpCommonSuffix(OS);
0862 }
0863 #endif
0864 };
0865
0866 class GlobalVariable final
0867 : public GlobalWithNodeAPI<GlobalVariable, llvm::GlobalVariable,
0868 GlobalObject, llvm::GlobalObject> {
0869 GlobalVariable(llvm::GlobalObject *C, Context &Ctx)
0870 : GlobalWithNodeAPI(ClassID::GlobalVariable, C, Ctx) {}
0871 friend class Context;
0872
0873
0874 struct LLVMGVToGV {
0875 Context &Ctx;
0876 LLVMGVToGV(Context &Ctx) : Ctx(Ctx) {}
0877 GlobalVariable &operator()(llvm::GlobalVariable &LLVMGV) const;
0878 };
0879
0880 public:
0881
0882 static bool classof(const sandboxir::Value *From) {
0883 return From->getSubclassID() == ClassID::GlobalVariable;
0884 }
0885
0886
0887
0888 inline bool hasInitializer() const {
0889 return cast<llvm::GlobalVariable>(Val)->hasInitializer();
0890 }
0891
0892
0893
0894
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908 inline bool hasDefinitiveInitializer() const {
0909 return cast<llvm::GlobalVariable>(Val)->hasDefinitiveInitializer();
0910 }
0911
0912
0913
0914 inline bool hasUniqueInitializer() const {
0915 return cast<llvm::GlobalVariable>(Val)->hasUniqueInitializer();
0916 }
0917
0918
0919
0920
0921
0922 Constant *getInitializer() const;
0923
0924
0925
0926 void setInitializer(Constant *InitVal);
0927
0928
0929
0930
0931
0932
0933
0934 bool isConstant() const {
0935 return cast<llvm::GlobalVariable>(Val)->isConstant();
0936 }
0937 void setConstant(bool V);
0938
0939 bool isExternallyInitialized() const {
0940 return cast<llvm::GlobalVariable>(Val)->isExternallyInitialized();
0941 }
0942 void setExternallyInitialized(bool Val);
0943
0944
0945
0946
0947
0948
0949
0950
0951
0952
0953
0954 bool hasAttribute(Attribute::AttrKind Kind) const {
0955 return cast<llvm::GlobalVariable>(Val)->hasAttribute(Kind);
0956 }
0957
0958
0959 bool hasAttribute(StringRef Kind) const {
0960 return cast<llvm::GlobalVariable>(Val)->hasAttribute(Kind);
0961 }
0962
0963
0964 bool hasAttributes() const {
0965 return cast<llvm::GlobalVariable>(Val)->hasAttributes();
0966 }
0967
0968
0969 Attribute getAttribute(Attribute::AttrKind Kind) const {
0970 return cast<llvm::GlobalVariable>(Val)->getAttribute(Kind);
0971 }
0972
0973
0974 Attribute getAttribute(StringRef Kind) const {
0975 return cast<llvm::GlobalVariable>(Val)->getAttribute(Kind);
0976 }
0977
0978
0979 AttributeSet getAttributes() const {
0980 return cast<llvm::GlobalVariable>(Val)->getAttributes();
0981 }
0982
0983
0984
0985
0986 AttributeList getAttributesAsList(unsigned Index) const {
0987 return cast<llvm::GlobalVariable>(Val)->getAttributesAsList(Index);
0988 }
0989
0990
0991 bool hasImplicitSection() const {
0992 return cast<llvm::GlobalVariable>(Val)->hasImplicitSection();
0993 }
0994
0995
0996
0997 unsigned getCodeModelRaw() const {
0998 return cast<llvm::GlobalVariable>(Val)->getCodeModelRaw();
0999 }
1000
1001
1002
1003
1004
1005 std::optional<CodeModel::Model> getCodeModel() const {
1006 return cast<llvm::GlobalVariable>(Val)->getCodeModel();
1007 }
1008
1009
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 {
1016 dumpCommonPrefix(OS);
1017 dumpCommonSuffix(OS);
1018 }
1019 #endif
1020 };
1021
1022 class GlobalAlias final
1023 : public GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
1024 llvm::GlobalValue> {
1025 GlobalAlias(llvm::GlobalAlias *C, Context &Ctx)
1026 : GlobalWithNodeAPI(ClassID::GlobalAlias, C, Ctx) {}
1027 friend class Context;
1028
1029 public:
1030
1031 static bool classof(const sandboxir::Value *From) {
1032 return From->getSubclassID() == ClassID::GlobalAlias;
1033 }
1034
1035
1036
1037
1038
1039
1040 void setAliasee(Constant *Aliasee);
1041 Constant *getAliasee() const;
1042
1043 const GlobalObject *getAliaseeObject() const;
1044 GlobalObject *getAliaseeObject() {
1045 return const_cast<GlobalObject *>(
1046 static_cast<const GlobalAlias *>(this)->getAliaseeObject());
1047 }
1048
1049 static bool isValidLinkage(LinkageTypes L) {
1050 return llvm::GlobalAlias::isValidLinkage(L);
1051 }
1052 };
1053
1054 class NoCFIValue final : public Constant {
1055 NoCFIValue(llvm::NoCFIValue *C, Context &Ctx)
1056 : Constant(ClassID::NoCFIValue, C, Ctx) {}
1057 friend class Context;
1058
1059 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
1060 return getOperandUseDefault(OpIdx, Verify);
1061 }
1062
1063 public:
1064
1065 static NoCFIValue *get(GlobalValue *GV);
1066
1067 GlobalValue *getGlobalValue() const;
1068
1069
1070 PointerType *getType() const;
1071
1072 static bool classof(const sandboxir::Value *From) {
1073 return From->getSubclassID() == ClassID::NoCFIValue;
1074 }
1075
1076 unsigned getUseOperandNo(const Use &Use) const final {
1077 return getUseOperandNoDefault(Use);
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 {
1085 dumpCommonPrefix(OS);
1086 dumpCommonSuffix(OS);
1087 }
1088 #endif
1089 };
1090
1091 class ConstantPtrAuth final : public Constant {
1092 ConstantPtrAuth(llvm::ConstantPtrAuth *C, Context &Ctx)
1093 : Constant(ClassID::ConstantPtrAuth, C, Ctx) {}
1094 friend class Context;
1095
1096 public:
1097
1098 static ConstantPtrAuth *get(Constant *Ptr, ConstantInt *Key,
1099 ConstantInt *Disc, Constant *AddrDisc);
1100
1101 Constant *getPointer() const;
1102
1103
1104 ConstantInt *getKey() const;
1105
1106
1107 ConstantInt *getDiscriminator() const;
1108
1109
1110
1111
1112 Constant *getAddrDiscriminator() const;
1113
1114
1115 bool hasAddressDiscriminator() const {
1116 return cast<llvm::ConstantPtrAuth>(Val)->hasAddressDiscriminator();
1117 }
1118
1119
1120
1121
1122
1123 bool hasSpecialAddressDiscriminator(uint64_t Value) const {
1124 return cast<llvm::ConstantPtrAuth>(Val)->hasSpecialAddressDiscriminator(
1125 Value);
1126 }
1127
1128
1129
1130
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
1138
1139 ConstantPtrAuth *getWithSameSchema(Constant *Pointer) const;
1140
1141
1142 static bool classof(const sandboxir::Value *From) {
1143 return From->getSubclassID() == ClassID::ConstantPtrAuth;
1144 }
1145 };
1146
1147 class ConstantExpr : public Constant {
1148 ConstantExpr(llvm::ConstantExpr *C, Context &Ctx)
1149 : Constant(ClassID::ConstantExpr, C, Ctx) {}
1150 friend class Context;
1151
1152 public:
1153
1154 static bool classof(const sandboxir::Value *From) {
1155 return From->getSubclassID() == ClassID::ConstantExpr;
1156 }
1157
1158 };
1159
1160 class BlockAddress final : public Constant {
1161 BlockAddress(llvm::BlockAddress *C, Context &Ctx)
1162 : Constant(ClassID::BlockAddress, C, Ctx) {}
1163 friend class Context;
1164
1165 public:
1166
1167 static BlockAddress *get(Function *F, BasicBlock *BB);
1168
1169
1170
1171 static BlockAddress *get(BasicBlock *BB);
1172
1173
1174
1175
1176 static BlockAddress *lookup(const BasicBlock *BB);
1177
1178 Function *getFunction() const;
1179 BasicBlock *getBasicBlock() const;
1180
1181
1182 static bool classof(const sandboxir::Value *From) {
1183 return From->getSubclassID() == ClassID::BlockAddress;
1184 }
1185 };
1186
1187 class DSOLocalEquivalent final : public Constant {
1188 DSOLocalEquivalent(llvm::DSOLocalEquivalent *C, Context &Ctx)
1189 : Constant(ClassID::DSOLocalEquivalent, C, Ctx) {}
1190 friend class Context;
1191
1192 public:
1193
1194 static DSOLocalEquivalent *get(GlobalValue *GV);
1195
1196 GlobalValue *getGlobalValue() const;
1197
1198
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 {
1213 dumpCommonPrefix(OS);
1214 dumpCommonSuffix(OS);
1215 }
1216 #endif
1217 };
1218
1219
1220 class ConstantTokenNone final : public Constant {
1221 ConstantTokenNone(llvm::ConstantTokenNone *C, Context &Ctx)
1222 : Constant(ClassID::ConstantTokenNone, C, Ctx) {}
1223 friend class Context;
1224
1225 public:
1226
1227 static ConstantTokenNone *get(Context &Ctx);
1228
1229
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 {
1244 dumpCommonPrefix(OS);
1245 dumpCommonSuffix(OS);
1246 }
1247 #endif
1248 };
1249
1250 }
1251
1252 #endif