factory method to construct the engine.
| 395 | |
| 396 | /// factory method to construct the engine. |
| 397 | Result<std::unique_ptr<Engine>> Engine::Make( |
| 398 | const std::shared_ptr<Configuration>& conf, bool cached, |
| 399 | std::optional<std::reference_wrapper<GandivaObjectCache>> object_cache) { |
| 400 | std::call_once(llvm_init_once_flag, InitOnce); |
| 401 | |
| 402 | // Create the target machine |
| 403 | ARROW_ASSIGN_OR_RAISE(auto jtmb, MakeTargetMachineBuilder(*conf)); |
| 404 | auto maybe_tm = jtmb.createTargetMachine(); |
| 405 | ARROW_ASSIGN_OR_RAISE(auto target_machine, |
| 406 | AsArrowResult(maybe_tm, "Could not create target machine: ")); |
| 407 | |
| 408 | auto shared_target_machine = |
| 409 | std::shared_ptr<llvm::TargetMachine>(std::move(target_machine)); |
| 410 | |
| 411 | // Build the LLJIT instance |
| 412 | ARROW_ASSIGN_OR_RAISE(auto jit, |
| 413 | BuildJIT(std::move(jtmb), shared_target_machine, object_cache)); |
| 414 | |
| 415 | std::unique_ptr<Engine> engine{ |
| 416 | new Engine(conf, std::move(jit), std::move(shared_target_machine), cached)}; |
| 417 | |
| 418 | ARROW_RETURN_NOT_OK(engine->Init()); |
| 419 | return engine; |
| 420 | } |
| 421 | |
| 422 | llvm::Module* Engine::module() { |
| 423 | DCHECK(!module_finalized_) << "module cannot be accessed after finalized"; |