<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hello,</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I would quite like to see this in Clang at least for the OpenCL builtin functions. Potentially we could migrate other Builtins to use TableGen too?</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">- For OpenCL developers, do we have an agreement currently to use this approach?<br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">- For the developers outside of OpenCL community, do you see any issue with a small increase (<span>a few hundred kilobytes</span>) of the Clang binary due to an include of a TableGen-ed trie file? Also would anyone
be interested in seeing other Builtins ported to this TableGen based approach?</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Thanks in advance,</p>
<p style="margin-top:0;margin-bottom:0">Anastasia<br>
</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> cfe-dev <cfe-dev-bounces@lists.llvm.org> on behalf of Joey Gouly via cfe-dev <cfe-dev@lists.llvm.org><br>
<b>Sent:</b> 02 November 2018 16:30<br>
<b>To:</b> clang-dev developer list<br>
<b>Cc:</b> nd; Sven Van Haastregt<br>
<b>Subject:</b> [cfe-dev] RFC: TableGen definition of OpenCL builtin functions</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
RFC: TableGen definition of OpenCL builtin functions<br>
<br>
<br>
<br>
# Introduction<br>
OpenCL has a large number of builtin functions that are available to OpenCL C<br>
users without explicitly declaring or including any header files.<br>
<br>
<br>
# Current status<br>
OpenCL builtins are currently declared in clang in lib/Headers/opencl-c.h and<br>
the flag -finclude-default-header includes the header into the user's program.<br>
This file is currently ~16K lines and 768K of data and declares ~13K function<br>
declarations. This is slow to parse for every OpenCL program that is compiled.<br>
Attempts to use PCH have been made to reduce the parsing time, at increased<br>
cost of space. The resulting PCH file is several megabytes, which is too big<br>
for some use cases.<br>
<br>
<br>
An approach to improve the current situation was attempted in [1], to split the<br>
header into smaller components. It seems this approach has several drawbacks<br>
related to macros and PCH.<br>
<br>
<br>
Another attempted improvement was made in [2], which was aimed directly at the<br>
'convert' builtin, which has ~6000 overloads.<br>
<br>
<br>
# This RFC<br>
The approach in this RFC uses TableGen to declare the OpenCL builtins in a<br>
concise manner. TableGen generates a trie and tables for recognising and<br>
constructing the function declaration. Clang then constructs the necessary<br>
builtin function declarations when a regular name lookup fails. This approach<br>
avoids the need to parse the opencl-c.h header and the tables themselves are<br>
significantly smaller than the PCH file.<br>
<br>
<br>
This follows a similar approach to Clang's current builtins, declared in<br>
include/clang/Basic/Builtins.def.<br>
Some reasons to go for a TableGen-based approach are:<br>
<br>
<br>
1) We want the declarations to be more concise, which we can do with TableGen<br>
but not with preprocessor macros.<br>
<br>
<br>
2) The OpenCL builtins do not need a BuiltinID, nor any other special handling<br>
in Clang, as their implementations are provided by the OpenCL vendor.<br>
<br>
<br>
Although out of the scope of this RFC, the builtins in Builtins.def could be<br>
migrated to a similar approach, there is already a comment in Builtins.def<br>
about moving to TableGen (from 2007!).<br>
<br>
<br>
The proposed solution can be viewed here <a href="https://reviews.llvm.org/D53023">
https://reviews.llvm.org/D53023</a><br>
<br>
<br>
# Next steps<br>
This is still a work-in-progress patch as it is missing functionality and has<br>
not been benchmarked for size/performance impact. We are hoping to hear from<br>
the wider clang community, as it might not only affect the OpenCL users. In<br>
particular, we expect the clang binary size will increase by roughly a few<br>
hundred kilobytes.<br>
<br>
<br>
Any feedback is welcome!<br>
<br>
<br>
# References<br>
[1] <a href="https://reviews.llvm.org/D51544">https://reviews.llvm.org/D51544</a><br>
[2] <a href="https://reviews.llvm.org/D52457">https://reviews.llvm.org/D52457</a><br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
cfe-dev@lists.llvm.org<br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>