sangeeta chowdhary via llvm-dev
2018-Jan-08 00:02 UTC
[llvm-dev] Integrating llvm pass with pass manager
Hello, I have followed steps given in - https://stackoverflow.com/questions/29910051/integrating-llvm-passes/48142693#48142693 <https://stackoverflow.com/questions/29910051/integrating-llvm-passes/48142693#48142693>, to integrate my pass with pass manager and run it with clang. I am able to run my pass with opt - opt -mypass but when I try to run it with clang, I always get an error - unknown argument: '-mypass'. Please help me for the same. I would be really grateful. Regards, Sangeeta -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180107/aee51816/attachment.html>
`-mypass` should be only recognize by the backend part (i.e. llvm). You should add `-mllvm` to tell clang the following argument have to be passed to the backend part. 2018-01-08 8:02 GMT+08:00 sangeeta chowdhary via llvm-dev < llvm-dev at lists.llvm.org>:> Hello, > > I have followed steps given in - https://stackoverflow.com/ > questions/29910051/integrating-llvm-passes/48142693#48142693, to > integrate my pass with pass manager and run it with clang. I am able to > run my pass with opt - opt -mypass but when I try to run it with clang, I > always get an error - unknown argument: '-mypass'. Please help me for the > same. I would be really grateful. > > Regards, > Sangeeta > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-- Wei-Ren Chen (陳韋任) Homepage: https://people.cs.nctu.edu.tw/~chenwj -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180112/1a7ca533/attachment.html>
sangeeta chowdhary via llvm-dev
2018-Jan-11 23:41 UTC
[llvm-dev] Integrating llvm pass with pass manager
Can you please tell me when I need to give this option and how. I am sorry I am new to this. Thank you so much for responding.> On Jan 11, 2018, at 6:28 PM, 陳韋任 <chenwj.cs97g at g2.nctu.edu.tw> wrote: > > -mllvm-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180111/d60a1351/attachment.html>
Do you pull clang under llvm/tools and compile it as well? In theory, if `opt` recognize the option, so does `clang -mllvm`. 2018-01-12 8:47 GMT+08:00 sangeeta chowdhary <sangitachowdhary at gmail.com>:> Hello, > > I have tried giving this option like this > > clang -c -emit-llvm -mllvm -rdetector hello.c -c -o hello.bc > but I am getting error " Unknown command line argument '-rdetector’.” > > Although same option work with opt - > opt -rdetector hello.ll > > > > On Jan 11, 2018, at 6:41 PM, sangeeta chowdhary < > sangitachowdhary at gmail.com> wrote: > > Can you please tell me when I need to give this option and how. I am sorry > I am new to this. Thank you so much for responding. > > On Jan 11, 2018, at 6:28 PM, 陳韋任 <chenwj.cs97g at g2.nctu.edu.tw> wrote: > > -mllvm > > > >-- Wei-Ren Chen (陳韋任) Homepage: https://people.cs.nctu.edu.tw/~chenwj -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180113/c9b780f5/attachment.html>
Look back to the SO link [1] you posted, I assume you register your pass by writing something like below already, INITIALIZE_PASS_BEGIN ... INITIALIZE_PASS_END ModulePass *llvm::createYourPass() { return new YourPass(); } The only suggestion I can give is looking at other existing pass to see what you might miss. For example, take a look on X86OptimizeLEAs.cpp. It works like the following ways. $ clang -mllvm -disable-x86-lea-opt test.c $ opt -disable-x86-lea-opt test.ll On the other hand, Mem2Reg.cpp fail to be used on clang. $ clang -mllvm -mem2reg test.c $ clang (LLVM option parsing): Unknown command line argument '-mem2reg'. Try: 'clang (LLVM option parsing) -help' I guess you need to implement the code below for your pass just like X86OptimizeLEAS.cpp does. static cl::opt<bool> DisableX86LEAOpt("disable-x86-lea-opt", cl::Hidden, cl::desc("X86: Disable LEA optimizations."), cl::init(false)); [1] https://stackoverflow.com/questions/29910051/integrating-llvm-passes/ 48142693#48142693 <https://www.google.com/url?q=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F29910051%2Fintegrating-llvm-passes%2F48142693%2348142693&sa=D&sntz=1&usg=AFQjCNEKxZuk7ahlWbtZwE0gXezqn29vNA> HTH, chenwj -- Wei-Ren Chen (陳韋任) Homepage: https://people.cs.nctu.edu.tw/~chenwj -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180113/2db0047e/attachment.html>
Craig Topper via llvm-dev
2018-Jan-13 03:45 UTC
[llvm-dev] Integrating llvm pass with pass manager
Clang doesn’t support adding passes from the command line the way opt does. Opt has special parsing in opt.cpp for this that clang doesn’t have. I’m not sure what the correct way to do this is. I think your plugin needs to do something to tell clang/llvm when to run the pass. I’ll try to look later when I’m back at a computer. On Fri, Jan 12, 2018 at 7:00 PM 陳韋任 via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Do you pull clang under llvm/tools and compile it as well? In theory, if > `opt` recognize the option, so does `clang -mllvm`. > > > 2018-01-12 8:47 GMT+08:00 sangeeta chowdhary <sangitachowdhary at gmail.com>: > >> Hello, >> >> I have tried giving this option like this >> >> clang -c -emit-llvm -mllvm -rdetector hello.c -c -o hello.bc >> but I am getting error " Unknown command line argument '-rdetector’.” >> >> Although same option work with opt - >> opt -rdetector hello.ll >> >> >> >> On Jan 11, 2018, at 6:41 PM, sangeeta chowdhary < >> sangitachowdhary at gmail.com> wrote: >> >> Can you please tell me when I need to give this option and how. I am >> sorry I am new to this. Thank you so much for responding. >> >> On Jan 11, 2018, at 6:28 PM, 陳韋任 <chenwj.cs97g at g2.nctu.edu.tw> wrote: >> >> -mllvm >> >> >> >> > -- > Wei-Ren Chen (陳韋任) > Homepage: https://people.cs.nctu.edu.tw/~chenwj > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- ~Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180113/d494228c/attachment.html>