basically can color

This commit is contained in:
2024-10-21 16:42:40 +00:00
parent 04ab579484
commit 8216cb774c
8 changed files with 284 additions and 51 deletions

View File

@ -38,6 +38,15 @@ class CFGType {
std::vector<std::string> id_to_var;
std::unordered_map<std::string, size_t> var_to_id;
FunctionDefItem *corresponding_func;
void init() {
nodes.clear();
entry = nullptr;
block_to_node.clear();
label_to_block.clear();
id_to_var.clear();
var_to_id.clear();
corresponding_func = nullptr;
}
};
namespace opt {
@ -48,7 +57,7 @@ class MoveInstruct : public ActionItem {
LLVMType ty;
MoveInstruct() = default;
void RecursivePrint([[maybe_unused]] std::ostream &os) const {
throw std::runtime_error("Move instruction is not an actual LLVM IR instruction");
os << "[Persudo] " << dest_full << " <-- " << src_full << "\n";
}
};
} // namespace opt
@ -161,4 +170,9 @@ const static std::vector<std::string> caller_saved_regs = {"x5", "x6", "x7",
const static std::vector<std::string> arg_regs = {"x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17"};
const static std::vector<std::string> allocating_regs = {"x3", "x4", "x9", "x18", "x19", "x20", "x21", "x22",
"x23", "x24", "x25", "x26", "x27", "x5", "x6", "x7",
"x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17"};
"x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17"};
inline bool VRegCheck(const std::string &s) {
if (s[0] != '%') return false;
return true;
}

View File

@ -5,12 +5,11 @@
class ConfGraphNode {
public:
const static size_t kInf = (std::numeric_limits<size_t>::max()) >> 2;
std::vector<size_t> var_ids;
std::list<size_t> var_ids;
size_t color;
size_t degree;
bool is_binded_with_physical_reg;
std::list<ConfGraphNode *> neighbors;
std::list<std::pair<ConfGraphNode *, opt::MoveInstruct *>> move_neighbors;
// the following are for graph maintenance
ConfGraphNode *is_merged_into;
@ -21,6 +20,7 @@ class ConfGraphNode {
bool is_temporarily_removed;
std::list<ConfGraphNode *> neighbors_half_available;
std::list<ConfGraphNode *> neighbors_not_available;
std::list<std::pair<ConfGraphNode *, opt::MoveInstruct *>> original_move_neighbors;
};
class ConfGraph {
public:
@ -39,6 +39,24 @@ class ConfGraph {
std::unordered_set<opt::MoveInstruct *> pending_moves;
std::unordered_set<opt::MoveInstruct *> potential_moves;
std::unordered_map<ConfGraphNode *, std::unordered_map<ConfGraphNode *, std::list<ConfGraphNode *>::iterator>>
adj_table_half_available;
std::unordered_map<ConfGraphNode *, std::unordered_map<ConfGraphNode *, std::list<ConfGraphNode *>::iterator>>
adj_table_not_available;
void init() {
id_to_node.clear();
nodes.clear();
adj_table.clear();
stack.clear();
actual_spills.clear();
low_degree_and_not_move_related.clear();
low_degree_and_move_related.clear();
high_degree_nodes.clear();
pending_moves.clear();
potential_moves.clear();
adj_table_half_available.clear();
adj_table_not_available.clear();
}
};
ConfGraph BuildConfGraph(CFGType &cfg);

View File

@ -11,17 +11,13 @@ class ForceDef : public ActionItem {
std::string var_full;
LLVMType ty;
ForceDef() = default;
void RecursivePrint(std::ostream &os) const {
throw std::runtime_error("ForceDef instruction is not an actual LLVM IR instruction");
}
void RecursivePrint(std::ostream &os) const { os << "[Persudo] def " << var_full << "\n"; }
};
class ForceUse : public ActionItem {
public:
std::string var_full;
ForceUse() = default;
void RecursivePrint(std::ostream &os) const {
throw std::runtime_error("ForceUse instruction is not an actual LLVM IR instruction");
}
void RecursivePrint(std::ostream &os) const { os << "[Persudo] use " << var_full << "\n"; }
};
class LoadSpilledArgs : public ActionItem {
public:
@ -30,7 +26,7 @@ class LoadSpilledArgs : public ActionItem {
LLVMType ty;
LoadSpilledArgs() = default;
void RecursivePrint(std::ostream &os) const {
throw std::runtime_error("LoadSpilledArgs instruction is not an actual LLVM IR instruction");
os << "[Persudo] load spilled args " << var_full << "with id=" << arg_id << "\n";
}
};
@ -41,7 +37,7 @@ class StoreSpilledArgs : public ActionItem {
LLVMType ty;
StoreSpilledArgs() = default;
void RecursivePrint(std::ostream &os) const {
throw std::runtime_error("StoreSpilledArgs instruction is not an actual LLVM IR instruction");
os << "[Persudo] store spilled args " << var_full << "with id=" << arg_id << "\n";
}
};
} // namespace opt