diff --git a/include/opt/confgraph.h b/include/opt/confgraph.h new file mode 100644 index 0000000..84f1644 --- /dev/null +++ b/include/opt/confgraph.h @@ -0,0 +1,21 @@ +#pragma once +#include "IR/IR_basic.h" +#include "cfg.h" +class ConfGraphNode { + public: + std::string var_name; + size_t color; + bool is_move_related; + bool move_related_but_frozen; + bool is_binded_with_physical_reg; + std::vector neighbors; + ConfGraphNode(std::string var_name) : var_name(var_name) {} +}; +class ConfGraph { + public: + std::unordered_map name_to_node; + std::vector> nodes; +}; + +ConfGraph BuildConfGraph(CFGType &cfg); +bool TryColoring(std::shared_ptr src, CFGType &cfg, ConfGraph& confgraph); \ No newline at end of file diff --git a/include/opt/regalloc.h b/include/opt/regalloc.h index 40d8521..02aeca5 100644 --- a/include/opt/regalloc.h +++ b/include/opt/regalloc.h @@ -1,5 +1,6 @@ #pragma once #include "liveanalysis.h" #include "phieliminate.h" +#include "confgraph.h" std::shared_ptr RegAlloc(std::shared_ptr src); \ No newline at end of file diff --git a/src/opt/confgraph.cpp b/src/opt/confgraph.cpp new file mode 100644 index 0000000..664ad86 --- /dev/null +++ b/src/opt/confgraph.cpp @@ -0,0 +1,6 @@ +#include "confgraph.h" +#include +#include "cfg.h" + +ConfGraph BuildConfGraph(CFGType &cfg) { ; } +bool TryColoring(std::shared_ptr src, CFGType &cfg, ConfGraph& confgraph) { return false; } diff --git a/src/opt/regalloc.cpp b/src/opt/regalloc.cpp index 7fc4e48..381a107 100644 --- a/src/opt/regalloc.cpp +++ b/src/opt/regalloc.cpp @@ -1,5 +1,7 @@ #include "regalloc.h" #include "IR/IR_basic.h" +#include "cfg.h" +#include "confgraph.h" #include "liveanalysis.h" #include "phieliminate.h" #include "tools.h" @@ -125,17 +127,22 @@ void EnforcePhysicalRegs(CFGType &cfg) { } } } -void ConductRegAllocForFunction([[maybe_unused]] std::shared_ptr func, CFGType &cfg) { - EnforcePhysicalRegs(cfg); - LiveAnalysis(cfg); +void ConductRegAllocForFunction(std::shared_ptr func) { + CFGType cfg; + ConfGraph confgraph; + do { + cfg = BuildCFGForFunction(func); + EnforcePhysicalRegs(cfg); + LiveAnalysis(cfg); + confgraph = BuildConfGraph(cfg); + } while (TryColoring(func, cfg, confgraph)); } std::shared_ptr RegAlloc(std::shared_ptr src) { auto res = src; for (auto &func : res->function_defs) { // func = std::make_shared(*func); - auto cfg = BuildCFGForFunction(func); - ConductRegAllocForFunction(func, cfg); + ConductRegAllocForFunction(func); } return res; } \ No newline at end of file