Page MenuHomePhabricator

Add SVE opaque built-in types
Needs ReviewPublic

Authored by rsandifo-arm on Jun 6 2019, 8:45 AM.



This patch adds the SVE built-in types defined by the Procedure Call
Standard for the Arm Architecture:

It handles the types in all relevant places that deal with built-in types.
At the moment, some of these places bail out with an error, including:

(1) trying to generate LLVM IR for the types
(2) trying to generate debug info for the types
(3) trying to mangle the types using the Microsoft C++ ABI
(4) trying to @encode the types in Objective C

(1) and (2) are fixed by follow-on patches but (unlike this patch)
they deal mostly with target-specific LLVM details, so seemed like
a logically separate change. There is currently no spec for (3) and
(4), so reporting an error seems like the correct behaviour for now.

The intention is that the types will become sizeless types:

The main purpose of the sizeless type extension is to diagnose
impossible or dangerous uses of the types, such as any that would
require sizeof to have a meaningful defined value.

Until then, the patch sets the alignments of the types to the values
specified in the link above. It also sets the sizes of the types to
zero, which is chosen to be consistently wrong and shouldn't affect
correctly-written code (i.e. code that would compile even with the
sizeless type extension).

The patch adds the common subset of functionality needed to test the
sizeless type extension on the one hand and to provide SVE intrinsic
functions on the other. After this patch, the two pieces of work are
essentially independent.

The patch is based on one by Graham Hunter:

Diff Detail

Event Timeline

rsandifo-arm created this revision.Jun 6 2019, 8:45 AM



@rjmccall you probably should review this part.

erik.pilkington added inline comments.

Sorry for the drive by comment, but: All of these mangling should really be using the "vendor extension" production IMO:

<type> ::= u <source-name>

As is, these manglings intrude on the users's namespace, (i.e. if they had a type named objc_selector or something), and confuse demanglers which incorrectly assume these are substitutable (vendor extension builtin types are substitutable too though, but that should be handled here).

Ka-Ka added a subscriber: Ka-Ka.Jun 11 2019, 11:39 PM
rsandifo-arm marked an inline comment as done.Wed, Jun 19, 7:13 AM
rsandifo-arm added inline comments.

It isn't obvious from the patch, but the SVE names that we're mangling are predefined names like __SVInt8_t. rather than user-facing names like svint8_t The predefined names and their mangling are defined by the platform ABI (, so it wouldn't be valid for another part of the implementation to use those names for something else.

I realise you were making a general point here though, sorry.


The mangling in the document you linked does use the vendor extension production here though, i.e. the example is void f(int8x8_t), which mangles to _Z1fu10__Int8x8_t. It is true that this shouldn't ever collide with another mangling in practice, but my point is there isn't any need to smuggle it into the mangling by pretending it's a user defined type, when the itanium grammar and related tools have a special way for vendors to add builtin types.

rovka added a subscriber: rovka.Thu, Jun 27, 4:59 AM

Just a few nits/suggestions.


You can be more specific :)


Maybe use SVE_TYPE instead of BUILTIN_TYPE, to avoid any confusion? You can't re-use a defition of BUILTIN_TYPE between this header and BuiltinTypes.def anyway, since they both undefine it at the end.


super nit: /// \brief SVE types with auto numeration


Here and in most other places: no need for 2 defines, you can just #define BUILTIN_TYPE (or if you choose to rename it to SVE_TYPE) since it's the same code for both vectors and predicates.


I agree with Erik here, the example in the PCS document seems to suggest using u. I think either the patch needs to be updated or the document needs to be more clear about what the mangling is supposed to look like.


Should we have llvm_unreachable or report a proper error? I like the unreachable if we're checking elsewhere that SVE isn't supported on Windows, but I notice we report errors for some of the other types.


I don't really know this code, but I can't help but notice that nullptr is only ever used for the void type. Is it safe to also use it for the SVE types, or can we do something else instead?

  • Fix comments in AArch64SVEACLETypes.def
  • Rename BUILTIN_TYPE to SVE_TYPE and use it where possible
  • Report errors for TODOs instead of using llvm_unreachable
  • Add a test for the errors
  • Formatting fixes
rsandifo-arm marked 7 inline comments as done.Thu, Jun 27, 11:20 AM

Thanks for the reviews!


Yeah, there were a few cut-&-pastos here, sorry. Hopefully fixed in the updated version.


Yeah, that's definitely better, especially given the different number of arguments. Done in the updated version.


Thanks, that shaved quite a lot of lines off the patch :-)


Thanks for highlighting this problem, and sorry for not noticing myself when pointing you at the doc.

Unfortunately, the specification and implementation already difer for the Advanced SIMD types, with both clang and GCC omitting the 'u' despite the spec saying it should be present. So we're considering changing the spec to match what's now the de facto ABI.

For SVE we do still have the opportunity to use 'u'. I've left it as-is for now though, until we've reached a decision about whether to follow existing practice for Advanced SIMD or whether to do what the spec says.


Fixed to report the error, since this wouldn't be trapped earlier.


Fixed to report an error here too and return a "safe" value until the TODO is fixed. Also added a test.

rovka added a comment.Tue, Jul 2, 3:21 AM

This looks much better, thanks! Shouldn't there be more tests, e.g. for mangling and maybe the ASTImporter?

Changes since last version:

  • Define the SVE types only for AArch64 targets
  • Use the vendor extension 'u' mangling, as per the spec
  • Report an error for @encode on the types
  • Fixed the licence text on the new file
  • Added more tests

Although I'd originally posted the patch so that the sizeless type
support had specific types to test, it'd be really useful if the patch
could go in independently of the sizeless type stuff, since the
patch contains the common subset of functionality needed by the
sizeless type patches and by the implementation of the intrinsics
(which apart from this patch are essentially separate pieces of work).

rsandifo-arm retitled this revision from SVE opaque type for C intrinsics demo to Add SVE opaque built-in types.Thu, Jul 4, 1:57 AM
rsandifo-arm edited the summary of this revision. (Show Details)

This looks much better, thanks! Shouldn't there be more tests, e.g. for mangling and maybe the ASTImporter?

Thanks. I've added tests for ASTImporter and mangling in the latest version, as well as tests for typeinfo, AST dumping, Objective C errors, PCH serialisation and (until we diagnose them as an error) sizeof/alignof queries.

The ASTImporter and the test for it looks good to me, thanks!

martong resigned from this revision.Thu, Jul 4, 2:34 AM
rjmccall added inline comments.Thu, Jul 4, 12:24 PM

These do seem more "builtin" than the SIMD types, but I don't think it deeply matters either way, since these are already reserved names.

Ping, and thanks for the reviews so far. I think I've addressed all the comments to date and I've tried to make the patch ready to commit in its current state (rather than the RFC that it originally was).

It would be really useful if we could apply the patch soon, so that we can start implementing the intrinsic functions. The patch is now independent of the "sizeless type" stuff, if there are concerns about that.

Seems reasonable to me.