summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-06-26 00:00:48 +0000
committerAlp Toker <alp@nuanti.com>2014-06-26 00:00:48 +0000
commit255907042245b77779e3e38c5ce66901866cabe5 (patch)
tree92db65aa99c37ab5f68cd6adaae1d8cf6d629b8f /lib/Transforms
parentce6e7c7a59e8595ea3f30d87cbad4af278cb5ef3 (diff)
downloadllvm-255907042245b77779e3e38c5ce66901866cabe5.tar.gz
llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.bz2
llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211749 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Instrumentation/DebugIR.cpp10
-rw-r--r--lib/Transforms/Instrumentation/GCOVProfiling.cpp15
-rw-r--r--lib/Transforms/Instrumentation/MemorySanitizer.cpp3
-rw-r--r--lib/Transforms/ObjCARC/ObjCARCOpts.cpp9
-rw-r--r--lib/Transforms/Utils/ASanStackFrameLayout.cpp3
-rw-r--r--lib/Transforms/Vectorize/LoopVectorize.cpp36
6 files changed, 32 insertions, 44 deletions
diff --git a/lib/Transforms/Instrumentation/DebugIR.cpp b/lib/Transforms/Instrumentation/DebugIR.cpp
index f2f1738808..56e60e6984 100644
--- a/lib/Transforms/Instrumentation/DebugIR.cpp
+++ b/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/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index cfeb62eb1f..5af938beae 100644
--- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/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/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 4ca0323807..bb88bc00ba 100644
--- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/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/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index dd4dd50f0b..744fb24048 100644
--- a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/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/lib/Transforms/Utils/ASanStackFrameLayout.cpp b/lib/Transforms/Utils/ASanStackFrameLayout.cpp
index cce016aafd..42fd398d5f 100644
--- a/lib/Transforms/Utils/ASanStackFrameLayout.cpp
+++ b/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/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp
index cb8a41dbea..2338d296cc 100644
--- a/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/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