Пример #1
0
void Builder::createJIT() {
  InitializeNativeTarget();
  std::string err;
  EngineBuilder eb = EngineBuilder(this->_mod);
  eb.setErrorStr(&err);
  auto jit = eb.create();
  this->_jit = jit;
  if (!jit) {
    std::cerr << "Impossible de créer le moteur JIT : " << err << std::endl;
  }
}
Пример #2
0
ExecutionEngine* createExecutionEngine(Module* mod) {

    if (globalExecEngine == 0)
    {
        //we first have to initialize the native target for code generation
        const bool initFailed = InitializeNativeTarget();

        if (initFailed) {
            errs() << "ERROR: could not initialize native target (required for "
                << "LLVM execution engine)\n";
            return NULL;
        }

        std::string errorMessage = "";

        EngineBuilder eb = EngineBuilder(mod);
        eb.setEngineKind(EngineKind::JIT);
        eb.setErrorStr(&errorMessage);
        eb.setJITMemoryManager(JITMemoryManager::CreateDefaultMemManager());
        eb.setOptLevel(CodeGenOpt::Aggressive);
        eb.setAllocateGVsWithCode(false);
        eb.setCodeModel(CodeModel::Default);
        //eb.setMArch("x86-64");
        //eb.setMCPU("corei7");
        //std::vector<std::string> attrs;
        //attrs.push_back("+sse41");
        //eb.setMAttrs(attrs);


        globalExecEngine = eb.create();

        if (errorMessage != "") {
            errs() << "ERROR: could not create execution engine for module "
                << mod->getModuleIdentifier() << ": " << errorMessage << "\n";
            return NULL;
        }

        if (!globalExecEngine) {
            errs() << "ERROR: could not create execution engine for module "
                << mod->getModuleIdentifier() << "!\n";
            return NULL;
        }
    }

    return globalExecEngine;
}