| 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(V: LLVMUse->get()); } |
| 16 | |
| 17 | void Use::set(Value *V) { |
| 18 | Ctx->getTracker().emplaceIfTracking<UseSet>(Args: *this); |
| 19 | LLVMUse->set(V->Val); |
| 20 | } |
| 21 | |
| 22 | unsigned Use::getOperandNo() const { return Usr->getUseOperandNo(Use: *this); } |
| 23 | |
| 24 | void Use::swap(Use &OtherUse) { |
| 25 | Ctx->getTracker().emplaceIfTracking<UseSwap>(Args: *this, Args: OtherUse); |
| 26 | LLVMUse->swap(RHS&: *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 |
| 62 | |