| Polaris: constant Class Reference | ||
|
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members
constant Class Referencefile constant.h Forward substitute all constants in the program. More...
Detailed Descriptionfile constant.h Forward substitute all constants in the program.Polaris Constant
OverviewThe function propagate_constants() forward substitutes all constant expressions in the given ProgramUnit. The pass can also remove any unreachable code in the ProgramUnit.The pass can also perform interprocedural constant propagation. See file InterProcConstProp.h for more details. DescriptionThis pass contains a collection of routines for propagating and substituting constant values.The most important of these routines is propagate_constants(). The routine propagate_constants propagates all symbolic and integer constant Expressions in a ProgramUnit. It then annotates the Expressions of all the Statements in the ProgramUnit with these constant values. The function propagate_constants() takes several parameters that can be used to customize its performance. The subst_reals flag decides whether the pass should only propagate integer or logical constants, or that it should propagate real, double, or complex constants as well. The subst_arrays flag can be used to allow or prohibit the propagation of constants containing array references. Finally, the remove_unreachable flag decides whether the pass should delete unreachable code while propagating constants. (The propagate_constants() routine is intelligent enough to examine only one of the two cases of an IF statement if constant propagation can determine that its conditional equals .TRUE. or .FALSE. The remove_unreachable flag tells it not to only ignore one of these two cases, but to delete the ignored case as well.) If a procedure call has a MAYMOD assertion, then the pass assumes that only the variables listed in the MAYMOD assertion are modified by the procedure. A MAYMOD assertion with no arguments means that no variables are modified by the call. If a procedure or function call does not have a MAYMOD assertion, the constant propagator assumes that the procedure modifies all of its arguments and all global variables and formal parameters of the caller. By setting the switch pc_call_mods=1, the pass would assume that such procedures only modify their arguments. The function propagate_constants() also has capabilities for propagating constants from DATA statements or conditionals of IF statements. If the program unit given to propagate_constants(pgm, ...) is the main program, the function will propagate the constant values of variables initialized by DATA statements. If unreachable code elimination is enabled, the function would propagate constants from conditional statements of the form "IF (FLAG) THEN", "IF (.NOT. FLAG) THEN", "IF (X .EQ. c) THEN", or "IF (X .NE. c) THEN", where c is an integer constant. That is, it would insert assignment statements of the form "FLAG = .TRUE.", "FLAG = .FALSE.", or "X = c" after the THEN and/or ELSE clauses of the IF statement. The propagation of DATA or IF conditional constants was provided to allow the deletion unreachable code derived from IF statements which allow their bodies to be executed only once (i.e., initialization code). Such code is usually of the form:
DATA INIT /.TRUE./
...
IF (INIT) THEN
...
INIT = .FALSE.
ENDIF
The propagate_constants() and expand_substitute() routines do not recognize constants defined in PARAMETER statements. To substitute the constant values of parameter variables, use one of the substitute_parameters() functions. One of these functions exist for substituting parameters in an Expression, Statement, symbol table (Symtab), or ProgramUnit. These routines accept a subst_real flag, which determines whether the substitution of real parameter expressions should be allowed. See file InterProcConstProp.h if one wishes to perform interprocedural constant propagation. ExampleTo propagate and substitute all constant integer and logical expressions in a ProgramUnit, just execute the following:
clear_substituted(pgm); propagate_constants(pgm, IGNORE_REALS, IGNORE_ARRAYS, REMOVE_UNREACH_CODE); expand_all_substituted(pgm); On the other hand, suppose one wishes to propagate the value of a single variable inside a DO loop. This can be done by executing:
RefSet<Symbol> vars_to_propagate; vars_to_propagate.ins(var); propagate_constants(pgm.stmts(), do_loop, *do_loop.follow_ref(), vars_to_propagate, LEAVE_UNREACHABLE_CODE); SwitchesBy setting switch "pc_call_mods" to 1, the constant propagator would assume that all procedure calls without MAYMOD assertions modify only their arguments. If this switch is not set to 1, all global and formal parameters are also assumed to be modified by such a procedure.Their are several switches used by the driver to determine the arguments to feed to propagate_constants() or substitute_parameters(). These switches are "pc_real", "pc_array" and "pc_unreach" for propagate_constants() and "sp_real" for substitute_parameters(). These switches are not used by the constant propagation pass, only by the driver. Known Bugs or LimitationsThe constant propagator may take a lot of time or space for large programs. The time and space complexity of the pass is O(n*v), where n is the number of statements, and v is the number of variables. The user can speed up the pass by constraining the number of variables or number of statements examined by the pass. See the interfaces to propagate_constants() for more details. Turning off unreachable code elimination can improve the speed of propagate_constants() by as much as 30-40%, but will have little effect on space requirements.Unreachable code elimination may act strangely if performed upon statement blocks that may contain only portions of control structures. For example, IF statements without ENDIFs. One must call clear_substituted() or expand_all_substituted() on a program with non-empty substituted fields before it is printed out, or the printed out program will not be executable.
The documentation for this class was generated from the following file: |
||
|