Lab4: Implement basic scalar optimizations and lower Phi nodes to assembly

This commit is contained in:
2026-05-05 10:20:15 +08:00
committed by CGH0S7
parent 0b0bc04be3
commit 8f7e0ac5b4
17 changed files with 1318 additions and 35 deletions

View File

@@ -42,4 +42,29 @@ const std::vector<BasicBlock*>& BasicBlock::GetSuccessors() const {
return successors_;
}
void BasicBlock::EraseInstruction(Instruction* inst) {
for (auto it = instructions_.begin(); it != instructions_.end(); ++it) {
if (it->get() == inst) {
inst->ClearOperands();
instructions_.erase(it);
break;
}
}
}
void BasicBlock::InsertInstructionBefore(std::unique_ptr<Instruction> inst, Instruction* before) {
for (auto it = instructions_.begin(); it != instructions_.end(); ++it) {
if (it->get() == before) {
inst->SetParent(this);
instructions_.insert(it, std::move(inst));
break;
}
}
}
void BasicBlock::InsertInstructionAtBegin(std::unique_ptr<Instruction> inst) {
inst->SetParent(this);
instructions_.insert(instructions_.begin(), std::move(inst));
}
} // namespace ir