From c2d4209f85f46cc91163bc47cc43db252c94acf6 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Thu, 19 Feb 2026 18:51:48 -0500 Subject: [willow]: more cleanup, tests (#12) --- willow/lib/IR/Value.cpp | 50 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'willow/lib/IR/Value.cpp') diff --git a/willow/lib/IR/Value.cpp b/willow/lib/IR/Value.cpp index 0bd1079..703e807 100644 --- a/willow/lib/IR/Value.cpp +++ b/willow/lib/IR/Value.cpp @@ -1,27 +1,23 @@ -// #include -// #include -// #include -// -// std::ostream &operator<<(std::ostream &os, const willow::Value &v) { -// using willow::ValueKind; -// auto ty = v.getType(); -// if (!v.isVoid()) -// os << ty << " "; -// -// switch (v.getValueKind()) { -// case ValueKind::Parameter: -// [[fallthrough]]; -// case ValueKind::Instruction: { -// return os << "%" << v.getName(); -// } -// case ValueKind::BasicBlock: { -// return os << "^" << v.getName(); -// } -// case ValueKind::Function: { -// return os << "@" << v.getName(); -// } -// case ValueKind::Constant: { -// return os << *static_cast(&v); -// } -// } -// } +#include +#include + +#include + +namespace willow { + +void Value::addUse(Instruction *instruction) { + auto [it, inserted] = uses.try_emplace(instruction, 1); + + if (!inserted) + it->second += 1; +} + +void Value::delUse(Instruction *instruction) { + assert(uses.contains(instruction) && "No uses to remove"); + auto it = uses.find(instruction); + it->second -= 1; + if (it->second == 0) + uses.erase(it); +} + +} // namespace willow -- cgit v1.2.3