diff options
| author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2026-02-19 18:45:44 -0500 |
|---|---|---|
| committer | Stefan Weigl-Bosker <stefan@s00.xyz> | 2026-02-19 18:45:44 -0500 |
| commit | af3d0ad1926eb825f64152cf217fc9a4777f0be3 (patch) | |
| tree | 8d7f73ce6c3c89863418382d8d553a06c668bbb3 /willow/lib/IR/Value.cpp | |
| parent | d11fbc8268f5775ad783f8570478daad4a9e81cf (diff) | |
| download | compiler-more-tests.tar.gz | |
[willow]: more cleanup, testsmore-tests
Diffstat (limited to 'willow/lib/IR/Value.cpp')
| -rw-r--r-- | willow/lib/IR/Value.cpp | 50 |
1 files changed, 23 insertions, 27 deletions
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 <willow/IR/Value.h> -// #include <willow/IR/Constant.h> -// #include <ostream> -// -// 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<const willow::Constant*>(&v); -// } -// } -// } +#include <willow/IR/Constant.h> +#include <willow/IR/Value.h> + +#include <cassert> + +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 |