LLVM 24.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;
26class UserUseIterator;
27class CallBase;
28class PHINode;
29
30// Forward declare instruction wrapper classes so qualified friend
31// declarations below refer to SandboxIR classes instead of introducing new
32// unqualified declarations.
33#define DEF_INSTR(ID, OPC, CLASS) class CLASS;
34#define DEF_DISABLE_AUTO_UNDEF // ValuesDefFilesList.def includes multiple .def
35#include "llvm/SandboxIR/ValuesDefFilesList.def"
36#undef DEF_INSTR
37
38/// Represents a Def-use/Use-def edge in SandboxIR.
39/// NOTE: Unlike llvm::Use, this is not an integral part of the use-def chains.
40/// It is also not uniqued and is currently passed by value, so you can have
41/// more than one sandboxir::Use objects for the same use-def edge.
42class Use {
43 llvm::Use *LLVMUse;
44 User *Usr;
45 Context *Ctx;
46
47 /// Don't allow the user to create a sandboxir::Use directly.
48 Use(llvm::Use *LLVMUse, User *Usr, Context &Ctx)
49 : LLVMUse(LLVMUse), Usr(Usr), Ctx(&Ctx) {}
50 Use() : LLVMUse(nullptr), Ctx(nullptr) {}
51
52 friend ::llvm::sandboxir::Value; // For constructor
53 friend ::llvm::sandboxir::User; // For constructor
54 friend ::llvm::sandboxir::OperandUseIterator; // For constructor
55 friend ::llvm::sandboxir::UserUseIterator; // For accessing members
56 friend ::llvm::sandboxir::CallBase; // For LLVMUse
57 friend ::llvm::sandboxir::PHINode; // For LLVMUse
58 // Friend instructions so that they can call the constructor if needed.
59#define DEF_INSTR(ID, OPC, CLASS) friend ::llvm::sandboxir::CLASS;
60#define DEF_DISABLE_AUTO_UNDEF // ValuesDefFilesList.def includes multiple .def
61#include "llvm/SandboxIR/ValuesDefFilesList.def"
62#undef DEF_INSTR
63
64public:
65 operator Value *() const { return get(); }
66 LLVM_ABI Value *get() const;
67 LLVM_ABI void set(Value *V);
68 class User *getUser() const { return Usr; }
69 LLVM_ABI unsigned getOperandNo() const;
70 LLVM_ABI void swap(Use &OtherUse);
71 Context *getContext() const { return Ctx; }
72 bool operator==(const Use &Other) const {
73 assert(Ctx == Other.Ctx && "Contexts differ!");
74 return LLVMUse == Other.LLVMUse && Usr == Other.Usr;
75 }
76 bool operator!=(const Use &Other) const { return !(*this == Other); }
77#ifndef NDEBUG
78 LLVM_ABI void dumpOS(raw_ostream &OS) const;
79 void dump() const;
80#endif // NDEBUG
81};
82
83} // namespace llvm::sandboxir
84
85#endif // LLVM_SANDBOXIR_USE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:211
This defines the Use class.
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:42
LLVM_ABI void set(Value *V)
Definition Use.cpp:17
LLVM_ABI unsigned getOperandNo() const
Definition Use.cpp:22
LLVM_ABI void dumpOS(raw_ostream &OS) const
Definition Use.cpp:30
LLVM_ABI void swap(Use &OtherUse)
Definition Use.cpp:24
bool operator==(const Use &Other) const
Definition Use.h:72
void dump() const
Definition Use.cpp:58
bool operator!=(const Use &Other) const
Definition Use.h:76
Context * getContext() const
Definition Use.h:71
class User * getUser() const
Definition Use.h:68
LLVM_ABI Value * get() const
Definition Use.cpp:15
Iterator for the Use edges of a Value's users.
Definition Value.h:46
A sandboxir::User has operands.
Definition User.h:59
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
@ Other
Any other memory.
Definition ModRef.h:68