Skip to content

Commit 5e33df3

Browse files
Erich KeaneAaronBallman
Erich Keane
andauthored
[NFC][SYCL] Fix some uses of stringref& and qualtype& (#3504)
Identified elsewhere, these are a few cases of 'simple' types that are intended to be copied being passed around as const references. This patch just replaces them. Also, StringRefs for can be just llvm::StringLiteral for literals, since that does constexpr construction. Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
1 parent 6e9ddb6 commit 5e33df3

File tree

1 file changed

+68
-65
lines changed

1 file changed

+68
-65
lines changed

clang/lib/Sema/SemaSYCL.cpp

+68-65
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,49 @@ namespace {
6868
/// Various utilities.
6969
class Util {
7070
public:
71-
using DeclContextDesc = std::pair<clang::Decl::Kind, StringRef>;
71+
using DeclContextDesc = std::pair<Decl::Kind, StringRef>;
72+
73+
template <size_t N>
74+
static constexpr DeclContextDesc MakeDeclContextDesc(Decl::Kind K,
75+
const char (&Str)[N]) {
76+
return DeclContextDesc{K, llvm::StringLiteral{Str}};
77+
}
78+
79+
static constexpr DeclContextDesc MakeDeclContextDesc(Decl::Kind K,
80+
StringRef SR) {
81+
return DeclContextDesc{K, SR};
82+
}
7283

7384
/// Checks whether given clang type is a full specialization of the SYCL
7485
/// accessor class.
75-
static bool isSyclAccessorType(const QualType &Ty);
86+
static bool isSyclAccessorType(QualType Ty);
7687

7788
/// Checks whether given clang type is a full specialization of the SYCL
7889
/// sampler class.
79-
static bool isSyclSamplerType(const QualType &Ty);
90+
static bool isSyclSamplerType(QualType Ty);
8091

8192
/// Checks whether given clang type is a full specialization of the SYCL
8293
/// stream class.
83-
static bool isSyclStreamType(const QualType &Ty);
94+
static bool isSyclStreamType(QualType Ty);
8495

8596
/// Checks whether given clang type is a full specialization of the SYCL
8697
/// half class.
87-
static bool isSyclHalfType(const QualType &Ty);
98+
static bool isSyclHalfType(QualType Ty);
8899

89100
/// Checks whether given clang type is a full specialization of the SYCL
90101
/// accessor_property_list class.
91-
static bool isAccessorPropertyListType(const QualType &Ty);
102+
static bool isAccessorPropertyListType(QualType Ty);
92103

93104
/// Checks whether given clang type is a full specialization of the SYCL
94105
/// buffer_location class.
95-
static bool isSyclBufferLocationType(const QualType &Ty);
106+
static bool isSyclBufferLocationType(QualType Ty);
96107

97108
/// Checks whether given clang type is a standard SYCL API class with given
98109
/// name.
99110
/// \param Ty the clang type being checked
100111
/// \param Name the class name checked against
101112
/// \param Tmpl whether the class is template instantiation or simple record
102-
static bool isSyclType(const QualType &Ty, StringRef Name, bool Tmpl = false);
113+
static bool isSyclType(QualType Ty, StringRef Name, bool Tmpl = false);
103114

104115
/// Checks whether given function is a standard SYCL API function with given
105116
/// name.
@@ -109,11 +120,11 @@ class Util {
109120

110121
/// Checks whether given clang type is a full specialization of the SYCL
111122
/// specialization constant class.
112-
static bool isSyclSpecConstantType(const QualType &Ty);
123+
static bool isSyclSpecConstantType(QualType Ty);
113124

114125
/// Checks whether given clang type is a full specialization of the SYCL
115126
/// kernel_handler class.
116-
static bool isSyclKernelHandlerType(const QualType &Ty);
127+
static bool isSyclKernelHandlerType(QualType Ty);
117128

118129
// Checks declaration context hierarchy.
119130
/// \param DC the context of the item to be checked.
@@ -127,7 +138,7 @@ class Util {
127138
/// \param Ty the clang type being checked
128139
/// \param Scopes the declaration scopes leading from the type to the
129140
/// translation unit (excluding the latter)
130-
static bool matchQualifiedTypeName(const QualType &Ty,
141+
static bool matchQualifiedTypeName(QualType Ty,
131142
ArrayRef<Util::DeclContextDesc> Scopes);
132143
};
133144

@@ -1321,7 +1332,7 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
13211332
DiagnosticsEngine &Diag;
13221333
// Check whether the object should be disallowed from being copied to kernel.
13231334
// Return true if not copyable, false if copyable.
1324-
bool checkNotCopyableToKernel(const FieldDecl *FD, const QualType &FieldTy) {
1335+
bool checkNotCopyableToKernel(const FieldDecl *FD, QualType FieldTy) {
13251336
if (FieldTy->isArrayType()) {
13261337
if (const auto *CAT =
13271338
SemaRef.getASTContext().getAsConstantArrayType(FieldTy)) {
@@ -4305,70 +4316,62 @@ bool SYCLIntegrationFooter::emit(raw_ostream &O) {
43054316
// Utility class methods
43064317
// -----------------------------------------------------------------------------
43074318

4308-
bool Util::isSyclAccessorType(const QualType &Ty) {
4319+
bool Util::isSyclAccessorType(QualType Ty) {
43094320
return isSyclType(Ty, "accessor", true /*Tmpl*/);
43104321
}
43114322

4312-
bool Util::isSyclSamplerType(const QualType &Ty) {
4313-
return isSyclType(Ty, "sampler");
4314-
}
4323+
bool Util::isSyclSamplerType(QualType Ty) { return isSyclType(Ty, "sampler"); }
43154324

4316-
bool Util::isSyclStreamType(const QualType &Ty) {
4317-
return isSyclType(Ty, "stream");
4318-
}
4325+
bool Util::isSyclStreamType(QualType Ty) { return isSyclType(Ty, "stream"); }
43194326

4320-
bool Util::isSyclHalfType(const QualType &Ty) {
4321-
const StringRef &Name = "half";
4327+
bool Util::isSyclHalfType(QualType Ty) {
43224328
std::array<DeclContextDesc, 5> Scopes = {
4323-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "cl"},
4324-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "sycl"},
4325-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "detail"},
4326-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "half_impl"},
4327-
Util::DeclContextDesc{Decl::Kind::CXXRecord, Name}};
4329+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),
4330+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"),
4331+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "detail"),
4332+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "half_impl"),
4333+
Util::MakeDeclContextDesc(Decl::Kind::CXXRecord, "half")};
43284334
return matchQualifiedTypeName(Ty, Scopes);
43294335
}
43304336

4331-
bool Util::isSyclSpecConstantType(const QualType &Ty) {
4332-
const StringRef &Name = "spec_constant";
4337+
bool Util::isSyclSpecConstantType(QualType Ty) {
43334338
std::array<DeclContextDesc, 5> Scopes = {
4334-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "cl"},
4335-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "sycl"},
4336-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "ONEAPI"},
4337-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "experimental"},
4338-
Util::DeclContextDesc{Decl::Kind::ClassTemplateSpecialization, Name}};
4339+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),
4340+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"),
4341+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "ONEAPI"),
4342+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "experimental"),
4343+
Util::MakeDeclContextDesc(Decl::Kind::ClassTemplateSpecialization,
4344+
"spec_constant")};
43394345
return matchQualifiedTypeName(Ty, Scopes);
43404346
}
43414347

