486 Commits

Author SHA1 Message Date
NAKAMURA Takumi
7d5d987e93 [CMake] Reorder and reformat deps 2023-04-17 00:32:16 +09:00
Jie Fu
62a0049ae4 [llvm-exegesis] Fix -Wc++98-compat-extra-semi in BenchmarkRunner.cpp (NFC)
/data/llvm-project/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp:66:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-W
c++98-compat-extra-semi]
};
 ^
1 error generated.
2023-04-14 15:46:09 +08:00
Aiden Grossman
d22805940a [llvm-exegesis] Refactor common parts out of FunctionExecutorImpl
This patch refactors some code out of FunctionExecutorImpl into the base
class that should be common across all implementations of
FunctionExecutor. Particularly, this patch factors out
accumulateCounterValues, and also factors out runAndSample, moving
implementation specific code into a new runWithCounter function. This
makes adding new implementations of FunctinExecutor easier.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D148079
2023-04-14 07:37:28 +00:00
Aiden Grossman
999a8b8ce9 [llvm-exegesis][NFC] remove runAndMeasure
This completes the FIXME listed in FunctionExecutor in regards to
deprecating this function. It simply makes the appropriate call into
runAndSample and grabs the first counter value. This patch completely
removes the function, moving that logic into the callers (currently only
uopsBenchmarkRunner). This makes creating new FunctionExecutors easier
as an implementation no longer needs to worry about this detail.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D147878
2023-04-14 07:16:34 +00:00
David Blaikie
df9af1fe7c Remove redundant get() call and use auto on LHS of make_unique 2023-04-07 22:12:52 +00: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
Pavel Kosov
5348a25377 [llvm-exegesis][AArch64] Add return statement at the end of the snippet correctly
Currently llvm-exegesis fails to do this which causes every snippet to crash

~~

Huawei RRI, OS Lab

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D147699
2023-04-06 14:56:53 +03:00
Pavel Kosov
b02e2ed7ac [llvm-exegesis] Make possible to execute snippets without perf counters
Performance counters may be unavailable due to various reasons (such as
access restriction via sysctl properties or the CPU model being unknown
to libpfm). On the other hand, for debugging llvm-exegesis itself it is
still useful to be able to run generated code snippets to ensure that
the snippet does not crash at run time.

The --use-dummy-perf-counters command line option makes llvm-exegesis
behave just as usual except for using fake event counts instead of asking
the kernel for actual values.

~~

Huawei RRI, OS Lab

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D146301
2023-04-06 13:08:48 +03:00
Pavel Kosov
39fc67b8af [llvm-exegesis] Factor out DisassemblerHelper from the Analysis class
As part of preparing the reports, the Analysis class needs to print
machine instructions in a disassembled form. For this purpose, the class
has four fields (namely Context_, AsmInfo_, InstPrinter_ and Disasm_).
All the constructor of the Analysis class does is conditionally
initializing these four fields.

This commit factors out the logic for decoding machine code and printing
it in an assembler form into a separate DisassemblerHelper class.

~~

Huawei RRI, OS Lab

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D147156
2023-04-04 09:17:50 +03:00
Aiden Grossman
389bf5d870 [llvm-exegesis] Refactor InstructionBenchmark to Benchmark
When llvm-exegesis was first introduced, it only supported benchmarking
individual instructions, hence the name for the data structure storing
the data corresponding to a benchmark being called InstructionBenchmark
made sense. However, now that benchmarking arbitrary snippets is
supported, InstructionBenchmark doesn't correspond to a single
instruction. This patch refactors InstructionBenchmark to be called
Benchmark to clean up this little bit of technical debt.

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D146884
2023-03-27 08:14:36 +00:00
Kazu Hirata
8bdf387858 Use *{Map,Set}::contains (NFC)
Differential Revision: https://reviews.llvm.org/D146104
2023-03-15 08:46:32 -07:00
Nikita Popov
eea0d06f88 [llvm-exegesis] Include more specific header (NFC) 2023-03-02 11:24:10 +01:00
Archibald Elliott
d768bf994f [NFC][TargetParser] Replace uses of llvm/Support/Host.h
The forwarding header is left in place because of its use in
`polly/lib/External/isl/interface/extract_interface.cc`, but I have
added a GCC warning about the fact it is deprecated, because it is used
in `isl` from where it is included by Polly.
2023-02-10 09:59:46 +00: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
David Blaikie
0e754e114a Migrate away from C++20-deprecated POD type traits 2023-01-26 00:14:58 +00:00
Jay Foad
073401e59c [MC] Define and use MCInstrDesc implicit_uses and implicit_defs. NFC.
The new methods return a range for easier iteration. Use them everywhere
instead of getImplicitUses, getNumImplicitUses, getImplicitDefs and
getNumImplicitDefs. A future patch will remove the old methods.

