Skip to content

Commit

Permalink
Revert "Introduce a string_ostream string builder facilty"
Browse files Browse the repository at this point in the history
Temporarily back out commits r211749, r211752 and r211754.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211814 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
atoker committed Jun 26, 2014
1 parent eca517d commit 8dd8d5c
Show file tree
Hide file tree
Showing 57 changed files with 288 additions and 226 deletions.
10 changes: 7 additions & 3 deletions include/llvm/Analysis/CFGPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
if (!Node->getName().empty())
return Node->getName().str();

string_ostream OS;
std::string Str;
raw_string_ostream OS(Str);

Node->printAsOperand(OS, false);
return OS.str();
}

static std::string getCompleteNodeLabel(const BasicBlock *Node,
const Function *) {
enum { MaxColumns = 80 };
string_ostream OS;
std::string Str;
raw_string_ostream OS(Str);

if (Node->getName().empty()) {
Node->printAsOperand(OS, false);
Expand Down Expand Up @@ -106,7 +109,8 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {

if (SuccNo == 0) return "def";

string_ostream OS;
std::string Str;
raw_string_ostream OS(Str);
SwitchInst::ConstCaseIt Case =
SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
OS << Case.getCaseValue()->getValue();
Expand Down
11 changes: 8 additions & 3 deletions include/llvm/ExecutionEngine/ObjectBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ class ObjectBuffer {
class ObjectBufferStream : public ObjectBuffer {
void anchor() override;
public:
ObjectBufferStream() {}
ObjectBufferStream() : OS(SV) {}
virtual ~ObjectBufferStream() {}

raw_ostream &getOStream() { return OS; }
void flush()
{
OS.flush();

// Make the data accessible via the ObjectBuffer::Buffer
Buffer.reset(MemoryBuffer::getMemBuffer(OS.str(), "", false));
Buffer.reset(MemoryBuffer::getMemBuffer(StringRef(SV.data(), SV.size()),
"",
false));
}

protected:
small_string_ostream<4096> OS; // Working buffer into which we JIT.
SmallVector<char, 4096> SV; // Working buffer into which we JIT.
raw_svector_ostream OS; // streaming wrapper
};

} // namespace llvm
Expand Down
3 changes: 2 additions & 1 deletion include/llvm/Support/GraphWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class GraphWriter {
O << "|" << DOT::EscapeString(NodeDesc);
}

string_ostream EdgeSourceLabels;
std::string edgeSourceLabels;
raw_string_ostream EdgeSourceLabels(edgeSourceLabels);
bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);

if (hasEdgeSourceLabels) {
Expand Down
3 changes: 2 additions & 1 deletion include/llvm/Support/YAMLTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ template<typename T>
typename std::enable_if<has_ScalarTraits<T>::value,void>::type
yamlize(IO &io, T &Val, bool) {
if ( io.outputting() ) {
llvm::string_ostream Buffer;
std::string Storage;
llvm::raw_string_ostream Buffer(Storage);
ScalarTraits<T>::output(Val, io.getContext(), Buffer);
StringRef Str = Buffer.str();
io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
Expand Down
30 changes: 2 additions & 28 deletions include/llvm/Support/raw_ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#define LLVM_SUPPORT_RAW_OSTREAM_H

#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"

namespace llvm {
class format_object_base;
template <typename T>
class SmallVectorImpl;

namespace sys {
namespace fs {
Expand Down Expand Up @@ -460,14 +461,6 @@ class raw_svector_ostream : public raw_ostream {
/// current_pos - Return the current position within the stream, not
/// counting the bytes currently in the buffer.
uint64_t current_pos() const override;

protected:
// This constructor is specified not to access \p O provided for storage as it
// may not yet be initialized at construction time.
explicit raw_svector_ostream(SmallVectorImpl<char> &O, std::nullptr_t)
: OS(O){};
void init();

public:
/// Construct a new raw_svector_ostream.
///
Expand Down Expand Up @@ -500,25 +493,6 @@ class raw_null_ostream : public raw_ostream {
~raw_null_ostream();
};

/// string_ostream - A raw_ostream that builds a string. This is a
/// raw_svector_ostream with storage.
template <unsigned InternalLen>
class small_string_ostream : public raw_svector_ostream {
SmallVector<char, InternalLen> Buffer;
// There's no need to flush explicitly.
using raw_svector_ostream::flush;

public:
small_string_ostream() : raw_svector_ostream(Buffer, nullptr) { init(); }

void clear() {
flush();
Buffer.clear();
}
};

typedef small_string_ostream<128> string_ostream;

} // end llvm namespace

#endif
4 changes: 2 additions & 2 deletions include/llvm/TableGen/StringToOffsetTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class StringToOffsetTable {

void EmitString(raw_ostream &O) {
// Escape the string.
small_string_ostream<256> Str;
Str.write_escaped(AggregateString);
SmallString<256> Str;
raw_svector_ostream(Str).write_escaped(AggregateString);
AggregateString = Str.str();

O << " \"";
Expand Down
9 changes: 4 additions & 5 deletions lib/Analysis/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
char **OutMessages) {
raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
string_ostream MsgsOS;
std::string Messages;
raw_string_ostream MsgsOS(Messages);

LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);

Expand All @@ -86,10 +87,8 @@ LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
if (Action == LLVMAbortProcessAction && Result)
report_fatal_error("Broken module found, compilation aborted!");

if (OutMessages) {
MsgsOS << '\0';
*OutMessages = strdup(MsgsOS.str().data());
}
if (OutMessages)
*OutMessages = strdup(MsgsOS.str().c_str());

return Result;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Analysis/BlockFrequencyInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ struct DOTGraphTraits<BlockFrequencyInfo*> : public DefaultDOTGraphTraits {

std::string getNodeLabel(const BasicBlock *Node,
const BlockFrequencyInfo *Graph) {
string_ostream OS;
std::string Result;
raw_string_ostream OS(Result);

OS << Node->getName() << ":";
OS << Node->getName().str() << ":";
switch (ViewBlockFreqPropagationDAG) {
case GVDT_Fraction:
Graph->printBlockFreq(OS, Node);
Expand All @@ -97,7 +98,7 @@ struct DOTGraphTraits<BlockFrequencyInfo*> : public DefaultDOTGraphTraits {
"never reach this point.");
}

return OS.str();
return Result;
}
};

Expand Down
7 changes: 4 additions & 3 deletions lib/Analysis/Lint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ namespace {
const DataLayout *DL;
TargetLibraryInfo *TLI;

string_ostream MessagesStr;
std::string Messages;
raw_string_ostream MessagesStr;

static char ID; // Pass identification, replacement for typeid
Lint() : FunctionPass(ID) {
Lint() : FunctionPass(ID), MessagesStr(Messages) {
initializeLintPass(*PassRegistry::getPassRegistry());
}

Expand Down Expand Up @@ -180,7 +181,7 @@ bool Lint::runOnFunction(Function &F) {
TLI = &getAnalysis<TargetLibraryInfo>();
visit(F);
dbgs() << MessagesStr.str();
MessagesStr.clear();
Messages.clear();
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
using namespace llvm;

static std::string getTypeString(Type *T) {
string_ostream Result;
Result << *T;
return Result.str();
std::string Result;
raw_string_ostream Tmp(Result);
Tmp << *T;
return Tmp.str();
}

/// Run: module ::= toplevelentity*
Expand Down
3 changes: 2 additions & 1 deletion lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,8 @@ static const MCExpr *lowerConstant(const Constant *CV, AsmPrinter &AP) {

// Otherwise report the problem to the user.
{
string_ostream OS;
std::string S;
raw_string_ostream OS(S);
OS << "Unsupported expression in static initializer: ";
CE->printAsOperand(OS, /*PrintType=*/false,
!AP.MF ? nullptr : AP.MF->getFunction()->getParent());
Expand Down
12 changes: 8 additions & 4 deletions lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
}
}
if (Error) {
string_ostream Msg;
std::string msg;
raw_string_ostream Msg(msg);
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
Expand Down Expand Up @@ -412,7 +413,8 @@ static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
}
}
if (Error) {
string_ostream Msg;
std::string msg;
raw_string_ostream Msg(msg);
Msg << "invalid operand in inline asm: '" << AsmStr << "'";
MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
}
Expand Down Expand Up @@ -469,7 +471,8 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {

// Emit the inline asm to a temporary string so we can emit it through
// EmitInlineAsm.
small_string_ostream<256> OS;
SmallString<256> StringData;
raw_svector_ostream OS(StringData);

// The variant of the current asmprinter.
int AsmPrinterVariant = MAI->getAssemblerDialect();
Expand Down Expand Up @@ -514,7 +517,8 @@ void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
}
OS << Counter;
} else {
string_ostream Msg;
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Unknown special formatter '" << Code
<< "' for machine instr: " << *MI;
report_fatal_error(Msg.str());
Expand Down
7 changes: 4 additions & 3 deletions lib/CodeGen/MachineBlockFrequencyInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo*> :

std::string getNodeLabel(const MachineBasicBlock *Node,
const MachineBlockFrequencyInfo *Graph) {
string_ostream OS;
std::string Result;
raw_string_ostream OS(Result);

OS << Node->getName() << ":";
OS << Node->getName().str() << ":";
switch (ViewMachineBlockFreqPropagationDAG) {
case GVDT_Fraction:
Graph->printBlockFreq(OS, Node);
Expand All @@ -104,7 +105,7 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo*> :
"never reach this point.");
}

return OS.str();
return Result;
}
};

Expand Down
12 changes: 8 additions & 4 deletions lib/CodeGen/MachineBlockPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,23 @@ INITIALIZE_PASS_END(MachineBlockPlacement, "block-placement2",
///
/// Only used by debug logging.
static std::string getBlockName(MachineBasicBlock *BB) {
string_ostream OS;
std::string Result;
raw_string_ostream OS(Result);
OS << "BB#" << BB->getNumber()
<< " (derived from LLVM BB '" << BB->getName() << "')";
return OS.str();
OS.flush();
return Result;
}

/// \brief Helper to print the number of a MBB.
///
/// Only used by debug logging.
static std::string getBlockNum(MachineBasicBlock *BB) {
string_ostream OS;
std::string Result;
raw_string_ostream OS(Result);
OS << "BB#" << BB->getNumber();
return OS.str();
OS.flush();
return Result;
}
#endif

Expand Down
5 changes: 3 additions & 2 deletions lib/CodeGen/MachineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,9 @@ MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,

const char *Prefix = isLinkerPrivate ? DL->getLinkerPrivateGlobalPrefix() :
DL->getPrivateGlobalPrefix();
small_string_ostream<60> Name;
Name << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
SmallString<60> Name;
raw_svector_ostream(Name)
<< Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
return Ctx.GetOrCreateSymbol(Name.str());
}

Expand Down
3 changes: 2 additions & 1 deletion lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3235,7 +3235,8 @@ struct DOTGraphTraits<ScheduleDAGMI*> : public DefaultDOTGraphTraits {
}

static std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *G) {
string_ostream SS;
std::string Str;
raw_string_ostream SS(Str);
const ScheduleDAGMI *DAG = static_cast<const ScheduleDAGMI*>(G);
const SchedDFSResult *DFS = DAG->hasVRegLiveness() ?
static_cast<const ScheduleDAGMILive*>(G)->getDFSResult() : nullptr;
Expand Down
3 changes: 2 additions & 1 deletion lib/CodeGen/ScheduleDAGInstrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,8 @@ void ScheduleDAGInstrs::dumpNode(const SUnit *SU) const {
}

std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
string_ostream oss;
std::string s;
raw_string_ostream oss(s);
if (SU == &EntrySU)
oss << "<entry>";
else if (SU == &ExitSU)
Expand Down
3 changes: 2 additions & 1 deletion lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3245,7 +3245,8 @@ SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,


void SelectionDAGISel::CannotYetSelect(SDNode *N) {
string_ostream Msg;
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Cannot select: ";

if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&
Expand Down
3 changes: 2 additions & 1 deletion lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ void SelectionDAG::setSubgraphColor(SDNode *N, const char *Color) {
}

std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
string_ostream O;
std::string s;
raw_string_ostream O(s);
O << "SU(" << SU->NodeNum << "): ";
if (SU->getNode()) {
SmallVector<SDNode *, 4> GluedNodes;
Expand Down
9 changes: 5 additions & 4 deletions lib/CodeGen/TargetSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ unsigned TargetSchedModel::computeOperandLatency(
if (SCDesc->isValid() && !DefMI->getOperand(DefOperIdx).isImplicit()
&& !DefMI->getDesc().OpInfo[DefOperIdx].isOptionalDef()
&& SchedModel.isComplete()) {
string_ostream Err;
Err << "DefIdx " << DefIdx << " exceeds machine model writes for "
<< *DefMI;
report_fatal_error(Err.str());
std::string Err;
raw_string_ostream ss(Err);
ss << "DefIdx " << DefIdx << " exceeds machine model writes for "
<< *DefMI;
report_fatal_error(ss.str());
}
#endif
// FIXME: Automatically giving all implicit defs defaultDefLatency is
Expand Down
Loading

0 comments on commit 8dd8d5c

Please sign in to comment.