Polaris: AbstractAccess.h Source File

AbstractAccess.h

Go to the documentation of this file.
00001 #ifndef _ABSTRACTACCESS_H
00002 #define _ABSTRACTACCESS_H
00003 ///
00004 #ifdef POLARIS_GNU_PRAGMAS
00005 #pragma interface
00006 #endif
00007 ///
00008 #include <fstream.h>
00009 #include "ClassNames.h"
00010 ///
00011 extern int _ipa;
00012 /// A static global to hold the value of the ipa switch
00013 extern int _ipa_reasons;
00014 /// A static global to hold the value of the ipa_reasons switch
00015 extern int _ar_coalesce;
00016 /// A static global to hold the value of the ar_coalesce switch
00017 extern int _ar_aggregate;
00018 /// A static global to hold the value of the ar_aggregate switch
00019 extern int _ar_interleave;
00020 /// A static global to hold the value of the ar_interleave switch
00021 extern int _ar_match_dims;
00022 /// A static global to hold the value of the ar_match_dims switch
00023 extern int _ar_logging;
00024 /// A static global to hold the value of the ar_match_dims switch
00025 extern ofstream arlog;
00026 /// The file for writing the Access Region log.
00027 extern int _ar_leave_descr;
00028 /// Controls whether descriptors are left on statements or not
00029 extern int _ar_prtstats;
00030 /// Controls collecting and printing of statistics (ar_prtstats switch)
00031 extern int _ar_approx_thresh;
00032 /// Set the threshold for list size which causes the list to be replaced by 
00033 /// a single "approximate LMAD"
00034 extern int _ar_effort;
00035 /// Controls how hard we work on simplifying a set of descriptors 
00036 /// (scale of 1 to 10, 10 being to work the hardest)
00037 extern int _ar_reshape;
00038 extern ofstream stats_out;
00039 /// Controls collecting of array reshaping data, and writing it to
00040 /// the sequential output file opened on stats_out.
00041 ///
00042 enum AR_MONOTON {
00043     AR_PROVEN_NON_MONO,  /// proven non-monotonic
00044     AR_PROVEN_MONO,      /// proven monotonic
00045     AR_MONO_UNSURE,      /// not sure of monotonicity - check at runtime
00046     AR_UNKNOWN_MONO
00047 };
00048 ///
00049 enum AR_TYPE {
00050     AR_UNKNOWN,
00051     AR_READ,
00052     AR_WRITE,
00053     AR_READWRITE
00054 };
00055 ///
00056 enum RED_OP {
00057     RED_OP_NONE,
00058     RED_OP_PLUS,
00059     RED_OP_MUL,
00060     RED_OP_MIN,
00061     RED_OP_MAX
00062 };
00063 ///
00064 class ProgramUnit;
00065 class Statement;
00066 class Symbol;
00067 ///<class StmtRanges;
00068 class RangeAccessor;
00069 class UGraphIterator;
00070 
00071 #include "Collection/RefList.h"
00072 #include "AccessDimension.h"
00073 #include "Expression/Expression.h"
00074 
00075 class AbstractAccess : public Listable {
00076 
00077     friend class SimGraph;
00078     friend class SimBiGraph;
00079 
00080  protected:
00081     Symbol * _symbol;
00082 
00083     List<AccessDimension> _dims;
00084 
00085     Expression * _start;
00086 
00087     Expression * _correctness;     ///< Correctness condition for this descriptor
00088     int _exec_pred;     ///< index into global repository for execution predicate (from surrounding IF statements)
00089 
00090     ACCURACY _accuracy;
00091 
00092     Expression * _actual;          ///< temporary storage for the actual array reference
00093     Statement * _actual_stmt;      ///< Pointer to the statement where _actual resides.
00094 
00095     bool _read_only, _write_first, _imprecise_sorting, _possible_reduction, _possible_induction, _approximate;
00096 
00097     Statement *  _summarized_to;             ///< DO loop or other statement this access
00098                                          ///< is "summarized to".
00099     ProgramUnit * _pgm_summarized_to;        ///< ProgramUnit of stmt "summarized_to"
00100 
00101     int _diagonal:1,_triangular:1,_subsub:1,_nonaffine:1,_monoton:4,_access_type:3,
00102     _visited:1,_no_overlap:3,_bytesize:6,_reduct_op:4;
00103 
00104     int _nesting_level;             ///< Only through this statement, how many loops is the orig
00105                                 ///< access nested inside?
00106 ///<    RefList<AbstractAccess> _outer; // Pointer to next-outer summarizations of this access
00107 ///<    RefList<AbstractAccess> _inner; // Pointer to next-inner summarizations of this access
00108 
00109  public:
00110     AbstractAccess( );
00111     AbstractAccess( const Symbol & sym, const List<AccessDimension> & dims, Expression * start );
00112     AbstractAccess( const Symbol & sym, const List<AccessDimension> & dims, Expression * start, ACCURACY accu, AR_TYPE artype );
00113     AbstractAccess( const Symbol & sym, const List<AccessDimension> & dims, Expression * start, AbstractAccess * model_aa );
00114     AbstractAccess( const AbstractAccess & other );
00115 
00116     ~AbstractAccess( );
00117 
00118     Symbol & symbol( ) const; ///< Return the symbol whose accesses are represented
00119     virtual Listable *listable_clone() const;
00120 
00121     virtual AbstractAccess *clone() const;
00122 
00123     void relink_eptrs( ProgramUnit & p );
00124 
00125     int byte_size( );           ///< Size of one element in bytes
00126     void byte_size(int bytes);  ///< Set byte size
00127 
00128     void convert_size(int new_size);   ///< Convert the descriptor to a new (smaller) size
00129 
00130 ///<    void range_dict ( StmtRanges * rd );  // Insert the range dictionary
00131 ///<    StmtRanges & range_dict( );   // Return a reference to the range dictionary
00132 
00133 ///<    void create_range_dict ( RangeAccessor & r_acc );
00134     ///< create _range_dict from the ranges in the RangeAccessor
00135 
00136     int sort_add_dim(AccessDimension * newdim, RangeAccessor & range_acc);  ///< Add newdim in its sorted position
00137 
00138     bool coalesce();  ///< Attempt to do the coalesceing operation on the object
00139     bool try_coalescing(RangeAccessor & range_acc, AccessDimension & dim_lo, int lodim,
00140             AccessDimension & dim_hi, int hidim, UGraphIterator & ugi);
00141     ///< try coalescing on two specific dimensions.
00142 
00143      Expression * correctness( );     ///< Return the correctness condition
00144      void correctness(Expression * e );     ///< Set the correctness condition
00145     bool exec_predicate_exists( ) const;          ///< Return whether there is an execution predicate
00146     bool exec_predicate_true( ) const;            ///< Return "true" if predicate does not exist, or exists and is ".TRUE.".
00147     bool exec_predicate_false( ) const;            ///< Return "true" if the predicate exists and is ".FALSE.".
00148     int exec_predicate( );  ///< Return the execution predicate
00149     void exec_predicate( int pred );  ///< Set the execution predicate
00150 
00151     void accuracy( ACCURACY accu );
00152     ACCURACY accuracy ( ) const;
00153 
00154     void add_actual ( Statement *stmt, Expression * expr );  ///< Takes possession of the expression
00155     Expression & actual_guarded ( ) const;
00156     void remove_actual ( );                 ///< delete the actual expression ( to regain space )
00157     Boolean actual_exists ( ) const;
00158     Statement * actual_stmt() const;        ///< return _actual_stmt
00159     int number_of_dimensions( ) const;      ///< Number of dimensions in access 
00160                                             ///< (number_of_dimension_objects minus zero-stride dims)
00161     void check_sort( );                     ///< Check the sorting of dimensions. Set _imprecise_sorting.      
00162 
00163     void add_dimension( const AccessDimension * dim );
00164     void add_dimension( const AccessDimension * dim, int which_dim );
00165     ///< add a new dimension, given by dim
00166 
00167     void del_dimension( int which_dim );
00168     ///< Delete the indicated dimension
00169 
00170     int nesting_level();                 ///< Return nesting level 
00171     void nesting_level( int level );     ///< Set nesting level
00172     void inc_nesting( );                 ///< Increment nesting level
00173 
00174 ///<    RefList<AbstractAccess> & outer( );  // Return list of outer pointers
00175 ///<    RefList<AbstractAccess> & inner( );  // Return list of pointer to next-inner summaries
00176 
00177         ///< compute a new dimension holding at a point in the program,
00178         ///< using expressions as from a DO statement:
00179         ///<    index = lo, hi, by
00180     int compute_new_dimension( ProgramUnit & pgm, Statement & stmt, 
00181                    Symbol & index, 
00182                    Expression & lo, Expression & hi, Expression & by);
00183 
00184     ///< remove the current object from the inner/outer chain and replace with the given object
00185 
00186     AccessDimension & dimension( int i );
00187 
00188     Iterator<AccessDimension> iter_dims( );
00189     
00190     Boolean start_exists( ) const;
00191     void start( Expression * start );
00192     Expression & start_guarded( ) const;
00193 
00194     Expression * lastoffset( ) const;
00195 
00196     Statement * summarized_to();             ///< Retrieve attached statement
00197     void summarized_to( Statement * stmt );  ///< Set attached statement
00198 
00199     ProgramUnit * pgm_summarized_to();             ///< Retrieve attached statement
00200     void pgm_summarized_to( ProgramUnit * stmt );  ///< Set attached statement
00201 
00202     void check_access_patterns( );           ///< Determine whether the access 
00203                                          ///< is triangular or subscripted-subscript 
00204                              ///< interprocedurally
00205      void mark_visited( );                    ///< Mark object visited during traversal
00206      bool was_visited( );                     ///< Return whether visited
00207 
00208      void mark_imprecise( );           ///< Mark that dimension sorting was not precise
00209      void mark_precise( );             ///< Mark that dimension sorting was precise
00210      bool is_imprecise( );             ///< Return whether dim sorting was precise
00211 
00212      void mark_diagonal( );                   ///< Mark object diagonal
00213      void mark_not_diagonal( );               ///< Mark object not diagonal
00214      bool is_diagonal( );                     ///< Return true or false,depending
00215 
00216      void mark_triangular( );                 ///< Mark object triangular
00217      void mark_not_triangular( );             ///< Mark object not triangular
00218      bool is_triangular( );                   ///< Return true or false,depending
00219                                                 ///< on _triangular
00220      void mark_subsub( );                     ///< Mark subscripted subscript
00221      bool is_subsub( );                       ///< Return true or false depending
00222                                                     ///< on _subsub
00223      void mark_nonaffine( );            ///< Mark non-affine
00224      bool is_nonaffine( );                    ///< Return true or false depending
00225                                                     ///< on _nonaffine
00226      void monoton( AR_MONOTON mono );         ///< Set monotonicity
00227      AR_MONOTON monoton( );                   ///< Return monotonicity
00228 
00229      void reduct_op( RED_OP op );      ///< Set the reduction operator
00230      RED_OP reduct_op( );              ///< Get the reduction operator
00231 
00232     AbstractAccess * remap_interface_vars(InlineObject * inline_object, 
00233                       Statement & stmt,
00234                       const Symbol & sym,
00235                       REF_TYPE ref,
00236                       int exec_pred=-1) const;
00237 
00238      bool read_only();    ///< Is the region read-only?
00239      bool write_first();  ///< Was the whole region written first before reading?
00240      bool approximate();  ///< Is this an approximate LMAD?
00241      void set_approximate();  ///< Mark this LMAD as approximate.
00242 
00243      int no_overlap();   ///< Do different iterations of the loop where this 
00244                             ///<  access region is attached cause overlapping access?
00245      bool poss_reduct();  ///< Is this a possible reduction?
00246      bool poss_induct();  ///< Is this a possible induction?
00247 
00248      void read_only  (bool val);  ///< Set the read_only flag
00249      void write_first(bool val);  ///< Set the write_first flag
00250      void no_overlap (bool val);  ///< Set the no_overlap flag
00251      void no_overlap (int val);   ///< Set the no_overlap flag
00252      void poss_reduct(bool val);  ///< Set the possible_reduction flag
00253      void poss_induct(bool val);  ///< Set the possible_induction flag
00254 
00255     void set_check_overlap( int which_dim, bool value );  ///< Set the overlap on the given dimension
00256     void calc_overlap (int which_dim);  ///< Calculate and set the overlap value
00257 
00258     void translate_GSA_symbols( TranslateObject * tobj );
00259     ///< Translate all GSA symbols in the descriptor's expressions to their non-GSA form
00260 
00261 ///<    void store_traversal (RefList<AbstractAccess> & ard_list) const;  
00262     ///< Add ARDs representing a traversal of inner links, starting at this node, to the list
00263 
00264     ///< Functions for matching all or parts of Access Regions
00265     bool match( AbstractAccess * aa );
00266     bool match_by_dims( AbstractAccess * aa );
00267     int  match_dims( AbstractAccess * aa );
00268     int  match_dims_stride( AbstractAccess * aa );
00269     bool match_by_strides( AbstractAccess * aa );
00270     bool match_by_dims_except_1( AbstractAccess * aa );
00271     bool match_by_start_dims_except_1( AbstractAccess * aa );
00272 
00273     ///< This one is to satisfy Listable
00274     virtual void    print(ostream & o) const;
00275 
00276     friend ostream & operator << (ostream & o, const AbstractAccess & aa);
00277 };
00278 
00279 inline Expression *
00280 AbstractAccess::correctness( )
00281 {
00282     return _correctness;
00283 }
00284 
00285 inline void 
00286 AbstractAccess::mark_imprecise( )
00287 {
00288     _imprecise_sorting = true;
00289 }
00290 inline void 
00291 AbstractAccess::mark_precise( )
00292 {
00293     _imprecise_sorting = false;
00294 }
00295 inline bool 
00296 AbstractAccess::is_imprecise( )
00297 {
00298     return _imprecise_sorting;
00299 }
00300 
00301 inline void 
00302 AbstractAccess::mark_subsub( )
00303 {
00304     _subsub = 1;
00305 }
00306 
00307 inline bool
00308 AbstractAccess::is_subsub( )
00309 {
00310     if (_subsub) {
00311     return true;
00312     } else {
00313     return false;
00314     }
00315 }
00316 inline void 
00317 AbstractAccess::mark_nonaffine( )
00318 {
00319     _nonaffine = 1;
00320 }
00321 
00322 inline bool
00323 AbstractAccess::is_nonaffine( )
00324 {
00325     if (_nonaffine) {
00326     return true;
00327     } else {
00328     return false;
00329     }
00330 }
00331 inline void 
00332 AbstractAccess::mark_triangular( )
00333 {
00334     _triangular = 1;
00335 }
00336 
00337 inline void
00338 AbstractAccess::mark_not_triangular( )
00339 {
00340     _triangular = 0;
00341 }
00342 
00343 inline bool
00344 AbstractAccess::is_triangular( )
00345 {
00346     if (_triangular) {
00347     return true;
00348     } else {
00349     return false;
00350     }
00351 }
00352 
00353 inline void 
00354 AbstractAccess::mark_visited( )
00355 {
00356     _visited = 1;
00357 }
00358 
00359 inline bool
00360 AbstractAccess::was_visited( )
00361 {
00362     if (_visited) {
00363     return true;
00364     } else {
00365     return false;
00366     }
00367 }
00368 
00369 inline void 
00370 AbstractAccess::mark_diagonal( )
00371 {
00372     _diagonal = 1;
00373 }
00374 
00375 inline void
00376 AbstractAccess::mark_not_diagonal( )
00377 {
00378     _diagonal = 0;
00379 }
00380 
00381 inline bool
00382 AbstractAccess::is_diagonal( )
00383 {
00384     if (_diagonal) {
00385     return true;
00386     } else {
00387     return false;
00388     }
00389 }
00390 
00391 inline void
00392 AbstractAccess::monoton( AR_MONOTON mono ) 
00393 {
00394     _monoton = mono;
00395 }
00396 
00397 inline AR_MONOTON
00398 AbstractAccess::monoton( )
00399 {
00400     return (AR_MONOTON) _monoton;
00401 }
00402 
00403 inline bool
00404 AbstractAccess:: read_only()
00405 {
00406     return (_read_only == 1);
00407 }
00408 
00409 inline void
00410 AbstractAccess:: set_approximate()
00411 {
00412     _approximate = true;
00413 }
00414 
00415 inline bool
00416 AbstractAccess:: approximate()
00417 {
00418     return _approximate;
00419 }
00420 
00421 inline bool
00422 AbstractAccess:: write_first()
00423 {
00424     return (_write_first == 1);
00425 }
00426 
00427 inline int
00428 AbstractAccess:: no_overlap()
00429 {
00430     return _no_overlap;
00431 }
00432 
00433 inline void
00434 AbstractAccess:: read_only(bool val)
00435 {
00436     _read_only = val;
00437 }
00438 
00439 inline void
00440 AbstractAccess:: write_first(bool val)
00441 {
00442     _write_first = val;
00443 }
00444 
00445 inline void
00446 AbstractAccess:: no_overlap(bool val)
00447 {
00448     if (val) {
00449     _no_overlap = 1;
00450     } else {
00451     _no_overlap = 0;
00452     }
00453 }
00454 
00455 inline void
00456 AbstractAccess:: no_overlap(int val)
00457 {
00458     _no_overlap = val;
00459 }
00460 
00461 
00462 #endif
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:35 2005