使用LLVM ORC JIT编译问题

时间:2017-08-05 09:22:42

标签: c++ llvm jit orc

我在树上编译LLVM ORC JIT示例。但是我遇到了一些我无法解决的问题。

首先,我使用最新稳定的LLVM和clang启用C ++ 14编译,这意味着4.0.1。我收到以下错误。我错过了一些特定的编译选项吗?

编译在这里看起来像这样。

Compiling contribJIT.cpp
PWD:  /home/ikuehl/projects-llvm/TurboLisp/domainEngineer  Source file: contribJIT  Source file type:  cpp  source sub-folder:  src/contrib  Compiler:  /usr/local/bin/clang++ COMPILE_FLAG option:  -v -g0 -fPIC -fno-use-cxa-atexit -emit-llvm -I/usr/local/include -I/opt/BOOST/include -std=c++14 -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS  LLVM_CONFIG_COMPILE option:  -I/usr/local/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS  option:  -emit-llvm  sub-path:  contrib  lto:  -flto=thin -O3

if test "contrib" = "contrib/parser"; then cd bin/x86_64/contrib; `/usr/local/bin/clang++ -emit-llvm -c -v -g0 -fPIC -fno-use-cxa-atexit -emit-llvm -I/usr/local/include -I/opt/BOOST/include -std=c++14 -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS ../../../src/contrib/'contribJIT'.'cpp' -o 'contribJIT'.o `/usr/local/bin/llvm-config --cppflags``; cd ..; else cd bin/x86_64/contrib; `/usr/local/bin/clang++ -emit-llvm -c -v -g0 -fPIC -fno-use-cxa-atexit -emit-llvm -I/usr/local/include -I/opt/BOOST/include -std=c++14 -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS ../../../src/contrib/'contribJIT'.'cpp' -o 'contribJIT'.o `/usr/local/bin/llvm-config --cppflags``; cd ..; fi
clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/local/bin/clang-4.0" -cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -emit-llvm-uselists -disable-free -main-file-name contribJIT.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /home/ikuehl/projects-llvm/TurboLisp/domainEngineer/bin/x86_64/contrib/contribJIT.gcno -resource-dir /usr/local/bin/../lib/clang/4.0.1 -I /usr/local/include -I /opt/BOOST/include -D __STDC_CONSTANT_MACROS -D __STDC_LIMIT_MACROS -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/4.0.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/ikuehl/projects-llvm/TurboLisp/domainEngineer/bin/x86_64/contrib -ferror-limit 19 -fmessage-length 237 -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o contribJIT.o -x c++ ../../../src/contrib/contribJIT.cpp
clang -cc1 version 4.0.1 based upon LLVM 4.0.1 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0"
ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 /opt/BOOST/include
 /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0
 /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0
 /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward
 /usr/local/include
 /usr/local/bin/../lib/clang/4.0.1/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.

我得到的错误是:

  

错误:未知类型名称'RTDyldObjectLinkingLayer';你的意思是   'RTDyldObjectLinkingLayerBase'?

而且,我得到更多错误。这告诉我模板有问题。

  

错误:类模板'IRCompileLayer'的模板参数太多         IRCompileLayer CompileLayer;

关于RTDyldObjectLinkingLayer的另一个错误:

  

错误:类模板'IRCompileLayer'的模板参数太多         IRCompileLayer CompileLayer;

#define _CONTRIB_JIT_ 1

#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <algorithm>
#include <memory>
#include <string>
#include <vector>

using namespace llvm;
using namespace llvm::orc;

namespace tl {
  namespace contrib {

    class GenericJIT {

    private:
      std::unique_ptr<TargetMachine> TM;
      const DataLayout DL;
      RTDyldObjectLinkingLayer ObjectLayer;
      IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;

    public:
      using ModuleHandle = decltype(CompileLayer)::ModuleSetHandleT;

      GenericJIT()
    : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
      ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
      CompileLayer(ObjectLayer) {
    llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
      }

      TargetMachine &getTargetMachine() { return *TM; }

      ModuleHandle addModule(std::unique_ptr<Module> M) {
    // Build our symbol resolver:
    // Lambda 1: Look back into the JIT itself to find symbols that are part of
    //           the same "logical dylib".
    // Lambda 2: Search for external symbols in the host process.
    auto Resolver = createLambdaResolver(
                         [&](const std::string &Name) {
                           if (auto Sym = CompileLayer.findSymbol(Name, false))
                         return Sym;
                           return JITSymbol(nullptr);
                         },
                         [](const std::string &Name) {
                           if (auto SymAddr =
                           RTDyldMemoryManager::getSymbolAddressInProcess(Name))
                         return JITSymbol(SymAddr, JITSymbolFlags::Exported);
                           return JITSymbol(nullptr);
                         });

    // Add the set to the JIT with the resolver we created above and a newly
    // created SectionMemoryManager.
    return cantFail(CompileLayer.addModule(std::move(M),
                           std::move(Resolver)));
      }

      JITSymbol findSymbol(const std::string Name) {
    std::string MangledName;
    raw_string_ostream MangledNameStream(MangledName);
    Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
    return CompileLayer.findSymbol(MangledNameStream.str(), true);
      }

      void removeModule(ModuleHandle H) {
    cantFail(CompileLayer.removeModule(H));
      }
    };

  }
}

从LLVM网站LLVM ORC JIT Example复制代码是一对一的。

有人能告诉我我的代码或编译选项中遗漏了什么吗?

0 个答案:

没有答案