Get rid of all functions that don't need to be compiled. This helps in reducing the overall compilation time. This pass is trivial, and is always done since the number of functions in gandiva is very high. (Adapted from Apache Impala) Done by marking all the unused functions as internal, and then, running a pass for dead code elimination.
| 452 | // Done by marking all the unused functions as internal, and then, running |
| 453 | // a pass for dead code elimination. |
| 454 | Status Engine::RemoveUnusedFunctions() { |
| 455 | // Setup an optimiser pipeline |
| 456 | llvm::PassBuilder pass_builder; |
| 457 | llvm::ModuleAnalysisManager module_am; |
| 458 | |
| 459 | pass_builder.registerModuleAnalyses(module_am); |
| 460 | llvm::ModulePassManager module_pm; |
| 461 | |
| 462 | std::unordered_set<std::string> used_functions; |
| 463 | used_functions.insert(functions_to_compile_.begin(), functions_to_compile_.end()); |
| 464 | |
| 465 | module_pm.addPass( |
| 466 | llvm::InternalizePass([&used_functions](const llvm::GlobalValue& variable) -> bool { |
| 467 | return used_functions.find(variable.getName().str()) != used_functions.end(); |
| 468 | })); |
| 469 | module_pm.addPass(llvm::GlobalDCEPass()); |
| 470 | |
| 471 | module_pm.run(*module_, module_am); |
| 472 | return Status::OK(); |
| 473 | } |
| 474 | |
| 475 | // several passes requiring LLVM 14+ that are not available in the legacy pass manager |
| 476 | #if LLVM_VERSION_MAJOR >= 14 |