|
|
|
|
@ -38,6 +38,12 @@ enum class PhysReg {
|
|
|
|
|
W13,
|
|
|
|
|
W14,
|
|
|
|
|
W15,
|
|
|
|
|
W19,
|
|
|
|
|
W20,
|
|
|
|
|
W21,
|
|
|
|
|
W22,
|
|
|
|
|
W23,
|
|
|
|
|
W24,
|
|
|
|
|
X0,
|
|
|
|
|
X1,
|
|
|
|
|
X2,
|
|
|
|
|
@ -54,6 +60,12 @@ enum class PhysReg {
|
|
|
|
|
X13,
|
|
|
|
|
X14,
|
|
|
|
|
X15,
|
|
|
|
|
X19,
|
|
|
|
|
X20,
|
|
|
|
|
X21,
|
|
|
|
|
X22,
|
|
|
|
|
X23,
|
|
|
|
|
X24,
|
|
|
|
|
S0,
|
|
|
|
|
S1,
|
|
|
|
|
S2,
|
|
|
|
|
@ -80,6 +92,8 @@ PhysReg WRegFromIndex(int index);
|
|
|
|
|
PhysReg XRegFromIndex(int index);
|
|
|
|
|
PhysReg SRegFromIndex(int index);
|
|
|
|
|
|
|
|
|
|
enum class RegClass { GPR32, GPR64, FPR32 };
|
|
|
|
|
|
|
|
|
|
enum class CondCode { EQ, NE, LT, LE, GT, GE };
|
|
|
|
|
|
|
|
|
|
const char* CondCodeName(CondCode cc);
|
|
|
|
|
@ -123,9 +137,10 @@ enum class Opcode {
|
|
|
|
|
|
|
|
|
|
class Operand {
|
|
|
|
|
public:
|
|
|
|
|
enum class Kind { Reg, Imm, FrameIndex, GlobalSymbol, Block };
|
|
|
|
|
enum class Kind { Reg, VReg, Imm, FrameIndex, GlobalSymbol, Block };
|
|
|
|
|
|
|
|
|
|
static Operand Reg(PhysReg reg);
|
|
|
|
|
static Operand VReg(int id);
|
|
|
|
|
static Operand Imm(int value);
|
|
|
|
|
static Operand FrameIndex(int index);
|
|
|
|
|
static Operand GlobalSymbol(std::string symbol);
|
|
|
|
|
@ -133,6 +148,7 @@ class Operand {
|
|
|
|
|
|
|
|
|
|
Kind GetKind() const { return kind_; }
|
|
|
|
|
PhysReg GetReg() const { return reg_; }
|
|
|
|
|
int GetVReg() const { return imm_; }
|
|
|
|
|
int GetImm() const { return imm_; }
|
|
|
|
|
int GetFrameIndex() const { return imm_; }
|
|
|
|
|
const std::string& GetSymbol() const { return symbol_; }
|
|
|
|
|
@ -152,6 +168,7 @@ class MachineInstr {
|
|
|
|
|
MachineInstr(Opcode opcode, std::vector<Operand> operands = {});
|
|
|
|
|
|
|
|
|
|
Opcode GetOpcode() const { return opcode_; }
|
|
|
|
|
std::vector<Operand>& GetOperands() { return operands_; }
|
|
|
|
|
const std::vector<Operand>& GetOperands() const { return operands_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
@ -170,6 +187,14 @@ struct FrameSlot {
|
|
|
|
|
FrameSlotKind kind = FrameSlotKind::Temp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct VirtualRegInfo {
|
|
|
|
|
int id = -1;
|
|
|
|
|
RegClass reg_class = RegClass::GPR32;
|
|
|
|
|
int home_slot = -1;
|
|
|
|
|
bool spilled = false;
|
|
|
|
|
PhysReg assigned_reg = PhysReg::W0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MachineBasicBlock {
|
|
|
|
|
public:
|
|
|
|
|
explicit MachineBasicBlock(std::string name);
|
|
|
|
|
@ -237,12 +262,23 @@ class MachineFunction {
|
|
|
|
|
void SetStackArgSize(int size) { stack_arg_size_ = size; }
|
|
|
|
|
bool IsLeaf() const { return is_leaf_; }
|
|
|
|
|
void SetLeaf(bool is_leaf) { is_leaf_ = is_leaf; }
|
|
|
|
|
int CreateVirtualReg(RegClass reg_class, int home_slot = -1);
|
|
|
|
|
VirtualRegInfo& GetVirtualReg(int id);
|
|
|
|
|
const VirtualRegInfo& GetVirtualReg(int id) const;
|
|
|
|
|
std::vector<VirtualRegInfo>& GetVirtualRegs() { return virtual_regs_; }
|
|
|
|
|
const std::vector<VirtualRegInfo>& GetVirtualRegs() const { return virtual_regs_; }
|
|
|
|
|
void AddUsedCalleeSavedReg(PhysReg reg);
|
|
|
|
|
const std::vector<PhysReg>& GetUsedCalleeSavedRegs() const {
|
|
|
|
|
return used_callee_saved_regs_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string name_;
|
|
|
|
|
bool is_declaration_ = false;
|
|
|
|
|
std::vector<std::unique_ptr<MachineBasicBlock>> blocks_;
|
|
|
|
|
std::vector<FrameSlot> frame_slots_;
|
|
|
|
|
std::vector<VirtualRegInfo> virtual_regs_;
|
|
|
|
|
std::vector<PhysReg> used_callee_saved_regs_;
|
|
|
|
|
int frame_size_ = 0;
|
|
|
|
|
int stack_arg_size_ = 0;
|
|
|
|
|
bool is_leaf_ = true;
|
|
|
|
|
|