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_LIVE_H
00038 #define CBZ_LIVE_H
00039
00041 // live.h
00042 //
00043
00044 // string is not the best choice to identify a variable. I'd like to
00045 // have something like a uniqe address in a symbol table somewhere, to
00046 // avoid confusing two variables with the same name
00047 // (e.g. int foo () { { int a; } { int a; } } )
00048 // whatever var_id turns out to be, it'll have to have a == operator.
00049
00050 typedef declSetFlowVal liveFlowVal;
00051
00052 class liveFlowProblem: public FlowProblem {
00053 private:
00054
00055 procNode *proc;
00056 declNode **decls;
00057 map <var_id, int> *name2num;
00058 int flowsize;
00059
00060 public:
00061 liveFlowProblem (int n, map<var_id,int> *m, declNode **vars) :
00062 decls(vars),
00063 name2num(m),
00064 flowsize(n),
00065 FlowProblem(false, new liveFlowVal (n, m, vars)) { }
00066
00067 ~liveFlowProblem (void) { }
00068 void flow_node (FlowVal *, Node *, Point);
00069 void flow_block (FlowVal *, blockNode *, Point);
00070 void dan_iterate (procNode *p);
00071 };
00072
00073 class liveAnnote: public Annote {
00074 decl_list _live_vars;
00075
00076 public:
00077
00078 static liveAnnote * getLiveAnnote(basicblockNode *b) {
00079 string live("liveness");
00080 for (annote_list_p i=b->annotations().begin();
00081 i!=b->annotations().end(); i++) {
00082 if ((*i)->is_annote_kind (live))
00083 return (liveAnnote *) *i;
00084 }
00085 return NULL;
00086 }
00087
00088 static void removeliveness (basicblockNode *b) {
00089 string live("liveness");
00090 for (annote_list_p i=b->annotations().begin();
00091 i!=b->annotations().end(); ) {
00092 if ((*i)->is_annote_kind (live)) {
00093 // this deletes the liveness annotation
00094 delete *i;
00095 i = b->annotations().erase (i);
00096 }
00097 else
00098 i++;
00099 }
00100 }
00101
00102 liveAnnote (decl_list l) : _live_vars (l) { }
00103
00104 liveAnnote (void) { }
00105
00106 decl_list & live_vars (void) { return _live_vars; }
00107 void live_vars (decl_list l) { _live_vars = l; }
00108
00109 bool is_annote_kind (string & name) {
00110 return name == "liveness";
00111 }
00112 };
00113
00114 class livenessRemover : public Walker {
00115 public:
00116
00117 livenessRemover (void) : Walker (Preorder, Subtree) { }
00118
00119 void at_basicblock (basicblockNode *b, Order) {
00120 if (b->annotations().size())
00121 liveAnnote::removeliveness (b);
00122 }
00123 };
00124
00125 class livenessWalker: public Walker {
00126 public:
00127 livenessWalker(): Walker (Preorder, Subtree) {}
00128
00129 void at_proc (procNode *, Order);
00130 };
00131
00132
00133 #endif // CBZ_LIVE_H
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001