P4C
The P4 Compiler
Loading...
Searching...
No Matches
simplify.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_SIMPLIFY_H_
9#define FRONTENDS_P4_SIMPLIFY_H_
10
11#include "frontends/common/resolveReferences/resolveReferences.h"
12#include "frontends/p4/methodInstance.h"
13#include "frontends/p4/typeChecking/typeChecker.h"
14#include "ir/ir.h"
15
16namespace P4 {
17
42class DoSimplifyControlFlow : public Transform, public ResolutionContext {
43 TypeMap *typeMap;
44 bool foldInlinedFrom;
45
46 public:
47 explicit DoSimplifyControlFlow(TypeMap *typeMap, bool foldInlinedFrom)
48 : typeMap(typeMap), foldInlinedFrom(foldInlinedFrom) {
49 CHECK_NULL(typeMap);
50 setName("DoSimplifyControlFlow");
51 // We may want to replace the same statement with different things
52 // in different places.
53 visitDagOnce = false;
54 }
55 const IR::Node *postorder(IR::BlockStatement *statement) override;
56 const IR::Node *postorder(IR::IfStatement *statement) override;
57 const IR::Node *postorder(IR::EmptyStatement *statement) override;
58 const IR::Node *postorder(IR::SwitchStatement *statement) override;
59};
60
63class SimplifyControlFlow : public PassRepeated {
64 public:
65 explicit SimplifyControlFlow(TypeMap *typeMap, bool foldInlinedFrom,
66 TypeChecking *typeChecking = nullptr) {
67 if (!typeChecking) typeChecking = new TypeChecking(nullptr, typeMap);
68 passes.push_back(typeChecking);
69 passes.push_back(new DoSimplifyControlFlow(typeMap, foldInlinedFrom));
70 setName("SimplifyControlFlow");
71 }
72};
73
74} // namespace P4
75
76#endif /* FRONTENDS_P4_SIMPLIFY_H_ */
Replace complex control flow nodes with simpler ones where possible.
Definition simplify.h:42
Definition node.h:44
Definition visitor.h:433
Definition typeChecker.h:46
Definition typeMap.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13