Difficulty in understanding loop analysis code

Hey all!

I’m new to LLVM and advance C++.

I came across this piece of code and found it difficult to understand.

Can anyone please explain how is it working ? I want to get loop count, sub loop count etc printed as output.

//Iteration on loops

for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i)
Loop *L = *i;
int subloop = 1;

static LLVMContext Context;
BasicBlock *parentLoopPred = L->getLoopPredecessor();
BasicBlock parentLoopHead = L->getHeader();
> subLoopAll = L->getSubLoops();

Loop::iterator j, f;
//Parent Loop Calculation
//Counter = 0 instruction insertion
// You must declare a constant Int like so instead of using it directly in a AllocaInst instantiation.
ConstantInt *IntVal4 = ConstantInt::get(Type::getInt32Ty(Context), 4); // counter = 4
Value *one1 = ConstantInt::get(Type::getInt32Ty(Context), -1, true);
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”);
parentLoopPred->getInstList().insert(parentLoopPred->getFirstInsertionPt(), ACounter1);

Instruction *SCounter1 = new StoreInst(one1, ACounter1);
//Counter++ instruction insertion
Value *IValue1 = ConstantInt::get(Type::getInt32Ty(Context), 1, true);
Instruction *CValue1 = new LoadInst(ACounter1, “midCount”);
parentLoopHead->getInstList().insert(parentLoopHead->getFirstInsertionPt(), CValue1);
Instruction *NValue1 = BinaryOperator::CreateNSWAdd(CValue1, IValue1, “incremented”);// Instruction::Add, CValue, IValue, “”);
Instruction *SNValue1 = new StoreInst(NValue1, ACounter1);
Value *PValue1 = SNValue1->getOperand(0);
std::vector<Value *> printArrayRef1;
Value *PValue12 = ConstantInt::get(Type::getInt32Ty(Context), subLoopAll.size(), true);

std::vector<Value *> printArrayRef12;