[clang] 6a6fcbf - [Clang][AArch64] NFC: Add IsArmStreamingFunction.
Sander de Smalen via cfe-commits
cfe-commits at lists.llvm.org
Tue May 7 08:34:09 PDT 2024
Author: Sander de Smalen
Date: 2024-05-07T15:33:24Z
New Revision: 6a6fcbffbb31f83fab7425d43e28eb6aa39dbfe9
URL: https://github.com/llvm/llvm-project/commit/6a6fcbffbb31f83fab7425d43e28eb6aa39dbfe9
DIFF: https://github.com/llvm/llvm-project/commit/6a6fcbffbb31f83fab7425d43e28eb6aa39dbfe9.diff
LOG: [Clang][AArch64] NFC: Add IsArmStreamingFunction.
Simple refactoring to make a single interface that checks if a
FunctionDecl is a __arm[_locally]_streaming function.
Added:
Modified:
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/Targets/AArch64.cpp
clang/lib/Sema/SemaDeclAttr.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index a53c27a99a8c36..de8b923645f8d6 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -5049,6 +5049,11 @@ static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
return "$ompvariant";
}
+/// Returns whether the given FunctionDecl has an __arm[_locally]_streaming
+/// attribute.
+bool IsArmStreamingFunction(const FunctionDecl *FD,
+ bool IncludeLocallyStreaming);
+
} // namespace clang
#endif // LLVM_CLANG_AST_DECL_H
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index e7e95c16b69786..ec851c9371e10a 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5758,3 +5758,18 @@ ExportDecl *ExportDecl::Create(ASTContext &C, DeclContext *DC,
ExportDecl *ExportDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
return new (C, ID) ExportDecl(nullptr, SourceLocation());
}
+
+bool clang::IsArmStreamingFunction(const FunctionDecl *FD,
+ bool IncludeLocallyStreaming) {
+ if (IncludeLocallyStreaming)
+ if (FD->hasAttr<ArmLocallyStreamingAttr>())
+ return true;
+
+ if (const Type *Ty = FD->getType().getTypePtrOrNull())
+ if (const auto *FPT = Ty->getAs<FunctionProtoType>())
+ if (FPT->getAArch64SMEAttributes() &
+ FunctionType::SME_PStateSMEnabledMask)
+ return true;
+
+ return false;
+}
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp b/clang/lib/CodeGen/Targets/AArch64.cpp
index 452dc049d51b4f..e32b060ebeb936 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -8,6 +8,7 @@
#include "ABIInfoImpl.h"
#include "TargetInfo.h"
+#include "clang/AST/Decl.h"
#include "clang/Basic/DiagnosticFrontend.h"
#include "llvm/TargetParser/AArch64TargetParser.h"
@@ -852,14 +853,6 @@ Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
/*allowHigherAlign*/ false);
}
-static bool isStreaming(const FunctionDecl *F) {
- if (F->hasAttr<ArmLocallyStreamingAttr>())
- return true;
- if (const auto *T = F->getType()->getAs<FunctionProtoType>())
- return T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask;
- return false;
-}
-
static bool isStreamingCompatible(const FunctionDecl *F) {
if (const auto *T = F->getType()->getAs<FunctionProtoType>())
return T->getAArch64SMEAttributes() &
@@ -906,8 +899,10 @@ void AArch64TargetCodeGenInfo::checkFunctionCallABIStreaming(
if (!Caller || !Callee || !Callee->hasAttr<AlwaysInlineAttr>())
return;
- bool CallerIsStreaming = isStreaming(Caller);
- bool CalleeIsStreaming = isStreaming(Callee);
+ bool CallerIsStreaming =
+ IsArmStreamingFunction(Caller, /*IncludeLocallyStreaming=*/true);
+ bool CalleeIsStreaming =
+ IsArmStreamingFunction(Callee, /*IncludeLocallyStreaming=*/true);
bool CallerIsStreamingCompatible = isStreamingCompatible(Caller);
bool CalleeIsStreamingCompatible = isStreamingCompatible(Callee);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 363ae93cb62df1..6ca42856459f7b 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3538,13 +3538,6 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
return false;
}
-static bool hasArmStreamingInterface(const FunctionDecl *FD) {
- if (const auto *T = FD->getType()->getAs<FunctionProtoType>())
- if (T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask)
- return true;
- return false;
-}
-
// Check Target Version attrs
bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
StringRef &AttrStr, bool &isDefault) {
@@ -3563,7 +3556,8 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
<< Unsupported << None << CurFeature << TargetVersion;
}
- if (hasArmStreamingInterface(cast<FunctionDecl>(D)))
+ if (IsArmStreamingFunction(cast<FunctionDecl>(D),
+ /*IncludeLocallyStreaming=*/false))
return Diag(LiteralLoc, diag::err_sme_streaming_cannot_be_multiversioned);
return false;
}
@@ -3665,7 +3659,8 @@ bool Sema::checkTargetClonesAttrString(
HasNotDefault = true;
}
}
- if (hasArmStreamingInterface(cast<FunctionDecl>(D)))
+ if (IsArmStreamingFunction(cast<FunctionDecl>(D),
+ /*IncludeLocallyStreaming=*/false))
return Diag(LiteralLoc,
diag::err_sme_streaming_cannot_be_multiversioned);
} else {
More information about the cfe-commits
mailing list