finish preparations for coloring

This commit is contained in:
2024-10-21 06:08:16 +00:00
parent 1073750a8d
commit 11b9f31b7a
4 changed files with 113 additions and 20 deletions

View File

@ -149,4 +149,16 @@ bool GetCollectionsIsSame(const Container &a, const Container &b, Compare comp =
return ita == a.end() && itb == b.end();
}
CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func);
CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func);
// RISC-V calling convention compatible
const static std::vector<std::string> held_tmp_regs = {"x28", "x29", "x30", "x31"};
const static std::string zero = "x0", sp = "x2", ra = "x1", fp = "x8";
const static std::vector<std::string> callee_saved_regs = {"x3", "x4", "x9", "x18", "x19", "x20", "x21",
"x22", "x23", "x24", "x25", "x26", "x27"};
const static std::vector<std::string> caller_saved_regs = {"x5", "x6", "x7", "x10", "x11", "x12",
"x13", "x14", "x15", "x16", "x17"};
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"};

View File

@ -3,19 +3,32 @@
#include "cfg.h"
class ConfGraphNode {
public:
std::string var_name;
const static size_t kInf = (std::numeric_limits<size_t>::max()) >> 2;
std::vector<size_t> var_ids;
size_t color;
bool is_move_related;
bool move_related_but_frozen;
size_t degree;
bool is_binded_with_physical_reg;
std::vector<ConfGraphNode *> neighbors;
ConfGraphNode(std::string var_name) : var_name(var_name) {}
std::list<ConfGraphNode *> neighbors;
std::list<opt::MoveInstruct *> move_neighbors;
ConfGraphNode() = default;
};
class ConfGraph {
public:
std::unordered_map<std::string, ConfGraphNode *> name_to_node;
// available after construction
std::unordered_map<size_t, ConfGraphNode *> id_to_node;
std::vector<std::shared_ptr<ConfGraphNode>> nodes;
std::unordered_map<ConfGraphNode *, std::unordered_map<ConfGraphNode *, std::list<ConfGraphNode *>::iterator>>
adj_table;
// available during coloring
std::vector<ConfGraphNode *> stack;
std::vector<ConfGraphNode *> actual_spills;
std::unordered_set<ConfGraphNode *> low_degree_and_not_move_related;
std::unordered_set<ConfGraphNode *> low_degree_and_move_related;
std::unordered_set<ConfGraphNode *> high_degree_nodes;
std::unordered_set<opt::MoveInstruct *> pending_moves;
std::unordered_set<opt::MoveInstruct *> potential_moves;
};
ConfGraph BuildConfGraph(CFGType &cfg);
bool TryColoring(std::shared_ptr<FunctionDefItem> src, CFGType &cfg, ConfGraph& confgraph);
bool ConductColoring(std::shared_ptr<FunctionDefItem> src, CFGType &cfg, ConfGraph &confgraph);