4342-
bool Util::isSyclKernelHandlerType(const QualType &Ty) {
4343-
const StringRef &Name = "kernel_handler";
4348+
bool Util::isSyclKernelHandlerType(QualType Ty) {
43444349
std::array<DeclContextDesc, 3> Scopes = {
4345-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "cl"},
4346-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "sycl"},
4347-
Util::DeclContextDesc{Decl::Kind::CXXRecord, Name}};
4350+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),
4351+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"),
4352+
Util::MakeDeclContextDesc(Decl::Kind::CXXRecord, "kernel_handler")};
43484353
return matchQualifiedTypeName(Ty, Scopes);
43494354
}
43504355

4351-
bool Util::isSyclBufferLocationType(const QualType &Ty) {
4352-
const StringRef &PropertyName = "buffer_location";
4353-
const StringRef &InstanceName = "instance";
4356+
bool Util::isSyclBufferLocationType(QualType Ty) {
43544357
std::array<DeclContextDesc, 6> Scopes = {
4355-
Util::DeclContextDesc{Decl::Kind::Namespace, "cl"},
4356-
Util::DeclContextDesc{Decl::Kind::Namespace, "sycl"},
4357-
Util::DeclContextDesc{Decl::Kind::Namespace, "INTEL"},
4358-
Util::DeclContextDesc{Decl::Kind::Namespace, "property"},
4359-
Util::DeclContextDesc{Decl::Kind::CXXRecord, PropertyName},
4360-
Util::DeclContextDesc{Decl::Kind::ClassTemplateSpecialization,
4361-
InstanceName}};
4358+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),
4359+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"),
4360+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "INTEL"),
4361+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "property"),
4362+
Util::MakeDeclContextDesc(Decl::Kind::CXXRecord, "buffer_location"),
4363+
Util::MakeDeclContextDesc(Decl::Kind::ClassTemplateSpecialization,
4364+
"instance")};
43624365
return matchQualifiedTypeName(Ty, Scopes);
43634366
}
43644367

