Commit Graph

1673 Commits

Author SHA1 Message Date
Job Noorman
d755e10e7a [BOLT] Make sure Mach-O binaries are actually linked
Note that this issue is also solved by D147544.

Reviewed By: alexander-shaposhnikov

Differential Revision: https://reviews.llvm.org/D149244
2023-05-02 16:22:49 +02:00
Job Noorman
f3ea4228fd [BOLT] Make sure all section allocations have deterministic contents
For empty sections, RuntimeDyld always allocates 1 byte but leaves it
uninitialized. This causes the contents of some output sections to be
non-deterministic.

Note that this issue is also solved by D147544.

Fixes #59008

Reviewed By: maksfb

Differential Revision: https://reviews.llvm.org/D149243
2023-05-02 16:18:01 +02:00
Yi Kong
78d8d01649 Revert "[BOLT] Parallelize legacy profile merging"
This reverts commit 35af20d9e0.

The patch caused a test failure.
2023-04-28 21:24:52 +09:00
Yi Kong
35af20d9e0 [BOLT] Parallelize legacy profile merging
Merging profiles is quite expensive, but easily paralleizable.

8359 profiles on n2d-standard-128:
single-thread: 808s
multi-thread: 200s (~75% speed up)

Differential Revision: https://reviews.llvm.org/D149014
2023-04-27 15:37:14 +09:00
Job Noorman
8421c7ad30 [BOLT][Wrapper] Fix off-by-one when parsing 'cmp' output
The byte offsets in the output of 'cmp' start from 1, not from 0 as the
current parser assumes. This caused mismatched bytes to sometimes be
attributed to the wrong section.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D149046
2023-04-24 20:54:56 +02:00
Job Noorman
b3780af3b3 [BOLT] Fix many tests detected as unsupported
Since D148847, many tests are detected as being unsupported. This is
caused by BOLT_TARGETS_TO_BUILD being ;-separated whereas the previously
used TARGETS_TO_BUILD is space-separated.

This patch fixes this by creating config.targets lit.cfg.py by splitting
on ';'.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D149026
2023-04-24 11:39:02 -07:00
Christian Ulmann
f5425c128a [LoopInfo] Move generic LoopInfo into own files
This commit splits the generic part of `LoopInfo` into separate files.
These new `GenericLoopInfo` files are located in `llvm/Support` to be inline
with `GenericDomTree`.

Furthermore, this change ensures that MLIR's Bazel build does not have
to link against `LLVMAnalysis` just to use these template headers.

Depends on D148219

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D148235
2023-04-24 06:07:05 +00:00
Nathan Sidwell
5b9f0309d6 [BOLT] Remove unsupported ELF type reloc handling
Drop unsupported ELF format reloc handling -- RewriteInstance lacks
this flexibility elsewhere.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D148946
2023-04-23 13:09:37 -04:00
Nathan Sidwell
ffb42e313d [BOLT] Remove unneeded dyncasts
These checks are unnecessary -- we've already bailed if the format was wrong.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D148848
2023-04-21 13:40:54 -04:00
Nathan Sidwell
f84ac48f1e [BOLT] Add BOLT_TARGETS_TO_BUILD
Adds BOLT_TARGETS_TO_BUILD, which defaults to the intersection of
X86;AArch64 and LLVM_TARGETS_TO_BUILD, but allows configuration to
alter that -- for instance omitting one of those two targets even if
llvm supports both.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D148847
2023-04-21 13:07:04 -04:00
Nathan Sidwell
1c3653df08 [BOLT] Robustify compile-time config check
The BOLT runtime is specifically hard coded for x86_64 linux or x86_64
darwin. (Using x86_64 syscalls, hardcoding syscall numbers.)

Make it very clear this is for those specific pair of systems.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D148825
2023-04-21 12:37:54 -04:00
Nathan Sidwell
06b8057cc2 [BOLT] Make BOLT_ENABLE_RUNTIME user-configurable
Defaults to ON for x86_64 && (Linux | Darwin).

If enabled, checks that /proc/self/map_files is readable. Some systems are configured so that getdents fails with EPERM.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D148742
2023-04-20 14:41:32 -04:00
Nathan Sidwell
c3368fbfe8 [BOLT][NFC] Remove exec permission from some tests
These files unnecessarily had execute permission.
2023-04-19 19:42:01 -04:00
Nathan Sidwell
0044647fdc [BOLT] Add bolt-runtime requirement to tests
These tests rely on the	X86 runtime, add the REQUIRES.

