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/ConstantPool.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 willow/lib/IR/ConstantPool.cpp (limited to 'willow/lib/IR/ConstantPool.cpp') 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 + +#include + +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 lock(int_mutex); + + auto [it, _] = icache.try_emplace(k, std::make_unique(ty, val)); + + return it->second.get(); +} + +PoisonVal *ConstantPool::getPoisonVal(Type ty) { + std::lock_guard lock(poison_mutex); + + auto [it, _] = + pcache.try_emplace(ty.getImpl(), std::make_unique(ty)); + + return it->second.get(); +} + +} -- cgit v1.2.3