P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
P4::FindVariableValues Class Referencefinal
Inheritance diagram for P4::FindVariableValues:

Public Member Functions

 FindVariableValues (ReferenceMap *refMap, TypeMap *typeMap, std::map< const IR::Node *, std::map< cstring, const IR::Expression * > * > *acts)
 

Detailed Description

Global copy propagation, currently only operationg on control blocks where it optimizes the bodies of actions by propagating literal values for variables used in those actions. Pass is limited to only optimizing actions called in the 'apply' body of the control block and has no effect on actions found in tables. This pass is designed as an extension of the LocalCopyPropagation pass, but the logic has been separated into a standalone pass to avoid additionally complicating the LocalCopyProp pass. GlobalCopyPropagation pass was made with the intent of being used together with the existing LocalCopyPropagation pass, and therefore doesn't introduce some of the features of that pass.

The logic of this pass is divided into 2 passes, an Inspector pass that collects information on the variables used in the program and their values at the time of the action call and a Transformer pass that uses this information to edit the action bodies. The nature of the below mentionied optimization is such that it requires retroactive transformations to the action bodies, and this was the reason for having 2 separate passes.

The main situation that this pass optimizes is given below: ... control ing(out bit<16> y, ...) { bit<16> x; action do_action() { y = x; }

apply { x = 16w5; do_action(); } } ...

, and after optimization: ... control ing(out bit<16> y, ...) { action do_action() { y = 16w5; }

apply { do_action(); } } ...

Precondition
This pass should be run after the LocalizeAllActions frontend pass, which ensures that each action is invoked only once. This pass operates on control blocks and collects information about the state of the variables in that block and later distributes this information to the Transformer pass. Information is represented as a map that contains literal values for variables that need to be propagated, each action node has it's own map of information.