Differential Revision: https://reviews.llvm.org/D148737
2023-04-19 19:42:01 -04:00
Nathan Sidwell
9c92b023da [BOLT][NFC] Move phdr typedef to cpp file
This typedef is only used inside the RewriteInstance source file, let's not
expose it in the header file -- even if private.

Differential Revision: https://reviews.llvm.org/D148667
2023-04-19 15:51:17 -04:00
Nathan Sidwell
f2f0411924 [BOLT] Adjust Shdr alignment
Shdr's are not necesarily size 2^n, and there is no reason to align to
that boundary if they are.

Differential Revision: https://reviews.llvm.org/D148666
2023-04-19 15:51:12 -04:00
Nathan Sidwell
3c8757a863 [BOLT] Don't enable runtime when not building X86 2023-04-18 18:19:55 -04:00
Alexander Yermolovich
125df67421 [BOLT][DWARF] Fix handling of CUs without TU reference
When input is DWP with DWARF5 bolt wasn't handling correctly CUs that didn't
have TU references. Which resulted in a crash.

Reviewed By: maksfb

Differential Revision: https://reviews.llvm.org/D148589
2023-04-17 17:56:08 -07:00
Amir Ayupov
286b5071f1 [BOLT][test] Update AArch64/r_aarch64_prelxx.s test
Update section flags and type after https://reviews.llvm.org/D148386

Reviewed By: #bolt, rafauler, MaskRay

Differential Revision: https://reviews.llvm.org/D148511
2023-04-17 23:33:42 +02:00
Job Noorman
48ad4296f7 [BOLT] Fix use-after-free in RewriteInstance::mapCodeSections
When a cold function is too large, its section gets deregistered.
However, the section is still dereferenced later to get its RuntimeDyld
ID. This patch moves the deregistration to after the last dereference.

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D148427
2023-04-17 16:16:49 +02:00
Mark de Wever
44d38022ab Revert "Revert "Revert "[CMake] Bumps minimum version to 3.20.0."""
This reverts commit 1ef4c3c859.

Two buildbots still haven't been updated.
2023-04-15 20:12:24 +02:00
Mark de Wever
1ef4c3c859 Revert "Revert "[CMake] Bumps minimum version to 3.20.0.""
This reverts commit 92523a35a8.

Reland to see whether CIs are updated.
2023-04-15 13:12:04 +02:00
Job Noorman
8bbfac7be1 [BOLT][NFC] Fix UB due to unaligned load in DebugStrOffsetsWriter
The following tests fail when enabling UBSan due to an unaligned memory
load:

> runtime error: load of misaligned address 0x620000000643 for type
> 'const uint32_t' (aka 'const unsigned int'), which requires 4 byte
> alignment

  BOLT :: AArch64/asm-func-debug.test
  BOLT :: AArch64/update-debug-reloc.test
  BOLT :: X86/asm-func-debug.test
  BOLT :: X86/dwarf5-df-dualcu.test
  BOLT :: X86/dwarf5-df-mono-dualcu.test
  BOLT :: X86/dwarf5-ftypes-dwp-input-dwo-output.test
  BOLT :: X86/dwarf5-locaddrx.test
  BOLT :: X86/dwarf5-split-dwarf4-monolithic.test
  BOLT :: X86/inlined-function-mixed.test
  BOLT :: non-empty-debug-line.test

This patch fixes this by using read32le for the load.

Reviewed By: ayermolo

Differential Revision: https://reviews.llvm.org/D148217
2023-04-13 16:39:22 +02:00
Job Noorman
df3f1e2f31 [BOLT][NFC] Fix UB due to left shift of negative value
The following test fails when enabling UBSan due to a left shift of a
negative value:

> runtime error: left shift of negative value -2

  BOLT :: AArch64/ext-island-ref.s

