#include "Value.h" #include "liverange.hpp" #include #include using std::cout; using std::endl; using std::to_string; using namespace LRA; namespace RA { #define MAXR 32 bool no_reg_alloca(Value *v); struct ActiveCMP { bool operator()(LiveInterval const &lhs, LiveInterval const &rhs) const { if (lhs.first.j != rhs.first.j) return lhs.first.j < rhs.first.j; else return lhs.first.i < rhs.first.i; } }; class RegAllocator { public: RegAllocator(const uint R_) : R(R_), used{false} { assert(R <= MAXR); } RegAllocator() = delete; // input set is sorted by increasing start point void LinearScan(const LVITS &liveints); void reset(); const map &get() const { return regmap; } void print(string (*regname)(int)) { for (auto [op, reg] : regmap) cout << op->get_name() << " ~ " << regname(reg) << endl; } private: const uint R; bool used[MAXR + 1]; // index range: 1 ~ R map regmap; // sorted by increasing end point set active; void ExpireOldIntervals(LiveInterval); void SpillAtInterval(LiveInterval); }; } // namespace RA