summaryrefslogtreecommitdiff
path: root/willow/lib/IR/Value.cpp
diff options
context:
space:
mode:
authorStefan Weigl-Bosker <stefan@s00.xyz>2026-02-19 18:45:44 -0500
committerStefan Weigl-Bosker <stefan@s00.xyz>2026-02-19 18:45:44 -0500
commitaf3d0ad1926eb825f64152cf217fc9a4777f0be3 (patch)
tree8d7f73ce6c3c89863418382d8d553a06c668bbb3 /willow/lib/IR/Value.cpp
parentd11fbc8268f5775ad783f8570478daad4a9e81cf (diff)
downloadcompiler-af3d0ad1926eb825f64152cf217fc9a4777f0be3.tar.gz
[willow]: more cleanup, testsmore-tests
Diffstat (limited to 'willow/lib/IR/Value.cpp')
-rw-r--r--willow/lib/IR/Value.cpp50
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