This patch fixes this by using a multiplication instead of a shift.

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D148218
2023-04-13 14:29:19 +02:00
Muhammad Omair Javaid
1a8f3f96c2 [BOLT] Fix section-end-sym.s test to only run x86/Linux
section-end-sym.s contains x86_64 assembly instruction execution on target.
I have changed REQURIES: field system-linux --> x86_64-linux
This came up while testing LLVM 16.0.1 release on AArch64 Linux.
2023-04-12 17:14:30 +05:00
Rafael Auler
b87bf74428 [BOLT] Fix creation of invalid CFG in presence of dead code
When there is a direct jump right after an indirect one, in
the absence of code jumpting to this direct jump, this is obviously
dead code. However, BOLT was failing to recognize that by mistakenly
placing both jmp instructions in the same basic block, and creating
wrong successor edges. Fix that, so we can safely run UCE on
that. This bug also causes validateCFG to fail and BOLT to crash if it
is running ICP on that function.

Reviewed By: #bolt, Amir

Differential Revision: https://reviews.llvm.org/D148055
2023-04-11 17:19:39 -07:00
Alexis Engelke
0c049ea60a [MC] Always encode instruction into SmallVector
All users of MCCodeEmitter::encodeInstruction use a raw_svector_ostream
to encode the instruction into a SmallVector. The raw_ostream however
incurs some overhead for the actual encoding.

This change allows an MCCodeEmitter to directly emit an instruction into
a SmallVector without using a raw_ostream and therefore allow for
performance improvments in encoding. A default path that uses existing
raw_ostream implementations is provided.

Reviewed By: MaskRay, Amir

Differential Revision: https://reviews.llvm.org/D145791
2023-04-06 16:21:49 +02:00
Yi Kong
d788db3d19 [BOLT][NFC] Simplify code using std::optional
Use std::optional instead of tracking if it is the first profile seen.

Differential Revision: https://reviews.llvm.org/D147308
2023-04-01 13:47:36 +08:00
spupyrev
92758a99c3 [BOLT] computing raw branch count for yaml profiles
`Function.RawBranchCount` is initialized for fdata profile but not for yaml one.
The diff adds the computation of the field for yaml profiles

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D144211
2023-03-28 11:09:21 -07:00
Denis Revunov
22a4aaf2b0 [BOLT] Don't use section relocations when computing hash for data from other section
When computing symbol hashes in BinarySection::hash, we try to find relocations
in the section which reference the passed BinaryData. We do so by doing
lower_bound on data begin offset and upper_bound on data end offset. Since
offsets are relative to the current section, if it is a data from the previous
section, we get underflow when computing offset and lower_bound returns
Relocations.end(). If this data also ends where current section begins,
upper_bound on zero offset will return some valid iterator if we have any
relocations after the first byte. Then we'll try to iterate from lower_bound to
upper_bound, since they're not equal, which in that case means we'll dereference
Relocations.end(), increment it, and try to do so until we reach the second
valid iterator. Of course we reach segfault earlier. In this patch we stop BOLT
from searching relocations for symbols outside of the current section.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D146620
2023-03-24 21:59:50 +03:00
Amy Huang
fd47ab05e5 Add "REQUIRES: asserts" to test that uses --debug-only flag 2023-03-22 17:05:11 -07:00
Job Noorman
54ab954149 [BOLT] Reject symbols pointing to section end
Sometimes, symbols are present that point to the end of a section (i.e.,
one-past the highest valid address). Currently, BOLT either rejects
those symbols when they don't point to another existing section, or errs
when they do and the other section is not executable. I suppose BOLT
would accept the symbol when it points to an executable section.

In any case, these symbols should not be considered while discovering
functions and should not result in an error. This patch implements that.

Note that this patch checks explicitly for symbols whose value equals
the end of their section. It might make more sense to verify that the
symbol's value is within [section start, section end). However, I'm not
sure if this could every happen *and* its value does not equal the end.

Another way to implement this is to verify that the BinarySection we
find at the symbol's address actually corresponds to the symbol's
section. I'm not sure what the best approach is so feedback is welcome.

Reviewed By: yota9, rafauler

Differential Revision: https://reviews.llvm.org/D146215
2023-03-21 13:59:39 +04:00
Mark de Wever
d0398d3593 Revert "Reland "[CMake] Bumps minimum version to 3.20.0.""
This reverts commit a72165e5df.

Some buildbots have not been updated yet.
2023-03-18 20:32:43 +01:00
Mark de Wever
a72165e5df Reland "[CMake] Bumps minimum version to 3.20.0."
This reverts commit 92523a35a8.

