diff options
author | Alp Toker <alp@nuanti.com> | 2014-06-26 00:00:48 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-06-26 00:00:48 +0000 |
commit | 614717388cfccd6a6d34ed17a4680181e22cab22 (patch) | |
tree | 98ceaaca266d95b9e657783de3452ee20f891178 /llvm/lib/CodeGen | |
parent | 49f09fd88afbf04a2c661c1917665b46f96729fa (diff) | |
download | bcm5719-llvm-614717388cfccd6a6d34ed17a4680181e22cab22.tar.gz bcm5719-llvm-614717388cfccd6a6d34ed17a4680181e22cab22.zip |
Introduce a string_ostream string builder facilty
string_ostream is a safe and efficient string builder that combines opaque
stack storage with a built-in ostream interface.
small_string_ostream<bytes> additionally permits an explicit stack storage size
other than the default 128 bytes to be provided. Beyond that, storage is
transferred to the heap.
This convenient class can be used in most places an
std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair
would previously have been used, in order to guarantee consistent access
without byte truncation.
The patch also converts much of LLVM to use the new facility. These changes
include several probable bug fixes for truncated output, a programming error
that's no longer possible with the new interface.
llvm-svn: 211749
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockPlacement.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineScheduler.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/ScheduleDAGInstrs.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/TargetSchedule.cpp | 9 |
10 files changed, 22 insertions, 38 deletions
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 |