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