[llvm-dev] Integrating llvm pass with pass manager

702 views
Skip to first unread message

sangeeta chowdhary via llvm-dev

unread,
Jan 7, 2018, 7:02:35 PM1/7/18
to llvm...@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

陳韋任 via llvm-dev

unread,
Jan 11, 2018, 6:29:07 PM1/11/18
to sangeeta chowdhary, LLVM Developers Mailing List
`-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.

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev




--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj

sangeeta chowdhary via llvm-dev

unread,
Jan 11, 2018, 6:41:46 PM1/11/18
to 陳韋任, LLVM Developers Mailing List
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...@g2.nctu.edu.tw> wrote:

-mllvm

陳韋任 via llvm-dev

unread,
Jan 12, 2018, 10:00:00 PM1/12/18
to sangeeta chowdhary, LLVM Developers Mailing List
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 <sangitac...@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 

陳韋任 via llvm-dev

unread,
Jan 12, 2018, 10:40:35 PM1/12/18
to sangeeta chowdhary, LLVM Developers Mailing List
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));


Craig Topper via llvm-dev

unread,
Jan 12, 2018, 10:45:38 PM1/12/18
to 陳韋任, LLVM Developers Mailing List, sangeeta chowdhary
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.

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
~Craig

David Chisnall via llvm-dev

unread,
Jan 13, 2018, 7:35:38 AM1/13/18
to Craig Topper, LLVM Developers Mailing List, sangeeta chowdhary
On 13 Jan 2018, at 03:45, Craig Topper via llvm-dev <llvm...@lists.llvm.org> wrote:
>
> 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.

You need to use RegisterStandardPasses to add it to the default pipeline automatically. You can find an example here:

https://github.com/CompilerTeaching/SimplePass/blob/ba5248a9ea0bd9e1fab3b1f8a5c85d6e0db57acd/SimplePass.cc#L116

David

sangeeta chowdhary via llvm-dev

unread,
Jan 13, 2018, 7:14:39 PM1/13/18
to David Chisnall, LLVM Developers Mailing List
I have taken SimplePass and added in Transform directory, “libLLVMSimplePass.a” is built but I can not see this pass in opt —help. I don’t even see the name of pass while registering it in the example.

David Chisnall via llvm-dev

unread,
Jan 15, 2018, 8:21:56 AM1/15/18
to sangeeta chowdhary, LLVM Developers Mailing List
On 14 Jan 2018, at 00:14, sangeeta chowdhary <sangitac...@gmail.com> wrote:
>
> I have taken SimplePass and added in Transform directory, “libLLVMSimplePass.a” is built but I can not see this pass in opt —help. I don’t even see the name of pass while registering it in the example.

The SimplePass example is intended to be built out of tree, so I’ve no idea what happens if you try building it in tree. I wouldn’t expect to see it in the opt --help output, because it doesn’t define its own command-line options, it just adds itself to the default optimiser pipeline (at the end, and even if you’re running at -O0). You can see that it works by building it with its own CMake build system and then passing -Xclang -load -Xclang ./SimplePass.so to your clang command line.

sangeeta chowdhary via llvm-dev

unread,
Jan 15, 2018, 8:29:00 AM1/15/18
to David Chisnall, LLVM Developers Mailing List
Thats not what I am looking for. I want to run it with clang by just giving name of my pass. I have expalined it in my previous mail. 
Reply all
Reply to author
Forward
0 new messages