forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
699 B
36 lines
699 B
#include "mir/MIR.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "utils/Log.h"
|
|
|
|
namespace mir {
|
|
namespace {
|
|
|
|
bool IsAllowedReg(PhysReg reg) {
|
|
switch (reg) {
|
|
case PhysReg::W0:
|
|
case PhysReg::W8:
|
|
case PhysReg::W9:
|
|
case PhysReg::X29:
|
|
case PhysReg::X30:
|
|
case PhysReg::SP:
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void RunRegAlloc(MachineFunction& function) {
|
|
for (const auto& inst : function.entry().instructions()) {
|
|
for (const auto& operand : inst.operands()) {
|
|
if (operand.kind() == Operand::Kind::Reg && !IsAllowedReg(operand.reg())) {
|
|
throw std::runtime_error(FormatError("mir", "寄存器分配失败"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace mir
|