This is an archive of the discontinued LLVM Phabricator instance.

[VectorUtils] Enhance VFABI demangling API
Needs ReviewPublic

Authored by Nuullll on Jan 12 2023, 8:11 PM.

Details

Summary

This patch adds more flexibility to the original VFABI demangling API.

  1. Allow demangling an empty parameter list, which is explicitly allowed by X86 VFABI doc (section 2.6) and probably implicitly allowed by AArch64 VFABI doc (section 4.1) as well.
  2. Allow passing the module as a nullptr, so that we don't check the existence of the demangled vector function name. This is useful when we want to create the widened function according to the demangling result.

Signed-off-by: Yilong Guo <yilong.guo@intel.com>

Diff Detail

Event Timeline

Nuullll created this revision.Jan 12 2023, 8:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 8:11 PM
Nuullll published this revision for review.Jan 12 2023, 8:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 8:23 PM
lebedev.ri requested changes to this revision.Jan 15 2023, 5:06 PM

Not really familiar with this.

  1. Do we need that parameter? Is empty <parameters> list generally ill-formed and must be diagnosed?
  2. I'm not seeing what callee (other than the tests) actually sets that parameter to true?

(marking as reviewed)

This revision now requires changes to proceed.Jan 15 2023, 5:06 PM

Thanks a lot for reviewing!

@lebedev.ri

  1. Do we need that parameter? Is empty <parameters> list generally ill-formed and must be diagnosed?

There's one subtle difference in AArch64 and X86 VFABI documentations about Vector Function Name Mangling: the X86 doc explicitly allows an empty parameter list while the AArch64 doc doesn't -- so I think this is why we need a parameter to let users choose whatever standard to conform. In fact, our internal implementation has to remove the diagnostic on empty parameter from tryDemangleForVFABI to make sure we're conforming the X86 VFABI.

  1. I'm not seeing what callee (other than the tests) actually sets that parameter to true?

Yes, the tryDemangleForVFABI API isn't used much in the LLVM codebase (and I didn't touch those usages to keep their behaviors unchanged, for safety). But like I mentioned above, a valid X86 implementation should allow an empty parameter list according to the current VFABI doc.

Thanks a lot for reviewing!

@lebedev.ri

  1. Do we need that parameter? Is empty <parameters> list generally ill-formed and must be diagnosed?

There's one subtle difference in AArch64 and X86 VFABI documentations about Vector Function Name Mangling: the X86 doc explicitly allows an empty parameter list while the AArch64 doc doesn't -- so I think this is why we need a parameter to let users choose whatever standard to conform. In fact, our internal implementation has to remove the diagnostic on empty parameter from tryDemangleForVFABI to make sure we're conforming the X86 VFABI.

Nitpick: would it be possible to simply ask AArch64 for clarification, what is the intended behaviour for them?

  1. I'm not seeing what callee (other than the tests) actually sets that parameter to true?

Yes, the tryDemangleForVFABI API isn't used much in the LLVM codebase (and I didn't touch those usages to keep their behaviors unchanged, for safety). But like I mentioned above, a valid X86 implementation should allow an empty parameter list according to the current VFABI doc.

So it's a dead code?

Thanks a lot for reviewing!

@lebedev.ri

  1. Do we need that parameter? Is empty <parameters> list generally ill-formed and must be diagnosed?

There's one subtle difference in AArch64 and X86 VFABI documentations about Vector Function Name Mangling: the X86 doc explicitly allows an empty parameter list while the AArch64 doc doesn't -- so I think this is why we need a parameter to let users choose whatever standard to conform. In fact, our internal implementation has to remove the diagnostic on empty parameter from tryDemangleForVFABI to make sure we're conforming the X86 VFABI.

Nitpick: would it be possible to simply ask AArch64 for clarification, what is the intended behaviour for them?

@fpetrogalli Can you please kindly provide some inputs on AArch64 VFABI? Reference commit: https://github.com/ARM-software/abi-aa/commit/8fcf3f72d7cc200c50a4b029cee295469ab46fe5

  1. I'm not seeing what callee (other than the tests) actually sets that parameter to true?

Yes, the tryDemangleForVFABI API isn't used much in the LLVM codebase (and I didn't touch those usages to keep their behaviors unchanged, for safety). But like I mentioned above, a valid X86 implementation should allow an empty parameter list according to the current VFABI doc.

