Re: llvm JIT addGlobalMapping, can not add a class member function, which is a template function.

閲覧: 9 回
最初の未読メッセージにスキップ

Hans Wennborg

未読、
2018/07/30 4:12:122018/07/30
To: Tao Peng、Clang maintainers
Hi Tao,

I think this question would be better suited for the llvm-dev mailing
list: https://lists.llvm.org/mailman/listinfo/llvm-dev

Thanks,
Hans

On Wed, Jul 18, 2018 at 5:12 AM, Tao Peng <dev.p...@gmail.com> wrote:
> Hi all,
>
> I am a newer of clang and llvm. I used llvm to code-gen, but I encounter a
> problem.
>
> I have a class as below:
>
> class AAA {
> public:
> template<typename Type>
> void func(Type str) {
> std::cout << str << std::endl;
> }
>
> void func2() {
> std::cout << "hello" << std::endl;
> }
> };
>
>
> And I have a llvm::ExecutionEngine* mJit;
>
> Now I want to use `addGlobalMapping` to add the `AAA::func` and `AAA::func2`
> to the llvm's global mapping.
>
>
> // success
> mJit->addGlobalMapping(fn_func2, reinterpret_cast<void*>(&AAA::func2));
>
> // failed
> // Because the `AAA::func` is an template function
> mJit->addGlobalMapping(fn_func, reinterpret_cast<void*>(&AAA::func));
>
>
> And then I tried one method as follow:
>
>
> template<class Class, typename K>
> using TemplateFunc = void (Class::*) (K);
>
> TemplateFunc<AAA, int> myFunc = &AAA::func;
> mJit->addGlobalMapping(fn_func, reinterpret_cast<void*>(myFunc));
>
>
> But it came an error when link:
>
> Llvm::Finalize(): error: undefined reference to "void AAA::func<int>(int)".
> collect2: error: ld returned 1 exit status
>
>
> So how to add a c++ template function to the llvm JIT global mapping ?
>
> Thanks so much.
全員に返信
投稿者に返信
転送
新着メール 0 件