[llvm-dev] Difficulty in understanding loop analysis code
Fatima Ahmed via llvm-dev
llvm-dev at lists.llvm.org
Wed Dec 19 09:47:24 PST 2018
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.Thanks.
//Iteration on loops for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i)
{
Loop *L = *i;
int subloop = 1;
countLoop++;
static LLVMContext Context;
BasicBlock *parentLoopPred = L->getLoopPredecessor();
BasicBlock *parentLoopHead = L->getHeader();
std::vector<Loop*> 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);
SCounter1->insertAfter(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, "");
NValue1->insertAfter(CValue1);
Instruction *SNValue1 = new StoreInst(NValue1, ACounter1);
SNValue1->insertAfter(NValue1);
Value *PValue1 = SNValue1->getOperand(0);
std::vector<Value *> printArrayRef1;
Value *PValue12 = ConstantInt::get(Type::getInt32Ty(Context), subLoopAll.size(), true);
std::vector<Value *> printArrayRef12;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181219/3d5e1aee/attachment.html>
More information about the llvm-dev
mailing list