std::vector<std::vector<BasicBlock *> *>* BBTraversalHelper::getSCCTraversalOrder(Function &currF) { std::vector<std::vector<BasicBlock *> *> *bbTraversalList = new std::vector<std::vector<BasicBlock *> *>(); const Function *F = &currF; for (scc_iterator<const Function *> I = scc_begin(F), IE = scc_end(F); I != IE; ++I) { // Obtain the vector of BBs in this SCC and print it out. const std::vector<const BasicBlock *> &SCCBBs = *I; std::vector<const BasicBlock *> *currSCC = new std::vector<const BasicBlock *>(); for (std::vector<const BasicBlock *>::const_iterator BBI = SCCBBs.begin(), BBIE = SCCBBs.end(); BBI != BBIE; ++BBI) { currSCC->insert(currSCC->begin(), (*BBI)); } std::vector<BasicBlock *> *newCurrSCC = new std::vector<BasicBlock *>(); for (unsigned int i = 0; i < currSCC->size(); i++) { for (Function::iterator b = currF.begin(), be = currF.end(); b != be; ++b) { BasicBlock *BB = &(*b); if (BB == (*currSCC)[i]) { newCurrSCC->insert(newCurrSCC->begin(), BB); break; } } } delete (currSCC); bbTraversalList->insert(bbTraversalList->begin(), newCurrSCC); } return bbTraversalList; }
/** * @brief Runs basic block analysis and saves contained info. * * This method is need to run before methods that finds out results of this * basic block analysis. * * @param[in] func Function which basic blocks are analyzed. */ void BBTraversalAnalysis::doBBsAnalysis(Function &func) { // If analysis was run before than now is need to clear everything. clear(); Node *prevNode = nullptr; for (scc_iterator<Function *> i = scc_begin(&func), e = scc_end(&func); i != e; ++i) { const BBVec &sccBBs(*i); if (sccBBs.size() > 1) { // We have strongly connected component. This means cycle basic // basic block dependency. prevNode = processBBsInSCC(sccBBs, prevNode); continue; } if (sccBBs.size() == 1) { if (isBBLoop(**sccBBs.begin())) { // Loop on same basic block. prevNode = processBBsInSCC(sccBBs, prevNode); continue; } // No recursion. prevNode = processBBNotInSCC(sccBBs, prevNode); } } // Set current node to initial state of analysis. currNode = headNode; }