#pragma once #include "pass_base.h" namespace CompSysY { class PassSCCP final : public Pass { public: PassSCCP() : Pass("constant propagation") {} void run(const Module &module) override; enum class ConstLatTag { Top = 0, Const, Bottom }; struct ConstLat { ConstLatTag tag = ConstLatTag::Top; int value = ~0; bool is_top() const { return tag == ConstLatTag::Top; } bool is_bot() const { return tag == ConstLatTag::Bottom; } bool is_const() const { return tag == ConstLatTag::Const; } bool operator==(const ConstLat &op2) const { return tag == op2.tag && value == op2.value; } bool operator!=(const ConstLat &op2) const { return !(tag == op2.tag && value == op2.value); } static ConstLat get_bot() { return {ConstLatTag::Bottom, ~0}; } }; private: typedef std::pair edge_type; std::set FLowWL; std::set SSAWL; std::map ExecFlag; std::map LatCell; std::unordered_map inst_id; std::unordered_map id_inst; std::set> edge_set; std::unordered_map> edge_list; void build_single_inst_block(Function *func); void Initialize(Function *); void SCCP(Function *); void Visit_Phi(InstPhi *); void Visit_Inst(Instruction *); ConstLat Lat_Eval(Instruction *inst); void post_sccp(); }; class PassMem2Reg final : public Pass { public: PassMem2Reg() : Pass("mem2reg") {} void run(const Module &module) override; }; class PassBuildCFG final : public Pass { public: PassBuildCFG() : Pass("build control flow graph") {} void run(const Module &module) override; }; class PassConstFold final : public Pass { public: PassConstFold() : Pass("constant fold") {} void run(const Module &module) override; }; class PassDCE final : public Pass { public: PassDCE() : Pass("dead code elimination") {} void run(const Module &module) override; }; } // namespace CompSysY