411 REFERENCE · Wikibooks
ROSE Compiler Framework/Constant Propagation
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Please see also ROSE Compiler Framework/Generic Dataflow Framework since this analysis is implemented using the framework.
overview
See 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
The 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
List
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
test 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