1 //===- Use.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 // Sandbox IR Use. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_SANDBOXIR_USE_H 14 #define LLVM_SANDBOXIR_USE_H 15 16 #include "llvm/IR/Use.h" 17 #include "llvm/Support/raw_ostream.h" 18 19 namespace llvm::sandboxir { 20 21 class Context; 22 class Value; 23 class User; 24 25 /// Represents a Def-use/Use-def edge in SandboxIR. 26 /// NOTE: Unlike llvm::Use, this is not an integral part of the use-def chains. 27 /// It is also not uniqued and is currently passed by value, so you can have 28 /// more than one sandboxir::Use objects for the same use-def edge. 29 class Use { 30 llvm::Use *LLVMUse; 31 User *Usr; 32 Context *Ctx; 33 34 /// Don't allow the user to create a sandboxir::Use directly. Use(llvm::Use * LLVMUse,User * Usr,Context & Ctx)35 Use(llvm::Use *LLVMUse, User *Usr, Context &Ctx) 36 : LLVMUse(LLVMUse), Usr(Usr), Ctx(&Ctx) {} Use()37 Use() : LLVMUse(nullptr), Ctx(nullptr) {} 38 39 friend class Value; // For constructor 40 friend class User; // For constructor 41 friend class OperandUseIterator; // For constructor 42 friend class UserUseIterator; // For accessing members 43 44 public: 45 operator Value *() const { return get(); } 46 Value *get() const; 47 void set(Value *V); getUser()48 class User *getUser() const { return Usr; } 49 unsigned getOperandNo() const; getContext()50 Context *getContext() const { return Ctx; } 51 bool operator==(const Use &Other) const { 52 assert(Ctx == Other.Ctx && "Contexts differ!"); 53 return LLVMUse == Other.LLVMUse && Usr == Other.Usr; 54 } 55 bool operator!=(const Use &Other) const { return !(*this == Other); } 56 #ifndef NDEBUG 57 void dump(raw_ostream &OS) const; 58 void dump() const; 59 #endif // NDEBUG 60 }; 61 62 } // namespace llvm::sandboxir 63 64 #endif // LLVM_SANDBOXIR_USE_H 65