Lab4: Implement basic scalar optimizations and lower Phi nodes to assembly
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user