Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tsMJ8-0018IB-EH for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Mar 2025 13:39:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tsMJ5-005JLv-RZ for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Mar 2025 13:39:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tsMJ5-005JGw-EP for pgsql-hackers@lists.postgresql.org; Wed, 12 Mar 2025 13:39:35 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tsMJ1-002Rs1-0X for pgsql-hackers@postgresql.org; Wed, 12 Mar 2025 13:39:34 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-307d1ab59c6so71142191fa.1 for ; Wed, 12 Mar 2025 06:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=percona.com; s=google; t=1741786771; x=1742391571; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=m43a3RCUasoWHoipkDgwcRx+8xMiHngm3OFmEn0g2GU=; b=NfqPPhhV7Y7ci8ZWxlPcTSzRTKpEvCo4kvk8D542ff9p1l2jyaL1xENohf55ZtN9LD Xd0bCepwlBNyAYjTsfYU6BOGn+FXzgV528+UEpn4fXHOY0H/qJkcyMBcSJoKeRlvx0QD UpLr/J63zirootnaQmNcEVZY6GvOOU0UVNKBc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741786771; x=1742391571; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=m43a3RCUasoWHoipkDgwcRx+8xMiHngm3OFmEn0g2GU=; b=E8B3zl7e/SfXMM1HjVOdxZFfcHYkhhqzyRwi6OagvuaJo8wvqJeDAzPcCSmJRIonxa 0rDZ3A+NT/TcA76tJ++Njb/IjzDmJU3S+pNVqTNEj8uwnGFzNXQHXb1PK19FrLxylUr5 4GmUygXYxd/dDjSs3RQJt6hnRiZLxgpx47lKulDXmVeBCPSfovPqzAH5uMKpqp08YUxI m/tDDnKlMvzuOlD6xH2bIPCeOqHwkLUSuuG8gSmK+lPxQTNmM61wRF75mnbjWDGsiAy4 7AappsQvr6qAw+lhSg57FGlRQ233PT/JyWtRw7dx+6gt2ftcIF7EGq/oMH9ITQAvYeBn Trrg== X-Forwarded-Encrypted: i=1; AJvYcCUwGDdqj89Ygm35gwYx9hmsEXv6daEyERStIfllKWobaFMYsaRK1UemQcqFoix981GXSW0ageo1A+TJbQjT@postgresql.org X-Gm-Message-State: AOJu0YzuUb1/0F6jTdBiv8gQm0TZRp4WUoZnIhwuSpUMyw7szA1ekSbP eAldaaTS0fEjWhMlZhFocTFIZuOwG2MKjt2UVhWBK2iE0PPir/LCcdbbVVPg1k7Q/m5ZxkivCCG r+PTN1fL6ZjBDK0C7FrTgekxSt42Sd5D+RIGXrx1xqb54SOzbPh+/eR89/fHsA24KRaw+kQB0lY Dn0Nfmw6dS2A/GHmk5uauVCn2tiEgROIPRrJ9TuKboKQNRq4ZdjxGwWBvfu0FgKxdm8ulBeVSvo 8cHc08eB+FsSCVYxWqbI2YymOJF12UDK/MWOypZRge0NlU= X-Gm-Gg: ASbGncuwRAXDkDETub4UDP2m8KUvu02CTFUIUn4bhN1iADy2twpKd7KV/ssuuQF3GdI 6DRGV9l1ChpkUOcDHjBPj25UVXeu2XH3x3nBABPD2FmywSfW/EYWdy6zkuicip11gjf7y2hZFAF byDu4RLLjm8rA9xL7Rq8S0kbqu1gQ= X-Google-Smtp-Source: AGHT+IEe/I+jxcZe2dAhnMJs5emt6YeYoR5MsZ+Me23IQiKZhAN3kpn0SEc1TgZ6ArW1p6rYP+EEvFbS7uRqrw2unrY= X-Received: by 2002:ac2:4299:0:b0:549:b0f3:438b with SMTP id 2adb3069b0e04-549b0f34516mr1123387e87.46.1741786771239; Wed, 12 Mar 2025 06:39:31 -0700 (PDT) MIME-Version: 1.0 References: <206b001d-1884-4081-bd02-bed5c92f02ba@eisentraut.org> In-Reply-To: From: Diego Fronza Date: Wed, 12 Mar 2025 10:39:19 -0300 X-Gm-Features: AQ5f1Jr2eANmmkY6wdPDWpa83pgrSuD1I8tBf2aPWXLfRPng7iPVDlmsk9lfIcg Message-ID: Subject: Re: meson vs. llvm bitcode files To: Nazir Bilal Yavuz Cc: Peter Eisentraut , pgsql-hackers , Andres Freund Content-Type: multipart/alternative; boundary="000000000000c65bb30630255505" X-CLOUD-SEC-AV-Sent: true X-CLOUD-SEC-AV-Info: percona,google_mail,monitor X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c65bb30630255505 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, The v7 patch looks good to me, handling the bitcode modules in a uniform way and also avoiding the hacky code and warnings, much better now. A small note about the bitcode emission for generated sources in contrib, using cube as example, currently it creates two dict entries in a list: bc_seg_gen_sources =3D [{'srcfiles': [seg_scan]}] bc_seg_gen_sources +=3D {'srcfiles': [seg_parse[0]]} Then pass it to the bitcode_modules: bitcode_modules +=3D { ... 'gen_srcfiles': bc_seg_gen_sources, } It could be passed as a list with a single dict, since both generated sources share the same compilation flags: bitcode_modules +=3D { ... 'gen_srcfiles': [ { 'srcfiles': [cube_scan, cube_parse[0]] }. ] } Both approaches work, the first one has the advantage of being able to pass separate additional_flags per generated source. Thanks for your reply Nazir, also waiting for more opinions on this. Regards, Diego On Wed, Mar 12, 2025 at 7:27=E2=80=AFAM Nazir Bilal Yavuz wrote: > Hi, > > On Tue, 11 Mar 2025 at 01:04, Diego Fronza > wrote: > > I did a full review on the provided patches plus some tests, I was able > to validate that the loading of bitcode modules is working also JIT works > for both backend and contrib modules. > > Thank you! > > > To test JIT on contrib modules I just lowered the costs for all jit > settings and used the intarray extension, using the data/test__int.data: > > CREATE EXTENSION intarray; > > CREATE TABLE test__int( a int[] );1 > > \copy test__int from 'data/test__int.data' > > > > For queries any from line 98+ on contrib/intarray/sql/_int.sql will wor= k. > > > > Then I added extra debug messages to llvmjit_inline.cpp on > add_module_to_inline_search_path() function, also on > llvm_build_inline_plan(), I was able to see many functions in this module > being successfully inlined. > > > > I'm attaching a new patch based on your original work which add further > support for generating bitcode from: > > Thanks for doing that! > > > - Generated backend sources: processed by flex, bison, etc. > > - Generated contrib module sources, > > I think we do not need to separate these two. > > foreach srcfile : bitcode_module['srcfiles'] > - if meson.version().version_compare('>=3D0.59') > + srcfilename =3D '@0@'.format(srcfile) > + if srcfilename.startswith(' + srcfilename =3D srcfile.full_path().split(meson.build_root() + '/'= )[1] > + elif meson.version().version_compare('>=3D0.59') > > Also, checking if the string starts with ' hacky, and 'srcfilename =3D '@0@'.format(srcfile)' causes a deprecation > warning. So, instead of this we can process all generated sources like > how generated backend sources are processed. I updated the patch with > that. > > > On this patch I just included fmgrtab.c and src/backend/parser for the > backend generated code. > > For contrib generated sources I added contrib/cube as an example. > > I applied your contrib/cube example and did the same thing for the > contrib/seg. > > > All relevant details about the changes are included in the patch itself= . > > > > As you may know already I also created a PR focused on llvm bitcode > emission on meson, it generates bitcode for all backend and contribution > modules, currently under review by some colleagues at Percona: > https://github.com/percona/postgres/pull/103 > > I'm curious if we should get all or some of the generated backend > sources compiled to bitcode, similar to contrib modules. > > I think we can do this. I added other backend sources like you did in > the PR but attached it as another patch (0007) because I wanted to > hear other people's opinions on that first. > > v3 is attached. > > -- > Regards, > Nazir Bilal Yavuz > Microsoft > --000000000000c65bb30630255505 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

