P4C
The P4 Compiler
Loading...
Searching...
No Matches
redundantParsers.h
1/*
2 * Copyright 2022 Intel Corporation
3 * SPDX-FileCopyrightText: 2022 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_REDUNDANTPARSERS_H_
9#define FRONTENDS_P4_REDUNDANTPARSERS_H_
10
11#include "frontends/common/resolveReferences/resolveReferences.h"
12#include "frontends/p4/typeChecking/typeChecker.h"
13#include "frontends/p4/unusedDeclarations.h"
14#include "ir/ir.h"
15
16namespace P4 {
17
21class FindRedundantParsers : public Inspector {
22 std::set<const IR::P4Parser *> &redundantParsers;
23 bool preorder(const IR::P4Parser *parser) override;
24
25 public:
26 explicit FindRedundantParsers(std::set<const IR::P4Parser *> &redundantParsers)
27 : redundantParsers(redundantParsers) {}
28};
29
33class EliminateSubparserCalls : public Transform, public ResolutionContext {
34 const std::set<const IR::P4Parser *> &redundantParsers;
35 TypeMap *typeMap;
36 const IR::Node *postorder(IR::MethodCallStatement *methodCallStmt) override;
37
38 public:
39 EliminateSubparserCalls(const std::set<const IR::P4Parser *> &redundantParsers,
40 TypeMap *typeMap)
41 : redundantParsers(redundantParsers), typeMap(typeMap) {}
42};
43
44class RemoveRedundantParsers : public PassManager {
45 std::set<const IR::P4Parser *> redundantParsers;
46
47 public:
48 RemoveRedundantParsers(TypeMap *typeMap, const RemoveUnusedPolicy &policy)
49 : PassManager{new TypeChecking(nullptr, typeMap, true),
50 new FindRedundantParsers(redundantParsers),
51 new EliminateSubparserCalls(redundantParsers, typeMap),
52 new RemoveAllUnusedDeclarations(policy)} {
53 setName("RemoveRedundantParsers");
54 }
55};
56
57} // namespace P4
58
59#endif /* FRONTENDS_P4_REDUNDANTPARSERS_H_ */
Definition redundantParsers.h:33
Definition redundantParsers.h:21
Definition node.h:53
Definition visitor.h:418
Iterates UnusedDeclarations until convergence.
Definition unusedDeclarations.h:196
Definition unusedDeclarations.h:48
Definition visitor.h:442
Definition typeChecker.h:55
Definition typeMap.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13