Skip to content

Commit

Permalink
[AArch64] Alter arm_sve.h to be target-based, not preprocessor based.
Browse files Browse the repository at this point in the history
This patch makes SVE intrinsics more useable by gating them on the
target, not by ifdef preprocessor macros. See #56480. This alters the
SVEEmitter for arm_sve.h to remove the #ifdef guards and instead use
TARGET_BUILTIN with the correct features so that the existing "'func'
needs target feature sve" error will be generated when sve is not
present.

The ArchGuard containing defines in the SVEEmitter are changed to
TargetGuard containing target features. In the arm_neon.h emitter there
are both existing ArchGuard ifdefs mixed with new TargetGuard target
feature guards, so the name is change in the SVE too for consistency.
The few functions that are present in arm_sve.h (as opposed to builtin
aliases) have __attribute__((target("sve"))) added. Some of the tests
needed to be rejigged a little, as well as updating the error message,
as the error now happens at a later point.

Differential Revision: https://reviews.llvm.org/D131064
  • Loading branch information
davemgreen committed Jan 4, 2023
1 parent f8d008d commit 6cac7c2
Show file tree
Hide file tree
Showing 9 changed files with 3,588 additions and 3,631 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Basic/BuiltinsSVE.def
Expand Up @@ -19,3 +19,4 @@
#undef GET_SVE_BUILTINS

#undef BUILTIN
#undef TARGET_BUILTIN
118 changes: 59 additions & 59 deletions clang/include/clang/Basic/arm_sve.td

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion clang/lib/Basic/Targets/AArch64.cpp
Expand Up @@ -31,7 +31,9 @@ static constexpr Builtin::Info BuiltinInfo[] = {
#include "clang/Basic/BuiltinsNEON.def"

#define BUILTIN(ID, TYPE, ATTRS) \
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
#include "clang/Basic/BuiltinsSVE.def"

#define BUILTIN(ID, TYPE, ATTRS) \
Expand Down
102 changes: 51 additions & 51 deletions clang/test/Sema/aarch64-sve-intrinsics/acle_sve_bfloat.cpp
@@ -1,87 +1,87 @@
// REQUIRES: aarch64-registered-target

// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -fsyntax-only -verify -verify-ignore-unexpected=error,note %s
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -fsyntax-only -verify -verify-ignore-unexpected=error,note -emit-llvm -o - %s

#include <arm_sve.h>

void test_bfloat(svbool_t pg, uint64_t u64, int64_t i64, const bfloat16_t *const_bf16_ptr, svbfloat16_t bf16, svbfloat16x2_t bf16x2, svbfloat16x3_t bf16x3, svbfloat16x4_t bf16x4)
void test_bfloat(svbool_t pg, uint64_t u64, int64_t i64, const bfloat16_t *const_bf16_ptr, bfloat16_t *bf16_ptr, svbfloat16_t bf16, svbfloat16x2_t bf16x2, svbfloat16x3_t bf16x3, svbfloat16x4_t bf16x4)
{
// expected-error@+1 {{use of undeclared identifier 'svcreate2_bf16'}}
// expected-error@+1 {{'svcreate2_bf16' needs target feature sve,bf16}}
svcreate2_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svcreate3_bf16'}}
// expected-error@+1 {{'svcreate3_bf16' needs target feature sve,bf16}}
svcreate3_bf16(bf16, bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svcreate4_bf16'}}
// expected-error@+1 {{'svcreate4_bf16' needs target feature sve,bf16}}
svcreate4_bf16(bf16, bf16, bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svget2_bf16'}}
svget2_bf16(bf16x2, u64);
// expected-error@+1 {{use of undeclared identifier 'svget3_bf16'}}
svget3_bf16(bf16x3, u64);
// expected-error@+1 {{use of undeclared identifier 'svget4_bf16'}}
svget4_bf16(bf16x4, u64);
// expected-error@+1 {{use of undeclared identifier 'svld1_bf16'}}
// expected-error@+1 {{'svget2_bf16' needs target feature sve,bf16}}
svget2_bf16(bf16x2, 1);
// expected-error@+1 {{'svget3_bf16' needs target feature sve,bf16}}
svget3_bf16(bf16x3, 1);
// expected-error@+1 {{'svget4_bf16' needs target feature sve,bf16}}
svget4_bf16(bf16x4, 1);
// expected-error@+1 {{'svld1_bf16' needs target feature sve,bf16}}
svld1_bf16(pg, const_bf16_ptr);
// expected-error@+1 {{use of undeclared identifier 'svld1_vnum_bf16'}}
// expected-error@+1 {{'svld1_vnum_bf16' needs target feature sve,bf16}}
svld1_vnum_bf16(pg, const_bf16_ptr, i64);
// expected-error@+1 {{use of undeclared identifier 'svld1rq_bf16'}}
// expected-error@+1 {{'svld1rq_bf16' needs target feature sve,bf16}}
svld1rq_bf16(pg, const_bf16_ptr);
// expected-error@+1 {{use of undeclared identifier 'svldff1_bf16'}}
// expected-error@+1 {{'svldff1_bf16' needs target feature sve,bf16}}
svldff1_bf16(pg, const_bf16_ptr);
// expected-error@+1 {{use of undeclared identifier 'svldff1_vnum_bf16'}}
// expected-error@+1 {{'svldff1_vnum_bf16' needs target feature sve,bf16}}
svldff1_vnum_bf16(pg, const_bf16_ptr, i64);
// expected-error@+1 {{use of undeclared identifier 'svldnf1_bf16'}}
// expected-error@+1 {{'svldnf1_bf16' needs target feature sve,bf16}}
svldnf1_bf16(pg, const_bf16_ptr);
// expected-error@+1 {{use of undeclared identifier 'svldnf1_vnum_bf16'}}
// expected-error@+1 {{'svldnf1_vnum_bf16' needs target feature sve,bf16}}
svldnf1_vnum_bf16(pg, const_bf16_ptr, i64);
// expected-error@+1 {{use of undeclared identifier 'svldnt1_bf16'}}
// expected-error@+1 {{'svldnt1_bf16' needs target feature sve,bf16}}
svldnt1_bf16(pg, const_bf16_ptr);
// expected-error@+1 {{use of undeclared identifier 'svldnt1_vnum_bf16'}}
// expected-error@+1 {{'svldnt1_vnum_bf16' needs target feature sve,bf16}}
svldnt1_vnum_bf16(pg, const_bf16_ptr, i64);
// expected-error@+1 {{use of undeclared identifier 'svrev_bf16'}}
// expected-error@+1 {{'svrev_bf16' needs target feature sve,bf16}}
svrev_bf16(bf16);
// expected-error@+1 {{use of undeclared identifier 'svset2_bf16'}}
svset2_bf16(bf16x2, u64, bf16);
// expected-error@+1 {{use of undeclared identifier 'svset3_bf16'}}
svset3_bf16(bf16x3, u64, bf16);
// expected-error@+1 {{use of undeclared identifier 'svset4_bf16'}}
svset4_bf16(bf16x4, u64, bf16);
// expected-error@+1 {{use of undeclared identifier 'svst1_bf16'}}
svst1_bf16(pg, const_bf16_ptr, bf16);
// expected-error@+1 {{use of undeclared identifier 'svst1_vnum_bf16'}}
svst1_vnum_bf16(pg, const_bf16_ptr, i64, bf16);
// expected-error@+1 {{use of undeclared identifier 'svstnt1_bf16'}}
svstnt1_bf16(pg, const_bf16_ptr, bf16);
// expected-error@+1 {{use of undeclared identifier 'svstnt1_vnum_bf16'}}
svstnt1_vnum_bf16(pg, const_bf16_ptr, i64, bf16);
// expected-error@+1 {{use of undeclared identifier 'svtrn1_bf16'}}
// expected-error@+1 {{'svset2_bf16' needs target feature sve,bf16}}
svset2_bf16(bf16x2, 1, bf16);
// expected-error@+1 {{'svset3_bf16' needs target feature sve,bf16}}
svset3_bf16(bf16x3, 1, bf16);
// expected-error@+1 {{'svset4_bf16' needs target feature sve,bf16}}
svset4_bf16(bf16x4, 1, bf16);
// expected-error@+1 {{'svst1_bf16' needs target feature sve,bf16}}
svst1_bf16(pg, bf16_ptr, bf16);
// expected-error@+1 {{'svst1_vnum_bf16' needs target feature sve,bf16}}
svst1_vnum_bf16(pg, bf16_ptr, i64, bf16);
// expected-error@+1 {{'svstnt1_bf16' needs target feature sve,bf16}}
svstnt1_bf16(pg, bf16_ptr, bf16);
// expected-error@+1 {{'svstnt1_vnum_bf16' needs target feature sve,bf16}}
svstnt1_vnum_bf16(pg, bf16_ptr, i64, bf16);
// expected-error@+1 {{'svtrn1_bf16' needs target feature sve,bf16}}
svtrn1_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svtrn1q_bf16'}}
// expected-error@+1 {{'svtrn1q_bf16' needs target feature sve,bf16}}
svtrn1q_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svtrn2_bf16'}}
// expected-error@+1 {{'svtrn2_bf16' needs target feature sve,bf16}}
svtrn2_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svtrn2q_bf16'}}
// expected-error@+1 {{'svtrn2q_bf16' needs target feature sve,bf16}}
svtrn2q_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svundef_bf16'}}
// expected-error@+1 {{'svundef_bf16' needs target feature sve,bf16}}
svundef_bf16();
// expected-error@+1 {{use of undeclared identifier 'svundef2_bf16'}}
// expected-error@+1 {{'svundef2_bf16' needs target feature sve,bf16}}
svundef2_bf16();
// expected-error@+1 {{use of undeclared identifier 'svundef3_bf16'}}
// expected-error@+1 {{'svundef3_bf16' needs target feature sve,bf16}}
svundef3_bf16();
// expected-error@+1 {{use of undeclared identifier 'svundef4_bf16'}}
// expected-error@+1 {{'svundef4_bf16' needs target feature sve,bf16}}
svundef4_bf16();
// expected-error@+1 {{use of undeclared identifier 'svuzp1_bf16'}}
// expected-error@+1 {{'svuzp1_bf16' needs target feature sve,bf16}}
svuzp1_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svuzp1q_bf16'}}
// expected-error@+1 {{'svuzp1q_bf16' needs target feature sve,bf16}}
svuzp1q_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svuzp2_bf16'}}
// expected-error@+1 {{'svuzp2_bf16' needs target feature sve,bf16}}
svuzp2_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svuzp2q_bf16'}}
// expected-error@+1 {{'svuzp2q_bf16' needs target feature sve,bf16}}
svuzp2q_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svzip1_bf16'}}
// expected-error@+1 {{'svzip1_bf16' needs target feature sve,bf16}}
svzip1_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svzip1q_bf16'}}
// expected-error@+1 {{'svzip1q_bf16' needs target feature sve,bf16}}
svzip1q_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svzip2_bf16'}}
// expected-error@+1 {{'svzip2_bf16' needs target feature sve,bf16}}
svzip2_bf16(bf16, bf16);
// expected-error@+1 {{use of undeclared identifier 'svzip2q_bf16'}}
// expected-error@+1 {{'svzip2q_bf16' needs target feature sve,bf16}}
svzip2q_bf16(bf16, bf16);
}
32 changes: 32 additions & 0 deletions clang/test/Sema/aarch64-sve-intrinsics/acle_sve_target.cpp
@@ -0,0 +1,32 @@
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsyntax-only -verify -emit-llvm -o - -ferror-limit 100 %s
// REQUIRES: aarch64-registered-target

// Test that functions with the correct target attributes can use the correct SVE intrinsics.
// expected-no-diagnostics

#include <arm_sve.h>

void __attribute__((target("sve"))) test_sve(svint64_t x, svint64_t y)
{
svzip2(x, y);
}

void __attribute__((target("sve,bf16"))) test_bfloat(svfloat32_t x, svbfloat16_t y, bfloat16_t z)
{
svbfdot_n_f32(x, y, z);
}

void __attribute__((target("sve2"))) test_sve2(svbool_t pg)
{
svlogb_f16_z(pg, svundef_f16());
}

void __attribute__((target("sve2-sha3"))) test_sve2_sha3()
{
svrax1_s64(svundef_s64(), svundef_s64());
}

void __attribute__((target("sve2"))) test_f16(svbool_t pg)
{
svlogb_f16_z(pg, svundef_f16());
}

0 comments on commit 6cac7c2

Please sign in to comment.