Test whether all CI runners are updated.
2023-03-18 13:33:42 +01:00
Vladislav Khmelevsky
f9bf9f925e [BOLT] Add .relr.dyn section support
Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Differential Revision: https://reviews.llvm.org/D146085
2023-03-17 17:24:19 +04:00
Kazu Hirata
4e585e51c1 Use *{Map,Set}::contains (NFC) 2023-03-15 22:55:35 -07:00
Amir Ayupov
c7af4f383d [BOLT][NFC] Simplify preprocessProfile
Move out prepareToParse lambda, generalize it to handle mem events perf process.

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D146002
2023-03-15 12:56:06 -07:00
Kazu Hirata
8bdf387858 Use *{Map,Set}::contains (NFC)
Differential Revision: https://reviews.llvm.org/D146104
2023-03-15 08:46:32 -07:00
Amir Ayupov
edda85771a [BOLT][NFC] Move addRelocation{X86,AArch64} into MCPlusBuilder
The two methods don't belong in BinaryFunction methods.
Move the dispatch tables into target-specific MCPlusBuilder methods.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D131813
2023-03-14 17:34:25 -07:00
Amir Ayupov
ce1061074d [BOLT][NFC] Simplify MCPlusBuilder::getRegSize
Pre-calculate the register size table in MCPlusBuilder constructor,
similar to `AliasMap`/`SmallerAliasMap` in `initAliases`.

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D145828
2023-03-14 17:26:36 -07:00
Amir Ayupov
4e99891e70 [BOLT][NFC] Provide default impl for MIB methods that are only overridden on X86
Simplifies D145687

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D145972
2023-03-14 17:19:24 -07:00
Amir Ayupov
2eae9d8eb2 [BOLT][NFC] Use llvm::is_contained
Apply the replacement throughout BOLT.

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D145464
2023-03-14 15:37:03 -07:00
Amir Ayupov
16e67e6932 [BOLT][NFC] Remove BB::getBranchInfo accepting MCSymbol ptr
Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D144924
2023-03-14 15:35:05 -07:00
Vladislav Khmelevsky
207ea5f2e4 [BOLT] Add writable segment for allocatable sections
The golang support creates 2 new data segments, one of them contains
relocations in PIC binaries, so the section must have writable rights.
Currently BOLT creates only one new segment that contains new sections
with RX rights, now also create RW segment if there are any new writable
sections were allocated during BOLT binary processing.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Differential Revision: https://reviews.llvm.org/D143390
2023-03-15 00:06:55 +04:00
Amir Ayupov
223ec28da4 [BOLT][NFC] Return instruction list from createInstrIncMemory
Leverage move semantics for `std::vector`.

This also makes it consistent with `createInstrumentationSnippet`.

Reviewed By: Elvina

Differential Revision: https://reviews.llvm.org/D145465
2023-03-13 12:56:39 -07:00
Job Noorman
4875e06709 [BOLT][NFC] Improve performance of MCPlusBuilder::initAliases
It was using a redundant iteration over super regs to build
SmallerAliasMap. Removing this results in exactly the same alias maps
and a noticeable performance gain on targets with a large number of
registers.

Just anecdotally: on my machine, processing a small AArch64 binary went
from 2.7s down to 80ms.

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D145779
2023-03-13 11:51:12 -07:00
Vladislav Khmelevsky
40b273998a [BOLT] Pass instrumentation-file arg for X86 xmm test
Differential Revision: https://reviews.llvm.org/D144865
2023-03-13 13:37:28 +04:00
Vladislav Khmelevsky
7117af529e [BOLT] Improve dynamic relocations support for CI
This patch fixes few problems with supporting dynamic relocations in CI.
1. After dynamic relocations and functions were read search for dynamic
relocations located in functions. Currently we expected them only to be
relative and only to be in constant island. Mark islands of such
functions to have dynamic relocations and create CI access symbol on the
relocation offset, so the BD would be created for such place.
2. During function disassemble and handling address reference for
constant island check if the referred external CI has dynamic
relocation. And if it has one we would continue to refer original CI
rather then creating a local copy.
3. After function disassembly stage mark function that has dynamic reloc
in CI as non-simple. We don't want such functions to be optimized, since
such passes as split function would create 2 copies of CI which we
unable to support currently.
4. During updating output values for BF search for BD located in CI and
update their output locations.
5. On dynamic relocation patching stage search for binary data located
on relocation offset. If it was moved use new relocation offset value
rather then an old one.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Differential Revision: https://reviews.llvm.org/D143748
2023-03-13 13:37:28 +04:00
Mark de Wever
92523a35a8 Revert "[CMake] Bumps minimum version to 3.20.0."
Some build bots have not been updated to the new minimal CMake version.
Reverting for now and ping the buildbot owners.

