Return a vector rather than mutating a given one.

This is cleaner and as efficient as before.

Differential Revision: http://llvm-reviews.chandlerc.com/D3284

llvm-svn: 205590
This commit is contained in:
Rui Ueyama
2014-04-04 00:15:52 +00:00
parent 8bd093b1e5
commit 8dc9f0a371
3 changed files with 15 additions and 14 deletions

View File

@@ -58,10 +58,10 @@ public:
const Atom *findByName(StringRef sym);
/// @brief returns vector of remaining UndefinedAtoms
void undefines(std::vector<const UndefinedAtom *>&);
std::vector<const UndefinedAtom *> undefines();
/// returns vector of tentative definitions
void tentativeDefinitions(std::vector<StringRef> &);
std::vector<StringRef> tentativeDefinitions();
/// @brief count of by-name entries in symbol table
unsigned int size();

View File

@@ -74,19 +74,16 @@ void Resolver::forEachUndefines(UndefCallback callback,
int64_t undefineGenCount = 0;
do {
undefineGenCount = _symbolTable.size();
std::vector<const UndefinedAtom *> undefines;
_symbolTable.undefines(undefines);
for (const UndefinedAtom *undefAtom : undefines) {
for (const UndefinedAtom *undefAtom : _symbolTable.undefines()) {
StringRef undefName = undefAtom->name();
// load for previous undefine may also have loaded this undefine
if (!_symbolTable.isDefined(undefName))
callback(undefName, false);
}
// search libraries for overrides of common symbols
if (searchForOverrides) {
std::vector<StringRef> tentDefNames;
_symbolTable.tentativeDefinitions(tentDefNames);
for (StringRef tentDefName : tentDefNames) {
for (StringRef tentDefName : _symbolTable.tentativeDefinitions()) {
// Load for previous tentative may also have loaded
// something that overrode this tentative, so always check.
const Atom *curAtom = _symbolTable.findByName(tentDefName);
@@ -359,8 +356,7 @@ void Resolver::deadStripOptimize() {
// error out if some undefines remain
bool Resolver::checkUndefines() {
// build vector of remaining undefined symbols
std::vector<const UndefinedAtom *> undefinedAtoms;
_symbolTable.undefines(undefinedAtoms);
std::vector<const UndefinedAtom *> undefinedAtoms = _symbolTable.undefines();
if (_context.deadStrip()) {
// When dead code stripping, we don't care if dead atoms are undefined.
undefinedAtoms.erase(

View File

@@ -392,7 +392,8 @@ unsigned int SymbolTable::size() {
return _nameTable.size();
}
void SymbolTable::undefines(std::vector<const UndefinedAtom *> &undefs) {
std::vector<const UndefinedAtom *> SymbolTable::undefines() {
std::vector<const UndefinedAtom *> ret;
for (auto it : _nameTable) {
const Atom *atom = it.second;
assert(atom != nullptr);
@@ -400,19 +401,23 @@ void SymbolTable::undefines(std::vector<const UndefinedAtom *> &undefs) {
AtomToAtom::iterator pos = _replacedAtoms.find(undef);
if (pos != _replacedAtoms.end())
continue;
undefs.push_back(undef);
ret.push_back(undef);
}
}
return ret;
}
void SymbolTable::tentativeDefinitions(std::vector<StringRef> &names) {
std::vector<StringRef> SymbolTable::tentativeDefinitions() {
std::vector<StringRef> ret;
for (auto entry : _nameTable) {
const Atom *atom = entry.second;
StringRef name = entry.first;
assert(atom != nullptr);
if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
if (defAtom->merge() == DefinedAtom::mergeAsTentative)
names.push_back(name);
ret.push_back(name);
}
return ret;
}
} // namespace lld