[lld] r192277 - [Layout] Assign ordinals in Resolution order.
Shankar Easwaran
shankare at codeaurora.org
Tue Oct 8 22:23:23 PDT 2013
Author: shankare
Date: Wed Oct 9 00:23:23 2013
New Revision: 192277
URL: http://llvm.org/viewvc/llvm-project?rev=192277&view=rev
Log:
[Layout] Assign ordinals in Resolution order.
Modified:
lld/trunk/include/lld/Core/File.h
lld/trunk/include/lld/Core/LinkingContext.h
lld/trunk/include/lld/Driver/InputGraph.h
lld/trunk/include/lld/ReaderWriter/FileArchive.h
lld/trunk/lib/Core/LinkingContext.cpp
lld/trunk/lib/Core/Resolver.cpp
lld/trunk/lib/Driver/Driver.cpp
lld/trunk/lib/Driver/InputGraph.cpp
lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Wed Oct 9 00:23:23 2013
@@ -73,12 +73,11 @@ public:
return _ordinal;
}
- /// Sets the command line order of the file. The parameter must
- /// also be incremented to the next available ordinal number.
- virtual void setOrdinalAndIncrement(uint64_t &ordinal) const {
- _ordinal = ordinal;
- ++ordinal;
- }
+ /// Returns true/false depending on whether an ordinal has been set.
+ bool hasOrdinal() const { return (_ordinal != UINT64_MAX); }
+
+ /// Sets the command line order of the file.
+ void setOrdinal(uint64_t ordinal) const { _ordinal = ordinal; }
public:
template <typename T> class atom_iterator; // forward reference
Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Wed Oct 9 00:23:23 2013
@@ -304,7 +304,8 @@ public:
/// The LinkingContext's can override the default behavior to change the way
/// the resolver operates. This uses the currentInputElement. When there are
/// no more files to be processed an appropriate InputGraphError is
- /// returned.
+ /// returned. Ordinals are assigned to files returned by nextFile, which means
+ /// ordinals would be assigned in the way files are resolved.
virtual ErrorOr<File &> nextFile();
/// Set the resolver state for the current Input element This is used by the
@@ -314,6 +315,9 @@ public:
/// atoms.
virtual void setResolverState(uint32_t resolverState);
+ /// Return the next ordinal and Increment it.
+ virtual uint64_t getNextOrdinalAndIncrement() { return _nextOrdinal++; }
+
/// @}
/// \name Methods needed by YAML I/O and error messages to convert Kind values
@@ -363,6 +367,7 @@ protected:
std::unique_ptr<InputGraph> _inputGraph;
mutable llvm::BumpPtrAllocator _allocator;
InputElement *_currentInputElement;
+ uint64_t _nextOrdinal;
private:
/// Validate the subclass bits. Only called by validate.
Modified: lld/trunk/include/lld/Driver/InputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/InputGraph.h?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/InputGraph.h (original)
+++ lld/trunk/include/lld/Driver/InputGraph.h Wed Oct 9 00:23:23 2013
@@ -67,9 +67,6 @@ public:
/// \brief Set Ordinals for all the InputElements that form the InputGraph
virtual bool assignOrdinals();
- /// \brief Set ordinals for all the Files that are part of the InputElements
- virtual bool assignFileOrdinals(uint64_t &ordinal);
-
/// Destructor
virtual ~InputGraph() {}
@@ -149,10 +146,6 @@ public:
_ordinal = ordinal;
}
- /// \brief Assign File ordinals for files contained
- /// in the InputElement
- virtual void assignFileOrdinals(uint64_t &fileOrdinal) = 0;
-
virtual int64_t getOrdinal() const { return _ordinal; }
virtual int64_t weight() const { return _weight; }
@@ -228,10 +221,6 @@ public:
return make_range(_elements.begin(), _elements.end());
}
- /// \brief Assign File ordinals for files contained
- /// in the InputElement
- virtual void assignFileOrdinals(uint64_t &startOrdinal);
-
virtual void resetNextIndex() {
_currentElementIndex = _nextElementIndex = 0;
for (auto &elem : _elements)
@@ -306,10 +295,6 @@ public:
_files.push_back(std::move(ai));
}
- /// \brief Assign File ordinals for files contained
- /// in the InputElement
- virtual void assignFileOrdinals(uint64_t &startOrdinal);
-
/// \brief Reset the file index if the resolver needs to process
/// the node again.
virtual void resetNextIndex();
@@ -426,10 +411,6 @@ public:
// Do nothing here.
virtual void resetNextIndex() {}
- /// \brief Assign File ordinals for files contained
- /// in the InputElement
- virtual void assignFileOrdinals(uint64_t &startOrdinal);
-
protected:
StringRef _path; // A string associated with this file.
InputGraph::FileVectorT _files; // Vector of lld::File objects
Modified: lld/trunk/include/lld/ReaderWriter/FileArchive.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/FileArchive.h?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/FileArchive.h (original)
+++ lld/trunk/include/lld/ReaderWriter/FileArchive.h Wed Oct 9 00:23:23 2013
@@ -56,8 +56,6 @@ public:
assert(result.size() == 1);
- result[0]->setOrdinalAndIncrement(_curChildOrd);
-
// give up the pointer so that this object no longer manages it
return result[0].release();
}
@@ -79,23 +77,9 @@ public:
if ((ec = _context.getDefaultReader().parseFile(mbc, result)))
return ec;
}
- for (auto &file : result)
- file->setOrdinalAndIncrement(_curChildOrd);
return error_code::success();
}
- /// \brief members
-
- virtual void setOrdinalAndIncrement(uint64_t &ordinal) const {
- _ordinal = ordinal++;
- _curChildOrd = _ordinal;
- // Leave space in ordinal range for all children
- for (auto mf = _archive->begin_children(),
- me = _archive->end_children(); mf != me; ++mf) {
- ordinal++;
- }
- }
-
virtual const atom_collection<DefinedAtom> &defined() const {
return _definedAtoms;
}
Modified: lld/trunk/lib/Core/LinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/LinkingContext.cpp?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/lib/Core/LinkingContext.cpp (original)
+++ lld/trunk/lib/Core/LinkingContext.cpp Wed Oct 9 00:23:23 2013
@@ -24,7 +24,8 @@ LinkingContext::LinkingContext()
_warnIfCoalesableAtomsHaveDifferentLoadName(false),
_printRemainingUndefines(true), _allowRemainingUndefines(false),
_logInputFiles(false), _allowShlibUndefines(false),
- _outputFileType(OutputFileType::Default), _currentInputElement(nullptr) {}
+ _outputFileType(OutputFileType::Default), _currentInputElement(nullptr),
+ _nextOrdinal(0) {}
LinkingContext::~LinkingContext() {}
Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Wed Oct 9 00:23:23 2013
@@ -108,8 +108,10 @@ void Resolver::handleArchiveFile(const F
StringRef undefName = undefAtom->name();
// load for previous undefine may also have loaded this undefine
if (!_symbolTable.isDefined(undefName)) {
- if (const File *member = archiveFile->find(undefName, false))
+ if (const File *member = archiveFile->find(undefName, false)) {
+ member->setOrdinal(_context.getNextOrdinalAndIncrement());
handleFile(*member);
+ }
}
// If the undefined symbol has an alternative name, try to resolve the
// symbol with the name to give it a second chance. This feature is used
@@ -132,8 +134,10 @@ void Resolver::handleArchiveFile(const F
assert(curAtom != nullptr);
if (const DefinedAtom *curDefAtom = dyn_cast<DefinedAtom>(curAtom)) {
if (curDefAtom->merge() == DefinedAtom::mergeAsTentative) {
- if (const File *member = archiveFile->find(tentDefName, true))
+ if (const File *member = archiveFile->find(tentDefName, true)) {
+ member->setOrdinal(_context.getNextOrdinalAndIncrement());
handleFile(*member);
+ }
}
}
}
@@ -147,7 +151,6 @@ void Resolver::handleSharedLibrary(const
// Add all the atoms from the shared library
handleFile(*sharedLibrary);
-
do {
undefineGenCount = _symbolTable.size();
std::vector<const UndefinedAtom *> undefines;
@@ -295,12 +298,20 @@ void Resolver::resolveUndefines() {
_context.setResolverState(Resolver::StateNoChange);
if (error_code(nextFile) == InputGraphError::no_more_files)
break;
- if (nextFile->kind() == File::kindObject)
+ if (nextFile->kind() == File::kindObject) {
+ nextFile->setOrdinal(_context.getNextOrdinalAndIncrement());
handleFile(*nextFile);
- if (nextFile->kind() == File::kindArchiveLibrary)
+ }
+ if (nextFile->kind() == File::kindArchiveLibrary) {
+ if (!nextFile->hasOrdinal())
+ nextFile->setOrdinal(_context.getNextOrdinalAndIncrement());
handleArchiveFile(*nextFile);
- if (nextFile->kind() == File::kindSharedLibrary)
+ }
+ if (nextFile->kind() == File::kindSharedLibrary) {
+ if (!nextFile->hasOrdinal())
+ nextFile->setOrdinal(_context.getNextOrdinalAndIncrement());
handleSharedLibrary(*nextFile);
+ }
}
}
Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Wed Oct 9 00:23:23 2013
@@ -104,9 +104,6 @@ bool Driver::link(LinkingContext &contex
context.inputGraph().doPostProcess();
- uint64_t ordinal = 0;
- context.inputGraph().assignFileOrdinals(ordinal);
-
// Do core linking.
ScopedTask resolveTask(getDefaultDomain(), "Resolve");
Resolver resolver(context);
Modified: lld/trunk/lib/Driver/InputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/InputGraph.cpp?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/lib/Driver/InputGraph.cpp (original)
+++ lld/trunk/lib/Driver/InputGraph.cpp Wed Oct 9 00:23:23 2013
@@ -29,12 +29,6 @@ bool InputGraph::assignOrdinals() {
return true;
}
-bool InputGraph::assignFileOrdinals(uint64_t &startOrdinal) {
- for (auto &ie : _inputArgs)
- ie->assignFileOrdinals(startOrdinal);
- return true;
-}
-
void InputGraph::doPostProcess() {
std::stable_sort(_inputArgs.begin(), _inputArgs.end(), sortInputElements);
}
@@ -103,13 +97,6 @@ FileNode::FileNode(StringRef path, int64
: InputElement(InputElement::Kind::File, ordinal), _path(path),
_resolveState(Resolver::StateNoChange), _nextFileIndex(0) {}
-/// \brief Assign File ordinals for files contained
-/// in the InputElement
-void FileNode::assignFileOrdinals(uint64_t &startOrdinal) {
- for (auto &file : _files)
- file->setOrdinalAndIncrement(startOrdinal);
-}
-
/// \brief Read the file into _buffer.
error_code
FileNode::readFile(const LinkingContext &ctx, raw_ostream &diagnostics) {
@@ -147,13 +134,6 @@ void FileNode::resetNextIndex() {
/// ControlNode
-/// \brief Assign File ordinals for files contained
-/// in the InputElement
-void ControlNode::assignFileOrdinals(uint64_t &startOrdinal) {
- for (auto &elem : _elements)
- elem->assignFileOrdinals(startOrdinal);
-}
-
/// \brief Get the resolver State. The return value of the resolve
/// state for a control node is the or'ed value of the resolve states
/// contained in it.
@@ -178,13 +158,6 @@ SimpleFileNode::SimpleFileNode(StringRef
: InputElement(InputElement::Kind::SimpleFile, ordinal), _path(path),
_nextFileIndex(0), _resolveState(Resolver::StateNoChange) {}
-/// \brief Assign File ordinals for files contained
-/// in the InputElement
-void SimpleFileNode::assignFileOrdinals(uint64_t &startOrdinal) {
- for (auto &file : _files)
- file->setOrdinalAndIncrement(startOrdinal);
-}
-
/// Group
/// \brief Return the next file that need to be processed by the resolver.
Modified: lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp Wed Oct 9 00:23:23 2013
@@ -34,10 +34,6 @@ public:
return f->kind() == kindLinkerScript;
}
- virtual void setOrdinalAndIncrement(uint64_t &ordinal) const {
- _ordinal = ordinal++;
- }
-
virtual const LinkingContext &getLinkingContext() const { return _context; }
virtual const atom_collection<DefinedAtom> &defined() const {
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=192277&r1=192276&r2=192277&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Wed Oct 9 00:23:23 2013
@@ -600,14 +600,6 @@ template <> struct MappingTraits<const l
const lld::File *denormalize(IO &io) { return this; }
- virtual void setOrdinalAndIncrement(uint64_t &ordinal) const {
- _ordinal = ordinal++;
- // Assign sequential ordinals to member files
- for (const ArchMember &member : _members) {
- member._content->setOrdinalAndIncrement(ordinal);
- }
- }
-
virtual const atom_collection<lld::DefinedAtom> &defined() const {
return _noDefinedAtoms;
}
More information about the llvm-commits
mailing list