P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
P4::DoSimplifyControlFlow Class Reference

Replace complex control flow nodes with simpler ones where possible. More...

Inheritance diagram for P4::DoSimplifyControlFlow:

Public Member Functions

 DoSimplifyControlFlow (ReferenceMap *refMap, TypeMap *typeMap)
 
const IR::Node * postorder (IR::BlockStatement *statement) override
 
const IR::Node * postorder (IR::EmptyStatement *statement) override
 
const IR::Node * postorder (IR::IfStatement *statement) override
 
const IR::Node * postorder (IR::SwitchStatement *statement) override
 

Detailed Description

Replace complex control flow nodes with simpler ones where possible.

Simplify the IR in the following ways:

  1. Remove empty statements from within parser states, actions, and block statements.
  2. Replace if statements with empty bodies with an empty statement.
  3. Remove fallthrough switch cases that are not followed by a case with a statement.
  4. Replace switch statements that switch on a table application but have no cases with a table application expression.
  5. If a block statement is within another block or a parser state, and (a) is empty, then replace it with an empty statement, or (b) does not contain declarations, then move its component statements to the enclosing block.
  6. If a block statement in an if statement branch only contains a single statement, replace the block with the statement it contains.
Precondition
An up-to-date ReferenceMap and TypeMap.