diff options
author | Youngsuk Kim <joseph942010@gmail.com> | 2024-07-01 21:52:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-01 21:52:37 -0400 |
commit | a95c85fba5fde0db8f128cf5564ac333e2b1f90f (patch) | |
tree | 33e65940496208c76803c15d2d0f38006ee9fcde | |
parent | 9b8c2fae38bcff0b16d996ee002ff1e989fa23ea (diff) | |
download | llvm-a95c85fba5fde0db8f128cf5564ac333e2b1f90f.zip llvm-a95c85fba5fde0db8f128cf5564ac333e2b1f90f.tar.gz llvm-a95c85fba5fde0db8f128cf5564ac333e2b1f90f.tar.bz2 |
[llvm][CodeGen] Avoid 'raw_string_ostream::str' (NFC) (#97318)
Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.
Work towards TODO comment to remove `raw_string_ostream::str()`.
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRPrinter.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineOutliner.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineScheduler.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/ScheduleDAGInstrs.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/TargetInstrInfo.cpp | 4 |
11 files changed, 20 insertions, 21 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 0033f0a..c52cbff 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1128,7 +1128,7 @@ static void emitKill(const MachineInstr *MI, AsmPrinter &AP) { OS << ' ' << (Op.isDef() ? "def " : "killed ") << printReg(Op.getReg(), AP.MF->getSubtarget().getRegisterInfo()); } - AP.OutStreamer->AddComment(OS.str()); + AP.OutStreamer->AddComment(Str); AP.OutStreamer->addBlankLine(); } @@ -1235,7 +1235,7 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) { } // NOTE: Want this comment at start of line, don't emit with AddComment. - AP.OutStreamer->emitRawComment(OS.str()); + AP.OutStreamer->emitRawComment(Str); return true; } @@ -2274,7 +2274,7 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) { OutContext.getObjectFileInfo()->getRemarksSection(); OutStreamer->switchSection(RemarksSection); - OutStreamer->emitBinaryData(OS.str()); + OutStreamer->emitBinaryData(Buf); } bool AsmPrinter::doFinalization(Module &M) { @@ -3282,7 +3282,7 @@ const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) { OS << "Unsupported expression in static initializer: "; CE->printAsOperand(OS, /*PrintType=*/false, !MF ? nullptr : MF->getFunction().getParent()); - report_fatal_error(Twine(OS.str())); + report_fatal_error(Twine(S)); } static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C, diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp index 08e3c20..5a7013c 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -311,7 +311,7 @@ static void EmitInlineAsmStr(const char *AsmStr, const MachineInstr *MI, std::string msg; raw_string_ostream Msg(msg); Msg << "invalid operand in inline asm: '" << AsmStr << "'"; - MMI->getModule()->getContext().emitError(LocCookie, Msg.str()); + MMI->getModule()->getContext().emitError(LocCookie, msg); } } break; @@ -411,7 +411,7 @@ void AsmPrinter::emitInlineAsm(const MachineInstr *MI) const { } } - emitInlineAsm(OS.str(), getSubtargetInfo(), TM.Options.MCOptions, LocMD, + emitInlineAsm(StringData, getSubtargetInfo(), TM.Options.MCOptions, LocMD, MI->getInlineAsmDialect()); // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index 14e6b79..552d4c9 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -3984,7 +3984,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) { raw_string_ostream InstStr(InstStrStorage); InstStr << Inst; - R << ": '" << InstStr.str() << "'"; + R << ": '" << InstStrStorage << "'"; } reportTranslationError(*MF, *TPC, *ORE, R); diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index 49993f7..48c3e0d 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -570,7 +570,7 @@ void MIRPrinter::convertMachineMetadataNodes(yaml::MachineFunction &YMF, std::string NS; raw_string_ostream StrOS(NS); MD.second->print(StrOS, MST, MF.getFunction().getParent()); - YMF.MachineMetadataNodes.push_back(StrOS.str()); + YMF.MachineMetadataNodes.push_back(NS); } } @@ -588,7 +588,7 @@ void MIRPrinter::convert(yaml::MachineFunction &MF, yaml::MachineConstantPoolValue YamlConstant; YamlConstant.ID = ID++; - YamlConstant.Value = StrOS.str(); + YamlConstant.Value = Str; YamlConstant.Alignment = Constant.getAlign(); YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry(); @@ -608,7 +608,7 @@ void MIRPrinter::convert(ModuleSlotTracker &MST, for (const auto *MBB : Table.MBBs) { raw_string_ostream StrOS(Str); StrOS << printMBBReference(*MBB); - Entry.Blocks.push_back(StrOS.str()); + Entry.Blocks.push_back(Str); Str.clear(); } YamlJTI.Entries.push_back(Entry); diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index 76e5952..c7ccf10 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -804,8 +804,7 @@ MachineFunction *MachineOutliner::createOutlinedFunction( Mg.getNameWithPrefix(MangledNameStream, F, false); DISubprogram *OutlinedSP = DB.createFunction( - Unit /* Context */, F->getName(), StringRef(MangledNameStream.str()), - Unit /* File */, + Unit /* Context */, F->getName(), StringRef(Dummy), Unit /* File */, 0 /* Line 0 is reserved for compiler-generated code. */, DB.createSubroutineType( DB.getOrCreateTypeArray(std::nullopt)), /* void type */ diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp index cf72f74..4a6d5ed 100644 --- a/llvm/lib/CodeGen/MachineScheduler.cpp +++ b/llvm/lib/CodeGen/MachineScheduler.cpp @@ -4413,7 +4413,7 @@ struct DOTGraphTraits<ScheduleDAGMI*> : public DefaultDOTGraphTraits { SS << "SU:" << SU->NodeNum; if (DFS) SS << " I:" << DFS->getNumInstrs(SU); - return SS.str(); + return Str; } static std::string getNodeDescription(const SUnit *SU, const ScheduleDAG *G) { diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp index c848ce4..68dece6 100644 --- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp +++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp @@ -1206,7 +1206,7 @@ std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const { oss << "<exit>"; else SU->getInstr()->print(oss, /*IsStandalone=*/true); - return oss.str(); + return s; } /// Return the basic block label. It is not necessarilly unique because a block diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 7429763..bc16f88 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -11749,7 +11749,7 @@ SDValue SelectionDAG::getSymbolFunctionGlobalAddress(SDValue Op, raw_string_ostream ErrorFormatter(ErrorStr); ErrorFormatter << "Undefined external symbol "; ErrorFormatter << '"' << Symbol << '"'; - report_fatal_error(Twine(ErrorFormatter.str())); + report_fatal_error(Twine(ErrorStr)); } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 8ce6dfc..ecdbf3e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1778,7 +1778,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) { raw_string_ostream InstStr(InstStrStorage); InstStr << *Inst; - R << ": " << InstStr.str(); + R << ": " << InstStrStorage; } reportFastISelFailure(*MF, *ORE, R, EnableFastISelAbort > 2); @@ -1827,7 +1827,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) { std::string InstStrStorage; raw_string_ostream InstStr(InstStrStorage); InstStr << *Inst; - R << ": " << InstStr.str(); + R << ": " << InstStrStorage; } reportFastISelFailure(*MF, *ORE, R, ShouldAbort); @@ -4370,5 +4370,5 @@ void SelectionDAGISel::CannotYetSelect(SDNode *N) { else Msg << "unknown intrinsic #" << iid; } - report_fatal_error(Twine(Msg.str())); + report_fatal_error(Twine(msg)); } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index b66eeb6..ac28f62 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -299,7 +299,7 @@ std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const { } else { O << "CROSS RC COPY"; } - return O.str(); + return s; } void ScheduleDAGSDNodes::getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const { diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index e01e7b3..3cd1bb2 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -1750,7 +1750,7 @@ std::string TargetInstrInfo::createMIROperandComment( OS << Info; } - return OS.str(); + return Flags; } int FlagIdx = MI.findInlineAsmFlagIdx(OpIdx); @@ -1784,7 +1784,7 @@ std::string TargetInstrInfo::createMIROperandComment( F.getRegMayBeFolded()) OS << " foldable"; - return OS.str(); + return Flags; } TargetInstrInfo::PipelinerLoopInfo::~PipelinerLoopInfo() = default; |