<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@SimSun";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.emailquote, li.emailquote, div.emailquote
{mso-style-name:emailquote;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:1.0pt;
border:none;
padding:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">To me, it is also an issue related to SIMD signature matching when the vectorizer kicks in. Losing info from FE to BE is not good in general.
<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><a name="_____replyseparator"></a><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Doerfert, Johannes [mailto:jdoerfert@anl.gov]
<br>
<b>Sent:</b> Monday, June 24, 2019 8:49 AM<br>
<b>To:</b> Tian, Xinmin <xinmin.tian@intel.com>; Saito, Hideki <hideki.saito@intel.com>; Francesco Petrogalli <Francesco.Petrogalli@arm.com><br>
<b>Cc:</b> Simon Moll <moll@cs.uni-saarland.de>; LLVM Development List <llvm-dev@lists.llvm.org>; Clang Dev <cfe-dev@lists.llvm.org>; Renato Golin <rengolin@gmail.com>; Finkel, Hal J. <hfinkel@anl.gov>; Andrea Bocci <andrea.bocci@cern.ch>; Elovikov, Andrei
<andrei.elovikov@intel.com>; Alexey Bataev <a.bataev@hotmail.com>; nd <nd@arm.com>; Roman Lebedev <lebedev.ri@gmail.com>; Philip Reames <listmail@philipreames.com>; Shawn Landden <slandden@gmail.com><br>
<b>Subject:</b> Re: RFC: Interface user provided vector functions with the vectorizer.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif;color:black">@Xinmin, Saito: If Clang/the frontend generates the version there is no problem, or is there? The frontend knows about the original source
type and it's ABI specific lowering already. <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif;color:black">@Francesco, we should even consider putting the generating capabilities outside of the OpenMP code generation (in the future). That could
allow easier reuse by other frontends.<o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif;color:black">Get
<a href="https://aka.ms/ghei36">Outlook for Android</a><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="98%" align="center">
</div>
<div id="x_divRplyFwdMsg">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black"> Tian, Xinmin <<a href="mailto:xinmin.tian@intel.com">xinmin.tian@intel.com</a>><br>
<b>Sent:</b> Monday, June 24, 2019 5:28:45 PM<br>
<b>To:</b> Saito, Hideki; Francesco Petrogalli; Doerfert, Johannes<br>
<b>Cc:</b> Simon Moll; LLVM Development List; Clang Dev; Renato Golin; Finkel, Hal J.; Andrea Bocci; Elovikov, Andrei; Alexey Bataev; nd; Roman Lebedev; Philip Reames; Shawn Landden<br>
<b>Subject:</b> RE: RFC: Interface user provided vector functions with the vectorizer.</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:11.0pt">>>>>I don’t know if this is going to be a problem for other architectures<br>
<br>
++++++I haven't checked what IA-32/Intel64 should do for type 2, but I fully agree that this needs to be done properly according to the ABI.<br>
<br>
Agreed. It looks we have an issue here. Given this is parameter, could we use metadata or attribute to preserve the "struct" info, in ICC, we called BE type saved info in the symtab.
<br>
<br>
Xinmin <br>
<br>
-----Original Message-----<br>
From: Saito, Hideki <br>
Sent: Friday, June 21, 2019 4:44 PM<br>
To: Francesco Petrogalli <<a href="mailto:Francesco.Petrogalli@arm.com">Francesco.Petrogalli@arm.com</a>>; Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov">jdoerfert@anl.gov</a>><br>
Cc: Simon Moll <<a href="mailto:moll@cs.uni-saarland.de">moll@cs.uni-saarland.de</a>>; LLVM Development List <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>>; Clang Dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>>;
Renato Golin <<a href="mailto:rengolin@gmail.com">rengolin@gmail.com</a>>; Finkel, Hal J. <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>>; Andrea Bocci <<a href="mailto:andrea.bocci@cern.ch">andrea.bocci@cern.ch</a>>; Elovikov, Andrei <<a href="mailto:andrei.elovikov@intel.com">andrei.elovikov@intel.com</a>>;
Alexey Bataev <<a href="mailto:a.bataev@hotmail.com">a.bataev@hotmail.com</a>>; Tian, Xinmin <<a href="mailto:xinmin.tian@intel.com">xinmin.tian@intel.com</a>>; nd <<a href="mailto:nd@arm.com">nd@arm.com</a>>; Roman Lebedev <<a href="mailto:lebedev.ri@gmail.com">lebedev.ri@gmail.com</a>>;
Philip Reames <<a href="mailto:listmail@philipreames.com">listmail@philipreames.com</a>>; Shawn Landden <<a href="mailto:slandden@gmail.com">slandden@gmail.com</a>><br>
Subject: RE: RFC: Interface user provided vector functions with the vectorizer.<br>
<br>
<br>
>In all cases, the IR type of the parameters in `foo` is i64, therefore is not possible to distinguish what C type generated the signature of `foo`.<br>
<br>
Ouch.<br>
<br>
>I don’t know if this is going to be a problem for other architectures<br>
<br>
I haven't checked what IA-32/Intel64 should do for type 2, but I fully agree that this needs to be done properly according to the ABI.<br>
<br>
>Therefore, I would like to propose a change to the RFC, which would move the responsibility off generating the vector function signature from LLVM to clang.<br>
<br>
Makes sense to me.<br>
<br>
-----Original Message-----<br>
From: Francesco Petrogalli [<a href="mailto:Francesco.Petrogalli@arm.com">mailto:Francesco.Petrogalli@arm.com</a>]<br>
Sent: Friday, June 21, 2019 2:04 PM<br>
To: Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov">jdoerfert@anl.gov</a>><br>
Cc: Simon Moll <<a href="mailto:moll@cs.uni-saarland.de">moll@cs.uni-saarland.de</a>>; LLVM Development List <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>>; Clang Dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>>;
Renato Golin <<a href="mailto:rengolin@gmail.com">rengolin@gmail.com</a>>; Finkel, Hal J. <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>>; Andrea Bocci <<a href="mailto:andrea.bocci@cern.ch">andrea.bocci@cern.ch</a>>; Elovikov, Andrei <<a href="mailto:andrei.elovikov@intel.com">andrei.elovikov@intel.com</a>>;
Alexey Bataev <<a href="mailto:a.bataev@hotmail.com">a.bataev@hotmail.com</a>>; Saito, Hideki <<a href="mailto:hideki.saito@intel.com">hideki.saito@intel.com</a>>; Tian, Xinmin <<a href="mailto:xinmin.tian@intel.com">xinmin.tian@intel.com</a>>; nd <<a href="mailto:nd@arm.com">nd@arm.com</a>>;
Roman Lebedev <<a href="mailto:lebedev.ri@gmail.com">lebedev.ri@gmail.com</a>>; Philip Reames <<a href="mailto:listmail@philipreames.com">listmail@philipreames.com</a>>; Shawn Landden <<a href="mailto:slandden@gmail.com">slandden@gmail.com</a>><br>
Subject: Re: RFC: Interface user provided vector functions with the vectorizer.<br>
<br>
Hi all - I am working with a colleague to provide an initial implementation of this.<br>
<br>
We encountered a problem when dealing with generating the vector signatures of functions that use complex data.<br>
<br>
In this proposal, we expect the SVFS component in the backed to demangle the name of the function in the attribute to be able to reconstruct the signature of the vector function from the scalar function signature.<br>
<br>
In case of Complex data, this doesn’t seem to be possible, because the information of “being a vector of 2 lanes” that is supposed to be carried by the complex scalar is lost in the transformation the data type in a “coerced” type.<br>
<br>
Consider these three types and the function `foo`:<br>
<br>
// Type 1<br>
typedef _Complex int S;<br>
<br>
// Type 2<br>
typedef struct x{<br>
int a;<br>
int b;<br>
} S;<br>
<br>
// Type 3<br>
typedef uint64_t S;<br>
<br>
S foo(S a, S b) {<br>
return ...;<br>
}<br>
<br>
In all cases, the IR type of the parameters in `foo` is i64, therefore is not possible to distinguish what C type generated the signature of `foo`.<br>
<br>
I don’t know if this is going to be a problem for other architectures, but this is definitely a problem on AArch64 where we need to be able to generate the correct vector function signature for a specific simdlen(N) attached on `foo`. When simdlen(2), for type
1 the vector type is <4 x i32>, for type 2 is <2 x i64*>, for type 3 is <2 x i64>.<br>
<br>
Therefore, I would like to propose a change to the RFC, which would move the responsibility off generating the vector function signature from LLVM to clang.<br>
<br>
In particular, (and this I believe has already been mentioned by Johannes), we could use the @llvm.compiler.used intrinsic to mark those declaration that needs to stay in the IR and not optimized away OPT before reaching the vectorizer.<br>
<br>
In summary, the change would consist of:<br>
<br>
1. Generate symbols declaration/definitions of the vector function with the mangled name in the IR, and mark it with @llvm-compiler.used. This could be done in CGOpenMPRuntime.cpp 2. Use the attribute vector-abs-variant defined in this RFC to map scalar names
to vector ABI mangled name, and used the same redirection mechanism for the user provided vector name.<br>
3. Move the “vector function signature generation” from the SVFS in LLVM to the openmp code generator of the clang frontend<br>
<br>
The SVFS query system would still work as in the current proposal. The only difference is that the vector function signature would be given by the frontend and not need to be recomputed.<br>
<br>
Here is an example of ho the IR would look like with this change:<br>
<br>
```<br>
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (<2 x i32> (<2 x i32>)* @f to i8*)], section "llvm.metadata"<br>
<br>
declare dso_local <2 x i32> @_ZGVnN2v_foo(<2 x i32> returned)<br>
<br>
declare i32 @foo(i32) #0<br>
<br>
; other function definition, including the one provided by the user `my_vector_foo` if the user provided a definition and not just the declaration<br>
<br>
attribute #0 = {vector-function-abi-variant=“_ZGVnN2v_foo(my_vector_foo)"}<br>
<br>
```<br>
<br>
If the attribute @llvm.compiler.used is not suitable for this (I am not aware of all implication of using it on a global symbol), maybe we could come up with a intrinsics that does what we need (avoid deleting declarations that are not used) and name it @llvm.vector.function.used?<br>
<br>
Please let me know what you think, I will submit an updated proposal next week.<br>
<br>
Kind regards,<br>
<br>
Francesco<br>
<br>
> On Jun 17, 2019, at 7:05 AM, Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov">jdoerfert@anl.gov</a>> wrote:<br>
> <br>
> I agree with Simon. This looks good conceptually. I have minor implementation comments but that can wait till the code reviews.<br>
> <br>
> Sorry for the delay and thanks for working on this.<br>
> <br>
> Get Outlook for Android<br>
> <br>
> From: Simon Moll <<a href="mailto:moll@cs.uni-saarland.de">moll@cs.uni-saarland.de</a>><br>
> Sent: Monday, June 17, 2019 10:02:58 AM<br>
> To: Francesco Petrogalli; LLVM Development List; Clang Dev<br>
> Cc: Renato Golin; Finkel, Hal J.; Andrea Bocci; Elovikov, Andrei; <br>
> Alexey Bataev; Doerfert, Johannes; Saito, Hideki; Tian, Xinmin; nd; <br>
> Roman Lebedev; Philip Reames; Shawn Landden<br>
> Subject: Re: RFC: Interface user provided vector functions with the vectorizer.<br>
> <br>
> Hi Francesco,<br>
> <br>
> On 6/11/19 10:55 PM, Francesco Petrogalli wrote:<br>
> > Dear all,<br>
> ><br>
> > I have re-written the proposal for interfacing user provided vector <br>
> > functions, originally posted in both llvm-dev and cfe-dev mailing<br>
> > list:<br>
> ><br>
> > "[RFC] Expose user provided vector function for auto-vectorization."<br>
> ><br>
> > The proposal looks quite different from the original submission, <br>
> > therefore I took the liberty to start a new thread.<br>
> ><br>
> > The original thread generated some good discussion. In particular, <br>
> > Simon Moll and Johannes Doerfert (CCed) have managed to provide good <br>
> > arguments for the following claims:<br>
> ><br>
> > 1. The Vector Function ABI name mangling scheme of a target is not<br>
> > enough to describe all uses cases of function vectorization that<br>
> > the compiler might end up needing to support in the future.<br>
> I think the new name of the attribute makes this point clear.<br>
> > 2. `declare variant` needs to be handled properly at IR level, to be<br>
> > able to give the compiler the full OpenMP context of the directive.<br>
> ><br>
> > This proposal addresses those two concerns and other (I believe) <br>
> > minor concerns that have been raised in the previous thread.<br>
> ><br>
> > This proposal is provided with examples and a self assessment around <br>
> > extendibility.<br>
> ><br>
> > I have CCed all the people that have participated in the discussion <br>
> > so far, please let me know if you think I have missed anything of <br>
> > what have been raised.<br>
> ><br>
> > Kind regards,<br>
> ><br>
> > Francesco<br>
> <br>
> LGTM. Please add me as a reviewer for this when you post patches.<br>
> <br>
> Thanks!<br>
> <br>
> Simon<br>
> <br>
> ><br>
> > *** DRAFT OF THE PROPOSAL ***<br>
> ><br>
> > # SCOPE OF THE RFC : Interface user provided vector functions with the vectorizer.<br>
> ><br>
> > Because the users care about portability (across compilers, <br>
> > libraries and systems), I believe we have to base sour solution on a <br>
> > standard that describes the mapping from the scalar function to the <br>
> > vector function.<br>
> ><br>
> > Because OpenMP is standard and widely used, we should base our <br>
> > solution on the mechanisms that the standard provides, via the <br>
> > directives `declare simd` and `declare variant`, the latter when <br>
> > used in with the `simd` trait in the `construct` set.<br>
> ><br>
> > Please notice that:<br>
> ><br>
> > 1. The scope of the proposal is not implementing full support for<br>
> > `pragma omp declare variant`.<br>
> > 2. The scope of the proposal is not enabling the vectorizer to do new<br>
> > kind of vectorizations (e.g. RV-like vectorization described by<br>
> > Simon).<br>
> > 3. The proposal aims to be extendible wrt 1. and 2.<br>
> > 4. The IR attribute introduced in this proposal is equivalent to the<br>
> > one needed for the VecClone pass under development in<br>
> > <a href="https://reviews.llvm.org/D22792">https://reviews.llvm.org/D22792</a><br>
> ><br>
> > # CLANG COMPONENTS<br>
> ><br>
> > A C function attribute, `clang_declare_simd_variant`, to attach to <br>
> > the scalar version. The attribute provides enough information to the <br>
> > compiler about the vector shape of the user defined function. The <br>
> > vector shapes handled by the attribute are those handled by the <br>
> > OpenMP standard via `declare simd` (and no more than that).<br>
> ><br>
> > 1. The function attribute handling in clang is crafted with the<br>
> > requirement that it will be possible to re-use the same components<br>
> > for the info generated by `declare variant` when used with a `simd`<br>
> > traits in the `construct` set.<br>
> > 2. The attribute allows orthogonality with the vectorization that is<br>
> > done via OpenMP: the user vector function is still exposed for<br>
> > vectorization when not using `-fopenmp-[simd]` once the `declare<br>
> > simd` and `declare variant` directive of OpenMP will be available<br>
> > in the front-end.<br>
> ><br>
> > ## C function attribute: `clang_declare_simd_variant`<br>
> ><br>
> > The definition of this attribute has been crafted to match the <br>
> > semantics of `declare variant` for a `simd` construct described in <br>
> > OpenMP 5.0. I have added only the traits of the `device` set, `isa` <br>
> > and `arch`, which I believe are enough to cover for the use case of <br>
> > this proposal. If that is not the case, please provide an example, <br>
> > extending the attribute will be easy even once the current one is <br>
> > implemented.<br>
> ><br>
> > ```<br>
> > clang_declare_simd_variant(<variant-func-id>, <simd clauses>{, <br>
> > <context selector clauses>})<br>
> ><br>
> > <variant-func-id>:= The name of a function variant that is a base language identifier, or,<br>
> > for C++, a template-id.<br>
> ><br>
> > <simd clauses> := <simdlen>, <mask>{, <optional simd clauses>}<br>
> ><br>
> > <simdlen> := simdlen(<positive number>) | simdlen("scalable")<br>
> ><br>
> > <mask> := inbranch | notinbranch<br>
> ><br>
> > <optional simd clauses> := <linear clause><br>
> > | <uniform clause><br>
> > | <align clause> | {,<optional simd<br>
> > clauses>}<br>
> ><br>
> > <linear clause> := linear_ref(<var>,<step>)<br>
> > | linear_var(<var>, <step>)<br>
> > | linear_uval(<var>, <step>)<br>
> > | linear(<var>, <step>)<br>
> ><br>
> > <step> := <var> | <non zero number><br>
> ><br>
> > <uniform clause> := uniform(<var>)<br>
> ><br>
> > <align clause> := align(<var>, <positive number>)<br>
> ><br>
> > <var> := Name of a parameter in the scalar function <br>
> > declaration/definition<br>
> ><br>
> > <non zero number> := ... | -2 | -1 | 1 | 2 | ...<br>
> ><br>
> > <positive number> := 1 | 2 | 3 | ...<br>
> ><br>
> > <context selector clauses> := {<isa>}{,} {<arch>}<br>
> ><br>
> > <isa> := isa(target-specific-value)<br>
> ><br>
> > <arch> := arch(target-specific-value)<br>
> ><br>
> > ```<br>
> ><br>
> > # LLVM COMPONENTS:<br>
> ><br>
> > ## VectorFunctionShape class<br>
> ><br>
> > The object `VectorFunctionShape` contains the information about the <br>
> > kind of vectorization available for an `llvm::Call`.<br>
> ><br>
> > The object `VectorFunctionShape` must contain the following information:<br>
> ><br>
> > 1. Vectorization Factor (or number or concurrent lanes executed by the<br>
> > SIMD version of the function). Encoded by unsigned integer.<br>
> > 2. Whether the vector function is requested for scalable<br>
> > vectorization, encoded by a boolean.<br>
> > 3. Information about masking / no masking, encoded by a boolean.<br>
> > 4. Information about the parameters, encoded in a container that<br>
> > carries objects of type `ParamaterType`, to describe features like<br>
> > `linear` and `uniform`.<br>
> > 5. Function name redirection, if a user has specified to use a custom<br>
> > name instead of the Vector Function ABI ones.<br>
> ><br>
> > Items 1. to 5. represents the information stored in the <br>
> > `vector-function-abi-variant` attribute (see next section).<br>
> ><br>
> > The object can be extended in the future to include new <br>
> > vectorization kinds (for example the RV-like vectorization of the <br>
> > Region Vectorizer), or to add more context information that might <br>
> > come from other uses of OpenMP `declare variant`, or to add new <br>
> > Vector Function ABIs not based on OpenMP. Such information can be <br>
> > retrieved by attributes that will be added to describe the `Call` instance.<br>
> ><br>
> > ## IR Attribute<br>
> ><br>
> > We define a `vector-function-abi-variant` attribute that lists the <br>
> > mangled names produced via the mangling function of the Vector <br>
> > Function ABI rules.<br>
> ><br>
> > ```<br>
> > vector-function-abi-variant = "abi_mangled_name_01, abi_mangled_name_02(user_redirection),..."<br>
> > ```<br>
> ><br>
> > 1. Because we use only OpenMP `declare simd` vectorization, and<br>
> > because we require a vector Function ABI, we make this explicit<br>
> > in the name of the attribute.<br>
> > 2. Because the Vector Function ABIs encode all the information<br>
> > needed to know the vectorization shape of the vector function in<br>
> > the mangled names, we provide the mangled name via the<br>
> > attribute.<br>
> > 3. Function names redirection is specified by enclosing the name of<br>
> > the redirection in parenthesis, as in<br>
> > `abi_mangled_name_02(user_redirection)`.<br>
> ><br>
> > ## Vector ABI Demangler<br>
> ><br>
> > The “Vector ABI demangler”, is the component that demangles the data <br>
> > in the `vector-function-abi-variant` attribute and that provides the <br>
> > instances of the class `VectorFunctionShape` that can be derived by <br>
> > the mangled names listed in the attribute.<br>
> ><br>
> > ## Query interface: Search Vector Function System (SVFS)<br>
> ><br>
> > An interface that can be queried by the LLVM components to <br>
> > understand whether or not a scalar function can be vectorized, and <br>
> > that retrieves the vector function to be used if such vector shape is available.<br>
> ><br>
> > 1. This component is going to be unrelated to OpenMP.<br>
> > 2. This component will use internally the demangler defined in the<br>
> > previous section, but it will not expose any aspect of the Vector<br>
> > Function ABI via its interface.<br>
> ><br>
> > The interface provides two methods.<br>
> ><br>
> > ```<br>
> > std::vector<VectorFunctionShape><br>
> > SVFS::isFunctionVectorizable(llvm::CallInst * Call);<br>
> ><br>
> > llvm::Function * SVFS::getVectorizedFunction(llvm::CallInst * Call, <br>
> > VectorFunctionShape Info); ```<br>
> ><br>
> > The first method is used to list all the vector shapes that <br>
> > available and attached to a scalar function. An empty results means <br>
> > that no vector versions are available.<br>
> ><br>
> > The second method retrieves the information needed to build a call <br>
> > to a vector function with a specific `VectorFunctionShape` info.<br>
> ><br>
> > # (SELF) ASSESSMENT ON EXTENDIBILITY<br>
> ><br>
> ><br>
> > 1. Extending the C function attribute `clang_declare_simd_variant` to<br>
> > new Vector Function ABIs that use OpenMP will be straightforward<br>
> > because the attribute is tight to such ABIs and OpenMP.<br>
> > 2. The C attribute `clang_declare_simd_variant` and the `declare<br>
> > variant` directive used for the `simd` trait will be sharing the<br>
> > internals in clang, so adding the OpenMP functionality for `simd`<br>
> > traits will be mostly handling the directive in the OpenMP<br>
> > parser. How this should be done is described in<br>
> > <br>
> > <a href="https://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attri">
https://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attri</a><br>
> > bute 3. The IR attribute `vector-function-abi-variant` is not to be<br>
> > extended to represent other kind of vectorization other than those<br>
> > handled by `declare simd` and that are handled with a Vector<br>
> > Function ABI.<br>
> > 4. The IR attribute `vector-function-abi-variant` is not defined to be<br>
> > extended to represent the information of `declare variant` in its<br>
> > totality.<br>
> > 5. The IR attribute will not need to change when we will introduce non<br>
> > vector function ABI vectorization (RV-like, reductions...) or when<br>
> > we will decide to fully support `declare variant`. The information<br>
> > it carries will not need to be invalidated, but just extended with<br>
> > new attributes that will need to be handled by the<br>
> > `VectorFunctionShape` class, in a similar way the<br>
> > `llvm::FPMathOperator` does with the `llvm::FastMathFlags`, which<br>
> > operates on individual attributes to describe an overall<br>
> > functionality.<br>
> ><br>
> > # Examples<br>
> ><br>
> > ## Example 1<br>
> ><br>
> > Exposing an Advanced SIMD vector function when targeting Advanced <br>
> > SIMD in AArch64.<br>
> ><br>
> > ```<br>
> > double foo_01(double Input)<br>
> > __attribute__(clang_declare_simd_variant(“vector_foo_01",<br>
> > simdlen(2), notinbranch, isa("simd"));<br>
> ><br>
> > // Advanced SIMD version<br>
> > float64x2_t vector_foo_01(float64x2_t VectorInput); ```<br>
> ><br>
> > The resulting IR attribute is:<br>
> ><br>
> > ```<br>
> > attribute #0 = {vector-abi-variant="_ZGVnN2v_foo_01(vector_foo_01)"}<br>
> > ```<br>
> ><br>
> > ## Example 2<br>
> ><br>
> > Exposing an Advanced SIMD vector function when targeting Advanced <br>
> > SIMD in AArch64, but with the wrong signature. The user specifies a <br>
> > masked version of the function in the clauses of the attribute, the <br>
> > compiler throws an error suggesting the signature expected for <br>
> > ``vector_foo_02.``<br>
> ><br>
> > ```<br>
> > double foo_02(double Input)<br>
> > __attribute__(clang_declare_simd_variant(“vector_foo_02",<br>
> > simdlen(2), inbranch, isa("simd"));<br>
> ><br>
> > // Advanced SIMD version<br>
> > float64x2_t vector_foo_02(float64x2_t VectorInput);<br>
> > // (suggested) compiler error -> ^ Missing mask parameter of type `uint64x2_t`.<br>
> > ```<br>
> ><br>
> > ## Example 3<br>
> ><br>
> > Targeting `sincos`-like signatures.<br>
> ><br>
> > ```<br>
> > void foo_03(double Input, double * Output) <br>
> > __attribute__(clang_declare_simd_variant(“vector_foo_03",<br>
> > simdlen(2), notinbranch, linear(Output, 1), isa("simd"));<br>
> ><br>
> > // Advanced SIMD version<br>
> > void vector_foo_03(float64x2_t VectorInput, double * Output); ```<br>
> ><br>
> > The resulting IR attribute is:<br>
> ><br>
> > ```<br>
> > attribute #0 =<br>
> > {vector-abi-variant="_ZGVnN2vl8_foo_03(vector_foo_03)"}<br>
> > ```<br>
> > ## Example 4<br>
> ><br>
> > Scalable vectorization targeting SVE<br>
> ><br>
> > ```<br>
> > double foo_04(double Input)<br>
> > __attribute__(clang_declare_simd_variant(“vector_foo_04",<br>
> > simdlen("scalable"), notinbranch, isa("sve"));<br>
> ><br>
> > // SVE version<br>
> > svfloat64_t vector_foo_04(svfloat64_t VectorInput, svbool_t Mask); <br>
> > ```<br>
> ><br>
> > The resulting IR attribute is:<br>
> ><br>
> > ```<br>
> > attribute #0 = {vector-abi-variant="_ZGVsM2v_foo_04(vector_foo_04)"}<br>
> > ```<br>
> ><br>
> > ## Example 5<br>
> ><br>
> > Fixed length vectorization targeting SVE<br>
> ><br>
> > ```<br>
> > double foo_05(double Input)<br>
> > __attribute__(clang_declare_simd_variant(“vector_foo_05",<br>
> > simdlen(4), inbranch, isa("sve"));<br>
> ><br>
> > // Fixed-length SVE version<br>
> > svfloat64_t vector_foo_05(svfloat64_t VectorInput, svbool_t Mask); <br>
> > ```<br>
> ><br>
> > The resulting IR attribute is:<br>
> ><br>
> > ```<br>
> > attribute #0 = {vector-abi-variant="_ZGVsM2v_foo_04(vector_foo_04)"}<br>
> > ```<br>
> ><br>
> > ## Example 06<br>
> ><br>
> > This is an x86 example, equivalent to the one provided by Andrei <br>
> > Elovikow in <br>
> > <a href="http://lists.llvm.org/pipermail/llvm-dev/2019-June/132885.html">http://lists.llvm.org/pipermail/llvm-dev/2019-June/132885.html</a>.<br>
> > Godbolt rendering with ICC at <a href="https://godbolt.org/z/Of1NxZ">https://godbolt.org/z/Of1NxZ</a><br>
> ><br>
> > ```<br>
> > float MyAdd(float* a, int b)<br>
> > __attribute__(clang_declare_simd_variant(“MyAddVec", simdlen(8), notinbranch, arch("core_2nd_gen_avx")) {<br>
> > return *a + b;<br>
> > }<br>
> ><br>
> ><br>
> > __m256 MyAddVec(float* v_a, __m128i v_b1, __m128i v_b2); ```<br>
> ><br>
> > The resulting IR attribute is:<br>
> ><br>
> > ```<br>
> > attribute #0 = {vector-abi-variant="_ZGVbN8l4v_MyAdd(MyAddVec)"}<br>
> > ```<br>
> ><br>
> > ## Example showing interaction with `declare simd`<br>
> ><br>
> > ```<br>
> > #pragma omp declare simd linear(a) notinbranch float foo_06(float <br>
> > *a, int x) __attribute__(clang_declare_simd_variant(“vector_foo_06", simdlen(4), linear(a), notinbranch, arch("armv8.2-a+simd")) {<br>
> > return *a + x;<br>
> > }<br>
> ><br>
> > // Advanced SIMD version<br>
> > float32x4_t vector_foo_06(float *a, int32x4_t vx) { // Custom <br>
> > implementation.<br>
> > }<br>
> > ```<br>
> ><br>
> > The resulting IR attribute is made of three symbols:<br>
> ><br>
> > 1. `_ZGVnN2l4v_foo_06` and `_ZGVnN4l4v_foo_06`, which represent the<br>
> > ones the compiler builds by auto-vectorizing `foo_06` according to<br>
> > the rule defined in the Vector Function ABI specifications for<br>
> > AArch64.<br>
> > 2. `_ZGVnN4l4v_foo_06(vector_foo_06)`, which represents the<br>
> > user-defined redirection of the 4-lane version of `foo_06` to the<br>
> > custom implementation provided by the user when targeting Advanced<br>
> > SIMD for version 8.2 of the A64 instruction set.<br>
> ><br>
> > ```<br>
> > attribute #0 =<br>
> > {vector-function-abi-variant="_ZGVnN2l4v_foo_06,_ZGVnN4l4v_foo_06,_Z<br>
> > GVnN4l4v_foo_06(vector_foo_06)"}<br>
> > ```<br>
> ><br>
> --<br>
> <br>
> Simon Moll<br>
> Researcher / PhD Student<br>
> <br>
> Compiler Design Lab (Prof. Hack)<br>
> Saarland University, Computer Science<br>
> Building E1.3, Room 4.31<br>
> <br>
> Tel. +49 (0)681 302-57521 : <a href="mailto:moll@cs.uni-saarland.de">moll@cs.uni-saarland.de</a> Fax. +49 (0)681<br>
> 302-3065 : <a href="http://compilers.cs.uni-saarland.de/people/moll">http://compilers.cs.uni-saarland.de/people/moll</a><o:p></o:p></span></p>
</div>
</div>
</body>
</html>