P4C
The P4 Compiler
Loading...
Searching...
No Matches
replaceSelectRange.h
1/*
2 * Copyright 2020, MNK Labs & Consulting
3 * http://mnkcg.com
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18#ifndef MIDEND_REPLACESELECTRANGE_H_
19#define MIDEND_REPLACESELECTRANGE_H_
20
21#include <set>
22#include <vector>
23
24#include "ir/ir.h"
25
26namespace P4 {
27
33 public:
34 // number of new cases generated for ternary operations due to a range
35 // Each case is a key set expression.
36 const unsigned MAX_CASES;
37 // An index i is in this set if selectExpression->components[i] needs to be
38 // cast from int to bit. This is needed if and only if the expression at
39 // position i is of int type and there is a label that has in the i-th
40 // position a range expression. This is needed since we replace ranges with
41 // masks and masks are only defined for signed types.
42 std::set<size_t> signedIndicesToReplace;
43
44 explicit ReplaceSelectRange(unsigned max = 100) : MAX_CASES(max) {
45 setName("DoReplaceSelectRange");
46 }
47
48 const IR::Node *postorder(IR::SelectExpression *e) override;
49 const IR::Node *postorder(IR::SelectCase *p) override;
50
51 std::vector<const IR::Mask *> *rangeToMasks(const IR::Range *, size_t);
52 std::vector<IR::Vector<IR::Expression>> cartesianAppend(
53 const std::vector<IR::Vector<IR::Expression>> &vecs,
54 const std::vector<const IR::Mask *> &masks);
55 std::vector<IR::Vector<IR::Expression>> cartesianAppend(
56 const std::vector<IR::Vector<IR::Expression>> &vecs, const IR::Expression *e);
57};
58
59} // namespace P4
60
61#endif /* MIDEND_REPLACESELECTRANGE_H_ */
Definition node.h:94
Definition vector.h:59
Definition replaceSelectRange.h:32
Definition visitor.h:424
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24