C-Breeze
C Compiler Infrastructure

[ Project home page]

path.h

Go to the documentation of this file.
00001 // $Id: path.h,v 1.4 2003/08/07 23:14:27 pnav Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2000 University of Texas at Austin
00008 // 
00009 //  Samuel Z. Guyer
00010 //  Daniel A. Jimenez
00011 //  Calvin Lin
00012 // 
00013 //  Permission is hereby granted, free of charge, to any person
00014 //  obtaining a copy of this software and associated documentation
00015 //  files (the "Software"), to deal in the Software without
00016 //  restriction, including without limitation the rights to use, copy,
00017 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00018 //  of the Software, and to permit persons to whom the Software is
00019 //  furnished to do so, subject to the following conditions:
00020 //  
00021 //  The above copyright notice and this permission notice shall be
00022 //  included in all copies or substantial portions of the Software.
00023 //  
00024 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00028 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00029 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00030 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00031 //  THE SOFTWARE.
00032 //
00033 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00034 //  Computer Science for inspiring parts of the C-Breeze design.
00035 //
00036 // ----------------------------------------------------------------------
00037 
00038 #ifndef CBZ_PATH_H
00039 #define CBZ_PATH_H
00040 
00041 #include "location.h"
00042 
00043 class Path;
00044 
00045 // ------------------------------------------------------------
00046 // PathDB
00047 // ------------------------------------------------------------
00048 
00049 // Store the paths in a multi-map from parent to children
00050 
00051 typedef multimap< const Path *, const Path * > path_map;
00052 typedef path_map::iterator path_map_p;
00053 typedef path_map::const_iterator path_map_cp;
00054 typedef pair< const Path *, const Path * > path_map_pair;
00055 
00056 class PathDB
00057 {
00058 private:
00059 
00060   path_map _paths;
00061 
00062 public:
00063 
00064   PathDB();
00065 
00066   // --- Add a path to the database, eliminating duplicates and
00067   // sharing structure wherever possible.
00068 
00069   const Path * intern(const Path * con);
00070 
00071   // --- Look up a path, without creating a new entry. If the
00072   // path doesn't exist in the database, then it returns null.
00073 
00074   const Path * lookup(const Path * con);
00075 
00076   // --- Equality and dominance tests
00077 
00078   static bool equals(const Path * one, const Path * two);
00079   static bool dominates(const Path * dom, const Path * cur);
00080   static bool strictly_dominates(const Path * dom, const Path * cur);
00081 
00082   // --- Print some statistics
00083 
00084   void stats();
00085 
00086   // --- Output
00087 
00088   void print(ostream & o) const;
00089 
00090   friend ostream& operator<<(ostream & o, const PathDB & cdb) {
00091     cdb.print(o);
00092     return o;
00093   }
00094 };
00095 
00096 // ------------------------------------------------------------
00097 // Path
00098 // ------------------------------------------------------------
00099 
00100 // A path is a chain of Locations. We use the PathDB class to
00101 // allow "interning" of paths so that common components of the
00102 // chain are shared. This also makes other comparisons more efficient
00103 // because two identical paths will have the same pointer value.
00104 
00105 // The PathDB passed into the constructors always interns the
00106 // parent pointer. This maintains the invariant that all components of
00107 // a path chain are interned, with the one exception of the
00108 // last. This exception is primarily for performance: we don't want to
00109 // end up with every single program position in the database.
00110 
00111 class Path : public Location
00112 {
00113   friend class PathDB;
00114 
00115 private:
00116 
00117   const Path * _parent;
00118   int _depth;
00119   // int _refs;
00120   bool _dominates_exit;
00121   PathDB * _db;
00122 
00123   // --- Private default constructor
00124 
00125   Path();
00126 
00127   static const Path * Always;
00128 
00129 public:
00130 
00131   // --- Constructor: build a new path by "pushing" a new procedure
00132   // on the end. The parent is automatically interned.
00133 
00134   Path(PathDB * db, const Path * parent,
00135        procNode * callee);
00136 
00137   Path(PathDB * db, const Path * parent,
00138        procNode * callee, basicblockNode * block);
00139 
00140   Path(PathDB * db, const Path * parent,
00141        const Location & loc);
00142 
00143   // --- Copy a path: this is useful for modifying one that has
00144   // been interned (and thus cannot be modified!).
00145 
00146   Path(const Path & other);
00147 
00148   // --- Destructor
00149 
00150   ~Path();
00151 
00152   // --- Fields
00153 
00154   inline const Path * parent() const { return _parent; }
00155   inline int depth() const { return _depth; }
00156   inline bool dominates_exit() const { return _dominates_exit; }
00157 
00158   // --- Useful query functions
00159 
00160   bool is_recursive() const;
00161   bool is_proc_present(procNode * proc) const;
00162   bool is_always() const { return this == Always; }
00163 
00164   // --- The special "Always" path
00165 
00166   static const Path * always() { return Always; }
00167 
00168   // --- Output
00169 
00170   void print_shallow(ostream & o) const {
00171     if (is_always())
00172       o << "Always";
00173     else
00174       print(o);
00175   }
00176 
00177   void print_deep(ostream & o) const {
00178     print_shallow(o);
00179     if (parent()) {
00180       o << ":";
00181       parent()->print_deep(o);
00182     }
00183   }
00184 
00185   friend ostream& operator<<(ostream & o, const Path & c) {
00186     c.print_deep(o);
00187     return o;
00188   }
00189 
00190 private:
00191 
00192   // void inc_refs() { _refs++; }
00193   // void dec_refs() { _refs--; }
00194 
00195 };
00196 
00197 #endif // 

Generated on February 1, 2006
Back to the C-Breeze home page