Skip to content

Commit f7a360d

Browse files
authored
[SYCL][NFC] Fix some 'startswith/endswith' related to SYCL (#12573)
Replace some deprecated 'startswith' and 'endswith' with 'starts_with' and 'ends_with' to clear some warnings when building SYCL compiler. --------- Signed-off-by: jinge90 <[email protected]>
1 parent f9e4f10 commit f7a360d

File tree

20 files changed

+43
-42
lines changed

20 files changed

+43
-42
lines changed

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ llvm::Type *CodeGenTypes::ConvertSYCLJointMatrixINTELType(RecordDecl *RD) {
342342
if (CompTy->isStructTy()) {
343343
StringRef LlvmTyName = CompTy->getStructName();
344344
// Emit half/int16/float for sycl[::*]::{half,bfloat16,tf32}
345-
if (LlvmTyName.startswith("class.sycl::") ||
346-
LlvmTyName.startswith("class.__sycl_internal::"))
345+
if (LlvmTyName.starts_with("class.sycl::") ||
346+
LlvmTyName.starts_with("class.__sycl_internal::"))
347347
LlvmTyName = LlvmTyName.rsplit("::").second;
348348
if (LlvmTyName == "half") {
349349
CompTy = llvm::Type::getHalfTy(getLLVMContext());

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,7 +3518,7 @@ getLinkerArgs(Compilation &C, DerivedArgList &Args, bool IncludeObj = false) {
35183518
// manner than the OpenMP processing. We should try and refactor this
35193519
// to use the OpenMP flow (adding -l<name> to the llvm-link step)
35203520
auto resolveStaticLib = [&](StringRef LibName, bool IsStatic) -> bool {
3521-
if (!LibName.startswith("-l"))
3521+
if (!LibName.starts_with("-l"))
35223522
return false;
35233523
for (auto &LPath : LibPaths) {
35243524
if (!IsStatic) {
@@ -3663,7 +3663,7 @@ static bool IsSYCLDeviceLibObj(std::string ObjFilePath, bool isMSVCEnv) {
36633663
StringRef ObjFileName = llvm::sys::path::filename(ObjFilePath);
36643664
StringRef ObjSuffix = isMSVCEnv ? ".obj" : ".o";
36653665
bool Ret =
3666-
(ObjFileName.startswith("libsycl-") && ObjFileName.endswith(ObjSuffix))
3666+
(ObjFileName.starts_with("libsycl-") && ObjFileName.ends_with(ObjSuffix))
36673667
? true
36683668
: false;
36693669
return Ret;

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
344344
// The deprecated -DLLVM_ENABLE_PROJECTS=libcxx configuration installs
345345
// libc++.so in D.Dir+"/../lib/". Detect this path.
346346
// TODO Remove once LLVM_ENABLE_PROJECTS=libcxx is unsupported.
347-
if (StringRef(D.Dir).startswith(SysRoot) &&
347+
if (StringRef(D.Dir).starts_with(SysRoot) &&
348348
(Args.hasArg(options::OPT_fsycl) ||
349349
D.getVFS().exists(D.Dir + "/../lib/libsycl.so")))
350350
addPathIfExists(D, D.Dir + "/../lib", Paths);

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
401401
LibPostfix = ".cubin";
402402
}
403403
StringRef LibSyclPrefix("libsycl-");
404-
if (!InputFilename.startswith(LibSyclPrefix) ||
405-
!InputFilename.endswith(LibPostfix) || (InputFilename.count('-') < 2))
404+
if (!InputFilename.starts_with(LibSyclPrefix) ||
405+
!InputFilename.ends_with(LibPostfix) ||
406+
(InputFilename.count('-') < 2))
406407
return false;
407408
// Skip the prefix "libsycl-"
408409
std::string PureLibName =
@@ -419,7 +420,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
419420
PureLibName.substr(0, FinalDashPos) + PureLibName.substr(DotPos);
420421
}
421422
for (const auto &L : SYCLDeviceLibList) {
422-
if (StringRef(PureLibName).startswith(L))
423+
if (StringRef(PureLibName).starts_with(L))
423424
return true;
424425
}
425426
return false;
@@ -1354,7 +1355,7 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
13541355
for (auto *A : Args) {
13551356
if (!A->getOption().matches(options::OPT_Xsycl_backend_EQ))
13561357
continue;
1357-
if (StringRef(A->getValue()).startswith("intel_gpu"))
1358+
if (StringRef(A->getValue()).starts_with("intel_gpu"))
13581359
TargArgs.push_back(A->getValue(1));
13591360
}
13601361
if (llvm::find_if(TargArgs, [&](auto Cur) {

clang/lib/Driver/ToolChains/SYCL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ constexpr char AmdGPU[] = "amd_gpu_";
125125
template <auto GPUArh> std::optional<StringRef> isGPUTarget(StringRef Target) {
126126
// Handle target specifications that resemble '(intel, nvidia, amd)_gpu_*'
127127
// here.
128-
if (Target.startswith(GPUArh)) {
128+
if (Target.starts_with(GPUArh)) {
129129
return resolveGenDevice(Target);
130130
}
131131
return std::nullopt;

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
282282
.Default(false);
283283
};
284284
if ((getEmissionReason(FDecl) == Sema::DeviceDiagnosticReason::Sycl) &&
285-
Id && !Id->getName().startswith("__spirv_") &&
286-
!Id->getName().startswith("__sycl_") &&
287-
!Id->getName().startswith("__devicelib_ConvertBF16ToFINTEL") &&
288-
!Id->getName().startswith("__devicelib_ConvertFToBF16INTEL") &&
289-
!Id->getName().startswith("__assert_fail") &&
285+
Id && !Id->getName().starts_with("__spirv_") &&
286+
!Id->getName().starts_with("__sycl_") &&
287+
!Id->getName().starts_with("__devicelib_ConvertBF16ToFINTEL") &&
288+
!Id->getName().starts_with("__devicelib_ConvertFToBF16INTEL") &&
289+
!Id->getName().starts_with("__assert_fail") &&
290290
!isMsvcMathFn(Id->getName())) {
291291
SYCLDiagIfDeviceCode(
292292
*Locs.begin(), diag::err_sycl_device_function_is_called_from_esimd,

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4295,7 +4295,7 @@ static void CheckSYCL2020SubGroupSizes(Sema &S, FunctionDecl *SYCLKernel,
42954295
// No need to validate __spirv routines here since they
42964296
// are mapped to the equivalent SPIRV operations.
42974297
const IdentifierInfo *II = FD->getIdentifier();
4298-
if (II && II->getName().startswith("__spirv_"))
4298+
if (II && II->getName().starts_with("__spirv_"))
42994299
return;
43004300

43014301
// Else we need to figure out why they don't match.

clang/tools/clang-offload-deps/ClangOffloadDeps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int main(int argc, const char **argv) {
173173
// possibly reusing ClangOffloadBundler's 'OffloadTargetInfo'.
174174
for (const std::string &Target : Targets) {
175175
std::string Prefix = Target + ".";
176-
if (Symbol.startswith(Prefix))
176+
if (Symbol.starts_with(Prefix))
177177
Target2Symbols[Target].insert(
178178
Symbol.substr(Prefix.size(), Len - Prefix.size()));
179179
}

llvm/lib/SYCLLowerIR/ESIMD/ESIMDUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ constexpr char SLM_ALLOCATOR_DTOR_SUFFIX[] = "EED2Ev";
3434
bool isSlmAllocatorConstructor(const Function &F) {
3535
auto Name = F.getName();
3636
return Name.starts_with(SLM_ALLOCATOR_CTOR_DTOR_PREFIX) &&
37-
Name.endswith(SLM_ALLOCATOR_CTOR_SUFFIX);
37+
Name.ends_with(SLM_ALLOCATOR_CTOR_SUFFIX);
3838
}
3939

4040
bool isSlmAllocatorDestructor(const Function &F) {
4141
auto Name = F.getName();
4242
return Name.starts_with(SLM_ALLOCATOR_CTOR_DTOR_PREFIX) &&
43-
Name.endswith(SLM_ALLOCATOR_DTOR_SUFFIX);
43+
Name.ends_with(SLM_ALLOCATOR_DTOR_SUFFIX);
4444
}
4545

4646
bool isSlmInit(const Function &F) {

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,15 +1596,15 @@ SmallPtrSet<Type *, 4> collectGenXVolatileTypes(Module &M) {
15961596
// TODO FIXME relying on type name in LLVM IR is fragile, needs rework
15971597
if (!GTy || !GTy->getName()
15981598
.rtrim(".0123456789")
1599-
.endswith("sycl::_V1::ext::intel::esimd::simd"))
1599+
.ends_with("sycl::_V1::ext::intel::esimd::simd"))
16001600
continue;
16011601
assert(GTy->getNumContainedTypes() == 1);
16021602
auto VTy = GTy->getContainedType(0);
16031603
if ((GTy = dyn_cast<StructType>(VTy))) {
1604-
assert(
1605-
GTy->getName()
1606-
.rtrim(".0123456789")
1607-
.endswith("sycl::_V1::ext::intel::esimd::detail::simd_obj_impl"));
1604+
assert(GTy->getName()
1605+
.rtrim(".0123456789")
1606+
.ends_with(
1607+
"sycl::_V1::ext::intel::esimd::detail::simd_obj_impl"));
16081608
VTy = GTy->getContainedType(0);
16091609
}
16101610
assert(VTy->isVectorTy());

llvm/lib/SYCLLowerIR/PrepareSYCLNativeCPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static Function *addGetFunc(Module &M, StringRef Name, Type *StateType) {
283283
static Function *addReplaceFunc(Module &M, StringRef Name, Type *StateType) {
284284
Function *Res;
285285
const char GetPrefix[] = "__dpcpp_nativecpu_get";
286-
if (Name.startswith(GetPrefix)) {
286+
if (Name.starts_with(GetPrefix)) {
287287
Res = addGetFunc(M, Name, StateType);
288288
} else if (Name == NativeCPUSetLocalId) {
289289
Res = addSetLocalIdFunc(M, Name, StateType);

llvm/lib/Support/PropertySetIO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ PropertySetRegistry::read(const MemoryBuffer *Buf) {
3737

3838
for (line_iterator LI(*Buf); !LI.is_at_end(); LI++) {
3939
// see if this line starts a new property set
40-
if (LI->startswith("[")) {
40+
if (LI->starts_with("[")) {
4141
// yes - parse the category (property name)
4242
auto EndPos = LI->rfind(']');
4343
if (EndPos == StringRef::npos)

llvm/lib/Support/SimpleTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ Expected<SimpleTable::UPtrTy> SimpleTable::read(MemoryBuffer *Buf,
214214
return std::make_unique<SimpleTable>();
215215
UPtrTy Res;
216216

217-
if (LI->startswith(COL_TITLE_LINE_OPEN)) {
218-
if (!LI->endswith(COL_TITLE_LINE_CLOSE))
217+
if (LI->starts_with(COL_TITLE_LINE_OPEN)) {
218+
if (!LI->ends_with(COL_TITLE_LINE_CLOSE))
219219
return createStringError(errc::invalid_argument, "malformed title line");
220220
// column titles present
221221
StringRef L = LI->substr(1, LI->size() - 2); // trim '[' and ']'

llvm/lib/TargetParser/Triple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) {
726726
(SubArchName.ends_with("r6el") || SubArchName.ends_with("r6")))
727727
return Triple::MipsSubArch_r6;
728728

729-
if (SubArchName.startswith("spir")) {
729+
if (SubArchName.starts_with("spir")) {
730730
StringRef SA(SubArchName);
731731
if (SA.consume_front("spir64_") || SA.consume_front("spir_")) {
732732
if (SA == "fpga")

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
838838
// // extractelement <8 x i32> (bitcast <4 x i64> %X to <8 x i32>), i32 0
839839
// ```
840840
// can't be lowered by SPIR-V translator to "standard" format.
841-
if (StringRef(Trunc.getModule()->getTargetTriple()).startswith("spir"))
841+
if (StringRef(Trunc.getModule()->getTargetTriple()).starts_with("spir"))
842842
return nullptr;
843843

844844
// Whenever an element is extracted from a vector, and then truncated,

llvm/lib/Transforms/Instrumentation/SPIRITTAnnotations.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ bool insertAtomicInstrumentationCall(Module &M, StringRef Name,
243243

244244
PreservedAnalyses SPIRITTAnnotationsPass::run(Module &M,
245245
ModuleAnalysisManager &MAM) {
246-
assert(StringRef(M.getTargetTriple()).startswith("spir"));
246+
assert(StringRef(M.getTargetTriple()).starts_with("spir"));
247247
bool IRModified = false;
248248
std::vector<StringRef> SPIRVCrossWGInstuctions = {
249249
SPIRV_CONTROL_BARRIER, SPIRV_GROUP_ALL, SPIRV_GROUP_ANY,
@@ -299,15 +299,15 @@ PreservedAnalyses SPIRITTAnnotationsPass::run(Module &M,
299299
if (std::any_of(SPIRVCrossWGInstuctions.begin(),
300300
SPIRVCrossWGInstuctions.end(),
301301
[&CalleeName](StringRef Name) {
302-
return CalleeName.startswith(Name);
302+
return CalleeName.starts_with(Name);
303303
})) {
304304
Instruction *InstAfterBarrier = CI->getNextNode();
305305
const DebugLoc &DL = CI->getDebugLoc();
306306
insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WG_BARRIER, CI, DL);
307307
insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WI_RESUME,
308308
InstAfterBarrier, DL);
309309
IRModified = true;
310-
} else if (CalleeName.startswith(SPIRV_ATOMIC_INST)) {
310+
} else if (CalleeName.starts_with(SPIRV_ATOMIC_INST)) {
311311
Instruction *InstAfterAtomic = CI->getNextNode();
312312
IRModified |= insertAtomicInstrumentationCall(
313313
M, ITT_ANNOTATION_ATOMIC_START, CI, CI, CalleeName);

llvm/tools/sycl-post-link/ModuleSplitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool isSpirvSyclBuiltin(StringRef FName) {
7979
// now skip the digits
8080
FName = FName.drop_while([](char C) { return std::isdigit(C); });
8181

82-
return FName.startswith("__spirv_") || FName.startswith("__sycl_");
82+
return FName.starts_with("__spirv_") || FName.starts_with("__sycl_");
8383
}
8484

8585
// Return true if the function is a ESIMD builtin
@@ -91,12 +91,12 @@ bool isESIMDBuiltin(StringRef FName) {
9191
// now skip the digits
9292
FName = FName.drop_while([](char C) { return std::isdigit(C); });
9393

94-
return FName.startswith("__esimd_");
94+
return FName.starts_with("__esimd_");
9595
}
9696

9797
// Return true if the function name starts with "__builtin_"
9898
bool isGenericBuiltin(StringRef FName) {
99-
return FName.startswith("__builtin_");
99+
return FName.starts_with("__builtin_");
100100
}
101101

102102
bool isKernel(const Function &F) {

llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ uint32_t llvm::getSYCLDeviceLibReqMask(const Module &M) {
696696
return 0;
697697
uint32_t ReqMask = 0;
698698
for (const Function &SF : M) {
699-
if (SF.getName().startswith(DEVICELIB_FUNC_PREFIX) && SF.isDeclaration()) {
699+
if (SF.getName().starts_with(DEVICELIB_FUNC_PREFIX) && SF.isDeclaration()) {
700700
assert(SF.getCallingConv() == CallingConv::SPIR_FUNC);
701701
uint32_t DeviceLibBits = getDeviceLibBits(SF.getName().str());
702702
ReqMask |= DeviceLibBits;

llvm/tools/sycl-post-link/SpecConstants.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,8 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
801801
if (!F.isDeclaration())
802802
continue;
803803

804-
if (!F.getName().startswith(SYCL_GET_SCALAR_2020_SPEC_CONST_VAL) &&
805-
!F.getName().startswith(SYCL_GET_COMPOSITE_2020_SPEC_CONST_VAL))
804+
if (!F.getName().starts_with(SYCL_GET_SCALAR_2020_SPEC_CONST_VAL) &&
805+
!F.getName().starts_with(SYCL_GET_COMPOSITE_2020_SPEC_CONST_VAL))
806806
continue;
807807

808808
SmallVector<CallInst *, 32> SCIntrCalls;
@@ -1014,8 +1014,8 @@ bool SpecConstantsPass::collectSpecConstantDefaultValuesMetadata(
10141014

10151015
bool llvm::checkModuleContainsSpecConsts(const Module &M) {
10161016
for (const Function &F : M.functions()) {
1017-
if (F.getName().startswith(SYCL_GET_SCALAR_2020_SPEC_CONST_VAL) ||
1018-
F.getName().startswith(SYCL_GET_COMPOSITE_2020_SPEC_CONST_VAL))
1017+
if (F.getName().starts_with(SYCL_GET_SCALAR_2020_SPEC_CONST_VAL) ||
1018+
F.getName().starts_with(SYCL_GET_COMPOSITE_2020_SPEC_CONST_VAL))
10191019
return true;
10201020
}
10211021

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ std::string makeResultFileName(Twine Ext, int I, StringRef Suffix) {
340340
: sys::path::parent_path(OutputFilename);
341341
const StringRef Sep = sys::path::get_separator();
342342
std::string Dir = Dir0.str();
343-
if (!Dir0.empty() && !Dir0.endswith(Sep))
343+
if (!Dir0.empty() && !Dir0.ends_with(Sep))
344344
Dir += Sep.str();
345345
return Dir + sys::path::stem(OutputFilename).str() + Suffix.str() + "_" +
346346
std::to_string(I) + Ext.str();

0 commit comments

Comments
 (0)