Hello . I'm trying to implement FunctionPass for detecting loops in llvm IR. How can I get <condition> for loop from llvm::Loop object.? Is there any example? Thanks in advance, Edvard -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120723/85e7f2f9/attachment.html>
On 7/23/12 7:04 PM, Edvard Ghazaryan wrote:> > > Hello . > > I'm trying to implement FunctionPass for detecting loops in llvm IR.I think the LoopInfo analysis already locates loops.> How can I get <condition> for loop from llvm::Loop object.? > Is there any example? >I think one way to do this is to use the PostDominator pass to compute control-dependences for the loop and then find which basic block(s) are dependences for the loop entry basic block. The condition variable should be an argument to the terminator instruction of the basic block on which the loop entry block depends. -- John T.> Thanks in advance, > Edvard > > > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120724/5ef4552f/attachment.html>
Hello . I ran opt with -indvars options , got wrong result. This is my example: test.cc : int test(int a) { for (int i = 2; i < a; ++i) { a += ; } return a; } clang -O3 -emit-llvm -S test.cc -o test.ll opt -indvards -S test.ll -o indvars.ll > /dev/null indvars.ll : ; ModuleID = 'test.ll' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" target triple = "i386-pc-linux-gnu" define i32 @_Z4testi(i32 %a) nounwind readnone { entry: %cmp1 = icmp sgt i32 %a, 2 br i1 %cmp1, label %for.body.preheader, label %for.end for.body.preheader: ; preds = %entry br label %for.body for.body: ; preds = %for.body.preheader, %for.body %a.addr.03 = phi i32 [ %add, %for.body ], [ %a, %for.body.preheader ] //should start at 0 , I think there is no Canonicalize Induction Variable %i.02 = phi i32 [ %inc, %for.body ], [ 2, %for.body.preheader ] %add = add nsw i32 %a.addr.03, %i.02 %inc = add nsw i32 %i.02, 1 %cmp = icmp slt i32 %inc, %add br i1 %cmp, label %for.body, label %for.end.loopexit for.end.loopexit: ; preds = %for.body %add.lcssa = phi i32 [ %add, %for.body ] br label %for.end for.end: ; preds = %for.end.loopexit, %entry %a.addr.0.lcssa = phi i32 [ %a, %entry ], [ %add.lcssa, %for.end.loopexit ] ret i32 %a.addr.0.lcssa } Someone can explain why? Thanks in advance, Edvard -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120724/eee664d3/attachment.html>
Hello . opt -indvars pass does not generate canonical induction variable. (NULL == loop->getCanonicalInductionVariable();) PLEASE explain why? and how can I fix it? Thanks in advance, Edvard -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120724/92a28ed5/attachment.html>
On Jul 23, 2012, at 5:04 PM, Edvard Ghazaryan <edvard_gh at yahoo.com> wrote:> > > Hello . > > I'm trying to implement FunctionPass for detecting loops in llvm IR. > How can I get <condition> for loop from llvm::Loop object.? > Is there any example?I'm not sure I understand the question. Here are some tips. Loop::getLoopLatch() give you a canonical "latch" block if it exists. BasicBlock::getTerminator() gives you the branch. This is done throughout the code, so you can see the pattern. Loop::getExitingBlocks() gives you all the branches that may leave the loop. Or may want to do your own search for the "last" exit by following block predecessors from the loop header. -Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120725/c2cf1672/attachment.html>