liberty/lib/LAMP/LAMPLoopSample.cpp
/* Clone the loop and return the clone
   * Most of this code comes from DOALLCloneLoop
   */
Clone the loop and return the clone
Most of this code comes from DOALLCloneLoop
Clone the loop and return the clone Most of this code comes from DOALLCloneLoop
Loop* LAMPLoopSample::LAMPCloneLoop(Loop *OrigL, LoopInfo *LI,
      ValueToValueMapTy &clonedValueMap,
      SmallVector<BasicBlock *, 16> &ClonedBlocks)
  {
    Loop *NewLoop = LI->AllocateLoop();
    for (Loop::block_iterator I = OrigL->block_begin(), E = OrigL->block_end();
        I != E; ++I)
    {
      BasicBlock *BB = *I;
      BasicBlock *NewBB = CloneBasicBlock(BB, clonedValueMap, ".clone");
      clonedValueMap[BB] = NewBB;
      for (BasicBlock::iterator ii = NewBB->begin(), ee = NewBB->end();
          ii != ee; ++ii)
      {
      }
      LoopInfoBase<BasicBlock, Loop> &LIB = *LI;
      NewLoop->addBasicBlockToLoop(NewBB, LIB);
      ClonedBlocks.push_back(NewBB);
    }
    for(SmallVector<BasicBlock *, 16>::iterator NBItr = ClonedBlocks.begin(),
        NBE = ClonedBlocks.end();  NBItr != NBE; ++NBItr)
    {
      BasicBlock *NB = *NBItr;
      for(BasicBlock::iterator BI = NB->begin(), BE = NB->end();
          BI != BE; ++BI)
      {
        Instruction *Insn = &*BI;
        for (unsigned index = 0, num_ops = Insn->getNumOperands();
            index != num_ops; ++index)
        {
          Value *Op = Insn->getOperand(index);
          ValueToValueMapTy::iterator OpItr = clonedValueMap.find(Op);
          if (OpItr != clonedValueMap.end())
            Insn->setOperand(index, OpItr->second);
        }
      }
    }
    BasicBlock *Latch = OrigL->getLoopLatch();
    Function *F = Latch->getParent();
    BasicBlock **ClonedBlBegin = &*(ClonedBlocks.begin());
    BasicBlock **ClonedBlEnd = &*(ClonedBlocks.end());
    llvm::iplist_impl<llvm::simple_ilist<llvm::BasicBlock>, llvm::SymbolTableListTraits<llvm::BasicBlock>>::iterator it(OrigL->getLoopPreheader());
    F->getBasicBlockList().insert(it,
        ClonedBlBegin, ClonedBlEnd);
    return NewLoop;
  }
Loop * LAMPLoopSample :: LAMPCloneLoop ( Loop * OrigL , LoopInfo * LI , ValueToValueMapTy & clonedValueMap , SmallVector < BasicBlock * , 16 > & ClonedBlocks ) { Loop * NewLoop = LI -> AllocateLoop ( ) ; for ( Loop :: block_iterator I = OrigL -> block_begin ( ) , E = OrigL -> block_end ( ) ; I != E ; ++ I ) { BasicBlock * BB = * I ; BasicBlock * NewBB = CloneBasicBlock ( BB , clonedValueMap , " " ) ; clonedValueMap [ BB ] = NewBB ; for ( BasicBlock :: iterator ii = NewBB -> begin ( ) , ee = NewBB -> end ( ) ; ii != ee ; ++ ii ) { } LoopInfoBase < BasicBlock , Loop > & LIB = * LI ; NewLoop -> addBasicBlockToLoop ( NewBB , LIB ) ; ClonedBlocks . push_back ( NewBB ) ; } for ( SmallVector < BasicBlock * , 16 > :: iterator NBItr = ClonedBlocks . begin ( ) , NBE = ClonedBlocks . end ( ) ; NBItr != NBE ; ++ NBItr ) { BasicBlock * NB = * NBItr ; for ( BasicBlock :: iterator BI = NB -> begin ( ) , BE = NB -> end ( ) ; BI != BE ; ++ BI ) { Instruction * Insn = & * BI ; for ( unsigned index = 0 , num_ops = Insn -> getNumOperands ( ) ; index != num_ops ; ++ index ) { Value * Op = Insn -> getOperand ( index ) ; ValueToValueMapTy :: iterator OpItr = clonedValueMap . find ( Op ) ; if ( OpItr != clonedValueMap . end ( ) ) Insn -> setOperand ( index , OpItr -> second ) ; } } } BasicBlock * Latch = OrigL -> getLoopLatch ( ) ; Function * F = Latch -> getParent ( ) ; BasicBlock * * ClonedBlBegin = & * ( ClonedBlocks . begin ( ) ) ; BasicBlock * * ClonedBlEnd = & * ( ClonedBlocks . end ( ) ) ; llvm :: iplist_impl < llvm :: simple_ilist < llvm :: BasicBlock > , llvm :: SymbolTableListTraits < llvm :: BasicBlock > > :: iterator it ( OrigL -> getLoopPreheader ( ) ) ; F -> getBasicBlockList ( ) . insert ( it , ClonedBlBegin , ClonedBlEnd ) ; return NewLoop ; }
Clone the loop and return the clone
 Most of this code comes from DOALLCloneLoop
Clone the loop and return the clone Most of this code comes from DOALLCloneLoop
// Create New Loop structure // Clone Basic Blocks. //LLVM_DEBUG(errs() << *ii << "\n"); /// Remember clonedHeader and clonedLoopExitingBB /*
         if (BB == Header)
         clonedHeader = NewBB;
         if (BB == loopExitingBB)
         clonedLoopExitingBB = NewBB;
         */ // Remap instructions to reference operands from ValueMap.