Provide an easy way to use LLVM's Polly

a9b7165
Opened by gnzlbg at 2023-04-05 17:38:47

To use polly with clang I just need to compile polly together with llvm and clang (just check it out and put it in the correct directory before compiling), load it as a clang plugin, and then enable -mllvm polly.

It would be nice if:

  • [ ] rustc always came with an LLVM compiled with polly
  • [ ] it had an easy option to enable it from rustc that:
    • [ ] loads polly's /lib/LLVMPolly.so as a plugin
    • [ ] enables it in llvm's opt: -mllvm polly.
  • [ ] had an easy way to pass polly options without having to do the -mllvm -polly-option_name=value dance over and over again.

This would allow to start experimenting with polly, to e.g. make sure that it gets proper aliasing information for Rust.

  1. Hi, it seems I can simply checkout https://github.com/llvm-mirror/polly into src/llvm/tools/polly, checkout the release_60 branch and llvms cmake will do the rest of the configuration. I rebuilt rust and was able to build a program with RUSTFLAGS="-C passes=polly,polly-parallel" for example. :)

    Matthias Krüger at 2018-02-11 08:36:30

  2. Could we build with it by default?

    gnzlbg at 2018-02-12 11:28:14

  3. I tried adding to the rust repos .gitmodules as a submodule however this did not work, probably because it would check out not into the root repo but rather into the directory of another submodule (llvm). What is the best to handle this? Add it as submodule of the llvm repo or add it to the llvm/tools/polly "manually" via some custom command in some build script?

    Matthias Krüger at 2018-02-12 12:51:13

  4. This isn't as straight forward as suggested. After cloning the polly repo into src/llvm/tools, the passes won't be available: you'll have to modify the librustc_llvm build script to add Polly and PollyISL to the link. Next, you'll need to modifiy rustllvm by initializing the polly passes into the llvm pass registry by calling polly::initializePollyPasses in LLVMInitializePasses, and lastly calling polly::registerPollyPasses in LLVMRustAddAnalysisPasses (probably not the best spot to do this, but required the fewest changes).

    Richard Diamond at 2018-02-21 16:48:41

  5. BTW there is an ongoing discussion in the LLVM community about moving Polly into LLVM proper, using its infrastructure in existing and new loop optimizations, and slowly moving at least some of Polly's capabilities into the default optimization pipeline. See here for example. This is a project that will take a long time to fully come to fruition but the end result will not just be easier to use from rustc, it will hopefully also result in better and more general optimizations overall.

    Hanna Kruppe at 2018-02-21 16:53:48

  6. Triage: https://github.com/rust-lang/rust/pull/51061 exists 🎊

    Steve Klabnik at 2018-11-20 20:03:12

  7. https://github.com/rust-lang/rust/pull/78566 allows polly to be passed into llvm-args. It is not available by default on nightly, and to use the pass, one must currently build rustc with polly enabled.

    memoryruins at 2020-12-18 17:33:53