demo.cpp
/* Get all inevitable basic blocks in a loop.
 * A inevitable Basic Block is a basic basic that dominate by the back edges.
 * What is back edges: back edge is the edge to the loop header in the loop.
 */
Get all inevitable basic blocks in a loop.
A inevitable Basic Block is a basic basic that dominate by the back edges.
What is back edges: back edge is the edge to the loop header in the loop.
Get all inevitable basic blocks in a loop . A inevitable Basic Block is a basic basic that dominate by the back edges . What is back edges : back edge is the edge to the loop header in the loop .
set<BasicBlock *>* Support::getInevitableBBinLoop(Loop *pLoop, PostDominatorTree &pdt){
	BasicBlock *HB = &*pLoop->getHeader();
	set<BasicBlock *> BackEgeSet;
	BackEgeSet.clear();
	set<BasicBlock *>* InevitableBBSet = new set<BasicBlock *>;
	InevitableBBSet->clear();
	for (auto it = pred_begin(HB), et = pred_end(HB); it != et; ++it)
	{
		BasicBlock* predecessor = *it;
		if(pLoop->contains(predecessor)){
			BackEgeSet.insert(predecessor);
#ifdef INEV_BB
			errs() << "back eges :\n" ;
			predecessor->print(errs());
			errs() << "\n" ;
#endif
		}
	}
	for (Loop::block_iterator BI = pLoop->block_begin(); BI != pLoop->block_end(); BI++) {
		BasicBlock *BB = *BI;
#ifdef INEV_BB
		errs() << "BasicBlock\n" ;
		BB->print(errs());
		errs() << "\n" ;
#endif
		bool isInevitableBB = true;
		for(auto BackEge : BackEgeSet){
			if(!(pdt.dominates(BackEge,BB))){
				isInevitableBB = false;
			}
		}
		if(isInevitableBB){
			InevitableBBSet->insert(BB);
		}
	}
	return InevitableBBSet;
}
set < BasicBlock * > * Support :: getInevitableBBinLoop ( Loop * pLoop , PostDominatorTree & pdt ) { BasicBlock * HB = & * pLoop -> getHeader ( ) ; set < BasicBlock * > BackEgeSet ; BackEgeSet . clear ( ) ; set < BasicBlock * > * InevitableBBSet = new set < BasicBlock * > ; InevitableBBSet -> clear ( ) ; for ( auto it = pred_begin ( HB ) , et = pred_end ( HB ) ; it != et ; ++ it ) { BasicBlock * predecessor = * it ; if ( pLoop -> contains ( predecessor ) ) { BackEgeSet . insert ( predecessor ) ; #ifdef INEV_BB errs ( ) << " \n " ; predecessor -> print ( errs ( ) ) ; errs ( ) << " \n " ; #endif } } for ( Loop :: block_iterator BI = pLoop -> block_begin ( ) ; BI != pLoop -> block_end ( ) ; BI ++ ) { BasicBlock * BB = * BI ; #ifdef INEV_BB errs ( ) << " \n " ; BB -> print ( errs ( ) ) ; errs ( ) << " \n " ; #endif bool isInevitableBB = true ; for ( auto BackEge : BackEgeSet ) { if ( ! ( pdt . dominates ( BackEge , BB ) ) ) { isInevitableBB = false ; } } if ( isInevitableBB ) { InevitableBBSet -> insert ( BB ) ; } } return InevitableBBSet ; }
Get all inevitable basic blocks in a loop.
Get all inevitable basic blocks in a loop .
/* Get all the back edges in a loop.
	 */ /* Get the inevitable basic blocks.
	 */ /* Postdominated by all backedge
			 */