summaryrefslogtreecommitdiff
path: root/willow/lib/IR/ConstantPool.cpp
diff options
context:
space:
mode:
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();
+}
+
+}