4365-
bool Util::isSyclType(const QualType &Ty, StringRef Name, bool Tmpl) {
4368+
bool Util::isSyclType(QualType Ty, StringRef Name, bool Tmpl) {
43664369
Decl::Kind ClassDeclKind =
43674370
Tmpl ? Decl::Kind::ClassTemplateSpecialization : Decl::Kind::CXXRecord;
43684371
std::array<DeclContextDesc, 3> Scopes = {
4369-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "cl"},
4370-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "sycl"},
4371-
Util::DeclContextDesc{ClassDeclKind, Name}};
4372+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),
4373+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"),
4374+
Util::MakeDeclContextDesc(ClassDeclKind, Name)};
43724375
return matchQualifiedTypeName(Ty, Scopes);
43734376
}
43744377

@@ -4382,18 +4385,18 @@ bool Util::isSyclFunction(const FunctionDecl *FD, StringRef Name) {
43824385
return false;
43834386

43844387
std::array<DeclContextDesc, 2> Scopes = {
4385-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "cl"},
4386-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "sycl"}};
4388+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),
4389+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl")};
43874390
return matchContext(DC, Scopes);
43884391
}
43894392

4390-
bool Util::isAccessorPropertyListType(const QualType &Ty) {
4391-
const StringRef &Name = "accessor_property_list";
4393+
bool Util::isAccessorPropertyListType(QualType Ty) {
43924394
std::array<DeclContextDesc, 4> Scopes = {
4393-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "cl"},
4394-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "sycl"},
4395-
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "ONEAPI"},
4396-
Util::DeclContextDesc{Decl::Kind::ClassTemplateSpecialization, Name}};
4395+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "cl"),
4396+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"),
4397+
Util::MakeDeclContextDesc(Decl::Kind::Namespace, "ONEAPI"),
4398+
Util::MakeDeclContextDesc(Decl::Kind::ClassTemplateSpecialization,
4399+
"accessor_property_list")};
43974400
return matchQualifiedTypeName(Ty, Scopes);
43984401
}
43994402

@@ -4405,17 +4408,17 @@ bool Util::matchContext(const DeclContext *Ctx,
44054408
StringRef Name = "";
44064409

44074410
for (const auto &Scope : llvm::reverse(Scopes)) {
4408-
clang::Decl::Kind DK = Ctx->getDeclKind();
4411+
Decl::Kind DK = Ctx->getDeclKind();
44094412
if (DK != Scope.first)
44104413
return false;
44114414

44124415
switch (DK) {
4413-
case clang::Decl::Kind::ClassTemplateSpecialization:
4416+
case Decl::Kind::ClassTemplateSpecialization:
44144417
// ClassTemplateSpecializationDecl inherits from CXXRecordDecl
4415-
case clang::Decl::Kind::CXXRecord:
4418+
case Decl::Kind::CXXRecord:
44164419
Name = cast<CXXRecordDecl>(Ctx)->getName();
44174420
break;
4418-
case clang::Decl::Kind::Namespace:
4421+
case Decl::Kind::Namespace:
44194422
Name = cast<NamespaceDecl>(Ctx)->getName();
44204423
break;
44214424
default:
@@ -4428,7 +4431,7 @@ bool Util::matchContext(const DeclContext *Ctx,
44284431
return Ctx->isTranslationUnit();
44294432
}
44304433

4431-
bool Util::matchQualifiedTypeName(const QualType &Ty,
4434+
bool Util::matchQualifiedTypeName(QualType Ty,
44324435
ArrayRef<Util::DeclContextDesc> Scopes) {
44334436
const CXXRecordDecl *RecTy = Ty->getAsCXXRecordDecl();
44344437

0 commit comments

Comments
 (0)