[llvm-dev] ScalarEvolution class returns no valid loop exit count

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] ScalarEvolution class returns no valid loop exit count

Alberto Barbaro via llvm-dev
Hi,

I have problems to estimate the loop exit count of a simple loop with the ScalarEvolution class.

simple loop:
......
    int a = 0;
    for(int i; i < 10; ++i){
        a = a + 1;
    };
......

For the loop analyzation I use the ScalarEvolution class with the following initialization:
......
void analysis(Function* func)

    DominatorTree DT = DominatorTree();
    DT.recalculate(*func);
    DT.updateDFSNumbers();
   
    LoopInfoBase<BasicBlock, Loop> LIB;
    LIB.releaseMemory();
    LIB.analyze(DT);
   
    for(auto&bb :*func){
        Loop * L = LIB.getLoopFor(&bb);
        if(L != nullptr){
            AssumptionCache AC = AssumptionCache(*bb.getParent());
            Triple MT(llvm::sys::getDefaultTargetTriple());
            TargetLibraryInfoImpl TLII(MT);
            TargetLibraryInfoWrapperPass TLI = TargetLibraryInfoWrapperPass(TLII);
           
            LoopInfo LI = LoopInfo(DT);
            LI.analyze(DT);
           
            ScalarEvolution SE = ScalarEvolution(*func, TLI.getTLI(),AC, DT, LI);
            BasicBlock * exitingblock = L->getUniqueExitBlock();
            const SCEV * exitingcount = SE.getExitCount (L,exitblock );
        }
    }
}
......

Unfortunately I get this result by printing the SCEV exitingcount variable:
***COULDNOTCOMPUTE***

It has been tested that the exitingblock of the loop was calculated successfully.
The LLVM IR is parsed and analysed without the usual pass framework. For this reason
the use of the getAnalysis<ScalarEvolution>() is not possible. The question is wether there
is something I`m doing wrong during the initialization of the ScalarEvolution class? Or is
the use of LLVM analysis classes without the passmanager framework not possible?

Best regards!
Benedikt



_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] ScalarEvolution class returns no valid loop exit count

Alberto Barbaro via llvm-dev
Are you sure exitingblock is not null?  This should probably be an
assert in getExitCount itself.

Other than that, SCEV normally expects that the loops have been
canonicalized and some basic optimizations have been performed.  How
are you obtaining the IR you're passing to analysis?

-- Sanjoy
On Tue, Nov 27, 2018 at 1:14 PM benedikt steinmeier via llvm-dev
<[hidden email]> wrote:

>
> Hi,
>
> I have problems to estimate the loop exit count of a simple loop with the ScalarEvolution class.
>
> simple loop:
> ......
>     int a = 0;
>     for(int i; i < 10; ++i){
>         a = a + 1;
>     };
> ......
>
> For the loop analyzation I use the ScalarEvolution class with the following initialization:
> ......
> void analysis(Function* func)
>     DominatorTree DT = DominatorTree();
>     DT.recalculate(*func);
>     DT.updateDFSNumbers();
>
>     LoopInfoBase<BasicBlock, Loop> LIB;
>     LIB.releaseMemory();
>     LIB.analyze(DT);
>
>     for(auto&bb :*func){
>         Loop * L = LIB.getLoopFor(&bb);
>         if(L != nullptr){
>             AssumptionCache AC = AssumptionCache(*bb.getParent());
>             Triple MT(llvm::sys::getDefaultTargetTriple());
>             TargetLibraryInfoImpl TLII(MT);
>             TargetLibraryInfoWrapperPass TLI = TargetLibraryInfoWrapperPass(TLII);
>
>             LoopInfo LI = LoopInfo(DT);
>             LI.analyze(DT);
>
>             ScalarEvolution SE = ScalarEvolution(*func, TLI.getTLI(),AC, DT, LI);
>             BasicBlock * exitingblock = L->getUniqueExitBlock();
>             const SCEV * exitingcount = SE.getExitCount (L,exitblock );
>         }
>     }
> }
> ......
>
> Unfortunately I get this result by printing the SCEV exitingcount variable:
> ***COULDNOTCOMPUTE***
>
> It has been tested that the exitingblock of the loop was calculated successfully.
> The LLVM IR is parsed and analysed without the usual pass framework. For this reason
> the use of the getAnalysis<ScalarEvolution>() is not possible. The question is wether there
> is something I`m doing wrong during the initialization of the ScalarEvolution class? Or is
> the use of LLVM analysis classes without the passmanager framework not possible?
>
> Best regards!
> Benedikt
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] ScalarEvolution class returns no valid loop exit count

Alberto Barbaro via llvm-dev
Hi Sanjoy,

the LLVM IR is parsed with following expression:
.......
string file = "....";
static LLVMContext cont;
SMDiagnostic diag;
unique_ptr<Module> module = parseIRFile(file, diag, cont);
.......

I mixed up the LLVM loop exit block with the loop exiting block in my analyses code. But after
resolving this issue, the exiting block is successfully determined:
......
BB1:                                              ; preds = %BB3, %BB0
  %3 = load i32, i32* %2, align 4
  %4 = icmp slt i32 %3, 10
  br i1 %4, label %BB2, label %BB4
.......

Nevertheless the loop exiting count can not be calculated with the ScalarEvolution class. I will try to
do the loop optimizations.

Many greetings
Benedikt





Am Di., 27. Nov. 2018 um 22:25 Uhr schrieb Sanjoy Das <[hidden email]>:
Are you sure exitingblock is not null?  This should probably be an
assert in getExitCount itself.

Other than that, SCEV normally expects that the loops have been
canonicalized and some basic optimizations have been performed.  How
are you obtaining the IR you're passing to analysis?

