[llvm-dev] How to include a opt pass in clang driver

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] How to include a opt pass in clang driver

Muhui Jiang via llvm-dev
Hello,

I have written a pass for the IR and I can run it with opt -load lib/LLVMMyPass.so -mypass -myarguments -S -o output.ll < output.bc

I have registered my pass with the following code:
static RegisterPass<MyPass>
X("mypass", "MyPass Pass (with getAnalysisUsage implemented)");

How do I include the same pass in the clang driver. I tried running the pass:

clang output.c -o output -Xclang -load -Xclang lib/LLVMMyPass.so -mypass -myarguments

However, the pass is not being run as I cannot see output from my pass. What is the standard way to do it?

I have also tried approach described here: https://www.cs.cornell.edu/~asampson/blog/clangpass.html . It didn't work.

Regards,
Soham Sinha
PhD Student, Department of Computer Science
Boston University

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] How to include a opt pass in clang driver

Muhui Jiang via llvm-dev
On 6/25/2018 1:38 PM, Soham Sinha via llvm-dev wrote:

> Hello,
>
> I have written a pass for the IR and I can run it with opt -load
> lib/LLVMMyPass.so -mypass -myarguments -S -o output.ll < output.bc
>
> I have registered my pass with the following code:
> static RegisterPass<MyPass>
> X("mypass", "MyPass Pass (with getAnalysisUsage implemented)");
>
> How do I include the same pass in the clang driver. I tried running
> the pass:
>
> clang output.c -o output -Xclang -load -Xclang lib/LLVMMyPass.so
> -mypass -myarguments
>
> However, the pass is not being run as I cannot see output from my
> pass. What is the standard way to do it?

See RegisterStandardPasses in llvm/Transforms/IPO/PassManagerBuilder.h .

-Eli

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] How to include a opt pass in clang driver

Muhui Jiang via llvm-dev
Hi Eli,

I have tried that:

static void registerMyPass(const PassManagerBuilder &,
                                llvm::legacy::PassManagerBase &PM) {
       PM.add(new MyPass());
}

static RegisterStandardPasses
    RegisterMyPass(PassManagerBuilder::EP_OptimizerLast,
                          registerMyPass);

It still couldn't find my pass.


Regards,
Soham Sinha
PhD Student, Department of Computer Science
Boston University


On Mon, Jun 25, 2018 at 3:58 PM Friedman, Eli <[hidden email]> wrote:
On 6/25/2018 1:38 PM, Soham Sinha via llvm-dev wrote:
> Hello,
>
> I have written a pass for the IR and I can run it with opt -load
> lib/LLVMMyPass.so -mypass -myarguments -S -o output.ll < output.bc
>
> I have registered my pass with the following code:
> static RegisterPass<MyPass>
> X("mypass", "MyPass Pass (with getAnalysisUsage implemented)");
>
> How do I include the same pass in the clang driver. I tried running
> the pass:
>
> clang output.c -o output -Xclang -load -Xclang lib/LLVMMyPass.so
> -mypass -myarguments
>
> However, the pass is not being run as I cannot see output from my
> pass. What is the standard way to do it?

See RegisterStandardPasses in llvm/Transforms/IPO/PassManagerBuilder.h .

-Eli

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] How to include a opt pass in clang driver

Muhui Jiang via llvm-dev
On 6/25/2018 2:03 PM, Soham Sinha wrote:

> Hi Eli,
>
> I have tried that:
>
> static void registerMyPass(const PassManagerBuilder &,
> llvm::legacy::PassManagerBase &PM) {
>        PM.add(new MyPass());
> }
>
> static RegisterStandardPasses
>     RegisterMyPass(PassManagerBuilder::EP_OptimizerLast,
>                           registerMyPass);

OptimizerLast doesn't run unless you turn on optimizations (-O2). Maybe
that's the issue?

-Eli

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] How to include a opt pass in clang driver

Muhui Jiang via llvm-dev
Yeah it worked. Thank you so much! Correct command

clang output.c -o output -Xclang -load -Xclang lib/LLVMMyPass.so -mllvm -myarguments

Regards,
Soham Sinha
PhD Student, Department of Computer Science
Boston University


On Mon, Jun 25, 2018 at 4:21 PM Friedman, Eli <[hidden email]> wrote:
On 6/25/2018 2:03 PM, Soham Sinha wrote:
> Hi Eli,
>
> I have tried that:
>
> static void registerMyPass(const PassManagerBuilder &,
> llvm::legacy::PassManagerBase &PM) {
>        PM.add(new MyPass());
> }
>
> static RegisterStandardPasses
>     RegisterMyPass(PassManagerBuilder::EP_OptimizerLast,
>                           registerMyPass);

OptimizerLast doesn't run unless you turn on optimizations (-O2). Maybe
that's the issue?

-Eli

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev