Skip to content

Commit fb4a10d

Browse files
committed
Address review comments.
Fix variable names, allow fixed-width types in streaming functions if the streaming and non-streaming widths are the same.
1 parent 283ad46 commit fb4a10d

File tree

7 files changed

+51
-45
lines changed

7 files changed

+51
-45
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,7 @@ class TargetInfo : public TransferrableTargetInfo,
10421042

10431043
/// Returns target-specific min and max values VScale_Range.
10441044
virtual std::optional<std::pair<unsigned, unsigned>>
1045-
getVScaleRange(const LangOptions &LangOpts,
1046-
ArmStreamingKind IsArmStreamingFunction,
1045+
getVScaleRange(const LangOptions &LangOpts, ArmStreamingKind Mode,
10471046
llvm::StringMap<bool> *FeatureMap = nullptr) const {
10481047
return std::nullopt;
10491048
}

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,21 +823,21 @@ AArch64TargetInfo::getTargetBuiltins() const {
823823

824824
std::optional<std::pair<unsigned, unsigned>>
825825
AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts,
826-
ArmStreamingKind IsArmStreamingFunction,
826+
ArmStreamingKind Mode,
827827
llvm::StringMap<bool> *FeatureMap) const {
828-
if (IsArmStreamingFunction == ArmStreamingKind::NotStreaming &&
828+
if (Mode == ArmStreamingKind::NotStreaming &&
829829
(LangOpts.VScaleMin || LangOpts.VScaleMax))
830830
return std::pair<unsigned, unsigned>(
831831
LangOpts.VScaleMin ? LangOpts.VScaleMin : 1,
832832
LangOpts.VScaleMax ? LangOpts.VScaleMax : 16);
833833

834-
if (IsArmStreamingFunction == ArmStreamingKind::Streaming &&
834+
if (Mode == ArmStreamingKind::Streaming &&
835835
(LangOpts.VScaleStreamingMin || LangOpts.VScaleStreamingMax))
836836
return std::pair<unsigned, unsigned>(
837837
LangOpts.VScaleStreamingMin ? LangOpts.VScaleStreamingMin : 1,
838838
LangOpts.VScaleStreamingMax ? LangOpts.VScaleStreamingMax : 16);
839839

840-
if (IsArmStreamingFunction == ArmStreamingKind::StreamingCompatible &&
840+
if (Mode == ArmStreamingKind::StreamingCompatible &&
841841
((LangOpts.VScaleMin && LangOpts.VScaleStreamingMin) ||
842842
(LangOpts.VScaleMax && LangOpts.VScaleStreamingMax))) {
843843
unsigned Min =
@@ -852,7 +852,7 @@ AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts,
852852
if (hasFeature("sve") || (FeatureMap && (FeatureMap->lookup("sve"))))
853853
return std::pair<unsigned, unsigned>(1, 16);
854854

855-
if (IsArmStreamingFunction == ArmStreamingKind::Streaming &&
855+
if (Mode == ArmStreamingKind::Streaming &&
856856
(hasFeature("sme") || (FeatureMap && (FeatureMap->lookup("sme")))))
857857
return std::pair<unsigned, unsigned>(1, 16);
858858

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
198198
llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
199199

200200
std::optional<std::pair<unsigned, unsigned>>
201-
getVScaleRange(const LangOptions &LangOpts,
202-
ArmStreamingKind IsArmStreamingFunction,
201+
getVScaleRange(const LangOptions &LangOpts, ArmStreamingKind Mode,
203202
llvm::StringMap<bool> *FeatureMap = nullptr) const override;
204203
bool doesFeatureAffectCodeGen(StringRef Name) const override;
205204
bool validateCpuSupports(StringRef FeatureStr) const override;

clang/lib/Basic/Targets/RISCV.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ class RISCVTargetInfo : public TargetInfo {
9999
const std::vector<std::string> &FeaturesVec) const override;
100100

101101
std::optional<std::pair<unsigned, unsigned>>
102-
getVScaleRange(const LangOptions &LangOpts,
103-
ArmStreamingKind IsArmStreamingFunction,
102+
getVScaleRange(const LangOptions &LangOpts, ArmStreamingKind Mode,
104103
llvm::StringMap<bool> *FeatureMap = nullptr) const override;
105104

106105
bool hasFeature(StringRef Feature) const override;

clang/lib/Sema/Sema.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,9 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
22652265
if (auto *VT = Ty->getAs<VectorType>();
22662266
VT && FD &&
22672267
(VT->getVectorKind() == VectorKind::SveFixedLengthData ||
2268-
VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)) {
2268+
VT->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
2269+
(LangOpts.VScaleMin != LangOpts.VScaleStreamingMin ||
2270+
LangOpts.VScaleMax != LangOpts.VScaleStreamingMax)) {
22692271
if (IsArmStreamingFunction(FD, /*IncludeLocallyStreaming=*/true)) {
22702272
Diag(Loc, diag::err_sve_fixed_vector_in_streaming_function) << Ty << 0;
22712273
} else if (const auto *FTy = FD->getType()->getAs<FunctionProtoType>()) {

clang/lib/Sema/SemaARM.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,16 +1423,20 @@ static uint64_t getSVETypeSize(ASTContext &Context, const BuiltinType *Ty,
14231423

14241424
bool SemaARM::areCompatibleSveTypes(QualType FirstType, QualType SecondType) {
14251425
bool IsStreaming = false;
1426-
if (const FunctionDecl *FD =
1427-
SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
1428-
// For streaming-compatible functions, we don't know vector length.
1429-
if (const auto *T = FD->getType()->getAs<FunctionProtoType>())
1430-
if (T->getAArch64SMEAttributes() &
1431-
FunctionType::SME_PStateSMCompatibleMask)
1432-
return false;
1426+
if (LangOpts.VScaleMin != LangOpts.VScaleStreamingMin ||
1427+
LangOpts.VScaleMax != LangOpts.VScaleStreamingMax) {
1428+
if (const FunctionDecl *FD =
1429+
SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
1430+
// For streaming-compatible functions, we don't know vector length.
1431+
if (const auto *T = FD->getType()->getAs<FunctionProtoType>()) {
1432+
if (T->getAArch64SMEAttributes() &
1433+
FunctionType::SME_PStateSMCompatibleMask)
1434+
return false;
1435+
}
14331436

1434-
if (IsArmStreamingFunction(FD, /*IncludeLocallyStreaming=*/true))
1435-
IsStreaming = true;
1437+
if (IsArmStreamingFunction(FD, /*IncludeLocallyStreaming=*/true))
1438+
IsStreaming = true;
1439+
}
14361440
}
14371441

14381442
auto IsValidCast = [&](QualType FirstType, QualType SecondType) {
@@ -1464,16 +1468,19 @@ bool SemaARM::areCompatibleSveTypes(QualType FirstType, QualType SecondType) {
14641468
bool SemaARM::areLaxCompatibleSveTypes(QualType FirstType,
14651469
QualType SecondType) {
14661470
bool IsStreaming = false;
1467-
if (const FunctionDecl *FD =
1468-
SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
1469-
// For streaming-compatible functions, we don't know vector length.
1470-
if (const auto *T = FD->getType()->getAs<FunctionProtoType>())
1471-
if (T->getAArch64SMEAttributes() &
1472-
FunctionType::SME_PStateSMCompatibleMask)
1473-
return false;
1474-
1475-
if (IsArmStreamingFunction(FD, /*IncludeLocallyStreaming=*/true))
1476-
IsStreaming = true;
1471+
if (LangOpts.VScaleMin != LangOpts.VScaleStreamingMin ||
1472+
LangOpts.VScaleMax != LangOpts.VScaleStreamingMax) {
1473+
if (const FunctionDecl *FD =
1474+
SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
1475+
// For streaming-compatible functions, we don't know vector length.
1476+
if (const auto *T = FD->getType()->getAs<FunctionProtoType>())
1477+
if (T->getAArch64SMEAttributes() &
1478+
FunctionType::SME_PStateSMCompatibleMask)
1479+
return false;
1480+
1481+
if (IsArmStreamingFunction(FD, /*IncludeLocallyStreaming=*/true))
1482+
IsStreaming = true;
1483+
}
14771484
}
14781485

14791486
auto IsLaxCompatible = [&](QualType FirstType, QualType SecondType) {

clang/test/Sema/attr-arm-sve-vector-bits.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify -mvscale-min=1 -mvscale-max=1 %s
2-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify -mvscale-min=2 -mvscale-max=2 %s
3-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify -mvscale-min=4 -mvscale-max=4 %s
4-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify -mvscale-min=8 -mvscale-max=8 %s
5-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify -mvscale-min=16 -mvscale-max=16 %s
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected,streamingdifferent -mvscale-min=1 -mvscale-max=1 %s
2+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected,streamingdifferent -mvscale-min=2 -mvscale-max=2 -mvscale-streaming-min=2 %s
3+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected -mvscale-min=4 -mvscale-max=4 -mvscale-streaming-min=4 -mvscale-streaming-max=4 %s
4+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected,streamingdifferent -mvscale-min=8 -mvscale-max=8 -mvscale-streaming-min=4 -mvscale-streaming-max=8 %s
5+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected,streamingdifferent -mvscale-min=16 -mvscale-max=16 %s
66

77
#include <stdint.h>
88

@@ -386,20 +386,20 @@ TEST_OPS(fixed_float64_t)
386386
// --------------------------------------------------------------------------//
387387
// Streaming
388388
__arm_locally_streaming void locally_streaming() {
389-
svint8_t t1 = extern_int8; // expected-error {{cannot be used in a streaming function}}
390-
svbool_t t2 = extern_bool; // expected-error {{cannot be used in a streaming function}}
389+
svint8_t t1 = extern_int8; // streamingdifferent-error {{cannot be used in a streaming function}}
390+
svbool_t t2 = extern_bool; // streamingdifferent-error {{cannot be used in a streaming function}}
391391
void* t3 = extern_int8_ptr;
392392
}
393393
void streaming(void) __arm_streaming {
394-
svint8_t t1 = extern_int8; // expected-error {{cannot be used in a streaming function}}
395-
svbool_t t2 = extern_bool; // expected-error {{cannot be used in a streaming function}}
394+
svint8_t t1 = extern_int8; // streamingdifferent-error {{cannot be used in a streaming function}}
395+
svbool_t t2 = extern_bool; // streamingdifferent-error {{cannot be used in a streaming function}}
396396
void* t3 = extern_int8_ptr;
397397
}
398398
void streaming_compatible(void) __arm_streaming_compatible {
399-
svint8_t t1 = extern_int8; // expected-error {{cannot be used in a streaming-compatible function}} \
400-
// expected-error {{initializing}}
401-
svbool_t t2 = extern_bool; // expected-error {{cannot be used in a streaming-compatible function}} \
402-
// expected-error {{initializing}}
399+
svint8_t t1 = extern_int8; // streamingdifferent-error {{cannot be used in a streaming-compatible function}} \
400+
// streamingdifferent-error {{initializing}}
401+
svbool_t t2 = extern_bool; // streamingdifferent-error {{cannot be used in a streaming-compatible function}} \
402+
// streamingdifferent-error {{initializing}}
403403
void* t3 = extern_int8_ptr;
404404
}
405-
__arm_locally_streaming void locally_streaming_arg(fixed_int8_t x) {} // expected-error {{cannot be used in a streaming function}}
405+
__arm_locally_streaming void locally_streaming_arg(fixed_int8_t x) {} // streamingdifferent-error {{cannot be used in a streaming function}}

0 commit comments

Comments
 (0)