From: Rui Ueyama Date: Thu, 15 Jan 2015 08:31:46 +0000 (+0000) Subject: Rename InputElement Node. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=61635440a935fd8192fcc3c76bf6bac7b68166b3;p=platform%2Fupstream%2Fllvm.git Rename InputElement Node. InputElement was named that because it's an element of an InputGraph. It's losing the origin because the InputGraph is now being removed. InputElement's subclass is FileNode, that naming inconsistency needed to be fixed. llvm-svn: 226147 --- diff --git a/lld/include/lld/Core/InputGraph.h b/lld/include/lld/Core/InputGraph.h index 32b1dfe..a2e9c2d 100644 --- a/lld/include/lld/Core/InputGraph.h +++ b/lld/include/lld/Core/InputGraph.h @@ -30,48 +30,42 @@ namespace lld { -class InputElement; +class Node; class LinkingContext; class InputGraph { public: - std::vector> &members() { + std::vector> &members() { return _members; } protected: - std::vector> _members; + std::vector> _members; }; -/// \brief This describes each element in the InputGraph. The Kind -/// determines what the current node contains. -class InputElement { +// 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. +class Node { public: - /// Each input element in the graph can be a File or a control - enum class Kind : uint8_t { - File, // Represents a type associated with File Nodes - GroupEnd, - }; - - InputElement(Kind type) : _kind(type) {} - virtual ~InputElement() {} - - /// Return the Element Type for an Input Element + enum class Kind { File, GroupEnd }; + Node(Kind type) : _kind(type) {} + virtual ~Node() {} virtual Kind kind() const { return _kind; } -protected: - Kind _kind; // The type of the Element +private: + Kind _kind; }; // This is a marker for --end-group. getSize() returns the number of // files between the corresponding --start-group and this marker. -class GroupEnd : public InputElement { +class GroupEnd : public Node { public: - GroupEnd(int size) : InputElement(Kind::GroupEnd), _size(size) {} + GroupEnd(int size) : Node(Kind::GroupEnd), _size(size) {} int getSize() const { return _size; } - static inline bool classof(const InputElement *a) { + static inline bool classof(const Node *a) { return a->kind() == Kind::GroupEnd; } @@ -80,15 +74,15 @@ private: }; // A container of File. -class FileNode : public InputElement { +class FileNode : public Node { public: explicit FileNode(std::unique_ptr f) - : InputElement(InputElement::Kind::File), _file(std::move(f)) {} + : Node(Node::Kind::File), _file(std::move(f)) {} virtual ~FileNode() {} - static inline bool classof(const InputElement *a) { - return a->kind() == InputElement::Kind::File; + static inline bool classof(const Node *a) { + return a->kind() == Node::Kind::File; } File *getFile() { return _file.get(); } diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index fb1e9da..9528b17 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -26,7 +26,7 @@ class PassManager; class File; class Writer; class InputGraph; -class InputElement; +class Node; class SharedLibraryFile; /// \brief The LinkingContext class encapsulates "what and how" to link. diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp index ce398ff..1af8233 100644 --- a/lld/lib/Core/Resolver.cpp +++ b/lld/lib/Core/Resolver.cpp @@ -232,7 +232,7 @@ void Resolver::addAtoms(const std::vector &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> &inputs = + std::vector> &inputs = _context.getInputGraph().members(); for (int i = begin; i < end; ++i) if (FileNode *node = dyn_cast(inputs[i].get())) @@ -242,7 +242,7 @@ bool Resolver::undefinesAdded(int begin, int end) { } File *Resolver::getFile(int &index, int &groupLevel) { - std::vector> &inputs + std::vector> &inputs = _context.getInputGraph().members(); if ((size_t)index >= inputs.size()) return nullptr; diff --git a/lld/lib/Driver/CoreDriver.cpp b/lld/lib/Driver/CoreDriver.cpp index 4a16b02..1a49577 100644 --- a/lld/lib/Driver/CoreDriver.cpp +++ b/lld/lib/Driver/CoreDriver.cpp @@ -153,7 +153,7 @@ bool CoreDriver::parse(int argc, const char *argv[], CoreLinkingContext &ctx, std::vector> files = loadFile(ctx, inputArg->getValue(), false); for (std::unique_ptr &file : files) { - inputGraph->members().push_back(std::unique_ptr( + inputGraph->members().push_back(std::unique_ptr( new FileNode(std::move(file)))); } break; diff --git a/lld/lib/Driver/Driver.cpp b/lld/lib/Driver/Driver.cpp index eac75bf..c9058cc 100644 --- a/lld/lib/Driver/Driver.cpp +++ b/lld/lib/Driver/Driver.cpp @@ -84,7 +84,7 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) { ScopedTask readTask(getDefaultDomain(), "Read Args"); TaskGroup tg; std::mutex diagnosticsMutex; - for (std::unique_ptr &ie : inputGraph.members()) { + for (std::unique_ptr &ie : inputGraph.members()) { 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 diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 2e7ef17..7c6982c 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -275,7 +275,7 @@ evaluateLinkerScript(ELFLinkingContext &ctx, InputGraph *inputGraph, if (ctx.logInputFiles()) diag << file->path() << "\n"; inputGraph->members().push_back( - std::unique_ptr(new FileNode(std::move(file)))); + std::unique_ptr(new FileNode(std::move(file)))); ++numfiles; } } @@ -616,7 +616,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[], if (ctx->logInputFiles()) diagnostics << file->path() << "\n"; inputGraph->members().push_back( - std::unique_ptr(new FileNode(std::move(file)))); + std::unique_ptr(new FileNode(std::move(file)))); } numfiles += files.size(); break; diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 77f3a22..9aa447a 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -801,7 +801,7 @@ parseArgs(int argc, const char **argv, PECOFFLinkingContext &ctx, // graph. static bool hasLibrary(const PECOFFLinkingContext &ctx, File *file) { StringRef path = file->path(); - for (std::unique_ptr &p : ctx.getInputGraph().members()) + for (std::unique_ptr &p : ctx.getInputGraph().members()) if (auto *f = dyn_cast(p.get())) if (f->getFile()->path() == path) return true; @@ -1417,7 +1417,7 @@ bool WinLinkDriver::parse(int argc, const char *argv[], return false; ctx.getResolvableSymsFile()->add(file.get()); ctx.getInputGraph().members().push_back( - std::unique_ptr(new FileNode(std::move(file)))); + std::unique_ptr(new FileNode(std::move(file)))); } // Add the library group to the input graph. diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index ca1e11a..7d6587f 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -928,12 +928,12 @@ bool MachOLinkingContext::customAtomOrderer(const DefinedAtom *left, return true; } -static File *getFirstFile(const std::unique_ptr &elem) { - FileNode *e = dyn_cast(const_cast(elem.get())); +static File *getFirstFile(const std::unique_ptr &elem) { + FileNode *e = dyn_cast(const_cast(elem.get())); return e ? e->getFile() : nullptr; } -static bool isLibrary(const std::unique_ptr &elem) { +static bool isLibrary(const std::unique_ptr &elem) { File *f = getFirstFile(elem); return f && (isa(f) || isa(f)); } @@ -946,11 +946,11 @@ static bool isLibrary(const std::unique_ptr &elem) { // so that the Resolver will reiterate over the libraries as long as we find // new undefines from libraries. void MachOLinkingContext::maybeSortInputFiles() { - std::vector> &elements + std::vector> &elements = getInputGraph().members(); std::stable_sort(elements.begin(), elements.end(), - [](const std::unique_ptr &a, - const std::unique_ptr &b) { + [](const std::unique_ptr &a, + const std::unique_ptr &b) { return !isLibrary(a) && isLibrary(b); }); size_t numLibs = std::count_if(elements.begin(), elements.end(), isLibrary); diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp index de4ddca..76ab852 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp @@ -90,7 +90,7 @@ std::unique_ptr PECOFFLinkingContext::createUndefinedSymbolFile() const { void PECOFFLinkingContext::addLibraryFile(std::unique_ptr file) { GroupEnd *currentGroupEnd; int pos = -1; - std::vector> &elements + std::vector> &elements = getInputGraph().members(); for (int i = 0, e = elements.size(); i < e; ++i) { if ((currentGroupEnd = dyn_cast(elements[i].get()))) { @@ -107,7 +107,7 @@ void PECOFFLinkingContext::addLibraryFile(std::unique_ptr file) { bool PECOFFLinkingContext::createImplicitFiles( std::vector> &) { pecoff::ResolvableSymbols* syms = getResolvableSymsFile(); - std::vector> &members + std::vector> &members = getInputGraph().members(); // Create a file for the entry point function. diff --git a/lld/unittests/DriverTests/DriverTest.h b/lld/unittests/DriverTests/DriverTest.h index 41c5bc5..c854e38 100644 --- a/lld/unittests/DriverTests/DriverTest.h +++ b/lld/unittests/DriverTests/DriverTest.h @@ -32,10 +32,9 @@ protected: // Convenience method for getting i'th input files name. std::string inputFile(int index) { - InputElement &inputElement = - *linkingContext()->getInputGraph().members()[index]; - if (inputElement.kind() == InputElement::Kind::File) - return cast(&inputElement)->getFile()->path(); + Node &node = *linkingContext()->getInputGraph().members()[index]; + if (node.kind() == Node::Kind::File) + return cast(&node)->getFile()->path(); llvm_unreachable("not handling other types of input files"); }