diff --git a/bolt/include/bolt/Profile/YAMLProfileReader.h b/bolt/include/bolt/Profile/YAMLProfileReader.h index bd5a86fd676a59..a6f0fd6f3251f0 100644 --- a/bolt/include/bolt/Profile/YAMLProfileReader.h +++ b/bolt/include/bolt/Profile/YAMLProfileReader.h @@ -105,7 +105,7 @@ class YAMLProfileReader : public ProfileReaderBase { yaml::bolt::BinaryProfile YamlBP; /// Map a function ID from a YAML profile to a BinaryFunction object. - std::vector YamlProfileToFunction; + DenseMap YamlProfileToFunction; using FunctionSet = std::unordered_set; /// To keep track of functions that have a matched profile before the profile @@ -162,8 +162,6 @@ class YAMLProfileReader : public ProfileReaderBase { /// Update matched YAML -> BinaryFunction pair. void matchProfileToFunction(yaml::bolt::BinaryFunctionProfile &YamlBF, BinaryFunction &BF) { - if (YamlBF.Id >= YamlProfileToFunction.size()) - YamlProfileToFunction.resize(YamlBF.Id + 1); YamlProfileToFunction[YamlBF.Id] = &BF; YamlBF.Used = true; diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index fe0fcfdcd42f9b..a5dc8492b59003 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -238,9 +238,7 @@ bool YAMLProfileReader::parseFunctionProfile( BB.setExecutionCount(YamlBB.ExecCount); for (const yaml::bolt::CallSiteInfo &YamlCSI : YamlBB.CallSites) { - BinaryFunction *Callee = YamlCSI.DestId < YamlProfileToFunction.size() - ? YamlProfileToFunction[YamlCSI.DestId] - : nullptr; + BinaryFunction *Callee = YamlProfileToFunction.lookup(YamlCSI.DestId); bool IsFunction = Callee ? true : false; MCSymbol *CalleeSymbol = nullptr; if (IsFunction) @@ -703,7 +701,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { break; } } - YamlProfileToFunction.resize(YamlBP.Functions.size() + 1); + YamlProfileToFunction.reserve(YamlBP.Functions.size()); // Computes hash for binary functions. if (opts::MatchProfileWithFunctionHash) { @@ -756,12 +754,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { NormalizeByCalls = usesEvent("branches"); uint64_t NumUnused = 0; for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) { - if (YamlBF.Id >= YamlProfileToFunction.size()) { - // Such profile was ignored. - ++NumUnused; - continue; - } - if (BinaryFunction *BF = YamlProfileToFunction[YamlBF.Id]) + if (BinaryFunction *BF = YamlProfileToFunction.lookup(YamlBF.Id)) parseFunctionProfile(*BF, YamlBF); else ++NumUnused;