diff options
| author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2026-02-19 18:45:44 -0500 |
|---|---|---|
| committer | Stefan Weigl-Bosker <stefan@s00.xyz> | 2026-02-19 18:45:44 -0500 |
| commit | af3d0ad1926eb825f64152cf217fc9a4777f0be3 (patch) | |
| tree | 8d7f73ce6c3c89863418382d8d553a06c668bbb3 /willow/lib/IR/BasicBlock.cpp | |
| parent | d11fbc8268f5775ad783f8570478daad4a9e81cf (diff) | |
| download | compiler-af3d0ad1926eb825f64152cf217fc9a4777f0be3.tar.gz | |
[willow]: more cleanup, testsmore-tests
Diffstat (limited to 'willow/lib/IR/BasicBlock.cpp')
| -rw-r--r-- | willow/lib/IR/BasicBlock.cpp | 54 |
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 |