summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/Analysis.cpp5
-rw-r--r--llvm/lib/Analysis/BlockFrequencyInfo.cpp7
-rw-r--r--llvm/lib/Analysis/Lint.cpp7
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp7
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp3
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp12
-rw-r--r--llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp7
-rw-r--r--llvm/lib/CodeGen/MachineBlockPlacement.cpp12
-rw-r--r--llvm/lib/CodeGen/MachineFunction.cpp5
-rw-r--r--llvm/lib/CodeGen/MachineScheduler.cpp3
-rw-r--r--llvm/lib/CodeGen/ScheduleDAGInstrs.cpp3
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp3
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp3
-rw-r--r--llvm/lib/CodeGen/TargetSchedule.cpp9
-rw-r--r--llvm/lib/DebugInfo/DWARFDebugFrame.cpp7
-rw-r--r--llvm/lib/IR/Core.cpp37
-rw-r--r--llvm/lib/IR/DataLayout.cpp3
-rw-r--r--llvm/lib/IR/LLVMContext.cpp15
-rw-r--r--llvm/lib/IRReader/IRReader.cpp8
-rw-r--r--llvm/lib/LTO/LTOCodeGenerator.cpp11
-rw-r--r--llvm/lib/MC/MCAsmStreamer.cpp7
-rw-r--r--llvm/lib/MC/MCContext.cpp14
-rw-r--r--llvm/lib/MC/MCDisassembler/Disassembler.cpp8
-rw-r--r--llvm/lib/MC/MCDwarf.cpp6
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp6
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp7
-rw-r--r--llvm/lib/Option/Arg.cpp6
-rw-r--r--llvm/lib/Support/CommandLine.cpp34
-rw-r--r--llvm/lib/Support/raw_ostream.cpp4
-rw-r--r--llvm/lib/TableGen/SetTheory.cpp11
-rw-r--r--llvm/lib/TableGen/TGParser.cpp3
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp3
-rw-r--r--llvm/lib/Target/TargetMachineC.cpp12
-rw-r--r--llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp3
-rw-r--r--llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp3
-rw-r--r--llvm/lib/Target/X86/X86AsmPrinter.cpp6
-rw-r--r--llvm/lib/Target/XCore/XCoreAsmPrinter.cpp3
-rw-r--r--llvm/lib/Transforms/Instrumentation/DebugIR.cpp10
-rw-r--r--llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp15
-rw-r--r--llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp3
-rw-r--r--llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp9
-rw-r--r--llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp3
-rw-r--r--llvm/lib/Transforms/Vectorize/LoopVectorize.cpp36
43 files changed, 155 insertions, 224 deletions
diff --git a/llvm/lib/Analysis/Analysis.cpp b/llvm/lib/Analysis/Analysis.cpp
index ade940a7d30..7b6397679d7 100644
--- a/llvm/lib/Analysis/Analysis.cpp
+++ b/llvm/lib/Analysis/Analysis.cpp
@@ -75,8 +75,7 @@ void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
char **OutMessages) {
raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
- std::string Messages;
- raw_string_ostream MsgsOS(Messages);
+ string_ostream MsgsOS;
LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
@@ -88,7 +87,7 @@ LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
report_fatal_error("Broken module found, compilation aborted!");
if (OutMessages)
- *OutMessages = strdup(MsgsOS.str().c_str());
+ *OutMessages = strndup(MsgsOS.str().data(), MsgsOS.str().size());
return Result;
}
diff --git a/llvm/lib/Analysis/BlockFrequencyInfo.cpp b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
index 8ed8e3e4c2e..7e702c31435 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfo.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
@@ -82,10 +82,9 @@ struct DOTGraphTraits<BlockFrequencyInfo*> : public DefaultDOTGraphTraits {
std::string getNodeLabel(const BasicBlock *Node,
const BlockFrequencyInfo *Graph) {
- std::string Result;
- raw_string_ostream OS(Result);
+ string_ostream OS;
- OS << Node->getName().str() << ":";
+ OS << Node->getName() << ":";
switch (ViewBlockFreqPropagationDAG) {
case GVDT_Fraction:
Graph->printBlockFreq(OS, Node);
@@ -98,7 +97,7 @@ struct DOTGraphTraits<BlockFrequencyInfo*> : public DefaultDOTGraphTraits {
"never reach this point.");
}
- return Result;
+ return OS.str();
}
};
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index b14f3292e90..806a1fdee5b 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -105,11 +105,10 @@ namespace {
const DataLayout *DL;
TargetLibraryInfo *TLI;
- std::string Messages;
- raw_string_ostream MessagesStr;
+ string_ostream MessagesStr;
static char ID; // Pass identification, replacement for typeid
- Lint() : FunctionPass(ID), MessagesStr(Messages) {
+ Lint() : FunctionPass(ID) {
initializeLintPass(*PassRegistry::getPassRegistry());
}
@@ -181,7 +180,7 @@ bool Lint::runOnFunction(Function &F) {
TLI = &getAnalysis<TargetLibraryInfo>();
visit(F);
dbgs() << MessagesStr.str();
- Messages.clear();
+ MessagesStr.clear();
return false;
}
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index f4442068520..840f764d3ad 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -28,10 +28,9 @@
using namespace llvm;
static std::string getTypeString(Type *T) {
- std::string Result;
- raw_string_ostream Tmp(Result);
- Tmp << *T;
- return Tmp.str();
+ string_ostream Result;
+ Result << *T;
+ return Result.str();
}
/// Run: module ::= toplevelentity*
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 799ee92d3ad..ebb49c34a73 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1585,8 +1585,7 @@ static const MCExpr *lowerConstant(const Constant *CV, AsmPrinter &AP) {
// Otherwise report the problem to the user.
{
- std::string S;
- raw_string_ostream OS(S);
+ string_ostream OS;
OS << "Unsupported expression in static initializer: ";
CE->printAsOperand(OS, /*PrintType=*/false,
!AP.MF ? nullptr : AP.MF->getFunction()->getParent());
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index 46ee0c856bd..01f26d0c4ce 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -241,8 +241,7 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
}
}
if (Error) {
- std::string msg;
- raw_string_ostream Msg(msg);
+ string_ostream Msg;
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
@@ -413,8 +412,7 @@ static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
}
}
if (Error) {
- std::string msg;
- raw_string_ostream Msg(msg);
+ string_ostream Msg;
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
@@ -471,8 +469,7 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
// Emit the inline asm to a temporary string so we can emit it through
// EmitInlineAsm.
- SmallString<256> StringData;
- raw_svector_ostream OS(StringData);
+ small_string_ostream<256> OS;
// The variant of the current asmprinter.
int AsmPrinterVariant = MAI->getAssemblerDialect();
@@ -517,8 +514,7 @@ void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
}
OS << Counter;
} else {
- std::string msg;
- raw_string_ostream Msg(msg);
+ string_ostream Msg;
Msg << "Unknown special formatter '" << Code
<< "' for machine instr: " << *MI;
report_fatal_error(Msg.str());
diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
index 9151d99089d..35e4a56cec4 100644
--- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
+++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
@@ -89,10 +89,9 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo*> :
std::string getNodeLabel(const MachineBasicBlock *Node,
const MachineBlockFrequencyInfo *Graph) {
- std::string Result;
- raw_string_ostream OS(Result);
+ string_ostream OS;
- OS << Node->getName().str() << ":";
+ OS << Node->getName() << ":";
switch (ViewMachineBlockFreqPropagationDAG) {
case GVDT_Fraction:
Graph->printBlockFreq(OS, Node);
@@ -105,7 +104,7 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo*> :
"never reach this point.");
}
- return Result;
+ return OS.str();
}
};
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 74af1e2d64b..891f605e2a1 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -264,23 +264,19 @@ INITIALIZE_PASS_END(MachineBlockPlacement, "block-placement2",
///
/// Only used by debug logging.
static std::string getBlockName(MachineBasicBlock *BB) {
- std::string Result;
- raw_string_ostream OS(Result);
+ string_ostream OS;
OS << "BB#" << BB->getNumber()
<< " (derived from LLVM BB '" << BB->getName() << "')";
- OS.flush();
- return Result;
+ return OS.str();
}
/// \brief Helper to print the number of a MBB.
///
/// Only used by debug logging.
static std::string getBlockNum(MachineBasicBlock *BB) {
- std::string Result;
- raw_string_ostream OS(Result);
+ string_ostream OS;
OS << "BB#" << BB->getNumber();
- OS.flush();
- return Result;
+ return OS.str();
}
#endif
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index 6138aef4adc..20210adf30f 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -465,9 +465,8 @@ MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
const char *Prefix = isLinkerPrivate ? DL->getLinkerPrivateGlobalPrefix() :
DL->getPrivateGlobalPrefix();
- SmallString<60> Name;
- raw_svector_ostream(Name)
- << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
+ small_string_ostream<60> Name;
+ Name << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
return Ctx.GetOrCreateSymbol(Name.str());
}
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 0baf2a6c1c2..f7459bbf6fc 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -3235,8 +3235,7 @@ struct DOTGraphTraits<ScheduleDAGMI*> : public DefaultDOTGraphTraits {
}
static std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *G) {
- std::string Str;
- raw_string_ostream SS(Str);
+ string_ostream SS;
const ScheduleDAGMI *DAG = static_cast<const ScheduleDAGMI*>(G);
const SchedDFSResult *DFS = DAG->hasVRegLiveness() ?
static_cast<const ScheduleDAGMILive*>(G)->getDFSResult() : nullptr;
diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
index 92a9a30f24c..baf4af6abaa 100644
--- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
+++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
@@ -1197,8 +1197,7 @@ void ScheduleDAGInstrs::dumpNode(const SUnit *SU) const {
}
std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
- std::string s;
- raw_string_ostream oss(s);
+ string_ostream oss;
if (SU == &EntrySU)
oss << "<entry>";
else if (SU == &ExitSU)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 57e22e21c37..a2cc2908167 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -3245,8 +3245,7 @@ SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
void SelectionDAGISel::CannotYetSelect(SDNode *N) {
- std::string msg;
- raw_string_ostream Msg(msg);
+ string_ostream Msg;
Msg << "Cannot select: ";
if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
index 4df5ede388f..680a7ec5dda 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
@@ -268,8 +268,7 @@ void SelectionDAG::setSubgraphColor(SDNode *N, const char *Color) {
}
std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
- std::string s;
- raw_string_ostream O(s);
+ string_ostream O;
O << "SU(" << SU->NodeNum << "): ";
if (SU->getNode()) {
SmallVector<SDNode *, 4> GluedNodes;
diff --git a/llvm/lib/CodeGen/TargetSchedule.cpp b/llvm/lib/CodeGen/TargetSchedule.cpp
index b0f2ca68884..d18a514a85e 100644
--- a/llvm/lib/CodeGen/TargetSchedule.cpp
+++ b/llvm/lib/CodeGen/TargetSchedule.cpp
@@ -212,11 +212,10 @@ unsigned TargetSchedModel::computeOperandLatency(
if (SCDesc->isValid() && !DefMI->getOperand(DefOperIdx).isImplicit()
&& !DefMI->getDesc().OpInfo[DefOperIdx].isOptionalDef()
&& SchedModel.isComplete()) {
- std::string Err;
- raw_string_ostream ss(Err);
- ss << "DefIdx " << DefIdx << " exceeds machine model writes for "
- << *DefMI;
- report_fatal_error(ss.str());
+ string_ostream Err;
+ Err << "DefIdx " << DefIdx << " exceeds machine model writes for "
+ << *DefMI;
+ report_fatal_error(Err.str());
}
#endif
// FIXME: Automatically giving all implicit defs defaultDefLatency is
diff --git a/llvm/lib/DebugInfo/DWARFDebugFrame.cpp b/llvm/lib/DebugInfo/DWARFDebugFrame.cpp
index a33548e95b0..2227260bb0d 100644
--- a/llvm/lib/DebugInfo/DWARFDebugFrame.cpp
+++ b/llvm/lib/DebugInfo/DWARFDebugFrame.cpp
@@ -353,10 +353,9 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
Entries.back()->parseInstructions(Data, &Offset, EndStructureOffset);
if (Offset != EndStructureOffset) {
- std::string Str;
- raw_string_ostream OS(Str);
- OS << format("Parsing entry instructions at %lx failed", StartOffset);
- report_fatal_error(Str);
+ string_ostream Str;
+ Str << format("Parsing entry instructions at %lx failed", StartOffset);
+ report_fatal_error(Str.str());
}
}
}
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 2c49d5b949c..bf936d6dc7e 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -62,6 +62,11 @@ void LLVMShutdown() {
/*===-- Error handling ----------------------------------------------------===*/
+static char *LLVMCreateMessage(StringRef Message) {
+ assert(Message.find('\0') == Message.npos);
+ return strndup(Message.data(), Message.size());
+}
+
char *LLVMCreateMessage(const char *Message) {
return strdup(Message);
}
@@ -110,14 +115,10 @@ unsigned LLVMGetMDKindID(const char* Name, unsigned SLen) {
}
char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
- std::string MsgStorage;
- raw_string_ostream Stream(MsgStorage);
- DiagnosticPrinterRawOStream DP(Stream);
-
+ string_ostream Msg;
+ DiagnosticPrinterRawOStream DP(Msg);
unwrap(DI)->print(DP);
- Stream.flush();
-
- return LLVMCreateMessage(MsgStorage.c_str());
+ return LLVMCreateMessage(Msg.str());
}
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
@@ -201,13 +202,9 @@ LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
}
char *LLVMPrintModuleToString(LLVMModuleRef M) {
- std::string buf;
- raw_string_ostream os(buf);
-
+ string_ostream os;
unwrap(M)->print(os, nullptr);
- os.flush();
-
- return strdup(buf.c_str());
+ return LLVMCreateMessage(os.str());
}
/*--.. Operations on inline assembler ......................................--*/
@@ -278,17 +275,14 @@ void LLVMDumpType(LLVMTypeRef Ty) {
}
char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
- std::string buf;
- raw_string_ostream os(buf);
+ string_ostream os;
if (unwrap(Ty))
unwrap(Ty)->print(os);
else
os << "Printing <null> Type";
- os.flush();
-
- return strdup(buf.c_str());
+ return strndup(os.str().data(), os.str().size());
}
/*--.. Operations on integer types .........................................--*/
@@ -532,17 +526,14 @@ void LLVMDumpValue(LLVMValueRef Val) {
}
char* LLVMPrintValueToString(LLVMValueRef Val) {
- std::string buf;
- raw_string_ostream os(buf);
+ string_ostream os;
if (unwrap(Val))
unwrap(Val)->print(os);
else
os << "Printing <null> Value";
- os.flush();
-
- return strdup(buf.c_str());
+ return strndup(os.str().data(), os.str().size());
}
void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index dea05fbef4a..3aa775097df 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -519,8 +519,7 @@ const StructLayout *DataLayout::getStructLayout(StructType *Ty) const {
}
std::string DataLayout::getStringRepresentation() const {
- std::string Result;
- raw_string_ostream OS(Result);
+ string_ostream OS;
OS << (LittleEndian ? "e" : "E");
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index de825f00b20..201b278285c 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -164,23 +164,22 @@ void LLVMContext::diagnose(const DiagnosticInfo &DI) {
}
// Otherwise, print the message with a prefix based on the severity.
- std::string MsgStorage;
- raw_string_ostream Stream(MsgStorage);
- DiagnosticPrinterRawOStream DP(Stream);
+ string_ostream Msg;
+ DiagnosticPrinterRawOStream DP(Msg);
DI.print(DP);
- Stream.flush();
+
switch (DI.getSeverity()) {
case DS_Error:
- errs() << "error: " << MsgStorage << "\n";
+ errs() << "error: " << Msg.str() << "\n";
exit(1);
case DS_Warning:
- errs() << "warning: " << MsgStorage << "\n";
+ errs() << "warning: " << Msg.str() << "\n";
break;
case DS_Remark:
- errs() << "remark: " << MsgStorage << "\n";
+ errs() << "remark: " << Msg.str() << "\n";
break;
case DS_Note:
- errs() << "note: " << MsgStorage << "\n";
+ errs() << "note: " << Msg.str() << "\n";
break;
}
}
diff --git a/llvm/lib/IRReader/IRReader.cpp b/llvm/lib/IRReader/IRReader.cpp
index 01aa074abad..6d389d4dc45 100644
--- a/llvm/lib/IRReader/IRReader.cpp
+++ b/llvm/lib/IRReader/IRReader.cpp
@@ -108,13 +108,9 @@ LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
if(!*OutM) {
if (OutMessage) {
- std::string buf;
- raw_string_ostream os(buf);
-
+ string_ostream os;
Diag.print(nullptr, os, false);
- os.flush();
-
- *OutMessage = strdup(buf.c_str());
+ *OutMessage = strndup(os.str().data(), os.str().size());
}
return 1;
}
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index a1709f60fff..d87299b5c78 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -549,16 +549,17 @@ void LTOCodeGenerator::DiagnosticHandler2(const DiagnosticInfo &DI) {
break;
}
// Create the string that will be reported to the external diagnostic handler.
- std::string MsgStorage;
- raw_string_ostream Stream(MsgStorage);
- DiagnosticPrinterRawOStream DP(Stream);
+ string_ostream Msg;
+ DiagnosticPrinterRawOStream DP(Msg);
DI.print(DP);
- Stream.flush();
+
+ // Null-terminate the C string.
+ Msg << '\0';
// If this method has been called it means someone has set up an external
// diagnostic handler. Assert on that.
assert(DiagHandler && "Invalid diagnostic handler");
- (*DiagHandler)(Severity, MsgStorage.c_str(), DiagContext);
+ (*DiagHandler)(Severity, Msg.str().data(), DiagContext);
}
void
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index da235ec1d33..a3a81a6bc71 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -1175,9 +1175,10 @@ void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
raw_ostream &OS = GetCommentOS();
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
- raw_svector_ostream VecOS(Code);
- Emitter->EncodeInstruction(Inst, VecOS, Fixups, STI);
- VecOS.flush();
+ {
+ raw_svector_ostream VecOS(Code);
+ Emitter->EncodeInstruction(Inst, VecOS, Fixups, STI);
+ }
// If we are showing fixups, create symbolic markers in the encoded
// representation. We do this by making a per-bit map to the fixup item index,
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index bd2c4e960ac..3a8cfaa947a 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -140,17 +140,15 @@ MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
}
MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() {
- SmallString<128> NameSV;
- raw_svector_ostream(NameSV)
- << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
- return CreateSymbol(NameSV);
+ small_string_ostream<128> NameSV;
+ NameSV << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
+ return CreateSymbol(NameSV.str());
}
MCSymbol *MCContext::CreateTempSymbol() {
- SmallString<128> NameSV;
- raw_svector_ostream(NameSV)
- << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
- return CreateSymbol(NameSV);
+ small_string_ostream<128> NameSV;
+ NameSV << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
+ return CreateSymbol(NameSV.str());
}
unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
diff --git a/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/llvm/lib/MC/MCDisassembler/Disassembler.cpp
index 0530c26369c..e3ec4eb30db 100644
--- a/llvm/lib/MC/MCDisassembler/Disassembler.cpp
+++ b/llvm/lib/MC/MCDisassembler/Disassembler.cpp
@@ -270,8 +270,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
const MCDisassembler *DisAsm = DC->getDisAsm();
MCInstPrinter *IP = DC->getIP();
MCDisassembler::DecodeStatus S;
- SmallVector<char, 64> InsnStr;
- raw_svector_ostream Annotations(InsnStr);
+ small_string_ostream<64> Annotations;
S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC,
/*REMOVE*/ nulls(), Annotations);
switch (S) {
@@ -281,13 +280,10 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
return 0;
case MCDisassembler::Success: {
- Annotations.flush();
- StringRef AnnotationsStr = Annotations.str();
-
SmallVector<char, 64> InsnStr;
raw_svector_ostream OS(InsnStr);
formatted_raw_ostream FormattedOS(OS);
- IP->printInst(&Inst, FormattedOS, AnnotationsStr);
+ IP->printInst(&Inst, FormattedOS, Annotations.str());
if (DC->getOptions() & LLVMDisassembler_Option_PrintLatency)
emitLatency(DC, Inst);
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index bddbf578d80..eab4d88f253 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -420,8 +420,7 @@ unsigned MCDwarfLineTableHeader::getFile(StringRef &Directory,
void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
uint64_t AddrDelta) {
MCContext &Context = MCOS->getContext();
- SmallString<256> Tmp;
- raw_svector_ostream OS(Tmp);
+ small_string_ostream<256> OS;
MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OS);
MCOS->EmitBytes(OS.str());
}
@@ -1647,8 +1646,7 @@ void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,
uint64_t AddrDelta) {
MCContext &Context = Streamer.getContext();
- SmallString<256> Tmp;
- raw_svector_ostream OS(Tmp);
+ small_string_ostream<256> OS;
MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
Streamer.EmitBytes(OS.str());
}
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index fa5dfdc9fed..7bfbbf4932b 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -4580,8 +4580,7 @@ bool AsmParser::parseMSInlineAsm(
}
// Build the IR assembly string.
- std::string AsmStringIR;
- raw_string_ostream OS(AsmStringIR);
+ string_ostream OS;
const char *AsmStart = SrcMgr.getMemoryBuffer(0)->getBufferStart();
const char *AsmEnd = SrcMgr.getMemoryBuffer(0)->getBufferEnd();
array_pod_sort(AsmStrRewrites.begin(), AsmStrRewrites.end(), rewritesSort);
@@ -4646,8 +4645,7 @@ bool AsmParser::parseMSInlineAsm(
}
case AOK_DotOperator:
// Insert the dot if the user omitted it.
- OS.flush();
- if (AsmStringIR.back() != '.')
+ if (OS.str().back() != '.')
OS << '.';
OS << AR.Val;
break;
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index dbfc07270a6..2511a4a3faa 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -301,7 +301,7 @@ static unsigned getCPUType(const MachOObjectFile *O) {
static void printRelocationTargetName(const MachOObjectFile *O,
const MachO::any_relocation_info &RE,
- raw_string_ostream &fmt) {
+ raw_ostream &fmt) {
bool IsScattered = O->isRelocationScattered(RE);
// Target of a scattered relocation is an address. In the interest of
@@ -1010,8 +1010,7 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
unsigned Arch = this->getArch();
- std::string fmtbuf;
- raw_string_ostream fmt(fmtbuf);
+ string_ostream fmt;
unsigned Type = this->getAnyRelocationType(RE);
bool IsPCRel = this->getAnyRelocationPCRel(RE);
@@ -1174,7 +1173,7 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
} else
printRelocationTargetName(this, RE, fmt);
- fmt.flush();
+ StringRef fmtbuf = fmt.str();
Result.append(fmtbuf.begin(), fmtbuf.end());
return object_error::success;
}
diff --git a/llvm/lib/Option/Arg.cpp b/llvm/lib/Option/Arg.cpp
index 4c8da58f536..30a69229737 100644
--- a/llvm/lib/Option/Arg.cpp
+++ b/llvm/lib/Option/Arg.cpp
@@ -62,8 +62,7 @@ void Arg::dump() const {
}
std::string Arg::getAsString(const ArgList &Args) const {
- SmallString<256> Res;
- llvm::raw_svector_ostream OS(Res);
+ small_string_ostream<256> OS;
ArgStringList ASL;
render(Args, ASL);
@@ -95,8 +94,7 @@ void Arg::render(const ArgList &Args, ArgStringList &Output) const {
break;
case Option::RenderCommaJoinedStyle: {
- SmallString<256> Res;
- llvm::raw_svector_ostream OS(Res);
+ small_string_ostream<256> OS;
OS << getSpelling();
for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
if (i) OS << ',';
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index c2b739fa736..e28e1d17638 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1342,25 +1342,21 @@ printGenericOptionDiff(const Option &O, const GenericOptionValue &Value,
// printOptionDiff - Specializations for printing basic value types.
//
-#define PRINT_OPT_DIFF(T) \
- void parser<T>:: \
- printOptionDiff(const Option &O, T V, OptionValue<T> D, \
- size_t GlobalWidth) const { \
- printOptionName(O, GlobalWidth); \
- std::string Str; \
- { \
- raw_string_ostream SS(Str); \
- SS << V; \
- } \
- outs() << "= " << Str; \
- size_t NumSpaces = MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0;\
- outs().indent(NumSpaces) << " (default: "; \
- if (D.hasValue()) \
- outs() << D.getValue(); \
- else \
- outs() << "*no default*"; \
- outs() << ")\n"; \
- } \
+#define PRINT_OPT_DIFF(T) \
+ void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
+ size_t GlobalWidth) const { \
+ printOptionName(O, GlobalWidth); \
+ string_ostream SS; \
+ SS << V; \
+ outs() << "= " << SS.str(); \
+ size_t NumSpaces = MaxOptWidth > SS.tell() ? MaxOptWidth - SS.tell() : 0; \
+ outs().indent(NumSpaces) << " (default: "; \
+ if (D.hasValue()) \
+ outs() << D.getValue(); \
+ else \
+ outs() << "*no default*"; \
+ outs() << ")\n"; \
+ }
PRINT_OPT_DIFF(bool)
PRINT_OPT_DIFF(boolOrDefault)
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index f7c213ac2b8..b3f3056ba6b 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -704,6 +704,10 @@ void raw_string_ostream::write_impl(const char *Ptr, size_t Size) {
// and we only need to set the vector size when the data is flushed.
raw_svector_ostream::raw_svector_ostream(SmallVectorImpl<char> &O) : OS(O) {
+ init();
+}
+
+void raw_svector_ostream::init() {
// Set up the initial external buffer. We make sure that the buffer has at
// least 128 bytes free; raw_ostream itself only requires 64, but we want to
// make sure that we don't grow the buffer unnecessarily on destruction (when
diff --git a/llvm/lib/TableGen/SetTheory.cpp b/llvm/lib/TableGen/SetTheory.cpp
index c99c2bab45a..594d4d9a942 100644
--- a/llvm/lib/TableGen/SetTheory.cpp
+++ b/llvm/lib/TableGen/SetTheory.cpp
@@ -209,13 +209,12 @@ struct SequenceOp : public SetTheory::Operator {
break;
else if (Step < 0 && From < To)
break;
- std::string Name;
- raw_string_ostream OS(Name);
- OS << format(Format.c_str(), unsigned(From));
- Record *Rec = Records.getDef(OS.str());
+ string_ostream Name;
+ Name << format(Format.c_str(), unsigned(From));
+ Record *Rec = Records.getDef(Name.str());
if (!Rec)
- PrintFatalError(Loc, "No def named '" + Name + "': " +
- Expr->getAsString());
+ PrintFatalError(Loc, "No def named '" + Name.str() + "': " +
+ Expr->getAsString());
// Try to reevaluate Rec in case it is a set.
if (const RecVec *Result = ST.expand(Rec))
Elts.insert(Result->begin(), Result->end());
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 0550692ebce..76ef696c68c 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -1307,8 +1307,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
if (ItemType) {
ListRecTy *ListType = dyn_cast<ListRecTy>(ItemType);
if (!ListType) {
- std::string s;
- raw_string_ostream ss(s);
+ string_ostream ss;
ss << "Type mismatch for list, expected list type, got "
<< ItemType->getAsString();
TokError(ss.str());
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index 195b3c0fe9e..eee2f9264fc 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -146,8 +146,7 @@ const MCExpr *nvptx::LowerConstant(const Constant *CV, AsmPrinter &AP) {
// Otherwise report the problem to the user.
{
- std::string S;
- raw_string_ostream OS(S);
+ string_ostream OS;
OS << "Unsupported expression in static initializer: ";
CE->printAsOperand(OS, /*PrintType=*/ false,
!AP.MF ? nullptr : AP.MF->getFunction()->getParent());
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index 20923c97ec8..0b0a09a0ad7 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -237,15 +237,13 @@ LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T,
LLVMModuleRef M, LLVMCodeGenFileType codegen, char** ErrorMessage,
LLVMMemoryBufferRef *OutMemBuf) {
- std::string CodeString;
- raw_string_ostream OStream(CodeString);
- formatted_raw_ostream Out(OStream);
+ string_ostream Code;
+ formatted_raw_ostream Out(Code);
bool Result = LLVMTargetMachineEmit(T, M, Out, codegen, ErrorMessage);
- OStream.flush();
- std::string &Data = OStream.str();
- *OutMemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(Data.c_str(),
- Data.length(), "");
+ StringRef Buffer = Code.str();
+ *OutMemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(Buffer.data(),
+ Buffer.size(), "");
return Result;
}
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 3e57914f9e9..7e04608d991 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -2412,8 +2412,7 @@ bool X86AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
- SmallString<126> Msg;
- raw_svector_ostream OS(Msg);
+ small_string_ostream<128> OS;
OS << "ambiguous instructions require an explicit suffix (could be ";
for (unsigned i = 0; i != NumMatches; ++i) {
if (i != 0)
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 78403424da6..3f9eb07d83d 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -281,8 +281,7 @@ void X86AsmBackend::relaxInstruction(const MCInst &Inst, MCInst &Res) const {
unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode());
if (RelaxedOp == Inst.getOpcode()) {
- SmallString<256> Tmp;
- raw_svector_ostream OS(Tmp);
+ small_string_ostream<256> OS;
Inst.dump_pretty(OS);
OS << "\n";
report_fatal_error("unexpected instruction to relax: " + OS.str());
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 1dca5689ade..cdfff821431 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -550,8 +550,7 @@ emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
}
void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
- SmallString<128> Directive;
- raw_svector_ostream OS(Directive);
+ small_string_ostream<128> OS;
StringRef Name = Sym->getName();
if (Subtarget->isTargetKnownWindowsMSVC())
@@ -572,8 +571,7 @@ void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
OS << ",data";
}
- OS.flush();
- OutStreamer.EmitBytes(Directive);
+ OutStreamer.EmitBytes(OS.str());
}
void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
diff --git a/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp b/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp
index e98d4f933df..7b5da334965 100644
--- a/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp
+++ b/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp
@@ -267,8 +267,7 @@ PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
}
void XCoreAsmPrinter::EmitInstruction(const MachineInstr *MI) {
- SmallString<128> Str;
- raw_svector_ostream O(Str);
+ small_string_ostream<128> O;
switch (MI->getOpcode()) {
case XCore::DBG_VALUE:
diff --git a/llvm/lib/Transforms/Instrumentation/DebugIR.cpp b/llvm/lib/Transforms/Instrumentation/DebugIR.cpp
index f2f1738808b..56e60e69849 100644
--- a/llvm/lib/Transforms/Instrumentation/DebugIR.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DebugIR.cpp
@@ -352,14 +352,12 @@ private:
}
std::string getTypeName(Type *T) {
- std::string TypeName;
- raw_string_ostream TypeStream(TypeName);
+ string_ostream OS;
if (T)
- T->print(TypeStream);
+ T->print(OS);
else
- TypeStream << "Printing <null> Type";
- TypeStream.flush();
- return TypeName;
+ OS << "Printing <null> Type";
+ return OS.str();
}
/// Returns the MDNode that represents type T if it is already created, or 0
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index cfeb62eb1f9..5af938beaed 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -316,11 +316,9 @@ namespace {
}
ReturnBlock = new GCOVBlock(i++, os);
- std::string FunctionNameAndLine;
- raw_string_ostream FNLOS(FunctionNameAndLine);
- FNLOS << getFunctionName(SP) << SP.getLineNumber();
- FNLOS.flush();
- FuncChecksum = hash_value(FunctionNameAndLine);
+ string_ostream FnNameLine;
+ FnNameLine << getFunctionName(SP) << SP.getLineNumber();
+ FuncChecksum = hash_value(FnNameLine.str());
}
~GCOVFunction() {
@@ -337,15 +335,14 @@ namespace {
}
std::string getEdgeDestinations() {
- std::string EdgeDestinations;
- raw_string_ostream EDOS(EdgeDestinations);
+ string_ostream EdgeDestinations;
Function *F = Blocks.begin()->first->getParent();
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
GCOVBlock &Block = *Blocks[I];
for (int i = 0, e = Block.OutEdges.size(); i != e; ++i)
- EDOS << Block.OutEdges[i]->Number;
+ EdgeDestinations << Block.OutEdges[i]->Number;
}
- return EdgeDestinations;
+ return EdgeDestinations.str();
}
uint32_t getFuncChecksum() {
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 4ca03238071..bb88bc00bad 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -2424,8 +2424,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
if (PoisonStack && MS.TrackOrigins) {
setOrigin(&I, getCleanOrigin());
- SmallString<2048> StackDescriptionStorage;
- raw_svector_ostream StackDescription(StackDescriptionStorage);
+ small_string_ostream<2048> StackDescription;
// We create a string with a description of the stack allocation and
// pass it into __msan_set_alloca_origin.
// It will be printed by the run-time if stack-originated UMR is found.
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index dd4dd50f0ba..744fb24048a 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -835,8 +835,7 @@ static MDString *AppendMDNodeToSourcePtr(unsigned NodeId,
// of line at the module level and to provide a very simple format
// encoding the information herein. Both of these makes it simpler to
// parse the annotations by a simple external program.
- std::string Str;
- raw_string_ostream os(Str);
+ string_ostream os;
os << "(" << Inst->getParent()->getParent()->getName() << ",%"
<< Inst->getName() << ")";
@@ -849,8 +848,7 @@ static MDString *AppendMDNodeToSourcePtr(unsigned NodeId,
Hash = cast<MDString>(Node->getOperand(0));
}
} else if (Argument *Arg = dyn_cast<Argument>(Ptr)) {
- std::string str;
- raw_string_ostream os(str);
+ string_ostream os;
os << "(" << Arg->getParent()->getName() << ",%" << Arg->getName()
<< ")";
Hash = MDString::get(Arg->getContext(), os.str());
@@ -860,8 +858,7 @@ static MDString *AppendMDNodeToSourcePtr(unsigned NodeId,
}
static std::string SequenceToString(Sequence A) {
- std::string str;
- raw_string_ostream os(str);
+ string_ostream os;
os << A;
return os.str();
}
diff --git a/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp b/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
index cce016aafdd..42fd398d5f3 100644
--- a/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
+++ b/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
@@ -65,8 +65,7 @@ ComputeASanStackFrameLayout(SmallVectorImpl<ASanStackVariableDescription> &Vars,
Vars[i].Alignment = std::max(Vars[i].Alignment, kMinAlignment);
std::stable_sort(Vars.begin(), Vars.end(), CompareVars);
- SmallString<2048> StackDescriptionStorage;
- raw_svector_ostream StackDescription(StackDescriptionStorage);
+ small_string_ostream<2048> StackDescription;
StackDescription << NumVars;
Layout->FrameAlignment = std::max(Granularity, Vars[0].Alignment);
SmallVector<uint8_t, 64> &SB(Layout->ShadowBytes);
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index cb8a41dbeab..2338d296ccf 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -212,24 +212,23 @@ class LoopVectorizationCostModel;
/// Optimization analysis message produced during vectorization. Messages inform
/// the user why vectorization did not occur.
class Report {
- std::string Message;
- raw_string_ostream Out;
+ string_ostream Message;
Instruction *Instr;
public:
- Report(Instruction *I = nullptr) : Out(Message), Instr(I) {
- Out << "loop not vectorized: ";
+ Report(Instruction *I = nullptr) : Instr(I) {
+ Message << "loop not vectorized: ";
}
template <typename A> Report &operator<<(const A &Value) {
- Out << Value;
+ Message << Value;
return *this;
}
Instruction *getInstr() { return Instr; }
- std::string &str() { return Out.str(); }
- operator Twine() { return Out.str(); }
+ StringRef str() { return Message.str(); }
+ operator Twine() { return Message.str(); }
};
/// InnerLoopVectorizer vectorizes loops which contain only one basic
@@ -503,18 +502,17 @@ static void setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr) {
#ifndef NDEBUG
/// \return string containing a file name and a line # for the given loop.
static std::string getDebugLocString(const Loop *L) {
- std::string Result;
- if (L) {
- raw_string_ostream OS(Result);
- const DebugLoc LoopDbgLoc = L->getStartLoc();
- if (!LoopDbgLoc.isUnknown())
- LoopDbgLoc.print(L->getHeader()->getContext(), OS);
- else
- // Just print the module name.
- OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
- OS.flush();
- }
- return Result;
+ if (!L)
+ return std::string();
+
+ string_ostream OS;
+ const DebugLoc LoopDbgLoc = L->getStartLoc();
+ if (!LoopDbgLoc.isUnknown())
+ LoopDbgLoc.print(L->getHeader()->getContext(), OS);
+ else
+ // Just print the module name.
+ OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
+ return OS.str();
}
#endif
OpenPOWER on IntegriCloud