[lld-macho][NFC] Encapsulate symbol priority implementation.

Just some code clean up.

Reviewed By: #lld-macho, int3

Differential Revision: https://reviews.llvm.org/D122752
This commit is contained in:
Roger Kim
2022-03-31 13:29:03 -04:00
parent 0e890904ea
commit 34b9729561
3 changed files with 18 additions and 20 deletions

View File

@@ -30,7 +30,6 @@ namespace macho {
class InputSection;
class Symbol;
struct SymbolPriorityEntry;
using NamePair = std::pair<llvm::StringRef, llvm::StringRef>;
using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>;
@@ -191,20 +190,6 @@ struct Configuration {
}
};
// The symbol with the highest priority should be ordered first in the output
// section (modulo input section contiguity constraints). Using priority
// (highest first) instead of order (lowest first) has the convenient property
// that the default-constructed zero priority -- for symbols/sections without a
// user-defined order -- naturally ends up putting them at the end of the
// output.
struct SymbolPriorityEntry {
// The priority given to a matching symbol, regardless of which object file
// it originated from.
size_t anyObjectFile = 0;
// The priority given to a matching symbol from a particular object file.
llvm::DenseMap<llvm::StringRef, size_t> objectFiles;
};
// Whether to force-load an archive.
enum class ForceLoad {
Default, // Apply -all_load or -ObjC behaviors if those flags are enabled

View File

@@ -283,11 +283,10 @@ void macho::PriorityBuilder::extractCallGraphProfile() {
entry.toIndex < obj->symbols.size());
auto *fromSym = dyn_cast_or_null<Defined>(obj->symbols[entry.fromIndex]);
auto *toSym = dyn_cast_or_null<Defined>(obj->symbols[entry.toIndex]);
if (!fromSym || !toSym ||
(hasOrderFile &&
(getSymbolPriority(fromSym) || getSymbolPriority(toSym))))
continue;
callGraphProfile[{fromSym->isec, toSym->isec}] += entry.count;
if (fromSym && toSym &&
(!hasOrderFile ||
(!getSymbolPriority(fromSym) && !getSymbolPriority(toSym))))
callGraphProfile[{fromSym->isec, toSym->isec}] += entry.count;
}
}
}

View File

@@ -56,6 +56,20 @@ public:
llvm::DenseMap<const InputSection *, size_t> buildInputSectionPriorities();
private:
// The symbol with the highest priority should be ordered first in the output
// section (modulo input section contiguity constraints). Using priority
// (highest first) instead of order (lowest first) has the convenient property
// that the default-constructed zero priority -- for symbols/sections without
// a user-defined order -- naturally ends up putting them at the end of the
// output.
struct SymbolPriorityEntry {
// The priority given to a matching symbol, regardless of which object file
// it originated from.
size_t anyObjectFile = 0;
// The priority given to a matching symbol from a particular object file.
llvm::DenseMap<llvm::StringRef, size_t> objectFiles;
};
llvm::Optional<size_t> getSymbolPriority(const Defined *sym);
llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities;
llvm::MapVector<SectionPair, uint64_t> callGraphProfile;