Jump to content

ROSE Compiler Framework/Constant Propagation

From Wikibooks, open books for an open world

Please see also ROSE Compiler Framework/Generic Dataflow Framework since this analysis is implemented using the framework.

overview

[edit | edit source]

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

[edit | edit source]

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

[edit | edit source]

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

[edit | edit source]

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