MCPcopy Create free account
hub / github.com/apache/arrow / FinalizeModule

Method FinalizeModule

cpp/src/gandiva/engine.cc:568–602  ·  view source on GitHub ↗

Optimise and compile the module.

Source from the content-addressed store, hash-verified

566
567// Optimise and compile the module.
568Status Engine::FinalizeModule() {
569 if (!cached_) {
570 ARROW_RETURN_NOT_OK(RemoveUnusedFunctions());
571
572 if (optimize_) {
573 auto target_analysis = target_machine_->getTargetIRAnalysis();
574// misc passes to allow for inlining, vectorization, ..
575#if LLVM_VERSION_MAJOR >= 14
576 OptimizeModuleWithNewPassManager(*module_, std::move(target_analysis));
577#else
578 OptimizeModuleWithLegacyPassManager(*module_, std::move(target_analysis));
579#endif
580 }
581
582 ARROW_RETURN_IF(llvm::verifyModule(*module_, &llvm::errs()),
583 Status::CodeGenError("Module verification failed after optimizer"));
584
585 // print the module IR and save it for later use if IR dumping is needed
586 // since the module will be moved to construct LLJIT instance, and it is not
587 // available after LLJIT instance is constructed
588 if (conf_->dump_ir()) {
589 module_ir_ = DumpModuleIR(*module_);
590 }
591
592 llvm::orc::ThreadSafeModule tsm(std::move(module_), std::move(context_));
593 auto error = lljit_->addIRModule(std::move(tsm));
594 if (error) {
595 return Status::CodeGenError("Failed to add IR module to LLJIT: ",
596 llvm::toString(std::move(error)));
597 }
598 }
599 module_finalized_ = true;
600
601 return Status::OK();
602}
603
604Result<void*> Engine::CompiledFunction(const std::string& function) {
605 DCHECK(module_finalized_)

Callers 3

TEST_FFunction · 0.80
BuildMethod · 0.80
TEST_FFunction · 0.80

Calls 5

CodeGenErrorFunction · 0.85
DumpModuleIRFunction · 0.85
OKFunction · 0.50

Tested by 2

TEST_FFunction · 0.64
TEST_FFunction · 0.64