Skip to content

Commit 3723946

Browse files
authored
[SandboxIR][NFC] Create Use.cpp and delete SandboxIR.cpp (#110323)
1 parent e9700d0 commit 3723946

File tree

4 files changed

+106
-110
lines changed

4 files changed

+106
-110
lines changed

llvm/lib/SandboxIR/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ add_llvm_component_library(LLVMSandboxIR
88
Pass.cpp
99
PassManager.cpp
1010
Region.cpp
11-
SandboxIR.cpp
1211
Tracker.cpp
1312
Type.cpp
1413
User.cpp
14+
Use.cpp
1515
Value.cpp
1616

1717
ADDITIONAL_HEADER_DIRS

llvm/lib/SandboxIR/SandboxIR.cpp

Lines changed: 0 additions & 109 deletions
This file was deleted.

llvm/lib/SandboxIR/Use.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===- Use.cpp ------------------------------------------------------------===//
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+
#include "llvm/SandboxIR/Use.h"
10+
#include "llvm/SandboxIR/Context.h"
11+
#include "llvm/SandboxIR/User.h"
12+
13+
namespace llvm::sandboxir {
14+
15+
Value *Use::get() const { return Ctx->getValue(LLVMUse->get()); }
16+
17+
void Use::set(Value *V) {
18+
Ctx->getTracker().emplaceIfTracking<UseSet>(*this);
19+
LLVMUse->set(V->Val);
20+
}
21+
22+
unsigned Use::getOperandNo() const { return Usr->getUseOperandNo(*this); }
23+
24+
void Use::swap(Use &OtherUse) {
25+
Ctx->getTracker().emplaceIfTracking<UseSwap>(*this, OtherUse);
26+
LLVMUse->swap(*OtherUse.LLVMUse);
27+
}
28+
29+
#ifndef NDEBUG
30+
void Use::dumpOS(raw_ostream &OS) const {
31+
Value *Def = nullptr;
32+
if (LLVMUse == nullptr)
33+
OS << "<null> LLVM Use! ";
34+
else
35+
Def = Ctx->getValue(LLVMUse->get());
36+
OS << "Def: ";
37+
if (Def == nullptr)
38+
OS << "NULL";
39+
else
40+
OS << *Def;
41+
OS << "\n";
42+
43+
OS << "User: ";
44+
if (Usr == nullptr)
45+
OS << "NULL";
46+
else
47+
OS << *Usr;
48+
OS << "\n";
49+
50+
OS << "OperandNo: ";
51+
if (Usr == nullptr)
52+
OS << "N/A";
53+
else
54+
OS << getOperandNo();
55+
OS << "\n";
56+
}
57+
58+
void Use::dump() const { dumpOS(dbgs()); }
59+
#endif // NDEBUG
60+
61+
} // namespace llvm::sandboxir

llvm/lib/SandboxIR/User.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,50 @@
1111

1212
namespace llvm::sandboxir {
1313

14+
Use OperandUseIterator::operator*() const { return Use; }
15+
16+
OperandUseIterator &OperandUseIterator::operator++() {
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;
21+
}
22+
23+
UserUseIterator &UserUseIterator::operator++() {
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+
39+
OperandUseIterator OperandUseIterator::operator+(unsigned Num) const {
40+
sandboxir::Use U = Use.getUser()->getOperandUseInternal(
41+
Use.getOperandNo() + Num, /*Verify=*/true);
42+
return OperandUseIterator(U);
43+
}
44+
45+
OperandUseIterator OperandUseIterator::operator-(unsigned Num) const {
46+
assert(Use.getOperandNo() >= Num && "Out of bounds!");
47+
sandboxir::Use U = Use.getUser()->getOperandUseInternal(
48+
Use.getOperandNo() - Num, /*Verify=*/true);
49+
return OperandUseIterator(U);
50+
}
51+
52+
int OperandUseIterator::operator-(const OperandUseIterator &Other) const {
53+
int ThisOpNo = Use.getOperandNo();
54+
int OtherOpNo = Other.Use.getOperandNo();
55+
return ThisOpNo - OtherOpNo;
56+
}
57+
1458
Use User::getOperandUseDefault(unsigned OpIdx, bool Verify) const {
1559
assert((!Verify || OpIdx < getNumOperands()) && "Out of bounds!");
1660
assert(isa<llvm::User>(Val) && "Non-users have no operands!");

0 commit comments

Comments
 (0)