Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/SandboxIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
109 changes: 0 additions & 109 deletions llvm/lib/SandboxIR/SandboxIR.cpp

This file was deleted.

61 changes: 61 additions & 0 deletions llvm/lib/SandboxIR/Use.cpp
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions llvm/lib/SandboxIR/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
Loading