forked from rose-compiler/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constantFoldingTransformation.C
44 lines (36 loc) · 1.7 KB
/
constantFoldingTransformation.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "rose.h"
#include "constantFolding.h"
// IMPORTANT NOTE:
// The constant folding demonstrated here is appropriate for
// the untransformed AST (it cleans up constant expression trees
// let in the AST by the frontend which can tend to confuse some
// analysis and transformation mechanism (PRE, specifically).
// So it is useful to run before doing forms of analysis where
// your analysis does not want to see unfolded constant expression
// trees (the sort commontly folded by most frontends). The
// additional constant folding done here is on the AST directly
// and is useful for cleaning up transformations. However,
// it is not finished!
int
main ( int argc, char * argv[] )
{
// Initialize and check compatibility. See Rose::initialize
ROSE_INITIALIZE;
SgProject* project = frontend(argc,argv);
ROSE_ASSERT(project != NULL);
// Test constant folding on expression trees already folded by EDG
// (nothing to do since the frontend already did constant folding,
// but this does remove the constant expression trees which are
// redundent with previously constant folded values).
ConstantFolding::constantFoldingOptimization(project);
// Generate from constant expressions from simple constants, as some
// transformations might be likely to do, this will clean them up.
ConstantFolding::constantUnFoldingTest(project);
ConstantFolding::constantUnFoldingTest(project);
ConstantFolding::constantUnFoldingTest(project);
ConstantFolding::constantUnFoldingTest(project);
// Now do the constant folding on the ugly constant expressions that
// we just generated!
ConstantFolding::constantFoldingOptimization(project);
return backend(project);
}