220 PrintingPolicy Policy(LO);
222 vector<Optional<CFGStmt>> pre;
223 vector<unsigned int> waitBlockIDVector;
224 vector<const CFGBlock *> CFGBlockVector;
227 typedef map<CFGBlock *, SusCFG *> susCFGBlockMapType;
228 typedef pair<CFGBlock *, SusCFG *> susCFGBlockPairType;
230 susCFGBlockMapType susCFGBlockMap;
232 bool isFirstCFGBlockID =
false;
234 for (CFG::iterator it =
_cfg->end() - 1, eit =
_cfg->begin(); it != eit;
236 const CFGBlock *b = *it;
239 if (susCFGBlockMap.find(
const_cast<CFGBlock *
>(b)) ==
240 susCFGBlockMap.end()) {
241 currBlock =
new SusCFG(
const_cast<CFGBlock *
>(b));
242 susCFGBlockMap.insert(
243 susCFGBlockPairType(
const_cast<CFGBlock *
>(b), currBlock));
245 susCFGBlockMapType::iterator susCFGBlockFound =
246 susCFGBlockMap.find(
const_cast<CFGBlock *
>(b));
247 currBlock = susCFGBlockFound->second;
250 bool foundWait =
false;
252 vector<CFGBlock *> splitBlocksVector;
258 unsigned int prevCFGBlockID;
260 for (CFGBlock::const_iterator bit = b->begin(), bite = b->end();
261 bit != bite; bit++) {
262 if (Optional<CFGStmt> cs = bit->getAs<CFGStmt>()) {
263 const CFGStmt *s = (CFGStmt
const *)&cs;
267 CFGBlock *newSplitBlock =
_cfg->createBlock();
269 for (
unsigned int i = 0; i < pre.size(); i++) {
270 newSplitBlock->appendStmt(
const_cast<Stmt *
>(pre.at(i)->getStmt()),
271 _cfg->getBumpVectorContext());
274 CFGBlock *waitBlock =
_cfg->createBlock();
276 waitBlock->appendStmt(
const_cast<Stmt *
>(cs->getStmt()),
277 _cfg->getBumpVectorContext());
278 waitBlock->setLabel(
const_cast<Stmt *
>(cs->getStmt()));
279 splitBlocksVector.push_back(newSplitBlock);
280 splitBlocksVector.push_back(waitBlock);
292 CFGBlock *prev = NULL;
295 for (std::size_t i = 0; i < splitBlocksVector.size(); i++) {
296 CFGBlock *current = splitBlocksVector.at(i);
298 new SusCFG(
const_cast<CFGBlock *
>(splitBlocksVector.at(i)));
300 if (current->getLabel()) {
304 if (pre.size() != 0) {
306 CFGBlock *newCFGBlock =
_cfg->createBlock();
307 for (std::size_t j{0}; j < pre.size(); j++) {
308 newCFGBlock->appendStmt(
const_cast<Stmt *
>(pre.at(j)->getStmt()),
309 _cfg->getBumpVectorContext());
314 splitBlocksVector.push_back(newCFGBlock);
318 for (CFGBlock::const_pred_iterator pit = b->pred_begin(),
319 pite = b->pred_end();
320 pit != pite; pit++) {
321 const CFGBlock *pred = *pit;
323 if (susCFGBlockMap.find(
const_cast<CFGBlock *
>(pred)) ==
324 susCFGBlockMap.end()) {
325 SusCFG *tmpBlock =
new SusCFG(
const_cast<CFGBlock *
>(pred));
326 susCFGBlockMap.insert(
327 susCFGBlockPairType(
const_cast<CFGBlock *
>(pred), tmpBlock));
330 susCFGBlockMapType::iterator susCFGBlockFound =
331 susCFGBlockMap.find(
const_cast<CFGBlock *
>(pred));
338 prevBlock = splitBlock;
339 }
else if (i == splitBlocksVector.size() - 1) {
340 prev = splitBlocksVector.at(i - 1);
341 if (susCFGBlockMap.find(prev) == susCFGBlockMap.end()) {
342 SusCFG *tmpBlock =
new SusCFG(
const_cast<CFGBlock *
>(prev));
343 susCFGBlockMap.insert(
344 susCFGBlockPairType(
const_cast<CFGBlock *
>(prev), tmpBlock));
347 susCFGBlockMapType::iterator susCFGBlockFound =
348 susCFGBlockMap.find(
const_cast<CFGBlock *
>(prev));
353 for (CFGBlock::const_succ_iterator sit = b->succ_begin(),
354 site = b->succ_end();
355 sit != site; sit++) {
356 const CFGBlock *succ = *sit;
358 if (susCFGBlockMap.find(
const_cast<CFGBlock *
>(succ)) ==
359 susCFGBlockMap.end()) {
360 SusCFG *tmpBlock =
new SusCFG(
const_cast<CFGBlock *
>(succ));
361 susCFGBlockMap.insert(
362 susCFGBlockPairType(
const_cast<CFGBlock *
>(succ), tmpBlock));
365 susCFGBlockMapType::iterator susCFGBlockFound =
366 susCFGBlockMap.find(
const_cast<CFGBlock *
>(succ));
371 prev = splitBlocksVector.at(i - 1);
372 if (susCFGBlockMap.find(
const_cast<CFGBlock *
>(prev)) ==
373 susCFGBlockMap.end()) {
374 SusCFG *tmpBlock =
new SusCFG(
const_cast<CFGBlock *
>(prev));
375 susCFGBlockMap.insert(
376 susCFGBlockPairType(
const_cast<CFGBlock *
>(prev), tmpBlock));
379 susCFGBlockMapType::iterator susCFGBlockFound =
380 susCFGBlockMap.find(
const_cast<CFGBlock *
>(prev));
384 prevBlock = splitBlock;
389 for (CFGBlock::const_pred_iterator pit = b->pred_begin(),
390 pite = b->pred_end();
391 pit != pite; pit++) {
392 const CFGBlock *predBlock = *pit;
395 if (susCFGBlockMap.find(
const_cast<CFGBlock *
>(predBlock)) ==
396 susCFGBlockMap.end()) {
397 SusCFG *tmpBlock =
new SusCFG(
const_cast<CFGBlock *
>(predBlock));
398 susCFGBlockMap.insert(susCFGBlockPairType(
399 const_cast<CFGBlock *
>(predBlock), tmpBlock));
402 susCFGBlockMapType::iterator predSusCFGBlockFound =
403 susCFGBlockMap.find(
const_cast<CFGBlock *
>(predBlock));
408 for (CFGBlock::const_succ_iterator sit = b->succ_begin(),
409 site = b->succ_end();
410 sit != site; sit++) {
411 const CFGBlock *succBlock = *sit;
412 SusCFG *tmpBlock{
nullptr};
415 if (susCFGBlockMap.find(
const_cast<CFGBlock *
>(succBlock)) ==
416 susCFGBlockMap.end()) {
417 tmpBlock =
new SusCFG(
const_cast<CFGBlock *
>(succBlock));
418 susCFGBlockMap.insert(susCFGBlockPairType(
419 const_cast<CFGBlock *
>(succBlock), tmpBlock));
422 susCFGBlockMapType::iterator succSusCFGBlockFound =
423 susCFGBlockMap.find(
const_cast<CFGBlock *
>(succBlock));
445 State *initialState) {
446 deque<SusCFG *> traversedBlocks;
447 vector<SusCFG *> visitedBlocks;
449 traversedBlocks.push_front(block);
450 bool isWaitEncounter =
false;
451 vector<SusCFG *> transitionBlocks;
452 while (traversedBlocks.size() != 0) {
453 SusCFG *currentBlock = traversedBlocks.front();
455 traversedBlocks.pop_front();
459 isWaitEncounter =
true;
460 susCFGStateMapType::iterator stateFound =
462 State *finalState = stateFound->second;
485 return transitionBlocks;
507 traversedBlocks.push_front(
508 currentBlock->
getSuccBlocks().at(0)->getChildBlockList().at(0));
512 if (currentBlock->
getSuccBlocks().at(0)->getBlockID() != 0) {
513 traversedBlocks.push_front(currentBlock->
getSuccBlocks().at(0));
522 susCFGSuccIDMapType::iterator susCFGFound =
524 if (susCFGFound->second == currentBlock->
getSuccBlocks().size() - 1) {
532 .at(susCFGFound->second + 1)
535 .at(susCFGFound->second + 1)
536 ->getChildBlockList()
539 .at(susCFGFound->second + 1)
540 ->getChildBlockList()
545 susCFGFound->second + 1))) {
547 .at(susCFGFound->second + 1)
548 ->getBlockID() != 0) {
549 traversedBlocks.push_front(
556 visitedBlocks.push_back(currentBlock);
557 transitionBlocks.push_back(currentBlock);
560 if (isWaitEncounter ==
false) {
568 stateCommonCodeBlockMapType::iterator stateFound =
570 vector<SusCFG *> remainingCodeBlocks = stateFound->second;
571 checkInsert(transitionBlocks, remainingCodeBlocks);
574 return transitionBlocks;
597 for (std::size_t i{0}; i < susCFGVector.size(); i++) {
598 if (susCFGVector.at(i)->isWaitBlock() || i == 0) {
599 waitBlocks.push_back(susCFGVector.at(i));
600 State *state =
new State(susCFGVector.at(i),
false,
false,
false,
false);
611 for (std::size_t i{0}; i < waitBlocks.size(); i++) {
612 SusCFG *waitBlock = waitBlocks.at(i);
616 susCFGStateMapType::iterator stateFound =
618 State *initialState = stateFound->second;
620 vector<SusCFG *> backTrackCodeBlocks;
625 SusCFG *initialInsertBlock;
634 vector<SusCFG *> transitionCodeBlocks =
635 modifDFS(initialInsertBlock, initialState);
638 backTrackCodeBlocks.clear();
639 for (std::size_t j{0}; j < transitionCodeBlocks.size(); j++) {
640 backTrackCodeBlocks.push_back(transitionCodeBlocks.at(j));
644 for (j = backTrackCodeBlocks.size() - 2; j >= 0; j--) {
645 if (backTrackCodeBlocks.at(j)->getSuccBlocks().size() > 1) {
648 SusCFG *backBlock = backTrackCodeBlocks.at(j);
650 if (backBlock->
getSuccBlocks().at(0)->getChildBlockList().at(0) ==
651 backTrackCodeBlocks.at(j + 1)) {
658 }
else if (backBlock->
getSuccBlocks().at(1)->isParentBlock()) {
659 if (backBlock->
getSuccBlocks().at(1)->getChildBlockList().at(0) ==
660 backTrackCodeBlocks.at(j + 1)) {
670 backTrackCodeBlocks.at(j + 1)) {
677 backTrackCodeBlocks.at(j + 1)) {
704 if (backTrackCodeBlocks.size() != 0) {
705 backTrackCodeBlocks.pop_back();
708 }
while (backTrackCodeBlocks.size() != 0);
825 for (
unsigned int i = 0; i < susCFGVector.size(); i++) {
826 _os <<
"\n Block ID : " << susCFGVector.at(i)->getBlockID();
827 _os <<
"\n Is Wait Block : " << susCFGVector.at(i)->isWaitBlock();
828 if (susCFGVector.at(i)->getParentBlockID()) {
829 _os <<
"\n Parent ID : " << susCFGVector.at(i)->getParentBlockID();
833 _os <<
"\n Size of Children : "
836 vector<SusCFG *> predBlocks = susCFGVector.at(i)->getPredBlocks();
837 vector<SusCFG *> succBlocks = susCFGVector.at(i)->getSuccBlocks();
838 _os <<
"\n Predecessor Blocks : ";
839 for (
unsigned int j = 0; j < predBlocks.size(); j++) {
840 if (predBlocks.at(j)) {
841 _os << predBlocks.at(j)->getBlockID() <<
" ";
844 _os <<
"\n Successor Blocks : ";
845 for (
unsigned int j = 0; j < succBlocks.size(); j++) {
846 if (succBlocks.at(j)) {
847 _os << succBlocks.at(j)->getBlockID() <<
" ";