Polaris: InterProcConstProp Class Reference

InterProcConstProp Class Reference

The DUMMY_PGM_FILE macro (defined in the g++ command) holds the side-effects of procedures not in the given set of program units. More...

#include <InterProcConstProp.h>

List of all members.

Public Member Functions

 InterProcConstProp (Program &pgms, PC_REAL_BOOL subst_reals, PC_ARRAY_BOOL subst_arrays, char *intrin_file_name, int debug=0)
 Compute the interprocedural constants that enter each program unit in pgms.
virtual ~InterProcConstProp ()
 Destructor.
void clone_and_propagate (PC_UNREACH_BOOL remove_unreachable)
 Clone all procedures that have multiple sets of constants entering them.
void double_clone_and_propagate (PC_UNREACH_BOOL remove_unreachable)
 Like clone_and_propagate except that interprocedural constants are computed a second time.
void iter_clone_and_propagate (PC_UNREACH_BOOL remove_unreachable)
 Similate to double_clone_and_propagate() except that this method will repeatedly perform interprocedural constant propagation until no more new constants are uncovered.
void expand_all_substituted ()
 Replace all variables with their precomputed constant expressions for all expressions in the given object.
void pgms_can_be_called_externally ()
 Assume that all procedures in my given set of programs can be called externally when I compute my constants.
void print_consts_sets (ostream &o) const
 silvius: make this public:
void add_maymods ()
 silvius: make this public:
void propagate_constants (PC_UNREACH_BOOL remove_unreachable)
virtual void print (ostream &o) const
 Print out all my data structures.

Friends

class IPCPProcData


Detailed Description

The DUMMY_PGM_FILE macro (defined in the g++ command) holds the side-effects of procedures not in the given set of program units.

Polaris Constant

See also:
InterProcConstProp.h

InterProcConstProp.h

Description

This class performs interprocedural symbolic constant propagation on the given Program. That is, it can propagate integer, logical, and symbolic constants across procedure boundaries. It is also capable of eliminating unreachable code and propagate some constant values from DATA statements or the tests of IF statements. See constant.h for more details.

Procedure cloning is performed to allow greater opportunity to propagate constants accross procedure boundaries. Procedure cloning is the copying and renaming of a procedure to decrease the number of call sites that invoke the procedure. Procedure cloning aids constant propagation since a procedure argument has a constant value on entry to the procedure only when the same constant value is passed into that procedure for all call sites.

In addition to propagating interprocedural constants, the pass also determines the side effects of each procedure. More specifically, it determines what variables may be modified by a procedure. The pass annotates each call site with a MAYMOD assertion that identifies these modified variables. Only those call sites for procedures that are in the given Program object are annotated with MAYMOD assertions. These MAYMOD assertions may contain global variables that were not passed in as an argument to the call site. Aliasing and equivalencing is taken into account when computing side-effects.

When the interprocedural constant propagator encounters a call site for a procedure that hasn't been declared, it first tries to find the procedure in the file DUMMY_PGM_FILE. This file contains a set of false declarations of commonly used fortran programs, such as CPUTIM or ELAPSE. These declarations only provide enough code to determine which arguments are modified and which are not. If the procedure is not in DUMMY_PGM_FILE, it then checks whether the the call site has a MAYMOD assertion. If so, it uses the assertion to determine what variables are modified by the call site. If it doesn't have a MAYMOD assertion, the pass assumes that the call site modifies all its arguments as well as all global variables and formal parameters of the caller. Setting the switch "pc_call_mods" to 1 would cause it to assume that only call site's arguments are modified in this case.

Example

The following code segment will propagate and substitute all integer, logical, and symbolic constants in the given Program object. These constants will be allowed to cross procedure boundaries.

       InterProcConstProp propagator(pgms, IGNORE_REALS, IGNORE_ARRAYS);
       propagator.iter_clone_and_propagate(REMOVE_UNREACHABLE_CODE);
       propagator.expand_all_substituted();

Known Bugs or Limitations

Conditional (flow-sensitive) constants cannot be propagated out of procedure calls by a single pass of interprocedural constant propagation. This is why the methods double_clone_and_propagate() and iter_clone_and_propagate() were provided.

Symbolic constants containing local variables cannot be propagated outside a procedure.

Constructor will go in an infinite loop if the given set of programs contain recursive procedure calls.

See "Known Bugs or Limitations" in constant.h for other potential problems.

Definition at line 102 of file InterProcConstProp.h.


Constructor & Destructor Documentation