This reverts commit 44c6b905f8.
2023-03-04 18:28:13 +01:00
Mark de Wever
44c6b905f8 [CMake] Bumps minimum version to 3.20.0.
This partly undoes D137724.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.

Reviewed By: mehdi_amini, MaskRay, ChuanqiXu, to268, thieta, tschuett, phosek, #libunwind, #libc_vendors, #libc, #libc_abi, sivachandra, philnik, zibi

Differential Revision: https://reviews.llvm.org/D144509
2023-03-04 12:40:57 +01:00
Amir Ayupov
1e1dfbb94a [BOLT][Instrumentation] Preserve red zone for functions with tail calls only
Allow a function with tail calls only to clobber its red zone.

Fixes https://github.com/llvm/llvm-project/issues/61114.

Reviewed By: #bolt, yota9

Differential Revision: https://reviews.llvm.org/D145202
2023-03-03 12:02:17 -08:00
Maksim Panchenko
73b89e3f38 [BOLT] Remove dependency on StringMap iteration order
Remove the usage of StringMap in places where the iteration order
affects the output since the iteration over StringMap is
non-deterministic.

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D145194
2023-03-03 09:21:26 -08:00
Amir Ayupov
d77f96a9e0 [BOLT][NFC] Simplify BinaryFunction::setTrapOnEntry
Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D144758
2023-02-27 15:41:40 -08:00
Amir Ayupov
c30ab9dcff [BOLT][NFC] Log reversing splitting decision
Expose log for testing purposes.

Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D144674
2023-02-27 15:28:06 -08:00
Amir Ayupov
1c286acfb8 [BOLT] Prevent unsetting unknown control flow for split jump table
In case of a function with unknown control flow but with a single jump
table and a single jump table site, we attempt to match the jump table
and a site and update block successors using jump table targets.
Restrict this behavior for split jump tables which have targets in a
fragment function.

Fixes https://github.com/llvm/llvm-project/issues/60795.

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D144602
2023-02-27 15:22:43 -08:00
Amir Ayupov
08ab4faf1a [BOLT][NFC] Const-ify analyzeJumpTable
Avoid modifying `BF`, instead set extra output parameter and modify BF in caller
scope.

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D144598
2023-02-27 15:22:35 -08:00
Maksim Panchenko
03e94f6608 [BOLT] Change call count output for ICF
ICF optimization runs multiple passes and the order in which functions
are folded could be dependent on the order they are being processed.
This order is indeterministic as functions are intermediately stored in
std::unordered_map<>. Note that this order is mostly stable, but is not
guaranteed to be and can change e.g. after switching to a different C++
library implementation.

Because the processing (and folding) order is indeterministic, the
previous way of calculating merged function call count could produce
different results.

Change the way we calculate the ICF call count to make it independent of
the function folding/processing order.

Mostly NFC as the output binary should remain the same, the change
affects only the console output.

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D144807
2023-02-27 15:21:16 -08:00
Maksim Panchenko
fb28196a64 [BOLT] Fix intermittent crash with instrumentation
When createInstrumentedIndirectCall() was invoked for tail calls, we
attached annotation instruction twice to the new call instruction.
First in createDirectCall(), and then again while copying over the
metadata operands.

As a result, the annotations were not properly stripped for such calls
before the call to freeAnnotations() in LowerAnnotations pass. That lead
to use-after-free while restoring the offsets with setOffset() call.

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D144806
2023-02-27 14:11:10 -08:00
Sebastian Pop
c63c185e72 [BOLT] fix tests on arm64
The two tests were failing on arm64-linux with:
BOLT-ERROR: invalid target 'x86-64'.

