P4C
The P4 Compiler
Loading...
Searching...
No Matches
bmv2/common/lower.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef BACKENDS_BMV2_COMMON_LOWER_H_
18#define BACKENDS_BMV2_COMMON_LOWER_H_
19
20#include "frontends/common/resolveReferences/resolveReferences.h"
21#include "frontends/p4/typeMap.h"
22#include "ir/ir.h"
23#include "midend/removeComplexExpressions.h"
24
25namespace P4::BMV2 {
26
29 P4::TypeMap *typeMap;
31 int maxShiftWidth;
32
33 const IR::Expression *shift(const IR::Operation_Binary *expression) const;
34
35 public:
36 explicit LowerExpressions(P4::TypeMap *typeMap, int maxShiftWidth = 8)
37 : typeMap(typeMap), maxShiftWidth(maxShiftWidth) {
38 CHECK_NULL(typeMap);
39 setName("LowerExpressions");
40 }
41
42 const IR::Node *postorder(IR::Expression *expression) override;
43 const IR::Node *postorder(IR::Shl *expression) override { return shift(expression); }
44 const IR::Node *postorder(IR::Shr *expression) override { return shift(expression); }
45 const IR::Node *postorder(IR::Cast *expression) override;
46 const IR::Node *postorder(IR::Neg *expression) override;
47 const IR::Node *postorder(IR::Slice *expression) override;
48 const IR::Node *postorder(IR::Concat *expression) override;
49 const IR::Node *preorder(IR::P4Table *table) override {
50 prune();
51 return table;
52 } // don't simplify expressions in table
53};
54
56 public:
58 P4::RemoveComplexExpressionsPolicy *policy = nullptr)
59 : P4::RemoveComplexExpressions(refMap, typeMap, policy) {}
60
61 const IR::Node *postorder(IR::MethodCallExpression *expression) override;
62};
63
64} // namespace P4::BMV2
65
66#endif /* BACKENDS_BMV2_COMMON_LOWER_H_ */
This pass rewrites expressions which are not supported natively on BMv2.
Definition bmv2/common/lower.h:28
Definition bmv2/common/lower.h:55
Definition node.h:95
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition removeComplexExpressions.h:45
Definition removeComplexExpressions.h:30
Definition visitor.h:424
Definition typeMap.h:41
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21