Skip to content

Commit

Permalink
[llvm] Use StringRef::consume_front (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Dec 25, 2023
1 parent 76243ad commit f5f2c31
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 23 deletions.
3 changes: 1 addition & 2 deletions llvm/lib/ExecutionEngine/Orc/Debugging/DebugInfoSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ llvm::orc::createDWARFContext(LinkGraph &G) {
auto SecData = getSectionData(Sec);
auto Name = Sec.getName();
// DWARFContext expects the section name to not start with a dot
if (Name.starts_with("."))
Name = Name.drop_front();
Name.consume_front(".");
LLVM_DEBUG(dbgs() << "Creating DWARFContext section " << Name
<< " with size " << SecData.size() << "\n");
DWARFSectionData[Name] =
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/MC/WasmObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,8 +1526,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
StringRef Name = SectionName;

// For user-defined custom sections, strip the prefix
if (Name.starts_with(".custom_section."))
Name = Name.substr(strlen(".custom_section."));
Name.consume_front(".custom_section.");

MCSymbol *Begin = Sec.getBeginSymbol();
if (Begin) {
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVTypeByName(
// N is the number of elements of the vector.
Type *Ty;

if (TypeStr.starts_with("atomic_"))
TypeStr = TypeStr.substr(strlen("atomic_"));
TypeStr.consume_front("atomic_");

if (TypeStr.starts_with("void")) {
Ty = Type::getVoidTy(Ctx);
Expand Down Expand Up @@ -1007,8 +1006,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVTypeByName(
// Handle "typeN*" or "type vector[N]*".
bool IsPtrToVec = TypeStr.consume_back("*");

if (TypeStr.starts_with(" vector[")) {
TypeStr = TypeStr.substr(strlen(" vector["));
if (TypeStr.consume_front(" vector[")) {
TypeStr = TypeStr.substr(0, TypeStr.find(']'));
}
TypeStr.getAsInteger(10, VecElts);
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2312,8 +2312,7 @@ bool X86AsmParser::ParseIntelDotOperator(IntelExprStateMachine &SM,

// Drop the optional '.'.
StringRef DotDispStr = Tok.getString();
if (DotDispStr.starts_with("."))
DotDispStr = DotDispStr.drop_front(1);
DotDispStr.consume_front(".");
StringRef TrailingDot;

// .Imm gets lexed as a real.
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/X86/X86InsertPrefetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ bool X86InsertPrefetch::findPrefetchInfo(const FunctionSamples *TopSamples,
int64_t D = static_cast<int64_t>(S_V.second);
unsigned IID = 0;
for (const auto &HintType : HintTypes) {
if (Name.starts_with(HintType.first)) {
Name = Name.drop_front(HintType.first.size());
if (Name.consume_front(HintType.first)) {
IID = HintType.second;
break;
}
Expand Down
6 changes: 1 addition & 5 deletions llvm/lib/TargetParser/ARMTargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,7 @@ StringRef ARM::getArchExtName(uint64_t ArchExtKind) {
}

static bool stripNegationPrefix(StringRef &Name) {
if (Name.starts_with("no")) {
Name = Name.substr(2);
return true;
}
return false;
return Name.consume_front("no");
}

StringRef ARM::getArchExtFeature(StringRef ArchExt) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/TargetParser/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,7 @@ static VersionTuple parseVersionFromName(StringRef Name) {
VersionTuple Triple::getEnvironmentVersion() const {
StringRef EnvironmentName = getEnvironmentName();
StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
if (EnvironmentName.starts_with(EnvironmentTypeName))
EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
EnvironmentName.consume_front(EnvironmentTypeName);

return parseVersionFromName(EnvironmentName);
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-ar/llvm-ar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,8 +1287,7 @@ static const char *matchFlagWithArg(StringRef Expected,
ArrayRef<const char *> Args) {
StringRef Arg = *ArgIt;

if (Arg.starts_with("--"))
Arg = Arg.substr(2);
Arg.consume_front("--");

size_t len = Expected.size();
if (Arg == Expected) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-diff/llvm-diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ static std::unique_ptr<Module> readModule(LLVMContext &Context,
static void diffGlobal(DifferenceEngine &Engine, Module &L, Module &R,
StringRef Name) {
// Drop leading sigils from the global name.
if (Name.starts_with("@"))
Name = Name.substr(1);
Name.consume_front("@");

Function *LFn = L.getFunction(Name);
Function *RFn = R.getFunction(Name);
Expand Down

0 comments on commit f5f2c31

Please sign in to comment.