summaryrefslogtreecommitdiff
path: root/willow/lib/IR/BasicBlock.cpp
diff options
context:
space:
mode:
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