SuspensionAutomata.cpp 29.3 KB
Newer Older
Anirudh Kaushik's avatar
Anirudh Kaushik committed
1
2
#include "SuspensionAutomata.h"
#include "FindArgument.h"
Jimmy Lu's avatar
Jimmy Lu committed
3
4
5

#include <algorithm>

Anirudh Kaushik's avatar
Anirudh Kaushik committed
6
7
using namespace scpar;

rmrf's avatar
rmrf committed
8
9
10
SusCFG::SusCFG(CFGBlock *block)
    : _block(block), _parentCFGBlock(NULL), _parentSusCFGBlock(NULL),
      _isWaitBlock(false), _isParentBlock(false), _isGPUFit(false) {}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
11

rmrf's avatar
rmrf committed
12
SusCFG::~SusCFG() {}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
13

rmrf's avatar
rmrf committed
14
void SusCFG::addParentBlock(CFGBlock *parentBlock) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
15
16
17
  _parentCFGBlock = parentBlock;
}

rmrf's avatar
rmrf committed
18
void SusCFG::addParentBlock(SusCFG *parentBlock) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
19
20
21
  _parentSusCFGBlock = parentBlock;
}

rmrf's avatar
rmrf committed
22
void SusCFG::addPredBlocks(SusCFG *block) { _predBlocks.push_back(block); }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
23

rmrf's avatar
rmrf committed
24
void SusCFG::addSuccBlocks(SusCFG *block) { _succBlocks.push_back(block); }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
25

rmrf's avatar
rmrf committed
26
void SusCFG::addGPUFit() { _isGPUFit = true; }
Anirudh's avatar
Anirudh committed
27

rmrf's avatar
rmrf committed
28
void SusCFG::denyGPUFit() { _isGPUFit = false; }
Anirudh's avatar
Anirudh committed
29

rmrf's avatar
rmrf committed
30
void SusCFG::addChildBlockList(SusCFG *block) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
31
32
33
  _childBlockList.push_back(block);
}

rmrf's avatar
rmrf committed
34
void SusCFG::addChildBlockList(vector<SusCFG *> blockList) {
35
  for (unsigned int i = 0; i < blockList.size(); i++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
36
37
38
39
    _childBlockList.push_back(blockList.at(i));
  }
}

