LLVM 22.0.0git
Use.h
Go to the documentation of this file.
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"
19
20namespace llvm::sandboxir {
21
22class Context;
23class Value;
24class User;
25class CallBase;
26class CallBrInst;
27class PHINode;
28
29/// Represents a Def-use/Use-def edge in SandboxIR.
30/// NOTE: Unlike llvm::Use, this is not an integral part of the use-def chains.
31/// It is also not uniqued and is currently passed by value, so you can have
32/// more than one sandboxir::Use objects for the same use-def edge.
33class Use {
34 llvm::Use *LLVMUse;
35 User *Usr;
36 Context *Ctx;
37
38 /// Don't allow the user to create a sandboxir::Use directly.
39 Use(llvm::Use *LLVMUse, User *Usr, Context &Ctx)
40 : LLVMUse(LLVMUse), Usr(Usr), Ctx(&Ctx) {}
41 Use() : LLVMUse(nullptr), Ctx(nullptr) {}
42
43 friend class Value; // For constructor
44 friend class User; // For constructor
45 friend class OperandUseIterator; // For constructor
46 friend class UserUseIterator; // For accessing members
47 friend class CallBase; // For LLVMUse
48 friend class CallBrInst; // For constructor
49 friend class PHINode; // For LLVMUse
50
51public:
52 operator Value *() const { return get(); }
53 LLVM_ABI Value *get() const;
54 LLVM_ABI void set(Value *V);
55 class User *getUser() const { return Usr; }
56 LLVM_ABI unsigned getOperandNo() const;
57 LLVM_ABI void swap(Use &OtherUse);
58 Context *getContext() const { return Ctx; }
59 bool operator==(const Use &Other) const {
60 assert(Ctx == Other.Ctx && "Contexts differ!");
61 return LLVMUse == Other.LLVMUse && Usr == Other.Usr;
62 }
63 bool operator!=(const Use &Other) const { return !(*this == Other); }
64#ifndef NDEBUG
65 void dumpOS(raw_ostream &OS) const;
66 void dump() const;
67#endif // NDEBUG
68};
69
70} // namespace llvm::sandboxir
71
72#endif // LLVM_SANDBOXIR_USE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition: Compiler.h:213
This defines the Use class.
raw_pwrite_stream & OS
A Use represents the edge between a Value definition and its users.
Definition: Use.h:35
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
Iterator for the Use edges of a User's operands.
Definition: User.h:24
Represents a Def-use/Use-def edge in SandboxIR.
Definition: Use.h:33
LLVM_ABI void set(Value *V)
Definition: Use.cpp:17
LLVM_ABI unsigned getOperandNo() const
Definition: Use.cpp:22
void dumpOS(raw_ostream &OS) const
Definition: Use.cpp:30
bool operator==(const Use &Other) const
Definition: Use.h:59
void dump() const
Definition: Use.cpp:58
bool operator!=(const Use &Other) const
Definition: Use.h:63
Context * getContext() const
Definition: Use.h:58
class User * getUser() const
Definition: Use.h:55
LLVM_ABI Value * get() const
Definition: Use.cpp:15
Iterator for the Use edges of a Value's users.
Definition: Value.h:40
A sandboxir::User has operands.
Definition: User.h:59
A SandboxIR Value has users. This is the base class.
Definition: Value.h:66
@ User
could "use" a pointer
@ Other
Any other memory.