Otawa  0.10
WideningListener.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * Listener associated with WideningFixPoint
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
23 
24 #ifndef OTAWA_DFA_HAI_WIDENINGLISTENER_H_
25 #define OTAWA_DFA_HAI_WIDENINGLISTENER_H_
26 
28 #include <otawa/cfg/CFG.h>
29 #include <otawa/cfg/CFGCollector.h>
30 #include <otawa/cfg/BasicBlock.h>
31 #include <otawa/cfg/Edge.h>
32 #include <otawa/prop/PropList.h>
33 #include <elm/genstruct/Vector.h>
34 
35 namespace otawa { namespace dfa { namespace hai {
36 
37 
38 
39 template <class P>
41 
42  public:
43 
44 
45 
46  typedef P Problem;
47 
49 
50  typename Problem::Domain ***results;
51  typename Problem::Domain ***results_out;
52 
53  WideningListener(WorkSpace *_fw, Problem& _prob, bool _store_out = false) : fw(_fw), prob(_prob), store_out(_store_out) {
54  const CFGCollection *col = INVOLVED_CFGS(fw);
55  results = new typename Problem::Domain**[col->count()];
56  if (store_out)
57  results_out = new typename Problem::Domain**[col->count()];
58  for (int i = 0; i < col->count(); i++) {
59  CFG *cfg = col->get(i);
60  results[i] = new typename Problem::Domain*[cfg->countBB()];
61  if (store_out)
62  results_out[i] = new typename Problem::Domain*[cfg->countBB()];
63  for (int j = 0; j < cfg->countBB(); j++){
64  results[i][j] = new typename Problem::Domain(prob.bottom());
65  if (store_out)
66  results_out[i][j] = new typename Problem::Domain(prob.bottom());
67  }
68  }
69  }
70 
72  const CFGCollection *col = INVOLVED_CFGS(fw);
73  for (int i = 0; i < col->count(); i++) {
74  CFG *cfg = col->get(i);
75  for (int j = 0; j < cfg->countBB(); j++){
76  delete results[i][j];
77  if (store_out)
78  delete results_out[i][j];
79  }
80  delete [] results[i];
81  if (store_out)
82  delete [] results_out[i];
83  }
84  delete [] results;
85  if (store_out)
86  delete [] results_out;
87  }
88 
89  void blockInterpreted(const WideningFixPoint< WideningListener > *fp, BasicBlock* bb, const typename Problem::Domain& in, const typename Problem::Domain& out, CFG *cur_cfg, elm::genstruct::Vector<Edge*> *callStack) const;
90 
92 
93  inline Problem& getProb() {
94  return(prob);
95  }
96 
97  private:
100  bool store_out;
101 
102 
103 };
104 
108 template <class Problem >
110 
111 template <class Problem >
112 void WideningListener<Problem>::blockInterpreted(const WideningFixPoint<WideningListener> *fp, BasicBlock* bb, const typename Problem::Domain& in, const typename Problem::Domain& out, CFG *cur_cfg, elm::genstruct::Vector<Edge*> *callStack) const {
113 
114  int bbnumber = bb->number() ;
115  int cfgnumber = cur_cfg->number();
116 
117  prob.lub(*results[cfgnumber][bbnumber], in);
118 
119  if (BB_OUT_STATE(bb) != 0)
120  prob.lub(**BB_OUT_STATE(bb), out);
121 
122  if (store_out)
123  prob.lub(*results_out[cfgnumber][bbnumber], out);
124 #ifdef DEBUG
125  cout << "[TRACE] Block " << bbnumber << ": IN=" << in << " OUT=" << out << "\n";
126 #endif
127 }
128 
129 template <class Problem >
131 }
132 
133 } } } // otawa::dfa::hai
134 
135 #endif // OTAWA_DFA_HAI_WIDENINGLISTENER_H_
WideningListener(WorkSpace *_fw, Problem &_prob, bool _store_out=false)
Definition: WideningListener.h:53
Problem::Domain *** results_out
Definition: WideningListener.h:51
Problem & prob
Definition: WideningListener.h:99
void fixPointReached(const WideningFixPoint< WideningListener > *fp, BasicBlock *bb)
This is called whenever a loop's fixpoint is reached.
Definition: WideningListener.h:130
~WideningListener()
Definition: WideningListener.h:71
Definition: WideningFixPoint.h:44
sys::SystemInStream & in
int number(void)
Definition: CFG.h:111
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
Control Flow Graph representation.
Definition: CFG.h:42
static Identifier< typename Problem::Domain * > BB_OUT_STATE
PRIVATE - DO NOT USE.
Definition: WideningListener.h:48
CFG * get(int index) const
Get a CFG from the collection using its index.
Definition: features.h:51
Problem::Domain *** results
Definition: WideningListener.h:50
WorkSpace * fw
Definition: WideningListener.h:98
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
Contains a collection of CFGs (used with INVOLVED_CFGS property).
Definition: features.h:45
int number(void) const
Get the number hooked on this basic block, that is, value of ID_Index property.
Definition: BasicBlock.h:146
sys::SystemOutStream & out
Identifier< const CFGCollection * > INVOLVED_CFGS
This property is used to link the current computation involved CFG on the framework.
dtd::Element cfg(dtd::make("cfg", _CFG).attr(id).content((entry,*bb, exit,*edge)))
This listener gathers in an array the LUB of the in-states for all analyzed basic blocks...
Definition: WideningListener.h:40
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
int count(void) const
Get the count of CFG in the collection.
Definition: features.h:50
void blockInterpreted(const WideningFixPoint< WideningListener > *fp, BasicBlock *bb, const typename Problem::Domain &in, const typename Problem::Domain &out, CFG *cur_cfg, elm::genstruct::Vector< Edge * > *callStack) const
This is called whenever a block is processed.
Definition: WideningListener.h:112
P Problem
Definition: WideningListener.h:46
io::Output cout
Problem & getProb()
Definition: WideningListener.h:93
bool store_out
Definition: WideningListener.h:100
int countBB(void)
Definition: CFG.h:105