Skip to content

Commit e0f245e

Browse files
[Clang][AArch64] Add fix vector types to header into SVE
This patch is needed for the reduction instructions in sve2.1 It add ta new header to sve with all the fixed vector types. The new types are only added if neon is not declared.
1 parent 0ca830e commit e0f245e

File tree

7 files changed

+188
-3
lines changed

7 files changed

+188
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===--- arm_vector_type.td - ARM Fixed vector types compiler interface ---===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the TableGen definitions from which the ARM BF16 header
10+
// file will be generated.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
include "arm_neon_incl.td"

clang/lib/Headers/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST LLVM_TARGETS_TO_BUILD)
385385
clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
386386
# Generate arm_cde.h
387387
clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
388+
# Generate arm_vector_type.h
389+
clang_generate_header(-gen-arm-vector-type arm_vector_type.td arm_vector_type.h)
388390

389391
# Add headers to target specific lists
390392
list(APPEND arm_common_generated_files
@@ -401,6 +403,7 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST LLVM_TARGETS_TO_BUILD)
401403
"${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
402404
"${CMAKE_CURRENT_BINARY_DIR}/arm_sme_draft_spec_subject_to_change.h"
403405
"${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
406+
"${CMAKE_CURRENT_BINARY_DIR}/arm_vector_type.h"
404407
)
405408
endif()
406409
if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
2+
// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
3+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
4+
#include <arm_sve.h>
5+
6+
// function return types
7+
// CHECK-LABEL: define dso_local <8 x half> @test_ret_v8f16(
8+
// CHECK-SAME: <8 x half> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
9+
// CHECK-NEXT: entry:
10+
// CHECK-NEXT: ret <8 x half> [[V]]
11+
//
12+
float16x8_t test_ret_v8f16(float16x8_t v) {
13+
return v;
14+
}
15+
16+
// CHECK-LABEL: define dso_local <4 x float> @test_ret_v4f32(
17+
// CHECK-SAME: <4 x float> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
18+
// CHECK-NEXT: entry:
19+
// CHECK-NEXT: ret <4 x float> [[V]]
20+
//
21+
float32x4_t test_ret_v4f32(float32x4_t v) {
22+
return v;
23+
}
24+
25+
// CHECK-LABEL: define dso_local <2 x double> @test_ret_v2f64(
26+
// CHECK-SAME: <2 x double> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
27+
// CHECK-NEXT: entry:
28+
// CHECK-NEXT: ret <2 x double> [[V]]
29+
//
30+
float64x2_t test_ret_v2f64(float64x2_t v) {
31+
return v;
32+
}
33+
34+
// CHECK-LABEL: define dso_local <8 x bfloat> @test_ret_v8bf16(
35+
// CHECK-SAME: <8 x bfloat> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
36+
// CHECK-NEXT: entry:
37+
// CHECK-NEXT: ret <8 x bfloat> [[V]]
38+
//
39+
bfloat16x8_t test_ret_v8bf16(bfloat16x8_t v) {
40+
return v;
41+
}
42+
43+
// CHECK-LABEL: define dso_local <16 x i8> @test_ret_v16s8(
44+
// CHECK-SAME: <16 x i8> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
45+
// CHECK-NEXT: entry:
46+
// CHECK-NEXT: ret <16 x i8> [[V]]
47+
//
48+
int8x16_t test_ret_v16s8(int8x16_t v) {
49+
return v;
50+
}
51+
52+
// CHECK-LABEL: define dso_local <8 x i16> @test_ret_v8s16(
53+
// CHECK-SAME: <8 x i16> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
54+
// CHECK-NEXT: entry:
55+
// CHECK-NEXT: ret <8 x i16> [[V]]
56+
//
57+
int16x8_t test_ret_v8s16(int16x8_t v) {
58+
return v;
59+
}
60+
61+
// CHECK-LABEL: define dso_local <4 x i32> @test_ret_v32s4(
62+
// CHECK-SAME: <4 x i32> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
63+
// CHECK-NEXT: entry:
64+
// CHECK-NEXT: ret <4 x i32> [[V]]
65+
//
66+
int32x4_t test_ret_v32s4(int32x4_t v) {
67+
return v;
68+
}
69+
70+
// CHECK-LABEL: define dso_local <2 x i64> @test_ret_v64s2(
71+
// CHECK-SAME: <2 x i64> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
72+
// CHECK-NEXT: entry:
73+
// CHECK-NEXT: ret <2 x i64> [[V]]
74+
//
75+
int64x2_t test_ret_v64s2(int64x2_t v) {
76+
return v;
77+
}
78+
79+
// CHECK-LABEL: define dso_local <16 x i8> @test_ret_v16u8(
80+
// CHECK-SAME: <16 x i8> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
81+
// CHECK-NEXT: entry:
82+
// CHECK-NEXT: ret <16 x i8> [[V]]
83+
//
84+
uint8x16_t test_ret_v16u8(uint8x16_t v) {
85+
return v;
86+
}
87+
88+
// CHECK-LABEL: define dso_local <8 x i16> @test_ret_v8u16(
89+
// CHECK-SAME: <8 x i16> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
90+
// CHECK-NEXT: entry:
91+
// CHECK-NEXT: ret <8 x i16> [[V]]
92+
//
93+
uint16x8_t test_ret_v8u16(uint16x8_t v) {
94+
return v;
95+
}
96+
97+
// CHECK-LABEL: define dso_local <4 x i32> @test_ret_v32u4(
98+
// CHECK-SAME: <4 x i32> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
99+
// CHECK-NEXT: entry:
100+
// CHECK-NEXT: ret <4 x i32> [[V]]
101+
//
102+
uint32x4_t test_ret_v32u4(uint32x4_t v) {
103+
return v;
104+
}
105+
106+
// CHECK-LABEL: define dso_local <2 x i64> @test_ret_v64u2(
107+
// CHECK-SAME: <2 x i64> noundef returned [[V:%.*]]) local_unnamed_addr #[[ATTR0]] {
108+
// CHECK-NEXT: entry:
109+
// CHECK-NEXT: ret <2 x i64> [[V]]
110+
//
111+
uint64x2_t test_ret_v64u2(uint64x2_t v) {
112+
return v;
113+
}

clang/utils/TableGen/NeonEmitter.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,8 @@ class NeonEmitter {
593593
// Emit arm_bf16.h.inc
594594
void runBF16(raw_ostream &o);
595595

596+
void runVectorType(raw_ostream &o);
597+
596598
// Emit all the __builtin prototypes used in arm_neon.h, arm_fp16.h and
597599
// arm_bf16.h
598600
void runHeader(raw_ostream &o);
@@ -2546,6 +2548,44 @@ void NeonEmitter::runFP16(raw_ostream &OS) {
25462548
OS << "#endif /* __ARM_FP16_H */\n";
25472549
}
25482550

2551+
void NeonEmitter::runVectorType(raw_ostream &OS) {
2552+
OS << "/*===---- arm_vector_type - ARM vector type "
2553+
"------===\n"
2554+
" *\n"
2555+
" *\n"
2556+
" * Part of the LLVM Project, under the Apache License v2.0 with LLVM "
2557+
"Exceptions.\n"
2558+
" * See https://llvm.org/LICENSE.txt for license information.\n"
2559+
" * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n"
2560+
" *\n"
2561+
" *===-----------------------------------------------------------------"
2562+
"------===\n"
2563+
" */\n\n";
2564+
OS << "#ifndef __ARM_NEON_TYPES_H\n";
2565+
OS << "#define __ARM_NEON_TYPES_H\n";
2566+
OS << "#ifdef __cplusplus\n";
2567+
OS << "extern \"C\" {\n";
2568+
OS << "#endif\n";
2569+
OS << "#ifndef __ARM_NEON_H\n";
2570+
2571+
std::string TypedefTypes("QcQsQiQlQUcQUsQUiQUlQhQfQdQb");
2572+
std::vector<TypeSpec> TDTypeVec = TypeSpec::fromTypeSpecs(TypedefTypes);
2573+
for (auto &TS : TDTypeVec) {
2574+
Type T(TS, ".");
2575+
OS << "typedef __attribute__((vector_size(16))) ";
2576+
2577+
Type T2 = T;
2578+
T2.makeScalar();
2579+
OS << T2.str();
2580+
OS << " " << T.str() << ";\n";
2581+
}
2582+
OS << "#endif\n";
2583+
OS << "#ifdef __cplusplus\n";
2584+
OS << "} // extern \"C\"\n";
2585+
OS << "#endif\n";
2586+
OS << "#endif //__ARM_NEON_TYPES_H\n";
2587+
}
2588+
25492589
void NeonEmitter::runBF16(raw_ostream &OS) {
25502590
OS << "/*===---- arm_bf16.h - ARM BF16 intrinsics "
25512591
"-----------------------------------===\n"
@@ -2640,6 +2680,10 @@ void clang::EmitNeonSema(RecordKeeper &Records, raw_ostream &OS) {
26402680
NeonEmitter(Records).runHeader(OS);
26412681
}
26422682

2683+
void clang::EmitVectorType(RecordKeeper &Records, raw_ostream &OS) {
2684+
NeonEmitter(Records).runVectorType(OS);
2685+
}
2686+
26432687
void clang::EmitNeonTest(RecordKeeper &Records, raw_ostream &OS) {
26442688
llvm_unreachable("Neon test generation no longer implemented!");
26452689
}

clang/utils/TableGen/SveEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,7 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
12801280
OS << "typedef __SVBfloat16_t svbfloat16_t;\n";
12811281

12821282
OS << "#include <arm_bf16.h>\n";
1283+
OS << "#include <arm_vector_type.h>\n";
12831284

12841285
OS << "typedef __SVFloat32_t svfloat32_t;\n";
12851286
OS << "typedef __SVFloat64_t svfloat64_t;\n";
@@ -1724,4 +1725,5 @@ void EmitSmeBuiltinCG(RecordKeeper &Records, raw_ostream &OS) {
17241725
void EmitSmeRangeChecks(RecordKeeper &Records, raw_ostream &OS) {
17251726
SVEEmitter(Records).createSMERangeChecks(OS);
17261727
}
1728+
17271729
} // End namespace clang

clang/utils/TableGen/TableGen.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum ActionType {
7373
GenArmNeon,
7474
GenArmFP16,
7575
GenArmBF16,
76+
GenArmVectorType,
7677
GenArmNeonSema,
7778
GenArmNeonTest,
7879
GenArmMveHeader,
@@ -229,6 +230,8 @@ cl::opt<ActionType> Action(
229230
clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"),
230231
clEnumValN(GenArmFP16, "gen-arm-fp16", "Generate arm_fp16.h for clang"),
231232
clEnumValN(GenArmBF16, "gen-arm-bf16", "Generate arm_bf16.h for clang"),
233+
clEnumValN(GenArmVectorType, "gen-arm-vector-type",
234+
"Generate arm_vector_type.h for clang"),
232235
clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
233236
"Generate ARM NEON sema support for clang"),
234237
clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
@@ -279,11 +282,14 @@ cl::opt<ActionType> Action(
279282
"Generate riscv_vector_builtin_cg.inc for clang"),
280283
clEnumValN(GenRISCVVectorBuiltinSema, "gen-riscv-vector-builtin-sema",
281284
"Generate riscv_vector_builtin_sema.inc for clang"),
282-
clEnumValN(GenRISCVSiFiveVectorBuiltins, "gen-riscv-sifive-vector-builtins",
285+
clEnumValN(GenRISCVSiFiveVectorBuiltins,
286+
"gen-riscv-sifive-vector-builtins",
283287
"Generate riscv_sifive_vector_builtins.inc for clang"),
284-
clEnumValN(GenRISCVSiFiveVectorBuiltinCG, "gen-riscv-sifive-vector-builtin-codegen",
288+
clEnumValN(GenRISCVSiFiveVectorBuiltinCG,
289+
"gen-riscv-sifive-vector-builtin-codegen",
285290
"Generate riscv_sifive_vector_builtin_cg.inc for clang"),
286-
clEnumValN(GenRISCVSiFiveVectorBuiltinSema, "gen-riscv-sifive-vector-builtin-sema",
291+
clEnumValN(GenRISCVSiFiveVectorBuiltinSema,
292+
"gen-riscv-sifive-vector-builtin-sema",
287293
"Generate riscv_sifive_vector_builtin_sema.inc for clang"),
288294
clEnumValN(GenAttrDocs, "gen-attr-docs",
289295
"Generate attribute documentation"),
@@ -449,6 +455,9 @@ bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
449455
case GenArmFP16:
450456
EmitFP16(Records, OS);
451457
break;
458+
case GenArmVectorType:
459+
EmitVectorType(Records, OS);
460+
break;
452461
case GenArmBF16:
453462
EmitBF16(Records, OS);
454463
break;

clang/utils/TableGen/TableGenBackends.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void EmitNeon(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
9797
void EmitFP16(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
9898
void EmitBF16(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
9999
void EmitNeonSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
100+
void EmitVectorType(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
100101
void EmitNeonTest(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
101102

102103
void EmitSveHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);

0 commit comments

Comments
 (0)