diff options
| author | Rui Ueyama <ruiu@google.com> | 2015-01-15 08:46:36 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2015-01-15 08:46:36 +0000 |
| commit | 883afba228f67bf156f299a137f74eb00f71010f (patch) | |
| tree | a3605d91c4169ec91abe529507d079a6b77d03fc | |
| parent | f8637360e2ea0e1c697bcfc24dafa8f12d31171c (diff) | |
| download | bcm5719-llvm-883afba228f67bf156f299a137f74eb00f71010f.tar.gz bcm5719-llvm-883afba228f67bf156f299a137f74eb00f71010f.zip | |
Remove InputGraph and use std::vector<Node> instead.
In total we have removed more than 1000 lines!
llvm-svn: 226149
| -rw-r--r-- | lld/include/lld/Core/InputGraph.h | 20 | ||||
| -rw-r--r-- | lld/include/lld/Core/LinkingContext.h | 9 | ||||
| -rw-r--r-- | lld/include/lld/ReaderWriter/PECOFFLinkingContext.h | 2 | ||||
| -rw-r--r-- | lld/lib/Core/Resolver.cpp | 6 | ||||
| -rw-r--r-- | lld/lib/Driver/CoreDriver.cpp | 8 | ||||
| -rw-r--r-- | lld/lib/Driver/DarwinLdDriver.cpp | 27 | ||||
| -rw-r--r-- | lld/lib/Driver/Driver.cpp | 9 | ||||
| -rw-r--r-- | lld/lib/Driver/GnuLdDriver.cpp | 20 | ||||
| -rw-r--r-- | lld/lib/Driver/WinLinkDriver.cpp | 10 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp | 3 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp | 6 | ||||
| -rw-r--r-- | lld/unittests/DriverTests/DriverTest.h | 4 |
12 files changed, 39 insertions, 85 deletions
diff --git a/lld/include/lld/Core/InputGraph.h b/lld/include/lld/Core/InputGraph.h index a2e9c2da95c..afb04c27927 100644 --- a/lld/include/lld/Core/InputGraph.h +++ b/lld/include/lld/Core/InputGraph.h @@ -17,32 +17,12 @@ #define LLD_CORE_INPUT_GRAPH_H #include "lld/Core/File.h" -#include "lld/Core/range.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/Option/ArgList.h" -#include "llvm/Support/ErrorOr.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/raw_ostream.h" -#include <functional> #include <memory> -#include <stack> #include <vector> namespace lld { -class Node; -class LinkingContext; - -class InputGraph { -public: - std::vector<std::unique_ptr<Node>> &members() { - return _members; - } - -protected: - std::vector<std::unique_ptr<Node>> _members; -}; - // A Node represents a FileNode or other type of Node. In the latter case, // the node contains meta information about the input file list. // Currently only GroupEnd node is defined as a meta node. diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index 9528b1714a2..1bd4f97e3d2 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -25,7 +25,6 @@ namespace lld { class PassManager; class File; class Writer; -class InputGraph; class Node; class SharedLibraryFile; @@ -216,10 +215,8 @@ public: return _aliasSymbols; } - void setInputGraph(std::unique_ptr<InputGraph> inputGraph) { - _inputGraph = std::move(inputGraph); - } - InputGraph &getInputGraph() const { return *_inputGraph; } + std::vector<std::unique_ptr<Node>> &getNodes() { return _nodes; } + const std::vector<std::unique_ptr<Node>> &getNodes() const { return _nodes; } /// Notify the LinkingContext when an atom is added to the symbol table. /// This is an opportunity for flavor specific work to be done. @@ -365,7 +362,7 @@ protected: std::map<std::string, std::string> _aliasSymbols; std::vector<const char *> _llvmOptions; StringRefVector _initialUndefinedSymbols; - std::unique_ptr<InputGraph> _inputGraph; + std::vector<std::unique_ptr<Node>> _nodes; mutable llvm::BumpPtrAllocator _allocator; mutable uint64_t _nextOrdinal; Registry _registry; diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h index bbf2b603dcc..7aba11cae8d 100644 --- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h @@ -334,8 +334,6 @@ public: return *r; } - virtual bool hasInputGraph() { return !!_inputGraph; } - void addLibraryFile(std::unique_ptr<FileNode> file); void setModuleDefinitionFile(const std::string val) { diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp index 1af8233a796..ae2c71f06ad 100644 --- a/lld/lib/Core/Resolver.cpp +++ b/lld/lib/Core/Resolver.cpp @@ -232,8 +232,7 @@ void Resolver::addAtoms(const std::vector<const DefinedAtom *> &newAtoms) { // Returns true if at least one of N previous files has created an // undefined symbol. bool Resolver::undefinesAdded(int begin, int end) { - std::vector<std::unique_ptr<Node>> &inputs = - _context.getInputGraph().members(); + std::vector<std::unique_ptr<Node>> &inputs = _context.getNodes(); for (int i = begin; i < end; ++i) if (FileNode *node = dyn_cast<FileNode>(inputs[i].get())) if (_newUndefinesAdded[node->getFile()]) @@ -242,8 +241,7 @@ bool Resolver::undefinesAdded(int begin, int end) { } File *Resolver::getFile(int &index, int &groupLevel) { - std::vector<std::unique_ptr<Node>> &inputs - = _context.getInputGraph().members(); + std::vector<std::unique_ptr<Node>> &inputs = _context.getNodes(); if ((size_t)index >= inputs.size()) return nullptr; if (GroupEnd *group = dyn_cast<GroupEnd>(inputs[index].get())) { diff --git a/lld/lib/Driver/CoreDriver.cpp b/lld/lib/Driver/CoreDriver.cpp index 1a495771789..e0438030978 100644 --- a/lld/lib/Driver/CoreDriver.cpp +++ b/lld/lib/Driver/CoreDriver.cpp @@ -103,8 +103,6 @@ bool CoreDriver::parse(int argc, const char *argv[], CoreLinkingContext &ctx, return false; } - std::unique_ptr<InputGraph> inputGraph(new InputGraph()); - // Set default options ctx.setOutputPath("-"); ctx.setDeadStripping(false); @@ -153,7 +151,7 @@ bool CoreDriver::parse(int argc, const char *argv[], CoreLinkingContext &ctx, std::vector<std::unique_ptr<File>> files = loadFile(ctx, inputArg->getValue(), false); for (std::unique_ptr<File> &file : files) { - inputGraph->members().push_back(std::unique_ptr<Node>( + ctx.getNodes().push_back(std::unique_ptr<Node>( new FileNode(std::move(file)))); } break; @@ -164,13 +162,11 @@ bool CoreDriver::parse(int argc, const char *argv[], CoreLinkingContext &ctx, } } - if (inputGraph->members().empty()) { + if (ctx.getNodes().empty()) { diagnostics << "No input files\n"; return false; } - ctx.setInputGraph(std::move(inputGraph)); - // Validate the combination of options used. return ctx.validate(diagnostics); } diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index 78c524b499c..8831fb39609 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -113,14 +113,13 @@ static std::string canonicalizePath(StringRef path) { } } -static void addFile(StringRef path, std::unique_ptr<InputGraph> &inputGraph, - MachOLinkingContext &ctx, bool loadWholeArchive, +static void addFile(StringRef path, MachOLinkingContext &ctx, + bool loadWholeArchive, bool upwardDylib, raw_ostream &diag) { std::vector<std::unique_ptr<File>> files = loadFile(ctx, path, diag, loadWholeArchive, upwardDylib); for (std::unique_ptr<File> &file : files) - inputGraph->members().push_back( - llvm::make_unique<FileNode>(std::move(file))); + ctx.getNodes().push_back(llvm::make_unique<FileNode>(std::move(file))); } // Export lists are one symbol per line. Blank lines are ignored. @@ -214,7 +213,6 @@ static std::error_code parseOrderFile(StringRef orderFilePath, // per line. The <dir> prefix is prepended to each partial path. // static std::error_code loadFileList(StringRef fileListPath, - std::unique_ptr<InputGraph> &inputGraph, MachOLinkingContext &ctx, bool forceLoad, raw_ostream &diagnostics) { // If there is a comma, split off <dir>. @@ -251,7 +249,7 @@ static std::error_code loadFileList(StringRef fileListPath, if (ctx.testingFileUsage()) { diagnostics << "Found filelist entry " << canonicalizePath(path) << '\n'; } - addFile(path, inputGraph, ctx, forceLoad, false, diagnostics); + addFile(path, ctx, forceLoad, false, diagnostics); buffer = lineAndRest.second; } return std::error_code(); @@ -569,7 +567,6 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], ctx.registry().addSupportNativeObjects(); ctx.registry().addSupportYamlFiles(); } - std::unique_ptr<InputGraph> inputGraph(new InputGraph()); // Now construct the set of library search directories, following ld64's // baroque set of accumulated hacks. Mostly, the algorithm constructs @@ -793,13 +790,13 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], default: continue; case OPT_INPUT: - addFile(arg->getValue(), inputGraph, ctx, globalWholeArchive, false, diagnostics); + addFile(arg->getValue(), ctx, globalWholeArchive, false, diagnostics); break; case OPT_upward_library: - addFile(arg->getValue(), inputGraph, ctx, false, true, diagnostics); + addFile(arg->getValue(), ctx, false, true, diagnostics); break; case OPT_force_load: - addFile(arg->getValue(), inputGraph, ctx, true, false, diagnostics); + addFile(arg->getValue(), ctx, true, false, diagnostics); break; case OPT_l: case OPT_upward_l: @@ -813,7 +810,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], diagnostics << "Found " << (upward ? "upward " : " ") << "library " << canonicalizePath(resolvedPath.get()) << '\n'; } - addFile(resolvedPath.get(), inputGraph, ctx, globalWholeArchive, upward, diagnostics); + addFile(resolvedPath.get(), ctx, globalWholeArchive, upward, diagnostics); break; case OPT_framework: case OPT_upward_framework: @@ -827,10 +824,10 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], diagnostics << "Found " << (upward ? "upward " : " ") << "framework " << canonicalizePath(resolvedPath.get()) << '\n'; } - addFile(resolvedPath.get(), inputGraph, ctx, globalWholeArchive, upward, diagnostics); + addFile(resolvedPath.get(), ctx, globalWholeArchive, upward, diagnostics); break; case OPT_filelist: - if (std::error_code ec = loadFileList(arg->getValue(), inputGraph, + if (std::error_code ec = loadFileList(arg->getValue(), ctx, globalWholeArchive, diagnostics)) { diagnostics << "error: " << ec.message() @@ -842,13 +839,11 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], } } - if (inputGraph->members().empty()) { + if (ctx.getNodes().empty()) { diagnostics << "No input files\n"; return false; } - ctx.setInputGraph(std::move(inputGraph)); - // Validate the combination of options used. return ctx.validate(diagnostics); } diff --git a/lld/lib/Driver/Driver.cpp b/lld/lib/Driver/Driver.cpp index c9058cc2fad..85c2bd9d402 100644 --- a/lld/lib/Driver/Driver.cpp +++ b/lld/lib/Driver/Driver.cpp @@ -74,8 +74,7 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) { args[numArgs + 1] = 0; llvm::cl::ParseCommandLineOptions(numArgs + 1, args); } - InputGraph &inputGraph = context.getInputGraph(); - if (inputGraph.members().empty()) + if (context.getNodes().empty()) return false; bool fail = false; @@ -84,7 +83,7 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) { ScopedTask readTask(getDefaultDomain(), "Read Args"); TaskGroup tg; std::mutex diagnosticsMutex; - for (std::unique_ptr<Node> &ie : inputGraph.members()) { + for (std::unique_ptr<Node> &ie : context.getNodes()) { tg.spawn([&] { // Writes to the same output stream is not guaranteed to be thread-safe. // We buffer the diagnostics output to a separate string-backed output @@ -118,7 +117,7 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) { std::vector<std::unique_ptr<File>> internalFiles; context.createInternalFiles(internalFiles); for (auto i = internalFiles.rbegin(), e = internalFiles.rend(); i != e; ++i) { - auto &members = context.getInputGraph().members(); + auto &members = context.getNodes(); members.insert(members.begin(), llvm::make_unique<FileNode>(std::move(*i))); } @@ -126,7 +125,7 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) { std::vector<std::unique_ptr<File>> implicitFiles; context.createImplicitFiles(implicitFiles); for (auto i = implicitFiles.rbegin(), e = implicitFiles.rend(); i != e; ++i) { - auto &members = context.getInputGraph().members(); + auto &members = context.getNodes(); members.insert(members.begin(), llvm::make_unique<FileNode>(std::move(*i))); } diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 7c6982cf61a..4ce363c0d1e 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -111,7 +111,6 @@ maybeExpandResponseFiles(int argc, const char **argv, BumpPtrAllocator &alloc) { return std::make_tuple(argc, copy); } -// Get the Input file magic for creating appropriate InputGraph nodes. static std::error_code getFileMagic(StringRef path, llvm::sys::fs::file_magic &magic) { std::error_code ec = llvm::sys::fs::identify_magic(path, magic); @@ -234,8 +233,8 @@ static bool isPathUnderSysroot(StringRef sysroot, StringRef path) { } static std::error_code -evaluateLinkerScript(ELFLinkingContext &ctx, InputGraph *inputGraph, - StringRef path, raw_ostream &diag) { +evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path, + raw_ostream &diag) { // Read the script file from disk and parse. ErrorOr<std::unique_ptr<MemoryBuffer>> mb = MemoryBuffer::getFileOrSTDIN(path); @@ -274,12 +273,12 @@ evaluateLinkerScript(ELFLinkingContext &ctx, InputGraph *inputGraph, for (std::unique_ptr<File> &file : files) { if (ctx.logInputFiles()) diag << file->path() << "\n"; - inputGraph->members().push_back( + ctx.getNodes().push_back( std::unique_ptr<Node>(new FileNode(std::move(file)))); ++numfiles; } } - inputGraph->members().push_back(llvm::make_unique<GroupEnd>(numfiles)); + ctx.getNodes().push_back(llvm::make_unique<GroupEnd>(numfiles)); } return std::error_code(); } @@ -355,7 +354,6 @@ bool GnuLdDriver::parse(int argc, const char *argv[], return false; } - std::unique_ptr<InputGraph> inputGraph(new InputGraph()); std::stack<int> groupStack; int numfiles = 0; @@ -550,7 +548,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[], return false; } int startGroupPos = groupStack.top(); - inputGraph->members().push_back( + ctx->getNodes().push_back( llvm::make_unique<GroupEnd>(numfiles - startGroupPos)); groupStack.pop(); break; @@ -601,8 +599,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[], if (isScript) { if (ctx->logInputFiles()) diagnostics << path << "\n"; - std::error_code ec = evaluateLinkerScript( - *ctx, inputGraph.get(), realpath, diagnostics); + std::error_code ec = evaluateLinkerScript(*ctx, realpath, diagnostics); if (ec) { diagnostics << path << ": Error parsing linker script: " << ec.message() << "\n"; @@ -615,7 +612,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[], for (std::unique_ptr<File> &file : files) { if (ctx->logInputFiles()) diagnostics << file->path() << "\n"; - inputGraph->members().push_back( + ctx->getNodes().push_back( std::unique_ptr<Node>(new FileNode(std::move(file)))); } numfiles += files.size(); @@ -667,7 +664,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[], } // end switch on option ID } // end for - if (inputGraph->members().empty()) { + if (ctx->getNodes().empty()) { diagnostics << "No input files\n"; return false; } @@ -692,7 +689,6 @@ bool GnuLdDriver::parse(int argc, const char *argv[], if (!ctx->validate(diagnostics)) return false; - ctx->setInputGraph(std::move(inputGraph)); context.swap(ctx); return true; } diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 9aa447ac1ec..8977cb7034a 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -799,9 +799,9 @@ parseArgs(int argc, const char **argv, PECOFFLinkingContext &ctx, // Returns true if the given file node has already been added to the input // graph. -static bool hasLibrary(const PECOFFLinkingContext &ctx, File *file) { +static bool hasLibrary(PECOFFLinkingContext &ctx, File *file) { StringRef path = file->path(); - for (std::unique_ptr<Node> &p : ctx.getInputGraph().members()) + for (std::unique_ptr<Node> &p : ctx.getNodes()) if (auto *f = dyn_cast<FileNode>(p.get())) if (f->getFile()->path() == path) return true; @@ -1409,21 +1409,19 @@ bool WinLinkDriver::parse(int argc, const char *argv[], } // Add the input files to the input graph. - if (!ctx.hasInputGraph()) - ctx.setInputGraph(std::unique_ptr<InputGraph>(new InputGraph())); for (std::unique_ptr<File> &file : files) { if (isReadingDirectiveSection) if (file->parse()) return false; ctx.getResolvableSymsFile()->add(file.get()); - ctx.getInputGraph().members().push_back( + ctx.getNodes().push_back( std::unique_ptr<Node>(new FileNode(std::move(file)))); } // Add the library group to the input graph. if (!isReadingDirectiveSection) { // Add a group-end marker. - ctx.getInputGraph().members().push_back(llvm::make_unique<GroupEnd>(0)); + ctx.getNodes().push_back(llvm::make_unique<GroupEnd>(0)); } // Add the library files to the library group. diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 7d6587f2188..cd36c3545d5 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -946,8 +946,7 @@ static bool isLibrary(const std::unique_ptr<Node> &elem) { // so that the Resolver will reiterate over the libraries as long as we find // new undefines from libraries. void MachOLinkingContext::maybeSortInputFiles() { - std::vector<std::unique_ptr<Node>> &elements - = getInputGraph().members(); + std::vector<std::unique_ptr<Node>> &elements = getNodes(); std::stable_sort(elements.begin(), elements.end(), [](const std::unique_ptr<Node> &a, const std::unique_ptr<Node> &b) { diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp index 76ab8521c2c..97ef52a5eaf 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp @@ -90,8 +90,7 @@ std::unique_ptr<File> PECOFFLinkingContext::createUndefinedSymbolFile() const { void PECOFFLinkingContext::addLibraryFile(std::unique_ptr<FileNode> file) { GroupEnd *currentGroupEnd; int pos = -1; - std::vector<std::unique_ptr<Node>> &elements - = getInputGraph().members(); + std::vector<std::unique_ptr<Node>> &elements = getNodes(); for (int i = 0, e = elements.size(); i < e; ++i) { if ((currentGroupEnd = dyn_cast<GroupEnd>(elements[i].get()))) { pos = i; @@ -107,8 +106,7 @@ void PECOFFLinkingContext::addLibraryFile(std::unique_ptr<FileNode> file) { bool PECOFFLinkingContext::createImplicitFiles( std::vector<std::unique_ptr<File>> &) { pecoff::ResolvableSymbols* syms = getResolvableSymsFile(); - std::vector<std::unique_ptr<Node>> &members - = getInputGraph().members(); + std::vector<std::unique_ptr<Node>> &members = getNodes(); // Create a file for the entry point function. std::unique_ptr<FileNode> entry(new FileNode( diff --git a/lld/unittests/DriverTests/DriverTest.h b/lld/unittests/DriverTests/DriverTest.h index c854e382aed..185d470a719 100644 --- a/lld/unittests/DriverTests/DriverTest.h +++ b/lld/unittests/DriverTests/DriverTest.h @@ -27,12 +27,12 @@ protected: // Convenience method for getting number of input files. int inputFileCount() { - return linkingContext()->getInputGraph().members().size(); + return linkingContext()->getNodes().size(); } // Convenience method for getting i'th input files name. std::string inputFile(int index) { - Node &node = *linkingContext()->getInputGraph().members()[index]; + Node &node = *linkingContext()->getNodes()[index]; if (node.kind() == Node::Kind::File) return cast<FileNode>(&node)->getFile()->path(); llvm_unreachable("not handling other types of input files"); |

