Polaris: AccessDimension.cc Source File

AccessDimension.cc

Go to the documentation of this file.
00001 ///
00002 /// \file AccessDimension.cc
00003 ///
00004 ///
00005 #ifdef POLARIS_GNU_PRAGMAS
00006 #pragma implementation
00007 #endif
00008 ///
00009 #include "AccessDimension.h"
00010 #include "Traverser.h"
00011 #include "utilities/gsa_util.h"
00012 #include "InlineObject.h"
00013 #include "ProgramUnit.h"
00014 
00015 AccessDimension::AccessDimension( ) {
00016     #ifdef CLASS_INSTANCE_REGISTRY
00017     register_instance(ACCESS_DIMENSION, sizeof(AccessDimension), this);
00018     #endif
00019 
00020     _stride = NULL;
00021     _span   = NULL;
00022     _accuracy = ACCU_UNKNOWN;
00023     _check_overlap = false;
00024 }
00025 
00026 /// We take ownership of the stride and span expressions
00027 
00028 AccessDimension::AccessDimension( Expression * stride, 
00029                   Expression * span ) 
00030 {
00031     #ifdef CLASS_INSTANCE_REGISTRY
00032     register_instance(ACCESS_DIMENSION, sizeof(AccessDimension), this);
00033     #endif
00034 
00035   _stride = stride;
00036   _span   = span;
00037   _index = 0;
00038 
00039   _check_overlap = false;
00040   _accuracy = ACCU_EXACT;
00041   _singleton = false;
00042 }
00043 
00044 /// We take ownership of the stride and span expressions
00045 
00046 AccessDimension::AccessDimension( Expression * stride, 
00047                   Expression * span,
00048                   ACCURACY acc) {
00049     #ifdef CLASS_INSTANCE_REGISTRY
00050     register_instance(ACCESS_DIMENSION, sizeof(AccessDimension), this);
00051     #endif
00052 
00053     _stride = stride;
00054     _span   = span;
00055     _index = 0;
00056 
00057     _accuracy = acc;
00058     _check_overlap = false;
00059     _singleton = false;
00060 }
00061 
00062 /// We take ownership of the stride and span expressions
00063 
00064 AccessDimension::AccessDimension(Expression * stride, 
00065                  Expression * span,
00066                  ACCURACY acc,
00067                  Monotonicity  * mono) {
00068     #ifdef CLASS_INSTANCE_REGISTRY
00069     register_instance(ACCESS_DIMENSION, sizeof(AccessDimension), this);
00070     #endif
00071 
00072     _stride = stride;
00073     _span   = span;
00074     _index = 0;
00075 
00076     _check_overlap = false;
00077     _accuracy = acc;
00078     _mono = *mono;
00079     delete mono;
00080     _singleton = false;
00081 }
00082 
00083 AccessDimension::AccessDimension( const AccessDimension & other ) {
00084     #ifdef CLASS_INSTANCE_REGISTRY
00085     register_instance(ACCESS_DIMENSION, sizeof(AccessDimension), this);
00086     #endif
00087 
00088     if (other._stride) {
00089     _stride = other._stride->clone();
00090     } else {
00091     _stride = NULL;
00092     }
00093     if (other._span) {
00094     _span = other._span->clone();
00095     } else {
00096     _span = NULL;
00097     }
00098     _check_overlap = other._check_overlap;
00099     _index = other._index;
00100     _accuracy = other._accuracy;
00101     _mono = other._mono;
00102     _singleton = other._singleton;
00103 }
00104 
00105 AccessDimension::~AccessDimension( ) {
00106     #ifdef CLASS_INSTANCE_REGISTRY
00107     unregister_instance(ACCESS_DIMENSION, this);
00108     #endif
00109 
00110     if (_stride) {
00111     delete _stride;
00112     }
00113     if (_span) {
00114     delete _span;
00115     }
00116 }
00117 
00118 Symbol * 
00119 AccessDimension::index( ) {
00120     return _index;
00121 }
00122 
00123 void 
00124 AccessDimension::index( Symbol * index) {
00125     _index = index;
00126 }
00127 
00128 Expression &
00129 AccessDimension::stride_guarded( ) const {
00130     p_assert(_stride, "AccessDimension: stride does not exist");
00131     return (Expression &) *_stride;
00132 }
00133 
00134 Expression &
00135 AccessDimension::span_guarded( ) const {
00136     p_assert(_span, "AccessDimension: span does not exist");
00137     return (Expression &) *_span;
00138 }
00139 
00140 void
00141 AccessDimension::accuracy ( ACCURACY acc ) {
00142     _accuracy = acc;
00143 }
00144 
00145 ACCURACY
00146 AccessDimension::accuracy ( ) const {
00147     return _accuracy;
00148 }
00149 
00150 Boolean
00151 AccessDimension::stride_exists( ) const {
00152     if (_stride) {
00153     return True;
00154     } else {
00155     return False;
00156     }
00157 }
00158 
00159 Boolean
00160 AccessDimension::span_exists( ) const {
00161     if (_span) {
00162     return True;
00163     } else {
00164     return False;
00165     }
00166 }
00167 
00168 AccessDimension *
00169 AccessDimension::remap_interface_vars( InlineObject * inl_obj, REF_TYPE ref ) const
00170 {
00171     Expression * new_stride = 0;
00172     Expression * new_span   = 0;
00173 
00174     if (this->stride_exists()) {
00175     new_stride = this->stride_guarded().clone();
00176     }
00177 
00178     if (this->span_exists()) {
00179     new_span = this->span_guarded().clone();
00180     }
00181 
00182     if (new_stride) {
00183     new_stride = trans_update_expr(inl_obj, new_stride);
00184     }
00185 
00186     if (new_span) {
00187     new_span = trans_update_expr(inl_obj, new_span);
00188     }
00189 
00190     AccessDimension * new_ad = new AccessDimension(new_stride, 
00191                            new_span,
00192                            this->accuracy(),
00193                            this->monotonicity().clone());
00194 
00195     if (_index) {
00196     VariableSymbol * trsym = inl_obj->translate_symbol( *_index );
00197     if (!trsym) {
00198         Symbol & newsym = trans_update_symbol(inl_obj, *(VariableSymbol *)_index);
00199         new_ad->_index = &newsym;
00200     } else {
00201         new_ad->_index = trsym;
00202     }
00203     }
00204 
00205     if (_singleton) {
00206     new_ad->_singleton = true;
00207     }
00208 
00209     return new_ad;
00210 }
00211 
00212 AccessDimension * 
00213 AccessDimension::clone( ) const {
00214     return new AccessDimension( *this );
00215 }
00216     
00217 Listable *
00218 AccessDimension::listable_clone() const
00219 {
00220     return (Listable *) clone();
00221 }
00222 
00223 void 
00224 AccessDimension::relink_eptrs( ProgramUnit & p ) {
00225     if (_stride) {
00226     _stride->relink_eptrs( p );
00227     }
00228     if (_span) {
00229     _span->relink_eptrs( p );
00230     }
00231 }
00232 
00233 /// We take ownership of the stride expression:
00234 
00235 void 
00236 AccessDimension::stride( Expression * stride ) {
00237     p_assert(stride, "stride: NULL expression address");    
00238 
00239     if (_stride) {
00240     delete _stride;
00241     }
00242 
00243     _stride = stride;
00244 }
00245 
00246 /// We take ownership of the span expression:
00247 
00248 void 
00249 AccessDimension::span( Expression * span ) {
00250     p_assert(span, "span: NULL expression address");    
00251 
00252     if (_span) {
00253     delete _span;
00254     }
00255 
00256     _span = span;
00257 }
00258 
00259 void
00260 AccessDimension::monotonicity ( Monotonicity mon )
00261 {
00262     _mono = mon;
00263 }
00264 
00265 Monotonicity 
00266 AccessDimension::monotonicity( ) const
00267 {
00268     return _mono;
00269 }
00270 
00271 void
00272 AccessDimension::translate_GSA_symbols ( TranslateObject * tobj )
00273 {
00274     _stride = tobj->translate_GSA_refs_expr(_stride);
00275     _span   = tobj->translate_GSA_refs_expr(_span);
00276 
00277     VariableSymbol * newsym = tobj->translate_symbol( *_index );
00278 
00279     if (newsym) {
00280     _index = newsym;
00281     }
00282 }
00283 
00284 void
00285 AccessDimension::print( ostream & o ) const {
00286     if (_stride) {
00287     o << "{Stride= " << *_stride;
00288     } else {
00289     o << "No stride";
00290     }
00291     if (_span) {
00292     o << ", Span= " << *_span ;
00293     } else {
00294     o << ", No span";
00295     }
00296 
00297     switch (_accuracy) {
00298     case ACCU_UNKNOWN: o << "[ACCU_UNKNOWN]";  break;
00299     case ACCU_EXACT:   o << "[ACCU_EXACT]";    break;
00300     case ACCU_SUPERSET:o << "[ACCU_SUPERSET]"; break;
00301     case ACCU_SUBSET:  o << "[ACCU_SUBSET]";   break;
00302     default:           o << "[ACCU_BAD VALUE]";break;
00303     }
00304 
00305     o << " {Monotonicity: " << _mono << "}";
00306 
00307     if (_singleton) {
00308     o << "-Singleton";
00309     }
00310 
00311     o << "}";
00312 }
00313 
00314 ostream & 
00315 operator << (ostream & o, const AccessDimension & ad) 
00316 {
00317     ad.print(o);
00318     return o;
00319 }
00320 
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:36 2005