[llvm] [SandboxIR][NFC] Create Use.cpp and delete SandboxIR.cpp (PR #110323)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 27 13:30:06 PDT 2024
https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/110323
None
>From f443bbe824a879badf9ea47d013d7242719a5fe7 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Fri, 27 Sep 2024 08:53:20 -0700
Subject: [PATCH] [SandboxIR][NFC] Create Use.cpp and delete SandboxIR.cpp
---
llvm/lib/SandboxIR/CMakeLists.txt | 2 +-
llvm/lib/SandboxIR/SandboxIR.cpp | 109 ------------------------------
llvm/lib/SandboxIR/Use.cpp | 61 +++++++++++++++++
llvm/lib/SandboxIR/User.cpp | 44 ++++++++++++
4 files changed, 106 insertions(+), 110 deletions(-)
delete mode 100644 llvm/lib/SandboxIR/SandboxIR.cpp
create mode 100644 llvm/lib/SandboxIR/Use.cpp
diff --git a/llvm/lib/SandboxIR/CMakeLists.txt b/llvm/lib/SandboxIR/CMakeLists.txt
index 7c817ed133ed8e..293be1849f29d3 100644
--- a/llvm/lib/SandboxIR/CMakeLists.txt
+++ b/llvm/lib/SandboxIR/CMakeLists.txt
@@ -8,10 +8,10 @@ add_llvm_component_library(LLVMSandboxIR
Pass.cpp
PassManager.cpp
Region.cpp
- SandboxIR.cpp
Tracker.cpp
Type.cpp
User.cpp
+ Use.cpp
Value.cpp
ADDITIONAL_HEADER_DIRS
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
deleted file mode 100644
index 89575da2578db7..00000000000000
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-//===- SandboxIR.cpp - A transactional overlay IR on top of LLVM IR -------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/IR/Constants.h"
-#include "llvm/SandboxIR/Argument.h"
-#include "llvm/SandboxIR/BasicBlock.h"
-#include "llvm/SandboxIR/Context.h"
-#include "llvm/SandboxIR/User.h"
-#include "llvm/Support/Debug.h"
-#include <sstream>
-
-using namespace llvm::sandboxir;
-
-Value *Use::get() const { return Ctx->getValue(LLVMUse->get()); }
-
-void Use::set(Value *V) {
- Ctx->getTracker().emplaceIfTracking<UseSet>(*this);
- LLVMUse->set(V->Val);
-}
-
-unsigned Use::getOperandNo() const { return Usr->getUseOperandNo(*this); }
-
-void Use::swap(Use &OtherUse) {
- Ctx->getTracker().emplaceIfTracking<UseSwap>(*this, OtherUse);
- LLVMUse->swap(*OtherUse.LLVMUse);
-}
-
-#ifndef NDEBUG
-void Use::dumpOS(raw_ostream &OS) const {
- Value *Def = nullptr;
- if (LLVMUse == nullptr)
- OS << "<null> LLVM Use! ";
- else
- Def = Ctx->getValue(LLVMUse->get());
- OS << "Def: ";
- if (Def == nullptr)
- OS << "NULL";
- else
- OS << *Def;
- OS << "\n";
-
- OS << "User: ";
- if (Usr == nullptr)
- OS << "NULL";
- else
- OS << *Usr;
- OS << "\n";
-
- OS << "OperandNo: ";
- if (Usr == nullptr)
- OS << "N/A";
- else
- OS << getOperandNo();
- OS << "\n";
-}
-
-void Use::dump() const { dumpOS(dbgs()); }
-#endif // NDEBUG
-
-Use OperandUseIterator::operator*() const { return Use; }
-
-OperandUseIterator &OperandUseIterator::operator++() {
- assert(Use.LLVMUse != nullptr && "Already at end!");
- User *User = Use.getUser();
- Use = User->getOperandUseInternal(Use.getOperandNo() + 1, /*Verify=*/false);
- return *this;
-}
-
-UserUseIterator &UserUseIterator::operator++() {
- // Get the corresponding llvm::Use, get the next in the list, and update the
- // sandboxir::Use.
- llvm::Use *&LLVMUse = Use.LLVMUse;
- assert(LLVMUse != nullptr && "Already at end!");
- LLVMUse = LLVMUse->getNext();
- if (LLVMUse == nullptr) {
- Use.Usr = nullptr;
- return *this;
- }
- auto *Ctx = Use.Ctx;
- auto *LLVMUser = LLVMUse->getUser();
- Use.Usr = cast_or_null<sandboxir::User>(Ctx->getValue(LLVMUser));
- return *this;
-}
-
-OperandUseIterator OperandUseIterator::operator+(unsigned Num) const {
- sandboxir::Use U = Use.getUser()->getOperandUseInternal(
- Use.getOperandNo() + Num, /*Verify=*/true);
- return OperandUseIterator(U);
-}
-
-OperandUseIterator OperandUseIterator::operator-(unsigned Num) const {
- assert(Use.getOperandNo() >= Num && "Out of bounds!");
- sandboxir::Use U = Use.getUser()->getOperandUseInternal(
- Use.getOperandNo() - Num, /*Verify=*/true);
- return OperandUseIterator(U);
-}
-
-int OperandUseIterator::operator-(const OperandUseIterator &Other) const {
- int ThisOpNo = Use.getOperandNo();
- int OtherOpNo = Other.Use.getOperandNo();
- return ThisOpNo - OtherOpNo;
-}
diff --git a/llvm/lib/SandboxIR/Use.cpp b/llvm/lib/SandboxIR/Use.cpp
new file mode 100644
index 00000000000000..ffbd41da518497
--- /dev/null
+++ b/llvm/lib/SandboxIR/Use.cpp
@@ -0,0 +1,61 @@
+//===- Use.cpp ------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/SandboxIR/Use.h"
+#include "llvm/SandboxIR/Context.h"
+#include "llvm/SandboxIR/User.h"
+
+namespace llvm::sandboxir {
+
+Value *Use::get() const { return Ctx->getValue(LLVMUse->get()); }
+
+void Use::set(Value *V) {
+ Ctx->getTracker().emplaceIfTracking<UseSet>(*this);
+ LLVMUse->set(V->Val);
+}
+
+unsigned Use::getOperandNo() const { return Usr->getUseOperandNo(*this); }
+
+void Use::swap(Use &OtherUse) {
+ Ctx->getTracker().emplaceIfTracking<UseSwap>(*this, OtherUse);
+ LLVMUse->swap(*OtherUse.LLVMUse);
+}
+
+#ifndef NDEBUG
+void Use::dumpOS(raw_ostream &OS) const {
+ Value *Def = nullptr;
+ if (LLVMUse == nullptr)
+ OS << "<null> LLVM Use! ";
+ else
+ Def = Ctx->getValue(LLVMUse->get());
+ OS << "Def: ";
+ if (Def == nullptr)
+ OS << "NULL";
+ else
+ OS << *Def;
+ OS << "\n";
+
+ OS << "User: ";
+ if (Usr == nullptr)
+ OS << "NULL";
+ else
+ OS << *Usr;
+ OS << "\n";
+
+ OS << "OperandNo: ";
+ if (Usr == nullptr)
+ OS << "N/A";
+ else
+ OS << getOperandNo();
+ OS << "\n";
+}
+
+void Use::dump() const { dumpOS(dbgs()); }
+#endif // NDEBUG
+
+} // namespace llvm::sandboxir
diff --git a/llvm/lib/SandboxIR/User.cpp b/llvm/lib/SandboxIR/User.cpp
index 8afa52e32b7622..148d75199439aa 100644
--- a/llvm/lib/SandboxIR/User.cpp
+++ b/llvm/lib/SandboxIR/User.cpp
@@ -11,6 +11,50 @@
namespace llvm::sandboxir {
+Use OperandUseIterator::operator*() const { return Use; }
+
+OperandUseIterator &OperandUseIterator::operator++() {
+ assert(Use.LLVMUse != nullptr && "Already at end!");
+ User *User = Use.getUser();
+ Use = User->getOperandUseInternal(Use.getOperandNo() + 1, /*Verify=*/false);
+ return *this;
+}
+
+UserUseIterator &UserUseIterator::operator++() {
+ // Get the corresponding llvm::Use, get the next in the list, and update the
+ // sandboxir::Use.
+ llvm::Use *&LLVMUse = Use.LLVMUse;
+ assert(LLVMUse != nullptr && "Already at end!");
+ LLVMUse = LLVMUse->getNext();
+ if (LLVMUse == nullptr) {
+ Use.Usr = nullptr;
+ return *this;
+ }
+ auto *Ctx = Use.Ctx;
+ auto *LLVMUser = LLVMUse->getUser();
+ Use.Usr = cast_or_null<sandboxir::User>(Ctx->getValue(LLVMUser));
+ return *this;
+}
+
+OperandUseIterator OperandUseIterator::operator+(unsigned Num) const {
+ sandboxir::Use U = Use.getUser()->getOperandUseInternal(
+ Use.getOperandNo() + Num, /*Verify=*/true);
+ return OperandUseIterator(U);
+}
+
+OperandUseIterator OperandUseIterator::operator-(unsigned Num) const {
+ assert(Use.getOperandNo() >= Num && "Out of bounds!");
+ sandboxir::Use U = Use.getUser()->getOperandUseInternal(
+ Use.getOperandNo() - Num, /*Verify=*/true);
+ return OperandUseIterator(U);
+}
+
+int OperandUseIterator::operator-(const OperandUseIterator &Other) const {
+ int ThisOpNo = Use.getOperandNo();
+ int OtherOpNo = Other.Use.getOperandNo();
+ return ThisOpNo - OtherOpNo;
+}
+
Use User::getOperandUseDefault(unsigned OpIdx, bool Verify) const {
assert((!Verify || OpIdx < getNumOperands()) && "Out of bounds!");
assert(isa<llvm::User>(Val) && "Non-users have no operands!");
More information about the llvm-commits
mailing list