The v7 patch looks good = to me, handling the bitcode modules in a uniform way and also avoiding the = hacky code and warnings, much better now.

A small = note about the bitcode emission for generated sources in contrib, using cub= e as example, currently it creates two dict entries in a list:
bc_seg_= gen_sources =3D [{'srcfiles': [seg_scan]}]
bc_seg_gen_sources += =3D {'srcfiles': [seg_parse[0]]}

Then pass= it to the bitcode_modules:
bitcode_modules +=3D {
=C2= =A0 ...
=C2=A0 'gen_srcfiles': bc_seg_gen_sources,
<= div>}

It could be passed as a list with a single dict, s= ince both generated sources share=C2=A0the same compilation flags:
bitcode_modules +=3D {
=C2=A0 ...
= =C2=A0 'gen_srcfiles': [
=C2=A0 =C2=A0 {=C2=A0 'srcfi= les': [cube_scan, cube_parse[0]] }.
=C2=A0 ]
}

Both approaches work, the first one has the advantage = of being able to pass separate additional_flags per generated source.
=

Thanks for your reply Nazir, also waiting for more opin= ions on this.

Regards,
Diego

On Wed, Mar 12, 2= 025 at 7:27=E2=80=AFAM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:
Hi,

On Tue, 11 Mar 2025 at 01:04, Diego Fronza <diego.fronza@percona.com> wrote: > I did a full review on the provided patches plus some tests, I was abl= e to validate that the loading of bitcode modules is working also JIT works= for both backend and contrib modules.

