summaryrefslogtreecommitdiff
path: root/willow/lib/IR/ConstantPool.cpp
diff options
context:
space:
mode:
authorStefan Weigl-Bosker <stefan@s00.xyz>2026-02-19 18:51:48 -0500
committerGitHub <noreply@github.com>2026-02-19 18:51:48 -0500
commitc2d4209f85f46cc91163bc47cc43db252c94acf6 (patch)
tree8d7f73ce6c3c89863418382d8d553a06c668bbb3 /willow/lib/IR/ConstantPool.cpp
parentd11fbc8268f5775ad783f8570478daad4a9e81cf (diff)
downloadcompiler-c2d4209f85f46cc91163bc47cc43db252c94acf6.tar.gz
[willow]: more cleanup, tests (#12)
Diffstat (limited to 'willow/lib/IR/ConstantPool.cpp')
-rw-r--r--willow/lib/IR/ConstantPool.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/willow/lib/IR/ConstantPool.cpp b/willow/lib/IR/ConstantPool.cpp
new file mode 100644
index 0000000..d880913
--- /dev/null
+++ b/willow/lib/IR/ConstantPool.cpp
@@ -0,0 +1,26 @@
+#include <willow/IR/ConstantPool.h>
+
+#include <cassert>
+
+namespace willow {
+
+ConstantInt *ConstantPool::getInt(Type ty, uint64_t val) {
+ assert(ty.isInt() && "Expected integer type");
+ ConstantInt::Key &&k{ty.getImpl(), ty.getNumBits()};
+ std::lock_guard<std::mutex> lock(int_mutex);
+
+ auto [it, _] = icache.try_emplace(k, std::make_unique<ConstantInt>(ty, val));
+
+ return it->second.get();
+}
+
+PoisonVal *ConstantPool::getPoisonVal(Type ty) {
+ std::lock_guard<std::mutex> lock(poison_mutex);
+
+ auto [it, _] =
+ pcache.try_emplace(ty.getImpl(), std::make_unique<PoisonVal>(ty));
+
+ return it->second.get();
+}
+
+}