So it's a dead code?

One potential user is @mmasten 's https://reviews.llvm.org/D22792#change-yzkGZ4fTvFrz (see lib/Analysis/VectorVariant.cpp:50).
And I believe upstreaming VecClone for function vectorization is still part of Intel plan?
Tagging @xtian

Thanks a lot for reviewing!

@lebedev.ri

  1. Do we need that parameter? Is empty <parameters> list generally ill-formed and must be diagnosed?

There's one subtle difference in AArch64 and X86 VFABI documentations about Vector Function Name Mangling: the X86 doc explicitly allows an empty parameter list while the AArch64 doc doesn't -- so I think this is why we need a parameter to let users choose whatever standard to conform. In fact, our internal implementation has to remove the diagnostic on empty parameter from tryDemangleForVFABI to make sure we're conforming the X86 VFABI.

Nitpick: would it be possible to simply ask AArch64 for clarification, what is the intended behaviour for them?

@fpetrogalli Can you please kindly provide some inputs on AArch64 VFABI? Reference commit: https://github.com/ARM-software/abi-aa/commit/8fcf3f72d7cc200c50a4b029cee295469ab46fe5

It's been a long time since I looked into this, but from a quick skimming thought the Parameter mapping rules I think the behaviour of AArch64 would be to allow empty parameters list.

If you consider a function with signature int f(void), it means that the function has no input parameters. This means that the only <P> (parameter or return value, in the notation of the specs) considered to create the vector function is the return value.

So, if targeting for example NEON, the sequence of rules for mangling the name would be:

  1. MTV(P) = true (rule 3 of 4.1.1)
  2. PBV(P) = true ( rule 1 of 4.1.2)
  3. MAP(P) = ADVSIMD_MAP(P) (rule 2 of 4.1.3)
  4. LS(P) = 4 (rule 2 of 4.2.1 - T(P) is the type of P in the specs)
  5. NDS(f) = 4 (4.2.2)
  6. VLEN = 2,4 (rule 2 of 4.3.1)
  7. ADVSIMD_MAP(P) is a vector of VLEN elements of type T(P) (=int). -> int32x2_t and int32x4_t -> 2 vector functions can be associated to f (because NEON has 64 and 128 bit vector register views) (rule 3 of 4.3.2)

Therefore, according to the name mangling function at 4.5.1, we have 2 vector functions associated to f:

  • int32x2_t _ZVGnN2_f()
  • int32x4_t _ZVGnN4_f()

I hope helps clarifying a bit the current situation (unless of course I misinterpreted the specs).

I am CCing @stuij (hello mate! :) ), who I think is responsible for these bits of the compiler and the specs these days.

Notice that in the example with f I have ignored the generation of the versions that use Masking, because it seems odd to use masking for a function that have no input parameters... something that would need sorting in the specs, probably?

  1. I'm not seeing what callee (other than the tests) actually sets that parameter to true?

Yes, the tryDemangleForVFABI API isn't used much in the LLVM codebase (and I didn't touch those usages to keep their behaviors unchanged, for safety). But like I mentioned above, a valid X86 implementation should allow an empty parameter list according to the current VFABI doc.

So it's a dead code?

One potential user is @mmasten 's https://reviews.llvm.org/D22792#change-yzkGZ4fTvFrz (see lib/Analysis/VectorVariant.cpp:50).
And I believe upstreaming VecClone for function vectorization is still part of Intel plan?
Tagging @xtian

Matt added a subscriber: Matt.Jan 19 2023, 9:49 PM

Thanks a lot for reviewing!

@lebedev.ri

  1. Do we need that parameter? Is empty <parameters> list generally ill-formed and must be diagnosed?

There's one subtle difference in AArch64 and X86 VFABI documentations about Vector Function Name Mangling: the X86 doc explicitly allows an empty parameter list while the AArch64 doc doesn't -- so I think this is why we need a parameter to let users choose whatever standard to conform. In fact, our internal implementation has to remove the diagnostic on empty parameter from tryDemangleForVFABI to make sure we're conforming the X86 VFABI.

Nitpick: would it be possible to simply ask AArch64 for clarification, what is the intended behaviour for them?