rmrf's avatar
rmrf committed
40
void SusCFG::setWaitBlock() { _isWaitBlock = true; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
41

rmrf's avatar
rmrf committed
42
void SusCFG::setParentBlock() { _isParentBlock = true; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
43

rmrf's avatar
rmrf committed
44
void SusCFG::setWaitStmt(Stmt *stmt) { _waitStmt = stmt; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
45

rmrf's avatar
rmrf committed
46
vector<SusCFG *> SusCFG::getChildBlockList() { return _childBlockList; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
47

rmrf's avatar
rmrf committed
48
vector<SusCFG *> SusCFG::getPredBlocks() { return _predBlocks; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
49

rmrf's avatar
rmrf committed
50
vector<SusCFG *> SusCFG::getSuccBlocks() { return _succBlocks; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
51

rmrf's avatar
rmrf committed
52
unsigned int SusCFG::getBlockID() { return _block->getBlockID(); }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
53

rmrf's avatar
rmrf committed
54
bool SusCFG::isWaitBlock() { return _isWaitBlock; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
55

rmrf's avatar
rmrf committed
56
bool SusCFG::isParentBlock() { return _isParentBlock; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
57

rmrf's avatar
rmrf committed
58
bool SusCFG::isGPUFit() { return _isGPUFit; }
Anirudh's avatar
Anirudh committed
59

rmrf's avatar
rmrf committed
60
unsigned int SusCFG::getParentBlockID() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
61
62
63
64
65
66
67
  if (_parentCFGBlock) {
    return _parentCFGBlock->getBlockID();
  } else {
    return 0;
  }
}

rmrf's avatar
rmrf committed
68
CFGBlock *SusCFG::getBlock() { return _block; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
69

rmrf's avatar
rmrf committed
70
CFGBlock *SusCFG::getParentCFGBlock() { return _parentCFGBlock; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
71

rmrf's avatar
rmrf committed
72
SusCFG *SusCFG::getParentSusCFGBlock() { return _parentSusCFGBlock; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
73

rmrf's avatar
rmrf committed
74
Stmt *SusCFG::getWaitStmt() { return _waitStmt; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
75
76

////////////////////////////////////////////////////////////////////////////////////////
rmrf's avatar
rmrf committed
77
78
79
80
State::State(SusCFG *susCFG, bool isTimed, bool isDelta, bool isInitial,
             bool isEvent)
    : _susCFGBlock(susCFG), _isTimed(isTimed), _isDelta(isDelta),
      _isInitial(isInitial), _isEvent(isEvent) {}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
81

rmrf's avatar
rmrf committed
82
State::~State() { delete _susCFGBlock; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
83

rmrf's avatar
rmrf committed
84
bool State::isTimed() { return _isTimed; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
85

rmrf's avatar
rmrf committed
86
bool State::isDelta() { return _isDelta; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
87

rmrf's avatar
rmrf committed
88
bool State::isEvent() { return _isEvent; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
89

rmrf's avatar
rmrf committed
90
bool State::isInitial() { return _isInitial; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
91

rmrf's avatar
rmrf committed
92
void State::setInitial() { _isInitial = true; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
93

rmrf's avatar
rmrf committed
94
void State::setTimed() { _isTimed = true; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
95

rmrf's avatar
rmrf committed
96
void State::setEvent() { _isEvent = true; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
97

rmrf's avatar
rmrf committed
98
void State::setDelta() { _isDelta = true; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
99

rmrf's avatar
rmrf committed
100
void State::addEventName(string eventName) { _eventName = eventName; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
101

rmrf's avatar
rmrf committed
102
void State::addSimTime(float simTime) { _timeInNS = simTime; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
103

rmrf's avatar
rmrf committed
104
string State::getEventName() { return _eventName; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
105

rmrf's avatar
rmrf committed
106
float State::getSimTime() { return _timeInNS; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
107

rmrf's avatar
rmrf committed
108
SusCFG *State::returnSusCFGBlock() { return _susCFGBlock; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
109
110

////////////////////////////////////////////////////////////////////////////////////////
rmrf's avatar
rmrf committed
111
Transition::Transition() : _initialState(NULL), _finalState(NULL) {}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
112

rmrf's avatar
rmrf committed
113
Transition::~Transition() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
114
115
116
117
  delete _initialState;
  delete _finalState;
}

rmrf's avatar
rmrf committed
118
void Transition::addInstanceId(int instanceId) { _instanceId = instanceId; }
Anirudh's avatar
Anirudh committed
119

rmrf's avatar
rmrf committed
120
void Transition::addInitialState(State *state) { _initialState = state; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
121

rmrf's avatar
rmrf committed
122
void Transition::addFinalState(State *state) { _finalState = state; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
123

rmrf's avatar
rmrf committed
124
void Transition::addCodeBlocks(SusCFG *susCFG) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
125
126
127
  _codeBlockVector.push_back(susCFG);
}

rmrf's avatar
rmrf committed
128
void Transition::addCodeBlocks(vector<SusCFG *> susCFG) {
129
  for (unsigned int i = 0; i < susCFG.size(); i++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
130
131
132
133
    _codeBlockVector.push_back(susCFG.at(i));
  }
}

rmrf's avatar
rmrf committed
134
int Transition::returnInstanceId() { return _instanceId; }
Anirudh's avatar
Anirudh committed
135

rmrf's avatar
rmrf committed
136
State *Transition::returnInitialState() { return _initialState; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
137

rmrf's avatar
rmrf committed
138
State *Transition::returnFinalState() { return _finalState; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
139

rmrf's avatar
rmrf committed
140
vector<SusCFG *> Transition::returnCodeBlocks() { return _codeBlockVector; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
141

rmrf's avatar
rmrf committed
142
void Transition::dump(raw_ostream &os) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
143
  os << "\n ####### Transition #######";
rmrf's avatar
rmrf committed
144
145
  os << "\n Initial State : "
     << _initialState->returnSusCFGBlock()->getBlockID();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
146
147
  os << "\n Final State : " << _finalState->returnSusCFGBlock()->getBlockID();
  os << "\n Transition Blocks : ";
148
  for (unsigned int i = 0; i < _codeBlockVector.size(); i++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
149
150
151
152
153
    os << _codeBlockVector.at(i)->getBlockID() << " ";
  }
}

////////////////////////////////////////////////////////////////////////////////////////
rmrf's avatar
rmrf committed
154
155
156
157
158
SuspensionAutomata::SuspensionAutomata(vector<WaitContainer *> waitCalls,
                                       CXXMethodDecl *d, ASTContext *a,
                                       raw_ostream &os)
    : _d(d), _a(a), _os(os) {

159
160
  for (std::size_t i {0}; i < waitCalls.size(); i++) {
    WaitContainer *wc {waitCalls.at(i)}; 
rmrf's avatar
rmrf committed
161
162
    _waitCalls.push_back(wc->getASTNode());
  }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
163
164
}

rmrf's avatar
rmrf committed
165
SuspensionAutomata::~SuspensionAutomata() {}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
166

rmrf's avatar
rmrf committed
167
168
bool SuspensionAutomata::initialize() {
  const CFG::BuildOptions &b = CFG::BuildOptions();
169

rmrf's avatar
rmrf committed
170
  _cfg = CFG::buildCFG(cast<Decl>(_d), _d->getBody(), _a, b);
Anirudh Kaushik's avatar
Anirudh Kaushik committed
171

172
173
174
175
176
  if (_cfg != NULL) {
    return true;
  }

  return false;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
177
178
}

rmrf's avatar
rmrf committed
179
bool SuspensionAutomata::isWaitCall(const CFGStmt *cs) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
180
181
  bool f = false;

rmrf's avatar
rmrf committed
182
  Stmt *s = const_cast<Stmt *>(cs->getStmt());
Anirudh Kaushik's avatar
Anirudh Kaushik committed
183

rmrf's avatar
rmrf committed
184
  CXXMemberCallExpr *m = dyn_cast<CXXMemberCallExpr>(s);
Anirudh Kaushik's avatar
Anirudh Kaushik committed
185
186
187
188

  if (!m) {
    return f;
  }
189
190
  for (std::size_t i {0}; i < _waitCalls.size(); i++) {
    CallExpr *ce {_waitCalls.at(i)};
Anirudh Kaushik's avatar
Anirudh Kaushik committed
191
192
193
194
    if (m == ce) {
      f = true;
    }
  }
rmrf's avatar
rmrf committed
195
196
197
198
199
200
201
202
  /*
    for (EntryFunctionContainer::waitContainerListType::iterator it =
        _waitCalls.begin(), eit = _waitCalls.end(); it != eit; ++it)
      WaitContainer *w = (*it);
      if (m == w->getASTNode()) {
        f = true;
      }
   */
Anirudh Kaushik's avatar
Anirudh Kaushik committed
203
204
205
206
  return f;
}

/*************************************************************************
rmrf's avatar
rmrf committed
207
Description : Locates the suspension points in the CFG and
Anirudh Kaushik's avatar
Anirudh Kaushik committed
208
209
creates new CFG blocks that isolates the suspension statements from the code.
*************************************************************************/
rmrf's avatar
rmrf committed
210
void SuspensionAutomata::genSusCFG() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
211
212
213
214
215
216

  LangOptions LO;

  LO.CPlusPlus = true;
  PrintingPolicy Policy(LO);

rmrf's avatar
rmrf committed
217
218
219
220
  vector<Optional<CFGStmt>> pre;
  vector<unsigned int> waitBlockIDVector;
  vector<const CFGBlock *> CFGBlockVector;
  ;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
221

rmrf's avatar
rmrf committed
222
223
  typedef map<CFGBlock *, SusCFG *> susCFGBlockMapType;
  typedef pair<CFGBlock *, SusCFG *> susCFGBlockPairType;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
224
225
226

  susCFGBlockMapType susCFGBlockMap;

227
  bool isFirstCFGBlockID = false;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
228

rmrf's avatar
rmrf committed
229
230
  for (CFG::iterator it = _cfg->end() - 1, eit = _cfg->begin(); it != eit;
       --it) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
231
232
233
234

    const CFGBlock *b = *it;
    SusCFG *currBlock;

rmrf's avatar
rmrf committed
235
    if (susCFGBlockMap.find(const_cast<CFGBlock *>(b)) ==
Anirudh Kaushik's avatar
Anirudh Kaushik committed
236
        susCFGBlockMap.end()) {
rmrf's avatar
rmrf committed
237
238
239
      currBlock = new SusCFG(const_cast<CFGBlock *>(b));
      susCFGBlockMap.insert(
          susCFGBlockPairType(const_cast<CFGBlock *>(b), currBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
240
241
    } else {
      susCFGBlockMapType::iterator susCFGBlockFound =
rmrf's avatar
rmrf committed
242
          susCFGBlockMap.find(const_cast<CFGBlock *>(b));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
243
244
245
246
247
      currBlock = susCFGBlockFound->second;
    }

    bool foundWait = false;

rmrf's avatar
rmrf committed
248
249
    vector<CFGBlock *> splitBlocksVector;
    /*
Anirudh Kaushik's avatar
Anirudh Kaushik committed
250
251
252
    _os << "==========================================================\n";
    _os << "Dump CFG Block\n";
    b->dump(_cfg, LO, false);
Anirudh's avatar
Anirudh committed
253
    */
254
    unsigned int prevCFGBlockID;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
255
256
257

    for (CFGBlock::const_iterator bit = b->begin(), bite = b->end();
         bit != bite; bit++) {
rmrf's avatar
rmrf committed
258
259
      if (Optional<CFGStmt> cs = bit->getAs<CFGStmt>()) {
        const CFGStmt *s = (CFGStmt const *)&cs;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
260
261
262
263
264
265
266

        if (isWaitCall(s)) {

          foundWait = true;
          CFGBlock *newSplitBlock = _cfg->createBlock();

          for (unsigned int i = 0; i < pre.size(); i++) {
rmrf's avatar
rmrf committed
267
            newSplitBlock->appendStmt(const_cast<Stmt *>(pre.at(i)->getStmt()),
Anirudh Kaushik's avatar
Anirudh Kaushik committed
268
269
270
271
272
                                      _cfg->getBumpVectorContext());
          }

          CFGBlock *waitBlock = _cfg->createBlock();

rmrf's avatar
rmrf committed
273
          waitBlock->appendStmt(const_cast<Stmt *>(cs->getStmt()),
Anirudh Kaushik's avatar
Anirudh Kaushik committed
274
                                _cfg->getBumpVectorContext());
rmrf's avatar
rmrf committed
275
          waitBlock->setLabel(const_cast<Stmt *>(cs->getStmt()));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
276
277
278
279
280
281
282
283
284
          splitBlocksVector.push_back(newSplitBlock);
          splitBlocksVector.push_back(waitBlock);
          pre.clear();

        } else {
          pre.push_back(cs);
        }
      }
    }
rmrf's avatar
rmrf committed
285
    // pre.clear();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
286
287
288
289
290
291
292

    if (foundWait) {

      currBlock->setParentBlock();
      CFGBlock *prev = NULL;
      SusCFG *prevBlock = NULL;

293
      for (std::size_t i = 0; i < splitBlocksVector.size(); i++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
294
        CFGBlock *current = splitBlocksVector.at(i);
295
        SusCFG *splitBlock =
rmrf's avatar
rmrf committed
296
            new SusCFG(const_cast<CFGBlock *>(splitBlocksVector.at(i)));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
297
298
299
300
301
302
303
304
        currBlock->addChildBlockList(splitBlock);
        if (current->getLabel()) {
          splitBlock->setWaitBlock();
          splitBlock->setWaitStmt(current->getLabel());
        }
        if (pre.size() != 0) {
          // add trailing statements to post block wait stmt
          CFGBlock *newCFGBlock = _cfg->createBlock();
305
          for (std::size_t j{0}; j < pre.size(); j++) {
rmrf's avatar
rmrf committed
306
            newCFGBlock->appendStmt(const_cast<Stmt *>(pre.at(j)->getStmt()),
Anirudh Kaushik's avatar
Anirudh Kaushik committed
307
308
                                    _cfg->getBumpVectorContext());
          }
rmrf's avatar
rmrf committed
309
310
311
          // SusCFG * postSusCFGBlock = new SusCFG(newCFGBlock);
          // susCFGBlockMap.insert(susCFGBlockPairType(newCFGBlock,
          // postSusCFGBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
312
313
314
315
          splitBlocksVector.push_back(newCFGBlock);
          pre.clear();
        }
        if (i == 0) {
rmrf's avatar
rmrf committed
316
317
318
          for (CFGBlock::const_pred_iterator pit = b->pred_begin(),
                                             pite = b->pred_end();
               pit != pite; pit++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
319
320
            const CFGBlock *pred = *pit;

rmrf's avatar
rmrf committed
321
322
323
324
325
            if (susCFGBlockMap.find(const_cast<CFGBlock *>(pred)) ==
                susCFGBlockMap.end()) {
              SusCFG *tmpBlock = new SusCFG(const_cast<CFGBlock *>(pred));
              susCFGBlockMap.insert(
                  susCFGBlockPairType(const_cast<CFGBlock *>(pred), tmpBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
326
327
328
              splitBlock->addPredBlocks(tmpBlock);
            } else {
              susCFGBlockMapType::iterator susCFGBlockFound =
rmrf's avatar
rmrf committed
329
                  susCFGBlockMap.find(const_cast<CFGBlock *>(pred));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
330
331
332
333
              splitBlock->addPredBlocks(susCFGBlockFound->second);
            }
          }

rmrf's avatar
rmrf committed
334
          splitBlock->addParentBlock(const_cast<CFGBlock *>(b));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
335
336
337
338
339
          splitBlock->addParentBlock(currBlock);
          prevBlock = splitBlock;
        } else if (i == splitBlocksVector.size() - 1) {
          prev = splitBlocksVector.at(i - 1);
          if (susCFGBlockMap.find(prev) == susCFGBlockMap.end()) {
rmrf's avatar
rmrf committed
340
341
342
            SusCFG *tmpBlock = new SusCFG(const_cast<CFGBlock *>(prev));
            susCFGBlockMap.insert(
                susCFGBlockPairType(const_cast<CFGBlock *>(prev), tmpBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
343
344
345
            splitBlock->addPredBlocks(tmpBlock);
          } else {
            susCFGBlockMapType::iterator susCFGBlockFound =
rmrf's avatar
rmrf committed
346
                susCFGBlockMap.find(const_cast<CFGBlock *>(prev));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
347
348
349
350
            splitBlock->addPredBlocks(susCFGBlockFound->second);
          }
          prevBlock->addSuccBlocks(splitBlock);

rmrf's avatar
rmrf committed
351
352
353
          for (CFGBlock::const_succ_iterator sit = b->succ_begin(),
                                             site = b->succ_end();
               sit != site; sit++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
354
355
            const CFGBlock *succ = *sit;

rmrf's avatar
rmrf committed
356
357
358
359
360
            if (susCFGBlockMap.find(const_cast<CFGBlock *>(succ)) ==
                susCFGBlockMap.end()) {
              SusCFG *tmpBlock = new SusCFG(const_cast<CFGBlock *>(succ));
              susCFGBlockMap.insert(
                  susCFGBlockPairType(const_cast<CFGBlock *>(succ), tmpBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
361
362
363
              splitBlock->addSuccBlocks(tmpBlock);
            } else {
              susCFGBlockMapType::iterator susCFGBlockFound =
rmrf's avatar
rmrf committed
364
                  susCFGBlockMap.find(const_cast<CFGBlock *>(succ));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
365
366
367
368
369
              splitBlock->addSuccBlocks(susCFGBlockFound->second);
            }
          }
        } else {
          prev = splitBlocksVector.at(i - 1);
rmrf's avatar
rmrf committed
370
371
372
373
374
          if (susCFGBlockMap.find(const_cast<CFGBlock *>(prev)) ==
              susCFGBlockMap.end()) {
            SusCFG *tmpBlock = new SusCFG(const_cast<CFGBlock *>(prev));
            susCFGBlockMap.insert(
                susCFGBlockPairType(const_cast<CFGBlock *>(prev), tmpBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
375
376
377
            splitBlock->addPredBlocks(tmpBlock);
          } else {
            susCFGBlockMapType::iterator susCFGBlockFound =
rmrf's avatar
rmrf committed
378
                susCFGBlockMap.find(const_cast<CFGBlock *>(prev));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
379
380
381
382
383
384
385
386
            splitBlock->addPredBlocks(susCFGBlockFound->second);
          }
          prevBlock->addSuccBlocks(splitBlock);
          prevBlock = splitBlock;
        }
        _susCFGVector.push_back(splitBlock);
      }
    } else {
rmrf's avatar
rmrf committed
387
388
389
      for (CFGBlock::const_pred_iterator pit = b->pred_begin(),
                                         pite = b->pred_end();
           pit != pite; pit++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
390
391
392
        const CFGBlock *predBlock = *pit;

        if (predBlock) {
rmrf's avatar
rmrf committed
393
394
395
396
397
          if (susCFGBlockMap.find(const_cast<CFGBlock *>(predBlock)) ==
              susCFGBlockMap.end()) {
            SusCFG *tmpBlock = new SusCFG(const_cast<CFGBlock *>(predBlock));
            susCFGBlockMap.insert(susCFGBlockPairType(
                const_cast<CFGBlock *>(predBlock), tmpBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
398
399
400
            currBlock->addPredBlocks(tmpBlock);
          } else {
            susCFGBlockMapType::iterator predSusCFGBlockFound =
rmrf's avatar
rmrf committed
401
                susCFGBlockMap.find(const_cast<CFGBlock *>(predBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
402
403
404
405
            currBlock->addPredBlocks(predSusCFGBlockFound->second);
          }
        }
      }
rmrf's avatar
rmrf committed
406
407
408
      for (CFGBlock::const_succ_iterator sit = b->succ_begin(),
                                         site = b->succ_end();
           sit != site; sit++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
409
        const CFGBlock *succBlock = *sit;
410
        SusCFG *tmpBlock{nullptr};
Anirudh Kaushik's avatar
Anirudh Kaushik committed
411
412

        if (succBlock) {
rmrf's avatar
rmrf committed
413
414
415
416
417
          if (susCFGBlockMap.find(const_cast<CFGBlock *>(succBlock)) ==
              susCFGBlockMap.end()) {
            tmpBlock = new SusCFG(const_cast<CFGBlock *>(succBlock));
            susCFGBlockMap.insert(susCFGBlockPairType(
                const_cast<CFGBlock *>(succBlock), tmpBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
418
419
420
            currBlock->addSuccBlocks(tmpBlock);
          } else {
            susCFGBlockMapType::iterator succSusCFGBlockFound =
rmrf's avatar
rmrf committed
421
                susCFGBlockMap.find(const_cast<CFGBlock *>(succBlock));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
422
423
424
425
426
427
428
429
430
            currBlock->addSuccBlocks(succSusCFGBlockFound->second);
          }
        }
      }
      _susCFGVector.push_back(currBlock);
    }
  }
}

rmrf's avatar
rmrf committed
431
432
433
434
435
436
437
438
439
void SuspensionAutomata::addRemainingBlocks(
    State *initialState, vector<SusCFG *> &transitionBlocks) {
  bool duplicate = false;
  if (_stateCommonCodeBlockMap.find(initialState) !=
      _stateCommonCodeBlockMap.end()) {
    stateCommonCodeBlockMapType::iterator stateFound =
        _stateCommonCodeBlockMap.find(initialState);
    checkInsert(stateFound->second, transitionBlocks);
  }
Anirudh's avatar
Anirudh committed
440
441
}

rmrf's avatar
rmrf committed
442
443
444
445
vector<SusCFG *> SuspensionAutomata::modifDFS(SusCFG *block,
                                              State *initialState) {
  deque<SusCFG *> traversedBlocks;
  vector<SusCFG *> visitedBlocks;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
446

447
  traversedBlocks.push_front(block);
rmrf's avatar
rmrf committed
448
449
  bool isWaitEncounter = false;
  vector<SusCFG *> transitionBlocks;
450
451
  while (traversedBlocks.size() != 0) {
    SusCFG *currentBlock = traversedBlocks.front();
Anirudh's avatar
Anirudh committed
452

453
454
    traversedBlocks.pop_front();
    if (currentBlock->isWaitBlock()) {
455
      float timeInNs;
rmrf's avatar
rmrf committed
456
      string eventName;
Anirudh's avatar
Anirudh committed
457
      isWaitEncounter = true;
458
      susCFGStateMapType::iterator stateFound =
rmrf's avatar
rmrf committed
459
          susCFGStateMap.find(currentBlock);
460
461
462
463
464
465
466
467
468
469
470
471
472
      State *finalState = stateFound->second;

      if (isTimedWait(currentBlock->getWaitStmt())) {
        finalState->setTimed();
        timeInNs = getTime(currentBlock->getWaitStmt());
      } else if (isEventWait(currentBlock->getWaitStmt())) {

        finalState->setEvent();
        eventName = getEvent(currentBlock->getWaitStmt());
      } else if (isDeltaWait(currentBlock->getWaitStmt())) {
        finalState->setDelta();
      } else {
        finalState->setInitial();
rmrf's avatar
rmrf committed
473
474
      }

475
476
477
478
479
      Transition *t = new Transition();
      finalState->addEventName(eventName);
      finalState->addSimTime(timeInNs);
      t->addInitialState(initialState);
      t->addFinalState(finalState);
Anirudh's avatar
Anirudh committed
480
      addRemainingBlocks(initialState, transitionBlocks);
481
      t->addCodeBlocks(transitionBlocks);
Anirudh's avatar
Anirudh committed
482

483
484
485
      _transitionVector.push_back(t);
      return transitionBlocks;

rmrf's avatar
rmrf committed
486
487
488
489
    } else {
      // When adding blocks to traversed blocks, check if the last node prior to
      // the wait call has which branch discovered. Also need to check
      // terminator block or block 0
490
      //
491
      if (susCFGSuccIDMap.find(currentBlock) == susCFGSuccIDMap.end()) {
rmrf's avatar
rmrf committed
492
493
494
495
        // currentBlock is not our concern yet, so insert the 0th successive
        // block
        //_os <<"\n Current Block : " <<currentBlock->getBlockID()<<" not of
        //concern";
496
497
498
499
        //
      // TODO: BUG: There is an issue here. 
      // There exists a getSuccBlocks(), but it happens to be empty.
      // This happens when there is a thread that uses a wait(), but no while loop.
500
        if (currentBlock->getSuccBlocks().at(0)->isParentBlock()) {
rmrf's avatar
rmrf committed
501
502
503
504
505
506
          if (!isFound(
                  visitedBlocks,
                  currentBlock->getSuccBlocks().at(0)->getChildBlockList().at(
                      0))) {
            traversedBlocks.push_front(
                currentBlock->getSuccBlocks().at(0)->getChildBlockList().at(0));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
507
          }
rmrf's avatar
rmrf committed
508
        } else {
509
510
511
          if (!isFound(visitedBlocks, currentBlock->getSuccBlocks().at(0))) {
            if (currentBlock->getSuccBlocks().at(0)->getBlockID() != 0) {
              traversedBlocks.push_front(currentBlock->getSuccBlocks().at(0));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
512
513
            }
          }
rmrf's avatar
rmrf committed
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
        }
      } else {
        // currentBlock has a previous entry in the map, so take the other
        // succesive block if it exists
        //_os <<"\n Current block : " <<currentBlock->getBlockID()<<" is of
        //concern";
        susCFGSuccIDMapType::iterator susCFGFound =
            susCFGSuccIDMap.find(currentBlock);
        if (susCFGFound->second == currentBlock->getSuccBlocks().size() - 1) {
          // All the child branches of this node have been discovered. So, there
          // is nothing to discover
          //_os <<"\n Current block : " <<currentBlock->getBlockID()<<" has all
          //children accounted for";
          break;
        } else {
          if (currentBlock->getSuccBlocks()
                  .at(susCFGFound->second + 1)
                  ->isParentBlock()) {
            if (!isFound(visitedBlocks, currentBlock->getSuccBlocks()
                                            .at(susCFGFound->second + 1)
                                            ->getChildBlockList()
                                            .at(0))) {
              traversedBlocks.push_front(currentBlock->getSuccBlocks()
                                             .at(susCFGFound->second + 1)
                                             ->getChildBlockList()
                                             .at(0));
            }
          } else {
            if (!isFound(visitedBlocks, currentBlock->getSuccBlocks().at(
                                            susCFGFound->second + 1))) {
              if (currentBlock->getSuccBlocks()
                      .at(susCFGFound->second + 1)
                      ->getBlockID() != 0) {
                traversedBlocks.push_front(
                    currentBlock->getSuccBlocks().at(susCFGFound->second + 1));
              }
            }
          }
        }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
553
      }
554
555
556
557
      visitedBlocks.push_back(currentBlock);
      transitionBlocks.push_back(currentBlock);
    }
  }
rmrf's avatar
rmrf committed
558
559
560
561
562
563
564
565
566
567
568
569
  if (isWaitEncounter == false) {
    // we found a path that does not end in a wait block. So,
    // it will be in all paths from this initial state to all final wait states
    if (_stateCommonCodeBlockMap.find(initialState) ==
        _stateCommonCodeBlockMap.end()) {
      _stateCommonCodeBlockMap.insert(
          stateCommonCodeBlockPairType(initialState, transitionBlocks));
    } else {
      stateCommonCodeBlockMapType::iterator stateFound =
          _stateCommonCodeBlockMap.find(initialState);
      vector<SusCFG *> remainingCodeBlocks = stateFound->second;
      checkInsert(transitionBlocks, remainingCodeBlocks);
Anirudh's avatar
Anirudh committed
570
    }
rmrf's avatar
rmrf committed
571
572
573
574
575
576
577
  }
  return transitionBlocks;
}

void SuspensionAutomata::checkInsert(vector<SusCFG *> source,
                                     vector<SusCFG *> &target) {
  bool duplicate;
578
  for (std::size_t i {0}; i < source.size(); i++) {
rmrf's avatar
rmrf committed
579
580
581
582
583
584
585
586
587
588
589
    duplicate = false;
    for (int j = 0; j < target.size(); j++) {
      if (source.at(i) == target.at(j)) {
        duplicate = true;
        break;
      }
    }
    if (duplicate == false) {
      target.push_back(source.at(i));
    }
  }
Anirudh's avatar
Anirudh committed
590
}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
591

rmrf's avatar
rmrf committed
592
void SuspensionAutomata::genSauto() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
593
594
  susCFGVectorType susCFGVector = _susCFGVector;
  susCFGVectorType waitBlocks;
595
  for (std::size_t i {0}; i < susCFGVector.size(); i++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
596
    if (susCFGVector.at(i)->isWaitBlock() || i == 0) {
597
      waitBlocks.push_back(susCFGVector.at(i));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
598
      State *state = new State(susCFGVector.at(i), false, false, false, false);
rmrf's avatar
rmrf committed
599
      if (i == 0) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
600
        state->setInitial();
rmrf's avatar
rmrf committed
601
602
603
        //_os <<"\n State susblock set to initial : "
        //<<state->returnSusCFGBlock()->getBlockID(); _os <<"\n State : "
        //<<state->isTimed()<<" " <<state->isInitial()<<" " <<state->isDelta();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
604
605
606
607
      }
      susCFGStateMap.insert(susCFGStatePairType(susCFGVector.at(i), state));
    }
  }
rmrf's avatar
rmrf committed
608

609
  for (std::size_t i {0}; i < waitBlocks.size(); i++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
610

611
    SusCFG *waitBlock = waitBlocks.at(i);
rmrf's avatar
rmrf committed
612

613
614
    //_os <<"\n Looking at Wait Block : " <<waitBlock->getBlockID();

rmrf's avatar
rmrf committed
615
616
    susCFGStateMapType::iterator stateFound =
        susCFGStateMap.find(waitBlocks.at(i));
Anirudh Kaushik's avatar
Anirudh Kaushik committed
617
    State *initialState = stateFound->second;
618

rmrf's avatar
rmrf committed
619
620
    vector<SusCFG *> backTrackCodeBlocks;
    SusCFG *lastBlock;
621
622
623
624
625
    susCFGSuccIDMap.clear(); // For each new initial state, start fresh...
    // Left child.. do the same for the right child
    do {
      SusCFG *initialInsertBlock;
      if (waitBlock->getSuccBlocks().at(0)->isParentBlock()) {
rmrf's avatar
rmrf committed
626
627
        initialInsertBlock =
            waitBlock->getSuccBlocks().at(0)->getChildBlockList().at(0);
628
      }
rmrf's avatar
rmrf committed
629

630
631
632
      else {
        initialInsertBlock = waitBlock->getSuccBlocks().at(0);
      }
rmrf's avatar
rmrf committed
633
634
635
636
      vector<SusCFG *> transitionCodeBlocks =
          modifDFS(initialInsertBlock, initialState);

      //_os <<"\n Transition Blocks : ";
637
      backTrackCodeBlocks.clear();
638
      for (std::size_t j {0}; j < transitionCodeBlocks.size(); j++) {
639
640
641
        backTrackCodeBlocks.push_back(transitionCodeBlocks.at(j));
        //_os <<" "<<transitionCodeBlocks.at(j)->getBlockID();;
      }
642
      std::size_t j{};
rmrf's avatar
rmrf committed
643
      for (j = backTrackCodeBlocks.size() - 2; j >= 0; j--) {
644
        if (backTrackCodeBlocks.at(j)->getSuccBlocks().size() > 1) {
rmrf's avatar
rmrf committed
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
          //_os <<"\n Block : " <<backTrackCodeBlocks.at(j)->getBlockID()<<" has
          //more than one successor";
          SusCFG *backBlock = backTrackCodeBlocks.at(j);
          if (backBlock->getSuccBlocks().at(0)->isParentBlock()) {

            if (backBlock->getSuccBlocks().at(0)->getChildBlockList().at(0) ==
                backTrackCodeBlocks.at(j + 1)) {
              //_os <<"\n Block : " <<backBlock->getBlockID()<<" used the first
              //successor";
              susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 0));
              //_os <<"\n Map value : " <<susCFGSuccIDMap[backBlock];
              break;
            }
          } else if (backBlock->getSuccBlocks().at(1)->isParentBlock()) {

            if (backBlock->getSuccBlocks().at(1)->getChildBlockList().at(0) ==
                backTrackCodeBlocks.at(j + 1)) {
              //_os <<"\n Block : " <<backBlock->getBlockID()<<" used the second
              //successor";
              susCFGSuccIDMap.erase(backBlock);
              susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 1));
              break;
            }
668
          }
rmrf's avatar
rmrf committed
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684

          else if (backBlock->getSuccBlocks().at(0) ==
                   backTrackCodeBlocks.at(j + 1)) {
            //_os <<"\n Block : " <<backBlock->getBlockID()<<" used the first
            //successor";

            susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 0));
            break;
          } else if (backBlock->getSuccBlocks().at(1) ==
                     backTrackCodeBlocks.at(j + 1)) {
            //_os <<"\n Block : " <<backBlock->getBlockID()<<" used the second
            //successor";

            susCFGSuccIDMap.erase(backBlock);
            susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 1));
            break;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
685
          }
rmrf's avatar
rmrf committed
686
        }
687
      }
rmrf's avatar
rmrf committed
688
      //_os <<"\n J value : " <<j;
689
      if (j == -1) {
rmrf's avatar
rmrf committed
690
691
692
693
694
695
696
697
698
699
700
        if (susCFGSuccIDMap.find(backTrackCodeBlocks.back()) ==
            susCFGSuccIDMap.end()) {
          susCFGSuccIDMap.insert(
              susCFGSuccIDPairType(backTrackCodeBlocks.back(), 0));
        } else {
          if (susCFGSuccIDMap[backTrackCodeBlocks.back()] == 0) {
            susCFGSuccIDMap.erase(backTrackCodeBlocks.back());
            susCFGSuccIDMap.insert(
                susCFGSuccIDPairType(backTrackCodeBlocks.back(), 1));
          } else {
          }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
701
702
        }
      }
703
704

      // delete the blocks from the back to j
rmrf's avatar
rmrf committed
705
706
      if (backTrackCodeBlocks.size() != 0) {
        backTrackCodeBlocks.pop_back();
707
      }
rmrf's avatar
rmrf committed
708
709

    } while (backTrackCodeBlocks.size() != 0);
Anirudh Kaushik's avatar
Anirudh Kaushik committed
710
711
712
  }
}

rmrf's avatar
rmrf committed
713
template <typename Node> bool is_found(Node n1, Node n2) { return n1 == n2; }
Jimmy Lu's avatar
Jimmy Lu committed
714

rmrf's avatar
rmrf committed
715
716
717
718
template <template <typename, typename> class Container, typename Node,
          typename Allocator>
bool generic_isFound(Container<Node, Allocator> &container, Node node) {
  bool foundBlock = false;
Jimmy Lu's avatar
Jimmy Lu committed
719

rmrf's avatar
rmrf committed
720
721
722
  typename Container<Node, Allocator>::iterator itr = std::find_if(
      container.begin(), container.end(),
      std::bind1st(std::ptr_fun<Node, Node, bool>(is_found), node));
Jimmy Lu's avatar
Jimmy Lu committed
723

rmrf's avatar
rmrf committed
724
  return itr != container.end();
Jimmy Lu's avatar
Jimmy Lu committed
725
726
}

Anirudh Kaushik's avatar
Anirudh Kaushik committed
727
// need a utility class and this should be a template function
rmrf's avatar
rmrf committed
728
729
bool SuspensionAutomata::isFound(vector<SusCFG *> visitedState, SusCFG *block) {
  return generic_isFound(visitedState, block);
Anirudh Kaushik's avatar
Anirudh Kaushik committed
730
731
}

rmrf's avatar
rmrf committed
732
733
734
bool SuspensionAutomata::isFound(vector<Transition *> visitedState,
                                 Transition *block) {
  return generic_isFound(visitedState, block);
Anirudh Kaushik's avatar
Anirudh Kaushik committed
735
736
}

rmrf's avatar
rmrf committed
737
float SuspensionAutomata::getTime(Stmt *stmt) {
738
  float factor;
rmrf's avatar
rmrf committed
739
  if (CXXMemberCallExpr *ce = dyn_cast<CXXMemberCallExpr>(stmt)) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
    if (getArgumentName(ce->getArg(1)) == "SC_FS") {
      factor = 1000000;
    } else if (getArgumentName(ce->getArg(1)) == "SC_PS") {
      factor = 1000;
    } else if (getArgumentName(ce->getArg(1)) == "SC_NS") {
      factor = 1;
    } else if (getArgumentName(ce->getArg(1)) == "SC_US") {
      factor = 0.001;
    } else if (getArgumentName(ce->getArg(1)) == "SC_MS") {
      factor = 0.000001;
    } else if (getArgumentName(ce->getArg(1)) == "SC_SEC") {
      factor = 0.0000000001;
    }
    return (atof(getArgumentName(ce->getArg(0)).c_str()) * factor);
  }
}

rmrf's avatar
rmrf committed
757
758
string SuspensionAutomata::getEvent(Stmt *stmt) {
  if (CXXMemberCallExpr *ce = dyn_cast<CXXMemberCallExpr>(stmt)) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
759
760
761
762
    return (getArgumentName(ce->getArg(0)));
  }
}

rmrf's avatar
rmrf committed
763
bool SuspensionAutomata::isTimedWait(Stmt *stmt) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
764

rmrf's avatar
rmrf committed
765
  if (CXXMemberCallExpr *ce = dyn_cast<CXXMemberCallExpr>(stmt)) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
766
767
768
769
770
771
    if (ce->getNumArgs() > 1) {
      return true;
    }
  }
  return false;
}
772
773

string SuspensionAutomata::getArgumentName(Expr * arg) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
  if (arg == NULL)
    return string("NULL");

  clang::LangOptions LangOpts;
  LangOpts.CPlusPlus = true;
  clang::PrintingPolicy Policy(LangOpts);

  string TypeS;

  llvm::raw_string_ostream s(TypeS);

  arg->printPretty(s, 0, Policy);
  //  _os << ", argument: " << s.str() << "\n";
  return s.str();
}

rmrf's avatar
rmrf committed
790
bool SuspensionAutomata::isDeltaWait(Stmt *stmt) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
791

rmrf's avatar
rmrf committed
792
  if (CXXMemberCallExpr *ce = dyn_cast<CXXMemberCallExpr>(stmt)) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
793
794
795
796
797
798
799
800
801
802
803
804
805
    if (ce->getNumArgs() == 1) {
      string eventName = getArgumentName(ce->getArg(0));

      if (eventName == "SC_ZERO_TIME") {
        return true;
      } else {
        return false;
      }
    }
  }
  return false;
}

rmrf's avatar
rmrf committed
806
bool SuspensionAutomata::isEventWait(Stmt *stmt) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
807

rmrf's avatar
rmrf committed
808
  if (CXXMemberCallExpr *ce = dyn_cast<CXXMemberCallExpr>(stmt)) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
809
810
811
812
813
814
815
    if (ce->getNumArgs() == 1) {
      return true;
    }
  }
  return false;
}

rmrf's avatar
rmrf committed
816
SuspensionAutomata::susCFGVectorType SuspensionAutomata::getSusCFG() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
817
818
819
  return _susCFGVector;
}

rmrf's avatar
rmrf committed
820
SuspensionAutomata::transitionVectorType SuspensionAutomata::getSauto() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
821
822
823
  return _transitionVector;
}

rmrf's avatar
rmrf committed
824
void SuspensionAutomata::dumpSusCFG() {
825

Anirudh Kaushik's avatar
Anirudh Kaushik committed
826
827
828
829
830
831
832
833
834
835
  susCFGVectorType susCFGVector = _susCFGVector;

  for (unsigned int i = 0; i < susCFGVector.size(); i++) {
    _os << "\n Block ID : " << susCFGVector.at(i)->getBlockID();
    _os << "\n Is Wait Block : " << susCFGVector.at(i)->isWaitBlock();
    if (susCFGVector.at(i)->getParentBlockID()) {
      _os << "\n Parent ID : " << susCFGVector.at(i)->getParentBlockID();
      SusCFG *parentBlock = susCFGVector.at(i)->getParentSusCFGBlock();

      _os << "\n Parent Block ID : " << parentBlock->getBlockID();
rmrf's avatar
rmrf committed
836
837
      _os << "\n Size of Children : "
          << parentBlock->getChildBlockList().size();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
838
    }
rmrf's avatar
rmrf committed
839
840
    vector<SusCFG *> predBlocks = susCFGVector.at(i)->getPredBlocks();
    vector<SusCFG *> succBlocks = susCFGVector.at(i)->getSuccBlocks();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
    _os << "\n Predecessor Blocks : ";
    for (unsigned int j = 0; j < predBlocks.size(); j++) {
      if (predBlocks.at(j)) {
        _os << predBlocks.at(j)->getBlockID() << " ";
      }
    }
    _os << "\n Successor Blocks : ";
    for (unsigned int j = 0; j < succBlocks.size(); j++) {
      if (succBlocks.at(j)) {
        _os << succBlocks.at(j)->getBlockID() << " ";
      }
    }
  }
}

rmrf's avatar
rmrf committed
856
void SuspensionAutomata::dumpSauto() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
857

rmrf's avatar
rmrf committed
858
  vector<Transition *> transitionVector = _transitionVector;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
859
860
861
862
863
864
865
866
  _os << "\n Size of transitionVector : " << transitionVector.size();
  for (unsigned int i = 0; i < transitionVector.size(); i++) {
    Transition *t = transitionVector.at(i);
    t->dump(_os);
  }
}

//////////////////////////////////////////////////////////////////////////////