LLVM 20.0.0git
User.cpp
Go to the documentation of this file.
1//===- User.cpp - The User class of Sandbox IR ----------------------------===//
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
11
12namespace llvm::sandboxir {
13
15
17 assert(Use.LLVMUse != nullptr && "Already at end!");
18 User *User = Use.getUser();
19 Use = User->getOperandUseInternal(Use.getOperandNo() + 1, /*Verify=*/false);
20 return *this;
22
24 // Get the corresponding llvm::Use, get the next in the list, and update the
25 // sandboxir::Use.
26 llvm::Use *&LLVMUse = Use.LLVMUse;
27 assert(LLVMUse != nullptr && "Already at end!");
28 LLVMUse = LLVMUse->getNext();
29 if (LLVMUse == nullptr) {
30 Use.Usr = nullptr;
31 return *this;
32 }
33 auto *Ctx = Use.Ctx;
34 auto *LLVMUser = LLVMUse->getUser();
35 Use.Usr = cast_or_null<sandboxir::User>(Ctx->getValue(LLVMUser));
36 return *this;
37}
38
41 Use.getOperandNo() + Num, /*Verify=*/true);
42 return OperandUseIterator(U);
43}
44
46 assert(Use.getOperandNo() >= Num && "Out of bounds!");
48 Use.getOperandNo() - Num, /*Verify=*/true);
49 return OperandUseIterator(U);
51
53 int ThisOpNo = Use.getOperandNo();
54 int OtherOpNo = Other.Use.getOperandNo();
55 return ThisOpNo - OtherOpNo;
56}
57
58Use User::getOperandUseDefault(unsigned OpIdx, bool Verify) const {
59 assert((!Verify || OpIdx < getNumOperands()) && "Out of bounds!");
60 assert(isa<llvm::User>(Val) && "Non-users have no operands!");
61 llvm::Use *LLVMUse;
62 if (OpIdx != getNumOperands())
63 LLVMUse = &cast<llvm::User>(Val)->getOperandUse(OpIdx);
64 else
65 LLVMUse = cast<llvm::User>(Val)->op_end();
66 return Use(LLVMUse, const_cast<User *>(this), Ctx);
68
69#ifndef NDEBUG
71 assert(Ctx.getValue(Use.getUser()) == this &&
72 "Use not found in this SBUser's operands!");
73}
74#endif
75
76bool User::classof(const Value *From) {
77 switch (From->getSubclassID()) {
78#define DEF_VALUE(ID, CLASS)
79#define DEF_USER(ID, CLASS) \
80 case ClassID::ID: \
81 return true;
82#define DEF_INSTR(ID, OPC, CLASS) \
83 case ClassID::ID: \
84 return true;
85#include "llvm/SandboxIR/Values.def"
86 default:
87 return false;
88 }
89}
90
91void User::setOperand(unsigned OperandIdx, Value *Operand) {
92 assert(isa<llvm::User>(Val) && "No operands!");
94 // We are delegating to llvm::User::setOperand().
95 cast<llvm::User>(Val)->setOperand(OperandIdx, Operand->Val);
97
99 auto &Tracker = Ctx.getTracker();
100 if (Tracker.isTracking()) {
101 for (auto OpIdx : seq<unsigned>(0, getNumOperands())) {
102 auto Use = getOperandUse(OpIdx);
103 if (Use.get() == FromV)
104 Tracker.emplaceIfTracking<UseSet>(Use);
105 }
106 }
107 // We are delegating RUOW to LLVM IR's RUOW.
108 return cast<llvm::User>(Val)->replaceUsesOfWith(FromV->Val, ToV->Val);
109}
110
111#ifndef NDEBUG
114 // TODO: This is incomplete
116#endif // NDEBUG
117
118} // namespace llvm::sandboxir
BlockVerifier::State From
ppc ctr loops PowerPC CTR Loops Verify
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
Value * get() const
Definition: Use.h:66
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
sandboxir::Value * getValue(llvm::Value *V) const
Definition: Context.cpp:601
Tracker & getTracker()
Definition: Context.h:203
Iterator for the Use edges of a User's operands.
Definition: User.h:23
OperandUseIterator operator-(unsigned Num) const
Definition: User.cpp:45
value_type operator*() const
Definition: User.cpp:14
OperandUseIterator & operator++()
Definition: User.cpp:16
OperandUseIterator operator+(unsigned Num) const
Definition: User.cpp:39
bool emplaceIfTracking(ArgsT... Args)
A convenience wrapper for track() that constructs and tracks the Change object if tracking is enabled...
Definition: Tracker.h:495
Tracks the change of the source Value of a sandboxir::Use.
Definition: Tracker.h:138
Represents a Def-use/Use-def edge in SandboxIR.
Definition: Use.h:32
unsigned getOperandNo() const
Definition: Use.cpp:22
class User * getUser() const
Definition: Use.h:54
Iterator for the Use edges of a Value's users.
Definition: Value.h:37
UserUseIterator & operator++()
Definition: User.cpp:23
A sandboxir::User has operands.
Definition: User.h:58
void verifyUserOfLLVMUse(const llvm::Use &Use) const
Definition: User.cpp:70
virtual void setOperand(unsigned OperandIdx, Value *Operand)
Definition: User.cpp:91
bool replaceUsesOfWith(Value *FromV, Value *ToV)
Replaces any operands that match FromV with ToV.
Definition: User.cpp:98
Use getOperandUseDefault(unsigned OpIdx, bool Verify) const
\Returns the Use edge that corresponds to OpIdx.
Definition: User.cpp:58
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: User.cpp:76
virtual Use getOperandUseInternal(unsigned OpIdx, bool Verify) const =0
\Returns the Use for the OpIdx'th operand.
void dumpCommonHeader(raw_ostream &OS) const final
Definition: User.cpp:112
virtual unsigned getNumOperands() const
Definition: User.h:128
Use getOperandUse(unsigned OpIdx) const
\Returns the operand edge for OpIdx.
Definition: User.h:125
A SandboxIR Value has users. This is the base class.
Definition: Value.h:63
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition: Value.h:103
virtual void dumpCommonHeader(raw_ostream &OS) const
Definition: Value.cpp:85
Context & Ctx
All values point to the context.
Definition: Value.h:172
friend class Use
Definition: Value.h:107
@ Other
Any other memory.