P4C
The P4 Compiler
Loading...
Searching...
No Matches
replaceSelectRange.h
1/*
2 * Copyright 2020 MNK Labs & Consulting
3 * SPDX-FileCopyrightText: 2020 MNK Labs & Consulting
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7#ifndef MIDEND_REPLACESELECTRANGE_H_
8#define MIDEND_REPLACESELECTRANGE_H_
9
10#include <set>
11#include <vector>
12
13#include "ir/ir.h"
14
15namespace P4 {
16
21class ReplaceSelectRange : public Transform {
22 public:
23 // number of new cases generated for ternary operations due to a range
24 // Each case is a key set expression.
25 const unsigned MAX_CASES;
26 // An index i is in this set if selectExpression->components[i] needs to be
27 // cast from int to bit. This is needed if and only if the expression at
28 // position i is of int type and there is a label that has in the i-th
29 // position a range expression. This is needed since we replace ranges with
30 // masks and masks are only defined for signed types.
31 std::set<size_t> signedIndicesToReplace;
32
33 explicit ReplaceSelectRange(unsigned max = 100) : MAX_CASES(max) {
34 setName("DoReplaceSelectRange");
35 }
36
37 const IR::Node *postorder(IR::SelectExpression *e) override;
38 const IR::Node *postorder(IR::SelectCase *p) override;
39
40 std::vector<const IR::Mask *> *rangeToMasks(const IR::Range *, size_t);
41 std::vector<IR::Vector<IR::Expression>> cartesianAppend(
42 const std::vector<IR::Vector<IR::Expression>> &vecs,
43 const std::vector<const IR::Mask *> &masks);
44 std::vector<IR::Vector<IR::Expression>> cartesianAppend(
45 const std::vector<IR::Vector<IR::Expression>> &vecs, const IR::Expression *e);
46};
47
48} // namespace P4
49
50#endif /* MIDEND_REPLACESELECTRANGE_H_ */
Definition node.h:53
Definition ir/vector.h:59
Definition visitor.h:442
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13