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

reaching.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_REACHING_H
00038 #define CBZ_REACHING_H
00039 
00040 //
00041 // reaching.h
00042 //
00043 // This file contains class definitions for solving the reaching
00044 // definitions problem for basic blocks.  The end result of
00045 // reaching definitions analysis is that use of a variable
00046 // defined in a procedure will be annotated with a ud-chain
00047 // giving all of the definitions that reach that use.
00048 
00049 // udChainAnnote is an annotation (i.e., can be inserted into the
00050 // annotations() field of a node) containing a ud-chain.
00051 // Annotations are subclasses of the abstract class Annote.
00052 // an annotation must define the function 
00053 //
00054 //      bool is_annote_kind (string &);
00055 //
00056 // returning true when the identifying string of that kind
00057 // of annotation is passed to it, false otherwise.
00058 // This way the programmer can search the annotation list
00059 // for a node for the particular annotation he or she
00060 // is interested in.  See annote.h for more information 
00061 // about annotations.
00062 //
00063 // Ud-chains are store as a list of statement node pointers.
00064 // If a definition is unambiguous, the stmtNode * of the
00065 // definition itself is stored in the list.  If an ambiguous 
00066 // definition reaches a statement, NULL is used (rather than 
00067 // the empty exprstmtNode* allocated during the reachingGenKillWalker, 
00068 // which has a limited lifetime).  Note that, no matter how many 
00069 // ambiguous definitions reach a statement, only one NULL pointer 
00070 // needs to be stored in the ud-chain.
00071 
00072 class udChainAnnote : public Annote {
00073 
00074 private:
00075         stmt_list _ud_chain;
00076 
00077 public:
00078         udChainAnnote (void) { }
00079 
00080         // return a reference to the ud-chain in this annotation
00081         stmt_list & ud_chain (void) { return _ud_chain; }
00082 
00083         // return true if someone is searching for a ud-chain
00084         bool is_annote_kind (string & s) {
00085                 return s == "ud_chain";
00086         }
00087 
00088         // search a node for a udChainAnnote, returning
00089         // it if it's found, NULL otherwise.
00090         static udChainAnnote * getUdChain (Node *n) {
00091                 annote_list_p a;
00092                 for (a=n->annotations().begin(); 
00093                         a!=n->annotations().end(); a++) {
00094                         string s("ud_chain");
00095                         if ((*a)->is_annote_kind (s))
00096                                 return (udChainAnnote *) *a;
00097                 }
00098                 return NULL;
00099         }
00100 
00101         static void * removeUdChains (Node *n) {
00102                 annote_list_p a;
00103                 for (a=n->annotations().begin(); 
00104                         a!=n->annotations().end(); ) {
00105                         string s("ud_chain");
00106                         if ((*a)->is_annote_kind (s))
00107                                 a = n->annotations().erase (a);
00108                         else
00109                                 a++;
00110                 }
00111                         // EDB
00112                 return NULL;
00113 
00114         }
00115                 
00116 };
00117 
00118 class udChainRemover : public Walker {
00119 public:
00120         udChainRemover (void) : Walker (Preorder, Subtree) { }
00121 
00122         void at_id (idNode *i, Order) {
00123                 if (i->annotations().size())
00124                         udChainAnnote::removeUdChains (i);
00125         }
00126 };
00127 
00128 // reachingDefinitionsWalker does the dataflow analysis for the
00129 // reaching definitions problem, leaving ud-chains (described above)
00130 // at each use of a defined variable in a procedure.  It is (should be)
00131 // designed to be walked from either a procNode, to compute ud-chains
00132 // for one procedure, or from a unitNode, to compute ud-chains for
00133 // every procedure.  Thus, the at_proc() function should re-initialize
00134 // variables global to the class each time it is called.
00135 
00136 class reachingDefinitionsWalker : public Walker {
00137 
00138 public:
00139 
00140         // plain old walker
00141         reachingDefinitionsWalker (void) : Walker (Both, Subtree) { }
00142 
00143         void at_proc (procNode *, Order);
00144         void at_basicblock (basicblockNode *, Order);
00145 
00146 private:
00147         // make ud-chains for each use in this expression
00148         void make_ud_chains (exprNode *);
00149 
00150         // make ud-chains for each use in this statement
00151         void make_ud_chains (stmtNode *);
00152 
00153         // in and out sets for each basic block node
00154         map <basicblockNode *, defFlowVal *> in, out;
00155 
00156         // array of pointers to stmtNode's maps bit positions
00157         // to definitions in the current procedure
00158         stmtNode **num2node;
00159 
00160         // n is the number of definitions in the current procedure
00161         int     n;
00162 
00163         // the current value 
00164         defFlowVal *current_in;
00165 
00166         // maps definitions (stmts) to bit positions
00167         map <stmtNode *, int> node2num; 
00168 
00169         // maps a statement to the variable it defines
00170         map <stmtNode *, declNode *> defines;
00171 
00172         // maps a variable to the definitions
00173         // that (may) affect it
00174         map <declNode *, defFlowVal *> defs;
00175 
00176 };
00177 
00178 #endif // CBZ_REACHING_H

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