Skip to content

Commit 8210cdd

Browse files
[llvm] Use llvm::replace (NFC) (llvm#137481)
1 parent fda8b75 commit 8210cdd

File tree

16 files changed

+31
-42
lines changed

16 files changed

+31
-42
lines changed

llvm/include/llvm/TableGen/DirectiveEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class BaseRecord {
116116
std::string getFormattedName() const {
117117
StringRef Name = Def->getValueAsString("name");
118118
std::string N = Name.str();
119-
std::replace(N.begin(), N.end(), ' ', '_');
119+
llvm::replace(N, ' ', '_');
120120
return N;
121121
}
122122

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ StringRef CodeViewDebug::getFullFilepath(const DIFile *File) {
164164
// Canonicalize the path. We have to do it textually because we may no longer
165165
// have access the file in the filesystem.
166166
// First, replace all slashes with backslashes.
167-
std::replace(Filepath.begin(), Filepath.end(), '/', '\\');
167+
llvm::replace(Filepath, '/', '\\');
168168

169169
// Remove all "\.\" with "\".
170170
size_t Cursor = 0;

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,7 @@ class TransferTracker {
928928
assert(ActiveVLocIt != ActiveVLocs.end());
929929

930930
// Update all instances of Src in the variable's tracked values to Dst.
931-
std::replace(ActiveVLocIt->second.Ops.begin(),
932-
ActiveVLocIt->second.Ops.end(), SrcOp, DstOp);
931+
llvm::replace(ActiveVLocIt->second.Ops, SrcOp, DstOp);
933932

934933
auto &[Var, DILoc] = DVMap.lookupDVID(VarID);
935934
MachineInstr *MI = MTracker->emitLoc(ActiveVLocIt->second.Ops, Var, DILoc,

llvm/lib/CodeGen/LiveVariables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ void LiveVariables::recomputeForSingleDefVirtReg(Register Reg) {
764764
void LiveVariables::replaceKillInstruction(Register Reg, MachineInstr &OldMI,
765765
MachineInstr &NewMI) {
766766
VarInfo &VI = getVarInfo(Reg);
767-
std::replace(VI.Kills.begin(), VI.Kills.end(), &OldMI, &NewMI);
767+
llvm::replace(VI.Kills, &OldMI, &NewMI);
768768
}
769769

770770
/// removeVirtualRegistersKilled - Remove all killed info for the specified

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,8 +2713,7 @@ void SelectionDAGISel::UpdateChains(
27132713
assert(ChainVal.getValueType() == MVT::Other && "Not a chain?");
27142714
SelectionDAG::DAGNodeDeletedListener NDL(
27152715
*CurDAG, [&](SDNode *N, SDNode *E) {
2716-
std::replace(ChainNodesMatched.begin(), ChainNodesMatched.end(), N,
2717-
static_cast<SDNode *>(nullptr));
2716+
llvm::replace(ChainNodesMatched, N, static_cast<SDNode *>(nullptr));
27182717
});
27192718
if (ChainNode->getOpcode() != ISD::TokenFactor)
27202719
ReplaceUses(ChainVal, InputChain);

llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LVStringPool &llvm::logicalview::getStringPool() { return StringPool; }
3131
std::string llvm::logicalview::transformPath(StringRef Path) {
3232
std::string Name(Path);
3333
std::transform(Name.begin(), Name.end(), Name.begin(), tolower);
34-
std::replace(Name.begin(), Name.end(), '\\', '/');
34+
llvm::replace(Name, '\\', '/');
3535

3636
// Remove all duplicate slashes.
3737
size_t Pos = 0;

llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ std::string PDBSymbolCompiland::getSourceFileFullPath() const {
6363
auto Len = EnvWorkingDir.length();
6464
if (EnvWorkingDir[Len - 1] != '/' && EnvWorkingDir[Len - 1] != '\\') {
6565
std::string Path = EnvWorkingDir + "\\" + EnvSrc;
66-
std::replace(Path.begin(), Path.end(), '/', '\\');
66+
llvm::replace(Path, '/', '\\');
6767
// We will return it as full path if we can't find a better one.
6868
if (sys::path::is_absolute(Path))
6969
SourceFileFullPath = Path;

llvm/lib/Support/GraphWriter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,8 @@ static std::string replaceIllegalFilenameChars(std::string Filename,
102102
std::string IllegalChars =
103103
is_style_windows(sys::path::Style::native) ? "\\/:?\"<>|" : "/";
104104

105-
for (char IllegalChar : IllegalChars) {
106-
std::replace(Filename.begin(), Filename.end(), IllegalChar,
107-
ReplacementChar);
108-
}
105+
for (char IllegalChar : IllegalChars)
106+
llvm::replace(Filename, IllegalChar, ReplacementChar);
109107

110108
return Filename;
111109
}

llvm/lib/Support/Path.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void native(SmallVectorImpl<char> &Path, Style style) {
561561
Path = PathHome;
562562
}
563563
} else {
564-
std::replace(Path.begin(), Path.end(), '\\', '/');
564+
llvm::replace(Path, '\\', '/');
565565
}
566566
}
567567

@@ -570,7 +570,7 @@ std::string convert_to_slash(StringRef path, Style style) {
570570
return std::string(path);
571571

572572
std::string s = path.str();
573-
std::replace(s.begin(), s.end(), '\\', '/');
573+
llvm::replace(s, '\\', '/');
574574
return s;
575575
}
576576

llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static std::string lowerLLVMIntrinsicName(IntrinsicInst *II) {
6767
Function *IntrinsicFunc = II->getCalledFunction();
6868
assert(IntrinsicFunc && "Missing function");
6969
std::string FuncName = IntrinsicFunc->getName().str();
70-
std::replace(FuncName.begin(), FuncName.end(), '.', '_');
70+
llvm::replace(FuncName, '.', '_');
7171
FuncName = "spirv." + FuncName;
7272
return FuncName;
7373
}

llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static std::string getSignature(FunctionType *FTy) {
436436
erase_if(Sig, isSpace);
437437
// When s2wasm parses .s file, a comma means the end of an argument. So a
438438
// mangled function name can contain any character but a comma.
439-
std::replace(Sig.begin(), Sig.end(), ',', '.');
439+
llvm::replace(Sig, ',', '.');
440440
return Sig;
441441
}
442442

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14030,7 +14030,7 @@ static SDValue lowerV8I16GeneralSingleInputShuffle(
1403014030
// a dword. We find the adjacent index by toggling the low bit.
1403114031
int AdjIndex = InPlaceInputs[0] ^ 1;
1403214032
SourceHalfMask[AdjIndex - HalfOffset] = InPlaceInputs[1] - HalfOffset;
14033-
std::replace(HalfMask.begin(), HalfMask.end(), InPlaceInputs[1], AdjIndex);
14033+
llvm::replace(HalfMask, InPlaceInputs[1], AdjIndex);
1403414034
PSHUFDMask[AdjIndex / 2] = AdjIndex / 2;
1403514035
};
1403614036
fixInPlaceInputs(LToLInputs, HToLInputs, PSHUFLMask, LoMask, 0);
@@ -14114,8 +14114,7 @@ static SDValue lowerV8I16GeneralSingleInputShuffle(
1411414114
SourceOffset;
1411514115
SourceHalfMask[InputFixed - SourceOffset] =
1411614116
IncomingInputs[0] - SourceOffset;
14117-
std::replace(HalfMask.begin(), HalfMask.end(), IncomingInputs[0],
14118-
InputFixed);
14117+
llvm::replace(HalfMask, IncomingInputs[0], InputFixed);
1411914118
IncomingInputs[0] = InputFixed;
1412014119
}
1412114120
} else if (IncomingInputs.size() == 2) {

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
997997
/*PredecessorWithTwoSuccessors=*/false,
998998
DTUToUse ? nullptr : DT)) {
999999
// Dest has been folded into Fold. Update our worklists accordingly.
1000-
std::replace(Latches.begin(), Latches.end(), Dest, Fold);
1000+
llvm::replace(Latches, Dest, Fold);
10011001
llvm::erase(UnrolledLoopBlocks, Dest);
10021002
}
10031003
}

llvm/tools/llvm-config/llvm-config.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ static void VisitComponent(const std::string &Name,
142142
if (AC->Library) {
143143
if (Missing && GetComponentLibraryPath) {
144144
std::string path = (*GetComponentLibraryPath)(AC->Library);
145-
if (DirSep == "\\") {
146-
std::replace(path.begin(), path.end(), '/', '\\');
147-
}
145+
if (DirSep == "\\")
146+
llvm::replace(path, '/', '\\');
148147
if (!sys::fs::exists(path))
149148
Missing->push_back(path);
150149
}
@@ -396,13 +395,12 @@ int main(int argc, char **argv) {
396395
} else {
397396
StaticExt = "lib";
398397
DirSep = "\\";
399-
std::replace(ActiveObjRoot.begin(), ActiveObjRoot.end(), '/', '\\');
400-
std::replace(ActivePrefix.begin(), ActivePrefix.end(), '/', '\\');
401-
std::replace(ActiveBinDir.begin(), ActiveBinDir.end(), '/', '\\');
402-
std::replace(ActiveLibDir.begin(), ActiveLibDir.end(), '/', '\\');
403-
std::replace(ActiveCMakeDir.begin(), ActiveCMakeDir.end(), '/', '\\');
404-
std::replace(ActiveIncludeOption.begin(), ActiveIncludeOption.end(), '/',
405-
'\\');
398+
llvm::replace(ActiveObjRoot, '/', '\\');
399+
llvm::replace(ActivePrefix, '/', '\\');
400+
llvm::replace(ActiveBinDir, '/', '\\');
401+
llvm::replace(ActiveLibDir, '/', '\\');
402+
llvm::replace(ActiveCMakeDir, '/', '\\');
403+
llvm::replace(ActiveIncludeOption, '/', '\\');
406404
}
407405
SharedDir = ActiveBinDir;
408406
StaticDir = ActiveLibDir;
@@ -437,9 +435,8 @@ int main(int argc, char **argv) {
437435

438436
if (BuiltDyLib) {
439437
std::string path((SharedDir + DirSep + DyLibName).str());
440-
if (DirSep == "\\") {
441-
std::replace(path.begin(), path.end(), '/', '\\');
442-
}
438+
if (DirSep == "\\")
439+
llvm::replace(path, '/', '\\');
443440
DyLibExists = sys::fs::exists(path);
444441
if (!DyLibExists) {
445442
// The shared library does not exist: don't error unless the user
@@ -554,9 +551,8 @@ int main(int argc, char **argv) {
554551
Components.push_back(AC.Name);
555552
if (AC.Library && !IsInDevelopmentTree) {
556553
std::string path(GetComponentLibraryPath(AC.Library, false));
557-
if (DirSep == "\\") {
558-
std::replace(path.begin(), path.end(), '/', '\\');
559-
}
554+
if (DirSep == "\\")
555+
llvm::replace(path, '/', '\\');
560556
if (DyLibExists && !sys::fs::exists(path)) {
561557
Components =
562558
GetAllDyLibComponents(IsInDevelopmentTree, true, DirSep);

llvm/unittests/IR/DataLayoutTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class DataLayoutPrimitiveSpecificationTest
157157

158158
std::string format(StringRef Str) const {
159159
std::string Res = Str.str();
160-
std::replace(Res.begin(), Res.end(), '!', Specifier);
160+
llvm::replace(Res, '!', Specifier);
161161
return Res;
162162
}
163163
};

llvm/unittests/Support/Path.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,7 @@ TEST_F(FileSystemTest, CreateDir) {
10551055
do {
10561056
LongPathWithUnixSeparators.append("/DirNameWith19Charss");
10571057
} while (LongPathWithUnixSeparators.size() < 260);
1058-
std::replace(LongPathWithUnixSeparators.begin(),
1059-
LongPathWithUnixSeparators.end(),
1060-
'\\', '/');
1058+
llvm::replace(LongPathWithUnixSeparators, '\\', '/');
10611059
ASSERT_NO_ERROR(fs::create_directories(Twine(LongPathWithUnixSeparators)));
10621060
// cleanup
10631061
ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) +
@@ -2442,7 +2440,7 @@ TEST_F(FileSystemTest, widenPath) {
24422440
EXPECT_EQ(Result, Expected);
24432441

24442442
// Check that Unix separators are handled correctly.
2445-
std::replace(Input.begin(), Input.end(), '\\', '/');
2443+
llvm::replace(Input, '\\', '/');
24462444
ASSERT_NO_ERROR(windows::widenPath(Input, Result));
24472445
EXPECT_EQ(Result, Expected);
24482446

0 commit comments

Comments
 (0)