#ifndef REGALLOCA_HPP #define REGALLOCA_HPP #include "Function.h" #include "Value.h" #include "liverange.hpp" #include #include using std::cout; using std::endl; using namespace LRA; namespace RA { #define MAXR 32 #define ARG_MAX_R 8 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 if (lhs.first.i != rhs.first.i) return lhs.first.i < rhs.first.i; else return lhs.second < rhs.second; } }; class RegAllocator { public: RegAllocator(const uint R_, bool fl) : FLOAT(fl), R(R_), used{false} { cout << "RegAllocator initialize: R=" << R << endl; assert(R <= MAXR); } RegAllocator() = delete; static bool no_reg_alloca(Value *v); // input set is sorted by increasing start point void LinearScan(const LVITS &, Function *); const map &get() const { return regmap; } void print(string (*regname)(int)) { for (auto [op, reg] : regmap) cout << op->get_name() << " ~ " << regname(reg) << endl; } private: Function *cur_func; const bool FLOAT; const uint R; bool used[MAXR + 1]; // index range: 1 ~ R map regmap; // sorted by increasing end point set active; void reset(Function * = nullptr); int ReserveForArg(const LVITS &); void ExpireOldIntervals(LiveInterval); void SpillAtInterval(LiveInterval); }; } // namespace RA #endif