Otawa  0.10
PSTBuilder.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * Copyright (c) 2007, IRIT UPS <casse@irit.fr>
4  *
5  * Program Structure Tree Builder
6  * This file is part of OTAWA
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 Foobar; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #ifndef CACHE_PSTBUILDER_H_
24 #define CACHE_PSTBUILDER_H_
25 
26 #include <elm/assert.h>
27 #include <elm/util/Pair.h>
28 #include <elm/genstruct/DLList.h>
29 #include <elm/genstruct/Tree.h>
30 
32 #include <otawa/prog/WorkSpace.h>
33 #include <otawa/cfg/CFG.h>
34 #include <otawa/cfg/BasicBlock.h>
35 
36 namespace otawa {
37 
38 
39 /*
40  * This represents a Cycle-Equivalence class: two edges are cycle-equivalent if each cycle passing thru an edge also passes thru the other.
41  * (two edges are also cycle-equivalent if no cycle passes through the edges)
42  */
43 class CEClass {
44 
45  int count; // number of edges in this class
46  bool first;
47 
48  Edge *backEdge; // backEdge associated with the class, if any. There is at most 1 backEdge per class (and at least 0).
49 
50  public:
51 
52  // Constructors
53  inline CEClass(void) : count(0), first(true), backEdge(NULL) {
54  }
55 
56  // Account for tree edges in this class
57  inline void inc(void) {
58  count++;
59  }
60 
61  // Account for the backedge of this class, verifying that it is counted only once.
62  inline void inc(Edge *bracket) {
63  // Two back-edges cannot be cycle-equivalent.
64  ASSERT((backEdge == NULL) || (backEdge == bracket));
65  if (backEdge == NULL)
66  count++;
67  backEdge = bracket;
68  }
69  inline void dec(void) {
70  count--;
71  first = false;
72  }
73 
74  inline bool isLast(void) {
75  return (count == 1);
76  }
77 
78  inline bool isFirst(void) {
79  return first;
80  }
81 
82  inline int getCount(void) {
83  return(count);
84  }
85 
86  // Accessors
87 
88 };
89 
90 class SESERegion;
91 
92 class SESERegion : public PropList {
93 
94 
95 
98  CFG *cfg;
101  bool first,last;
103 
104  public:
105 
106  class BBIterator: public elm::genstruct::Vector<BasicBlock*>::Iterator {
107  public:
108 
109 
110  inline BBIterator(Vector<BasicBlock*> &_vec) : elm::genstruct::Vector<BasicBlock*>::Iterator(_vec){
111 
112  }
113  inline BBIterator(SESERegion *region) : elm::genstruct::Vector<BasicBlock*>::Iterator(region->bbs){
114 
115  }
116  };
117  inline SESERegion(CFG *_cfg, Edge *_entry, PSTree *_parent, bool _first, CEClass *_class) : entry(_entry), exit(NULL), cfg(_cfg),parent(_parent), first(_first), last(false), classe (_class) {
118  }
119 
120  inline SESERegion(CFG *_cfg) : entry(NULL), exit(NULL), cfg(_cfg), parent(NULL), classe(NULL) {
121  BasicBlock::OutIterator outedge(cfg->entry());
122  entry = *outedge;
123 
124  BasicBlock::InIterator inedge(cfg->exit());
125  exit = *inedge;
126  }
127 
128  inline PSTree *getParent() {
129  return parent;
130  }
131 
132  inline int countBB() {
133  return(bbs.length());
134  }
135  inline void addBB(BasicBlock *_bb) {
136  bbs.add(_bb);
137  }
138  inline void setExit(Edge *_exit) {
139  exit = _exit;
140  }
141  inline void print() {
142  cout << "Region: " << getEntry()->source()->number() << "->" << getEntry()->target()->number();
143  if (getExit() != NULL) {
144  cout << " to " << getExit()->source()->number() << "->" << getExit()->target()->number() ;
145  } else cout << " to ???";
146  }
147  inline Edge* getEntry() {
148  return(entry);
149  }
150  inline Edge* getExit() {
151  return(exit);
152  }
153  inline void setLast() {
154  last = true;
155  }
156  inline bool isFirst() {
157  return first;
158  }
159  CFG *getCFG() {
160  return cfg;
161  }
163  return bbs;
164  }
165  inline bool isLast() {
166  return last;
167  }
168  inline bool isRoot() {
169  return (parent == NULL);
170  }
171  inline CEClass *getClass() {
172  return classe;
173  }
174 
175 };
176 
177 
178 
180 
181  // Types
184 
185 
186 
187 
188  // Properties
192 
196 
199 
200 
201  // Private members
205 
207 
208  // Private methods
210  void assignClasses(CFG *cfg);
211  void buildTree(CFG *cfg, BasicBlock *bb, PSTree *subtree);
212 
213  public:
214  PSTBuilder(void);
215  virtual void processCFG(WorkSpace *, CFG*);
217  static int displayTree(PSTree *node, int col = 0, bool ending = false);
218 
219 };
220 
221 }
222 
223 #endif /*CACHE_PSTBUILDER_H_*/
const Vector< BasicBlock * > & getBBs()
Definition: PSTBuilder.h:162
CFG * cfg(void) const
Get the current CFG.
Definition: CFGProcessor.h:56
void assignClasses(CFG *cfg)
Using the DFS number on each BB and the backedge identification, assign Cycle-Equivalent Classes to t...
Definition: cfg_PSTBuilder.cpp:262
CEClass(void)
Definition: PSTBuilder.h:53
bool first
Definition: PSTBuilder.h:46
BasicBlock * source(void) const
Definition: Edge.h:52
static VirtualCFG * getVCFG(PSTree *tree, HashTable< BasicBlock *, BasicBlock * > &map)
Return a VCFG of the basic blocks represented by the region.
Definition: cfg_PSTBuilder.cpp:426
bool isFirst(void)
Definition: PSTBuilder.h:78
void setLast()
Definition: PSTBuilder.h:153
static Identifier< int > PST_HI
Definition: PSTBuilder.h:190
static int displayTree(PSTree *node, int col=0, bool ending=false)
Display the PST.
Definition: cfg_PSTBuilder.cpp:143
static Identifier< int > PST_DFSNUM
Definition: PSTBuilder.h:189
PSTBuilder(void)
Definition: cfg_PSTBuilder.cpp:105
static Identifier< CEClass * > PST_RECENTCLASS
Definition: PSTBuilder.h:195
bool isLast(void)
Definition: PSTBuilder.h:74
Edge * entry
Definition: PSTBuilder.h:96
void inc(Edge *bracket)
Definition: PSTBuilder.h:62
Vector< BasicBlock * > bbs
Definition: PSTBuilder.h:100
void print()
Definition: PSTBuilder.h:141
CEClass * classe
Definition: PSTBuilder.h:102
BasicBlock * entry(void)
Get the entry basic block of the CFG.
Definition: CFG.h:63
void buildTree(CFG *cfg, BasicBlock *bb, PSTree *subtree)
Using the Cycle-Equivalent informations on the edges, recursively build the PST.
Definition: cfg_PSTBuilder.cpp:173
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
Definition: PSTBuilder.h:106
Control Flow Graph representation.
Definition: CFG.h:42
CFG * cfg
Definition: PSTBuilder.h:98
CFG * getCFG()
Definition: PSTBuilder.h:159
BasicBlock * exit(void)
Get the exit basic block of the CFG.
Definition: CFG.h:65
Edge * fakeEdge
Definition: PSTBuilder.h:204
void dec(void)
Definition: PSTBuilder.h:69
SESERegion(CFG *_cfg, Edge *_entry, PSTree *_parent, bool _first, CEClass *_class)
Definition: PSTBuilder.h:117
bool last
Definition: PSTBuilder.h:101
static Identifier< bool > DFS_IS_BACKEDGE
Definition: PSTBuilder.h:198
Definition: PSTBuilder.h:92
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
Edge * backEdge
Definition: PSTBuilder.h:48
BBIterator(Vector< BasicBlock * > &_vec)
Definition: PSTBuilder.h:110
This is a specialization of the processor class dedicated to CFG processing.
Definition: CFGProcessor.h:35
Definition: BasicBlock.h:165
int number(void) const
Get the number hooked on this basic block, that is, value of ID_Index property.
Definition: BasicBlock.h:146
void inc(void)
Definition: PSTBuilder.h:57
Edge * getEntry()
Definition: PSTBuilder.h:147
int countBB()
Definition: PSTBuilder.h:132
PSTree * parent
Definition: PSTBuilder.h:99
Definition: PSTBuilder.h:43
A virtual CFG is a CFG not-mapped to real code, that is, it may contains virtual nodes for inlining f...
Definition: VirtualCFG.h:29
Definition: BasicBlock.h:160
BBIterator(SESERegion *region)
Definition: PSTBuilder.h:113
static Identifier< BracketSet * > PST_BSET
Definition: PSTBuilder.h:191
bool isFirst()
Definition: PSTBuilder.h:156
This class represents edges in the CFG representation.
Definition: Edge.h:33
BasicBlock * target(void) const
Definition: Edge.h:53
virtual void processCFG(WorkSpace *, CFG *)
Definition: cfg_PSTBuilder.cpp:112
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
CEClass * getClass()
Definition: PSTBuilder.h:171
This processor computes the Program Structure Tree of the CFG.
Definition: PSTBuilder.h:179
static Identifier< int > PST_RECENTSIZE
Definition: PSTBuilder.h:194
Edge * getExit()
Definition: PSTBuilder.h:150
void depthFirstSearch(BasicBlock *bb)
Do a depth-first search on the undirected version of the CFG assign the DFS number on each basic bloc...
Definition: cfg_PSTBuilder.cpp:235
PSTree * pst
Definition: PSTBuilder.h:206
int getCount(void)
Definition: PSTBuilder.h:82
This a list of properties.
Definition: PropList.h:63
Edge * exit
Definition: PSTBuilder.h:97
elm::Pair< Edge *, int > BSCName
Definition: PSTBuilder.h:182
elm::genstruct::DLList< Edge * > BracketSet
Definition: PSTBuilder.h:183
void setExit(Edge *_exit)
Definition: PSTBuilder.h:138
io::Output cout
void addBB(BasicBlock *_bb)
Definition: PSTBuilder.h:135
bool first
Definition: PSTBuilder.h:101
static Identifier< bool > PST_IS_CAPPING
Definition: PSTBuilder.h:197
bool isLast()
Definition: PSTBuilder.h:165
bool isRoot()
Definition: PSTBuilder.h:168
int cur_dfsnum
Definition: PSTBuilder.h:202
PSTree * getParent()
Definition: PSTBuilder.h:128
SESERegion(CFG *_cfg)
Definition: PSTBuilder.h:120
static Identifier< CEClass * > PST_CLASS
Definition: PSTBuilder.h:193
int count
Definition: PSTBuilder.h:45
BasicBlock ** node
Definition: PSTBuilder.h:203
Definition: features.h:29