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

location.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_LOCATION_H
00038 #define CBZ_LOCATION_H
00039 
00040 #include "allocation.h"
00041 #include "dominators.h"
00042 
00043 // ------------------------------------------------------------
00044 // Location
00045 // ------------------------------------------------------------
00046 
00047 // Dominance testing : Dominance is tested in much the same way it was
00048 // in the previous version: we have a chain of path components, so we
00049 // move up until the two arguments have a common immediate
00050 // parent. Then we call the type-specific dominance test. The only
00051 // complication is when the two paths turn out to be in a direct
00052 // ancestor/descendant relationship. In this case, we allow each type
00053 // to determine what it does in that situation. The cases are based on
00054 // the following rationale:
00055 
00056 // 1. Assignments to the formal parameters are associated with the
00057 // procLocation, and thus must dominate all other statements inside
00058 // the procedure.
00059 //       => ancestor procLocation always dominates descendant
00060 
00061 // 2. Control-flow merges are associated with the basicblockLocation,
00062 // and thus must dominate all other statements within that block.
00063 //       => ancestor basicblockLocation always dominates descendant
00064 
00065 // 3. The assignment of the return value at a callsite, which is
00066 // associated with the stmtLocation, should be dominated by all
00067 // assignments inside the procedure.
00068 //       => ancestor stmtLocation never dominates descendant
00069 
00070 // The rules for descendants are the mirrors of the above rules for
00071 // ancestors.
00072 
00073 //       => descendant stmtLocation only dominates ancestor stmtLocations
00074 //       => descendant basicblockLocation only dominates ancestor stmtLocations
00075 //       => descendant procLocation only dominates ancestor stmtLocations
00076 
00077 // This divides locations into two categories: stmtLocations and
00078 // non-stmtLocation. So we implement all of this logic with a boolean:
00079 // is_stmt.
00080 
00081 class procLocation;
00082 class basicblockLocation;
00083 class stmtLocation;
00084 
00085 class Location : public PerClassHeap< PointersHeap >
00086 {
00087 public:
00088 
00089   typedef enum { Statement, BasicBlock, Procedure } LocationKind;
00090 
00091   static unsigned int stmt_count;
00092   static unsigned int block_count;
00093   static unsigned int proc_count;
00094   static unsigned int dom_calls;
00095 
00096 private:
00097 
00098   Location & operator=(const Location & other)
00099   {
00100     cerr << "ERROR: Cannot assign Location objects" << endl;
00101     return *this;
00102   }
00103 
00104 protected:
00105 
00106   Location * _parent;
00107 
00108   int _depth:16;
00109   int _kind:4;
00110   int _dominates_exit:1;
00111   int _not_basicblock:1;
00112   int _not_procedure:1;
00113 
00114 public:
00115 
00116   Location(Location * parent, LocationKind kind);
00117 
00118   // Fields
00119 
00120   inline int depth() const { return _depth; }
00121   inline LocationKind kind() const { return (LocationKind)_kind; }
00122   inline Location * parent() const { return _parent; }
00123 
00124   inline int dominates_exit() const { return _dominates_exit; }
00125 
00128   static bool dominates(const Location * dom, const Location * cur);
00129 
00132   static bool strictly_dominates(const Location * dom, const Location * cur);
00133 
00136   static Location * common_parent(Location * one,
00137                                   Location * two);
00138 
00141   static procLocation * procedure(Location * where);
00142 
00145   static bool is_prefix(const Location * prefix, const Location * longer);
00146 
00152   virtual void adjust_depth() = 0;
00153  
00154   // Output
00155 
00156   virtual void print(ostream & o) const = 0;
00157   virtual void print_path(ostream & o) const = 0;
00158 
00159   friend ostream & operator<<(ostream & o, const Location & loc) {
00160     loc.print_path(o);
00161     return o;
00162   }
00163 
00164   // Destructor
00165 
00166   virtual ~Location();
00167 
00168   // Stats
00169 
00170   static void stats();
00171 };
00172 
00173 // ------------------------------------------------------------
00174 // stmtLocation
00175 // ------------------------------------------------------------
00176 
00177 class stmtLocation : public Location
00178 {
00179   friend class basicblockLocation;
00180   friend class procLocation;
00181 
00182 private:
00183 
00184   int _stmt_num;
00185   stmtNode * _stmt;
00186   procLocation * _calls;
00187 
00188   inline void stmt_num(int num) { _stmt_num = num; }
00189   inline void stmt(stmtNode * s) { _stmt = s; }
00190 
00191 public:
00192 
00193   stmtLocation(basicblockLocation * parent);
00194 
00201   void setup_call(procNode * proc, bool is_context_insensitive);
00202 
00208   procLocation * remove_call();
00209 
00210   // Fields
00211 
00212   inline basicblockLocation * block_location() const
00213   { return (basicblockLocation *) _parent; }
00214 
00215   inline int stmt_num() const { return _stmt_num; }
00216 
00217   inline stmtNode * stmt() const { return _stmt; }
00218 
00219   inline procLocation * calls() const { return _calls; }
00220 
00221   // Check for the presence of a function call
00222 
00223   bool is_present(const procNode * proc) const;
00224 
00227   virtual void adjust_depth();
00228 
00229   // Output
00230 
00231   virtual void print(ostream & o) const;
00232   virtual void print_path(ostream & o) const;
00233 
00234   // Destructor
00235 
00236   virtual ~stmtLocation();
00237 };
00238 
00239 typedef vector< stmtLocation > stmt_location_vec;
00240 typedef stmt_location_vec::iterator stmt_location_vec_p;
00241 
00242 // ------------------------------------------------------------
00243 // basicblockLocation
00244 // ------------------------------------------------------------
00245 
00246 class basicblockLocation : public Location
00247 {
00248   friend class procLocation;
00249 
00250 private:
00251 
00252   basicblockNode * const _block;
00253   stmt_location_vec _statements;
00254 
00255 public:
00256 
00257   basicblockLocation(procLocation * parent,
00258                      basicblockNode * block);
00259 
00260   // Fields
00261 
00262   inline procLocation * proc_location() const { return (procLocation *) _parent; }
00263   inline basicblockNode * block() const { return _block; }
00264   inline stmt_location_vec & statements() { return _statements; }
00265 
00268   stmtLocation * last() { return & _statements.back(); }
00269 
00272   virtual void adjust_depth();
00273 
00274   // Output
00275 
00276   virtual void print(ostream & o) const;
00277   virtual void print_path(ostream & o) const;
00278 
00279   // Destructor
00280 
00281   virtual ~basicblockLocation();
00282 };
00283 
00284 typedef map< basicblockNode *, basicblockLocation *,
00285               less< basicblockNode * >, basicblock_alloc > basicblock_location_map;
00286 typedef basicblock_location_map::iterator basicblock_location_map_p;
00287 typedef basicblock_location_map::const_iterator basicblock_location_map_cp;
00288 
00289 // ------------------------------------------------------------
00290 // procLocation
00291 // ------------------------------------------------------------
00292 
00293 class procLocation : public Location
00294 {
00295 private:
00296 
00297   procNode * const _proc;
00298   basicblock_location_map _basicblocks;
00299 
00300   static procLocation * Main;
00301 
00302 public:
00303 
00304   procLocation(stmtLocation * parent,
00305                procNode * proc,
00306                bool is_context_insensitive = false);
00307 
00308   // Fields
00309 
00310   inline stmtLocation * stmt_location() const { return (stmtLocation *) _parent; }
00311   inline procNode * proc() const { return _proc; }
00312   basicblockLocation * lookup_block(basicblockNode * block) const;
00313   procLocation * parent_proc() const;
00314 
00315   static inline procLocation * main() { return Main; }
00316 
00317   // -- Get the last statement in the procedure
00318 
00319   stmtLocation * last();
00320 
00326   void remove_from_tree();
00327 
00330   virtual void adjust_depth();
00331 
00332   // Output
00333 
00334   virtual void print(ostream & o) const;
00335   virtual void print_path(ostream & o) const;
00336 
00337   // Destructor
00338 
00339   virtual ~procLocation();
00340 };
00341 
00342 #endif // CBZ_LOCATION_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