P4C
The P4 Compiler
Loading...
Searching...
No Matches
size_of.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_COMMON_SIZE_OF_H_
20#define BACKENDS_TOFINO_BF_P4C_COMMON_SIZE_OF_H_
21
22#include "frontends/p4/strengthReduction.h"
23#include "ir/ir.h"
24
25namespace BFN {
26
27using namespace P4;
28
29class CloneConstants : public Transform {
30 public:
31 CloneConstants() = default;
32 const IR::Node *postorder(IR::Constant *constant) override {
33 // We clone the constant. This is necessary because the same
34 // the type associated with the constant may participate in
35 // type unification, and thus we want to have different type
36 // objects for different constant instances.
37 const IR::Type *type = constant->type;
38 if (type->is<IR::Type_Bits>()) {
39 type = constant->type->clone();
40 } else if (auto ii = type->to<IR::Type_InfInt>()) {
41 // You can't just clone a InfInt value, because
42 // you get the same declid. We want a new declid.
43 type = IR::Type_InfInt::get(ii->srcInfo);
44 } else {
45 BUG("unexpected type %2% for constant %2%", type, constant);
46 }
47 return new IR::Constant(constant->srcInfo, type, constant->value, constant->base);
48 }
49 static const IR::Expression *clone(const IR::Expression *expression) {
50 return expression->apply(CloneConstants())->to<IR::Expression>();
51 }
52};
53
59 public:
61 const IR::Node *preorder(IR::MAU::TypedPrimitive *p) override;
62 const IR::Node *preorder(IR::MethodCallExpression *mce) override;
63};
64
70 public:
71 const IR::Expression *getConstant(const IR::Expression *expr) const;
72 const IR::Node *postorder(IR::Slice *e) override;
73};
74
76 const IR::Node *sub(IR::MAU::Instruction *inst);
77 const IR::Node *preorder(IR::MAU::SaluInstruction *inst) override;
78 const IR::Node *preorder(IR::MAU::Instruction *inst) override;
79};
80
82 public:
84 addPasses({new ConvertSizeOfToConstant(), new BackendConstantFolding(),
86 }
87};
88
89} // namespace BFN
90
91#endif /* BACKENDS_TOFINO_BF_P4C_COMMON_SIZE_OF_H_ */
Definition size_of.h:69
Definition size_of.h:75
Definition size_of.h:58
Definition size_of.h:81
Definition constantFolding.cpp:28
Definition node.h:94
Definition ir/pass_manager.h:40
Definition visitor.h:424
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24