Juneyoung Lee via llvm-dev
2019-Dec-03 17:01 UTC
[llvm-dev] Adding custom callback function before/after passes
Hello all, Is there a way to register callback that runs before/after passes? PassTimingInfo seems to do a similar thing by calling PassInstrumentationCallbacks::registerBeforePassCallback / registerAfterPassCallback, but it is hard-wired with StandardInstrumentations class. Do we have something similar to RegisterStandardPasses, so custom callbacks can be added from somewhere outside LLVM? Thanks, Juneyoung Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191204/1a07f148/attachment.html>
Neil Henning via llvm-dev
2019-Dec-03 17:20 UTC
[llvm-dev] Adding custom callback function before/after passes
If you are using the legacy PassManager and control when the PassManager is created, you can do this with a little hack like: struct MyPassManager final : llvm::legacy::PassManager { void add(llvm::Pass* const pass) override { // Add your own pass which does a before callback llvm::legacy::PassManager::add(your_start_pass(pass)); // Add the originally requested pass llvm::legacy::PassManager::add(pass); // Add your own pass which does an after callback llvm::legacy::PassManager::add(your_end_pass(pass)); } } passManager; // add new passes to this pass manager! I've used this hack in the past (it is also something similar to how opt lets you bail out on a certain pass). Cheers, -Neil. On Tue, Dec 3, 2019 at 5:02 PM Juneyoung Lee via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello all, > > Is there a way to register callback that runs before/after passes? > PassTimingInfo seems to do a similar thing by calling > PassInstrumentationCallbacks::registerBeforePassCallback / > registerAfterPassCallback, but it is hard-wired with > StandardInstrumentations class. > Do we have something similar to RegisterStandardPasses, so custom > callbacks can be added from somewhere outside LLVM? > > Thanks, > Juneyoung Lee > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Neil Henning Senior Software Engineer Compiler unity.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191203/8fa90895/attachment.html>
Fedor Sergeev via llvm-dev
2019-Dec-11 15:44 UTC
[llvm-dev] Adding custom callback function before/after passes
On 12/3/19 8:01 PM, Juneyoung Lee via llvm-dev wrote:> Hello all, > > Is there a way to register callback that runs before/after passes? > PassTimingInfo seems to do a similar thing by calling > PassInstrumentationCallbacks::registerBeforePassCallback / > registerAfterPassCallback, but it is hard-wired with > StandardInstrumentations class.PassInstrumentation framework was introduced to the new PassManager specifically in mind with ability to register arbitrary callbacks and execute them as pass manager traverses through the pass pipeline. PassInstrumentationCallbacks are indeed the entity to register your callbacks into, before passing it to PassBuilder; You can check how it is being done in `llvm/tools/opt/NewPMDriver.cpp`llvm::runPassPipeline. StandardInstrumentations are just a few "standard" callbacks that provide "standard" functionality, like -print-after-all or -time-passes. StandardInstrumentations registers its individual instrumentations the same way you would register your own. Note, that PassInstrumentation is only supported in new pass manager (opt -passes= or clang -fexperimental-new-pass-manager). regards, Fedor.> Do we have something similar to RegisterStandardPasses, so custom > callbacks can be added from somewhere outside LLVM? > > Thanks, > Juneyoung Lee > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://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/20191211/51f9675d/attachment.html>
Juneyoung Lee via llvm-dev
2019-Dec-12 00:50 UTC
[llvm-dev] Adding custom callback function before/after passes
Hello Fedor. Thank you for the information. I made a simple patch that exposes PassInstrumentationCallback so llvmGetPassPluginInfo can use it: https://reviews.llvm.org/D71086 . Would this change make sense? Thanks, Juneyoung Lee On Thu, Dec 12, 2019 at 12:44 AM Fedor Sergeev <fedor.sergeev at azul.com> wrote:> > > On 12/3/19 8:01 PM, Juneyoung Lee via llvm-dev wrote: > > Hello all, > > Is there a way to register callback that runs before/after passes? > PassTimingInfo seems to do a similar thing by calling > PassInstrumentationCallbacks::registerBeforePassCallback / > registerAfterPassCallback, but it is hard-wired with > StandardInstrumentations class. > > PassInstrumentation framework was introduced to the new PassManager > specifically in mind with ability > to register arbitrary callbacks and execute them as pass manager traverses > through the pass pipeline. > > PassInstrumentationCallbacks are indeed the entity to register your > callbacks into, before passing it to PassBuilder; > You can check how it is being done in > `llvm/tools/opt/NewPMDriver.cpp`llvm::runPassPipeline. > > StandardInstrumentations are just a few "standard" callbacks that provide > "standard" functionality, like -print-after-all or -time-passes. > StandardInstrumentations registers its individual instrumentations the > same way you would register your own. > > Note, that PassInstrumentation is only supported in new pass manager (opt > -passes= or clang -fexperimental-new-pass-manager). > > regards, > Fedor. > > > Do we have something similar to RegisterStandardPasses, so custom > callbacks can be added from somewhere outside LLVM? > > Thanks, > Juneyoung Lee > > > > _______________________________________________ > LLVM Developers mailing listllvm-dev at lists.llvm.orghttps://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > >-- Juneyoung Lee Software Foundation Lab, Seoul National University -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191212/49c29d79/attachment.html>