Differential Revision: https://reviews.llvm.org/D144593
2023-02-25 16:46:50 +00:00
Shengchen Kan
471c0e000a [BOLT][X86][NFC] Simplify the code of X86MCPlusBuilder::getAliasSized
Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D144551
2023-02-23 10:41:28 +08:00
Amir Ayupov
48a215ae6c [BOLT][NFC] Return struct from evaluateX86MemoryOperand
Simplify `MCPlusBuilder::evaluateX86MemoryOperand`: make it return a struct
with memory operand analysis struct `X86MemOperand`.

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D144310
2023-02-22 12:06:50 -08:00
Vladislav Khmelevsky
b0d1f87b59 [BOLT] Fix data reoder for aarch64
Use proper relocation for aarch64

Differential Revision: https://reviews.llvm.org/D144095
2023-02-22 16:58:43 +04:00
Denis Revunov
abc1f33298 [BOLT][AArch64] Replace NOP with adrp in AdrRelaxationPass to preserve relative offsets.
Avoid replacing one adr instruction with two adrp+add by utilizing linker-provided nops
when they are present. By doing so we preserve relative offsets of next instructions
in a function which reduces chances to break undetected jump tables. This commit makes
release-mode lld-linked clang, lld and etc work after BOLT.

Reviewed By: rafauler, yota9

Differential Revision: https://reviews.llvm.org/D143887
2023-02-22 04:45:19 -05:00
Kristina Bessonova
98b9f8620a [BOLT] Attempt to fix bolt/test/runtime/AArch64/adrrelaxationpass.s after D144079
Differential Revision: https://reviews.llvm.org/D144344
2023-02-19 10:10:29 +02:00
Amir Ayupov
e88122f5f1 [BOLT] Rename BF::isParentFragment -> isChildOf
`isChildOf` is a more concise name for the check. Also, there's no need to
test if the function is a fragment before doing `isChildOf` check.

Reviewed By: #bolt, rafauler, maksfb

Differential Revision: https://reviews.llvm.org/D142667
2023-02-09 10:57:10 -08:00
Amir Ayupov
701109b9b6 [BOLT][Wrapper] Don't compare output upon error exit code
Fix llvm-bolt-wrapper to skip output file checks if llvm-bolt exits with error
code.

Test Plan:
- checkout to revision with invalid NFC mismatch in `is-strip.s` test
  (e.g. 056af487831fb573e6895901d1e48f93922f9635~)
- run `nfc-check-setup.py`
- run `bin/llvm-lit -a tools/bolt/test/X86/is-strip.s`

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D143614
2023-02-09 10:55:12 -08:00
Anton Sidorenko
6820cb2dd5 [Test] Fix YAML mapping keys duplication. NFC.
YAML specification does not allow keys duplication an a mapping. However, YAML
parser in LLVM does not have any check on that and uses only the last key entry.
In this change duplicated keys are merged to satisfy the spec.

Differential Revision: https://reviews.llvm.org/D141848
2023-02-09 12:59:50 +03:00
Amir Ayupov
c49941bd0d [BOLT] Process fragment siblings in lite mode, keep lite mode on
In lite mode, include split function fragments to the list of functions to
process even if a fragment has no samples. This is required to properly
detect and update split jump tables (jump tables that contain pointers to code
in the main and cold fragments).

Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D140457
2023-02-08 19:11:27 -08:00
yavtuk
0776fc32b1 [BOLT] Search section based on relocation symbol
We need to search referenced section based on relocations symbol section
to properly match end section symbols. For example on some binaries we
can observe that init_array_end/fini_array_end might be "placed" in to
the gap and since no section could be found for address the relocation
would be skipped resulting in wrong ADRP imm after emitting new text
resulting in binary sigsegv.

Credits for the test to Vladislav Khmelevskii aka yota9.
2023-02-08 00:15:56 +03:00
Amir Ayupov
056af48783 [BOLT][TEST] Fix is-strip test for NFC testing 2023-02-07 12:19:00 -08:00
Archibald Elliott
62c7f035b4 [NFC][TargetParser] Remove llvm/ADT/Triple.h
I also ran `git clang-format` to get the headers in the right order for
the new location, which has changed the order of other headers in two
files.
2023-02-07 12:39:46 +00:00
Amir Ayupov
c8482da779 [BOLT] Reintroduce allow-stripped
Reject stripped binaries as a policy.

