#ifndef LIVERANGE_HPP #define LIVERANGE_HPP #include "BasicBlock.h" #include "Function.h" #include "Instruction.h" #include "Module.h" #include "Value.h" #include #include #include #include #include #include using std::map; using std::pair; using std::set; using std::string; using std::vector; #define __LRA_PRINT__ class LiveRangeAnalyzer { friend class CodeGen; using LiveSet = set; using PhiMap = map>>; public: struct Interval { Interval(int a, int b) : i(a), j(b) {} Interval() = delete; int i, j; }; LiveRangeAnalyzer(Module *m_, PhiMap &phi_map_) : m(m_), phi_map(phi_map_) {} LiveRangeAnalyzer() = delete; void run(); void clear(); void print(Function *func, bool printSet = true); string print_liveSet(LiveSet &ls) { string s = "[ "; for (auto k : ls) s += k->get_name() + " "; s += "]"; return s; } private: Module *m; // Function *func; map liverange; map IN, OUT; map instr_id; map, int> cpstmt_id; const PhiMap &phi_map; void make_id(Function *); void run(Function *); LiveSet joinFor(BasicBlock *bb); void union_ip(LiveSet &dest, LiveSet &src) { LiveSet res; set_union(dest.begin(), dest.end(), src.begin(), src.end(), std::inserter(res, res.begin())); dest = res; } // Require: out-set is already set // Return: the in-set(will not set IN-map) LiveSet transferFunction(Instruction *); }; #endif