P4C
The P4 Compiler
Loading...
Searching...
No Matches
reassociation.h
1/*
2 * Copyright 2020 VMware, Inc.
3 * SPDX-FileCopyrightText: 2020 VMware, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_REASSOCIATION_H_
9#define FRONTENDS_P4_REASSOCIATION_H_
10
11#include "ir/ir.h"
12#include "ir/visitor.h"
13
14namespace P4 {
15
16using namespace literals;
17
21class Reassociation final : public Transform {
22 public:
23 Reassociation() {
24 visitDagOnce = true;
25 setName("Reassociation");
26 }
27 using Transform::postorder;
28
29 const IR::Node *reassociate(IR::Operation_Binary *root);
30
31 const IR::Node *postorder(IR::Add *expr) override { return reassociate(expr); }
32 const IR::Node *postorder(IR::Mul *expr) override { return reassociate(expr); }
33 const IR::Node *postorder(IR::BOr *expr) override { return reassociate(expr); }
34 const IR::Node *postorder(IR::BAnd *expr) override { return reassociate(expr); }
35 const IR::Node *postorder(IR::BXor *expr) override { return reassociate(expr); }
36 const IR::BlockStatement *preorder(IR::BlockStatement *bs) override {
37 // FIXME: Do we need to check for expression, so we'd be able to fine tune, e.g.
38 // @disable_optimization("reassociation")
39 if (bs->hasAnnotation(IR::Annotation::disableOptimizationAnnotation)) prune();
40 return bs;
41 }
42};
43
44} // namespace P4
45
46#endif /* FRONTENDS_P4_REASSOCIATION_H_ */
Definition node.h:53
Definition visitor.h:442
Definition cstring.h:80
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13