InterProcConstProp::InterProcConstProp Program pgms,
PC_REAL_BOOL  subst_reals,
PC_ARRAY_BOOL  subst_arrays,
char *  intrin_file_name,
int  debug = 0
 

Compute the interprocedural constants that enter each program unit in pgms.

The class pgms must contain a main program and not contain any recursive procedure calls.

If subst_reals == IGNORE_REALS, then only constant expressions that are integer or logical types are computed. Otherwise if subst_reals == SUBST_REALS, then real, double and complex constant expressions are computed as well.

If subst_arrays == IGNORE_ARRAYS, then only constant expressions that do not contain array references are computed. Otherwise, if subst_arrays == SUBST_ARRAYS, then constant expressions with array references are computed.

InterProcConstProp::~InterProcConstProp  )  [virtual]
 

Destructor.

Definition at line 424 of file InterProcConstProp.cc.


Member Function Documentation

void InterProcConstProp::clone_and_propagate PC_UNREACH_BOOL  remove_unreachable  ) 
 

Clone all procedures that have multiple sets of constants entering them.

Then forward substitute the generated constants for each procedure. These constants are not physically substituted into the program. Instead the constants are placed in the substituted() field for all constant variables.

If remove_unreachable == REMOVE_UNREACH_CODE, then any code that the pass determines to be unreachable is deleted. Otherwise, the unreachable code is left in place.

Definition at line 654 of file InterProcConstProp.cc.

Referenced by main().

void InterProcConstProp::double_clone_and_propagate PC_UNREACH_BOOL  remove_unreachable  ) 
 

Like clone_and_propagate except that interprocedural constants are computed a second time.

One may wish to do this because the second interprocedural constant propagation pass may use the constants from the first pass to eliminate more unreachable code and to propagate more conditional constants. This method is about twice as slow as clone_and_propagate().

Definition at line 665 of file InterProcConstProp.cc.

Referenced by main().

void InterProcConstProp::iter_clone_and_propagate PC_UNREACH_BOOL  remove_unreachable  ) 
 

Similate to double_clone_and_propagate() except that this method will repeatedly perform interprocedural constant propagation until no more new constants are uncovered.

This method is at least as slow as double_clone_and_propagate() and can potentially be much slower.

Definition at line 679 of file InterProcConstProp.cc.

References print_consts_sets().

Referenced by main().

void InterProcConstProp::expand_all_substituted  ) 
 

Replace all variables with their precomputed constant expressions for all expressions in the given object.

Definition at line 703 of file InterProcConstProp.cc.

References KeyIterator< S, T >::current_data(), IPCPProcData::expand_all_substituted(), ProtoDatabase< S, T >::member(), IPCPProcData::pgm(), Definition::tag_ref(), and KeyIterator< S, T >::valid().

Referenced by main().

void InterProcConstProp::pgms_can_be_called_externally  ) 
 

Assume that all procedures in my given set of programs can be called externally when I compute my constants.

Intuitively, this method ensures that if any constants are propagated into a procedure, these constants are anotated to a clone of the procedure rather than the procedure itself. Thus, it is safe to have some program outside my given set of programs call one of my programs.

Definition at line 436 of file InterProcConstProp.cc.

References IPCPProcData::called_externally(), Array< T >::entries(), ProtoDatabase< S, T >::member(), IPCPProcData::pgm(), and Definition::tag_ref().

void InterProcConstProp::print_consts_sets ostream &  o  )  const
 

silvius: make this public:

Definition at line 754 of file InterProcConstProp.cc.

References IPCPProcData::const_sets(), Iterator< T >::current(), KeyIterator< S, T >::current_data(), KeyIterator< S, T >::current_key(), IPCPConstants::print_constants(), Iterator< T >::valid(), and KeyIterator< S, T >::valid().

Referenced by iter_clone_and_propagate(), and main().

void InterProcConstProp::add_maymods  )  [inline]
 

silvius: make this public:

Definition at line 206 of file InterProcConstProp.h.

void InterProcConstProp::propagate_constants PC_UNREACH_BOOL  remove_unreachable  )  [inline]
 

Definition at line 211 of file InterProcConstProp.h.

void InterProcConstProp::print ostream &  o  )  const [virtual]
 

Print out all my data structures.

Definition at line 742 of file InterProcConstProp.cc.


Friends And Related Function Documentation

friend class IPCPProcData [friend]
 

Definition at line 103 of file InterProcConstProp.h.


The documentation for this class was generated from the following files:
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:07:34 2005