From: Rafael Espindola Date: Sat, 13 Jun 2015 12:50:13 +0000 (+0000) Subject: Update for llvm api change. X-Git-Tag: llvmorg-3.7.0-rc1~2426 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9bd82e9952fbbeeace03dd8422fda6c48582b127;p=platform%2Fupstream%2Fllvm.git Update for llvm api change. llvm-svn: 239671 --- diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 63f680c..257c9b4 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -10,7 +10,6 @@ #include "Config.h" #include "Driver.h" #include "InputFiles.h" -#include "Memory.h" #include "SymbolTable.h" #include "Writer.h" #include "llvm/ADT/Optional.h" diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h index d66b289..45bcfbf 100644 --- a/lld/COFF/Driver.h +++ b/lld/COFF/Driver.h @@ -10,12 +10,13 @@ #ifndef LLD_COFF_DRIVER_H #define LLD_COFF_DRIVER_H -#include "Memory.h" +#include "lld/Core/LLVM.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/Object/COFF.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" +#include "llvm/Support/StringSaver.h" #include #include #include @@ -37,6 +38,7 @@ bool link(int Argc, const char *Argv[]); class ArgParser { public: + ArgParser() : Alloc(AllocAux) {} // Parses command line options. ErrorOr> parse(int Argc, const char *Argv[]); @@ -55,12 +57,13 @@ private: ErrorOr> replaceResponseFiles(std::vector); - StringAllocator Alloc; + llvm::BumpPtrAllocator AllocAux; + llvm::BumpPtrStringSaver Alloc; }; class LinkerDriver { public: - LinkerDriver() : SearchPaths(getSearchPaths()) {} + LinkerDriver() : Alloc(AllocAux), SearchPaths(getSearchPaths()) {} bool link(int Argc, const char *Argv[]); // Used by the resolver to parse .drectve section contents. @@ -68,7 +71,8 @@ public: parseDirectives(StringRef S, std::vector> *Res); private: - StringAllocator Alloc; + llvm::BumpPtrAllocator AllocAux; + llvm::BumpPtrStringSaver Alloc; ArgParser Parser; // Opens a file. Path has to be resolved already. diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index b12e97a..22fdb8ba 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -16,7 +16,6 @@ #include "Config.h" #include "Driver.h" #include "Error.h" -#include "Memory.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" @@ -197,20 +196,9 @@ ArgParser::parse(int Argc, const char *Argv[]) { return parse(V); } -namespace { -class BumpPtrStringSaver : public llvm::cl::StringSaver { -public: - BumpPtrStringSaver(lld::coff::StringAllocator *A) : Alloc(A) {} - const char *SaveString(const char *S) override { - return Alloc->save(S).data(); - } - lld::coff::StringAllocator *Alloc; -}; -} - std::vector ArgParser::tokenize(StringRef S) { SmallVector Tokens; - BumpPtrStringSaver Saver(&Alloc); + BumpPtrStringSaver Saver(AllocAux); llvm::cl::TokenizeWindowsCommandLine(S, Saver, Tokens); return std::vector(Tokens.begin(), Tokens.end()); } @@ -220,7 +208,7 @@ std::vector ArgParser::tokenize(StringRef S) { ErrorOr> ArgParser::replaceResponseFiles(std::vector Argv) { SmallVector Tokens(&Argv[0], &Argv[0] + Argv.size()); - BumpPtrStringSaver Saver(&Alloc); + BumpPtrStringSaver Saver(AllocAux); ExpandResponseFiles(Saver, TokenizeWindowsCommandLine, Tokens); return std::vector(Tokens.begin(), Tokens.end()); } diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h index 9b46e8f..389a603 100644 --- a/lld/COFF/InputFiles.h +++ b/lld/COFF/InputFiles.h @@ -11,13 +11,13 @@ #define LLD_COFF_INPUT_FILES_H #include "Chunks.h" -#include "Memory.h" #include "Symbols.h" #include "lld/Core/LLVM.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/LTO/LTOModule.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" +#include "llvm/Support/StringSaver.h" #include #include #include @@ -144,7 +144,8 @@ private: // for details about the format. class ImportFile : public InputFile { public: - explicit ImportFile(MemoryBufferRef M) : InputFile(ImportKind, M) {} + explicit ImportFile(MemoryBufferRef M) + : InputFile(ImportKind, M), StringAlloc(StringAllocAux) {} static bool classof(const InputFile *F) { return F->kind() == ImportKind; } std::vector &getSymbols() override { return SymbolBodies; } @@ -153,7 +154,8 @@ private: std::vector SymbolBodies; llvm::BumpPtrAllocator Alloc; - StringAllocator StringAlloc; + llvm::BumpPtrAllocator StringAllocAux; + llvm::BumpPtrStringSaver StringAlloc; }; // Used for LTO. diff --git a/lld/COFF/Memory.h b/lld/COFF/Memory.h deleted file mode 100644 index 8ff4a42..0000000 --- a/lld/COFF/Memory.h +++ /dev/null @@ -1,43 +0,0 @@ -//===- Memory.h -----------------------------------------------------------===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLD_COFF_MEMORY_H -#define LLD_COFF_MEMORY_H - -#include "lld/Core/LLVM.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/ADT/Twine.h" -#include "llvm/Support/Allocator.h" -#include - -namespace lld { -namespace coff { - -class StringAllocator { -public: - // Returns a null-terminated copy of a string. - StringRef save(StringRef S) { - char *P = Alloc.Allocate(S.size() + 1); - memcpy(P, S.data(), S.size()); - P[S.size()] = '\0'; - return StringRef(P, S.size()); - } - - StringRef save(Twine S) { return save(StringRef(S.str())); } - StringRef save(const char *S) { return save(StringRef(S)); } - StringRef save(std::string &S) { return save(StringRef(S)); } - -private: - llvm::BumpPtrAllocator Alloc; -}; - -} // namespace coff -} // namespace lld - -#endif diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h index f50b816..df52982 100644 --- a/lld/COFF/SymbolTable.h +++ b/lld/COFF/SymbolTable.h @@ -11,7 +11,6 @@ #define LLD_COFF_SYMBOL_TABLE_H #include "InputFiles.h" -#include "Memory.h" #include "llvm/Support/Allocator.h" #include diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h index 2e19dd8..aadf2d6 100644 --- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h @@ -277,6 +277,8 @@ public: return is64Bit() ? "__delayLoadHelper2" : "___delayLoadHelper2@8"; } + llvm::BumpPtrAllocator &getAllocator() { return _allocator; } + StringRef allocate(StringRef ref) const { _allocMutex.lock(); char *x = _allocator.Allocate(ref.size() + 1); diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 0375ec8..935908b 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -31,6 +31,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/StringSaver.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include @@ -74,20 +75,6 @@ public: GnuLdOptTable() : OptTable(infoTable, llvm::array_lengthof(infoTable)){} }; -class DriverStringSaver : public llvm::cl::StringSaver { -public: - DriverStringSaver(BumpPtrAllocator &alloc) : _alloc(alloc) {} - - const char *SaveString(const char *s) override { - char *p = _alloc.Allocate(strlen(s) + 1); - strcpy(p, s); - return p; - } - -private: - BumpPtrAllocator &_alloc; -}; - } // anonymous namespace // If a command line option starts with "@", the driver reads its suffix as a @@ -101,7 +88,7 @@ maybeExpandResponseFiles(int argc, const char **argv, BumpPtrAllocator &alloc) { SmallVector smallvec; for (int i = 0; i < argc; ++i) smallvec.push_back(argv[i]); - DriverStringSaver saver(alloc); + llvm::BumpPtrStringSaver saver(alloc); llvm::cl::ExpandResponseFiles(saver, llvm::cl::TokenizeGNUCommandLine, smallvec); // Pack the results to a C-array and return it. diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 7bc26bb..80bd0b3 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -29,6 +29,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/Program.h" +#include "llvm/Support/StringSaver.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -694,20 +695,6 @@ static void processLibEnv(PECOFFLinkingContext &ctx) { ctx.appendInputSearchPath(ctx.allocate(path)); } -namespace { -class DriverStringSaver : public llvm::cl::StringSaver { -public: - DriverStringSaver(PECOFFLinkingContext &ctx) : _ctx(ctx) {} - - const char *SaveString(const char *s) override { - return _ctx.allocate(StringRef(s)).data(); - } - -private: - PECOFFLinkingContext &_ctx; -}; -} - // Tokenize command line options in a given file and add them to result. static bool readResponseFile(StringRef path, PECOFFLinkingContext &ctx, std::vector &result) { @@ -716,7 +703,7 @@ static bool readResponseFile(StringRef path, PECOFFLinkingContext &ctx, return false; StringRef contentsStr(reinterpret_cast(contents.data()), contents.size()); - DriverStringSaver saver(ctx); + llvm::BumpPtrStringSaver saver(ctx.getAllocator()); SmallVector args; llvm::cl::TokenizeWindowsCommandLine(contentsStr, saver, args); for (const char *s : args) diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index 813580e..46cf15c 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -29,6 +29,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" +#include "llvm/Support/StringSaver.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -54,14 +55,12 @@ using namespace lld; namespace { -class BumpPtrStringSaver : public llvm::cl::StringSaver { +class BumpPtrStringSaver final : public llvm::StringSaver { public: - const char *SaveString(const char *str) override { - size_t len = strlen(str); + BumpPtrStringSaver() : llvm::StringSaver(_alloc) {} + const char *saveImpl(StringRef Str) override { std::lock_guard lock(_allocMutex); - char *copy = _alloc.Allocate(len + 1); - memcpy(copy, str, len + 1); - return copy; + return llvm::StringSaver::saveImpl(Str); } private: