Getting the trip count of a loop

Hi,

I am trying to add a new loop pass in which I making a call to get the trip count of the loop using

Value *TripCountValue = L->getTripCount()

However I am always getting NULL for TripCountValue (confirmed through gdb). I am running this pass after the canonicalization of induction variables:

opt --debug-pass=Structure -stats -indvars -loop-rotate -my-loop-pass < main.bc > main.unroll.s
Pass Arguments: -domtree -loops -scalar-evolution -loopsimplify -domfrontier -scalar-evolution -lcssa -indvars -loop-rotate -domfrontier -scalar-evolution -lcssa -my-loop-pass -preverify -domtree -verify
Target Data Layout
ModulePass Manager
FunctionPass Manager
Dominator Tree Construction
Natural Loop Construction
Scalar Evolution Analysis
– Scalar Evolution Analysis
Canonicalize natural loops
Dominance Frontier Construction
Scalar Evolution Analysis
Loop Pass Manager
Loop-Closed SSA Form Pass
Canonicalize Induction Variables
– Canonicalize Induction Variables
Rotate Loops
– Loop-Closed SSA Form Pass
– Rotate Loops
– Dominance Frontier Construction
– Scalar Evolution Analysis
Dominance Frontier Construction
Scalar Evolution Analysis
Loop Pass Manager
Loop-Closed SSA Form Pass


– Loop-Closed SSA Form Pass
– Natural Loop Construction
– Canonicalize natural loops
– Dominance Frontier Construction
– Dominator Tree Construction
– Scalar Evolution Analysis
Preliminary module verification
Dominator Tree Construction
Module Verifier
– Preliminary module verification
– Dominator Tree Construction
– Module Verifier
Bitcode Writer
– Bitcode Writer

I have two loops in my source program which have statically-determinable bounds:

for (i=1; i < 99999; i++)
{

}

Is there anything else I should be doing before invoking the getTripCount() method ?

thanks,
Prakash

Prakash Prabhu wrote:

I am trying to add a new loop pass in which I making a call to get the trip count of the loop using

Value *TripCountValue = L->getTripCount()

That should work.

Could you file a bug and attach the bytecode after 'opt -indvars -loop-rotate'? I would need that to determine why LoopInfo::getTripCount isn't returning any value.

Nick

Thanks for the quick reply. Created Bug 2253: http://llvm.org/bugs/show_bug.cgi?id=2253

  • Prakash