[LLVMdev] Questions about trip count

Douglas do Couto Teixeira douglasdocouto at gmail.com
Thu Aug 12 12:41:31 PDT 2010


Dear guys,

    I am having problems to obtain good information from the LoopInfo. I am
always getting a trip count of 0, even though I am clearly passing a loop
with a constant bound. I am using this pass below:

void testLoopInfo(const Function& F) const {
    const LoopInfo *LI = &getAnalysis<LoopInfo>();
    Function::const_iterator BB = F.begin(), E = F.end();
    for (; BB != E; ++BB) {
        const Loop* l = LI->getLoopFor(&*BB);
        if (l != NULL) {
            l->dump();
            errs() << "BB:\t" << BB->getNameStr() << "\n" ;
            errs() << "Is simplifyed loop?\t" << l->isLoopSimplifyForm() <<
"\n" ;
            errs() << "Tripcount " << l->getSmallConstantTripCount() << "\n"
;
            const PHINode* phi = l->getCanonicalInductionVariable();
            errs() << "Induction variable: " << *phi << "\n";
        }
    }
}

When I feed it with this program:
int main(int argc, char** argv) {
    int i = 0;
    for (; i < 4; i++) {
        int j = 0;
        for (; j < 8; j++) {
            printf("%c\n", argv[i][j]);
        }
    }
}

It prints the following info, where all the trip counts are zero. What am I
doing wrong?

Hello: main
Loop at depth 1 containing: %bb4<header><exiting>,%bb3<latch>,%bb2,%bb,%bb1
    Loop at depth 2 containing: %bb2<header><exiting>,%bb1<latch>
BB:    bb
Is simplifyed loop?    1
Tripcount 0
Induction variable: printing a <null> value

Loop at depth 2 containing: %bb2<header><exiting>,%bb1<latch>
BB:    bb1
Is simplifyed loop?    1
Tripcount 0
Induction variable: printing a <null> value

Loop at depth 2 containing: %bb2<header><exiting>,%bb1<latch>
BB:    bb2
Is simplifyed loop?    1
Tripcount 0
Induction variable: printing a <null> value

Loop at depth 1 containing: %bb4<header><exiting>,%bb3<latch>,%bb2,%bb,%bb1
    Loop at depth 2 containing: %bb2<header><exiting>,%bb1<latch>
BB:    bb3
Is simplifyed loop?    1
Tripcount 0
Induction variable: printing a <null> value

Loop at depth 1 containing: %bb4<header><exiting>,%bb3<latch>,%bb2,%bb,%bb1
    Loop at depth 2 containing: %bb2<header><exiting>,%bb1<latch>
BB:    bb4
Is simplifyed loop?    1
Tripcount 0
Induction variable: printing a <null> value

Regards,

Douglas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100812/b25f51e7/attachment.html>


More information about the llvm-dev mailing list