<html><head></head><body><div class="ydp3c622a41yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div id="ydp3c622a41yiv6182583524"><div><div class="ydp3c622a41yiv6182583524ydp76b50fd2yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div><span>Hey all!</span></div><div><span><br></span></div><div><span>I'm new to LLVM and advance C++.</span></div><div><span><br></span></div><div><span> I came across this piece of code and found it difficult to understand.<br></span></div><div><span><br></span></div><div><span>Can anyone please explain how is it working ? I want to get loop count, sub loop count etc printed as output.</span></div><div><span>Thanks.</span></div><div><br></div><div><span>//Iteration on loops</span></div><div><span></span></div><span>            for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i)<br>            {<br>                Loop *L = *i;<br>                int subloop = 1;<br>                countLoop++;<br>                <br>                static LLVMContext Context;<br>                BasicBlock *parentLoopPred = L->getLoopPredecessor();<br>                BasicBlock *parentLoopHead = L->getHeader();<br>                std::vector<Loop*> subLoopAll = L->getSubLoops();<br>                                <br>                Loop::iterator j, f;<br>                //Parent Loop Calculation<br>                //Counter = 0 instruction insertion<br>                // You must declare a constant Int like so instead of using it directly in a AllocaInst instantiation.<br>                ConstantInt *IntVal4 = ConstantInt::get(Type::getInt32Ty(Context), 4); // counter = 4<br>                Value *one1 = ConstantInt::get(Type::getInt32Ty(Context), -1, true);<br>                Instruction *ACounter1 = new AllocaInst(Type::getInt32Ty(Context), 0, IntVal4, "counter");  //(IntegerType::get(mContext, 32), one,    "counter", loopPredecessor);  //(IntegerType::get(mContext, 32), IR.getInt32(0), "counter");<br>                parentLoopPred->getInstList().insert(parentLoopPred->getFirstInsertionPt(), ACounter1);<br><br>                Instruction *SCounter1 = new StoreInst(one1, ACounter1);<br>                SCounter1->insertAfter(ACounter1);<br>                //Counter++ instruction insertion<br>                Value *IValue1 = ConstantInt::get(Type::getInt32Ty(Context), 1, true);<br>                Instruction *CValue1 = new LoadInst(ACounter1, "midCount");<br>                parentLoopHead->getInstList().insert(parentLoopHead->getFirstInsertionPt(), CValue1);<br>                Instruction *NValue1 = BinaryOperator::CreateNSWAdd(CValue1, IValue1, "incremented");//  Instruction::Add, CValue, IValue, "");<br>                NValue1->insertAfter(CValue1);<br>                Instruction *SNValue1 = new StoreInst(NValue1, ACounter1);<br>                SNValue1->insertAfter(NValue1);<br>                Value *PValue1 = SNValue1->getOperand(0);<br>                std::vector<Value *> printArrayRef1;<br>                Value *PValue12 = ConstantInt::get(Type::getInt32Ty(Context), subLoopAll.size(), true);<br></span><div><span>                std::vector<Value *> printArrayRef12;</span></div><div><span><br></span></div></div></div></div></div></body></html>