LICM.hpp 812 Bytes
Newer Older
刘睿博's avatar
刘睿博 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include "FuncInfo.hpp"
#include "LoopDetection.hpp"
#include "PassManager.hpp"
#include <memory>
#include <unordered_map>

class LoopInvariantCodeMotion : public Pass {
  public:
    LoopInvariantCodeMotion(Module *m) : Pass(m) {}
    ~LoopInvariantCodeMotion() = default;

    void run() override;

  private:
    std::unordered_map<std::shared_ptr<Loop>, bool> is_loop_done_;
    std::unique_ptr<LoopDetection> loop_detection_;
    std::unique_ptr<FuncInfo> func_info_;
    void traverse_loop(std::shared_ptr<Loop> loop);
    void run_on_loop(std::shared_ptr<Loop> loop);
    void collect_loop_info(std::shared_ptr<Loop> loop,
                          std::set<Value *> &loop_instructions,
                          std::set<Value *> &updated_global,
                          bool &contains_impure_call);
};