[lld] r226149 - Remove InputGraph and use std::vector<Node> instead.
Rui Ueyama
ruiu at google.com
Thu Jan 15 00:46:36 PST 2015
Author: ruiu
Date: Thu Jan 15 02:46:36 2015
New Revision: 226149
URL: http://llvm.org/viewvc/llvm-project?rev=226149&view=rev
Log:
Remove InputGraph and use std::vector<Node> instead.
In total we have removed more than 1000 lines!
Modified:
lld/trunk/include/lld/Core/InputGraph.h
lld/trunk/include/lld/Core/LinkingContext.h
lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/trunk/lib/Core/Resolver.cpp
lld/trunk/lib/Driver/CoreDriver.cpp
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/Driver/Driver.cpp
lld/trunk/lib/Driver/GnuLdDriver.cpp
lld/trunk/lib/Driver/WinLinkDriver.cpp
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
lld/trunk/unittests/DriverTests/DriverTest.h
Modified: lld/trunk/include/lld/Core/InputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/InputGraph.h (original)
+++ lld/trunk/include/lld/Core/InputGraph.h Thu Jan 15 02:46:36 2015
@@ -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.
Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Thu Jan 15 02:46:36 2015
@@ -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;
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Thu Jan 15 02:46:36 2015
@@ -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) {
Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Thu Jan 15 02:46:36 2015
@@ -232,8 +232,7 @@ void Resolver::addAtoms(const std::vecto
// 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,
}
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())) {
Modified: lld/trunk/lib/Driver/CoreDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/CoreDriver.cpp?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/lib/Driver/CoreDriver.cpp (original)
+++ lld/trunk/lib/Driver/CoreDriver.cpp Thu Jan 15 02:46:36 2015
@@ -103,8 +103,6 @@ bool CoreDriver::parse(int argc, const c
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 c
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 c
}
}
- 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);
}
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Thu Jan 15 02:46:36 2015
@@ -113,14 +113,13 @@ static std::string canonicalizePath(Stri
}
}
-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(St
// 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(Stri
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, con
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, con
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, con
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, con
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, con
}
}
- 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);
}
Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Thu Jan 15 02:46:36 2015
@@ -74,8 +74,7 @@ bool Driver::link(LinkingContext &contex
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 &contex
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 &contex
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 &contex
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)));
}
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Thu Jan 15 02:46:36 2015
@@ -111,7 +111,6 @@ maybeExpandResponseFiles(int argc, const
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
}
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 &
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
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
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
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
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
} // 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
if (!ctx->validate(diagnostics))
return false;
- ctx->setInputGraph(std::move(inputGraph));
context.swap(ctx);
return true;
}
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu Jan 15 02:46:36 2015
@@ -799,9 +799,9 @@ parseArgs(int argc, const char **argv, P
// 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, cons
}
// 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.
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Thu Jan 15 02:46:36 2015
@@ -946,8 +946,7 @@ static bool isLibrary(const std::unique_
// 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) {
Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Thu Jan 15 02:46:36 2015
@@ -90,8 +90,7 @@ std::unique_ptr<File> PECOFFLinkingConte
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::addLibraryFil
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(
Modified: lld/trunk/unittests/DriverTests/DriverTest.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/DriverTest.h?rev=226149&r1=226148&r2=226149&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/DriverTest.h (original)
+++ lld/trunk/unittests/DriverTests/DriverTest.h Thu Jan 15 02:46:36 2015
@@ -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");
More information about the llvm-commits
mailing list