2163 Commits

Author SHA1 Message Date
Elvina Yakubova
765ce86991
[BOLT][DOC] Add script for automatic user guide generation (#93822) 2024-05-31 13:50:51 +01:00
Elvina Yakubova
23427b808c
[BOLT][NFC] Fix typo in DWARFRewriter.cpp (#93955) 2024-05-31 13:43:20 +01:00
Amir Ayupov
e9954ec087 [BOLT] Detect .warm split functions as cold fragments (#93759)
CDSplit splits functions up to three ways: main fragment with no suffix,
and fragments with .cold and .warm suffixes.

Add .warm suffix to the regex used to recognize split fragments.

Test Plan: updated register-fragments-bolt-symbols.s
2024-05-30 17:48:12 -07:00
shaw young
629b6f4eb1
[BOLT][NFC] Extend updateLayoutIndices (#93861)
Make FunctionLayout::updateLayoutIndices const and add an overloaded
function that updates LayoutIndices given an Order parameter.
2024-05-30 14:35:29 -07:00
Fangrui Song
ce5b371606
[BOLT,test] Make linker scripts less sensitive to lld's orphan placement (#93763)
Then two tests rely on .interp being the first section.
llvm-bolt would crash if lld places .interp after .got
(f639b57f7993cadb82ee9c36f04703ae4430ed85).

For best portability, when a linker scripts specifies a SECTIONS
command, the first section for each PT_LOAD segment should be specified
with a MAXPAGESIZE alignment. Otherwise, linkers have freedom to decide
how to place orphan sections, which might break intention.
2024-05-30 10:12:41 -07:00
Michael Kruse
c5a3f664fe
[BOLT] Revise IDE folder structure (#89742)
Update the folder titles for targets in the monorepository that have not
seen taken care of for some time. These are the folders that targets are
organized in Visual Studio and XCode (`set_property(TARGET <target>
PROPERTY FOLDER "<title>")`) when using the respective CMake's IDE
generator.

 * Ensure that every target is in a folder
 * Use a folder hierarchy with each LLVM subproject as a top-level folder
 * Use consistent folder names between subprojects
 * When using target-creating functions from AddLLVM.cmake, automatically
deduce the folder. This reduces the number of
`set_property`/`set_target_property`, but are still necessary when
`add_custom_target`, `add_executable`, `add_library`, etc. are used. A
LLVM_SUBPROJECT_TITLE definition is used for that in each subproject's
root CMakeLists.txt.
2024-05-25 17:15:37 +02:00
Alexander Yermolovich
8c2da89ec4
[BOLT] Do not emit debug_names entry for DIEs with DW_AT_declaration (#93347)
Previously BOLT was only doing it for DW_TAG_variables. It looks like
other type of DIEs can have this. So making it global.
2024-05-25 07:48:57 -07:00
Amir Ayupov
c460e454d1
[BOLT][NFCI] Fix return type of BC::getSignedValueAtAddress (#91664) 2024-05-24 16:04:06 -07:00
Amir Ayupov
f239490592
[BOLT][NFC] Define getExprValue helper (#91663)
Move out common code extracting the address of a MCExpr. To be reused in
#91667.

Test Plan: NFC
2024-05-24 15:33:25 -07:00
Amir Ayupov
be83f5c150
[BOLT][NFC] Simplify analyzeIndirectBranch (#91662)
Simplify mutually exclusive sanity checks in analyzeIndirectBranch,
where an UNKNOWN IndirectBranchType is to be returned. Reduces confusion
and code duplication when adding a new IndirectBranchType (to be added
in #91667).

Test Plan: NFC
2024-05-24 15:13:10 -07:00
Amir Ayupov
4658803958
[BOLT][NFC] Add isRIPRel and isIndexed helpers (#91661)
Move out common X86MemOperand checks into helper lambdas. To be reused
in #91667.

Test Plan: NFC
2024-05-24 14:49:41 -07:00
Amir Ayupov
720cade2b6
[BOLT][NFC] Avoid computing BF hash twice in YAML reader (#75096)
We compute BF hashes in `YAMLProfileReader::readProfile` when first
matching profile functions with binary functions, and second time in
`YAMLProfileReader::parseFunctionProfile` during the profile assignment
(we need to do that to account for LTO private functions with
mismatching suffix).

Avoid recomputing the hash if it's been set.
2024-05-24 14:00:03 -07:00
Sayhaan Siddiqui
dc7897aed3
[BOLT][NFC] Fix unused variable warning (#93323)
This fixes

```
warning: variable 'AbbrDecl' set but not used [-Wunused-but-set-variable]

   76 |     if (const DWARFAbbreviationDeclaration *AbbrDecl =
```
2024-05-24 10:33:30 -07:00
Amir Ayupov
d1d9545ed3
[BOLT][BAT] Add entries for deleted basic blocks
Deleted basic blocks are required for correct mapping of branches
modified by SCTC.

Increases BAT size, bytes:
- large binary: 8622496 -> 8703244.
- small binary (X86/bolt-address-translation.test): 928 -> 940.

Test Plan: updated bb-with-two-tail-calls.s

Reviewers: ayermolo, dcci, maksfb, rafaelauler

Reviewed By: rafaelauler

Pull Request: https://github.com/llvm/llvm-project/pull/91906
2024-05-23 19:19:07 -07:00
Amir Ayupov
83b3e13e89
[BOLT] Allow processing of binaries with stripped FILE symbols mismatching the profile (#93238)
Reintroduce allow-stripped as a fallback mechanism after enforcement of
HasSymbolsWithFileName was fixed in
https://github.com/llvm/llvm-project/pull/92625.

This partially reverts commit ccabbfff86a00a0b211f5d0835916a1250ebcf0f.
2024-05-23 16:40:08 -07:00
Amir Ayupov
a38f0157f2
[BOLT] Set InitialDynoStats after EstimateEdgeCounts (#93218)
InitialDynoStats used to be assigned inside `runAllPasses`, but the
assignment executed before any of the passes. As we've moved
`EstimateEdgeCounts` into a pass out of ProfileReader, it needs to
execute before initial dyno stats are set.

Thus move `InitialDynoStats` into BinaryContext and assignment into
`DynoStatsSetPass`.
2024-05-23 11:37:06 -07:00
Amir Ayupov
465bfd41fa
[BOLT][NFC] Simplify BBHashMapTy (#91812) 2024-05-22 16:00:51 -07:00
Amir Ayupov
3061fed2f0
[BOLT][NFC] Simplify FuncHashesTy (#91815)
Make EntryTy a thin wrapper struct.
2024-05-22 13:58:24 -07:00
Amir Ayupov
a79acb0ce5
[BOLT] Fix setHasSymbolsWithFileName (#92625)
The function is used to ignore the parameter and set
`HasSymbolsWithFileName` unconditionally.
2024-05-22 13:57:52 -07:00
Amir Ayupov
1529ec085a
[BOLT][NFC] Move out PrintProgramStats from Profile into Rewrite (#93075)
Eliminate the dependence of Profile on Passes.

Test Plan: NFC
2024-05-22 13:53:41 -07:00
Amir Ayupov
f3dc732b36
[BOLT][NFC] Make estimateEdgeCounts a BinaryFunctionPass (#93074) 2024-05-22 11:59:00 -07:00
shaw young
96378b3da8
[BOLT] Add NamedRegionTimer to inferStaleProfile (#93078) 2024-05-22 11:04:12 -07:00
Amir Ayupov
5057463814
[BOLT][NFC] Make BAT methods const (#91823) 2024-05-22 10:39:27 -07:00
Amir Ayupov
37e4945a8a
[BOLT][NFC] Clean up MCF (#93065)
Drop unimplemented solveMCF and remnants of it.
2024-05-22 09:32:06 -07:00
shaw young
c8fc234ee2
[BOLT][NFC] Eliminate uses of throwing std::map::at (#92950)
Remove calls to std::unordered_map::at, std::map::at, and
std::vector::at.
2024-05-22 09:27:14 -07:00
Amir Ayupov
7c5c8b2f47
[BOLT][NFC] Move BAT::fetchParentAddress to header (#93061)
Unbreak shared build after
https://github.com/llvm/llvm-project/pull/91683
2024-05-22 09:14:10 -07:00
Amir Ayupov
97025bd9d5
[BOLT] Use getLocationName in YAMLProfileWriter (#92493)
Disambiguate local functions using the containing file symbol in BAT
mode. Make local function naming consistent across BAT fdata and YAML
profiles.

Test Plan: updated register-fragments-bolt-symbols.s
2024-05-21 20:24:46 -07:00
Amir Ayupov
935b946b1f
[BOLT] Process cross references between ignored functions in BAT mode (#92484)
To align YAML and fdata profiles produced in BAT mode, lift two
restrictions applied in non-relocation mode when BAT is present:
1) register secondary entry points from ignored functions,
2) treat functions with secondary entry points as simple.

This allows constructing CFG for non-simple functions in non-relocation
mode and emitting YAML profile for them, which can then be used for
optimizations in relocation mode.

Test Plan: added test ignored-interprocedural-reference.s
2024-05-21 20:22:12 -07:00
Amir Ayupov
a9b67490b2
[BOLT] Report adjusted program stats from perf2bolt in BAT mode (#91683) 2024-05-21 18:54:15 -07:00
Heewon Cho
219ea26733
[BOLT][NFC] Remove dead initialization code (#92952)
Addressing #81441
2024-05-21 16:28:17 -07:00
Heewon Cho
b90861498b
[BOLT][NFC] Use const reference in range-based for loop (#92932)
Addressing #91195
2024-05-21 16:26:53 -07:00
Amir Ayupov
32c9d5ef4f Revert "[BOLT] Add NamedRegionTimer to inferStaleProfile (#92621)"
This reverts commit 9f2313829fd210f9923375e93bc11fe9685c26d5.

Creates a dependency cycle: lib/Rewrite depends on lib/Profile.
2024-05-21 13:55:32 -07:00
shaw young
9f2313829f
[BOLT] Add NamedRegionTimer to inferStaleProfile (#92621) 2024-05-21 13:26:57 -07:00
Kazu Hirata
1486653dcf
[BOLT] Use StringRef::contains (NFC) (#92842) 2024-05-20 19:18:45 -07:00
Amir Ayupov
bb627b0a0c
[BOLT] Ignore special symbols as function aliases in updateELFSymbolTable
Exempt special symbols (hot text/data and _end symbol) from normal
handling. We only need to set their value and make them absolute.

If these symbols are handled as normal symbols and if they alias
functions we may create non-sensical symbols, e.g. __hot_start.cold.

Test Plan: updated hot-end-symbol.s

Reviewers: maksfb, rafaelauler, ayermolo, dcci

Reviewed By: dcci, maksfb

Pull Request: https://github.com/llvm/llvm-project/pull/92713
2024-05-20 16:55:11 -07:00
Amir Ayupov
91423d7193
[BOLT][NFC] Don't assign YAML profile to functions with no CFG (#92487)
YAML profile for non-simple functions without CFG is
  1) useless for optimizations,
  2) can't be attached, similar to fdata profile,
  3) would be reported as invalid/stale even if the profile is valid.

Don't attempt to attach the profile in this case, aligning the behavior
to DataReader.

Test Plan: added yaml-non-simple.test
2024-05-19 20:15:31 -07:00
Amir Ayupov
878642954f
[BOLT] Fix preserved offset in fixDoubleJumps (#92485) 2024-05-19 13:23:04 -07:00
Nathan Sidwell
76fdc2e527
[BOLT][NFC] Rename isUnsupportedBranch to isReversibleBranch (#92447)
`isUnsupportedBranch` is not a very informative name, and doesn't match
its corresponding `reverseBranchCondition`, as I noted in PR #92018.
Here's a renaming to a more mnemonic name.
2024-05-17 15:40:40 -04:00
Amir Ayupov
9f15aa009c
[BOLT][NFC] Rename DataAggregator::BranchInfo to TakenBranchInfo
Align the name to its counterpart `FTInfo` which avoids name aliasing
with llvm::bolt::BranchInfo and allows to drop namespace specifier.

Test Plan: NFC

Reviewers: maksfb, rafaelauler, ayermolo, dcci

Reviewed By: dcci

Pull Request: https://github.com/llvm/llvm-project/pull/92017
2024-05-16 20:02:51 -07:00
Elvina Yakubova
dcf3102be8
[BOLT][NFC] Add documentation on BOLT options (#92117)
Add .md file documentation with all BOLT options to display it more
conveniently.
2024-05-15 16:16:39 +01:00
Krzysztof Parzyszek
95e307caeb Fix bolt build with -DBUILD_SHARED_LIBS=ON after 71fbbb69d
Commit 71fbbb69d63c461f391cbabf1e32cd9977c4ce68 moved getGUID out of
line in llvm/IR/GlobalValue, now users have to link LLVMCore to have
the definition of it.

/usr/bin/ld: CMakeFiles/LLVMBOLTRewrite.dir/PseudoProbeRewriter.cpp.o: in function `(anonymous namespace)::PseudoProbeRewriter::parsePseudoProbe()':
PseudoProbeRewriter.cpp:(.text._ZN12_GLOBAL__N_119PseudoProbeRewriter16parsePseudoProbeEv+0x3d0): undefined reference to `llvm::GlobalValue::getGUID(llvm::StringRef)'
/usr/bin/ld: CMakeFiles/LLVMBOLTRewrite.dir/PseudoProbeRewriter.cpp.o: in function `(anonymous namespace)::PseudoProbeRewriter::encodePseudoProbes()':
PseudoProbeRewriter.cpp:(.text._ZN12_GLOBAL__N_119PseudoProbeRewriter18encodePseudoProbesEv+0x11a1): undefined reference to `llvm::GlobalValue::getGUID(llvm::StringRef)'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/bolt/lib/Rewrite/CMakeFiles/LLVMBOLTRewrite.dir/build.make:275: lib/libLLVMBOLTRewrite.so.19.0git] Error 1
2024-05-15 08:35:49 -05:00
Alexander Yermolovich
99fad7ebd8
[BOLT][DWARF] Update DW_AT_comp_dir/DW_AT_dwo_name for DWO TUs (#91486)
Type unit DIE generated by clang contains DW_AT_comp_dir/DW_AT_dwo_name.
This was added to clang to help LLDB to figure out where type unit come
from when accessing an entry in a .debug_names accelerator table and
type units in .dwp file.

When BOLT writes out .dwo files it changes the name of them. User can
also specify directory of where they can be written out. Added support
to BOLT to update those attributes.
2024-05-14 15:08:45 -07:00
Nathan Sidwell
1aff294f6e
[BOLT][NFC] Simplify successor check (#91980)
Remove excess parentheses and use `boolean ? true-case : false-case` idiom.
2024-05-14 09:38:32 -04:00
Nathan Sidwell
725014d866
[BOLT][NFC] Simplify CFG validation (#91977)
Remove 'Valid' local boolean that has a single use, and return directly instead.
2024-05-14 09:36:34 -04:00
Amir Ayupov
b06f97b039
[BOLT] Allow pass-through blocks in YAMLProfileReader (#91828) 2024-05-13 18:02:38 -07:00
Amir Ayupov
4ecf2caf68
[BOLT] Use aggregated FuncBranchData in writeBATYAML
Switch from FuncBranchData intermediate maps (Intra/InterIndex)
to aggregated Data, same as one used by DataReader:
e62ce1f884/bolt/lib/Profile/DataReader.cpp (L385-L389)
This aligns the order of the output between YAMLProfileWriter and
writeBATYAML.

Test Plan: updated bolt-address-translation-yaml.test

Reviewers: rafaelauler, dcci, ayermolo, maksfb

Reviewed By: ayermolo, maksfb

Pull Request: https://github.com/llvm/llvm-project/pull/91289
2024-05-13 14:23:32 -07:00
Amir Ayupov
54b17fa4ee [BOLT] Preserve Offset annotation in fixDoubleJumps (#91898)
Offset annotation was missed when optimizing an unconditional branch to
a tail call.

Test Plan: update bb-with-two-tail-calls.s
2024-05-13 12:31:48 -07:00
Kazu Hirata
f841ca0c35
Use StringRef::operator== instead of StringRef::equals (NFC) (#91864)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  276 under llvm-project/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-12 23:08:40 -07:00
Amir Ayupov
b5af667b01
[BOLT] Map branch source address to the containing basic block in BAT YAML
Fix an issue where the profile for all branches that have a BRANCHENTRY
is dropped. If the branch has an entry in BAT, it will be translated to
its input offset. We used to only permit the basic block offset as a
branch source. Perform a lookup of containing basic block instead.

Test Plan: Updated bolt-address-translation-yaml.test

Reviewers: maksfb, dcci, rafaelauler, ayermolo

Reviewed By: maksfb

Pull Request: https://github.com/llvm/llvm-project/pull/91273
2024-05-12 17:11:09 -07:00
Maksim Panchenko
c8864bceeb
[BOLT] Fix race condition in a test (#91866)
Fix race condition in internal NFC test.
2024-05-11 23:59:57 -07:00