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;

llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ bool isUARSafeCall(CallInst *CI) {
306306
// It's safe to both pass pointers to local variables to them
307307
// and to tail-call them.
308308
return F && (F->isIntrinsic() || F->doesNotReturn() ||
309-
F->getName().startswith("__asan_") ||
310-
F->getName().startswith("__hwsan_") ||
311-
F->getName().startswith("__ubsan_") ||
312-
F->getName().startswith("__msan_") ||
313-
F->getName().startswith("__tsan_"));
309+
F->getName().starts_with("__asan_") ||
310+
F->getName().starts_with("__hwsan_") ||
311+
F->getName().starts_with("__ubsan_") ||
312+
F->getName().starts_with("__msan_") ||
313+
F->getName().starts_with("__tsan_"));
314314
}
315315

316316
bool hasUseAfterReturnUnsafeUses(Value &V) {
@@ -368,11 +368,11 @@ bool SanitizerBinaryMetadata::pretendAtomicAccess(const Value *Addr) {
368368
const auto OF = Triple(Mod.getTargetTriple()).getObjectFormat();
369369
const auto ProfSec =
370370
getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false);
371-
if (GV->getSection().endswith(ProfSec))
371+
if (GV->getSection().ends_with(ProfSec))
372372
return true;
373373
}
374-
if (GV->getName().startswith("__llvm_gcov") ||
375-
GV->getName().startswith("__llvm_gcda"))
374+
if (GV->getName().starts_with("__llvm_gcov") ||
375+
GV->getName().starts_with("__llvm_gcda"))
376376
return true;
377377

378378
return false;

llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void ModuleSanitizerCoverage::instrumentFunction(
606606
return;
607607
if (F.getName().find(".module_ctor") != std::string::npos)
608608
return; // Should not instrument sanitizer init functions.
609-
if (F.getName().startswith("__sanitizer_"))
609+
if (F.getName().starts_with("__sanitizer_"))
610610
return; // Don't instrument __sanitizer_* callbacks.
611611
// Don't touch available_externally functions, their actual body is elewhere.
612612
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage)

llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static bool shouldInstrumentReadWriteFromAddress(const Module *M, Value *Addr) {
360360
StringRef SectionName = GV->getSection();
361361
// Check if the global is in the PGO counters section.
362362
auto OF = Triple(M->getTargetTriple()).getObjectFormat();
363-
if (SectionName.endswith(
363+
if (SectionName.ends_with(
364364
getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false)))
365365
return false;
366366
}

llvm/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using namespace llvm::objcarc;
1919

2020
static StringRef getName(Value *V) {
2121
StringRef Name = V->getName();
22-
if (Name.startswith("\1"))
22+
if (Name.starts_with("\1"))
2323
return Name.substr(1);
2424
return Name;
2525
}

llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static bool hasAnyUnrollPragma(const Loop *L, StringRef Prefix) {
111111
if (!S)
112112
continue;
113113

114-
if (S->getString().startswith(Prefix))
114+
if (S->getString().starts_with(Prefix))
115115
return true;
116116
}
117117
}

llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ class LowerMatrixIntrinsics {
21742174
write("<no called fn>");
21752175
else {
21762176
StringRef Name = CI->getCalledFunction()->getName();
2177-
if (!Name.startswith("llvm.matrix")) {
2177+
if (!Name.starts_with("llvm.matrix")) {
21782178
write(Name);
21792179
return;
21802180
}

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ std::optional<MDNode *> llvm::makeFollowupLoopID(
296296
StringRef AttrName = cast<MDString>(NameMD)->getString();
297297

298298
// Do not inherit excluded attributes.
299-
return !AttrName.startswith(InheritOptionsExceptPrefix);
299+
return !AttrName.starts_with(InheritOptionsExceptPrefix);
300300
};
301301

302302
if (InheritThisAttribute(Op))

llvm/lib/Transforms/Utils/MetaRenamer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,15 @@ void MetaRename(Module &M,
151151
auto IsNameExcluded = [](StringRef &Name,
152152
SmallVectorImpl<StringRef> &ExcludedPrefixes) {
153153
return any_of(ExcludedPrefixes,
154-
[&Name](auto &Prefix) { return Name.startswith(Prefix); });
154+
[&Name](auto &Prefix) { return Name.starts_with(Prefix); });
155155
};
156156

157157
// Leave library functions alone because their presence or absence could
158158
// affect the behavior of other passes.
159159
auto ExcludeLibFuncs = [&](Function &F) {
160160
LibFunc Tmp;
161161
StringRef Name = F.getName();
162-
return Name.startswith("llvm.") || (!Name.empty() && Name[0] == 1) ||
162+
return Name.starts_with("llvm.") || (!Name.empty() && Name[0] == 1) ||
163163
GetTLI(F).getLibFunc(F, Tmp) ||
164164
IsNameExcluded(Name, ExcludedFuncPrefixes);
165165
};
@@ -177,7 +177,7 @@ void MetaRename(Module &M,
177177
// Rename all aliases
178178
for (GlobalAlias &GA : M.aliases()) {
179179
StringRef Name = GA.getName();
180-
if (Name.startswith("llvm.") || (!Name.empty() && Name[0] == 1) ||
180+
if (Name.starts_with("llvm.") || (!Name.empty() && Name[0] == 1) ||
181181
IsNameExcluded(Name, ExcludedAliasesPrefixes))
182182
continue;
183183

@@ -187,7 +187,7 @@ void MetaRename(Module &M,
187187
// Rename all global variables
188188
for (GlobalVariable &GV : M.globals()) {
189189
StringRef Name = GV.getName();
190-
if (Name.startswith("llvm.") || (!Name.empty() && Name[0] == 1) ||
190+
if (Name.starts_with("llvm.") || (!Name.empty() && Name[0] == 1) ||
191191
IsNameExcluded(Name, ExcludedGlobalsPrefixes))
192192
continue;
193193

llvm/lib/Transforms/Utils/ModuleUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ std::string llvm::getUniqueModuleId(Module *M) {
301301
MD5 Md5;
302302
bool ExportsSymbols = false;
303303
auto AddGlobal = [&](GlobalValue &GV) {
304-
if (GV.isDeclaration() || GV.getName().startswith("llvm.") ||
304+
if (GV.isDeclaration() || GV.getName().starts_with("llvm.") ||
305305
!GV.hasExternalLinkage() || GV.hasComdat())
306306
return;
307307
ExportsSymbols = true;

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilderBase &B,
18431843
StringRef CallerName = CI->getFunction()->getName();
18441844
if (!CallerName.empty() && CallerName.back() == 'f' &&
18451845
CallerName.size() == (CalleeName.size() + 1) &&
1846-
CallerName.startswith(CalleeName))
1846+
CallerName.starts_with(CalleeName))
18471847
return nullptr;
18481848
}
18491849

@@ -2378,8 +2378,8 @@ Value *LibCallSimplifier::optimizeFMinFMax(CallInst *CI, IRBuilderBase &B) {
23782378
FMF.setNoSignedZeros();
23792379
B.setFastMathFlags(FMF);
23802380

2381-
Intrinsic::ID IID = Callee->getName().startswith("fmin") ? Intrinsic::minnum
2382-
: Intrinsic::maxnum;
2381+
Intrinsic::ID IID = Callee->getName().starts_with("fmin") ? Intrinsic::minnum
2382+
: Intrinsic::maxnum;
23832383
Function *F = Intrinsic::getDeclaration(CI->getModule(), IID, CI->getType());
23842384
return copyFlags(
23852385
*CI, B.CreateCall(F, {CI->getArgOperand(0), CI->getArgOperand(1)}));

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ void LoopVectorizeHints::getHintsFromMetadata() {
289289
}
290290

291291
void LoopVectorizeHints::setHint(StringRef Name, Metadata *Arg) {
292-
if (!Name.startswith(Prefix()))
292+
if (!Name.starts_with(Prefix()))
293293
return;
294294
Name = Name.substr(Prefix().size(), StringRef::npos);
295295

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7629,7 +7629,7 @@ static void AddRuntimeUnrollDisableMetaData(Loop *L) {
76297629
if (MD) {
76307630
const auto *S = dyn_cast<MDString>(MD->getOperand(0));
76317631
IsUnrollMetadata =
7632-
S && S->getString().startswith("llvm.loop.unroll.disable");
7632+
S && S->getString().starts_with("llvm.loop.unroll.disable");
76337633
}
76347634
MDs.push_back(LoopID->getOperand(i));
76357635
}

0 commit comments

Comments
 (0)