-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-37834: [Gandiva] Migrate to new LLVM PassManager API #37867
Conversation
|
Could you also apply #37834 (comment) to accept LLVM 17? |
We have some micro benchmarkes in https://github.com/apache/arrow/blob/main/cpp/src/gandiva/tests/micro_benchmarks.cc . Can we use them? |
4c34593
to
b0fe18a
Compare
Let me check it out. I've compared the old/new LLVM IR generated by the particular test code today, and they are exactly the same (at least for this test case), so I assume the change is probably not too risky. |
I applied your patch for LLVM 17 a moment ago, and it should help to address some issues in the CI. LLVM incompatible API changes (or new API)But I realized my current changes use some APIs that are not available in lower version of LLVM, for example, this CI check failed (https://github.com/apache/arrow/actions/runs/6307346371/job/17123835292?pr=37867), there are at least 4 incompatible changes:
I used LLVM 14.0.6 locally.
@kou what do you think? linker errorThis CI check (https://github.com/apache/arrow/actions/runs/6307346377/job/17123834680?pr=37867) failed with some linker error links[1] LLVM release dates, https://releases.llvm.org |
Great!
Is it something like the following? diff --git a/cpp/src/gandiva/engine.cc b/cpp/src/gandiva/engine.cc
index 6abe81405..b5104c5b7 100644
--- a/cpp/src/gandiva/engine.cc
+++ b/cpp/src/gandiva/engine.cc
@@ -308,6 +308,7 @@ Status Engine::FinalizeModule() {
ARROW_RETURN_NOT_OK(RemoveUnusedFunctions());
if (optimize_) {
+#if LLVM_VERSION_MAJOR >= 14
// Setup an optimiser pipeline
llvm::PassBuilder pass_builder;
llvm::LoopAnalysisManager loop_am;
@@ -345,6 +346,30 @@ Status Engine::FinalizeModule() {
pass_builder.buildPerModuleDefaultPipeline(llvm::OptimizationLevel::O3)
.run(*module_, module_am);
+#else
+ // misc passes to allow for inlining, vectorization, ..
+ std::unique_ptr<llvm::legacy::PassManager> pass_manager(
+ new llvm::legacy::PassManager());
+
+ llvm::TargetIRAnalysis target_analysis =
+ execution_engine_->getTargetMachine()->getTargetIRAnalysis();
+ pass_manager->add(llvm::createTargetTransformInfoWrapperPass(target_analysis));
+ pass_manager->add(llvm::createFunctionInliningPass());
+ pass_manager->add(llvm::createInstructionCombiningPass());
+ pass_manager->add(llvm::createPromoteMemoryToRegisterPass());
+ pass_manager->add(llvm::createGVNPass());
+ pass_manager->add(llvm::createNewGVNPass());
+ pass_manager->add(llvm::createCFGSimplificationPass());
+ pass_manager->add(llvm::createLoopVectorizePass());
+ pass_manager->add(llvm::createSLPVectorizerPass());
+ pass_manager->add(llvm::createGlobalOptimizerPass());
+
+ // run the optimiser
+ llvm::PassManagerBuilder pass_builder;
+ pass_builder.OptLevel = 3;
+ pass_builder.populateModulePassManager(*pass_manager);
+ pass_manager->run(*module_);
+#endif
}
ARROW_RETURN_IF(llvm::verifyModule(*module_, &llvm::errs()), I like the approach.
It uses static linking. I think that we need to add more components for the new PassManager API at: arrow/cpp/cmake_modules/FindLLVMAlt.cmake Lines 89 to 98 in 23c1bf9
If you're not familiar with CMake, I can do it. But I can't work on it in this week... |
Yes, I am thinking something like you said.
Cool. I am not aware that the new PassManager needs to change LLVM components. Why this issue doesn't happen in other CI environments? Anyway, let me give it a try to see if I can figure it out by adding some more components. |
b0fe18a
to
6c514dc
Compare
FinalizeModuleFor the RemoveUnusedFunctionsFor the Here are the major APIs used in PassBuilder.registerModuleAnalysesFeb 1, 2015, LLVM 3.6.0 ModulePassManagerMay 13, 2017, LLVM 5.0 InternalizePassApr 27, 2016, LLVM 3.9.0 GlobalDCEPassMay 4, 2016, LLVM 3.9.0 CMake LLVM components changeI didn't change the CMake LLVM components yet, since if we use legacy LLVM PassManager API for old versions of LLVM, we probably don't need to change it any more. I will keep an eye on the CI results to see if it works for LLVM 17 environments. |
Sorry. Only for the linker error: We may be able to reproduce the linker error on local with |
6c93b96
to
f3048cf
Compare
…nager API so that the code can work with multiple versions of LLVM.
f3048cf
to
99a0909
Compare
After switching to use 2 implementations for legacy/new PassManager API, there are still 2 relevant CI checks failed:
Both seemed to be related with LLVM linking issue. I will do some further investigation but may have to be off for a few days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I've fixed the remained CI failures.
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit d428ef4. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 3 possible false positives for unstable benchmarks that are known to sometimes produce them. |
@kou thanks so much for fixing the remaining issues! |
…#37867) ### Rationale for this change In apache#37834, to support LLVM 17, we need to migrate to use the new LLVM PassManager API. ### What changes are included in this PR? This PR tries to migrate the legacy PassManager to the new PassManager. ### Are these changes tested? It should be covered by existing unit tests. But more performance tests may be needed to verify this change. ### Are there any user-facing changes? No * Closes: apache#37834 Lead-authored-by: Yue Ni <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
…#37867) ### Rationale for this change In apache#37834, to support LLVM 17, we need to migrate to use the new LLVM PassManager API. ### What changes are included in this PR? This PR tries to migrate the legacy PassManager to the new PassManager. ### Are these changes tested? It should be covered by existing unit tests. But more performance tests may be needed to verify this change. ### Are there any user-facing changes? No * Closes: apache#37834 Lead-authored-by: Yue Ni <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
…#37867) ### Rationale for this change In apache#37834, to support LLVM 17, we need to migrate to use the new LLVM PassManager API. ### What changes are included in this PR? This PR tries to migrate the legacy PassManager to the new PassManager. ### Are these changes tested? It should be covered by existing unit tests. But more performance tests may be needed to verify this change. ### Are there any user-facing changes? No * Closes: apache#37834 Lead-authored-by: Yue Ni <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
Rationale for this change
In #37834, to support LLVM 17, we need to migrate to use the new LLVM PassManager API.
What changes are included in this PR?
This PR tries to migrate the legacy PassManager to the new PassManager.
Are these changes tested?
It should be covered by existing unit tests. But more performance tests may be needed to verify this change.
Are there any user-facing changes?
No