< ROSE Compiler Framework

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
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.