Skip to content

[llvm] Use llvm::replace (NFC) #137481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/TableGen/DirectiveEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BaseRecord {
std::string getFormattedName() const {
StringRef Name = Def->getValueAsString("name");
std::string N = Name.str();
std::replace(N.begin(), N.end(), ' ', '_');
llvm::replace(N, ' ', '_');
return N;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ StringRef CodeViewDebug::getFullFilepath(const DIFile *File) {
// Canonicalize the path. We have to do it textually because we may no longer
// have access the file in the filesystem.
// First, replace all slashes with backslashes.
std::replace(Filepath.begin(), Filepath.end(), '/', '\\');
llvm::replace(Filepath, '/', '\\');

// Remove all "\.\" with "\".
size_t Cursor = 0;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,7 @@ class TransferTracker {
assert(ActiveVLocIt != ActiveVLocs.end());

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

auto &[Var, DILoc] = DVMap.lookupDVID(VarID);
MachineInstr *MI = MTracker->emitLoc(ActiveVLocIt->second.Ops, Var, DILoc,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/LiveVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void LiveVariables::recomputeForSingleDefVirtReg(Register Reg) {
void LiveVariables::replaceKillInstruction(Register Reg, MachineInstr &OldMI,
MachineInstr &NewMI) {
VarInfo &VI = getVarInfo(Reg);
std::replace(VI.Kills.begin(), VI.Kills.end(), &OldMI, &NewMI);
llvm::replace(VI.Kills, &OldMI, &NewMI);
}

/// removeVirtualRegistersKilled - Remove all killed info for the specified
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2713,8 +2713,7 @@ void SelectionDAGISel::UpdateChains(
assert(ChainVal.getValueType() == MVT::Other && "Not a chain?");
SelectionDAG::DAGNodeDeletedListener NDL(
*CurDAG, [&](SDNode *N, SDNode *E) {
std::replace(ChainNodesMatched.begin(), ChainNodesMatched.end(), N,
static_cast<SDNode *>(nullptr));
llvm::replace(ChainNodesMatched, N, static_cast<SDNode *>(nullptr));
});
if (ChainNode->getOpcode() != ISD::TokenFactor)
ReplaceUses(ChainVal, InputChain);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LVStringPool &llvm::logicalview::getStringPool() { return StringPool; }
std::string llvm::logicalview::transformPath(StringRef Path) {
std::string Name(Path);
std::transform(Name.begin(), Name.end(), Name.begin(), tolower);
std::replace(Name.begin(), Name.end(), '\\', '/');
llvm::replace(Name, '\\', '/');

// Remove all duplicate slashes.
size_t Pos = 0;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::string PDBSymbolCompiland::getSourceFileFullPath() const {
auto Len = EnvWorkingDir.length();
if (EnvWorkingDir[Len - 1] != '/' && EnvWorkingDir[Len - 1] != '\\') {
std::string Path = EnvWorkingDir + "\\" + EnvSrc;
std::replace(Path.begin(), Path.end(), '/', '\\');
llvm::replace(Path, '/', '\\');
// We will return it as full path if we can't find a better one.
if (sys::path::is_absolute(Path))
SourceFileFullPath = Path;
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Support/GraphWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ static std::string replaceIllegalFilenameChars(std::string Filename,
std::string IllegalChars =
is_style_windows(sys::path::Style::native) ? "\\/:?\"<>|" : "/";

for (char IllegalChar : IllegalChars) {
std::replace(Filename.begin(), Filename.end(), IllegalChar,
ReplacementChar);
}
for (char IllegalChar : IllegalChars)
llvm::replace(Filename, IllegalChar, ReplacementChar);

return Filename;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ void native(SmallVectorImpl<char> &Path, Style style) {
Path = PathHome;
}
} else {
std::replace(Path.begin(), Path.end(), '\\', '/');
llvm::replace(Path, '\\', '/');
}
}

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

std::string s = path.str();
std::replace(s.begin(), s.end(), '\\', '/');
llvm::replace(s, '\\', '/');
return s;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static std::string lowerLLVMIntrinsicName(IntrinsicInst *II) {
Function *IntrinsicFunc = II->getCalledFunction();
assert(IntrinsicFunc && "Missing function");
std::string FuncName = IntrinsicFunc->getName().str();
std::replace(FuncName.begin(), FuncName.end(), '.', '_');
llvm::replace(FuncName, '.', '_');
FuncName = "spirv." + FuncName;
return FuncName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ static std::string getSignature(FunctionType *FTy) {
erase_if(Sig, isSpace);
// When s2wasm parses .s file, a comma means the end of an argument. So a
// mangled function name can contain any character but a comma.
std::replace(Sig.begin(), Sig.end(), ',', '.');
llvm::replace(Sig, ',', '.');
return Sig;
}

Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14030,7 +14030,7 @@ static SDValue lowerV8I16GeneralSingleInputShuffle(
// a dword. We find the adjacent index by toggling the low bit.
int AdjIndex = InPlaceInputs[0] ^ 1;
SourceHalfMask[AdjIndex - HalfOffset] = InPlaceInputs[1] - HalfOffset;
std::replace(HalfMask.begin(), HalfMask.end(), InPlaceInputs[1], AdjIndex);
llvm::replace(HalfMask, InPlaceInputs[1], AdjIndex);
PSHUFDMask[AdjIndex / 2] = AdjIndex / 2;
};
fixInPlaceInputs(LToLInputs, HToLInputs, PSHUFLMask, LoMask, 0);
Expand Down Expand Up @@ -14114,8 +14114,7 @@ static SDValue lowerV8I16GeneralSingleInputShuffle(
SourceOffset;
SourceHalfMask[InputFixed - SourceOffset] =
IncomingInputs[0] - SourceOffset;
std::replace(HalfMask.begin(), HalfMask.end(), IncomingInputs[0],
InputFixed);
llvm::replace(HalfMask, IncomingInputs[0], InputFixed);
IncomingInputs[0] = InputFixed;
}
} else if (IncomingInputs.size() == 2) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/LoopUnroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
/*PredecessorWithTwoSuccessors=*/false,
DTUToUse ? nullptr : DT)) {
// Dest has been folded into Fold. Update our worklists accordingly.
std::replace(Latches.begin(), Latches.end(), Dest, Fold);
llvm::replace(Latches, Dest, Fold);
llvm::erase(UnrolledLoopBlocks, Dest);
}
}
Expand Down
28 changes: 12 additions & 16 deletions llvm/tools/llvm-config/llvm-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ static void VisitComponent(const std::string &Name,
if (AC->Library) {
if (Missing && GetComponentLibraryPath) {
std::string path = (*GetComponentLibraryPath)(AC->Library);
if (DirSep == "\\") {
std::replace(path.begin(), path.end(), '/', '\\');
}
if (DirSep == "\\")
llvm::replace(path, '/', '\\');
if (!sys::fs::exists(path))
Missing->push_back(path);
}
Expand Down Expand Up @@ -396,13 +395,12 @@ int main(int argc, char **argv) {
} else {
StaticExt = "lib";
DirSep = "\\";
std::replace(ActiveObjRoot.begin(), ActiveObjRoot.end(), '/', '\\');
std::replace(ActivePrefix.begin(), ActivePrefix.end(), '/', '\\');
std::replace(ActiveBinDir.begin(), ActiveBinDir.end(), '/', '\\');
std::replace(ActiveLibDir.begin(), ActiveLibDir.end(), '/', '\\');
std::replace(ActiveCMakeDir.begin(), ActiveCMakeDir.end(), '/', '\\');
std::replace(ActiveIncludeOption.begin(), ActiveIncludeOption.end(), '/',
'\\');
llvm::replace(ActiveObjRoot, '/', '\\');
llvm::replace(ActivePrefix, '/', '\\');
llvm::replace(ActiveBinDir, '/', '\\');
llvm::replace(ActiveLibDir, '/', '\\');
llvm::replace(ActiveCMakeDir, '/', '\\');
llvm::replace(ActiveIncludeOption, '/', '\\');
}
SharedDir = ActiveBinDir;
StaticDir = ActiveLibDir;
Expand Down Expand Up @@ -437,9 +435,8 @@ int main(int argc, char **argv) {

if (BuiltDyLib) {
std::string path((SharedDir + DirSep + DyLibName).str());
if (DirSep == "\\") {
std::replace(path.begin(), path.end(), '/', '\\');
}
if (DirSep == "\\")
llvm::replace(path, '/', '\\');
DyLibExists = sys::fs::exists(path);
if (!DyLibExists) {
// The shared library does not exist: don't error unless the user
Expand Down Expand Up @@ -554,9 +551,8 @@ int main(int argc, char **argv) {
Components.push_back(AC.Name);
if (AC.Library && !IsInDevelopmentTree) {
std::string path(GetComponentLibraryPath(AC.Library, false));
if (DirSep == "\\") {
std::replace(path.begin(), path.end(), '/', '\\');
}
if (DirSep == "\\")
llvm::replace(path, '/', '\\');
if (DyLibExists && !sys::fs::exists(path)) {
Components =
GetAllDyLibComponents(IsInDevelopmentTree, true, DirSep);
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/IR/DataLayoutTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class DataLayoutPrimitiveSpecificationTest

std::string format(StringRef Str) const {
std::string Res = Str.str();
std::replace(Res.begin(), Res.end(), '!', Specifier);
llvm::replace(Res, '!', Specifier);
return Res;
}
};
Expand Down
6 changes: 2 additions & 4 deletions llvm/unittests/Support/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,7 @@ TEST_F(FileSystemTest, CreateDir) {
do {
LongPathWithUnixSeparators.append("/DirNameWith19Charss");
} while (LongPathWithUnixSeparators.size() < 260);
std::replace(LongPathWithUnixSeparators.begin(),
LongPathWithUnixSeparators.end(),
'\\', '/');
llvm::replace(LongPathWithUnixSeparators, '\\', '/');
ASSERT_NO_ERROR(fs::create_directories(Twine(LongPathWithUnixSeparators)));
// cleanup
ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) +
Expand Down Expand Up @@ -2442,7 +2440,7 @@ TEST_F(FileSystemTest, widenPath) {
EXPECT_EQ(Result, Expected);

// Check that Unix separators are handled correctly.
std::replace(Input.begin(), Input.end(), '\\', '/');
llvm::replace(Input, '\\', '/');
ASSERT_NO_ERROR(windows::widenPath(Input, Result));
EXPECT_EQ(Result, Expected);

Expand Down
Loading