Lab4: Implement basic scalar optimizations and lower Phi nodes to assembly
This commit is contained in:
@@ -103,6 +103,8 @@ static std::string OpcodeToString(Opcode op) {
|
||||
return "sitofp";
|
||||
case Opcode::FPToSI:
|
||||
return "fptosi";
|
||||
case Opcode::Phi:
|
||||
return "phi";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
@@ -347,6 +349,16 @@ void IRPrinter::Print(const Module& module, std::ostream& os) {
|
||||
<< TypeToString(*cast->GetType()) << "\n";
|
||||
break;
|
||||
}
|
||||
case Opcode::Phi: {
|
||||
auto* phi = static_cast<const PhiInst*>(inst);
|
||||
os << " %" << phi->GetName() << " = phi " << TypeToString(*phi->GetType()) << " ";
|
||||
for (size_t i = 0; i < phi->GetNumIncoming(); ++i) {
|
||||
if (i > 0) os << ", ";
|
||||
os << "[ " << ValueToString(phi->GetIncomingValue(i)) << ", %" << phi->GetIncomingBlock(i)->GetName() << " ]";
|
||||
}
|
||||
os << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user