C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ipconstants.h

Go to the documentation of this file.
00001 // $Id: ipconstants.h,v 1.6 2003/08/07 23:14:16 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_IPCONSTANTS_H
00039 #define CBZ_IPCONSTANTS_H
00040 
00041 #include "pointers.h"
00042 #include "ipanalysis.h"
00043 
00044 // ------------------------------------------------------------
00045 // ipConstant
00046 // ------------------------------------------------------------
00047 
00055 class ipConstant : public analysisVal
00056 {
00057   friend class ipConstantPropagation;
00058   friend class ipConstantsChanger;
00059 
00060 private:
00061 
00062   constant _value;
00063   bool _top;
00064   bool _internal;
00065 
00066   ipConstant(constant & value);
00067   ipConstant();
00068   ipConstant(const ipConstant & other);
00069   virtual ~ipConstant();
00070 
00075 
00076   void to_bottom();
00077   bool is_top() const;
00078   bool is_bottom() const;
00079 
00080   inline const constant & value() const { return _value; }
00081   inline constant & value() { return _value; }
00082   
00085 public:
00086 
00087   inline void intern() { _internal = true; }
00088 
00089   void assign(const ipConstant * other);
00090 
00092   virtual bool diff(analysisVal * other) const;
00093 
00094 
00102   virtual void meet_with(const analysisVal * other);
00103 
00108   virtual void binary_operator(const Operator * op,
00109                                const analysisVal * right_operand);
00110 
00111   virtual void unary_operator(const Operator * op);
00112 
00113   virtual void cast_operator(const typeNode * type);
00116 
00117   void print(ostream & o);
00118 
00119 };
00120 
00121 // ------------------------------------------------------------
00122 // ipConstantPropagation
00123 // ------------------------------------------------------------
00124 
00125 typedef map< memoryDef *, ipConstant * > const_variables_map;
00126 typedef const_variables_map::iterator const_variables_map_p;
00127 
00128 typedef map< constNode * , ipConstant * > constants_map;
00129 typedef constants_map::iterator constants_map_p;
00130 
00131 typedef map< declNode * , ipConstant * > enums_map;
00132 typedef enums_map::iterator enums_map_p;
00133 
00134 typedef set< ipConstant * > ipconstant_set;
00135 typedef ipconstant_set::iterator ipconstant_set_p;
00136 
00137 #include "path.h"
00138 
00145 class ipConstantPropagation : public analysisProblem
00146 {
00147 private:
00148 
00149   const_variables_map _values;
00150   constants_map _constants;
00151   enums_map _enums;
00152   ipConstant * _top;
00153   ipConstant * _bottom;
00154   bool _debug;
00155 
00156   ipconstant_set _deleted;
00157   int _count;
00158 
00159 public:
00160 
00161   ipConstantPropagation(bool debug = false)
00162     : _values(),
00163       _constants(),
00164       _top(new ipConstant()),
00165       _bottom(new ipConstant()),
00166       _debug(debug),
00167       _deleted(),
00168       _count(0)
00169   {
00170     _bottom->to_bottom();
00171   }
00172 
00174   virtual bool assignment(const Path * where,
00175                           memoryDef * left_hand_side,
00176                           analysisVal * right_hand_side,
00177                           bool is_strong_update);
00178 
00188   virtual analysisVal * lookup(memoryBlock * block, memoryUse * use);
00189   virtual analysisVal * lookup(constNode * con);
00190   virtual analysisVal * lookup(const string & field_name);
00193 
00194   virtual void free(analysisVal * to_free);
00195 
00200   virtual analysisVal * top();
00201 
00206   virtual analysisVal * bottom();
00207 
00218   virtual analysisVal * binary_operator(const Operator * op,
00219                                         const analysisVal * left_operand,
00220                                         const analysisVal * right_operand);
00221 
00222   virtual analysisVal * unary_operator(const Operator * op,
00223                                        const analysisVal * operand);
00224 
00225   virtual analysisVal * cast_operator(const typeNode * type,
00226                                       const analysisVal * operand);
00227 
00230 
00231   void stats();
00232 
00233 private:
00234 
00235   void allocate(ipConstant * ic) {
00236     _count++;
00237     /*
00238     cout << "Allocate : (" << _count << ") ";
00239     ic->print(cout);
00240     cout << endl;
00241     */
00242   }
00243 
00244   ipConstant * clone(analysisVal * to_clone);
00245 };
00246 
00247 
00248 #endif // CBZ_IPCONSTANTS_H

Generated on August 27, 2003
Back to the C-Breeze home page