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.
77 lines
2.1 KiB
77 lines
2.1 KiB
#include "mir/MIR.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
namespace mir {
|
|
namespace {
|
|
|
|
const char* kWRegNames[] = {
|
|
"w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7",
|
|
"w8", "w9", "w10", "w11", "w12", "w13", "w14", "w15",
|
|
"w16", "w17", "w18", "w19", "w20", "w21", "w22", "w23",
|
|
"w24", "w25", "w26", "w27", "w28", "w29", "w30"};
|
|
const char* kXRegNames[] = {
|
|
"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
|
|
"x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
|
|
"x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
|
|
"x24", "x25", "x26", "x27", "x28", "x29", "x30"};
|
|
const char* kSRegNames[] = {
|
|
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
|
|
"s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
|
|
"s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
|
|
"s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31"};
|
|
|
|
} // namespace
|
|
|
|
bool IsGPR(ValueType type) {
|
|
return type == ValueType::I1 || type == ValueType::I32 || type == ValueType::Ptr;
|
|
}
|
|
|
|
bool IsFPR(ValueType type) { return type == ValueType::F32; }
|
|
|
|
int GetValueSize(ValueType type) {
|
|
switch (type) {
|
|
case ValueType::Void:
|
|
return 0;
|
|
case ValueType::I1:
|
|
case ValueType::I32:
|
|
case ValueType::F32:
|
|
return 4;
|
|
case ValueType::Ptr:
|
|
return 8;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int GetValueAlign(ValueType type) {
|
|
switch (type) {
|
|
case ValueType::Void:
|
|
return 1;
|
|
case ValueType::Ptr:
|
|
return 8;
|
|
case ValueType::I1:
|
|
case ValueType::I32:
|
|
case ValueType::F32:
|
|
return 4;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
const char* GetPhysRegName(PhysReg reg, ValueType type) {
|
|
if (!reg.IsValid()) {
|
|
throw std::runtime_error("invalid physical register");
|
|
}
|
|
if (reg.reg_class == RegClass::FPR) {
|
|
if (reg.index < 0 || reg.index >= 32) {
|
|
throw std::runtime_error("float register index out of range");
|
|
}
|
|
return kSRegNames[reg.index];
|
|
}
|
|
if (reg.index < 0 || reg.index >= 31) {
|
|
throw std::runtime_error("gpr register index out of range");
|
|
}
|
|
return type == ValueType::Ptr ? kXRegNames[reg.index] : kWRegNames[reg.index];
|
|
}
|
|
|
|
} // namespace mir
|