In some use cases the new methods are less efficient because they always
have to scan the whole uses/defs array to count its length, but that
will be fixed in a future patch by storing the number of implicit
uses/defs explicitly in MCInstrDesc. At that point there will be no need
to 0-terminate the arrays.

Differential Revision: https://reviews.llvm.org/D142215
2023-01-23 14:44:58 +00:00
Jay Foad
768aed1378 [MC] Make more use of MCInstrDesc::operands. NFC.
Change MCInstrDesc::operands to return an ArrayRef so we can easily use
it everywhere instead of the (IMHO ugly) opInfo_begin and opInfo_end.
A future patch will remove opInfo_begin and opInfo_end.

Also use it instead of raw access to the OpInfo pointer. A future patch
will remove this pointer.

Differential Revision: https://reviews.llvm.org/D142213
2023-01-23 11:31:41 +00:00
Kazu Hirata
caa99a01f5 Use llvm::popcount instead of llvm::countPopulation(NFC) 2023-01-22 12:48:51 -08:00
Piotr Fusik
898b5c9f5e [NFC] Fix "form/from" typos
Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D142007
2023-01-22 20:05:51 +01:00
Guillaume Chatelet
bb37cab8a5 [llvm-exegesis][NFC] Update benchmark phase naming to match documentation 2023-01-06 13:40:46 +00:00
Roman Lebedev
866c587af3
[NFC][exegesis] SnippetGenerator::generateConfigurations(): don't forget to reserve() 2023-01-05 21:39:04 +03:00
Roman Lebedev
b5b79e51b4
[NFC][exegesis] BenchmarkCodeStreamer: use existing RegNameToRegNo map 2023-01-05 20:11:56 +03:00
Roman Lebedev
e0ad2af691
[exegesis] "Skip codegen" dry-run mode
While "skip measurements mode" is super useful for test coverage,
i've come to discover it's trade-offs. It still calls back-end
to actually codegen the target assembly, and that is what is taking
80%+ of the time regardless of whether or not we skip the measurements.

On the other hand, just being able to see that exegesis can come up
with a snippet to measure something, is already very useful,
and takes maybe a second for a all-opcode sweep.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D140702
2023-01-05 17:47:17 +03:00
serge-sans-paille
38818b60c5
Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ part
Use deduction guides instead of helper functions.

The only non-automatic changes have been:

1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*))
2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase.
3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated.
4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that).

Per reviewers' comment, some useless makeArrayRef have been removed in the process.

This is a follow-up to https://reviews.llvm.org/D140896 that introduced
the deduction guides.

Differential Revision: https://reviews.llvm.org/D140955
2023-01-05 14:11:08 +01:00
Roman Lebedev
6a67b633b9
[exegesis] Analysis: filtering for benchmark results
By default, all benchmark results are analysed, but sometimes it may be useful
to only look at those that to not involve memory, or vice versa. This option
allows to either keep all benchmarks, or filter out (ignore) either all the
ones that do involve memory (involve instructions that may read or write to
memory), or the opposite, to only keep such benchmarks.

Personally, so far i have found the benchmarks that do involve memory
to have dubious results. But the ones that do not involve memory,
are generally actionable. So i would like to have a toggle to declutter results.

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D140734
2023-01-04 21:16:11 +03:00
Roman Lebedev
498704d511
[NFC][exegesis] By default, don't dump objects to disk
It's a strictly-developer feature, which is useless most of the time.

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

Reviewed By: RKSimon, gchatelet

Differential Revision: https://reviews.llvm.org/D140700
2022-12-28 16:56:54 +03:00
Roman Lebedev
03aa6b9197
[NFC][llvm-exegesis] Ensure that target options show up in --help
Fixes https://github.com/llvm/llvm-project/issues/59377
2022-12-21 03:38:30 +03:00
Roman Lebedev
a5b56313dd
[llvm-exegesis] AliasingConfigurations: pay attention to forbidden registers
When trying to measure latency of certain opcodes, e.g.
`./bin/llvm-exegesis --opcode-name=BT32ri8 --mode=latency --repetition-mode=loop  --benchmarks-file=- --max-configs-per-opcode=65536`,
we'd pick such an aliasing instruction, and such an aliasing registers,
that would alias with forbidden registers.

And in particular with loop counter in `loop` repetition mode,
which made the measurements never finish.
This does not address all such cases, only the most obvious one.

The added test case fails without the patch.

Fixes https://github.com/llvm/llvm-project/issues/59441
2022-12-21 02:01:14 +03:00
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +00:00
Archibald Elliott
142aa1bdd1 [Support] Move Target/CPU Printing out of CommandLine
This change is rather more invasive than intended. The main intention
here is to make CommandLine.cpp not rely on llvm/Support/Host.h. Right
now, this reliance is only in 3 superficial places:
- Choosing how to expand response files (in two places)
- Printing the default triple and current CPU in `--version` output.

The built in version system has a method for adding "extra version
printers", commonly used by several tools (such as llc) to report the
registered targets in the built version of LLVM. It was reasonably easy
to move the logic for printing the default triple and current CPU into
a similar function, and register it with any relevant binaries.

The incompatible change here is that now, even if
LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO is defined, most binaries
will no longer print out the default target triple and cpu when provided
with `--version`, for instance llvm-as and llvm-dis. This breakage is
intended, but the changes in this patch keep printing the default target
and detected in `llc` and `opt` as these were remarked as important
binaries in the LLVM install.

The change to expanding response files may also be controversial, but I
believe that these macros should correspond exactly to the host triple
introspection used before.

Differential Revision: https://reviews.llvm.org/D137837
2022-12-20 09:56:14 +00:00
Roman Lebedev
8c3a835990
[NFC][llvm-exegesis] Try to fix GCC7 build
https://lab.llvm.org/staging/#/builders/235/builds/1121
2022-12-19 18:10:18 +03:00
Roman Lebedev
e9972a7113
[NFC][llvm-exegesis] Try to fix GCC7 build
https://lab.llvm.org/staging/#/builders/235/builds/1090
2022-12-19 17:15:27 +03:00
Roman Lebedev
8685445b3c
[llvm-exegesis][X86] Explicitly not support WRFSBASE opcode.
We can't serialize if for latency measurements, and when measuring uops,
it crashes so hard even `CrashRecoveryContext` doesn't stop it.

Looks like *this* was the last crasher, now `--opcode-index=-1`
succeeds for all three benchmark modes here.
At least with Duplication repetitor.
2022-12-18 20:07:02 +03:00
Roman Lebedev
3ebfc88637
[NFC][llvm-exegesis] Improve getOpcodesOrDie()
We already have opcode name -> opcode index map, use it.
Reserve memory where appropriate.
2022-12-18 20:07:02 +03:00
Roman Lebedev
f95ddf0ee7
[llvm-exegesis] Benchmark: gracefully handle lack of configurations to run
Otherwise the progress meter would assert.
2022-12-18 20:07:02 +03:00
Roman Lebedev
18da9a0cb3
[llvm-exegesis] Fix 'min' repetition mode in presence of missing measurements
This was a regression from 17e202424c021fd903950fec7a8b6cca2d83abce.
Previously we'd gracefully handle missing measurements,
but that handling got accidentally lost during the code move,
and we'd assert.

What we want to do, is to discard all measurements (from all repetitors
in a given config) if any of them failed, but do append the snippet,
and do emit the empty measurement.
2022-12-18 17:52:04 +03:00
Roman Lebedev
dbc76ef791
[NFC][llvm-exegesis] Benchmark: move DumpObjectToDisk handling into runConfiguration()
`getRunnableConfiguration()` may be executed in parallel,
and then this the output would become even less useful.
2022-12-18 17:52:04 +03:00
Roman Lebedev
81b35aa69f
[NFC][llvm-exegesis] Extract runBenchmarkConfigurations() out of benchmarkMain()
`benchmarkMain()` is already bigger than it should be,
let's extract the important chunk before making it even larger.
2022-12-18 04:23:20 +03:00
Roman Lebedev
1dd4a6aac6
[NFC][llvm-exegesis] BenchmarkRunner: split runConfiguration() into getRunnableConfiguration() + runConfiguration()
We can run as many `getRunnableConfiguration()` in parallel as we want,
but `runConfiguration()` must be run *completely* standalone from everything.
This is a step towards enabling threading.
2022-12-18 04:23:20 +03:00
Roman Lebedev
a5de49755c
[NFC][llvm-exegesis] InstructionBenchmark: only allow move constructor
We don't ever legitimately need to copy it, so let's make that explicit
2022-12-18 04:23:20 +03:00
Roman Lebedev
a340019113
[llvm-exegesis] Unbreak --benchmarks-file=<f>
I'm absolutely flabbergasted by this.
I was absolutely sure this worked.
But apparently not.

When outputting to the file, we'd write a single `InstructionBenchmark`
to it, and then close the file. And for the next `InstructionBenchmark`,
we'd reopen the file, truncating it in process,
and thus the first `InstructionBenchmark` would be gone...
2022-12-18 03:50:10 +03:00
Roman Lebedev
118b49a09b
[NFCI][llvm-exegesis] BenchmarkRunner::runConfiguration(): extract assembleSnippet() helper 2022-12-17 23:14:53 +03:00
Roman Lebedev
41dd767fee
[NFC][llvm-exegesis] BenchmarkRunner::runConfiguration(): deduplicate DumpObjectToDisk handling
Always assemble into buffer, that is then optionally dumped into file.
2022-12-17 23:14:53 +03:00
Roman Lebedev
0db620aa30
[NFC][llvm-exegesis] BenchmarkRunner::runConfiguration(): reformat 2022-12-17 23:14:53 +03:00
Roman Lebedev
17e202424c
[NFCI][llvm-exegesis] Extract 'Min' repetition handling from BenchmarkRunner into it's caller
If `BenchmarkRunner::runConfiguration()` deals with more than a single
repetitor, tasking will be less straight-forward to implement.
But i think dealing with that in it's callee is even more readable.
2022-12-17 23:14:52 +03:00
Roman Lebedev
5b1592b5c5
[NFC][llvm-exegesis] LLVMState: only store references to reg/op names
We know that the original reference from which we've built these maps
will persist, so we do not need to copy the names.
2022-12-17 17:10:48 +03:00
Nikita Popov
1f53426895 [ProgressMeter] Remove unnecessary semicolon (NFC)
Fix compiler warning.
2022-12-15 17:05:05 +01:00
Kazu Hirata
6eb0b0a045 Don't include Optional.h
These files no longer use llvm::Optional.
2022-12-14 21:16:22 -08:00
Fangrui Song
da2f5d0a41 [tools] llvm::Optional => std::optional 2022-12-14 08:01:04 +00:00
Roman Lebedev
a33ae9ac35
[NFC][CMake] Explicitly link to MC when needed
These targets use `MCInst`, but don't explicitly link
to the library providing it (MC), and just rely on it
being pulled transitively through e.g. MCDisassembler,
but that only pulls includes, and does not link to it.

Case in point, when i add explicit destructor to `MCInst`,
defined in `.cpp`, these targets were failing to link.
2022-12-13 16:24:46 +03:00