#include 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