[llvm] 395f9ce - Use StringRef::{starts,ends}_with (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 16 10:14:51 PST 2023
Author: Kazu Hirata
Date: 2023-12-16T10:14:44-08:00
New Revision: 395f9ce30e884cb6ce02f7a3bdd0dd1f72ea9033
URL: https://github.com/llvm/llvm-project/commit/395f9ce30e884cb6ce02f7a3bdd0dd1f72ea9033
DIFF: https://github.com/llvm/llvm-project/commit/395f9ce30e884cb6ce02f7a3bdd0dd1f72ea9033.diff
LOG: Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.
I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
Added:
Modified:
clang/lib/Lex/HeaderSearch.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/Target/DirectX/DXILResource.cpp
llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
llvm/lib/Target/SPIRV/SPIRVUtils.cpp
llvm/lib/Target/Xtensa/AsmParser/XtensaAsmParser.cpp
Removed:
################################################################################
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index a0ac0eaf2f9004..0f1090187734ff 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1671,7 +1671,7 @@ static OptionalFileEntryRef getPrivateModuleMap(FileEntryRef File,
if (Filename == "module.map")
Diags.Report(diag::warn_deprecated_module_dot_map)
<< PrivateFilename << 1
- << File.getDir().getName().endswith(".framework");
+ << File.getDir().getName().ends_with(".framework");
}
return PMMFile;
}
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 738ec301d14799..6b54047020a05d 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5220,7 +5220,7 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, StringRef TT) {
Res.append("-p7:160:256:256:32");
if (!DL.contains("-p8") && !DL.starts_with("p8"))
Res.append("-p8:128:128");
- if (!DL.contains("-p9") && !DL.startswith("p9"))
+ if (!DL.contains("-p9") && !DL.starts_with("p9"))
Res.append("-p9:192:256:256:32");
return Res;
diff --git a/llvm/lib/Target/DirectX/DXILResource.cpp b/llvm/lib/Target/DirectX/DXILResource.cpp
index 92306d907e0546..d3ff12a1f7b34d 100644
--- a/llvm/lib/Target/DirectX/DXILResource.cpp
+++ b/llvm/lib/Target/DirectX/DXILResource.cpp
@@ -261,7 +261,7 @@ void UAVResource::parseSourceType(StringRef S) {
S = S.substr(S.find("<") + 1);
constexpr size_t PrefixLen = StringRef("vector<").size();
- if (S.startswith("vector<"))
+ if (S.starts_with("vector<"))
S = S.substr(PrefixLen, S.find(",") - PrefixLen);
else
S = S.substr(0, S.find(">"));
diff --git a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp
index 1af7b7a5d7845f..b69031adb16730 100644
--- a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp
+++ b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp
@@ -177,7 +177,7 @@ std::string getLinkStringForBuiltIn(SPIRV::BuiltIn::BuiltIn BuiltInValue) {
bool getSpirvBuiltInIdByName(llvm::StringRef Name,
SPIRV::BuiltIn::BuiltIn &BI) {
const std::string Prefix = "__spirv_BuiltIn";
- if (!Name.startswith(Prefix))
+ if (!Name.starts_with(Prefix))
return false;
const SPIRV::SymbolicOperand *Lookup =
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index ae9e801f8f50b8..5ac45079bd0026 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -872,8 +872,8 @@ static bool generateGroupInst(const SPIRV::IncomingCall *Call,
std::tie(GroupResultRegister, GroupResultType) =
buildBoolRegister(MIRBuilder, Call->ReturnType, GR);
- auto Scope = Builtin->Name.startswith("sub_group") ? SPIRV::Scope::Subgroup
- : SPIRV::Scope::Workgroup;
+ auto Scope = Builtin->Name.starts_with("sub_group") ? SPIRV::Scope::Subgroup
+ : SPIRV::Scope::Workgroup;
Register ScopeRegister = buildConstantIntReg(Scope, MIRBuilder, GR);
// Build work/sub group instruction.
@@ -1999,13 +1999,13 @@ struct OpenCLType {
//===----------------------------------------------------------------------===//
static Type *parseTypeString(const StringRef Name, LLVMContext &Context) {
- if (Name.startswith("void"))
+ if (Name.starts_with("void"))
return Type::getVoidTy(Context);
- else if (Name.startswith("int") || Name.startswith("uint"))
+ else if (Name.starts_with("int") || Name.starts_with("uint"))
return Type::getInt32Ty(Context);
- else if (Name.startswith("float"))
+ else if (Name.starts_with("float"))
return Type::getFloatTy(Context);
- else if (Name.startswith("half"))
+ else if (Name.starts_with("half"))
return Type::getHalfTy(Context);
llvm_unreachable("Unable to recognize type!");
}
@@ -2081,7 +2081,7 @@ parseBuiltinTypeNameToTargetExtType(std::string TypeName,
// Pointers-to-opaque-structs representing OpenCL types are first translated
// to equivalent SPIR-V types. OpenCL builtin type names should have the
// following format: e.g. %opencl.event_t
- if (NameWithParameters.startswith("opencl.")) {
+ if (NameWithParameters.starts_with("opencl.")) {
const SPIRV::OpenCLType *OCLTypeRecord =
SPIRV::lookupOpenCLType(NameWithParameters);
if (!OCLTypeRecord)
@@ -2093,7 +2093,7 @@ parseBuiltinTypeNameToTargetExtType(std::string TypeName,
// Names of the opaque structs representing a SPIR-V builtins without
// parameters should have the following format: e.g. %spirv.Event
- assert(NameWithParameters.startswith("spirv.") &&
+ assert(NameWithParameters.starts_with("spirv.") &&
"Unknown builtin opaque type!");
// Parameterized SPIR-V builtins names follow this format:
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index d450613196f3e4..b8a6784ff3c62d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -962,35 +962,35 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVTypeByName(
if (TypeStr.starts_with("atomic_"))
TypeStr = TypeStr.substr(strlen("atomic_"));
- if (TypeStr.startswith("void")) {
+ if (TypeStr.starts_with("void")) {
Ty = Type::getVoidTy(Ctx);
TypeStr = TypeStr.substr(strlen("void"));
- } else if (TypeStr.startswith("bool")) {
+ } else if (TypeStr.starts_with("bool")) {
Ty = Type::getIntNTy(Ctx, 1);
TypeStr = TypeStr.substr(strlen("bool"));
- } else if (TypeStr.startswith("char") || TypeStr.startswith("uchar")) {
+ } else if (TypeStr.starts_with("char") || TypeStr.starts_with("uchar")) {
Ty = Type::getInt8Ty(Ctx);
- TypeStr = TypeStr.startswith("char") ? TypeStr.substr(strlen("char"))
- : TypeStr.substr(strlen("uchar"));
- } else if (TypeStr.startswith("short") || TypeStr.startswith("ushort")) {
+ TypeStr = TypeStr.starts_with("char") ? TypeStr.substr(strlen("char"))
+ : TypeStr.substr(strlen("uchar"));
+ } else if (TypeStr.starts_with("short") || TypeStr.starts_with("ushort")) {
Ty = Type::getInt16Ty(Ctx);
- TypeStr = TypeStr.startswith("short") ? TypeStr.substr(strlen("short"))
- : TypeStr.substr(strlen("ushort"));
- } else if (TypeStr.startswith("int") || TypeStr.startswith("uint")) {
+ TypeStr = TypeStr.starts_with("short") ? TypeStr.substr(strlen("short"))
+ : TypeStr.substr(strlen("ushort"));
+ } else if (TypeStr.starts_with("int") || TypeStr.starts_with("uint")) {
Ty = Type::getInt32Ty(Ctx);
- TypeStr = TypeStr.startswith("int") ? TypeStr.substr(strlen("int"))
- : TypeStr.substr(strlen("uint"));
+ TypeStr = TypeStr.starts_with("int") ? TypeStr.substr(strlen("int"))
+ : TypeStr.substr(strlen("uint"));
} else if (TypeStr.starts_with("long") || TypeStr.starts_with("ulong")) {
Ty = Type::getInt64Ty(Ctx);
- TypeStr = TypeStr.startswith("long") ? TypeStr.substr(strlen("long"))
- : TypeStr.substr(strlen("ulong"));
- } else if (TypeStr.startswith("half")) {
+ TypeStr = TypeStr.starts_with("long") ? TypeStr.substr(strlen("long"))
+ : TypeStr.substr(strlen("ulong"));
+ } else if (TypeStr.starts_with("half")) {
Ty = Type::getHalfTy(Ctx);
TypeStr = TypeStr.substr(strlen("half"));
- } else if (TypeStr.startswith("float")) {
+ } else if (TypeStr.starts_with("float")) {
Ty = Type::getFloatTy(Ctx);
TypeStr = TypeStr.substr(strlen("float"));
- } else if (TypeStr.startswith("double")) {
+ } else if (TypeStr.starts_with("double")) {
Ty = Type::getDoubleTy(Ctx);
TypeStr = TypeStr.substr(strlen("double"));
} else
@@ -1007,7 +1007,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVTypeByName(
// Handle "typeN*" or "type vector[N]*".
bool IsPtrToVec = TypeStr.consume_back("*");
- if (TypeStr.startswith(" vector[")) {
+ if (TypeStr.starts_with(" vector[")) {
TypeStr = TypeStr.substr(strlen(" vector["));
TypeStr = TypeStr.substr(0, TypeStr.find(']'));
}
diff --git a/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp b/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
index 3a51e29dcf1618..322e051a87db1a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
@@ -177,8 +177,8 @@ void SPIRVRegularizer::visitCallInst(CallInst &CI) {
StringRef DemangledName(NameStr);
// TODO: add support for other builtins.
- if (DemangledName.startswith("fmin") || DemangledName.startswith("fmax") ||
- DemangledName.startswith("min") || DemangledName.startswith("max"))
+ if (DemangledName.starts_with("fmin") || DemangledName.starts_with("fmax") ||
+ DemangledName.starts_with("min") || DemangledName.starts_with("max"))
visitCallScalToVec(&CI, MangledName, DemangledName);
free(NameStr);
}
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index 0bd51436082d5f..1c0e8d84e2fd10 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -279,7 +279,7 @@ static bool isKernelQueryBI(const StringRef MangledName) {
}
static bool isNonMangledOCLBuiltin(StringRef Name) {
- if (!Name.startswith("__"))
+ if (!Name.starts_with("__"))
return false;
return isEnqueueKernelBI(Name) || isKernelQueryBI(Name) ||
@@ -289,8 +289,8 @@ static bool isNonMangledOCLBuiltin(StringRef Name) {
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name) {
bool IsNonMangledOCL = isNonMangledOCLBuiltin(Name);
- bool IsNonMangledSPIRV = Name.startswith("__spirv_");
- bool IsMangled = Name.startswith("_Z");
+ bool IsNonMangledSPIRV = Name.starts_with("__spirv_");
+ bool IsMangled = Name.starts_with("_Z");
if (!IsNonMangledOCL && !IsNonMangledSPIRV && !IsMangled)
return std::string();
@@ -311,7 +311,7 @@ std::string getOclOrSpirvBuiltinDemangledName(StringRef Name) {
// Similar to ::std:: in C++.
size_t Start, Len = 0;
size_t DemangledNameLenStart = 2;
- if (Name.startswith("_ZN")) {
+ if (Name.starts_with("_ZN")) {
// Skip CV and ref qualifiers.
size_t NameSpaceStart = Name.find_first_not_of("rVKRO", 3);
// All built-ins are in the ::cl:: namespace.
diff --git a/llvm/lib/Target/Xtensa/AsmParser/XtensaAsmParser.cpp b/llvm/lib/Target/Xtensa/AsmParser/XtensaAsmParser.cpp
index 76c7328b547cd4..3f808298527f8f 100644
--- a/llvm/lib/Target/Xtensa/AsmParser/XtensaAsmParser.cpp
+++ b/llvm/lib/Target/Xtensa/AsmParser/XtensaAsmParser.cpp
@@ -598,8 +598,8 @@ bool XtensaAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic,
bool XtensaAsmParser::ParseInstructionWithSR(ParseInstructionInfo &Info,
StringRef Name, SMLoc NameLoc,
OperandVector &Operands) {
- if ((Name.startswith("wsr.") || Name.startswith("rsr.") ||
- Name.startswith("xsr.")) &&
+ if ((Name.starts_with("wsr.") || Name.starts_with("rsr.") ||
+ Name.starts_with("xsr.")) &&
(Name.size() > 4)) {
// Parse case when instruction name is concatenated with SR register
// name, like "wsr.sar a1"
@@ -655,8 +655,8 @@ bool XtensaAsmParser::ParseInstructionWithSR(ParseInstructionInfo &Info,
bool XtensaAsmParser::ParseInstruction(ParseInstructionInfo &Info,
StringRef Name, SMLoc NameLoc,
OperandVector &Operands) {
- if (Name.startswith("wsr") || Name.startswith("rsr") ||
- Name.startswith("xsr")) {
+ if (Name.starts_with("wsr") || Name.starts_with("rsr") ||
+ Name.starts_with("xsr")) {
return ParseInstructionWithSR(Info, Name, NameLoc, Operands);
}
More information about the llvm-commits
mailing list