Rinaldini Julien
2012-Apr-27 12:09 UTC
[LLVMdev] RE : Detect if a basicblock is part of a loop
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 GrandmaisonJust 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.brThx, 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. > > -HalI'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...
> 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.llWhat's the clang default opt level? Maybe you should use "-O0" explicitly. Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
Rinaldini Julien
2012-Apr-27 12:30 UTC
[LLVMdev] RE : RE : Detect if a basicblock is part of a loop
I got the same code with or without -O0 opt level It seems that clang default opt level is 0... Cheers ________________________________________ De : 陳韋任 [chenwj at iis.sinica.edu.tw] Date d'envoi : vendredi 27 avril 2012 14:14 À : Rinaldini Julien Cc: llvmdev at cs.uiuc.edu Objet : Re: [LLVMdev] RE : Detect if a basicblock is part of a loop> 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.llWhat's the clang default opt level? Maybe you should use "-O0" explicitly. Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
> 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.llThen you might need to past your main.c. Besides, is LLVMobfuscationTest.so your own pass? What does it do? Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
Rinaldini Julien
2012-Apr-27 12:52 UTC
[LLVMdev] RE : RE : Detect if a basicblock is part of a loop
This is my main.c (just a crappy test file): #include <stdlib.h> void foo() { foo(); } int main(int argc,char** argv) { int a = 1; int b = 3; int c = a+b; int k; for(k=0;k<10;++k) { // The loop I'm trying to detect int sdf = 123123; c++; } if(c - atoi(argv[1]) < 4) c = 0; else c = 1; return c; } The ir code corresponding to the loop: ; <label>:7 ; preds = %13, %0 %8 = load i32* %k, align 4 %9 = icmp slt i32 %8, 10 br i1 %9, label %10, label %16 ; <label>:10 ; preds = %7 store i32 123123, i32* %sdf, align 4 %11 = load i32* %c, align 4 %12 = add nsw i32 %11, 1 store i32 %12, i32* %c, align 4 br label %13 ; <label>:13 ; preds = %10 %14 = load i32* %k, align 4 %15 = add nsw i32 %14, 1 store i32 %15, i32* %k, align 4 br label %7> is LLVMobfuscationTest.so your own pass? What does it do?Yes it's my own lib... It contains some obfuscation's passes. The one I'm trying to make now is making code flattening! Cheers ps: I tried Cristianno Martins solution, but it didn't work too :( ________________________________________ De : 陳韋任 [chenwj at iis.sinica.edu.tw] Date d'envoi : vendredi 27 avril 2012 14:45 À : Rinaldini Julien Cc: llvmdev at cs.uiuc.edu Objet : Re: [LLVMdev] RE : Detect if a basicblock is part of a loop> 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.llThen you might need to past your main.c. Besides, is LLVMobfuscationTest.so your own pass? What does it do? Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
Seemingly Similar Threads
- [LLVMdev] RE : RE : RE : Detect if a basicblock is part of a loop
- [LLVMdev] RE : RE : Detect if a basicblock is part of a loop
- [LLVMdev] RE : Detect if a basicblock is part of a loop
- [LLVMdev] RE : Detect if a basicblock is part of a loop
- [LLVMdev] RE : Detect if a basicblock is part of a loop