Skip to content

Commit 47edf5b

Browse files
committed
[ARM,CDE] Generalize MVE intrinsics infrastructure to support CDE
Summary: This patch generalizes the existing code to support CDE intrinsics which will share some properties with existing MVE intrinsics (some of the intrinsics will be polymorphic and accept/return values of MVE vector types). Specifically the patch: * Adds new tablegen backends -gen-arm-cde-builtin-def, -gen-arm-cde-builtin-codegen, -gen-arm-cde-builtin-sema, -gen-arm-cde-builtin-aliases, -gen-arm-cde-builtin-header based on existing MVE backends. * Renames the '__clang_arm_mve_alias' attribute into '__clang_arm_builtin_alias' (it will be used with CDE intrinsics as well as MVE intrinsics) * Implements semantic checks for the coprocessor argument of the CDE intrinsics as well as the existing coprocessor intrinsics. * Adds one CDE intrinsic __arm_cx1 to test the above changes Reviewers: simon_tatham, MarkMurrayARM, ostannard, dmgreen Reviewed By: simon_tatham Subscribers: sdesmalen, mgorny, kristof.beyls, danielkiss, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D75850
1 parent c2dafe1 commit 47edf5b

23 files changed

+792
-281
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,11 @@ def Alias : Attr {
622622
let Documentation = [Undocumented];
623623
}
624624

625-
def ArmMveAlias : InheritableAttr, TargetSpecificAttr<TargetARM> {
626-
let Spellings = [Clang<"__clang_arm_mve_alias">];
625+
def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr<TargetARM> {
626+
let Spellings = [Clang<"__clang_arm_builtin_alias">];
627627
let Args = [IdentifierArgument<"BuiltinName">];
628628
let Subjects = SubjectList<[Function], ErrorDiag>;
629-
let Documentation = [ArmMveAliasDocs];
629+
let Documentation = [ArmBuiltinAliasDocs];
630630
}
631631

632632
def Aligned : InheritableAttr {

clang/include/clang/Basic/AttrDocs.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4669,11 +4669,11 @@ When the Owner's lifetime ends, it will consider the Pointer to be dangling.
46694669
}];
46704670
}
46714671

