Skip to content

Commit 8b38a14

Browse files
author
Erich Keane
authored
[SYCL][NFC] Remove a bunch of unnecessary std::string allocations (#3347)
Apparently we have some static globals of type std::string to represent a string-literal. The result is that we get some std::string constructors (and thus allocations!) for no reason. These are only ever used as StringRef. This patch replaces those with constexpr llvm::StringLiteral types, which is a constexpr-constructed StringRef. These don't require allocations like std::string, so the initialization becomes a no-op. Additionally, these were being copied at least 1x later on, so the switch there likely saves runtime allocations as well.
1 parent ee7e99f commit 8b38a14

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ enum KernelInvocationKind {
5656
InvokeParallelForWorkGroup
5757
};
5858

59-
const static std::string InitMethodName = "__init";
60-
const static std::string InitESIMDMethodName = "__init_esimd";
61-
const static std::string FinalizeMethodName = "__finalize";
59+
static constexpr llvm::StringLiteral InitMethodName = "__init";
60+
static constexpr llvm::StringLiteral InitESIMDMethodName = "__init_esimd";
61+
static constexpr llvm::StringLiteral FinalizeMethodName = "__finalize";
6262
constexpr unsigned MaxKernelArgsSize = 2048;
6363

6464
namespace {
@@ -1713,7 +1713,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
17131713
bool isAccessorType = false) {
17141714
const auto *RecordDecl = FieldTy->getAsCXXRecordDecl();
17151715
assert(RecordDecl && "The accessor/sampler must be a RecordDecl");
1716-
const std::string &MethodName =
1716+
llvm::StringLiteral MethodName =
17171717
KernelDecl->hasAttr<SYCLSimdAttr>() && isAccessorType
17181718
? InitESIMDMethodName
17191719
: InitMethodName;
@@ -1827,9 +1827,9 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
18271827
QualType FieldTy) final {
18281828
const auto *RecordDecl = FieldTy->getAsCXXRecordDecl();
18291829
assert(RecordDecl && "The accessor/sampler must be a RecordDecl");
1830-
const std::string MethodName = KernelDecl->hasAttr<SYCLSimdAttr>()
1831-
? InitESIMDMethodName
1832-
: InitMethodName;
1830+
llvm::StringLiteral MethodName = KernelDecl->hasAttr<SYCLSimdAttr>()
1831+
? InitESIMDMethodName
1832+
: InitMethodName;
18331833
CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, MethodName);
18341834
assert(InitMethod && "The accessor/sampler must have the __init method");
18351835

@@ -1972,7 +1972,7 @@ class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler {
19721972
bool handleSpecialType(QualType FieldTy) {
19731973
const CXXRecordDecl *RecordDecl = FieldTy->getAsCXXRecordDecl();
19741974
assert(RecordDecl && "The accessor/sampler must be a RecordDecl");
1975-
const std::string &MethodName =
1975+
llvm::StringLiteral MethodName =
19761976
IsSIMD ? InitESIMDMethodName : InitMethodName;
19771977
CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, MethodName);
19781978
assert(InitMethod && "The accessor/sampler must have the __init method");
@@ -2386,7 +2386,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
23862386
return VD;
23872387
}
23882388

2389-
const std::string &getInitMethodName() const {
2389+
const llvm::StringLiteral getInitMethodName() const {
23902390
bool IsSIMDKernel = isESIMDKernelType(KernelObj);
23912391
return IsSIMDKernel ? InitESIMDMethodName : InitMethodName;
23922392
}

0 commit comments

Comments
 (0)