Exemplo n.º 1
0
    JuliaOJIT(TargetMachine &TM)
      : TM(TM),
        DL(TM.createDataLayout()),
        ObjStream(ObjBufferSV),
        MemMgr(CUSTOM_MEMORY_MANAGER()),
        ObjectLayer(DebugObjectRegistrar(*this)),
        CompileLayer(
                ObjectLayer,
                [this](Module &M) {
                    PM.run(M);
                    std::unique_ptr<MemoryBuffer> ObjBuffer(
                        new ObjectMemoryBuffer(std::move(ObjBufferSV)));
                    auto Obj = object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef());

                    if (!Obj) {
                        M.dump();
                        llvm::report_fatal_error("FATAL: Unable to compile LLVM Module.\n"
                            "The module's content was printed above. Please file a bug report");
                    }

                    return OwningObj(std::move(*Obj), std::move(ObjBuffer));
                }
            )
        {
            addOptimizationPasses(&PM);
            if (TM.addPassesToEmitMC(PM, Ctx, ObjStream))
                llvm_unreachable("Target does not support MC emission.");

            // Make sure SectionMemoryManager::getSymbolAddressInProcess can resolve
            // symbols in the program as well. The nullptr argument to the function
            // tells DynamicLibrary to load the program, not a library.
            std::string *ErrorStr = nullptr;
            if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr, ErrorStr))
                report_fatal_error("FATAL: unable to dlopen self\n" + *ErrorStr);
        }
Exemplo n.º 2
0
JuliaOJIT::JuliaOJIT(TargetMachine &TM)
  : TM(TM),
    DL(TM.createDataLayout()),
    ObjStream(ObjBufferSV),
    MemMgr(createRTDyldMemoryManager()),
    registrar(*this),
    ObjectLayer(
#if JL_LLVM_VERSION >= 50000
        [&] { return MemMgr; },
#endif
        std::ref(registrar)
        ),
    CompileLayer(
            ObjectLayer,
            CompilerT(this)
        )
{
    addTargetPasses(&PM, &TM);
    addOptimizationPasses(&PM, jl_generating_output() ? 0 : jl_options.opt_level);
    if (TM.addPassesToEmitMC(PM, Ctx, ObjStream))
        llvm_unreachable("Target does not support MC emission.");

    // Make sure SectionMemoryManager::getSymbolAddressInProcess can resolve
    // symbols in the program as well. The nullptr argument to the function
    // tells DynamicLibrary to load the program, not a library.
    std::string *ErrorStr = nullptr;
    if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr, ErrorStr))
        report_fatal_error("FATAL: unable to dlopen self\n" + *ErrorStr);
}
Exemplo n.º 3
0
JuliaOJIT::JuliaOJIT(TargetMachine &TM)
  : TM(TM),
    DL(TM.createDataLayout()),
    ObjStream(ObjBufferSV),
    MemMgr(createRTDyldMemoryManager()),
    ObjectLayer(DebugObjectRegistrar(*this)),
    CompileLayer(
            ObjectLayer,
            [this](Module &M) {
                JL_TIMING(LLVM_OPT);
                PM.run(M);
                std::unique_ptr<MemoryBuffer> ObjBuffer(
                    new ObjectMemoryBuffer(std::move(ObjBufferSV)));
                auto Obj = object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef());

                if (!Obj) {
#if JL_LLVM_VERSION >= 50000
                    M.print(llvm::dbgs(), nullptr, false, true);
#else
                    M.dump();
#endif
#if JL_LLVM_VERSION >= 30900
                    std::string Buf;
                    raw_string_ostream OS(Buf);
                    logAllUnhandledErrors(Obj.takeError(), OS, "");
                    OS.flush();
                    llvm::report_fatal_error("FATAL: Unable to compile LLVM Module: '" + Buf + "'\n"
                        "The module's content was printed above. Please file a bug report");
#else
                    llvm::report_fatal_error("FATAL: Unable to compile LLVM Module.\n"
                        "The module's content was printed above. Please file a bug report");
#endif
                }

                return OwningObj(std::move(*Obj), std::move(ObjBuffer));
            }
        )
{
    if (!jl_generating_output()) {
        addOptimizationPasses(&PM);
    }
    else {
        PM.add(createLowerGCFramePass());
        PM.add(createLowerPTLSPass(imaging_mode));
    }
    if (TM.addPassesToEmitMC(PM, Ctx, ObjStream))
        llvm_unreachable("Target does not support MC emission.");

    // Make sure SectionMemoryManager::getSymbolAddressInProcess can resolve
    // symbols in the program as well. The nullptr argument to the function
    // tells DynamicLibrary to load the program, not a library.
    std::string *ErrorStr = nullptr;
    if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr, ErrorStr))
        report_fatal_error("FATAL: unable to dlopen self\n" + *ErrorStr);
}