[LLVMdev] RE : Detect if a basicblock is part of a loop

Rinaldini Julien
Fri, 27 Apr 2012 12:09:38 -0000

Thx all for the quick answers...

> De : llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] de la
part de Arnaud ALLARD DE GRANDMAISON [arnaud.allarddegrandmaison at parrot.com]
>
> Hi,
>
> Depending on what have run before your pass, the loop may have been
unrolled or simplified if the computation inside the loop is too simple.
>
> Cheers,
> --
> Arnaud de Grandmaison

Just as I said to Hal, nothing else than:
$ clang -emit-llvm -S -o main.ll main.c
$ ../build/Release/bin/opt -load ../build/Release/lib/LLVMobfuscationTest.so
-flattening -S main.ll -o main.opt.ll

> From: llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] On
Behalf Of Cristianno Martins [cristiannomartins at gmail.com]

> Hi Rinaldini,
>
> In order to find information about loops inside a given function you should
use something like "LoopInfo *LI =
P->getAnalysis<LoopInfo>()", remembering to add
"AU.addRequired<LoopInfo>();" to your getAnalysisUsage method.
>
> If the function you are interested to is not located in the module being
compiled (if you created it as an auxiliary function, for example), you could
create this information by simply creating a DominatorTreeBase of your function
and using it to calculate the LoopInfo, as below:
>     DominatorTreeBase<BasicBlock> *DTB;
>     DTB = new DominatorTreeBase<BasicBlock>(false);
>     DTB->recalculate(*AuxFunction);
>
>     LoopInfoBase<BasicBlock, Loop> LIB;
>     LIB.Calculate(*DTB);
>
> Cheers,

> --
> Cristianno Martins
> PhD Student of Computer Science
> University of Campinas
> cmartins at ic.unicamp.br

Thx, I'll try that... I guess I missed the Dominator step last time

> On Thursday, 26 de April de 2012 at 11:57, Hal Finkel wrote:
>
> Rinaldini,
>
> What exactly did you run? Specifically, you may be missing some
> analysis passes that are necessary for LoopInfo to have the loop
> information you desire.
>
> -Hal

I'm running opt with my lib on a ir code emmitted by clang: $ clang
-emit-llvm -S -o main.ll main.c
and opt: $ ../build/Release/bin/opt -load
../build/Release/lib/LLVMobfuscationTest.so -flattening -S main.ll -o
main.opt.ll

No others optimization applied...