[lld] 34b9729 - [lld-macho][NFC] Encapsulate symbol priority implementation.
Roger Kim via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 31 10:47:46 PDT 2022
Author: Roger Kim
Date: 2022-03-31T13:47:38-04:00
New Revision: 34b972956158e37551cd7c64c3b67ebe8b21a0ff
URL: https://github.com/llvm/llvm-project/commit/34b972956158e37551cd7c64c3b67ebe8b21a0ff
DIFF: https://github.com/llvm/llvm-project/commit/34b972956158e37551cd7c64c3b67ebe8b21a0ff.diff
LOG: [lld-macho][NFC] Encapsulate symbol priority implementation.
Just some code clean up.
Reviewed By: #lld-macho, int3
Differential Revision: https://reviews.llvm.org/D122752
Added:
Modified:
lld/MachO/Config.h
lld/MachO/SectionPriorities.cpp
lld/MachO/SectionPriorities.h
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index ca81e2676a8e6..60dd3831c62d8 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -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
diff --git a/lld/MachO/SectionPriorities.cpp b/lld/MachO/SectionPriorities.cpp
index 01a8f91160227..cdabd3e9ef465 100644
--- a/lld/MachO/SectionPriorities.cpp
+++ b/lld/MachO/SectionPriorities.cpp
@@ -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;
}
}
}
diff --git a/lld/MachO/SectionPriorities.h b/lld/MachO/SectionPriorities.h
index 5275ed2a2f242..d27fef92f559f 100644
--- a/lld/MachO/SectionPriorities.h
+++ b/lld/MachO/SectionPriorities.h
@@ -56,6 +56,20 @@ class PriorityBuilder {
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;
More information about the llvm-commits
mailing list