Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

memoryaccess.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 //  C-Breeze
00004 //  C Compiler Framework
00005 // 
00006 //  Copyright (c) 2000 University of Texas at Austin
00007 // 
00008 //  Samuel Z. Guyer
00009 //  Daniel A. Jimenez
00010 //  Calvin Lin
00011 // 
00012 //  Permission is hereby granted, free of charge, to any person
00013 //  obtaining a copy of this software and associated documentation
00014 //  files (the "Software"), to deal in the Software without
00015 //  restriction, including without limitation the rights to use, copy,
00016 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00017 //  of the Software, and to permit persons to whom the Software is
00018 //  furnished to do so, subject to the following conditions:
00019 //  
00020 //  The above copyright notice and this permission notice shall be
00021 //  included in all copies or substantial portions of the Software.
00022 //  
00023 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00024 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00025 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00026 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00027 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00028 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00029 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00030 //  THE SOFTWARE.
00031 //
00032 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00033 //  Computer Science for inspiring parts of the C-Breeze design.
00034 //
00035 // ----------------------------------------------------------------------
00036 
00037 #ifndef CBZ_MEMORYACCESS_H
00038 #define CBZ_MEMORYACCESS_H
00039 
00040 #include <set>
00041 #include "location.h"
00042 
00043 class memoryBlock;
00044 
00045 typedef set< memoryBlock *,
00046              less< memoryBlock * >, memoryblock_alloc > memoryblock_set;
00047 typedef memoryblock_set::iterator memoryblock_set_p;
00048 typedef memoryblock_set::const_iterator memoryblock_set_cp;
00049 
00050 class memoryDef;
00051 
00052 typedef list< memoryDef *, memorydef_alloc > memorydef_list;
00053 typedef memorydef_list::iterator memorydef_list_p;
00054 typedef memorydef_list::const_iterator memorydef_list_cp;
00055 
00056 typedef set< memoryDef *, less< memoryDef *>, memorydef_alloc > memorydef_set;
00057 typedef memorydef_set::iterator memorydef_set_p;
00058 typedef memorydef_set::const_iterator memorydef_set_cp;
00059 
00060 class memoryUse;
00061 
00062 typedef list< memoryUse *, memoryuse_alloc > memoryuse_list;
00063 typedef memoryuse_list::iterator memoryuse_list_p;
00064 typedef memoryuse_list::const_iterator memoryuse_list_cp;
00065 
00066 typedef set< memoryUse *, less< memoryUse *>, memoryuse_alloc > memoryuse_set;
00067 typedef memoryuse_set::iterator memoryuse_set_p;
00068 
00069 // ------------------------------------------------------------
00070 // memoryAccess
00071 // ------------------------------------------------------------
00072 
00073 // Common base class for both defs and uses
00074 
00075 class memoryAccess : public PerClassHeap< PointersHeap >
00076 {
00077 public:
00078 
00079   static bool Verbose;
00080   static unsigned int def_count;
00081   static unsigned int use_count;
00082   static unsigned int merge_use_count;
00083 
00084   static void stats();
00085 
00086 private:
00087 
00088   Location * _where;
00089   bool _is_weak;
00090   bool _is_additive;
00091 
00092 public:
00093 
00094   // --- Constructor
00095 
00096   memoryAccess(Location * where);
00097 
00098   // --- Fields
00099 
00100   inline Location * where() const { return _where; }
00101 
00102   inline bool is_weak() const { return _is_weak; }
00103   inline void set_weak(bool is) { _is_weak = is; }
00104 
00105   inline bool is_additive() const { return _is_additive; }
00106   inline void set_additive() { _is_additive = true; }
00107 };
00108 
00109 typedef set< memoryAccess * > memoryaccess_set;
00110 typedef memoryaccess_set::iterator memoryaccess_set_p;
00111 typedef memoryaccess_set::const_iterator memoryaccess_set_cp;
00112 
00113 // ------------------------------------------------------------
00114 // memoryDef
00115 // ------------------------------------------------------------
00116 
00117 // A memoryDef represents a single definition of (assignment to) a
00118 // particular memoryBlock. It records the place where the def occured,
00119 // and the object deing modified. In addition, it is used to record
00120 // the points-to values of any pointer objects.
00121 
00122 class memoryDef : public memoryAccess
00123 {
00124 private:
00125 
00126   memoryuse_list _uses;
00127   memoryblock_set _points_to;
00128   memoryBlock * const _owner;
00129 
00130   memoryDef * _previous;
00131 
00132 public:
00133 
00134   // --- Constructor
00135 
00136   memoryDef(Location * where, memoryBlock * owner);
00137 
00138   // --- Destructor
00139 
00140   ~memoryDef();
00141 
00142   // --- Fields
00143 
00144   inline memoryuse_list & uses() { return _uses; }
00145   inline const memoryblock_set & points_to() const { return _points_to; }
00146   inline memoryBlock * owner() const { return _owner; }
00147 
00148   inline memoryDef * previous() const { return _previous; }
00149   inline void previous(memoryDef * previous_def) { _previous = previous_def; }
00150 
00151   // --- Manipulate the points-to function
00152 
00153   void add_pointers(const memoryblock_set & mbs);
00154   void clear_points_to();
00155 
00156   // --- Output
00157 
00158   void print(ostream & o) const;
00159 };
00160 
00161 // ------------------------------------------------------------
00162 // orderedDefs
00163 // ------------------------------------------------------------
00164 
00165 // An orderedDef object holds a sequence of memoryDefs in dominating
00166 // order (a particular def always comes before the defs that dominate
00167 // it).
00168 
00169 class orderedUses;
00170 
00171 class orderedDefs
00172 {
00173 private:
00174 
00175   memorydef_list _defs;
00176 
00177 public:
00178 
00179   orderedDefs()
00180     : _defs()
00181   {}
00182 
00183   // --- Find the memoryDef for a given program location
00184 
00185   memoryDef * find_def(Location * where) const;
00186 
00187   // --- Find the nearest strictly dominating memoryDef (use this to
00188   // find the reaching definition for a regular use.
00189 
00190   memoryDef * find_strictly_dominating_def(Location * where) const;
00191 
00192   // --- Find the nearest dominating memoryDef (use this to find the
00193   // reaching definition for a merge-point use.
00194 
00195   memoryDef * find_dominating_def(Location * where) const;
00196 
00197   // --- Add a new memoryDef in the proper place, and return a
00198   // reference to it. If there is already an entry for the given path,
00199   // just return that memoryDef.
00200 
00201   memoryDef * make_def_at(Location * where, memoryBlock * owner, bool & is_new);
00202 
00203   // --- Prune out unnecessary defs
00204 
00205   void prune(orderedUses & Uses);
00206 
00207   // --- Output
00208 
00209   void print(ostream & o) const;
00210 
00211   // --- Clear
00212 
00213   void clear();
00214 
00215   // --- Size
00216 
00217   int size() const { return _defs.size(); }
00218 };
00219 
00220 // ------------------------------------------------------------
00221 // memoryUse
00222 // ------------------------------------------------------------
00223 
00224 // A memoryUse represents a single use of the memoryBlock. It points
00225 // to the reaching definition (from the orderedDefs list). For merges
00226 // (phi functions) we create one for each of the control-flow
00227 // predecessors.
00228 
00229 class memoryUse : public memoryAccess
00230 {
00231 private:
00232 
00233   memoryDef * _reaching_def;
00234   bool _search_for_def;
00235 
00236 public:
00237 
00238   // --- Constructor
00239 
00240   memoryUse(Location * where);
00241 
00242   // --- Destructor
00243 
00244   ~memoryUse();
00245 
00246   // --- Fields
00247 
00248   memoryDef * reaching_def() const { return _reaching_def; }
00249   void reaching_def(memoryDef * def);
00250 
00251   inline bool search_for_def() const { return _search_for_def; }
00252   inline void search_for_def(bool val) { _search_for_def = val; }
00253 
00254   // --- Output
00255 
00256   void print(ostream & o) const;
00257 };
00258 
00259 
00260 typedef map< Location *, memoryUse *,
00261              less< Location * >, location_alloc > memoryuse_map;
00262 typedef memoryuse_map::iterator memoryuse_map_p;
00263 typedef memoryuse_map::const_iterator memoryuse_map_cp;
00264 typedef memoryuse_map::value_type memoryuse_map_pair;
00265 
00266 typedef map< basicblockNode *, memoryUse *,
00267              less< basicblockNode * >, basicblock_alloc> pred_use_map;
00268 typedef pred_use_map::iterator pred_use_map_p;
00269 typedef pred_use_map::const_iterator pred_use_map_cp;
00270 
00271 typedef map< Location *, pred_use_map,
00272              less< Location * >, location_alloc > merge_use_map;
00273 typedef merge_use_map::iterator merge_use_map_p;
00274 typedef merge_use_map::const_iterator merge_use_map_cp;
00275 
00276 // ------------------------------------------------------------
00277 // orderedUses
00278 // ------------------------------------------------------------
00279 
00280 class orderedUses
00281 {
00282 private:
00283 
00284   memoryuse_map _uses;
00285   merge_use_map _merge_uses;
00286   
00287 public:
00288 
00289   orderedUses()
00290     : _uses(),
00291       _merge_uses()
00292   {}
00293 
00294   // --- Find an existing use for the given location (doesn't work for
00295   // merge/phi functions).
00296 
00297   memoryUse * find_use(Location * where) const;
00298 
00299   // --- Add a new use for the given location, or return the existing
00300   // one.
00301 
00302   memoryUse * make_use_at(Location * where);
00303 
00304   // --- Add a new set of uses for a particular merge point: one use
00305   // for each control-flow predecessor, with the reaching definitions
00306   // set appropriately.
00307 
00308   const pred_use_map & make_merge_uses_at(basicblockLocation * where);
00309 
00310   // --- Update the def-use chains (only performed once at the end of
00311   // analysis by the memoryModel).
00312 
00313   void update_def_use_chains();
00314 
00315   // --- Prune uses for a particular location
00316 
00317   void prune(Location * where);
00318 
00319   // --- Output
00320 
00321   void print(ostream & o) const;
00322 
00323   // --- Clear
00324 
00325   void clear();
00326 };
00327 
00328 #endif // CBZ_MEMORYACCESS_H
00329 

Generated on Thu Jan 10 12:06:19 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001