[llvm-dev] ModulePass cannot be registered as EarlyAsPossible

Bevin Hansson via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 13 07:01:48 PDT 2018


Hi,

EP_EarlyAsPossible only works with FunctionPasses, yes. If you look at 
how it's used in PassManagerBuilder, it is only invoked from 
populateFunctionPassManager.

The earliest you can add ModulePasses is with EP_ModuleOptimizerEarly. 
However, those passes are not added on O0. If the OptLevel is 0, you can 
instead add the passes to EP_EnabledOnOptLevel0.

This might not be early enough for you, but those are the points that 
are available for module passes as far as I know.

Regards,
Bevin


On 2018-06-12 15:46, Son Tuan VU via llvm-dev wrote:
> Hello all,
>
> I've followed the example in 
> https://github.com/CompilerTeaching/SimplePass/blob/master/SimplePass.cc 
> in order to create a custom pass.
>
> The pass needs to be added before any transformation, so I used 
> EP_EarlyAsPossible extension point to register it. Furthermore, I need 
> to access to every GlobalVariable in the IR, so my pass has to be a 
> ModulePass, like this:
>
>   struct MyPass : public ModulePass {
>      static char ID;
>      MyPass(): ModulePass(ID) {}
>      virtual bool runOnModule(Module &M) {...}
>   ...
>   }
>
> However, every time I try to access to the Module object M inside 
> runOnModule(), clang just crashes.  Even a debug message like *outs() 
> << M.getName() << '\n';* would cause a segfault. So am I doing 
> something wrong, like EP_EarlyAsPossible is really not to be used with 
> ModulePasses, or is this rather a bug?
>
> In case this is not a bug, what would be the best way to manipulate an 
> IR Module as it is coming right out of the frontend?
>
> Thanks for your help,
>
> Son Tuan Vu
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180613/0d01234b/attachment.html>


More information about the llvm-dev mailing list