#ifndef LOOPUNROLL_HPP #define LOOPUNROLL_HPP #include "BasicBlock.h" #include "Module.h" #include "PassManager.hpp" #include #include #include using std::cout; using std::endl; using std::string; using std::to_string; using std::vector; namespace Graph { using Edge = std::pair; using BackEdgeList = vector; using SimpleLoop = vector; } /* This is a class to unroll simple loops: * - strict structure: * --a->b->c--- * ^-----+ * - if the loop has constant times, unroll it. */ class LoopUnroll : public Pass { public: LoopUnroll(Module *_m) : Pass(_m) { for (auto &f : m_->get_functions()) if (f.get_name() == "neg_idx_except") { neg_func = &f; break; } if (neg_func == nullptr) assert(false && "find function neg_idx_except first!"); } LoopUnroll() = delete; void run() override; static string str(const Graph::Edge &edge) { return "(" + edge.first->get_name() + ", " + edge.second->get_name() + ")"; } private: Function *neg_func; Graph::BackEdgeList detect_back(Function *); vector check_sloops(const Graph::BackEdgeList &) const; }; #endif