ROSE Compiler Framework/Constant Propagation
Please see also ROSE Compiler Framework/Generic Dataflow Framework since this analysis is implemented using the framework.
overview
editSee http://en.wikipedia.org/wiki/Constant_folding for the examples of constant folding and constant propagation "Constant propagation is the process of substituting the values of known constants in expressions at compile time. "
Example
editThe analysis will only generate lattices representing the propagated constant values. It will NOT actually transform the AST! So the example code below is used to only illustrate the propagation of values.
Input code
int x = 14;
int y = 7 - x / 2;
return y * (28 / x + 2);
Propagating x yields:
int x = 14;
int y = 7 - 14 / 2;
return y * (28 / 14 + 2);
Continuing to propagate yields the following:
int x = 14;
int y = 0;
return 0;
Source files
editList
- rose/tests/roseTests/programAnalysisTests/generalDataFlowAnalysisTests/constantPropagation.h
- rose/tests/roseTests/programAnalysisTests/generalDataFlowAnalysisTests/constantPropagation.C
TODO
- move them into rose/src/midend/programAnalysis/genericDataflow/simpleAnalyses
Tests
edittest translator
- rose/tests/roseTests/programAnalysisTests/generalDataFlowAnalysisTests/constantPropagationTest.C github-link
The test translator will
- generate dot graph for the CFG and attached constant lattice.
- verify the generated results are expected (given as pragmas in the input test input file)
test input with verification
- rose/tests/roseTests/programAnalysisTests/generalDataFlowAnalysisTests/cp_test1.C