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

ipconstants.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_IPCONSTANTS_H
00038 #define CBZ_IPCONSTANTS_H
00039 
00040 #include "pointers.h"
00041 #include "ipanalysis.h"
00042 
00043 // ------------------------------------------------------------
00044 // ipConstant
00045 // ------------------------------------------------------------
00046 
00047 // This class represents a single constant value associated with one
00048 // def of a variable. It can hold either a constant value, or have the
00049 // special lattice TOP value. The lattice BOTTOM is represented by a
00050 // constant no_val (which is built into the constant class).
00051 
00052 class ipConstant : public analysisVal
00053 {
00054   friend class ipConstantPropagation;
00055   friend class ipConstantsChanger;
00056 
00057 private:
00058 
00059   constant _value;
00060   bool _top;
00061   bool _internal;
00062 
00063   ipConstant(constant & value);
00064   ipConstant();
00065   ipConstant(const ipConstant & other);
00066   virtual ~ipConstant();
00067 
00068   // -- Fields
00069 
00070   void to_bottom();
00071   bool is_top() const;
00072   bool is_bottom() const;
00073 
00074   inline const constant & value() const { return _value; }
00075   inline constant & value() { return _value; }
00076 
00077 public:
00078 
00079   inline void intern() { _internal = true; }
00080 
00081   void assign(const ipConstant * other);
00082 
00083   // -- Comparison
00084 
00085   virtual bool diff(analysisVal * other) const;
00086 
00087   // -- Meet "^" operator
00088   // Must satisfy the following:
00089   //    Associative: x ^ (y ^ z) = (x ^ y) ^ z
00090   //    Commutative: x ^ y = y ^ x
00091   //    Idempotent:  x ^ x = x
00092 
00093   virtual void meet_with(const analysisVal * other);
00094 
00095   // -- Computational functions
00096 
00097   virtual void binary_operator(const Operator * op,
00098                                const analysisVal * right_operand);
00099 
00100   virtual void unary_operator(const Operator * op);
00101 
00102   virtual void cast_operator(const typeNode * type);
00103 
00104   // -- Output
00105 
00106   void print(ostream & o);
00107 
00108 };
00109 
00110 // ------------------------------------------------------------
00111 // ipConstantPropagation
00112 // ------------------------------------------------------------
00113 
00114 // This class controls the constant propagation algorithm by holding
00115 // the current states of all objects, looking them up when needed, and
00116 // setting their values at assignments.
00117 
00118 typedef map< memoryDef *, ipConstant * > const_variables_map;
00119 typedef const_variables_map::iterator const_variables_map_p;
00120 
00121 typedef map< constNode * , ipConstant * > constants_map;
00122 typedef constants_map::iterator constants_map_p;
00123 
00124 typedef map< declNode * , ipConstant * > enums_map;
00125 typedef enums_map::iterator enums_map_p;
00126 
00127 typedef set< ipConstant * > ipconstant_set;
00128 typedef ipconstant_set::iterator ipconstant_set_p;
00129 
00130 #include "path.h"
00131 
00132 class ipConstantPropagation : public analysisProblem
00133 {
00134 private:
00135 
00136   const_variables_map _values;
00137   constants_map _constants;
00138   enums_map _enums;
00139   ipConstant * _top;
00140   ipConstant * _bottom;
00141   bool _debug;
00142 
00143   ipconstant_set _deleted;
00144   int _count;
00145 
00146 public:
00147 
00148   ipConstantPropagation(bool debug = false)
00149     : _values(),
00150       _constants(),
00151       _top(new ipConstant()),
00152       _bottom(new ipConstant()),
00153       _debug(debug),
00154       _deleted(),
00155       _count(0)
00156   {
00157     _bottom->to_bottom();
00158   }
00159 
00160   // -- Process an assignment; return true if the state of the defined
00161   // object changes.
00162 
00163   virtual bool assignment(const Path * where,
00164                           memoryDef * left_hand_side,
00165                           analysisVal * right_hand_side,
00166                           bool is_strong_update);
00167 
00168   // -- Lookup the flow value for an object
00169   // IMPORTANT:
00170 
00171   // 1. Return a *copy* of any internal data structures because these
00172   // analysisVal objects will be deleted.
00173 
00174   // 2. If the given object cannot be found, return 0 and the analyzer
00175   // will automatically use BOTTOM.
00176 
00177   virtual analysisVal * lookup(memoryBlock * block, memoryUse * use);
00178   virtual analysisVal * lookup(constNode * con);
00179   virtual analysisVal * lookup(const string & field_name);
00180 
00181   // -- Free: must be able to accept 0 as an argument
00182 
00183   virtual void free(analysisVal * to_free);
00184 
00185   // -- Return a *COPY* of the TOP flow value
00186   // Must satisfy : x ^ T = x
00187 
00188   virtual analysisVal * top();
00189 
00190   // -- Return a *COPY* the BOTTOM flow value
00191   // Must satisfy : x ^ B = B
00192 
00193   virtual analysisVal * bottom();
00194 
00195   // -- Computational functions: produce a new analysisVal or
00196   // transform one of the input vals according to the given
00197   // operator. DO NOT DELETE any of the inputs (this is handled
00198   // automatically). Optionally, return 0 to indicate a bad
00199   // computation.
00200 
00201   virtual analysisVal * binary_operator(const Operator * op,
00202                                         const analysisVal * left_operand,
00203                                         const analysisVal * right_operand);
00204 
00205   virtual analysisVal * unary_operator(const Operator * op,
00206                                        const analysisVal * operand);
00207 
00208   virtual analysisVal * cast_operator(const typeNode * type,
00209                                       const analysisVal * operand);
00210 
00211   // -- Print some statistics
00212 
00213   void stats();
00214 
00215 private:
00216 
00217   void allocate(ipConstant * ic) {
00218     _count++;
00219     /*
00220     cout << "Allocate : (" << _count << ") ";
00221     ic->print(cout);
00222     cout << endl;
00223     */
00224   }
00225 
00226   ipConstant * clone(analysisVal * to_clone);
00227 };
00228 
00229 
00230 #endif // CBZ_IPCONSTANTS_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