The core issue with stripped binaries is that we can't detect the presence
of split functions which require extra handling. Therefore BOLT can't ensure
functional correctness of produced binary if the input stripped binary contains
split functions. Supporting such cases is an interesting problem but it goes
against BOLT's intended goal of achieving peak program performance.

Reviewed By: maksfb

Differential Revision: https://reviews.llvm.org/D142686
2023-02-06 18:08:13 -08:00
Amir Ayupov
be2f67c4d8 [BOLT][NFC] Replace anonymous namespace functions with static
Follow LLVM Coding Standards guideline on using anonymous namespaces
(https://llvm.org/docs/CodingStandards.html#anonymous-namespaces)
and use `static` modifier for function definitions.

Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D143124
2023-02-06 18:05:41 -08:00
Sebastian Pop
9921197920 [AArch64] fix bug #55005 handle DW_CFA_GNU_NegateRAState
GCC on AArch64 uses DW_CFA_GNU_NegateRAState for return address signing.

Differential Revision: https://reviews.llvm.org/D142572
2023-02-04 03:38:19 +00:00
Amir Ayupov
16492a6143 [BOLT][NFC] Rename {MachO,}RewriteInstance::create methods
Follow the code style of fallible constructors in [LLVM Programmer's Manual]
(https://llvm.org/docs/ProgrammersManual.html#fallible-constructors)
and rename `RewriteInstance::createRewriteInstance` to `RewriteInstance::create`

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D143119
2023-02-02 12:30:45 -08:00
Amir Ayupov
726ba82554 [BOLT][NFC] Simplify SW::checkStackPointerRestore
Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D143117
2023-02-02 12:04:17 -08:00
Amir Ayupov
72e5b14fe7 [BOLT][NFC] Use llvm::make_second_range
Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D143019
2023-02-02 12:02:31 -08:00
Amir Ayupov
4177e89354 [BOLT][CMake] Add dependency on llvm_vcsrevision_h
The dependence is needed since Utils includes VCSRevision.h, and other
LLVM components that include this header also have the llvm_vcsrevision_h
dependency.

Fixes #60460.

Reviewed By: #bolt, ayermolo

Differential Revision: https://reviews.llvm.org/D143101
2023-02-01 12:57:50 -08:00
Alexander Yermolovich
864133c5f9 [BOLT][DWARF] Add logging for split dwarf
Added logging when bolt is processing binary with split dwarf.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D142576
2023-01-27 15:50:55 -08:00
Rafael Auler
7768f63e5b [BOLT][NFC] Remove C-style out of bounds array ref
Old code breaks build with libstdc++ with assertions. Fix it.
2023-01-25 12:59:11 -08:00
Amir Ayupov
287508cd9c [BOLT] Use LTO fuzzy name matching in function-order
Allow partial name matching wrt LTO suffixes in `function-order`
user-supplied function list, the same as permitted by profile matching.

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D142269
2023-01-25 11:43:10 -08:00
Amir Ayupov
e20074053d [BOLT] Emit a warning about invalid entries in function-order list
Move individual warnings under verbosity >= 1, print out a warning with
aggregate number.

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D142397
2023-01-25 11:43:06 -08:00
Jay Foad
fbb003378b [BOLT] Use MCInstrDesc::operands() instead of OpInfo
operands() is the preferred accessor since D142213. OpInfo will be
removed in D142219.

Differential Revision: https://reviews.llvm.org/D142530
2023-01-25 17:26:48 +00:00
Alexander Yermolovich
f230099c13 [BOLT][DWARF] Reuse entries in .debug_addr when not modified
In some binaries produced with ThinLTO there are CUs that share entry in
.debug_addr. Before we would generate a new entry for each. Which lead to binary
size increase. This changes the behavior so that we re-use entries in
.debug_addr.

Reviewed By: maksfb

Differential Revision: https://reviews.llvm.org/D142425
2023-01-24 15:55:03 -08:00
Benjamin Kramer
7557b83aa5 [BOLT] Use range-based implicit def/use accessors. NFCI 2023-01-24 23:12:41 +01:00
Jay Foad
dc4cb724c7 [BOLT] Fix build error after D142214 2023-01-23 13:02:21 +00:00
Amir Ayupov
dbb7316e02 [BOLT][NFC] Move getLTOCommonName to Utils
Reuse getLTOCommonName in components other than Profile (to be used in Core)

Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D142259
2023-01-20 19:52:14 -08:00
Amir Ayupov
e5e07b01d8 [BOLT] Handle __uniq suffix added by -funique-internal-linkage-names
In profile matching, if `.__uniq` suffix added for internal linkage
symbols with `-funique-internal-linkage-names` prevents BOLT from
matching to a binary function, try to strip the suffix and perform
fuzzy name matching.

Follow-up to D124117.

Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D142073
2023-01-20 19:23:06 -08:00
Amir Ayupov
86b47f1438 [BOLT][NFC] Move out ReorderFunctions::printStats
Break out stats-printing code from ReorderFunctions::reorder for brevity.

Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D142250
2023-01-20 15:44:30 -08:00
Alexander Yermolovich
124ca880aa [BOLT][DWARF] Change loclist encoding to use base_addrx
Doing the same thing as for rangelists. Changing loclists to use base_addrx, it
slightly increases .debug_loclists, but reduces .debug_addr section.

| section             | clang-16.bolt.base | clang-16.bolt | raw       |  % |
| debug_loclists |  198208                  |  203398          | 5190     | 102%  |
| .debug_addr    | 14415808              | 14351448        | -64360 |99.5% |

Reviewed By: maksfb

Differential Revision: https://reviews.llvm.org/D141969
2023-01-20 11:30:34 -08:00
Amir Ayupov
69a9bbf106 [BOLT][NFC] Replace ambiguous BinarySection::isReadOnly with isWritable
Address feedback in https://reviews.llvm.org/D102284#2755060

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D141733
2023-01-18 14:53:07 -08:00
Amir Ayupov
43f382a9f4 [BOLT][NFC] Simplify handleRelocation
Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D132089
2023-01-18 14:19:35 -08:00
Amir Ayupov
4a7966ea1b [BOLT][NFC] DataAggregator code cleanup
Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D139794
2023-01-18 13:44:44 -08:00
Amir Ayupov
706606a7df [BOLT][NFC] Remove AArch64 override for evaluateBranch
Use MCInstrAnalysis implementation

Reviewed By: #bolt, rafauler, yota9

Differential Revision: https://reviews.llvm.org/D141983
2023-01-18 13:22:57 -08:00
Arthur Eubanks
59bc64c667 [bolt][test] Add REQUIRES: asserts to jt-symbol-disambiguation-3.s
Or else it unexpectedly passes in non-assert builds of bolt.
2023-01-16 17:50:46 -08:00
Joe Loser
a288d7f937 [llvm][ADT] Replace uses of makeMutableArrayRef with deduction guides
Similar to how `makeArrayRef` is deprecated in favor of deduction guides, do the
same for `makeMutableArrayRef`.

Once all of the places in-tree are using the deduction guides for
`MutableArrayRef`, we can mark `makeMutableArrayRef` as deprecated.

Differential Revision: https://reviews.llvm.org/D141814
2023-01-16 14:49:37 -07:00
Maksim Panchenko
27cf96c4ec [BOLT] Minor refactoring for -print-sorted-by option
Only display used values for -print-sorted-by option when printing help.

Differential Revision: https://reviews.llvm.org/D141209
2023-01-12 13:25:36 -08:00
Rafael Auler
e09f6f41ca [BOLT] Add test case triggering JT assertion
Current case that triggers BOLT assertion. Marked XFAIL.
In this test case, we reproduce the behavior seen in gcc where the
base address of a jump table is decremented by some number and ends up
at the exact addess of a jump table from another function. After
linking, the instruction references another jump table and that
confuses BOLT.

Reviewed By: #bolt, Amir

Differential Revision: https://reviews.llvm.org/D138245
2023-01-11 16:50:16 -08:00
Alexander Yermolovich
7fc7934023 [llvm][dwwarf] Change CU/TU index to 64-bit
Changed contribution data structure to 64 bit. I added the 32bit and 64bit
accessors to make it explicit where we use 32bit and where we use 64bit. Also to
make sure sure we catch all the cases where this data structure is used.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D139379
2023-01-11 15:07:11 -08:00
Alexander Yermolovich
6a4a697e17 Revert "[llvm][dwwarf] Change CU/TU index to 64-bit"
This reverts commit fa3fa4d0d4.
2023-01-11 14:41:24 -08:00