mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-15 04:00:56 +00:00
[BOLT][NFC] Simplify YAMLProfileReader
- Add `FunctionSet` type alias. - Use any_of - Use ErrorOr handling pattern Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D156043
This commit is contained in:
parent
cdf7ca6db7
commit
e8a75c3f6e
@ -51,17 +51,17 @@ private:
|
|||||||
/// Map a function ID from a YAML profile to a BinaryFunction object.
|
/// Map a function ID from a YAML profile to a BinaryFunction object.
|
||||||
std::vector<BinaryFunction *> YamlProfileToFunction;
|
std::vector<BinaryFunction *> YamlProfileToFunction;
|
||||||
|
|
||||||
|
using FunctionSet = std::unordered_set<const BinaryFunction *>;
|
||||||
/// To keep track of functions that have a matched profile before the profile
|
/// To keep track of functions that have a matched profile before the profile
|
||||||
/// is attributed.
|
/// is attributed.
|
||||||
std::unordered_set<const BinaryFunction *> ProfiledFunctions;
|
FunctionSet ProfiledFunctions;
|
||||||
|
|
||||||
/// For LTO symbol resolution.
|
/// For LTO symbol resolution.
|
||||||
/// Map a common LTO prefix to a list of YAML profiles matching the prefix.
|
/// Map a common LTO prefix to a list of YAML profiles matching the prefix.
|
||||||
StringMap<std::vector<yaml::bolt::BinaryFunctionProfile *>> LTOCommonNameMap;
|
StringMap<std::vector<yaml::bolt::BinaryFunctionProfile *>> LTOCommonNameMap;
|
||||||
|
|
||||||
/// Map a common LTO prefix to a set of binary functions.
|
/// Map a common LTO prefix to a set of binary functions.
|
||||||
StringMap<std::unordered_set<const BinaryFunction *>>
|
StringMap<FunctionSet> LTOCommonNameFunctionMap;
|
||||||
LTOCommonNameFunctionMap;
|
|
||||||
|
|
||||||
/// Strict matching of a name in a profile to its contents.
|
/// Strict matching of a name in a profile to its contents.
|
||||||
StringMap<yaml::bolt::BinaryFunctionProfile *> ProfileNameToProfile;
|
StringMap<yaml::bolt::BinaryFunctionProfile *> ProfileNameToProfile;
|
||||||
|
@ -36,13 +36,12 @@ namespace llvm {
|
|||||||
namespace bolt {
|
namespace bolt {
|
||||||
|
|
||||||
bool YAMLProfileReader::isYAML(const StringRef Filename) {
|
bool YAMLProfileReader::isYAML(const StringRef Filename) {
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
|
if (auto MB = MemoryBuffer::getFileOrSTDIN(Filename)) {
|
||||||
MemoryBuffer::getFileOrSTDIN(Filename);
|
StringRef Buffer = (*MB)->getBuffer();
|
||||||
if (std::error_code EC = MB.getError())
|
return Buffer.startswith("---\n");
|
||||||
report_error(Filename, EC);
|
} else {
|
||||||
StringRef Buffer = MB.get()->getBuffer();
|
report_error(Filename, MB.getError());
|
||||||
if (Buffer.startswith("---\n"))
|
}
|
||||||
return true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,13 +65,9 @@ void YAMLProfileReader::buildNameMaps(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool YAMLProfileReader::hasLocalsWithFileName() const {
|
bool YAMLProfileReader::hasLocalsWithFileName() const {
|
||||||
for (const StringMapEntry<yaml::bolt::BinaryFunctionProfile *> &KV :
|
return llvm::any_of(ProfileNameToProfile.keys(), [](StringRef FuncName) {
|
||||||
ProfileNameToProfile) {
|
return FuncName.count('/') == 2 && FuncName[0] != '/';
|
||||||
const StringRef &FuncName = KV.getKey();
|
});
|
||||||
if (FuncName.count('/') == 2 && FuncName[0] != '/')
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YAMLProfileReader::parseFunctionProfile(
|
bool YAMLProfileReader::parseFunctionProfile(
|
||||||
@ -327,12 +322,9 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
|
|||||||
|
|
||||||
auto profileMatches = [](const yaml::bolt::BinaryFunctionProfile &Profile,
|
auto profileMatches = [](const yaml::bolt::BinaryFunctionProfile &Profile,
|
||||||
BinaryFunction &BF) {
|
BinaryFunction &BF) {
|
||||||
if (opts::IgnoreHash && Profile.NumBasicBlocks == BF.size())
|
if (opts::IgnoreHash)
|
||||||
return true;
|
return Profile.NumBasicBlocks == BF.size();
|
||||||
if (!opts::IgnoreHash &&
|
return Profile.Hash == static_cast<uint64_t>(BF.getHash());
|
||||||
Profile.Hash == static_cast<uint64_t>(BF.getHash()))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// We have to do 2 passes since LTO introduces an ambiguity in function
|
// We have to do 2 passes since LTO introduces an ambiguity in function
|
||||||
|
Loading…
Reference in New Issue
Block a user