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

memoryblock.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_MEMORYBLOCK_H
00038 #define CBZ_MEMORYBLOCK_H
00039 
00040 #include "pointers_common.h"
00041 #include "location.h"
00042 #include "memoryaccess.h"
00043 
00044 #include <set>
00045 
00046 // ------------------------------------------------------------
00047 //  Memory block
00048 
00049 // Each object in memory that may be a pointer, or pointed to is
00050 // represented by a memoryBlock. 
00051 
00052 class memoryBlock;
00053 
00054 typedef list< memoryBlock * > memoryblock_list;
00055 typedef memoryblock_list::iterator memoryblock_list_p;
00056 
00057 typedef map< int, memoryBlock *, less< int > > component_map;
00058 typedef component_map::iterator component_map_p;
00059 typedef component_map::const_iterator component_map_cp;
00060 
00061 class memoryBlock : public PerClassHeap< PointersHeap >
00062 {
00063 private:
00064 
00067   REF const memoryBlock * _container;
00068 
00076 
00077   TREE orderedDefs Defs;
00078   TREE orderedUses Uses;
00079 
00081 
00088   REF memoryUse * _current_use;
00089 
00099   REF memoryDef * _current_def;
00100 
00103   component_map  _components;
00104 
00110   declNode * _decl;
00111 
00118   bool _synthetic_decl;
00119 
00126   procNode * _local_to;
00127 
00134   bool _multiplicity;
00135 
00141   bool _write_protected;
00142 
00147   bool _is_array;
00148 
00156   memoryDef * _initializer_def;
00157 
00158 private:
00159 
00160   friend class memoryModel;
00161 
00168   memoryBlock(declNode * decl, bool synthetic,
00169               memoryBlock * container,
00170               procNode * local_to = 0);
00171 
00177   ~memoryBlock();
00178 
00179 public:
00180 
00185   void clear();
00186 
00187   // --- Data members
00188 
00189   declNode * decl() const { return _decl; }
00190   procNode * local_to() const { return _local_to; }
00191 
00192   bool multiplicity() const { return _multiplicity; }
00193   void set_multiplicity() { _multiplicity = true; }
00194 
00195   bool write_protected() const { return _write_protected; }
00196   void set_write_protected() { _write_protected = true; }
00197 
00198   memoryUse * current_use() const { return _current_use; }
00199   memoryDef * current_def() const { return _current_def; }
00200 
00201   void reset_current_def_use(Location * unused);
00202   void set_current_def_use(Location * where);
00203 
00204   // --- Manage uses and defs
00205 
00206   memoryDef * def_at(Location * where, bool & is_new);
00207   memoryDef * nearest_def_at(Location * where);
00208   memoryUse * use_at(Location * where);
00209   memoryDef * last_def_at(basicblockLocation * block);
00210   memoryDef * find_def_at(Location * where);
00211 
00212   void set_current_to_nearest_def_at(Location * where);
00213 
00214   void setup_merge_uses_at(basicblockLocation * merge_location,
00215                            memoryDef * reaching_def,
00216                            basicblock_set & predecessors);
00217 
00218   void merge_uses_at(basicblockLocation * where,
00219                      memoryuse_list & uses,
00220                      bool computePointers);
00221 
00222   // --- Conservative 
00223 
00224   void reachable_blocks(Location * where,
00225                         memoryblock_list & worklist,
00226                         memoryblock_set & already_seen,
00227                         memoryBlock * null);
00228 
00229   // --- Prune out unneeded uses and defs
00230 
00231   void prune_defs_uses();
00232 
00233   // --- Manage structure fields
00234 
00235   void dot(const string & field_name,
00236            declNode * field_decl,
00237            memoryModel & Memory,
00238            memoryblock_set & results);
00239 
00240   // --- Handle special array objects
00241 
00242   bool is_array() const { return _is_array; }
00243 
00244   void set_array_element(memoryBlock * element);
00245 
00246   memoryBlock * get_array_element();
00247 
00248   memoryDef * setup_array_def();
00249 
00250   // --- Scoping
00251 
00252   bool in_scope(basicblockLocation * where) const;
00253 
00254   // --- Output
00255 
00256   friend ostream& operator<<(ostream & o, const memoryBlock & mb) {
00257     // mb.print(o, Path::always());
00258     return o;
00259   }
00260 
00261   // --- Pass after = true to see the points-to information after the
00262   // given statement has been executed.
00263 
00264   typedef enum { NAME_ONLY, CURRENT_VALUE, AFTER_ASSIGNMENT, ALL_VALUES } Output_mode;
00265 
00266   void print(ostream & o, Location * path, Output_mode mode = CURRENT_VALUE) const;
00267   string name() const;
00268 
00269   void print_def_use(ostream & o) const;
00270 
00271   // --- Update the def-use chains (only performed once at the end of
00272   // analysis by the memoryModel).
00273 
00274   void update_def_use_chains();
00275 
00276   // --- Statistics
00277 
00278   static void stats();
00279   int num_defs() const { return Defs.size(); }
00280   
00281 private:
00282 
00283   //  Structure field-name database
00284 
00285   // Since the number of possible field names is small, we keep them in
00286   // a database and then refer to them by number in the memoryBlock class.
00287 
00288   class FieldNameDB
00289   {
00290   private:
00291 
00292     typedef map< string, int, less< string > > field_name_map;
00293     typedef field_name_map::iterator field_name_map_p;
00294 
00295     field_name_map _fields;
00296     int _count;
00297 
00298   public:
00299 
00300     static int ArrayField;
00301 
00302     FieldNameDB()
00303       : _fields(),
00304         _count(0)
00305     {}
00306 
00307     // --- Get the index for a field name, create if needed
00308 
00309     int get_field(const string & name);
00310 
00311     // --- Reverse search: find the name for a particular index
00312 
00313     string field_name(int index);
00314   };
00315 
00316   static FieldNameDB FieldNames;
00317 };
00318 
00319 
00320 #endif // CBZ_MEMORYBLOCK_H

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