HsiangKai created this revision. HsiangKai added reviewers: craig.topper, frasercrmck, rogfer01, khchen, aaron.ballman. Herald added subscribers: StephenFan, jdoerfert, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb. HsiangKai requested review of this revision. Herald added subscribers: cfe-commits, MaskRay. Herald added a project: clang.
In some cases, we want to provide the alias name for the clang builtins. For example, the arguments must be constant integers for some RISC-V builtins. If we use wrapper functions, we could not constrain the arguments be constant integer. This attribute is used to achieve the purpose. Besides this, use `clang_builtin_alias` is more efficient than using wrapper functions. We use this attribute to deal with test time issue reported in https://bugs.llvm.org/show_bug.cgi?id=49962. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D100930 Files: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/AST/Decl.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c clang/test/Misc/pragma-attribute-supported-attributes-list.test clang/utils/TableGen/RISCVVEmitter.cpp
Index: clang/utils/TableGen/RISCVVEmitter.cpp =================================================================== --- clang/utils/TableGen/RISCVVEmitter.cpp +++ clang/utils/TableGen/RISCVVEmitter.cpp @@ -885,7 +885,7 @@ void RVVIntrinsic::emitMangledFuncDef(raw_ostream &OS) const { bool UseAliasAttr = !isMask() && !isOperandReordered(); if (UseAliasAttr) { - OS << "__attribute__((__clang_riscv_builtin_alias("; + OS << "__attribute__((clang_builtin_alias("; OS << "__builtin_rvv_" << getName() << ")))\n"; } OS << OutputType->getTypeStr() << " " << getMangledName() << "("; Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test =================================================================== --- clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -142,7 +142,7 @@ // CHECK-NEXT: PassObjectSize (SubjectMatchRule_variable_is_parameter) // CHECK-NEXT: PatchableFunctionEntry (SubjectMatchRule_function, SubjectMatchRule_objc_method) // CHECK-NEXT: Pointer (SubjectMatchRule_record_not_is_union) -// CHECK-NEXT: RISCVBuiltinAlias (SubjectMatchRule_function) +// CHECK-NEXT: BuiltinAlias (SubjectMatchRule_function) // CHECK-NEXT: ReleaseHandle (SubjectMatchRule_variable_is_parameter) // CHECK-NEXT: RenderScriptKernel (SubjectMatchRule_function) // CHECK-NEXT: ReqdWorkGroupSize (SubjectMatchRule_function) Index: clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c =================================================================== --- clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c +++ clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c @@ -10,7 +10,7 @@ static inline __attribute__((__always_inline__, __nodebug__)) __rvv_generic -__attribute__((__clang_riscv_builtin_alias(__builtin_rvv_vadd_vv_i8m1))) +__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1))) vint8m1_t vadd_generic (vint8m1_t op0, vint8m1_t op1, size_t op2); // CHECK-LABEL: @test( Index: clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c =================================================================== --- clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c +++ clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c @@ -9,7 +9,7 @@ static inline __attribute__((__always_inline__, __nodebug__)) __rvv_generic -__attribute__((__clang_riscv_builtin_alias(__builtin_rvv_vadd_vv_i8m1))) +__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1))) vint8m1_t vadd_generic (vint8m1_t op0, vint8m1_t op1, size_t op2); // CHECK: passing 'vint8m2_t' (aka '__rvv_int8m2_t') to parameter of incompatible type 'vint8m1_t' Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -5147,7 +5147,7 @@ D->addAttr(::new (S.Context) ArmBuiltinAliasAttr(S.Context, AL, Ident)); } -static bool RISCVVAliasValid(unsigned BuiltinID, StringRef AliasName) { +static bool AliasValid(unsigned BuiltinID, StringRef AliasName) { switch (BuiltinID) { default: return false; @@ -5158,7 +5158,7 @@ } } -static void handleRISCVBuiltinAliasAttr(Sema &S, Decl *D, +static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (!AL.isArgIdent(0)) { S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) @@ -5170,12 +5170,12 @@ unsigned BuiltinID = Ident->getBuiltinID(); StringRef AliasName = cast<FunctionDecl>(D)->getIdentifier()->getName(); - if (!RISCVVAliasValid(BuiltinID, AliasName)) { - S.Diag(AL.getLoc(), diag::err_attribute_riscv_builtin_alias); + if (!AliasValid(BuiltinID, AliasName)) { + S.Diag(AL.getLoc(), diag::err_attribute_builtin_alias); return; } - D->addAttr(::new (S.Context) RISCVBuiltinAliasAttr(S.Context, AL, Ident)); + D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } //===----------------------------------------------------------------------===// @@ -8276,8 +8276,8 @@ handleEnforceTCBAttr<EnforceTCBLeafAttr, EnforceTCBAttr>(S, D, AL); break; - case ParsedAttr::AT_RISCVBuiltinAlias: - handleRISCVBuiltinAliasAttr(S, D, AL); + case ParsedAttr::AT_BuiltinAlias: + handleBuiltinAliasAttr(S, D, AL); break; } } Index: clang/lib/AST/Decl.cpp =================================================================== --- clang/lib/AST/Decl.cpp +++ clang/lib/AST/Decl.cpp @@ -3265,8 +3265,8 @@ if (const auto *ABAA = getAttr<ArmBuiltinAliasAttr>()) { BuiltinID = ABAA->getBuiltinName()->getBuiltinID(); - } else if (const auto *RBAA = getAttr<RISCVBuiltinAliasAttr>()) { - BuiltinID = RBAA->getBuiltinName()->getBuiltinID(); + } else if (const auto *BAA = getAttr<BuiltinAliasAttr>()) { + BuiltinID = BAA->getBuiltinName()->getBuiltinID(); } else if (const auto *A = getAttr<BuiltinAttr>()) { BuiltinID = A->getID(); } @@ -3277,7 +3277,7 @@ // If the function is marked "overloadable", it has a different mangled name // and is not the C library function. if (!ConsiderWrapperFunctions && hasAttr<OverloadableAttr>() && - (!hasAttr<ArmBuiltinAliasAttr>() && !hasAttr<RISCVBuiltinAliasAttr>())) + (!hasAttr<ArmBuiltinAliasAttr>() && !hasAttr<BuiltinAliasAttr>())) return 0; ASTContext &Context = getASTContext(); Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4017,6 +4017,9 @@ def err_attribute_preferred_name_arg_invalid : Error< "argument %0 to 'preferred_name' attribute is not a typedef for " "a specialization of %1">; +def err_attribute_builtin_alias : Error< + "'clang_builtin_alias' attribute can only be applied to a target " + "builtin">; // called-once attribute diagnostics. def err_called_once_attribute_wrong_type : Error< @@ -11249,7 +11252,4 @@ // RISC-V builtin required extension warning def err_riscv_builtin_requires_extension : Error< "builtin requires '%0' extension support to be enabled">; -def err_attribute_riscv_builtin_alias : Error< - "'__clang_riscv_builtin_alias' attribute can only be applied to a RISC-V " - "builtin">; } // end of sema component. Index: clang/include/clang/Basic/AttrDocs.td =================================================================== --- clang/include/clang/Basic/AttrDocs.td +++ clang/include/clang/Basic/AttrDocs.td @@ -2132,25 +2132,6 @@ }]; } -def RISCVBuiltinAliasDocs : Documentation { - let Category = DocCatFunction; - let Content = [{ -This attribute is used in the implementation of the RVV C intrinsics. -It allows the C intrinsic functions to be declared using the names defined -in RVV builtins, and still be recognized as clang builtins equivalent to the -underlying name. For example, ``riscv_vector.h`` declares the function ``vadd`` -with ``__attribute__((__clang_riscv_builtin_alias(__builtin_rvv_vadd_vv_i8m1)))``. -This ensures that both functions are recognized as that clang builtin, -and in the latter case, the choice of which builtin to identify the -function as can be deferred until after overload resolution. - -This attribute can only be used to set up the aliases for certain RISC-V -C intrinsic functions; it is intended for use only inside ``riscv_*.h`` -and is not a general mechanism for declaring arbitrary aliases for -clang builtin functions. - }]; -} - def AVRInterruptDocs : Documentation { let Category = DocCatFunction; let Heading = "interrupt (AVR)"; @@ -4706,6 +4687,20 @@ }]; } +def BuiltinAliasDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +This attribute is used in the implementation of the C intrinsics. +It allows the C intrinsic functions to be declared using the names defined +in target builtins, and still be recognized as clang builtins equivalent to the +underlying name. For example, ``riscv_vector.h`` declares the function ``vadd`` +with ``__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1)))``. +This ensures that both functions are recognized as that clang builtin, +and in the latter case, the choice of which builtin to identify the +function as can be deferred until after overload resolution. + }]; +} + def PreferredNameDocs : Documentation { let Category = DocCatDecl; let Content = [{ Index: clang/include/clang/Basic/Attr.td =================================================================== --- clang/include/clang/Basic/Attr.td +++ clang/include/clang/Basic/Attr.td @@ -642,6 +642,13 @@ let Documentation = [Undocumented]; } +def BuiltinAlias : Attr { + let Spellings = [Clang<"clang_builtin_alias">]; + let Args = [IdentifierArgument<"BuiltinName">]; + let Subjects = SubjectList<[Function], ErrorDiag>; + let Documentation = [BuiltinAliasDocs]; +} + def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr<TargetAnyArm> { let Spellings = [Clang<"__clang_arm_builtin_alias">]; let Args = [IdentifierArgument<"BuiltinName">]; @@ -1767,13 +1774,6 @@ let Documentation = [RISCVInterruptDocs]; } -def RISCVBuiltinAlias : InheritableAttr, TargetSpecificAttr<TargetRISCV> { - let Spellings = [Clang<"__clang_riscv_builtin_alias">]; - let Subjects = SubjectList<[Function], ErrorDiag>; - let Args = [IdentifierArgument<"BuiltinName">]; - let Documentation = [RISCVBuiltinAliasDocs]; -} - // This is not a TargetSpecificAttr so that is silently accepted and // ignored on other targets as encouraged by the OpenCL spec. //
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits