CFGSimplificationPass.h 924 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "Compiler/CompilerPass.h"
  8. #include "Compiler/ControlFlowGraph.h"
  9. namespace JSSpecCompiler {
  10. // CFGSimplificationPass removes empty `BasicBlock`s with an unconditional jump continuation. It
  11. // also removes unreferenced blocks from the graph.
  12. class CFGSimplificationPass : public IntraproceduralCompilerPass {
  13. public:
  14. inline static constexpr StringView name = "cfg-simplification"sv;
  15. using IntraproceduralCompilerPass::IntraproceduralCompilerPass;
  16. protected:
  17. void process_function() override;
  18. private:
  19. enum class State : char {
  20. NotUsed,
  21. CurrentlyInside,
  22. Used,
  23. };
  24. bool compute_replacement_block(size_t i);
  25. void compute_referenced_blocks(BasicBlockRef block);
  26. Vector<BasicBlockRef> m_replacement;
  27. Vector<State> m_state;
  28. };
  29. }