Skip to content

Commit 6a6fcbf

Browse files
committed
[Clang][AArch64] NFC: Add IsArmStreamingFunction.
Simple refactoring to make a single interface that checks if a FunctionDecl is a __arm[_locally]_streaming function.
1 parent f724540 commit 6a6fcbf

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5049,6 +5049,11 @@ static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
50495049
return "$ompvariant";
50505050
}
50515051

5052+
/// Returns whether the given FunctionDecl has an __arm[_locally]_streaming
5053+
/// attribute.
5054+
bool IsArmStreamingFunction(const FunctionDecl *FD,
5055+
bool IncludeLocallyStreaming);
5056+
50525057
} // namespace clang
50535058

50545059
#endif // LLVM_CLANG_AST_DECL_H

clang/lib/AST/Decl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5758,3 +5758,18 @@ ExportDecl *ExportDecl::Create(ASTContext &C, DeclContext *DC,
57585758
ExportDecl *ExportDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
57595759
return new (C, ID) ExportDecl(nullptr, SourceLocation());
57605760
}
5761+
5762+
bool clang::IsArmStreamingFunction(const FunctionDecl *FD,
5763+
bool IncludeLocallyStreaming) {
5764+
if (IncludeLocallyStreaming)
5765+
if (FD->hasAttr<ArmLocallyStreamingAttr>())
5766+
return true;
5767+
5768+
if (const Type *Ty = FD->getType().getTypePtrOrNull())
5769+
if (const auto *FPT = Ty->getAs<FunctionProtoType>())
5770+
if (FPT->getAArch64SMEAttributes() &
5771+
FunctionType::SME_PStateSMEnabledMask)
5772+
return true;
5773+
5774+
return false;
5775+
}

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "ABIInfoImpl.h"
1010
#include "TargetInfo.h"
11+
#include "clang/AST/Decl.h"
1112
#include "clang/Basic/DiagnosticFrontend.h"
1213
#include "llvm/TargetParser/AArch64TargetParser.h"
1314

@@ -852,14 +853,6 @@ Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
852853
/*allowHigherAlign*/ false);
853854
}
854855

855-
static bool isStreaming(const FunctionDecl *F) {
856-
if (F->hasAttr<ArmLocallyStreamingAttr>())
857-
return true;
858-
if (const auto *T = F->getType()->getAs<FunctionProtoType>())
859-
return T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask;
860-
return false;
861-
}
862-
863856
static bool isStreamingCompatible(const FunctionDecl *F) {
864857
if (const auto *T = F->getType()->getAs<FunctionProtoType>())
865858
return T->getAArch64SMEAttributes() &
@@ -906,8 +899,10 @@ void AArch64TargetCodeGenInfo::checkFunctionCallABIStreaming(
906899
if (!Caller || !Callee || !Callee->hasAttr<AlwaysInlineAttr>())
907900
return;
908901

909-
bool CallerIsStreaming = isStreaming(Caller);
910-
bool CalleeIsStreaming = isStreaming(Callee);
902+
bool CallerIsStreaming =
903+
IsArmStreamingFunction(Caller, /*IncludeLocallyStreaming=*/true);
904+
bool CalleeIsStreaming =
905+
IsArmStreamingFunction(Callee, /*IncludeLocallyStreaming=*/true);
911906
bool CallerIsStreamingCompatible = isStreamingCompatible(Caller);
912907
bool CalleeIsStreamingCompatible = isStreamingCompatible(Callee);
913908

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,13 +3538,6 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
35383538
return false;
35393539
}
35403540

3541-
static bool hasArmStreamingInterface(const FunctionDecl *FD) {
3542-
if (const auto *T = FD->getType()->getAs<FunctionProtoType>())
3543-
if (T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask)
3544-
return true;
3545-
return false;
3546-
}
3547-
35483541
// Check Target Version attrs
35493542
bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
35503543
StringRef &AttrStr, bool &isDefault) {
@@ -3563,7 +3556,8 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
35633556
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
35643557
<< Unsupported << None << CurFeature << TargetVersion;
35653558
}
3566-
if (hasArmStreamingInterface(cast<FunctionDecl>(D)))
3559+
if (IsArmStreamingFunction(cast<FunctionDecl>(D),
3560+
/*IncludeLocallyStreaming=*/false))
35673561
return Diag(LiteralLoc, diag::err_sme_streaming_cannot_be_multiversioned);
35683562
return false;
35693563
}
@@ -3665,7 +3659,8 @@ bool Sema::checkTargetClonesAttrString(
36653659
HasNotDefault = true;
36663660
}
36673661
}
3668-
if (hasArmStreamingInterface(cast<FunctionDecl>(D)))
3662+
if (IsArmStreamingFunction(cast<FunctionDecl>(D),
3663+
/*IncludeLocallyStreaming=*/false))
36693664
return Diag(LiteralLoc,
36703665
diag::err_sme_streaming_cannot_be_multiversioned);
36713666
} else {

0 commit comments

Comments
 (0)