Otawa  0.10
ContextualLoopBound.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * ContextualLoopBound class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2008, 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 02110-1301 USA
21  */
22 
23 #ifndef OTAWA_FLOWFACT_CONTEXTUALLOOPBOUND_H_
24 #define OTAWA_FLOWFACT_CONTEXTUALLOOPBOUND_H_
25 
26 #include <otawa/base.h>
27 #include <otawa/properties.h>
28 #include <elm/genstruct/Tree.h>
29 #include <elm/genstruct/Vector.h>
30 
31 namespace otawa {
32 
33 using namespace elm;
34 
35 // ContextPath class
36 template <class T>
37 class ContextPath {
38 public:
39  inline void push(const T& addr) { stack.push(addr); }
40  inline T pop(void) { return stack.pop(); }
41  inline const T& top(void) const { return stack.top(); }
42  inline int count(void) const { return stack.length(); }
43  inline const T& get(int i) const { return stack[stack.length() - i - 1]; }
44  inline const T& operator[](int i) const { return get(i); }
45  inline bool isEmpty(void) const { return stack.isEmpty(); }
46  inline operator bool(void) const { return !isEmpty(); }
47  inline void clear(void) { stack.clear(); }
48 
49 private:
51 };
52 
53 
54 // AmbiguousBoundException class
56 public:
57  inline AmbiguousBoundException(const string& message)
58  : MessageException(message) { }
59 };
60 
61 
62 // ContextualLoopBound class
64 public:
65  static const int undefined = -1;
66 
67  ContextualLoopBound(int max = undefined, int total = undefined);
68 
69  void addMax(const ContextPath<Address>& path, int max)
71  void addTotal(const ContextPath<Address>& path, int total)
73  int findMax(const ContextPath<Address>& path);
74  int findTotal(const ContextPath<Address>& path);
75 
76 private:
77  typedef struct data_t {
78  inline data_t(
79  Address _fun = Address::null,
80  int _max = undefined,
81  int _total = undefined)
82  : fun(_fun), max(_max), total(_total) { }
84  int max, total;
85  } data_t;
87 
89  int lookMax(genstruct::Tree<data_t> *cur);
90  int lookTotal(genstruct::Tree<data_t> *cur);
91  void print(genstruct::Tree<data_t> *cur, int tab = 0);
92 };
93 
94 } // otawa
95 
96 #endif /* OTAWA_FLOWFACT_CONTEXTUALLOOPBOUND_H_ */
data_t(Address _fun=Address::null, int _max=undefined, int _total=undefined)
Definition: ContextualLoopBound.h:78
Address fun
Definition: ContextualLoopBound.h:83
int total
Definition: ContextualLoopBound.h:84
Definition: ContextualLoopBound.h:55
bool isEmpty(void) const
Definition: ContextualLoopBound.h:45
A contextual loop bound is a collection of loop bound (including max iteration and total iteration nu...
Definition: ContextualLoopBound.h:63
const T & operator[](int i) const
Shortcut to get().
Definition: ContextualLoopBound.h:44
T pop(void)
Remove the top call from the call stack.
Definition: ContextualLoopBound.h:40
Definition: ContextualLoopBound.h:77
genstruct::Vector< T > stack
Definition: ContextualLoopBound.h:50
genstruct::Tree< data_t > tree
Definition: ContextualLoopBound.h:86
AmbiguousBoundException(const string &message)
Definition: ContextualLoopBound.h:57
This class is a stack to store call chain in the program call graph.
Definition: ContextualLoopBound.h:37
void push(const T &addr)
Add a call to the call stack (becoming the new top call).
Definition: ContextualLoopBound.h:39
The representation of an address in OTAWA.
Definition: base.h:54
int count(void) const
Get the count of calls in the path.
Definition: ContextualLoopBound.h:42
static Address null
Null address.
Definition: base.h:58
const T & top(void) const
Return the top function call.
Definition: ContextualLoopBound.h:41
intn_t max(intn_t a, intn_t b)
Return the max with a signed comparison.
Definition: clp_analysis.cpp:180
void clear(void)
Definition: ContextualLoopBound.h:47
Definition: features.h:29