mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
JSSpecCompiler: Add control flow graph simplification pass
It removes empty `BasicBlock`s with an unconditional jump continuation and then removes unreferenced blocks from the graph.
This commit is contained in:
parent
475ef6965a
commit
12072dbac5
7 changed files with 215 additions and 1 deletions
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Compiler/CompilerPass.h"
|
||||
#include "Compiler/ControlFlowGraph.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
// CFGSimplificationPass removes empty `BasicBlock`s with an unconditional jump continuation. It
|
||||
// also removes unreferenced blocks from the graph.
|
||||
class CFGSimplificationPass : public IntraproceduralCompilerPass {
|
||||
public:
|
||||
inline static constexpr StringView name = "cfg-simplification"sv;
|
||||
|
||||
using IntraproceduralCompilerPass::IntraproceduralCompilerPass;
|
||||
|
||||
protected:
|
||||
void process_function() override;
|
||||
|
||||
private:
|
||||
enum class State : char {
|
||||
NotUsed,
|
||||
CurrentlyInside,
|
||||
Used,
|
||||
};
|
||||
|
||||
bool compute_replacement_block(size_t i);
|
||||
void compute_referenced_blocks(BasicBlockRef block);
|
||||
|
||||
Vector<BasicBlockRef> m_replacement;
|
||||
Vector<State> m_state;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue