26 bool unreachable =
false;
29 IR::Node *preorder(IR::Function *fn) {
37 IR::Node *preorder(IR::P4Action *act) {
41 IR::Node *preorder(IR::P4Control *c) {
45 IR::Node *preorder(IR::P4Parser *p) {
49 IR::Node *preorder(IR::ParserState *s) {
55 IR::Node *postorder(IR::Declaration *d) {
61 IR::Node *postorder(IR::Expression *e) {
66 IR::Node *preorder(IR::Statement *s) {
67 if (unreachable)
return nullptr;
70 IR::Node *preorder(IR::Declaration_Variable *v) {
71 if (unreachable)
return nullptr;
74 IR::Node *preorder(IR::BreakStatement *s) {
75 if (unreachable)
return nullptr;
79 IR::Node *preorder(IR::ContinueStatement *s) {
80 if (unreachable)
return nullptr;
84 IR::Node *preorder(IR::ExitStatement *s) {
85 if (unreachable)
return nullptr;
89 IR::Node *preorder(IR::ReturnStatement *s) {
90 if (unreachable)
return nullptr;
94 IR::Node *preorder(IR::IfStatement *ifstmt) {
95 if (unreachable)
return nullptr;
97 visit(ifstmt->ifTrue,
"ifTrue");
98 bool jumps = unreachable;
100 visit(ifstmt->ifFalse,
"ifTrue");
101 unreachable &= jumps;
102 if (!ifstmt->ifTrue) ifstmt->ifTrue =
new IR::EmptyStatement;
105 IR::Node *preorder(IR::SwitchStatement *swtch) {
106 if (unreachable)
return nullptr;
108 bool final_unreachable =
true;
109 bool has_default =
false;
110 for (
auto &c : swtch->cases) {
111 if (c->label->is<IR::DefaultExpression>()) has_default =
true;
115 BUG_CHECK(c->statement,
"bogus eliminated case");
116 final_unreachable &= unreachable;
119 unreachable = final_unreachable & has_default;
122 IR::Node *preorder(IR::ForStatement *loop) {
123 if (unreachable)
return nullptr;
125 visit(loop->init,
"init");
126 BUG_CHECK(!unreachable,
"jump in loop init statements");
127 visit(loop->body,
"body");
129 visit(loop->updates,
"updates");
131 if (!loop->body) loop->body =
new IR::EmptyStatement;
134 IR::Node *preorder(IR::ForInStatement *loop) {
135 if (unreachable)
return nullptr;
137 visit(loop->body,
"body");
139 if (!loop->body) loop->body =
new IR::EmptyStatement;
144 explicit ElimUnreachableStmts() {}
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13