[PATCH] make SmallString::str() return std::string

Yaron Keren yaron.keren at gmail.com
Thu Nov 20 00:53:09 PST 2014


Note! **this compiles but breaks tests**, it's not ready. I must have made an error somewhere. 
I'm keeping it in Phabricator hoping to continue fixing it time permitting.
If anyone else is interested in taking over, feel free.

This is an attempt in making SmallString::str() return std::string.
The first phase required making SmallString an equal-rights citizen in LLVM.

There were four use-cases for SmallString::str():

1 Input to a twine or StringRef accepting function.
2 << streaming to raw_stream.
3 Select an overloaded function accepting Twine and StringRef.
4 Really convert to std::string.

To solve 1 and 2, I extended Twine and raw_stream to accept SmallVectorImpl<char>.
This made most hundreds of existing .str() calls redundant which is very nice.

3 was solved by either adding a SmallVectorImpl<char>-accepting function or 
specifying StringRef(SmallString).

For 4, where std::string was really required, I added std::string SmallString::to_str().
.str() can not be reused immediatly as all the existing .str() code would compile OK but
with performance regressions due to the creation of std::string instead of a StringRef.

All .str() users must be reviewed to be removed most of the time or modified into 
to_str() before we can reuse .str().

http://reviews.llvm.org/D6336