-- Sanjoy
On Tue, Nov 27, 2018 at 1:14 PM benedikt steinmeier via llvm-dev
<[hidden email]> wrote:
>
> Hi,
>
> I have problems to estimate the loop exit count of a simple loop with the ScalarEvolution class.
>
> simple loop:
> ......
>     int a = 0;
>     for(int i; i < 10; ++i){
>         a = a + 1;
>     };
> ......
>
> For the loop analyzation I use the ScalarEvolution class with the following initialization:
> ......
> void analysis(Function* func)
>     DominatorTree DT = DominatorTree();
>     DT.recalculate(*func);
>     DT.updateDFSNumbers();
>
>     LoopInfoBase<BasicBlock, Loop> LIB;
>     LIB.releaseMemory();
>     LIB.analyze(DT);
>
>     for(auto&bb :*func){
>         Loop * L = LIB.getLoopFor(&bb);
>         if(L != nullptr){
>             AssumptionCache AC = AssumptionCache(*bb.getParent());
>             Triple MT(llvm::sys::getDefaultTargetTriple());
>             TargetLibraryInfoImpl TLII(MT);
>             TargetLibraryInfoWrapperPass TLI = TargetLibraryInfoWrapperPass(TLII);
>
>             LoopInfo LI = LoopInfo(DT);
>             LI.analyze(DT);
>
>             ScalarEvolution SE = ScalarEvolution(*func, TLI.getTLI(),AC, DT, LI);
>             BasicBlock * exitingblock = L->getUniqueExitBlock();
>             const SCEV * exitingcount = SE.getExitCount (L,exitblock );
>         }
>     }
> }
> ......
>
> Unfortunately I get this result by printing the SCEV exitingcount variable:
> ***COULDNOTCOMPUTE***
>
> It has been tested that the exitingblock of the loop was calculated successfully.
> The LLVM IR is parsed and analysed without the usual pass framework. For this reason
> the use of the getAnalysis<ScalarEvolution>() is not possible. The question is wether there
> is something I`m doing wrong during the initialization of the ScalarEvolution class? Or is
> the use of LLVM analysis classes without the passmanager framework not possible?
>
> Best regards!
> Benedikt
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] ScalarEvolution class returns no valid loop exit count

Alberto Barbaro via llvm-dev
Your Loop *L is from a different LoopInfo object than the one you're giving to ScalarEvolution. So your SE doesn't know your loop, and can't tell you anything about it.

Cheers,
Philip

On Wed, Nov 28, 2018 at 2:26 PM benedikt steinmeier via llvm-dev <[hidden email]> wrote:
Hi Sanjoy,

the LLVM IR is parsed with following expression:
.......
string file = "....";
static LLVMContext cont;
SMDiagnostic diag;
unique_ptr<Module> module = parseIRFile(file, diag, cont);
.......

I mixed up the LLVM loop exit block with the loop exiting block in my analyses code. But after
resolving this issue, the exiting block is successfully determined:
......
BB1:                                              ; preds = %BB3, %BB0
  %3 = load i32, i32* %2, align 4
  %4 = icmp slt i32 %3, 10
  br i1 %4, label %BB2, label %BB4
.......

Nevertheless the loop exiting count can not be calculated with the ScalarEvolution class. I will try to
do the loop optimizations.

Many greetings
Benedikt





Am Di., 27. Nov. 2018 um 22:25 Uhr schrieb Sanjoy Das <[hidden email]>:
Are you sure exitingblock is not null?  This should probably be an
assert in getExitCount itself.

Other than that, SCEV normally expects that the loops have been
canonicalized and some basic optimizations have been performed.  How
are you obtaining the IR you're passing to analysis?

-- Sanjoy
On Tue, Nov 27, 2018 at 1:14 PM benedikt steinmeier via llvm-dev
<[hidden email]> wrote:
>
> Hi,
>
> I have problems to estimate the loop exit count of a simple loop with the ScalarEvolution class.
>
> simple loop:
> ......
>     int a = 0;
>     for(int i; i < 10; ++i){
>         a = a + 1;
>     };
> ......
>
> For the loop analyzation I use the ScalarEvolution class with the following initialization:
> ......
> void analysis(Function* func)
>     DominatorTree DT = DominatorTree();
>     DT.recalculate(*func);
>     DT.updateDFSNumbers();
>
>     LoopInfoBase<BasicBlock, Loop> LIB;
>     LIB.releaseMemory();
>     LIB.analyze(DT);
>
>     for(auto&bb :*func){
>         Loop * L = LIB.getLoopFor(&bb);
>         if(L != nullptr){
>             AssumptionCache AC = AssumptionCache(*bb.getParent());
>             Triple MT(llvm::sys::getDefaultTargetTriple());
>             TargetLibraryInfoImpl TLII(MT);
>             TargetLibraryInfoWrapperPass TLI = TargetLibraryInfoWrapperPass(TLII);
>
>             LoopInfo LI = LoopInfo(DT);
>             LI.analyze(DT);
>
>             ScalarEvolution SE = ScalarEvolution(*func, TLI.getTLI(),AC, DT, LI);
>             BasicBlock * exitingblock = L->getUniqueExitBlock();
>             const SCEV * exitingcount = SE.getExitCount (L,exitblock );
>         }
>     }
> }
> ......
>
> Unfortunately I get this result by printing the SCEV exitingcount variable:
> ***COULDNOTCOMPUTE***
>
> It has been tested that the exitingblock of the loop was calculated successfully.
> The LLVM IR is parsed and analysed without the usual pass framework. For this reason
> the use of the getAnalysis<ScalarEvolution>() is not possible. The question is wether there
> is something I`m doing wrong during the initialization of the ScalarEvolution class? Or is
> the use of LLVM analysis classes without the passmanager framework not possible?
>
> Best regards!
> Benedikt
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev