579 Commits

Author SHA1 Message Date
Aiden Grossman
63c3148354 [llvm-exegesis] Fix stack pointer register restoration
9eb80ab3787e1851be8c686651688e870b93506b changed the method for stack
pointer restoration to fix segmentation faults. However, I made a
mistake in the patch and swapped a != for a ==, which caused an
arbitrary register (the first one specified) to get restored rather than
the stack pointer specifically. This patch fixes that issue and adds
test coverage to prevent regression.
2023-12-22 17:55:26 -08:00
Aiden Grossman
ceb196d990
[llvm-exegesis] Validate that address annotations are aligned (#75554)
This patch adds in validation at two different levels that address
annotations are page aligned. This is necessary as otherwise the mmap
calls will fail as MAP_FIXED/MAP_FIXED_NOREPLACE require page aligned
addresses. This happens silently in the subprocess. This patch adds
validation at snippet parsing time to give feedback to the user and also
adds asserts at code generation/address usage time to ensure that other
users of the Exegesis APIs conform to the same requirements.
2023-12-15 09:45:30 -08:00
Aiden Grossman
3194928c3c
[llvm-exegesis] Refactor MMAP platform-specific preprocessor directives (#75422)
This patch refactors the MMAP platform-specific preprocessor directives
in llvm-exegesis to a single file instead of having duplicate code split
across multiple files. These originally got introduced to get buildbots
green again due to platform specific failures.
2023-12-14 12:07:46 -08:00
David Spickett
0d02ecc6bd [llvm][llvm-exegesis] Fix unused private field warning on Windows
```
[5323/5730] Building CXX object tools\llvm-exegesis\lib\CMakeFiles\LLVMExegesis.dir\Error.cpp.obj
In file included from C:\Work\david.spickett\llvm-project\llvm\tools\llvm-exegesis\lib\Error.cpp:9:
C:\Work\david.spickett\llvm-project\llvm\tools\llvm-exegesis\lib/Error.h(76,7): warning: private field 'SignalNumber' is not used [-Wunused-private-field]
   76 |   int SignalNumber;
      |       ^
```

`SignalNumber` was only being used on Unixes.
2023-12-14 16:01:20 +00:00
Abhina Sree
ec41462d7a
[SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (#75339)
This patch adds strnlen to the zOSSupport.h file to fix build failures in multiple files.
2023-12-13 13:13:53 -05:00
Aiden Grossman
5830e8e745
[llvm-exegesis] Use explicit error classes for different snippet crashes (#74210)
This patch switches to using explicit snippet crashes that contain more
information about the specific type of error (like the address for a
segmentation fault) that occurred. All these new error classes inherit
from SnippetExecutionFailure to allow for easily grabbing all of them in
addition to filtering for specific types using the standard LLVM error
primitives.
2023-12-11 23:15:56 -08:00
Kazu Hirata
586ecdf205
[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-11 21:01:36 -08:00
Clement Courbet
9017229ecd
[llvm-exegesis]Allow clients to do their own snippet running error ha… (#74711)
…ndling.

Returns an error *and* a benchmark rather than an error *or* a
benchmark. This allows users to have custom error handling while still
being able to inspect the benchmark.

Apart from this small API change, this is an NFC.

This is an alternative to #74211.
2023-12-08 13:01:01 +01:00
Aiden Grossman
5058d738ba [llvm-exegesis] Add MAP_FIXED_NOREPLACE definiton
MAP_FIXED_NOREPLACE doesn't exist on older kernels, so we need to define
it to be MAP_FIXED.
2023-12-07 00:47:04 -08:00
Aiden Grossman
fc791b6127
[llvm-exegesis] Add option to specify the number of measurement repetitions (#74276)
Currently, the llvm-exegesis LatencyBenchmarkRunner repeats the
benchmark several times (currently 30) and then aggregates the result to
deal with noise in the measurement process. With this patch, the number
of repetitions to perform is made configurable rather than left as a
static number. This allows for significantly faster execution in
situations where someone is performing a task like experimenting with
memory annotations where the exact cycle counts might not be useful, and
also allows for increased precision when desired.
2023-12-07 00:32:33 -08:00
Aiden Grossman
f1963fde9f Reland "[llvm-exegesis] Add in snippet address annotation (#74218)"
This reverts commit 30d700117b772d94d8474ec56bd6f9cc423fc613.

This relands commit 3ab41f912a6c219a93b87c257139822ea07c8863.

When I was updating the patch to use llvm::to_integer, I only ran the
lit tests and didn't run the unit tests, one of which started to fail.
This patch fixes the broken unit test.
2023-12-07 00:20:24 -08:00
Aiden Grossman
30d700117b Revert "[llvm-exegesis] Add in snippet address annotation (#74218)"
This reverts commit 3ab41f912a6c219a93b87c257139822ea07c8863.

Unit tests break after recent changes. Will investigate/reland.
2023-12-06 11:25:03 -08:00
Aiden Grossman
3ab41f912a
[llvm-exegesis] Add in snippet address annotation (#74218) 2023-12-06 11:05:33 -08:00
Kazu Hirata
c630f95f33 [llvm-exegesis] Remove unnecessary includes (NFC)
Identified with clangd.
2023-12-05 23:28:09 -08:00
Kazu Hirata
06c5c27e44 [llvm-exegesis] Stop including array (NFC)
Identified with clangd.
2023-12-05 20:58:17 -08:00
Aiden Grossman
077fe97736
[llvm-exegesis] Disable core dumps in subprocess (#74144)
Core dumps are currently enabled within the llvm-exegesis subprocess
executor. This can create a lot of core dumps when going through
different snippets that might segfault when experimenting with memory
annotations. These core dumps are not really needed as the information
about the segfault is reported directly to the user.
2023-12-04 01:47:33 -08:00
Kazu Hirata
57eb4826e5 [llvm] Stop including string (NFC)
Identified with clangd.
2023-12-03 16:24:43 -08:00
Kazu Hirata
74ff52345d [llvm] Stop including unordered_map (NFC)
Identified with clangd.
2023-12-03 12:38:42 -08:00
Kazu Hirata
3b1761b845 [llvm] Stop including map (NFC)
Identified with clangd.
2023-12-03 11:31:38 -08:00
Kazu Hirata
520c3b82db [llvm] Stop including llvm/ADT/StringSet.h (NFC)
Identified with clangd.
2023-11-30 23:45:12 -08:00
Aiden Grossman
6688657896 Reland "[llvm-exegesis] Set stack pointer register after starting perf counter (#72489)"
This reverts commit 52b4b357268ac114f7972e37da1e5954f322df09.

This commit was causing build failures on bots without libpfm installed
as the CHECK requires were not set correctly. The test added should only
run on machines with libpfm enabled due to the limitations currently
imposed by the subprocess execution mode.
2023-11-30 15:27:26 -08:00
Aiden Grossman
52b4b35726 Revert "[llvm-exegesis] Set stack pointer register after starting perf counter (#72489)"
This reverts commit 9eb80ab3787e1851be8c686651688e870b93506b.

This is causing failures on multiple builders. Pulling it out until I
have time to fix it.
2023-11-29 02:06:13 -08:00
Aiden Grossman
9eb80ab378
[llvm-exegesis] Set stack pointer register after starting perf counter (#72489)
Before this patch, in subprocess mode, llvm-exegesis setup the stack
pointer register with the rest of the registers when it was requested by
the user. This would cause a segfault when the instructions to start the
perf counter ran as they use the stack to preserve the three registers
needed to make the syscall. This patch moves the setup of the stack
register to after the configuration of the perf counter to fix this
issue so that we have a valid stack pointer for all the preceeding
operations.

Regression test added.

This fixes #72193.
2023-11-29 01:40:42 -08:00
Aiden Grossman
0407248520 Reland "Reland "[llvm-exegesis] Switch from MCJIT to LLJIT (#72838)"
This reverts commit ea5de6021cf69a233106689cc6f0ee14899e1a83.

This patch was reverted as it broke a test on x86_64 Darwin due to the
symbol naming being different between platforms. As Darwin isn't a
supported platform for executing snippets for llvm-exegesis, we can just
disable the test to fix the issue.
2023-11-27 20:48:40 -08:00
Hans Wennborg
ea5de6021c Revert "Reland "[llvm-exegesis] Switch from MCJIT to LLJIT (#72838)""
This broke

  tools/llvm-exegesis/X86/latency/dummy-counters.test

on Mac, see comment on the PR.

> There was an issue with certain configurations failing to build due to a
> deleted Error constructor that should be fixed with this relanding.

This reverts commit 92b821f2dcddbfa934689e10d8f11df150ab1043.
2023-11-27 11:34:55 +01:00
Aiden Grossman
92b821f2dc Reland "[llvm-exegesis] Switch from MCJIT to LLJIT (#72838)"
This reverts commit ddc6ef46418cc419041d0bd85de40d0eb9396848.

This relands commit 12b0ab2c9ce8ef813d9eb888860f20daac3336bd.

There was an issue with certain configurations failing to build due to a
deleted Error constructor that should be fixed with this relanding.
2023-11-25 12:41:08 -08:00
Aiden Grossman
ddc6ef4641 Revert "[llvm-exegesis] Switch from MCJIT to LLJIT (#72838)"
This reverts commit 12b0ab2c9ce8ef813d9eb888860f20daac3336bd.

Currently failing on certain configurations due to a missing
constructor. Pulling out so that I can reproduce the issue and make sure
I fix it before resubmitting.
2023-11-24 12:07:50 -08:00
Aiden Grossman
12b0ab2c9c
[llvm-exegesis] Switch from MCJIT to LLJIT (#72838)
This patch switches from using MCJIT to LLJIT as MCJIT is going to be
deprecated soon.

Fixes #41764.
2023-11-24 11:36:20 -08:00
Aiden Grossman
8a02b70324
[llvm-exegesis] Refactor ExecutableFunction to use a named constructor (#72837)
This patch refactors ExecutableFunction to use a named constructor
pattern, namely adding the create function, so that errors occurring
during the creation of an ExecutableFunction can be propogated back up
rather than having to deal with them in report_fatal_error.
2023-11-24 02:15:34 -08:00
Aiden Grossman
27c98958c0
[llvm-exegesis] Preserve rcx and r11 around system call (#72807)
Currently, when making the ioctl system call, we're not preserving rcx
and r11. The system call will clobber these registers, meaning that the
values of the registers in the snippet will be different than expected.
This patch fixes that be preserving the registers around the system
call, similar to how the other registers involved in the making the
system call get preserved.

Fixes #72741.
2023-11-20 01:11:04 -08:00
Aiden Grossman
3300bc34f7
[llvm-exegesis] Fix race condition in subprocess mode (#72778)
If there were some scheduler effects where something like the parent
process got interrupted while the child process continued to run, there
would be nothing blocking it from exiting before the parent process
issued a PTRACE_ATTACH call. This would cause transient failures as this
occurred pretty rarely. This patch removes the possibility of a
transient failure by ensuring that the parent process attaches to the
child process before sending the counter file descriptor through the
socket, ensuring that the child process has at most progressed to being
blocked in the read call for the counter file descriptor.
2023-11-20 01:10:42 -08:00
Aiden Grossman
add20537cc Reland "[llvm-exegesis] Fix preservation of RDI in subprocess mode (#72458)"
This reverts commit 186db1bcb0096a6af348d7e17866c68fa2004068.

This relands commit 0718c1a8405ac130d72cd3525befed2911618cc7.

The REQUIRES flag in the test that was added only specified that the
machine needed to have the capability to execute the snippet rather than
actually run it with performance counters. This would work with
--dummy-perf-counters, but that is not currently supported in the
subprocess execution mode. So for now, we require the ability to
actually perform measurements to prevent test failures in configurations
that don't have libpfm or access to performance counters.
2023-11-16 14:03:07 -08:00
Aiden Grossman
186db1bcb0 Revert "[llvm-exegesis] Fix preservation of RDI in subprocess mode (#72458)"
This reverts commit 0718c1a8405ac130d72cd3525befed2911618cc7.

The test doesn't have the correct requires string apparently because it
attempts to run on all the buildbots. Reverting until I have time to fix
the test and reland it.
2023-11-16 10:39:53 -08:00
Aiden Grossman
0718c1a840
[llvm-exegesis] Fix preservation of RDI in subprocess mode (#72458)
I made a typo at some point while doing the subprocess implementation,
trying to pop RIP from the stack. For whatever reason, this ends up as
popq %rax after being JITed, which means we aren't properly preserving
the value of %rdi.

Regression test added.

This fixes #72188.
2023-11-16 10:27:10 -08:00
Kazu Hirata
643b2ccd82 [tools] Stop including llvm/ADT/StringMap.h (NFC)
These source files do not use StringMap.h.
2023-10-13 20:50:59 -07:00
Kazu Hirata
4a0ccfa865 Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an
enum. This patch replaces support::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-12 21:21:45 -07:00
Arthur Eubanks
0a1aa6cda2
[NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes (#66295)
This will make it easy for callers to see issues with and fix up calls
to createTargetMachine after a future change to the params of
TargetMachine.

This matches other nearby enums.

For downstream users, this should be a fairly straightforward
replacement,
e.g. s/CodeGenOpt::Aggressive/CodeGenOptLevel::Aggressive
or s/CGFT_/CodeGenFileType::
2023-09-14 14:10:14 -07:00
Kazu Hirata
c7b25faaac [llvm-exegesis] Use range-based for loops (NFC) 2023-09-09 00:27:23 -07:00
Aiden Grossman
9426416994
[llvm-exegesis] Add error handling for fork failures (#65186)
There are still some transient failures on the clang-avx512 builder on
the new subprocess memory tests. Some of them seem to be related to an
inability to fork, but it's hard to debug currently as there is no
explicit error handling for a failed fork call, and nice error reporting
for a failed fork is something that we should have regardless.
2023-09-08 00:27:15 -07:00
Aiden Grossman
c4a769ba03 [llvm-exegesis] Print errno on failures in subprocess
Some error logging in llvm-exegesis under the subprocess executor just
prints a generic failure information rather than any details about the
error as we omit printing the string version of errno. This patch adds
in printing errno at all relevant points in the subprocess executor that
were previously missed.

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D157682
2023-09-05 12:41:49 -07:00
Aiden Grossman
ca8dbdc12a [llvm-exegesis] Add error for subprocess and dummy perf counters
When using the subprocess execution mode and dummy perf counters
currently, cryptic errors will be printed out related to not being able
to send the file descriptor through a socket. This patch prints out an
explicit message that this configuration isn't (currently) supported.

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D157686
2023-09-05 12:34:26 -07:00
Khem Raj
01a92f06f2 [llvm-exegesis] Use mmap2 when mmap is unavailable to fix riscv32 build
Some 32-bit architectures don't have mmap and define mmap2 instead.
E.g. on riscv32 we may get

```
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-17.0.0-r0/git/llvm/tools/llvm-exegesis/lib/X86/Target.cpp:1116:19: error: use of undeclared identifier 'SYS_mmap'
|  1116 |   generateSyscall(SYS_mmap, MmapCode);
|       |                   ^
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-17.0.0-r0/git/llvm/tools/llvm-exegesis/lib/X86/Target.cpp:1134:19: error: use of undeclared identifier 'SYS_mmap'
|  1134 |   generateSyscall(SYS_mmap, GeneratedCode);                                                                                                                                       |       |                   ^
| 1 warning and 2 errors generated.
```

Co-Authored-By: Fangrui Song <i@maskray.me>
Differential Revision: https://reviews.llvm.org/D158375
2023-08-25 10:43:00 -07:00
Pavel Kosov
742fa941f2 [llvm-exegesis] Skip codegen of known-invalid snippets
On some targets, not all types of instruction operands are currently
handled. Instead of stopping the whole llvm-exegesis run because of any
instruction opcode that is not fully supported, write a per-opcode error
message and proceed to other opcodes. This improves the reliability of
--opcode-index=-1 sweep on partially supported targets.

Depends on: D146302, D146303

~~

Huawei RRI, OS Lab

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D146304
2023-08-25 16:43:43 +03:00
Michael Maitland
85e3875ad7 [TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics
D150312 added a TODO:

TODO: consider renaming the field `StartAtCycle` and `Cycles` to
`AcquireAtCycle` and `ReleaseAtCycle` respectively, to stress the
fact that resource allocation is now represented as an interval,
relatively to the issue cycle of the instruction.

This patch implements that TODO. This naming clarifies how to use these
fields in the scheduler. In addition it was confusing that `StartAtCycle` was
singular but `Cycles` was plural. This renaming fixes this inconsistency.

This commit as previously reverted since it missed renaming that came
down after rebasing. This version of the commit fixes those problems.

Differential Revision: https://reviews.llvm.org/D158568
2023-08-24 19:21:36 -07:00
Michael Maitland
71bfec762b Revert "[TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics"
This reverts commit 5b854f2c23ea1b000cb4cac4c0fea77326c03d43.

Build still failing.
2023-08-24 15:37:27 -07:00
Michael Maitland
5b854f2c23 [TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics
D150312 added a TODO:

TODO: consider renaming the field `StartAtCycle` and `Cycles` to
`AcquireAtCycle` and `ReleaseAtCycle` respectively, to stress the
fact that resource allocation is now represented as an interval,
relatively to the issue cycle of the instruction.

This patch implements that TODO. This naming clarifies how to use these
fields in the scheduler. In addition it was confusing that `StartAtCycle` was
singular but `Cycles` was plural. This renaming fixes this inconsistency.

This commit as previously reverted since it missed renaming that came
down after rebasing. This version of the commit fixes those problems.

Differential Revision: https://reviews.llvm.org/D158568
2023-08-24 15:25:42 -07:00
Michael Maitland
4d27dffb43 Revert "[TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics"
This reverts commit 030d33409568b2f0ea61116e83fd40ca27ba33ac.

This commit is causing build failures
2023-08-24 11:58:53 -07:00
Michael Maitland
030d334095 [TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics
D150312 added a TODO:

TODO: consider renaming the field `StartAtCycle` and `Cycles` to
`AcquireAtCycle` and `ReleaseAtCycle` respectively, to stress the
fact that resource allocation is now represented as an interval,
relatively to the issue cycle of the instruction.

This patch implements that TODO. This naming clarifies how to use these
fields in the scheduler. In addition it was confusing that `StartAtCycle` was
singular but `Cycles` was plural. This renaming fixes this inconsistency.

Differential Revision: https://reviews.llvm.org/D158568
2023-08-24 11:20:37 -07:00
Aiden Grossman
34e3bc0b92 [llvm-exegesis] Replace size_t with ssize_t where relevant
Currently BenchmarkRunner.cpp stores the return code of recvmsg as
size_t. Not only is this incorrect (as recvmsg returns ssize_t), but it
also makes the error code check after the statement completely irrelvant
as it checks if the number of bytes read is greater than zero (which
will always be true for an unsigned type).
2023-08-22 23:44:05 -07:00
Guillaume Chatelet
f70e83af7a [llvm-exegesis] Don't try to use SYS_rseq if it's not defined.
When compiling against recent glibc (>= 2.35) but old kernel headers (< 4.18), `SYS_rseq` is not defined and thus llvm-exegesis fails to build. So also check that `SYS_rseq` is defined before trying to use it.

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

Reviewed By: MaskRay, gchatelet

Differential Revision: https://reviews.llvm.org/D157189
2023-08-07 07:32:44 +00:00