Files:
  include/llvm/ADT/SmallString.h
  include/llvm/ADT/Twine.h
  include/llvm/MC/MCContext.h
  include/llvm/Option/ArgList.h
  include/llvm/Support/FileUtilities.h
  include/llvm/Support/raw_ostream.h
  include/llvm/TableGen/StringToOffsetTable.h
  lib/Bitcode/Reader/BitcodeReader.cpp
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
  lib/CodeGen/MachineFunction.cpp
  lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  lib/DebugInfo/DWARFDebugLine.cpp
  lib/IR/AsmWriter.cpp
  lib/IR/GCOV.cpp
  lib/LineEditor/LineEditor.cpp
  lib/Linker/LinkModules.cpp
  lib/MC/MCAsmStreamer.cpp
  lib/MC/MCAssembler.cpp
  lib/MC/MCContext.cpp
  lib/MC/MCDisassembler/Disassembler.cpp
  lib/MC/MCDwarf.cpp
  lib/Object/MachOObjectFile.cpp
  lib/Support/APInt.cpp
  lib/Support/GraphWriter.cpp
  lib/Support/LockFileManager.cpp
  lib/Support/Path.cpp
  lib/Support/Process.cpp
  lib/Support/Triple.cpp
  lib/Support/Twine.cpp
  lib/Support/Windows/Path.inc
  lib/Target/TargetLoweringObjectFile.cpp
  lib/Target/TargetMachine.cpp
  lib/Target/X86/AsmParser/X86AsmParser.cpp
  lib/Transforms/Instrumentation/GCOVProfiling.cpp
  tools/bugpoint/ExecutionDriver.cpp
  tools/bugpoint/ExtractFunction.cpp
  tools/bugpoint/Miscompilation.cpp
  tools/bugpoint/OptimizerDriver.cpp
  tools/bugpoint/ToolRunner.cpp
  tools/clang/lib/ARCMigrate/ARCMT.cpp
  tools/clang/lib/ARCMigrate/FileRemapper.cpp
  tools/clang/lib/ARCMigrate/ObjCMT.cpp
  tools/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
  tools/clang/lib/AST/DeclObjC.cpp
  tools/clang/lib/AST/Expr.cpp
  tools/clang/lib/AST/ItaniumMangle.cpp
  tools/clang/lib/AST/MicrosoftMangle.cpp
  tools/clang/lib/Basic/FileManager.cpp
  tools/clang/lib/Basic/VirtualFileSystem.cpp
  tools/clang/lib/CodeGen/CGDebugInfo.cpp
  tools/clang/lib/CodeGen/CGDeclCXX.cpp
  tools/clang/lib/CodeGen/CGObjCMac.cpp
  tools/clang/lib/CodeGen/CGVTT.cpp
  tools/clang/lib/CodeGen/CGVTables.cpp
  tools/clang/lib/CodeGen/ItaniumCXXABI.cpp
  tools/clang/lib/CodeGen/MicrosoftCXXABI.cpp
  tools/clang/lib/CodeGen/TargetInfo.cpp
  tools/clang/lib/Driver/CrossWindowsToolChain.cpp
  tools/clang/lib/Driver/Driver.cpp
  tools/clang/lib/Driver/MSVCToolChain.cpp
  tools/clang/lib/Driver/Multilib.cpp
  tools/clang/lib/Driver/SanitizerArgs.cpp
  tools/clang/lib/Driver/ToolChains.cpp
  tools/clang/lib/Driver/Tools.cpp
  tools/clang/lib/Edit/EditedSource.cpp
  tools/clang/lib/Frontend/ASTUnit.cpp
  tools/clang/lib/Frontend/CacheTokens.cpp
  tools/clang/lib/Frontend/CompilerInstance.cpp
  tools/clang/lib/Frontend/CompilerInvocation.cpp
  tools/clang/lib/Frontend/FrontendAction.cpp
  tools/clang/lib/Frontend/FrontendActions.cpp
  tools/clang/lib/Frontend/InitHeaderSearch.cpp
  tools/clang/lib/Frontend/LogDiagnosticPrinter.cpp
  tools/clang/lib/Frontend/ModuleDependencyCollector.cpp
  tools/clang/lib/Frontend/Rewrite/FrontendActions.cpp
  tools/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
  tools/clang/lib/Frontend/TextDiagnostic.cpp
  tools/clang/lib/Frontend/TextDiagnosticBuffer.cpp
  tools/clang/lib/Index/CommentToXML.cpp
  tools/clang/lib/Lex/HeaderSearch.cpp
  tools/clang/lib/Lex/ModuleMap.cpp
  tools/clang/lib/Lex/PPDirectives.cpp
  tools/clang/lib/Lex/PPMacroExpansion.cpp
  tools/clang/lib/Lex/Pragma.cpp
  tools/clang/lib/Lex/TokenLexer.cpp
  tools/clang/lib/Parse/ParseInit.cpp
  tools/clang/lib/Rewrite/Rewriter.cpp
  tools/clang/lib/Sema/SemaCodeComplete.cpp
  tools/clang/lib/Sema/SemaDecl.cpp
  tools/clang/lib/Sema/SemaExpr.cpp
  tools/clang/lib/Sema/SemaStmt.cpp
  tools/clang/lib/Serialization/ASTReader.cpp
  tools/clang/lib/Serialization/ASTReaderStmt.cpp
  tools/clang/lib/Serialization/ASTWriter.cpp
  tools/clang/lib/Serialization/GlobalModuleIndex.cpp
  tools/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
  tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
  tools/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  tools/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
  tools/clang/lib/Tooling/JSONCompilationDatabase.cpp
  tools/clang/lib/Tooling/Tooling.cpp
  tools/clang/tools/driver/driver.cpp
  tools/clang/tools/libclang/CIndex.cpp
  tools/clang/tools/libclang/CIndexCodeCompletion.cpp
  tools/clang/tools/libclang/CIndexer.cpp
  tools/clang/tools/libclang/CXComment.cpp
  tools/clang/tools/libclang/IndexingContext.cpp
  tools/clang/utils/TableGen/ClangAttrEmitter.cpp
  tools/clang/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp
  tools/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
  tools/llvm-cov/CodeCoverage.cpp
  tools/llvm-cov/gcov.cpp
  tools/llvm-objdump/MachODump.cpp
  tools/llvm-symbolizer/LLVMSymbolize.cpp
  utils/FileCheck/FileCheck.cpp
  utils/TableGen/AsmWriterEmitter.cpp
  utils/TableGen/DAGISelMatcherEmitter.cpp
  utils/TableGen/FixedLenDecoderEmitter.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6336.16418.patch
Type: text/x-patch
Size: 124223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141120/177ed26e/attachment.bin>


More information about the llvm-commits mailing list