Thank you!

> To test JIT on contrib modules I just lowered the costs for all jit se= ttings and used the intarray extension, using the data/test__int.data:
> CREATE EXTENSION intarray;
> CREATE TABLE test__int( a int[] );1
> \copy test__int from 'data/test__int.data'
>
> For queries any from line 98+ on contrib/intarray/sql/_int.sql will wo= rk.
>
> Then I added extra debug messages to llvmjit_inline.cpp on add_module_= to_inline_search_path() function, also on llvm_build_inline_plan(), I was a= ble to see many functions in this module being successfully inlined.
>
> I'm attaching a new patch based on your original work which add fu= rther support for generating bitcode from:

Thanks for doing that!

>=C2=A0 - Generated backend sources: processed by flex, bison, etc.
>=C2=A0 - Generated contrib module sources,

I think we do not need to separate these two.

=C2=A0 =C2=A0foreach srcfile : bitcode_module['srcfiles']
-=C2=A0 =C2=A0 if meson.version().version_compare('>=3D0.59') +=C2=A0 =C2=A0 srcfilename =3D '@0@'.format(srcfile)
+=C2=A0 =C2=A0 if srcfilename.startswith('<CustomTarget')
+=C2=A0 =C2=A0 =C2=A0 srcfilename =3D srcfile.full_path().split(meson.build= _root() + '/')[1]
+=C2=A0 =C2=A0 elif meson.version().version_compare('>=3D0.59')<= br>
Also, checking if the string starts with '<CustomTarget' is a bi= t
hacky, and 'srcfilename =3D '@0@'.format(srcfile)' causes a= deprecation
warning. So, instead of this we can process all generated sources like
how generated backend sources are processed. I updated the patch with
that.

> On this patch I just included fmgrtab.c and src/backend/parser for the= backend generated code.
> For contrib generated sources I added contrib/cube as an example.

I applied your contrib/cube example and did the same thing for the contrib/= seg.

> All relevant details about the changes are included in the patch itsel= f.
>
> As you may know already I also created a PR focused on llvm bitcode em= ission on meson, it generates bitcode for all backend and contribution modu= les, currently under review by some colleagues at Percona: https://github.com/percona/postgres/pull/103
> I'm curious if we should get all or some of the generated backend = sources compiled to bitcode, similar to contrib modules.

I think we can do this. I added other backend sources like you did in
the PR but attached it as another patch (0007) because I wanted to
hear other people's opinions on that first.

v3 is attached.

--
Regards,
Nazir Bilal Yavuz
Microsoft
--000000000000c65bb30630255505--