0

I was wondering if it's currently possible to have an 'external' (.so/.dylib) LLVM plugin (module) pass scheduled at LTO time? The reason for wanting this is a inter-modular optimization I want to add.

I also found this topic; How to write a custom intermodular pass in LLVM? But a separate tool is not an option for me.

Thanks

Community
  • 1
  • 1
dzan
  • 425
  • 3
  • 14

1 Answers1

0

I think the most helpful thing here might be to understand how passes are run and what the state of the code is during LTO.

First of all, when optimization passes are run by the compiler, they are done as a set that has been added to a PassManager. This means that LLVM/Clang, when passed something like -O3 will create a copy of a PassManager and subsequently provide it the set of passes expected to provide O3 level of optimization. This is very different from what you are doing with an external library which must be provided manually and cannot be fit into the pass pipeline normally.

Then we have the state of things when doing LTO. During Link Time Optimization, all of the individual translation units have been consolidated and are now a single Module. This means that an optimization which runs on each function will run on every function in the code base. Similarly, a per-module optimization will run on the full Module and therefor offer Inter-Procedural Analysis/Optimization.

If you're looking to use an Intra-Modular Pass then there is no reason to do this at LTO time and instead you can simply make a ModulePass and run that on each unit.

jtv
  • 128
  • 5
  • Hi, thanks for your reply! I am sorry I mistakenly wrote 'intra' but I meant 'inter'. I do need a whole program view for my pass because I want to do some things consistently across different TU's and also have a definitive view on what is declared in the code instead of in libraries. I really think I need an LTO pass, I have tested my code so far by manually compiling to IR and linking the modules into 1 but ideally I want to provide a compiler plugin. (I edited my question to use the correct term.) – dzan Oct 07 '15 at 08:29
  • It's entirely possible to utilize your `external` pass to emulate LTO but not in the sense I think you're hoping for. You can simply pass `-emit-llvm` to clang and have it output the IR file with which you can now manually operate on. This will allow you to run your pass with `opt` on the consolidated code. – jtv Oct 07 '15 at 17:55
  • I understand this is possible but it's not what I want. I have to be compatible with existing build processes. I asked around further and apparently it's not possible, probably it will be once the new PassManager is made default. Even then it still wouldn't work for older toolchains. – dzan Oct 09 '15 at 14:06