Re: [PATCH] Enable using llvm jitlink as an alternative llvm jit linker of old Rtdyld. - Mailing list pgsql-hackers
From | Alex Fan |
---|---|
Subject | Re: [PATCH] Enable using llvm jitlink as an alternative llvm jit linker of old Rtdyld. |
Date | |
Msg-id | CAP8f6fB96uUruo6E2okR1KFcOKJaCwJCTdB7foiwubHe=UyT4g@mail.gmail.com Whole thread Raw |
In response to | Re: [PATCH] Enable using llvm jitlink as an alternative llvm jit linker of old Rtdyld. (Andres Freund <andres@anarazel.de>) |
Responses |
Re: [PATCH] Enable using llvm jitlink as an alternative llvm jit linker of old Rtdyld.
|
List | pgsql-hackers |
There is discussion in https://github.com/riscv-non-isa/riscv-toolchain-conventions/issues/13 to change the abi default, but not much attention for some time. The consensus seems to be set the abi and extension explicitly.
> I recommend proposing a patch for adding such an API to LLVM.
> I recommend proposing a patch for adding such an API to LLVM.
I would like to try some time later. Jitlink allows lots of flexibility to inspect each linking process, I feel myself don't know enough use cases to propose a good enough c-abi for it.
The thing I am thinking is these patch to llvm will take some time to land especially for abi and extension default. But jitlink and orc for riscv is very mature since llvm-15, and even llvm-14 with two minor patches. It would be good to have these bits, though ugly, so that postgresql jit can work with llvm-15 as most distros are still moving to it.
cheers,
Alex Fan
On Sun, Dec 25, 2022 at 11:02 PM Andres Freund <andres@anarazel.de> wrote:
Hi,
On 2022-11-23 21:13:04 +1100, Alex Fan wrote:
> > @@ -241,6 +246,40 @@ llvm_mutable_module(LLVMJitContext *context)
> > context->module = LLVMModuleCreateWithName("pg");
> > LLVMSetTarget(context->module, llvm_triple);
> > LLVMSetDataLayout(context->module, llvm_layout);
> > +#ifdef __riscv
> > +#if __riscv_xlen == 64
> > +#ifdef __riscv_float_abi_double
> > + abiname = "lp64d";
> > +#elif defined(__riscv_float_abi_single)
> > + abiname = "lp64f";
> > +#else
> > + abiname = "lp64";
> > +#endif
> > +#elif __riscv_xlen == 32
> > +#ifdef __riscv_float_abi_double
> > + abiname = "ilp32d";
> > +#elif defined(__riscv_float_abi_single)
> > + abiname = "ilp32f";
> > +#else
> > + abiname = "ilp32";
> > +#endif
> > +#else
> > + elog(ERROR, "unsupported riscv xlen %d", __riscv_xlen);
> > +#endif
> > + /*
> > + * set this manually to avoid llvm defaulting to soft
> > float and
> > + * resulting in linker error: `can't link double-float
> > modules
> > + * with soft-float modules`
> > + * we could set this for TargetMachine via MCOptions, but
> > there
> > + * is no C API for it
> > + * ref:
I think this is something that should go into the llvm code, rather than
postgres.
> > @@ -820,16 +861,21 @@ llvm_session_initialize(void)
> > elog(DEBUG2, "LLVMJIT detected CPU \"%s\", with features \"%s\"",
> > cpu, features);
> >
> > +#ifdef __riscv
> > + reloc=LLVMRelocPIC;
> > + codemodel=LLVMCodeModelMedium;
> > +#endif
Same.
> > +#ifdef USE_JITLINK
> > +/*
> > + * There is no public C API to create ObjectLinkingLayer for JITLINK,
> > create our own
> > + */
> > +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::ExecutionSession,
> > LLVMOrcExecutionSessionRef)
> > +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::ObjectLayer,
> > LLVMOrcObjectLayerRef)
I recommend proposing a patch for adding such an API to LLVM.
Greetings,
Andres Freund
pgsql-hackers by date: