Hi Shahzad,> Is it possible that we can use LLVM optimization beside O1, O2, O3 > along with dragonegg plugin?sure, try this: gcc -fplugin=path/dragonegg.so ...other_options_here... -S -o - -fplugin-arg-dragonegg-emit-ir -fplugin-arg-dragonegg-llvm-ir-optimize=0 | opt -pass1 -pass2 ... Here -fplugin-arg-dragonegg-emit-ir tells it to output LLVM IR rather than target assembler. You can also use -flto here. -fplugin-arg-dragonegg-llvm-ir-optimize=0 disables the standard set of LLVM optimizations. In general, if a front-end can produce LLVM IR then you can do this, by outputting the IR and passing it to "opt". Ciao, Duncan.> > Regards > > Shahzad > > On Thu, Jun 7, 2012 at 10:59 PM, Abdul Wahid Memon > <engrwahidmemon at gmail.com> wrote: >> Thanks alot Chad for these quick and fine responses. >> >> Regards >> >> Abdul >> >> On Thu, Jun 7, 2012 at 10:57 PM, Chad Rosier<mcrosier at apple.com> wrote: >>> >>> On Jun 7, 2012, at 1:53 PM, Abdul Wahid Memon wrote: >>> >>>> Thanks again chad. One more question please. >>>> >>>> Is it possible that I can use these optimization using dragonegg plugin somehow? >>> >>> I haven't a clue. Maybe Duncan can answer that? >>> >>> Chad >>> >>>> >>>> Regards >>>> >>>> Shahzad >>>> >>>> On Thu, Jun 7, 2012 at 10:51 PM, Chad Rosier<mcrosier at apple.com> wrote: >>>>> >>>>> On Jun 7, 2012, at 1:48 PM, Abdul Wahid Memon wrote: >>>>> >>>>>> On Thu, Jun 7, 2012 at 10:44 PM, Chad Rosier<mcrosier at apple.com> wrote: >>>>>>> >>>>>>> On Jun 7, 2012, at 1:39 PM, Abdul Wahid Memon wrote: >>>>>>> >>>>>>>> Thanks alot Chad for quick response. Does this means that, we can not >>>>>>>> use LLVM optimizations except O1, O2, O3, O4 and unroll-loops with >>>>>>>> clang? >>>>>>> >>>>>>> Try using the -debug-pass=Arguments options to see what passes are being run at each optimization level. >>>>>> Yes, I have seen those optimization but I want to disable all the >>>>>> default optimization (-O0) and specify them individually to test their >>>>>> effect. >>>>> >>>>> 1. Generate the bitcode/ir with -O0 >>>>> 2. Run opt with the optimization in question. You should be able to specify most any pass with opt. >>>>> >>>>>>> >>>>>>> E.g., >>>>>>> clang -O[0-3] -mllvm -debug-pass=Arguments foo.c. >>>>>>> >>>>>>>> >>>>>>>> One more thing I would like to know that If I want to process multiple >>>>>>>> modules with opt at the same time like >>>>>>>> >>>>>>>> opt -adce *.bc >>>>>>> >>>>>>> I don't think this will work. >>>>>>> >>>>>> ok. >>>>>>>> >>>>>>>> then how is it possible with opt in one go, if I process all the >>>>>>>> bytecode files within Makefile. >>>>>>> >>>>>>> You should be able to define a rule in the Makefile to compile your bitcode/IR files. >>>>>> ok. I got the point. >>>>>> >>>>>> Thanks alot >>>>>> >>>>>> Shahzad >>>>>>> >>>>>>> Chad >>>>>>> >>>>>>>> >>>>>>>> Thanks. >>>>>>>> >>>>>>>> Shahzad >>>>>>>> >>>>>>>> On Thu, Jun 7, 2012 at 9:22 PM, Chad Rosier<mcrosier at apple.com> wrote: >>>>>>>>> >>>>>>>>> On Jun 7, 2012, at 10:59 AM, Abdul Wahid Memon wrote: >>>>>>>>> >>>>>>>>>> Hello everyone >>>>>>>>>> >>>>>>>>>> I am trying to use some LLVM optimizations like -die or -adce. Is it >>>>>>>>>> possible to use them along clang? >>>>>>>>>> >>>>>>>>>> Or is there a way where these optimization can be passed on to "opt" >>>>>>>>>> tool through clang, if opt is being used by clang behind the scenes? >>>>>>>>>> >>>>>>>>> >>>>>>>>> No, opt only works on llvm IR/bitcode. You can generate it like this: >>>>>>>>> clang -c foo.c -emit-llvm -o foo.bc >>>>>>>>> or >>>>>>>>> clang -S foo.c -emit-llvm -o foo.ll >>>>>>>>> >>>>>>>>> Then you can run the optimization(s): >>>>>>>>> opt -adce foo.bc -o foo-adce.bc >>>>>>>>> >>>>>>>>> Then you can compile using clang >>>>>>>>> clang -c foo-adce.bc -o foo-adce.o >>>>>>>>> >>>>>>>>> Chad >>>>>>>>> >>>>>>>>>> Thanks alot >>>>>>>>>> >>>>>>>>>> Regards >>>>>>>>>> >>>>>>>>>> Shahzad >>>>>>>>>> _______________________________________________ >>>>>>>>>> LLVM Developers mailing list >>>>>>>>>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>>>>>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>>>>>>>> >>>>>>> >>>>> >>>
Abdul Wahid Memon
2012-Jun-08 10:26 UTC
[LLVMdev] How to use LLVM optimizations with clang
Hello Duncan I tried your method and it works fine. What would be the next step to produce the final executable? I have tried the following but it is producing an error $ gcc -fplugin=/path/to/dragonegg.so -S *.c -fplugin-arg-dragonegg-emit-ir | opt -adce $ clang *.s Regards Shahzad On Fri, Jun 8, 2012 at 9:10 AM, Duncan Sands <baldrick at free.fr> wrote:> Hi Shahzad, > > >> Is it possible that we can use LLVM optimization beside O1, O2, O3 >> along with dragonegg plugin? > > > sure, try this: > > gcc -fplugin=path/dragonegg.so ...other_options_here... -S -o - > -fplugin-arg-dragonegg-emit-ir -fplugin-arg-dragonegg-llvm-ir-optimize=0 | > opt -pass1 -pass2 ... > > Here -fplugin-arg-dragonegg-emit-ir tells it to output LLVM IR rather than > target assembler. You can also use -flto here. > > -fplugin-arg-dragonegg-llvm-ir-optimize=0 disables the standard set of LLVM > optimizations. > > In general, if a front-end can produce LLVM IR then you can do this, by > outputting the IR and passing it to "opt". > > Ciao, Duncan. > > >> >> Regards >> >> Shahzad >> >> On Thu, Jun 7, 2012 at 10:59 PM, Abdul Wahid Memon >> <engrwahidmemon at gmail.com> wrote: >>> >>> Thanks alot Chad for these quick and fine responses. >>> >>> Regards >>> >>> Abdul >>> >>> On Thu, Jun 7, 2012 at 10:57 PM, Chad Rosier<mcrosier at apple.com> wrote: >>>> >>>> >>>> On Jun 7, 2012, at 1:53 PM, Abdul Wahid Memon wrote: >>>> >>>>> Thanks again chad. One more question please. >>>>> >>>>> Is it possible that I can use these optimization using dragonegg plugin >>>>> somehow? >>>> >>>> >>>> I haven't a clue. Maybe Duncan can answer that? >>>> >>>> Chad >>>> >>>>> >>>>> Regards >>>>> >>>>> Shahzad >>>>> >>>>> On Thu, Jun 7, 2012 at 10:51 PM, Chad Rosier<mcrosier at apple.com> >>>>> wrote: >>>>>> >>>>>> >>>>>> On Jun 7, 2012, at 1:48 PM, Abdul Wahid Memon wrote: >>>>>> >>>>>>> On Thu, Jun 7, 2012 at 10:44 PM, Chad Rosier<mcrosier at apple.com> >>>>>>> wrote: >>>>>>>> >>>>>>>> >>>>>>>> On Jun 7, 2012, at 1:39 PM, Abdul Wahid Memon wrote: >>>>>>>> >>>>>>>>> Thanks alot Chad for quick response. Does this means that, we can >>>>>>>>> not >>>>>>>>> use LLVM optimizations except O1, O2, O3, O4 and unroll-loops with >>>>>>>>> clang? >>>>>>>> >>>>>>>> >>>>>>>> Try using the -debug-pass=Arguments options to see what passes are >>>>>>>> being run at each optimization level. >>>>>>> >>>>>>> Yes, I have seen those optimization but I want to disable all the >>>>>>> default optimization (-O0) and specify them individually to test >>>>>>> their >>>>>>> effect. >>>>>> >>>>>> >>>>>> 1. Generate the bitcode/ir with -O0 >>>>>> 2. Run opt with the optimization in question. You should be able to >>>>>> specify most any pass with opt. >>>>>> >>>>>>>> >>>>>>>> E.g., >>>>>>>> clang -O[0-3] -mllvm -debug-pass=Arguments foo.c. >>>>>>>> >>>>>>>>> >>>>>>>>> One more thing I would like to know that If I want to process >>>>>>>>> multiple >>>>>>>>> modules with opt at the same time like >>>>>>>>> >>>>>>>>> opt -adce *.bc >>>>>>>> >>>>>>>> >>>>>>>> I don't think this will work. >>>>>>>> >>>>>>> ok. >>>>>>>>> >>>>>>>>> >>>>>>>>> then how is it possible with opt in one go, if I process all the >>>>>>>>> bytecode files within Makefile. >>>>>>>> >>>>>>>> >>>>>>>> You should be able to define a rule in the Makefile to compile your >>>>>>>> bitcode/IR files. >>>>>>> >>>>>>> ok. I got the point. >>>>>>> >>>>>>> Thanks alot >>>>>>> >>>>>>> Shahzad >>>>>>>> >>>>>>>> >>>>>>>> Chad >>>>>>>> >>>>>>>>> >>>>>>>>> Thanks. >>>>>>>>> >>>>>>>>> Shahzad >>>>>>>>> >>>>>>>>> On Thu, Jun 7, 2012 at 9:22 PM, Chad Rosier<mcrosier at apple.com> >>>>>>>>> wrote: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Jun 7, 2012, at 10:59 AM, Abdul Wahid Memon wrote: >>>>>>>>>> >>>>>>>>>>> Hello everyone >>>>>>>>>>> >>>>>>>>>>> I am trying to use some LLVM optimizations like -die or -adce. Is >>>>>>>>>>> it >>>>>>>>>>> possible to use them along clang? >>>>>>>>>>> >>>>>>>>>>> Or is there a way where these optimization can be passed on to >>>>>>>>>>> "opt" >>>>>>>>>>> tool through clang, if opt is being used by clang behind the >>>>>>>>>>> scenes? >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> No, opt only works on llvm IR/bitcode. You can generate it like >>>>>>>>>> this: >>>>>>>>>> clang -c foo.c -emit-llvm -o foo.bc >>>>>>>>>> or >>>>>>>>>> clang -S foo.c -emit-llvm -o foo.ll >>>>>>>>>> >>>>>>>>>> Then you can run the optimization(s): >>>>>>>>>> opt -adce foo.bc -o foo-adce.bc >>>>>>>>>> >>>>>>>>>> Then you can compile using clang >>>>>>>>>> clang -c foo-adce.bc -o foo-adce.o >>>>>>>>>> >>>>>>>>>> Chad >>>>>>>>>> >>>>>>>>>>> Thanks alot >>>>>>>>>>> >>>>>>>>>>> Regards >>>>>>>>>>> >>>>>>>>>>> Shahzad >>>>>>>>>>> _______________________________________________ >>>>>>>>>>> LLVM Developers mailing list >>>>>>>>>>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>>>>>>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>>>>>>>>> >>>>>>>>>> >>>>>>>> >>>>>> >>>> >
Hi Shahzad,> I tried your method and it works fine. What would be the next step to > produce the final executable? I have tried the following but it is > producing an error > > $ gcc -fplugin=/path/to/dragonegg.so -S *.c > -fplugin-arg-dragonegg-emit-ir | opt -adcethis won't work because you aren't passing the IR to opt (you need -o - for that if using a pipe) and you aren't doing anything with opt output. What's more, you are trying to compile multiple files at once. Probably something like this would work: for F in *.c ; do B=`basename $F .c` ; gcc -fplugin=/path/to/dragonegg.so -S -o - $F -fplugin-arg-dragonegg-emit-ir | opt -adce -o $B.ll ; done clang *.ll Ciao, Duncan.> > $ clang *.s > > Regards > > Shahzad > > On Fri, Jun 8, 2012 at 9:10 AM, Duncan Sands<baldrick at free.fr> wrote: >> Hi Shahzad, >> >> >>> Is it possible that we can use LLVM optimization beside O1, O2, O3 >>> along with dragonegg plugin? >> >> >> sure, try this: >> >> gcc -fplugin=path/dragonegg.so ...other_options_here... -S -o - >> -fplugin-arg-dragonegg-emit-ir -fplugin-arg-dragonegg-llvm-ir-optimize=0 | >> opt -pass1 -pass2 ... >> >> Here -fplugin-arg-dragonegg-emit-ir tells it to output LLVM IR rather than >> target assembler. You can also use -flto here. >> >> -fplugin-arg-dragonegg-llvm-ir-optimize=0 disables the standard set of LLVM >> optimizations. >> >> In general, if a front-end can produce LLVM IR then you can do this, by >> outputting the IR and passing it to "opt". >> >> Ciao, Duncan. >> >> >>> >>> Regards >>> >>> Shahzad >>> >>> On Thu, Jun 7, 2012 at 10:59 PM, Abdul Wahid Memon >>> <engrwahidmemon at gmail.com> wrote: >>>> >>>> Thanks alot Chad for these quick and fine responses. >>>> >>>> Regards >>>> >>>> Abdul >>>> >>>> On Thu, Jun 7, 2012 at 10:57 PM, Chad Rosier<mcrosier at apple.com> wrote: >>>>> >>>>> >>>>> On Jun 7, 2012, at 1:53 PM, Abdul Wahid Memon wrote: >>>>> >>>>>> Thanks again chad. One more question please. >>>>>> >>>>>> Is it possible that I can use these optimization using dragonegg plugin >>>>>> somehow? >>>>> >>>>> >>>>> I haven't a clue. Maybe Duncan can answer that? >>>>> >>>>> Chad >>>>> >>>>>> >>>>>> Regards >>>>>> >>>>>> Shahzad >>>>>> >>>>>> On Thu, Jun 7, 2012 at 10:51 PM, Chad Rosier<mcrosier at apple.com> >>>>>> wrote: >>>>>>> >>>>>>> >>>>>>> On Jun 7, 2012, at 1:48 PM, Abdul Wahid Memon wrote: >>>>>>> >>>>>>>> On Thu, Jun 7, 2012 at 10:44 PM, Chad Rosier<mcrosier at apple.com> >>>>>>>> wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> On Jun 7, 2012, at 1:39 PM, Abdul Wahid Memon wrote: >>>>>>>>> >>>>>>>>>> Thanks alot Chad for quick response. Does this means that, we can >>>>>>>>>> not >>>>>>>>>> use LLVM optimizations except O1, O2, O3, O4 and unroll-loops with >>>>>>>>>> clang? >>>>>>>>> >>>>>>>>> >>>>>>>>> Try using the -debug-pass=Arguments options to see what passes are >>>>>>>>> being run at each optimization level. >>>>>>>> >>>>>>>> Yes, I have seen those optimization but I want to disable all the >>>>>>>> default optimization (-O0) and specify them individually to test >>>>>>>> their >>>>>>>> effect. >>>>>>> >>>>>>> >>>>>>> 1. Generate the bitcode/ir with -O0 >>>>>>> 2. Run opt with the optimization in question. You should be able to >>>>>>> specify most any pass with opt. >>>>>>> >>>>>>>>> >>>>>>>>> E.g., >>>>>>>>> clang -O[0-3] -mllvm -debug-pass=Arguments foo.c. >>>>>>>>> >>>>>>>>>> >>>>>>>>>> One more thing I would like to know that If I want to process >>>>>>>>>> multiple >>>>>>>>>> modules with opt at the same time like >>>>>>>>>> >>>>>>>>>> opt -adce *.bc >>>>>>>>> >>>>>>>>> >>>>>>>>> I don't think this will work. >>>>>>>>> >>>>>>>> ok. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> then how is it possible with opt in one go, if I process all the >>>>>>>>>> bytecode files within Makefile. >>>>>>>>> >>>>>>>>> >>>>>>>>> You should be able to define a rule in the Makefile to compile your >>>>>>>>> bitcode/IR files. >>>>>>>> >>>>>>>> ok. I got the point. >>>>>>>> >>>>>>>> Thanks alot >>>>>>>> >>>>>>>> Shahzad >>>>>>>>> >>>>>>>>> >>>>>>>>> Chad >>>>>>>>> >>>>>>>>>> >>>>>>>>>> Thanks. >>>>>>>>>> >>>>>>>>>> Shahzad >>>>>>>>>> >>>>>>>>>> On Thu, Jun 7, 2012 at 9:22 PM, Chad Rosier<mcrosier at apple.com> >>>>>>>>>> wrote: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> On Jun 7, 2012, at 10:59 AM, Abdul Wahid Memon wrote: >>>>>>>>>>> >>>>>>>>>>>> Hello everyone >>>>>>>>>>>> >>>>>>>>>>>> I am trying to use some LLVM optimizations like -die or -adce. Is >>>>>>>>>>>> it >>>>>>>>>>>> possible to use them along clang? >>>>>>>>>>>> >>>>>>>>>>>> Or is there a way where these optimization can be passed on to >>>>>>>>>>>> "opt" >>>>>>>>>>>> tool through clang, if opt is being used by clang behind the >>>>>>>>>>>> scenes? >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> No, opt only works on llvm IR/bitcode. You can generate it like >>>>>>>>>>> this: >>>>>>>>>>> clang -c foo.c -emit-llvm -o foo.bc >>>>>>>>>>> or >>>>>>>>>>> clang -S foo.c -emit-llvm -o foo.ll >>>>>>>>>>> >>>>>>>>>>> Then you can run the optimization(s): >>>>>>>>>>> opt -adce foo.bc -o foo-adce.bc >>>>>>>>>>> >>>>>>>>>>> Then you can compile using clang >>>>>>>>>>> clang -c foo-adce.bc -o foo-adce.o >>>>>>>>>>> >>>>>>>>>>> Chad >>>>>>>>>>> >>>>>>>>>>>> Thanks alot >>>>>>>>>>>> >>>>>>>>>>>> Regards >>>>>>>>>>>> >>>>>>>>>>>> Shahzad >>>>>>>>>>>> _______________________________________________ >>>>>>>>>>>> LLVM Developers mailing list >>>>>>>>>>>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>>>>>>>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>> >>>>>>> >>>>> >>