P4C
The P4 Compiler
Loading...
Searching...
No Matches
optimizeExpressions.h
1/*
2 * SPDX-FileCopyrightText: 2022 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef FRONTENDS_P4_OPTIMIZEEXPRESSIONS_H_
8#define FRONTENDS_P4_OPTIMIZEEXPRESSIONS_H_
9
10#include "frontends/common/constantFolding.h"
11#include "frontends/p4/strengthReduction.h"
12
13namespace P4 {
14
17inline const IR::Expression *optimizeExpression(const IR::Expression *node) {
18 auto pass = PassRepeated({
19 new P4::StrengthReduction(nullptr, nullptr, nullptr),
20 new P4::ConstantFolding(nullptr, false),
21 });
22 node = node->apply(pass);
23 BUG_CHECK(::P4::errorCount() == 0, "Encountered errors while trying to optimize expressions.");
24 return node;
25}
26
27} // namespace P4
28
29#endif /* FRONTENDS_P4_OPTIMIZEEXPRESSIONS_H_ */
Definition constantFolding.h:187
Definition ir/pass_manager.h:146
Definition strengthReduction.h:142
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
const IR::Expression * optimizeExpression(const IR::Expression *node)
Definition optimizeExpressions.h:17
unsigned errorCount()
Definition lib/error.h:34