unsafe fn create_exec_engine(
    module: LLVMModuleRef,
    mappings: &[intrinsic::Mapping],
    conf: &ParsedConf,
) -> WeldResult<LLVMExecutionEngineRef> {
    // Create a filtered list of globals. Needs to be done before creating the execution engine
    // since we lose ownership of the module. (?)
    let mut globals = vec![];
    for mapping in mappings.iter() {
        let global = LLVMGetNamedFunction(module, mapping.0.as_ptr());
        // The LLVM optimizer can delete globals, so we need this check here!
        if !global.is_null() {
            globals.push((global, mapping.1));
        } else {
            trace!(
                "Function {:?} was deleted from module by optimizer",
                mapping.0
            );
        }
    }

    let mut engine = mem::MaybeUninit::uninit();
    let mut error_str = mem::MaybeUninit::uninit();
    let mut options = mem::MaybeUninit::<LLVMMCJITCompilerOptions>::uninit();
    let options_size = mem::size_of::<LLVMMCJITCompilerOptions>();
    LLVMInitializeMCJITCompilerOptions(options.as_mut_ptr(), options_size);
    let mut options: LLVMMCJITCompilerOptions = options.assume_init();
    options.OptLevel = conf.llvm.opt_level;
    options.CodeModel = LLVMCodeModel::LLVMCodeModelDefault;

    let result_code = LLVMCreateMCJITCompilerForModule(
        engine.as_mut_ptr(),
        module,
        &mut options,
        options_size,
        error_str.as_mut_ptr(),
    );

    if result_code != 0 {
        compile_err!(
            "Creating execution engine failed: {}",
            CStr::from_ptr(error_str.assume_init()).to_str().unwrap()
        )
    } else {
        let engine = engine.assume_init();
        for global in globals {
            LLVMAddGlobalMapping(engine, global.0, global.1);
        }
        Ok(engine)
    }
}
Create an MCJIT execution engine for a given module.
weld/src/codegen/llvm2/jit.rs