utils: Remove some no-op raw_string_ostream flush calls, NFC

Since 65b13610a5, 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.
This commit is contained in:
Duncan P. N. Exon Smith 2021-12-09 18:57:38 -08:00
parent 04f2712ef4
commit dcd6162b7f
12 changed files with 6 additions and 18 deletions

View File

@ -415,7 +415,6 @@ BuildInputAnnotations(const SourceMgr &SM, unsigned CheckFileBufferID,
"the check file or for an implicit pattern"); "the check file or for an implicit pattern");
if (DiagCountPerPattern[DiagItr->CheckLoc] > 1) if (DiagCountPerPattern[DiagItr->CheckLoc] > 1)
Label << "'" << DiagIndexPerPattern[DiagItr->CheckLoc]++; Label << "'" << DiagIndexPerPattern[DiagItr->CheckLoc]++;
Label.flush();
LabelWidth = std::max((std::string::size_type)LabelWidth, A.Label.size()); LabelWidth = std::max((std::string::size_type)LabelWidth, A.Label.size());
A.Marker = GetMarker(DiagItr->MatchTy); A.Marker = GetMarker(DiagItr->MatchTy);

View File

@ -757,8 +757,6 @@ public:
++I; ++I;
} }
} }
OS.flush();
return OutString; return OutString;
} }

View File

@ -515,7 +515,7 @@ void CodeEmitterGen::run(raw_ostream &o) {
<< " std::string msg;\n" << " std::string msg;\n"
<< " raw_string_ostream Msg(msg);\n" << " raw_string_ostream Msg(msg);\n"
<< " Msg << \"Not supported instr: \" << MI;\n" << " Msg << \"Not supported instr: \" << MI;\n"
<< " report_fatal_error(Msg.str().c_str());\n" << " report_fatal_error(msg.c_str());\n"
<< " }\n"; << " }\n";
if (UseAPInt) if (UseAPInt)
o << " Inst = Value;\n"; o << " Inst = Value;\n";

View File

@ -1583,7 +1583,7 @@ static TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
OS << "Invalid operand number in type constraint " OS << "Invalid operand number in type constraint "
<< (OpNo+NumResults) << " "; << (OpNo+NumResults) << " ";
N->print(OS); N->print(OS);
PrintFatalError(OS.str()); PrintFatalError(S);
} }
return N->getChild(OpNo); return N->getChild(OpNo);

View File

@ -169,7 +169,6 @@ static std::string GetPatFromTreePatternNode(const TreePatternNode *N) {
std::string str; std::string str;
raw_string_ostream Stream(str); raw_string_ostream Stream(str);
Stream << *N; Stream << *N;
Stream.str();
return str; return str;
} }
@ -235,7 +234,6 @@ static std::string getIncludePath(const Record *R) {
Stream << SrcMgr.getBufferInfo(CurBuf).Buffer->getBufferIdentifier() << ":" Stream << SrcMgr.getBufferInfo(CurBuf).Buffer->getBufferIdentifier() << ":"
<< SrcMgr.FindLineNumber(L, CurBuf); << SrcMgr.FindLineNumber(L, CurBuf);
Stream.str();
return str; return str;
} }

View File

@ -267,7 +267,7 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
std::string S; std::string S;
raw_string_ostream OS(S); raw_string_ostream OS(S);
OS << "We expect complex pattern uses to have names: " << *N; 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 // Remember this ComplexPattern so that we can emit it after all the other

View File

@ -568,7 +568,6 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) {
std::string ManglingSuffix; std::string ManglingSuffix;
raw_string_ostream SuffixOS(ManglingSuffix); raw_string_ostream SuffixOS(ManglingSuffix);
Operands.PrintManglingSuffix(SuffixOS, ImmediatePredicates, true); Operands.PrintManglingSuffix(SuffixOS, ImmediatePredicates, true);
SuffixOS.flush();
if (!StringSwitch<bool>(ManglingSuffix) if (!StringSwitch<bool>(ManglingSuffix)
.Cases("", "r", "rr", "ri", "i", "f", true) .Cases("", "r", "rr", "ri", "i", "f", true)
.Default(false)) .Default(false))

View File

@ -633,7 +633,7 @@ void GICombinerEmitter::emitNameMatcher(raw_ostream &OS) const {
raw_string_ostream SS(Code); raw_string_ostream SS(Code);
SS << "return " << EnumeratedRule.getID() << ";\n"; SS << "return " << EnumeratedRule.getID() << ";\n";
Cases.push_back( 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 " OS << "static Optional<uint64_t> getRuleIdxForIdentifier(StringRef "

View File

@ -109,7 +109,7 @@ public:
raw_string_ostream OS(Str); raw_string_ostream OS(Str);
emitCxxEnumValue(OS); emitCxxEnumValue(OS);
return OS.str(); return Str;
} }
void emitCxxEnumValue(raw_ostream &OS) const { void emitCxxEnumValue(raw_ostream &OS) const {
@ -1673,7 +1673,7 @@ public:
CommentOS << "Operand " << OpIdx; CommentOS << "Operand " << OpIdx;
else else
CommentOS << SymbolicName; CommentOS << SymbolicName;
Table << MatchTable::Comment(CommentOS.str()) << MatchTable::LineBreak; Table << MatchTable::Comment(Comment) << MatchTable::LineBreak;
} }
emitPredicateListOpcodes(Table, Rule); emitPredicateListOpcodes(Table, Rule);

View File

@ -233,7 +233,6 @@ void PredicateExpander::expandReturnStatement(raw_ostream &OS,
SS << "return "; SS << "return ";
expandPredicate(SS, Rec); expandPredicate(SS, Rec);
SS << ";"; SS << ";";
SS.flush();
OS << Buffer; OS << Buffer;
} }
@ -276,7 +275,6 @@ void PredicateExpander::expandOpcodeSwitchStatement(raw_ostream &OS,
SS.indent(getIndentLevel() * 2); SS.indent(getIndentLevel() * 2);
SS << "} // end of switch-stmt"; SS << "} // end of switch-stmt";
SS.flush();
OS << Buffer; OS << Buffer;
} }

View File

@ -1433,7 +1433,6 @@ static void emitPredicateProlog(const RecordKeeper &Records, raw_ostream &OS) {
for (Record *P : Prologs) for (Record *P : Prologs)
Stream << P->getValueAsString("Code") << '\n'; Stream << P->getValueAsString("Code") << '\n';
Stream.flush();
OS << Buffer; OS << Buffer;
} }
@ -1492,7 +1491,6 @@ static void emitPredicates(const CodeGenSchedTransition &T,
} }
SS << "return " << T.ToClassIdx << "; // " << SC.Name << '\n'; SS << "return " << T.ToClassIdx << "; // " << SC.Name << '\n';
SS.flush();
OS << Buffer; OS << Buffer;
} }

View File

@ -184,12 +184,10 @@ static std::string createJSONText(size_t MemoryMB, unsigned ValueSize) {
<< " \"key2\": \"" << std::string(ValueSize, '*') << "\",\n" << " \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
<< " \"key3\": \"" << std::string(ValueSize, '*') << "\"\n" << " \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
<< " }"; << " }";
Stream.flush();
if (JSONText.size() < MemoryBytes) Stream << ","; if (JSONText.size() < MemoryBytes) Stream << ",";
Stream << "\n"; Stream << "\n";
} }
Stream << "]\n"; Stream << "]\n";
Stream.flush();
return JSONText; return JSONText;
} }