#pragma once #include #include "IR/IR_basic.h" #include "cfg.h" class ConfGraphNode { public: const static size_t kInf = (std::numeric_limits::max()) >> 2; std::list var_ids; size_t color; size_t degree; bool is_binded_with_physical_reg; std::list neighbors; // the following are for graph maintenance ConfGraphNode *is_merged_into; static ConfGraphNode *FindFather(ConfGraphNode *x) { if (x->is_merged_into == x) return x; return x->is_merged_into = FindFather(x->is_merged_into); } bool is_temporarily_removed; std::list neighbors_half_available; std::list neighbors_not_available; std::list> original_move_neighbors; }; class ConfGraph { public: // available after construction std::unordered_map id_to_node; std::vector> nodes; std::unordered_map::iterator>> adj_table; // available during coloring std::vector stack; std::vector actual_spills; std::unordered_set low_degree_and_not_move_related; std::unordered_set low_degree_and_move_related; std::unordered_set high_degree_nodes; std::unordered_set pending_moves; std::unordered_set potential_moves; std::unordered_set awful_moves; std::unordered_map::iterator>> adj_table_half_available; std::unordered_map::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); bool ConductColoring(std::shared_ptr src, CFGType &cfg, ConfGraph &confgraph);