[llvm] dcd6162 - utils: Remove some no-op raw_string_ostream flush calls, NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 10 11:27:42 PST 2021
Author: Duncan P. N. Exon Smith
Date: 2021-12-10T11:26:08-08:00
New Revision: dcd6162b7fd5108a5fbf2fb29d870cb4255eb9c7
URL: https://github.com/llvm/llvm-project/commit/dcd6162b7fd5108a5fbf2fb29d870cb4255eb9c7
DIFF: https://github.com/llvm/llvm-project/commit/dcd6162b7fd5108a5fbf2fb29d870cb4255eb9c7.diff
LOG: utils: Remove some no-op raw_string_ostream flush calls, NFC
Since 65b13610a5226b84889b923bae884ba395ad084d, raw_string_ostream has
been unbuffered by default. Based on an audit of llvm/utils/, this
commit removes every call to `raw_string_ostream::flush()` and any call
to `raw_string_ostream::str()` whose result is ignored or that doesn't
help with clarity.
I left behind a few calls to `str()`. In these cases, the underlying
std::string was declared pretty far away and never used again, whereas
stream recently had its last write. The code is easier to read as-is;
the no-op call to `flush()` inside `str()` isn't harmful, and when
https://reviews.llvm.org/D115421 lands it'll be gone anyway.
Added:
Modified:
llvm/utils/FileCheck/FileCheck.cpp
llvm/utils/TableGen/AsmWriterEmitter.cpp
llvm/utils/TableGen/CodeEmitterGen.cpp
llvm/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
llvm/utils/TableGen/DAGISelMatcherGen.cpp
llvm/utils/TableGen/FastISelEmitter.cpp
llvm/utils/TableGen/GICombinerEmitter.cpp
llvm/utils/TableGen/GlobalISelEmitter.cpp
llvm/utils/TableGen/PredicateExpander.cpp
llvm/utils/TableGen/SubtargetEmitter.cpp
llvm/utils/yaml-bench/YAMLBench.cpp
Removed:
################################################################################
diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index 4dcc4812502e1..6742853c9b63a 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -415,7 +415,6 @@ BuildInputAnnotations(const SourceMgr &SM, unsigned CheckFileBufferID,
"the check file or for an implicit pattern");
if (DiagCountPerPattern[DiagItr->CheckLoc] > 1)
Label << "'" << DiagIndexPerPattern[DiagItr->CheckLoc]++;
- Label.flush();
LabelWidth = std::max((std::string::size_type)LabelWidth, A.Label.size());
A.Marker = GetMarker(DiagItr->MatchTy);
diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index bb13c4033db7b..9283ceeb31e08 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -757,8 +757,6 @@ class IAPrinter {
++I;
}
}
-
- OS.flush();
return OutString;
}
diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp
index ee77ef5eda5fc..fbac0d969917c 100644
--- a/llvm/utils/TableGen/CodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -515,7 +515,7 @@ void CodeEmitterGen::run(raw_ostream &o) {
<< " std::string msg;\n"
<< " raw_string_ostream Msg(msg);\n"
<< " Msg << \"Not supported instr: \" << MI;\n"
- << " report_fatal_error(Msg.str().c_str());\n"
+ << " report_fatal_error(msg.c_str());\n"
<< " }\n";
if (UseAPInt)
o << " Inst = Value;\n";
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index 5710b76bf69af..4de619df5b5f6 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -1583,7 +1583,7 @@ static TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
OS << "Invalid operand number in type constraint "
<< (OpNo+NumResults) << " ";
N->print(OS);
- PrintFatalError(OS.str());
+ PrintFatalError(S);
}
return N->getChild(OpNo);
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index a552998e4eeef..5b0d16a8f3c80 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -169,7 +169,6 @@ static std::string GetPatFromTreePatternNode(const TreePatternNode *N) {
std::string str;
raw_string_ostream Stream(str);
Stream << *N;
- Stream.str();
return str;
}
@@ -235,7 +234,6 @@ static std::string getIncludePath(const Record *R) {
Stream << SrcMgr.getBufferInfo(CurBuf).Buffer->getBufferIdentifier() << ":"
<< SrcMgr.FindLineNumber(L, CurBuf);
- Stream.str();
return str;
}
diff --git a/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
index 2625595cf9d5f..2361ed8a7a957 100644
--- a/llvm/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
@@ -267,7 +267,7 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
std::string S;
raw_string_ostream OS(S);
OS << "We expect complex pattern uses to have names: " << *N;
- PrintFatalError(OS.str());
+ PrintFatalError(S);
}
// Remember this ComplexPattern so that we can emit it after all the other
diff --git a/llvm/utils/TableGen/FastISelEmitter.cpp b/llvm/utils/TableGen/FastISelEmitter.cpp
index d64262124308a..ac9fe6db43280 100644
--- a/llvm/utils/TableGen/FastISelEmitter.cpp
+++ b/llvm/utils/TableGen/FastISelEmitter.cpp
@@ -568,7 +568,6 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) {
std::string ManglingSuffix;
raw_string_ostream SuffixOS(ManglingSuffix);
Operands.PrintManglingSuffix(SuffixOS, ImmediatePredicates, true);
- SuffixOS.flush();
if (!StringSwitch<bool>(ManglingSuffix)
.Cases("", "r", "rr", "ri", "i", "f", true)
.Default(false))
diff --git a/llvm/utils/TableGen/GICombinerEmitter.cpp b/llvm/utils/TableGen/GICombinerEmitter.cpp
index c03cd371ef9df..63a9ed682d4f6 100644
--- a/llvm/utils/TableGen/GICombinerEmitter.cpp
+++ b/llvm/utils/TableGen/GICombinerEmitter.cpp
@@ -633,7 +633,7 @@ void GICombinerEmitter::emitNameMatcher(raw_ostream &OS) const {
raw_string_ostream SS(Code);
SS << "return " << EnumeratedRule.getID() << ";\n";
Cases.push_back(
- std::make_pair(std::string(EnumeratedRule.getName()), SS.str()));
+ std::make_pair(std::string(EnumeratedRule.getName()), Code));
}
OS << "static Optional<uint64_t> getRuleIdxForIdentifier(StringRef "
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index d08186b7094b2..7b1bd41a951bb 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -109,7 +109,7 @@ class LLTCodeGen {
raw_string_ostream OS(Str);
emitCxxEnumValue(OS);
- return OS.str();
+ return Str;
}
void emitCxxEnumValue(raw_ostream &OS) const {
@@ -1673,7 +1673,7 @@ class OperandMatcher : public PredicateListMatcher<OperandPredicateMatcher> {
CommentOS << "Operand " << OpIdx;
else
CommentOS << SymbolicName;
- Table << MatchTable::Comment(CommentOS.str()) << MatchTable::LineBreak;
+ Table << MatchTable::Comment(Comment) << MatchTable::LineBreak;
}
emitPredicateListOpcodes(Table, Rule);
diff --git a/llvm/utils/TableGen/PredicateExpander.cpp b/llvm/utils/TableGen/PredicateExpander.cpp
index a7256499d5666..b129401461b51 100644
--- a/llvm/utils/TableGen/PredicateExpander.cpp
+++ b/llvm/utils/TableGen/PredicateExpander.cpp
@@ -233,7 +233,6 @@ void PredicateExpander::expandReturnStatement(raw_ostream &OS,
SS << "return ";
expandPredicate(SS, Rec);
SS << ";";
- SS.flush();
OS << Buffer;
}
@@ -276,7 +275,6 @@ void PredicateExpander::expandOpcodeSwitchStatement(raw_ostream &OS,
SS.indent(getIndentLevel() * 2);
SS << "} // end of switch-stmt";
- SS.flush();
OS << Buffer;
}
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index c88fe949c25c1..0deeeeed8e5ab 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -1433,7 +1433,6 @@ static void emitPredicateProlog(const RecordKeeper &Records, raw_ostream &OS) {
for (Record *P : Prologs)
Stream << P->getValueAsString("Code") << '\n';
- Stream.flush();
OS << Buffer;
}
@@ -1492,7 +1491,6 @@ static void emitPredicates(const CodeGenSchedTransition &T,
}
SS << "return " << T.ToClassIdx << "; // " << SC.Name << '\n';
- SS.flush();
OS << Buffer;
}
diff --git a/llvm/utils/yaml-bench/YAMLBench.cpp b/llvm/utils/yaml-bench/YAMLBench.cpp
index a9851c0f63e66..8b4043ef66cbf 100644
--- a/llvm/utils/yaml-bench/YAMLBench.cpp
+++ b/llvm/utils/yaml-bench/YAMLBench.cpp
@@ -184,12 +184,10 @@ static std::string createJSONText(size_t MemoryMB, unsigned ValueSize) {
<< " \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
<< " \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
<< " }";
- Stream.flush();
if (JSONText.size() < MemoryBytes) Stream << ",";
Stream << "\n";
}
Stream << "]\n";
- Stream.flush();
return JSONText;
}
More information about the llvm-commits
mailing list