@fpetrogalli Can you please kindly provide some inputs on AArch64 VFABI? Reference commit: https://github.com/ARM-software/abi-aa/commit/8fcf3f72d7cc200c50a4b029cee295469ab46fe5

It's been a long time since I looked into this, but from a quick skimming thought the Parameter mapping rules I think the behaviour of AArch64 would be to allow empty parameters list.

If you consider a function with signature int f(void), it means that the function has no input parameters. This means that the only <P> (parameter or return value, in the notation of the specs) considered to create the vector function is the return value.

So, if targeting for example NEON, the sequence of rules for mangling the name would be:

  1. MTV(P) = true (rule 3 of 4.1.1)
  2. PBV(P) = true ( rule 1 of 4.1.2)
  3. MAP(P) = ADVSIMD_MAP(P) (rule 2 of 4.1.3)
  4. LS(P) = 4 (rule 2 of 4.2.1 - T(P) is the type of P in the specs)
  5. NDS(f) = 4 (4.2.2)
  6. VLEN = 2,4 (rule 2 of 4.3.1)
  7. ADVSIMD_MAP(P) is a vector of VLEN elements of type T(P) (=int). -> int32x2_t and int32x4_t -> 2 vector functions can be associated to f (because NEON has 64 and 128 bit vector register views) (rule 3 of 4.3.2)

Therefore, according to the name mangling function at 4.5.1, we have 2 vector functions associated to f:

  • int32x2_t _ZVGnN2_f()
  • int32x4_t _ZVGnN4_f()

I hope helps clarifying a bit the current situation (unless of course I misinterpreted the specs).

I am CCing @stuij (hello mate! :) ), who I think is responsible for these bits of the compiler and the specs these days.

Notice that in the example with f I have ignored the generation of the versions that use Masking, because it seems odd to use masking for a function that have no input parameters... something that would need sorting in the specs, probably?

Hi @rsandifo-arm :) As our VFABI document owner, your thoughts?

I'm just responding to the above without having full context, so sorry if this is rehashing old discussions.

I agree with @fpetrogalli (hi!) that the intention probably wasn't to exclude parameterless functions. I suppose we should extend the grammar rule:

<parameters> := <parameter> { <parameter> }

to:

<parameters> := [<parameter> <parameters>]

But we don't have the equivalent of X86's:

d) If none of the above three cases is applicable, the CDT is int.

And I think that might have been deliberate. The X86 definition means that:

#pragma omp declare simd
void f(void);

is valid and produces multiple masked and unmasked versions (confirmed with GCC, whose implementation I'm more familiar with). But it isn't clear to me how such a function would be used, or how one would decide which vector ISA and vlen is the best fit. If there are well-defined semantics for this then perhaps we should change the AArch64 definition to allow it. But if there aren't well-defined semantics for it then it probably makes sense to keep things as they are.

So if it's just a question of whether the AArch64 ABI allows some parameterless functions, then like @fpetrogalli says, I think it does/should. But as it stands, there are some combinations that can be successfully demangled, but would never actually result from a valid #pragma. That includes the combination of a void return and no parameter types.

Thanks all for the inputs!

So if it's just a question of whether the AArch64 ABI allows some parameterless functions, then like @fpetrogalli says, I think it does/should. But as it stands, there are some combinations that can be successfully demangled, but would never actually result from a valid #pragma. That includes the combination of a void return and no parameter types.

I think we are in agreement that we should allow demangling a paramterless function name for both AArch64 and X86 VFABIs. I'll update the revision.

I agree with @fpetrogalli (hi!) that the intention probably wasn't to exclude parameterless functions. I suppose we should extend the grammar rule:

<parameters> := <parameter> { <parameter> }

to:

<parameters> := [<parameter> <parameters>]

@rsandifo-arm Will you kindly help clarify this in the AArch64 VFABI document?

Nuullll updated this revision to Diff 492973.Jan 27 2023, 8:26 PM
Nuullll edited the summary of this revision. (Show Details)

Removed the AllowEmptyParameter parameter.

fzou1 added a subscriber: fzou1.Jan 29 2023, 3:49 AM

A gentle ping :-)

mmasten accepted this revision.Feb 15 2023, 1:21 PM

LGTM. Are there any other outstanding concerns from anyone? From what I can tell from the latest comments everyone is ok with this change.

Hello, can anyone help commit this patch? Thanks!