summaryrefslogtreecommitdiff
path: root/willow/lib/IR/BasicBlock.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/BasicBlock.cpp
parentd11fbc8268f5775ad783f8570478daad4a9e81cf (diff)
downloadcompiler-af3d0ad1926eb825f64152cf217fc9a4777f0be3.tar.gz
[willow]: more cleanup, testsmore-tests
Diffstat (limited to 'willow/lib/IR/BasicBlock.cpp')
-rw-r--r--willow/lib/IR/BasicBlock.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/willow/lib/IR/BasicBlock.cpp b/willow/lib/IR/BasicBlock.cpp
new file mode 100644
index 0000000..ceb4653
--- /dev/null
+++ b/willow/lib/IR/BasicBlock.cpp
@@ -0,0 +1,54 @@
+#include <willow/IR/BasicBlock.h>
+
+namespace willow {
+
+void BasicBlock::push_back(Instruction &inst) {
+ assert(!inst.hasParent() && "Instruction is already parented");
+ body.push_back(inst);
+ inst.setParent(this);
+}
+
+void BasicBlock::push_front(Instruction &inst) {
+ assert(!inst.hasParent() && "Instruction is already parented");
+ body.push_front(inst);
+ inst.setParent(this);
+}
+
+BasicBlock::Iterator BasicBlock::insert(Iterator pos, Instruction &inst) {
+ assert(!inst.hasParent() && "Instruction is already parented");
+ auto it = body.insert(pos, inst);
+ inst.setParent(this);
+ return it;
+}
+
+BasicBlock::Iterator BasicBlock::erase(BasicBlock::Iterator pos) {
+ Instruction &I = *pos;
+ I.setParent(nullptr);
+ return body.erase(pos);
+}
+
+BasicBlock::Iterator BasicBlock::eraseAndDelete(BasicBlock::Iterator pos) {
+ Instruction &inst = *pos;
+ pos->setParent(nullptr);
+ auto it = body.erase(pos);
+ delete &inst;
+ return it;
+}
+
+void BasicBlock::addPred(BasicBlock *bb) {
+ auto [it, inserted] = predecessors.try_emplace(bb, 1);
+
+ if (!inserted)
+ it->second += 1;
+}
+
+void BasicBlock::delPred(BasicBlock *bb) {
+ auto it = preds().find(bb);
+
+ it->second -= 1;
+
+ if (it->second <= 0)
+ preds().erase(it);
+}
+
+} // namespace willow