4672-
def ArmMveAliasDocs : Documentation {
4672+
def ArmBuiltinAliasDocs : Documentation {
46734673
let Category = DocCatFunction;
46744674
let Content = [{
4675-
This attribute is used in the implementation of the ACLE intrinsics
4676-
for the Arm MVE instruction set. It allows the intrinsic functions to
4675+
This attribute is used in the implementation of the ACLE intrinsics.
4676+
It allows the intrinsic functions to
46774677
be declared using the names defined in ACLE, and still be recognized
46784678
as clang builtins equivalent to the underlying name. For example,
46794679
``arm_mve.h`` declares the function ``vaddq_u32`` with
@@ -4684,8 +4684,8 @@ recognized as that clang builtin, and in the latter case, the choice
46844684
of which builtin to identify the function as can be deferred until
46854685
after overload resolution.
46864686

4687-
This attribute can only be used to set up the aliases for the MVE
4688-
intrinsic functions; it is intended for use only inside ``arm_mve.h``,
4687+
This attribute can only be used to set up the aliases for certain Arm
4688+
intrinsic functions; it is intended for use only inside ``arm_*.h``
46894689
and is not a general mechanism for declaring arbitrary aliases for
46904690
clang builtin functions.
46914691
}];

clang/include/clang/Basic/BuiltinsARM.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
202202
// aren't included from both here and BuiltinsAArch64.def.)
203203
#include "clang/Basic/arm_mve_builtins.inc"
204204

205+
#include "clang/Basic/arm_cde_builtins.inc"
206+
205207
// MSVC
206208
LANGBUILTIN(__emit, "vIUiC", "", ALL_MS_LANGUAGES)
207209

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,16 @@ 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+
64+
clang_tablegen(arm_cde_builtins.inc -gen-arm-cde-builtin-def
65+
SOURCE arm_cde.td
66+
TARGET ClangARMCdeBuiltinsDef)
67+
clang_tablegen(arm_cde_builtin_cg.inc -gen-arm-cde-builtin-codegen
68+
SOURCE arm_cde.td
69+
TARGET ClangARMCdeBuiltinCG)
70+
clang_tablegen(arm_cde_builtin_sema.inc -gen-arm-cde-builtin-sema
71+
SOURCE arm_cde.td
72+
TARGET ClangARMCdeBuiltinSema)
73+
clang_tablegen(arm_cde_builtin_aliases.inc -gen-arm-cde-builtin-aliases
74+
SOURCE arm_cde.td
75+
TARGET ClangARMCdeBuiltinAliases)

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ def warn_redecl_library_builtin : Warning<
639639
def err_builtin_definition : Error<"definition of builtin function %0">;
640640
def err_builtin_redeclare : Error<"cannot redeclare builtin function %0">;
641641
def err_arm_invalid_specialreg : Error<"invalid special register for builtin">;
642+
def err_arm_invalid_coproc : Error<"coprocessor %0 must be configured as "
643+
"%select{GCP|CDE}1">;
642644
def err_invalid_cpu_supports : Error<"invalid cpu feature string for builtin">;
643645
def err_invalid_cpu_is : Error<"invalid cpu name for builtin">;
644646
def err_invalid_cpu_specific_dispatch_value : Error<
@@ -6722,8 +6724,8 @@ def warn_objc_unsafe_perform_selector : Warning<
67226724
InGroup<DiagGroup<"objc-unsafe-perform-selector">>;
67236725
def note_objc_unsafe_perform_selector_method_declared_here : Note<
67246726
"method %0 that returns %1 declared here">;
6725-
def err_attribute_arm_mve_alias : Error<
6726-
"'__clang_arm_mve_alias' attribute can only be applied to an ARM MVE builtin">;
6727+
def err_attribute_arm_builtin_alias : Error<
6728+
"'__clang_arm_builtin_alias' attribute can only be applied to an ARM builtin">;
67276729
def err_attribute_arm_mve_polymorphism : Error<
67286730
"'__clang_arm_mve_strict_polymorphism' attribute can only be applied to an MVE/NEON vector type">;
67296731

clang/include/clang/Basic/arm_cde.td

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===--- arm_cde.td - ACLE intrinsic functions for CDE --------------------===//
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 set of ACLE-specified source-level intrinsic
10+
// functions wrapping the CDE instructions.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
include "arm_mve_defs.td"
15+
16+
class CDEIntrinsic<Type ret, dag args, dag codegen>
17+
: Intrinsic<ret, args, codegen> {
18+
let builtinExtension = "cde";
19+
}
20+
21+
// Immediate (in range [0, 2^numBits - 1])
22+
class IB_ConstBits<int numBits> : IB_ConstRange<0, !add(!shl(1, numBits), -1)>;
23+
// numBits-wide immediate of type u32
24+
class CDEImmediateBits<int numBits> : Immediate<u32, IB_ConstBits<numBits>>;
25+
26+
// LLVM IR CDE intrinsic
27+
class CDEIRInt<string name, list<Type> params = [], bit appendKind = 0>
28+
: IRIntBase<"arm_cde_" # name, params, appendKind>;
29+
30+
// Coprocessor immediate
31+
def imm_coproc : Immediate<sint, IB_ConstRange<0, 7>>;
32+
33+
// Immediate integer parameters
34+
def imm_3b : CDEImmediateBits<3>;
35+
def imm_4b : CDEImmediateBits<4>;
36+
def imm_6b : CDEImmediateBits<6>;
37+
def imm_7b : CDEImmediateBits<7>;
38+
def imm_9b : CDEImmediateBits<9>;
39+
def imm_11b : CDEImmediateBits<11>;
40+
def imm_12b : CDEImmediateBits<12>;
41+
def imm_13b : CDEImmediateBits<13>;
42+
43+
let pnt = PNT_None, params = T.None in
44+
def cx1 : CDEIntrinsic<u32, (args imm_coproc:$cp, imm_13b:$imm),
45+
(CDEIRInt<"cx1"> $cp, $imm)>;

clang/include/clang/Basic/arm_mve_defs.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,16 @@ class Intrinsic<Type ret_, dag args_, dag codegen_> {
476476
// True if the builtin has to avoid evaluating its arguments.
477477
bit nonEvaluating = 0;
478478

479+
// True if the intrinsic needs only the C header part (no codegen, semantic
480+
// checks, etc). Used for redeclaring MVE intrinsics in the arm_cde.h header.
481+
bit headerOnly = 0;
482+
479483
// Use to override the suffix letter to make e.g.vfooq_p16
480484
// with an override suffix letter of "p".
481485
string overrideKindLetter = "";
486+
487+
// Name of the architecture extension, used in the Clang builtin name
488+
string builtinExtension = "mve";
482489
}
483490

484491
// Sometimes you have to use two separate Intrinsic declarations to
@@ -553,6 +560,7 @@ multiclass IntrinsicMXNameOverride<Type rettype, dag arguments, dag cg,
553560
// instead of having to repeat a long list every time.
554561

555562
def T {
563+
list<Type> None = [Void];
556564
list<Type> Signed = [s8, s16, s32];
557565
list<Type> Unsigned = [u8, u16, u32];
558566
list<Type> Int = Signed # Unsigned;

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11764,6 +11764,8 @@ class Sema final {
1176411764
unsigned MaxWidth);
1176511765
bool CheckNeonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
1176611766
bool CheckMVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
11767+
bool CheckCDEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
11768+
bool CheckARMCoprocessorImmediate(const Expr *CoprocArg, bool WantCDE);
1176711769
bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
1176811770

1176911771
bool CheckAArch64BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);

clang/lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,8 +3148,8 @@ FunctionDecl *FunctionDecl::getCanonicalDecl() { return getFirstDecl(); }
31483148
unsigned FunctionDecl::getBuiltinID(bool ConsiderWrapperFunctions) const {
31493149
unsigned BuiltinID;
31503150

3151-
if (const auto *AMAA = getAttr<ArmMveAliasAttr>()) {
3152-
BuiltinID = AMAA->getBuiltinName()->getBuiltinID();
3151+
if (const auto *ABAA = getAttr<ArmBuiltinAliasAttr>()) {
3152+
BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
31533153
} else {
31543154
if (!getIdentifier())
31553155
return 0;
@@ -3181,7 +3181,7 @@ unsigned FunctionDecl::getBuiltinID(bool ConsiderWrapperFunctions) const {
31813181
// If the function is marked "overloadable", it has a different mangled name
31823182
// and is not the C library function.
31833183
if (!ConsiderWrapperFunctions && hasAttr<OverloadableAttr>() &&
3184-
!hasAttr<ArmMveAliasAttr>())
3184+
!hasAttr<ArmBuiltinAliasAttr>())
31853185
return 0;
31863186

31873187
if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6538,6 +6538,9 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
65386538
// Deal with MVE builtins
65396539
if (Value *Result = EmitARMMVEBuiltinExpr(BuiltinID, E, ReturnValue, Arch))
65406540
return Result;
6541+
// Handle CDE builtins
6542+
if (Value *Result = EmitARMCDEBuiltinExpr(BuiltinID, E, ReturnValue, Arch))
6543+
return Result;
65416544

65426545
// Find out if any arguments are required to be integer constant
65436546
// expressions.
@@ -7212,6 +7215,17 @@ Value *CodeGenFunction::EmitARMMVEBuiltinExpr(unsigned BuiltinID,
72127215
llvm_unreachable("unknown custom codegen type.");
72137216
}
72147217

7218+
Value *CodeGenFunction::EmitARMCDEBuiltinExpr(unsigned BuiltinID,
7219+
const CallExpr *E,
7220+
ReturnValueSlot ReturnValue,
7221+
llvm::Triple::ArchType Arch) {
7222+
switch (BuiltinID) {
7223+
default:
7224+
return nullptr;
7225+
#include "clang/Basic/arm_cde_builtin_cg.inc"
7226+
}
7227+
}
7228+
72157229
static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID,
72167230
const CallExpr *E,
72177231
SmallVectorImpl<Value *> &Ops,

0 commit comments

Comments
 (0)