[llvm-branch-commits] [llvm] [BOLT] Factor out MCInstReference from gadget scanner (NFC) (PR #138655)

2025-05-28 Thread Maksim Panchenko via llvm-branch-commits
@@ -0,0 +1,57 @@ +//===- bolt/Passes/MCInstUtils.cpp ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apa

[llvm-branch-commits] [llvm] [BOLT] Factor out MCInstReference from gadget scanner (NFC) (PR #138655)

2025-05-28 Thread Maksim Panchenko via llvm-branch-commits
@@ -0,0 +1,168 @@ +//===- bolt/Core/MCInstUtils.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[llvm-branch-commits] [llvm] [BOLT] Factor out MCInstReference from gadget scanner (NFC) (PR #138655)

2025-05-28 Thread Maksim Panchenko via llvm-branch-commits
@@ -0,0 +1,168 @@ +//===- bolt/Core/MCInstUtils.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[llvm-branch-commits] [llvm] [BOLT] Factor out MCInstReference from gadget scanner (NFC) (PR #138655)

2025-05-28 Thread Maksim Panchenko via llvm-branch-commits
@@ -1682,48 +1648,66 @@ void Analysis::runOnFunction(BinaryFunction &BF, } } +// Compute the instruction address for printing (may be slow). +static uint64_t getAddress(const MCInstReference &Inst) { + const BinaryFunction *BF = Inst.getFunction(); + + if (Inst.hasCFG()) {

[llvm-branch-commits] [llvm] [BOLT] Factor out MCInstReference from gadget scanner (NFC) (PR #138655)

2025-05-28 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. As an NFC this change looks good to me. I've left a comments for a follow-up. https://github.com/llvm/llvm-project/pull/138655 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org

[llvm-branch-commits] [llvm] [BOLT] Factor out MCInstReference from gadget scanner (NFC) (PR #138655)

2025-05-28 Thread Maksim Panchenko via llvm-branch-commits
@@ -0,0 +1,168 @@ +//===- bolt/Core/MCInstUtils.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[llvm-branch-commits] [llvm] [BOLT] Factor out MCInstReference from gadget scanner (NFC) (PR #138655)

2025-05-28 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/138655 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [BOLT] Print heatmap from perf2bolt (PR #139194)

2025-05-12 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/139194 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [BOLT] Drop perf2bolt cold samples diagnostic (PR #139337)

2025-05-12 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/139337 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT][heatmap] Compute section utilization and partition score (PR #139193)

2025-05-12 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. The code LGTM. For practical applications, we sometimes use 3-way function splitting resulting in code being broken into more than two partitions. In such case, the most interesting metrics and score should be attached to non-cold partition

[llvm-branch-commits] [llvm] [BOLT] Build heatmap with pre-aggregated data (PR #138798)

2025-05-12 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/138798 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT][NFC] Define AArch64 jump table types (PR #132109)

2025-04-09 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb commented: I expect that eventually we will get RISC-V support for jump tables. In this context, I would prefer to keep the format of the jump table itself separate from the underlying architecture. I.e. we can use JTs with an absolute 64-bit addressing on any platfor

[llvm-branch-commits] [llvm] [BOLT] Make DataflowAnalysis::getStateBefore() const (NFC) (PR #133308)

2025-03-27 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/133308 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Skip out-of-range pending relocations (PR #116964)

2025-03-27 Thread Maksim Panchenko via llvm-branch-commits
@@ -174,11 +175,31 @@ void BinarySection::flushPendingRelocations(raw_pwrite_stream &OS, OS.pwrite(Patch.Bytes.data(), Patch.Bytes.size(), SectionFileOffset + Patch.Offset); + uint64_t SkippedPendingRelocations = 0; for (Relocation &Reloc : PendingReloca

[llvm-branch-commits] [llvm] [BOLT] Skip out-of-range pending relocations (PR #116964)

2025-03-27 Thread Maksim Panchenko via llvm-branch-commits
@@ -1689,6 +1689,8 @@ bool BinaryFunction::scanExternalRefs() { // Create relocation for every fixup. for (const MCFixup &Fixup : Fixups) { std::optional Rel = BC.MIB->createRelocation(Fixup, *BC.MAB); + // Can be skipped under the right circumstances. --

[llvm-branch-commits] [llvm] [BOLT] Skip out-of-range pending relocations (PR #116964)

2025-03-27 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb commented: Looks good! Minor nits. https://github.com/llvm/llvm-project/pull/116964 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Skip out-of-range pending relocations (PR #116964)

2025-03-27 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/116964 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] release/20.x: [BOLT, test] Link against a shared object to test PLT (#125625) (PR #126351)

2025-02-10 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/126351 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Fix counts aggregation in merge-fdata (PR #119652)

2024-12-14 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/119652 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [BOLT] Support perf2bolt-N in the driver (PR #111072)

2024-10-13 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. LGTM. Please add the description of the problem this PR fixes and link any related issue(s). https://github.com/llvm/llvm-project/pull/111072 ___ llvm-branch-commits mailing list llvm-branch-commit

[llvm-branch-commits] [BOLT][NFC] Speedup BAT::writeMaps (PR #112061)

2024-10-11 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. LGTM. I'd mark this PR as "NFCI". https://github.com/llvm/llvm-project/pull/112061 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/list

[llvm-branch-commits] [llvm] [BOLT] Allow builtin_unreachable to be at MaxSize address (PR #111771)

2024-10-09 Thread Maksim Panchenko via llvm-branch-commits
@@ -1365,8 +1365,9 @@ Error BinaryFunction::disassemble() { if (containsAddress(TargetAddress)) { TargetSymbol = getOrCreateLocalLabel(TargetAddress); } else { -if (TargetAddress == getAddress() + getSize() && -TargetA

[llvm-branch-commits] [CMake] Preserve clang.pre-bolt (PR #109351)

2024-09-20 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. Thanks! PS. Let's drop ICF from the flags. https://github.com/llvm/llvm-project/pull/109351 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/ma

[llvm-branch-commits] [llvm] release/19.x: [BOLT] Fix relocations handling (PR #102741)

2024-08-19 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. Thanks for the back port. https://github.com/llvm/llvm-project/pull/102741 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llv

[llvm-branch-commits] [llvm] [BOLT] Match blocks with calls as anchors (PR #96596)

2024-07-08 Thread Maksim Panchenko via llvm-branch-commits
@@ -155,5 +155,52 @@ std::string hashBlockLoose(BinaryContext &BC, const BinaryBasicBlock &BB) { return HashString; } +/// An even looser hash level relative to $ hashBlockLoose to use with stale +/// profile matching, composed of the names of a block's called functions in

[llvm-branch-commits] [llvm] [BOLT] Match blocks with calls as anchors (PR #96596)

2024-07-08 Thread Maksim Panchenko via llvm-branch-commits
@@ -155,5 +155,52 @@ std::string hashBlockLoose(BinaryContext &BC, const BinaryBasicBlock &BB) { return HashString; } +/// An even looser hash level relative to $ hashBlockLoose to use with stale +/// profile matching, composed of the names of a block's called functions in

[llvm-branch-commits] [llvm] [BOLT] Match blocks with calls as anchors (PR #96596)

2024-07-08 Thread Maksim Panchenko via llvm-branch-commits
@@ -56,6 +56,10 @@ class YAMLProfileReader : public ProfileReaderBase { /// is attributed. FunctionSet ProfiledFunctions; + /// Maps profiled function id to name, for function matching with calls as + /// anchors. + DenseMap IdToFunctionName; maksfb wro

[llvm-branch-commits] [llvm] [BOLT][NFC] Refactor function matching (PR #97502)

2024-07-05 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/97502 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Match blocks with calls as anchors (PR #96596)

2024-07-03 Thread Maksim Panchenko via llvm-branch-commits
maksfb wrote: Could you please reword the summary and add an example where the new matching technique helps. https://github.com/llvm/llvm-project/pull/96596 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org

[llvm-branch-commits] [llvm] [BOLT][NFC] Refactor function matching (PR #97502)

2024-07-03 Thread Maksim Panchenko via llvm-branch-commits
@@ -456,6 +435,39 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { ++MatchedWithLTOCommonName; } } + return MatchedWithLTOCommonName; +} + +Error YAMLProfileReader::readProfile(BinaryContext &BC) { + if (opts::Verbosity >= 1) { +outs() << "BOLT-INF

[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)

2024-06-28 Thread Maksim Panchenko via llvm-branch-commits
@@ -342,6 +350,108 @@ bool YAMLProfileReader::mayHaveProfileData(const BinaryFunction &BF) { return false; } +uint64_t YAMLProfileReader::matchWithNameSimilarity(BinaryContext &BC) { + uint64_t MatchedWithNameSimilarity = 0; + ItaniumPartialDemangler ItaniumPartialDemangl

[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)

2024-06-27 Thread Maksim Panchenko via llvm-branch-commits
@@ -415,11 +423,116 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF)) matchProfileToFunction(YamlBF, *BF); + // Uses name similarity to match functions that were not matched by name. + uint64_t Matc

[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)

2024-06-27 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/95884 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)

2024-06-27 Thread Maksim Panchenko via llvm-branch-commits
@@ -23,6 +26,11 @@ extern cl::opt Verbosity; extern cl::OptionCategory BoltOptCategory; extern cl::opt InferStaleProfile; +cl::opt NameSimilarityFunctionMatchingThreshold( +"name-similarity-function-matching-threshold", +cl::desc("Matches functions using namespace and

[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)

2024-06-27 Thread Maksim Panchenko via llvm-branch-commits
@@ -0,0 +1,64 @@ +## Tests function matching in YAMLProfileReader by name similarity. + +# REQUIRES: system-linux +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o +# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib +# RUN:

[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)

2024-06-27 Thread Maksim Panchenko via llvm-branch-commits
@@ -0,0 +1,64 @@ +## Tests function matching in YAMLProfileReader by name similarity. + +# REQUIRES: system-linux +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o +# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib +# RUN:

[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)

2024-06-27 Thread Maksim Panchenko via llvm-branch-commits
@@ -415,11 +423,116 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF)) matchProfileToFunction(YamlBF, *BF); + // Uses name similarity to match functions that were not matched by name. + uint64_t Matc

[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)

2024-06-27 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb commented: Please refactor new code into a separate function. Add a comment on how the matching is done such that the interface can be understood without reading the code. https://github.com/llvm/llvm-project/pull/95884 ___

[llvm-branch-commits] [BOLT] Detect .warm split functions as cold fragments (PR #93759)

2024-05-30 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. LGTM with the nit addressed. https://github.com/llvm/llvm-project/pull/93759 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/l

[llvm-branch-commits] [BOLT] Detect .warm split functions as cold fragments (PR #93759)

2024-05-30 Thread Maksim Panchenko via llvm-branch-commits
@@ -596,6 +597,9 @@ class RewriteInstance { NameResolver NR; + // Regex object matching split function names. + const Regex ColdFragment{"(.*)\\.(cold|warm)(\\.[0-9]+)?"}; maksfb wrote: nit: s/ColdFragment/FunctionFragmentTemplate/ https://github.com/ll

[llvm-branch-commits] [BOLT] Detect .warm split functions as cold fragments (PR #93759)

2024-05-30 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/93759 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Ignore special symbols as function aliases in updateELFSymbolTable (PR #92713)

2024-05-20 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. LGTM. Thanks. https://github.com/llvm/llvm-project/pull/92713 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-comm

[llvm-branch-commits] [llvm] [BOLT] Ignore hot markers as function references in updateELFSymbolTable (PR #92713)

2024-05-20 Thread Maksim Panchenko via llvm-branch-commits
@@ -4788,13 +4788,25 @@ void RewriteInstance::updateELFSymbolTable( if (!IsDynSym && shouldStrip(Symbol)) continue; +Expected SymbolName = Symbol.getName(StringSection); maksfb wrote: Can we move the code that checks for special symbols here and

[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Maksim Panchenko via llvm-branch-commits
@@ -2386,25 +2362,26 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC, return std::pair(BlockIt->first, BlockIt->second.getBBIndex()); }; - for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) { -const auto &[_, Index] = get

[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/91289 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. Looks good on my end. https://github.com/llvm/llvm-project/pull/91289 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bra

[llvm-branch-commits] [llvm] [BOLT] Map branch source address to the containing basic block in BAT YAML (PR #91273)

2024-05-12 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. Please see the nit for the error message (caps and new line). Otherwise LGTM. https://github.com/llvm/llvm-project/pull/91273 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org

[llvm-branch-commits] [llvm] [BOLT] Map branch source address to the containing basic block in BAT YAML (PR #91273)

2024-05-12 Thread Maksim Panchenko via llvm-branch-commits
@@ -2378,21 +2379,27 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC, return CSI; }; + // Lookup containing basic block offset and index + auto getBlock = [&BlockMap](uint32_t Offset) { +auto BlockIt = BlockMap.upper_bound(Off

[llvm-branch-commits] [llvm] [BOLT] Map branch source address to the containing basic block in BAT YAML (PR #91273)

2024-05-12 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/91273 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Map branch source address to the containing basic block in BAT YAML (PR #91273)

2024-05-12 Thread Maksim Panchenko via llvm-branch-commits
@@ -2378,21 +2378,24 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC, return CSI; }; + // Lookup containing basic block offset and index + auto getBlock = [&BlockMap](uint32_t Offset) { +auto BlockIt = BlockMap.upper_bound(Off

[llvm-branch-commits] [llvm] [BOLT] Map branch source address to the containing basic block in BAT YAML (PR #91273)

2024-05-10 Thread Maksim Panchenko via llvm-branch-commits
@@ -2378,21 +2378,24 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC, return CSI; }; + // Lookup containing basic block offset and index + auto getBlock = [&BlockMap](uint32_t Offset) { +auto BlockIt = BlockMap.upper_bound(Off

[llvm-branch-commits] [llvm] [BOLT] Ignore returns in DataAggregator (PR #90807)

2024-05-08 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/90807 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Ignore returns in DataAggregator (PR #90807)

2024-05-08 Thread Maksim Panchenko via llvm-branch-commits
@@ -1167,6 +1167,21 @@ void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction, } } +std::optional +BinaryFunction::disassembleInstructionAtOffset(uint64_t Offset) const { + assert(CurrentState == State::Empty); + assert(Offset < MaxSize && "invalid offset"); -

[llvm-branch-commits] [llvm] [BOLT] Ignore returns in DataAggregator (PR #90807)

2024-05-08 Thread Maksim Panchenko via llvm-branch-commits
@@ -1167,6 +1167,21 @@ void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction, } } +std::optional +BinaryFunction::disassembleInstructionAtOffset(uint64_t Offset) const { + assert(CurrentState == State::Empty); + assert(Offset < MaxSize && "invalid offset"); +

[llvm-branch-commits] [llvm] [BOLT] Ignore returns in DataAggregator (PR #90807)

2024-05-08 Thread Maksim Panchenko via llvm-branch-commits
@@ -1167,6 +1167,21 @@ void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction, } } +std::optional +BinaryFunction::disassembleInstructionAtOffset(uint64_t Offset) const { + assert(CurrentState == State::Empty); maksfb wrote: nit: add message.

[llvm-branch-commits] [llvm] [BOLT] Ignore returns in DataAggregator (PR #90807)

2024-05-08 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. Please address the nits. Otherwise - good to go. https://github.com/llvm/llvm-project/pull/90807 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bi

[llvm-branch-commits] [BOLT][BAT] Fix translate for branches added by BOLT (PR #90811)

2024-05-03 Thread Maksim Panchenko via llvm-branch-commits
@@ -492,6 +486,10 @@ uint64_t BoltAddressTranslation::translate(uint64_t FuncAddress, const uint32_t Val = KeyVal->second >> 1; // dropping BRANCHENTRY bit if (IsBranchSrc) { +// Branch entry is found in BAT +if (KeyVal->first == Offset && KeyVal->second & BRANCHE

[llvm-branch-commits] [BOLT][BAT] Fix translate for branches added by BOLT (PR #90811)

2024-05-03 Thread Maksim Panchenko via llvm-branch-commits
@@ -48,10 +48,9 @@ static cl::opt InputFilename(cl::Positional, cl::Required, cl::cat(BatDumpCategory)); -static cl::list Translate("translate", -cl::desc("t

[llvm-branch-commits] [BOLT][BAT] Fix translate for branches added by BOLT (PR #90811)

2024-05-03 Thread Maksim Panchenko via llvm-branch-commits
@@ -24,6 +24,32 @@ READ-BAT-CHECK-NOT: BOLT-ERROR: unable to save profile in YAML format for input READ-BAT-CHECK: BOLT-INFO: Parsed 5 BAT entries READ-BAT-CHECK: PERF2BOLT: read 79 aggregated LBR entries +# Check handling of a branch not in BAT (added by BOLT) +RUN: FileChec

[llvm-branch-commits] [BOLT][BAT] Fix translate for branches added by BOLT (PR #90811)

2024-05-03 Thread Maksim Panchenko via llvm-branch-commits
@@ -478,18 +478,34 @@ uint64_t BoltAddressTranslation::translate(uint64_t FuncAddress, return Offset; const MapTy &Map = Iter->second; + if (IsBranchSrc) { +// Try exact lookup first +auto KeyVal = Map.find(Offset); +if (KeyVal != Map.end() && KeyVal->secon

[llvm-branch-commits] [llvm] [BOLT] Use heuristic for matching split local functions (PR #90424)

2024-04-29 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/90424 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [BOLT] Use offset deduplication for cold fragments (PR #87853)

2024-04-14 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/87853 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT][BAT] Fix handling of split functions (PR #87569)

2024-04-11 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/87569 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Cover all call sites in writeBATYAML (PR #87743)

2024-04-11 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/87743 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Cover all call sites in writeBATYAML (PR #87743)

2024-04-10 Thread Maksim Panchenko via llvm-branch-commits
@@ -2341,86 +2341,62 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC, YamlBF.NumBasicBlocks = BAT->getNumBasicBlocks(FuncAddress); const BoltAddressTranslation::BBHashMapTy &BlockMap = BAT->getBBHashMap(FuncAddress); + YamlBF.Blocks

[llvm-branch-commits] [llvm] [BOLT] Cover all call sites in writeBATYAML (PR #87743)

2024-04-10 Thread Maksim Panchenko via llvm-branch-commits
@@ -2341,86 +2341,62 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC, YamlBF.NumBasicBlocks = BAT->getNumBasicBlocks(FuncAddress); const BoltAddressTranslation::BBHashMapTy &BlockMap = BAT->getBBHashMap(FuncAddress); + YamlBF.Blocks

[llvm-branch-commits] [llvm] [BOLT] Cover all call sites in writeBATYAML (PR #87743)

2024-04-10 Thread Maksim Panchenko via llvm-branch-commits
@@ -38,10 +38,63 @@ # RUN: llvm-bolt %t.exe -o %t.bat --data %t.fdata --funcs=func \ # RUN: --split-functions --split-strategy=all --split-all-cold --enable-bat +# Prepare pre-aggregated profile using %t.bat maksfb wrote: Use double `#`s. https://github.co

[llvm-branch-commits] [llvm] [BOLT][BAT] Fix handling of split functions (PR #87569)

2024-04-10 Thread Maksim Panchenko via llvm-branch-commits
@@ -59,10 +59,29 @@ # RUN: llvm-bolt %t.exe -o %t.bat2 --data %t.fdata --funcs=main,func \ # RUN: --split-functions --split-strategy=all --split-all-cold --enable-bat +# Prepare pre-aggregated profile using %t.bat maksfb wrote: Nit: use double `#`s. https:

[llvm-branch-commits] [llvm] [BOLT][BAT] Fix handling of split functions (PR #87569)

2024-04-10 Thread Maksim Panchenko via llvm-branch-commits
@@ -245,14 +245,12 @@ class DataAggregator : public DataReader { /// disassembled BinaryFunctions BinaryFunction *getBinaryFunctionContainingAddress(uint64_t Address) const; + /// Perform BAT translation for a given \p Func and return the parent + /// BinaryFunction or n

[llvm-branch-commits] [llvm] [BOLT] Emit empty FDE for injected functions (PR #87967)

2024-04-09 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/87967 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Emit empty FDE for injected functions (PR #87967)

2024-04-09 Thread Maksim Panchenko via llvm-branch-commits
maksfb wrote: Okay. That explains the increase. https://github.com/llvm/llvm-project/pull/87967 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Emit empty FDE for injected functions (PR #87967)

2024-04-09 Thread Maksim Panchenko via llvm-branch-commits
maksfb wrote: > > Creating a proper FDE entry is the right thing to do regardless of BAT. How > > large is the regression? > > The largest I've seen is 34M->39M (HHVM instrumentation). Did you check if we patch every single function in he original `.text`? How many functions are there? https

[llvm-branch-commits] [llvm] [BOLT] Emit empty FDE for injected functions (PR #87967)

2024-04-09 Thread Maksim Panchenko via llvm-branch-commits
maksfb wrote: > > Let's make `hasCFI()` return true for injected functions. > > Given that this change increases the size of eh_frame section, should we make > it dependent on `enable-bat`, i.e. when we expect to feed the binary back to > BOLT? > > Because otherwise this "fix" is a pure size

[llvm-branch-commits] [BOLT] Use BAT to register fragments (PR #87968)

2024-04-08 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb commented: Is information we emit in the symbol table insufficient to establish the fragment relationship? https://github.com/llvm/llvm-project/pull/87968 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.or

[llvm-branch-commits] [BOLT] Emit empty FDE for injected functions (PR #87967)

2024-04-08 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb commented: Let's make `hasCFI()` return true for injected functions. https://github.com/llvm/llvm-project/pull/87967 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailma

[llvm-branch-commits] [llvm] [BOLT] Use BAT for YAML profile call target information (PR #86219)

2024-04-05 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/86219 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Use BAT for YAML profile call target information (PR #86219)

2024-04-05 Thread Maksim Panchenko via llvm-branch-commits
@@ -161,6 +164,10 @@ class BoltAddressTranslation { /// Map a function to its secondary entry points vector std::unordered_map> SecondaryEntryPointsMap; + /// Translates a given \p Symbol into a BinaryFunction and + /// Returns a secondary entry point id for a given \p A

[llvm-branch-commits] [llvm] [BOLT] Use BAT for YAML profile call target information (PR #86219)

2024-04-05 Thread Maksim Panchenko via llvm-branch-commits
@@ -123,6 +124,12 @@ class BoltAddressTranslation { std::unordered_map> getBFBranches(uint64_t FuncOutputAddress) const; + /// For a given \p Symbol in the output binary, returns a corresponding pair + /// of parent BinaryFunction and secondary entry point in it. ---

[llvm-branch-commits] [llvm] [BOLT] Use BAT for YAML profile call target information (PR #86219)

2024-04-05 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. Looks good with nits addressed. https://github.com/llvm/llvm-project/pull/86219 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinf

[llvm-branch-commits] [llvm] [BOLT] Use BAT interfaces in YAMLProfileWriter::convert (PR #86219)

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits
@@ -27,25 +28,55 @@ namespace bolt { /// Set CallSiteInfo destination fields from \p Symbol and return a target /// BinaryFunction for that symbol. -static const BinaryFunction *setCSIDestination(const BinaryContext &BC, - yaml::bo

[llvm-branch-commits] [llvm] [BOLT][BAT] Support multi-way split functions (PR #87123)

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. https://github.com/llvm/llvm-project/pull/87123 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT][BAT] Support multi-way split functions (PR #87123)

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits
@@ -197,8 +197,10 @@ void BoltAddressTranslation::writeMaps(std::map &Maps, ? SecondaryEntryPointsMap[Address].size() : 0; if (Cold) { - size_t HotIndex = - std::distance(ColdPartSource.begin(), ColdPartSource.find(Address)); + //

[llvm-branch-commits] [llvm] [BOLT] Use BAT interfaces in YAMLProfileWriter::convert (PR #86219)

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits
@@ -27,25 +28,55 @@ namespace bolt { /// Set CallSiteInfo destination fields from \p Symbol and return a target /// BinaryFunction for that symbol. -static const BinaryFunction *setCSIDestination(const BinaryContext &BC, - yaml::bo

[llvm-branch-commits] [llvm] [BOLT] Use BAT interfaces in YAMLProfileWriter::convert (PR #86219)

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits
@@ -27,25 +28,55 @@ namespace bolt { /// Set CallSiteInfo destination fields from \p Symbol and return a target /// BinaryFunction for that symbol. -static const BinaryFunction *setCSIDestination(const BinaryContext &BC, - yaml::bo

[llvm-branch-commits] [llvm] [BOLT] Use BAT interfaces in YAMLProfileWriter::convert (PR #86219)

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits
@@ -27,25 +28,55 @@ namespace bolt { /// Set CallSiteInfo destination fields from \p Symbol and return a target /// BinaryFunction for that symbol. -static const BinaryFunction *setCSIDestination(const BinaryContext &BC, - yaml::bo

[llvm-branch-commits] [llvm] [BOLT] Use BAT interfaces in YAMLProfileWriter::convert (PR #86219)

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits
@@ -27,25 +28,55 @@ namespace bolt { /// Set CallSiteInfo destination fields from \p Symbol and return a target /// BinaryFunction for that symbol. -static const BinaryFunction *setCSIDestination(const BinaryContext &BC, - yaml::bo

[llvm-branch-commits] [llvm] [BOLT] Use BAT interfaces in YAMLProfileWriter::convert (PR #86219)

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits
@@ -123,6 +123,9 @@ class BoltAddressTranslation { std::unordered_map> getBFBranches(uint64_t FuncOutputAddress) const; + /// Returns a secondary entry point id for a given function and offset. maksfb wrote: "... function at a given \p Address..." https

[llvm-branch-commits] [llvm] [BOLT] Set EntryDiscriminator in YAML profile for indirect calls (PR #82128)

2024-03-27 Thread Maksim Panchenko via llvm-branch-commits
https://github.com/maksfb approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/82128 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

[llvm-branch-commits] [llvm] [BOLT] Set EntryDiscriminator in YAML profile for indirect calls (PR #82128)

2024-03-27 Thread Maksim Panchenko via llvm-branch-commits
@@ -78,32 +97,15 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS) { if (!ICSP) continue; for (const IndirectCallProfile &CSP : ICSP.get()) { - StringRef TargetName = ""; - CSI.DestId = 0; // designated for unknown