mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
JSSpecCompiler: Add bare-bones DCE pass
Right now the only dead code it eliminates is the unused phi nodes.
This commit is contained in:
parent
162c334508
commit
5338cdd153
6 changed files with 286 additions and 0 deletions
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Compiler/EnableGraphPointers.h"
|
||||
#include "Compiler/GenericASTPass.h"
|
||||
#include "Compiler/StronglyConnectedComponents.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
class DeadCodeEliminationPass
|
||||
: public IntraproceduralCompilerPass
|
||||
, private RecursiveASTVisitor
|
||||
, private EnableGraphPointers<DeadCodeEliminationPass, SSAVariableDeclarationRef> {
|
||||
public:
|
||||
inline static constexpr StringView name = "dce"sv;
|
||||
|
||||
using IntraproceduralCompilerPass::IntraproceduralCompilerPass;
|
||||
|
||||
protected:
|
||||
void process_function() override;
|
||||
|
||||
private:
|
||||
friend EnableGraphPointers;
|
||||
|
||||
static Vertex as_vertex(Variable* variable);
|
||||
RecursionDecision on_entry(Tree tree) override;
|
||||
void on_leave(Tree tree) override;
|
||||
void remove_unused_phi_nodes();
|
||||
|
||||
struct NodeData {
|
||||
Vector<Vertex> outgoing_edges;
|
||||
Vector<Vertex> incoming_edges;
|
||||
|
||||
bool is_referenced = false;
|
||||
};
|
||||
|
||||
Vector<NodeData> m_nodes;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue