Skip to content

Commit 8b409ea

Browse files
committed
[SVE] Auto-generate builtins and header for svld1.
This is a first patch in a series for the SveEmitter to generate the arm_sve.h header file and builtins. I've tried my best to strip down this patch as best as I could, but there are still a few changes that are not necessarily exercised by the load intrinsics in this patch, mostly around the SVEType class which has some common logic to represent types from a type and prototype string. I thought it didn't make much sense to remove that from this patch and split it up. Reviewers: efriedma, rovka, SjoerdMeijer, rsandifo-arm, rengolin Reviewed By: SjoerdMeijer Tags: #clang Differential Revision: https://reviews.llvm.org/D75470
1 parent c936525 commit 8b409ea

File tree

12 files changed

+925
-74
lines changed

12 files changed

+925
-74
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===- AArch64SVETypeFlags.h - Flags used to generate ACLE builtins- C++ -*-===//
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+
#ifndef LLVM_CLANG_BASIC_AARCH64SVETYPEFLAGS_H
10+
#define LLVM_CLANG_BASIC_AARCH64SVETYPEFLAGS_H
11+
12+
#include <stdint.h>
13+
14+
namespace clang {
15+
16+
/// Flags to identify the types for overloaded SVE builtins.
17+
class SVETypeFlags {
18+
uint64_t Flags;
19+
20+
public:
21+
/// These must be kept in sync with the flags in
22+
/// include/clang/Basic/arm_sve.td.
23+
static const uint64_t MemEltTypeOffset = 4; // Bit offset of MemEltTypeMask
24+
static const uint64_t EltTypeMask = 0x00000000000f;
25+
static const uint64_t MemEltTypeMask = 0x000000000070;
26+
static const uint64_t IsLoad = 0x000000000080;
27+
28+
enum EltType {
29+
Invalid,
30+
Int8,
31+
Int16,
32+
Int32,
33+
Int64,
34+
Float16,
35+
Float32,
36+
Float64,
37+
Bool8,
38+
Bool16,
39+
Bool32,
40+
Bool64
41+
};
42+
43+
enum MemEltTy {
44+
MemEltTyDefault,
45+
MemEltTyInt8,
46+
MemEltTyInt16,
47+
MemEltTyInt32,
48+
MemEltTyInt64
49+
};
50+
51+
SVETypeFlags(uint64_t F) : Flags(F) { }
52+
SVETypeFlags(EltType ET, bool IsUnsigned) : Flags(ET) { }
53+
54+
EltType getEltType() const { return (EltType)(Flags & EltTypeMask); }
55+
MemEltTy getMemEltType() const {
56+
return (MemEltTy)((Flags & MemEltTypeMask) >> MemEltTypeOffset);
57+
}
58+
59+
bool isLoad() const { return Flags & IsLoad; }
60+
61+
uint64_t getBits() const { return Flags; }
62+
bool isFlagSet(uint64_t Flag) const { return Flags & Flag; }
63+
};
64+
65+
} // end namespace clang
66+
67+
#endif

clang/include/clang/Basic/BuiltinsAArch64.def

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,6 @@ BUILTIN(__builtin_arm_tcommit, "v", "n")
9999
BUILTIN(__builtin_arm_tcancel, "vWUIi", "n")
100100
BUILTIN(__builtin_arm_ttest, "WUi", "nc")
101101

102-
// SVE
103-
BUILTIN(__builtin_sve_svld1_s16, "q8sq16bSsC*", "n")
104-
BUILTIN(__builtin_sve_svld1_s32, "q4iq16bSiC*", "n")
105-
BUILTIN(__builtin_sve_svld1_s64, "q2Wiq16bSWiC*", "n")
106-
BUILTIN(__builtin_sve_svld1_s8, "q16Scq16bScC*", "n")
107-
BUILTIN(__builtin_sve_svld1_u16, "q8Usq16bUsC*", "n")
108-
BUILTIN(__builtin_sve_svld1_u32, "q4Uiq16bUiC*", "n")
109-
BUILTIN(__builtin_sve_svld1_u64, "q2UWiq16bUWiC*", "n")
110-
BUILTIN(__builtin_sve_svld1_u8, "q16Ucq16bUcC*", "n")
111-
BUILTIN(__builtin_sve_svld1_f64, "q2dq16bdC*", "n")
112-
BUILTIN(__builtin_sve_svld1_f32, "q4fq16bfC*", "n")
113-
BUILTIN(__builtin_sve_svld1_f16, "q8hq16bhC*", "n")
114-
115102
TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
116103
TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
117104
TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===--- BuiltinsSVE.def - SVE Builtin function database --------*- C++ -*-===//
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 SVE-specific builtin function database. Users of
10+
// this file must define the BUILTIN macro to make use of this information.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
// The format of this database matches clang/Basic/Builtins.def.
15+
16+
#define GET_SVE_BUILTINS
17+
#include "clang/Basic/arm_sve_builtins.inc"
18+
#undef GET_SVE_BUILTINS
19+
20+
#undef BUILTIN

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ clang_tablegen(arm_mve_builtin_sema.inc -gen-arm-mve-builtin-sema
6060
clang_tablegen(arm_mve_builtin_aliases.inc -gen-arm-mve-builtin-aliases
6161
SOURCE arm_mve.td
6262
TARGET ClangARMMveBuiltinAliases)
63-
63+
clang_tablegen(arm_sve_builtins.inc -gen-arm-sve-builtins
64+
SOURCE arm_sve.td
65+
TARGET ClangARMSveBuiltins)
66+
clang_tablegen(arm_sve_codegenmap.inc -gen-arm-sve-codegenmap
67+
SOURCE arm_sve.td
68+
TARGET ClangARMSveCodeGenMap)
6469
clang_tablegen(arm_cde_builtins.inc -gen-arm-cde-builtin-def
6570
SOURCE arm_cde.td
6671
TARGET ClangARMCdeBuiltinsDef)

clang/include/clang/Basic/TargetBuiltins.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,22 @@ namespace clang {
4141
};
4242
}
4343

44+
namespace SVE {
45+
enum {
46+
LastNEONBuiltin = NEON::FirstTSBuiltin - 1,
47+
#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
48+
#include "clang/Basic/BuiltinsSVE.def"
49+
FirstTSBuiltin,
50+
};
51+
}
52+
4453
/// AArch64 builtins
4554
namespace AArch64 {
4655
enum {
4756
LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
4857
LastNEONBuiltin = NEON::FirstTSBuiltin - 1,
58+
FirstSVEBuiltin = NEON::FirstTSBuiltin,
59+
LastSVEBuiltin = SVE::FirstTSBuiltin - 1,
4960
#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
5061
#include "clang/Basic/BuiltinsAArch64.def"
5162
LastTSBuiltin

clang/include/clang/Basic/arm_sve.td

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,110 @@
1212
// https://developer.arm.com/architectures/system-architectures/software-standards/acle
1313
//
1414
//===----------------------------------------------------------------------===//
15+
16+
//===----------------------------------------------------------------------===//
17+
// Instruction definitions
18+
//===----------------------------------------------------------------------===//
19+
// Every intrinsic subclasses "Inst". An intrinsic has a name, a prototype and
20+
// a sequence of typespecs.
21+
//
22+
// The name is the base name of the intrinsic, for example "svld1". This is
23+
// then mangled by the tblgen backend to add type information ("svld1_s16").
24+
//
25+
// A typespec is a sequence of uppercase characters (modifiers) followed by one
26+
// lowercase character. A typespec encodes a particular "base type" of the
27+
// intrinsic.
28+
//
29+
// An example typespec is "Us" - unsigned short - svuint16_t. The available
30+
// typespec codes are given below.
31+
//
32+
// The string given to an Inst class is a sequence of typespecs. The intrinsic
33+
// is instantiated for every typespec in the sequence. For example "sdUsUd".
34+
//
35+
// The prototype is a string that defines the return type of the intrinsic
36+
// and the type of each argument. The return type and every argument gets a
37+
// "modifier" that can change in some way the "base type" of the intrinsic.
38+
//
39+
// The modifier 'd' means "default" and does not modify the base type in any
40+
// way. The available modifiers are given below.
41+
//
42+
// Typespecs
43+
// ---------
44+
// c: char
45+
// s: short
46+
// i: int
47+
// l: long
48+
// f: float
49+
// h: half-float
50+
// d: double
51+
52+
// Typespec modifiers
53+
// ------------------
54+
// P: boolean
55+
// U: unsigned
56+
57+
// Prototype modifiers
58+
// -------------------
59+
// prototype: return (arg, arg, ...)
60+
//
61+
// d: default
62+
// c: const pointer type
63+
// P: predicate type
64+
65+
class MergeType<int val> {
66+
int Value = val;
67+
}
68+
def MergeNone : MergeType<0>;
69+
def MergeAny : MergeType<1>;
70+
def MergeOp1 : MergeType<2>;
71+
def MergeZero : MergeType<3>;
72+
def MergeAnyExp : MergeType<4>; // Use merged builtin with explicit
73+
def MergeZeroExp : MergeType<5>; // generation of its inactive argument.
74+
75+
class MemEltTy<int val> {
76+
int Value = val;
77+
}
78+
def MemEltTyDefault : MemEltTy<0>;
79+
def MemEltTyInt8 : MemEltTy<1>;
80+
def MemEltTyInt16 : MemEltTy<2>;
81+
def MemEltTyInt32 : MemEltTy<3>;
82+
def MemEltTyInt64 : MemEltTy<4>;
83+
84+
class FlagType<int val> {
85+
int Value = val;
86+
}
87+
88+
// These must be kept in sync with the flags in utils/TableGen/SveEmitter.h
89+
// and include/clang/Basic/TargetBuiltins.h
90+
def NoFlags : FlagType<0x00000000>;
91+
// 0x00000001 => EltType
92+
// ...
93+
// 0x0000000f => EltType
94+
// 0x00000010 => MemEltType
95+
// ...
96+
// 0x00000070 => MemEltType
97+
def IsLoad : FlagType<0x00000080>;
98+
99+
// Every intrinsic subclasses Inst.
100+
class Inst<string n, string p, string t, MergeType mt, string i,
101+
list<FlagType> ft, MemEltTy met> {
102+
string Name = n;
103+
string Prototype = p;
104+
string Types = t;
105+
string ArchGuard = "";
106+
int Merge = mt.Value;
107+
string LLVMIntrinsic = i;
108+
list<FlagType> Flags = ft;
109+
int MemEltType = met.Value;
110+
}
111+
112+
// MInst: Instructions which access memory
113+
class MInst<string n, string p, string t, list<FlagType> f,
114+
MemEltTy met=MemEltTyDefault, string i="">
115+
: Inst<n, p, t, MergeNone, i, f, met> {}
116+
117+
////////////////////////////////////////////////////////////////////////////////
118+
// Loads
119+
120+
// Load one vector (scalar base)
121+
def SVLD1 : MInst<"svld1[_{2}]", "dPc", "csilUcUsUiUlhfd", [IsLoad]>;

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
2626
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
2727
#include "clang/Basic/BuiltinsNEON.def"
2828

29+
#define BUILTIN(ID, TYPE, ATTRS) \
30+
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
31+
#include "clang/Basic/BuiltinsSVE.def"
32+
2933
#define BUILTIN(ID, TYPE, ATTRS) \
3034
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
3135
#define LANGBUILTIN(ID, TYPE, ATTRS, LANG) \

0 commit comments

Comments
 (0)