Skip to content

Commit 3ca4fe8

Browse files
committed
[Transforms] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC.
startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
1 parent 8b3c071 commit 3ca4fe8

22 files changed

+53
-53
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ processGlobal(GlobalValue &GV,
16141614
function_ref<TargetTransformInfo &(Function &)> GetTTI,
16151615
function_ref<TargetLibraryInfo &(Function &)> GetTLI,
16161616
function_ref<DominatorTree &(Function &)> LookupDomTree) {
1617-
if (GV.getName().startswith("llvm."))
1617+
if (GV.getName().starts_with("llvm."))
16181618
return false;
16191619

16201620
GlobalStatus GS;

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ struct OMPInformationCache : public InformationCache {
622622
for (Function &F : M) {
623623
for (StringRef Prefix : {"__kmpc", "_ZN4ompx", "omp_"})
624624
if (F.hasFnAttribute(Attribute::NoInline) &&
625-
F.getName().startswith(Prefix) &&
625+
F.getName().starts_with(Prefix) &&
626626
!F.hasFnAttribute(Attribute::OptimizeNone))
627627
F.removeFnAttr(Attribute::NoInline);
628628
}
@@ -1996,7 +1996,7 @@ struct OpenMPOpt {
19961996
Function *F = I->getParent()->getParent();
19971997
auto &ORE = OREGetter(F);
19981998

1999-
if (RemarkName.startswith("OMP"))
1999+
if (RemarkName.starts_with("OMP"))
20002000
ORE.emit([&]() {
20012001
return RemarkCB(RemarkKind(DEBUG_TYPE, RemarkName, I))
20022002
<< " [" << RemarkName << "]";
@@ -2012,7 +2012,7 @@ struct OpenMPOpt {
20122012
RemarkCallBack &&RemarkCB) const {
20132013
auto &ORE = OREGetter(F);
20142014

2015-
if (RemarkName.startswith("OMP"))
2015+
if (RemarkName.starts_with("OMP"))
20162016
ORE.emit([&]() {
20172017
return RemarkCB(RemarkKind(DEBUG_TYPE, RemarkName, F))
20182018
<< " [" << RemarkName << "]";

llvm/lib/Transforms/IPO/StripSymbols.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo) {
7979
Value *V = VI->getValue();
8080
++VI;
8181
if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
82-
if (!PreserveDbgInfo || !V->getName().startswith("llvm.dbg"))
82+
if (!PreserveDbgInfo || !V->getName().starts_with("llvm.dbg"))
8383
// Set name to "", removing from symbol table!
8484
V->setName("");
8585
}
@@ -94,7 +94,7 @@ static void StripTypeNames(Module &M, bool PreserveDbgInfo) {
9494
for (StructType *STy : StructTypes) {
9595
if (STy->isLiteral() || STy->getName().empty()) continue;
9696

97-
if (PreserveDbgInfo && STy->getName().startswith("llvm.dbg"))
97+
if (PreserveDbgInfo && STy->getName().starts_with("llvm.dbg"))
9898
continue;
9999

100100
STy->setName("");
@@ -124,13 +124,13 @@ static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
124124

125125
for (GlobalVariable &GV : M.globals()) {
126126
if (GV.hasLocalLinkage() && !llvmUsedValues.contains(&GV))
127-
if (!PreserveDbgInfo || !GV.getName().startswith("llvm.dbg"))
127+
if (!PreserveDbgInfo || !GV.getName().starts_with("llvm.dbg"))
128128
GV.setName(""); // Internal symbols can't participate in linkage
129129
}
130130

131131
for (Function &I : M) {
132132
if (I.hasLocalLinkage() && !llvmUsedValues.contains(&I))
133-
if (!PreserveDbgInfo || !I.getName().startswith("llvm.dbg"))
133+
if (!PreserveDbgInfo || !I.getName().starts_with("llvm.dbg"))
134134
I.setName(""); // Internal symbols can't participate in linkage
135135
if (auto *Symtab = I.getValueSymbolTable())
136136
StripSymtab(*Symtab, PreserveDbgInfo);

llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void simplifyExternals(Module &M) {
186186

187187
if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
188188
// Changing the type of an intrinsic may invalidate the IR.
189-
F.getName().startswith("llvm."))
189+
F.getName().starts_with("llvm."))
190190
continue;
191191

192192
Function *NewF =

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ bool DevirtModule::runForTesting(
10031003
ExitOnError ExitOnErr(
10041004
"-wholeprogramdevirt-write-summary: " + ClWriteSummary + ": ");
10051005
std::error_code EC;
1006-
if (StringRef(ClWriteSummary).endswith(".bc")) {
1006+
if (StringRef(ClWriteSummary).ends_with(".bc")) {
10071007
raw_fd_ostream OS(ClWriteSummary, EC, sys::fs::OF_None);
10081008
ExitOnErr(errorCodeToError(EC));
10091009
writeIndexToFile(*Summary, OS);

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,17 +1189,17 @@ static size_t TypeStoreSizeToSizeIndex(uint32_t TypeSize) {
11891189
/// Check if \p G has been created by a trusted compiler pass.
11901190
static bool GlobalWasGeneratedByCompiler(GlobalVariable *G) {
11911191
// Do not instrument @llvm.global_ctors, @llvm.used, etc.
1192-
if (G->getName().startswith("llvm.") ||
1192+
if (G->getName().starts_with("llvm.") ||
11931193
// Do not instrument gcov counter arrays.
1194-
G->getName().startswith("__llvm_gcov_ctr") ||
1194+
G->getName().starts_with("__llvm_gcov_ctr") ||
11951195
// Do not instrument rtti proxy symbols for function sanitizer.
1196-
G->getName().startswith("__llvm_rtti_proxy"))
1196+
G->getName().starts_with("__llvm_rtti_proxy"))
11971197
return true;
11981198

11991199
// Do not instrument asan globals.
1200-
if (G->getName().startswith(kAsanGenPrefix) ||
1201-
G->getName().startswith(kSanCovGenPrefix) ||
1202-
G->getName().startswith(kODRGenPrefix))
1200+
if (G->getName().starts_with(kAsanGenPrefix) ||
1201+
G->getName().starts_with(kSanCovGenPrefix) ||
1202+
G->getName().starts_with(kODRGenPrefix))
12031203
return true;
12041204

12051205
return false;
@@ -1870,7 +1870,7 @@ ModuleAddressSanitizer::getExcludedAliasedGlobal(const GlobalAlias &GA) const {
18701870

18711871
// When compiling the kernel, globals that are aliased by symbols prefixed
18721872
// by "__" are special and cannot be padded with a redzone.
1873-
if (GA.getName().startswith("__"))
1873+
if (GA.getName().starts_with("__"))
18741874
return dyn_cast<GlobalVariable>(C->stripPointerCastsAndAliases());
18751875

18761876
return nullptr;
@@ -1940,9 +1940,9 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
19401940

19411941
// Do not instrument function pointers to initialization and termination
19421942
// routines: dynamic linker will not properly handle redzones.
1943-
if (Section.startswith(".preinit_array") ||
1944-
Section.startswith(".init_array") ||
1945-
Section.startswith(".fini_array")) {
1943+
if (Section.starts_with(".preinit_array") ||
1944+
Section.starts_with(".init_array") ||
1945+
Section.starts_with(".fini_array")) {
19461946
return false;
19471947
}
19481948

@@ -1979,7 +1979,7 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
19791979
// those conform to /usr/lib/objc/runtime.h, so we can't add redzones to
19801980
// them.
19811981
if (ParsedSegment == "__OBJC" ||
1982-
(ParsedSegment == "__DATA" && ParsedSection.startswith("__objc_"))) {
1982+
(ParsedSegment == "__DATA" && ParsedSection.starts_with("__objc_"))) {
19831983
LLVM_DEBUG(dbgs() << "Ignoring ObjC runtime global: " << *G << "\n");
19841984
return false;
19851985
}
@@ -2007,7 +2007,7 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
20072007
if (CompileKernel) {
20082008
// Globals that prefixed by "__" are special and cannot be padded with a
20092009
// redzone.
2010-
if (G->getName().startswith("__"))
2010+
if (G->getName().starts_with("__"))
20112011
return false;
20122012
}
20132013

@@ -2803,7 +2803,7 @@ bool AddressSanitizer::instrumentFunction(Function &F,
28032803
return false;
28042804
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false;
28052805
if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false;
2806-
if (F.getName().startswith("__asan_")) return false;
2806+
if (F.getName().starts_with("__asan_")) return false;
28072807

28082808
bool FunctionModified = false;
28092809

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ void HWAddressSanitizer::instrumentGlobals() {
16651665
if (GV.hasSanitizerMetadata() && GV.getSanitizerMetadata().NoHWAddress)
16661666
continue;
16671667

1668-
if (GV.isDeclarationForLinker() || GV.getName().startswith("llvm.") ||
1668+
if (GV.isDeclarationForLinker() || GV.getName().starts_with("llvm.") ||
16691669
GV.isThreadLocal())
16701670
continue;
16711671

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ static std::string getVarName(InstrProfInstBase *Inc, StringRef Prefix,
908908
Renamed = true;
909909
uint64_t FuncHash = Inc->getHash()->getZExtValue();
910910
SmallVector<char, 24> HashPostfix;
911-
if (Name.endswith((Twine(".") + Twine(FuncHash)).toStringRef(HashPostfix)))
911+
if (Name.ends_with((Twine(".") + Twine(FuncHash)).toStringRef(HashPostfix)))
912912
return (Prefix + Name).str();
913913
return (Prefix + Name + "." + Twine(FuncHash)).str();
914914
}

llvm/lib/Transforms/Instrumentation/MemProfiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,13 @@ MemProfiler::isInterestingMemoryAccess(Instruction *I) const {
364364
StringRef SectionName = GV->getSection();
365365
// Check if the global is in the PGO counters section.
366366
auto OF = Triple(I->getModule()->getTargetTriple()).getObjectFormat();
367-
if (SectionName.endswith(
367+
if (SectionName.ends_with(
368368
getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false)))
369369
return std::nullopt;
370370
}
371371

372372
// Do not instrument accesses to LLVM internal variables.
373-
if (GV->getName().startswith("__llvm"))
373+
if (GV->getName().starts_with("__llvm"))
374374
return std::nullopt;
375375
}
376376

@@ -562,7 +562,7 @@ bool MemProfiler::instrumentFunction(Function &F) {
562562
return false;
563563
if (ClDebugFunc == F.getName())
564564
return false;
565-
if (F.getName().startswith("__memprof_"))
565+
if (F.getName().starts_with("__memprof_"))
566566
return false;
567567

568568
bool FunctionModified = false;

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4157,7 +4157,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
41574157
if (Function *Func = CB.getCalledFunction()) {
41584158
// __sanitizer_unaligned_{load,store} functions may be called by users
41594159
// and always expects shadows in the TLS. So don't check them.
4160-
MayCheckCall &= !Func->getName().startswith("__sanitizer_unaligned_");
4160+
MayCheckCall &= !Func->getName().starts_with("__sanitizer_unaligned_");
41614161
}
41624162

41634163
unsigned ArgOffset = 0;

0 commit comments

Comments
 (0)