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");
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);

View File

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

View File

@ -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";

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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))

View File

@ -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 "

View File

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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}