143 Commits

Author SHA1 Message Date
Nicolai Hähnle
377a2767a9 update_test_checks: remove an unused function 2024-04-16 22:04:33 +02:00
Nicolai Hähnle
3846019d8f update_test_checks: keep meta variables stable by default
Resubmitting this after previous revert with the following changes:

- Split table into table_rhs_idx and table_candidate_idx so that
  bisect.bisect_left can be used without the `key` argument, which
  was introduced in Python 3.10
- Remove a re.Pattern type annotation

Original commit message:

Prior to this change, running UTC on larger tests, especially tests
with unnamed IR values, often resulted in a spuriously large diff
because e.g. TMPnn variables in the CHECK lines were renumbered. This
change attempts to reduce the diff by keeping those variable names the
same.

There are cases in which this "drift" of variable names can end up being
more confusing. The old behavior can be re-enabled with the
--reset-variable-names command line argument.

The improvement may not be immediately apparent in the diff of this change.
The point is that the diff of stable_ir_values.ll against
stable_ir_values.ll.expected after this change is smaller.

Ideally, we'd also keep meta variables for "global" objects stable, e.g.
for attributes (#nn) and metadata (!nn). However, that would require a
much more substantial refactoring of how we generate check lines, so I
left it for future work.
2024-03-08 04:33:38 +01:00
Nicolai Hähnle
b565126b4d Revert "update_test_checks: keep meta variables stable by default"
This reverts commit fb02f9ac84a6151e41aba8f7391edd132a9aaf14.

Looks like some Python version incompatibility, will investigate.
2024-03-08 04:25:07 +01:00
Nicolai Hähnle
fb02f9ac84 update_test_checks: keep meta variables stable by default
Prior to this change, running UTC on larger tests, especially tests
with unnamed IR values, often resulted in a spuriously large diff
because e.g. TMPnn variables in the CHECK lines were renumbered. This
change attempts to reduce the diff by keeping those variable names the
same.

There are cases in which this "drift" of variable names can end up being
more confusing. The old behavior can be re-enabled with the
--reset-variable-names command line argument.

The improvement may not be immediately apparent in the diff of this change.
The point is that the diff of stable_ir_values.ll against
stable_ir_values.ll.expected after this change is smaller.

Ideally, we'd also keep meta variables for "global" objects stable, e.g.
for attributes (#nn) and metadata (!nn). However, that would require a
much more substantial refactoring of how we generate check lines, so I
left it for future work.
2024-03-08 03:58:12 +01:00
Nicolai Hähnle
5747f9d3e9 update_test_checks: simplify get_ir_regex
The match argument isn't used.
2024-03-08 03:58:11 +01:00
Nicolai Hähnle
fc1e5f9785 update_test_checks: simplify is_local_def_ir_value
The match argument is unused.
2024-03-08 03:58:11 +01:00
Henrik G. Olsson
6a65b44322
[UTC] Don't leave dangling CHECK-SAME when removing CHECK lines (#82569)
When removing only lines that are global value CHECK lines, a related
CHECK-SAME line could be left dangling without a previous line to belong
to.

Resolves #78517
2024-02-28 17:08:36 -08:00
Luke Lau
283a6b9936
[UTC] Fix SyntaxWarning on Python 3.12 (#82327)
On Python 3.12 we now get a warning in common.py:

llvm/utils/UpdateTestChecks/common.py:488: SyntaxWarning: invalid escape
sequence '\s'

This fixes it by using a raw string literal, see
https://github.com/llvm/llvm-project/pull/78036 and
https://docs.python.org/3/library/re.html
2024-02-20 17:36:01 +08:00
Yi Kong
d6c2cbbc65
Fix test failure if CLANG_VENDOR contains spaces (#81017) 2024-02-08 07:31:34 +09:00
James Y Knight
31aebdd891
Include LLVM_VERSION_SUFFIX in the Clang version string. (#74469)
This causes current mainline to now report "18.0.0git" instead of
"18.0.0".

Fixes #53825
2023-12-05 12:20:12 -05:00
Matthias Braun
331111277a
Support BranchProbabilityInfo in update_analyze_test_checks.py (#72943)
- Change `BranchProbabilityPrinterPass` output to match expectations of `update_analyze_test_checks.py`.
- Add `Branch Probability Analysis` to list of supported analyses.
- Process `llvm/test/Analysis/BranchProbabilityInfo/basic.ll` with `update_analyze_test_checks.py` as proof of concept. Leaving the other tests unchanged to reduce the amount of churn.
2023-11-21 17:08:44 -08:00
Henrik G. Olsson
e6eda66cbc
Recommit changes to global checks (#71171)
Recommits the changes from https://reviews.llvm.org/D148216.
Explicitly named globals are now matched literally, instead of emitting
a capture group for the name. This resolves #70047.
Metadata and annotations, on the other hand, are captured and matched
against by default, since their identifiers are not stable.

The reasons for revert (#63746) have been fixed:
The first issue, that of duplicated checkers, has already been resolved
in #70050.
This PR resolves the second issue listed in #63746, regarding the order
of named and unnamed globals. This is fixed by recording the index of
substrings containing global values, and sorting the checks according to
that index before emitting them. This results in global value checks
being emitted in the order they were seen instead of being grouped
separately.
2023-11-13 14:45:27 +01:00
Florian Hahn
24839c3253
[UTC] Escape multiple {{ or }} in input for check lines. (#71790)
SCEV expressions may contain multiple {{ or }} in the debug output,
which needs escaping.

See
llvm/test/Analysis/LoopAccessAnalysis/loops-with-indirect-reads-and-writes.ll
for a test that needs escaping.
2023-11-09 17:18:11 +00:00
Ramkumar Ramachandra
4c01a58008
update_analyze_test_checks: support output from LAA (#67584)
update_analyze_test_checks.py is an invaluable tool in updating tests.
Unfortunately, it only supports output from the CostModel,
ScalarEvolution, and LoopVectorize analyses. Many LoopAccessAnalysis
tests use hand-crafted CHECK lines, and it is moreover tedious to
generate these CHECK lines, as the output fom the analysis is not
stable, and requires the test-writer to hand-craft FileCheck matches.
Alleviate this pain, and support output from:

  $ opt -passes='print<loop-accesses>'

This patch includes several non-trivial changes including:
- Preserving whitespace at the beginning of the line, so that the LAA
output can be properly indented.
- Regexes matching the unstable output, which is basically a pointer
address hex.
- Separating is_analyze from preserve_names clearly, as the former was
formerly used as an overload for the latter.

To demonstate the utility of this patch, several tests in
LoopAccessAnalysis have been auto-generated by
update_analyze_test_checks.py.
2023-10-31 14:33:53 +00:00
Henrik G. Olsson
da28c33094
[UTC] Recognise CHECK lines with globals matched literally (#70050)
Previously when using `-p` a.k.a. `--preserve-names` existing lines for
checking globals were not recognised as such, leading to the line being
kept while also being emitted again, resulting in duplicated CHECK
lines.

This resolves #70048.
2023-10-30 13:17:26 +01:00
Ramkumar Ramachandra
ac466c7525
UpdateTestChecks: squelch warning on SCEV output (#67443)
update_analyze_test_checks.py currently outputs a warning when updating
a script with the run line:

  $ opt -passes='print<scalar-evolution>'

saying that the script doesn't support its output, when it indeed does,
as evidenced by several tests in test/Analysis/ScalarEvolution generated
by this script. There is even a test for update_analyze_test_checks that
makes sure that SCEV output is supported. Hence, squelch the warning.

While at it, rename the update_analyze_test_checks test from basic.ll to
a more explicit scev.ll.
2023-09-26 19:40:13 +01:00
Jannik Silvanus
998c323910 [UTC] Keep function args parenthesis on label line (bumps version to 3)
If the function argument block contains patterns, we split argument
matching into a separate SAME line, because LABEL labels may not contain
pattern matches.

Until now, in this case we moved the parenthesis opening the argument block
into the second line.

This generates incorrect labels in case function names are not prefix-free.

For example, for a function `foo` we generated:

   CHECK-LABEL: foo
   CHECK-SAME: (<args of foo>)

If the output also contains a function `foo.specialzied`, then the label for
`foo` can match `foo.specialized`, depending on output order.

This patch moves opening parenthesis to the first line, breaking common prefixes:

   CHECK-LABEL: foo(
   CHECK-SAME: <args of foo>)

Bump the UTC version to 3, and only move the parenthesis for version 3 and later.

Differential Revision: https://reviews.llvm.org/D158497
2023-08-29 16:40:06 +02:00
Johannes Doerfert
dcd4d0a790 [UTC] Honor global-value-regex in UTC_ARGS
Without this we cannot update various clang OpenMP tests as the UTC_ARGS
version of -global-value-regex is simply ignored. The handling of the
flag should be changed to be in line with others, I left TODOs for now.
2023-08-23 10:40:30 -07:00
Johannes Doerfert
b9f1df7a04 Revert "[UTC] Add fallback support for specific metadata, and check their defs"
This reverts commit 8a3fdf7b908978625e9a7e57fbb443e4e6f98976 as it is
broken. See https://github.com/llvm/llvm-project/issues/63746.

Effectively fixes: https://github.com/llvm/llvm-project/issues/63746
2023-07-14 13:53:37 -07:00
Johannes Doerfert
75836eb952 Revert "[UTC] Fix git URL regex"
This reverts commit 6d64faf3b1d96f4dba8c2c46b8b65f1cc978e82b, as it is
built on top of https://reviews.llvm.org/D148216 which is broken.

See also https://github.com/llvm/llvm-project/issues/63746
2023-07-14 13:53:37 -07:00
Johannes Doerfert
c1b1c40920 Revert "[UTC] Generalize version regex"
This reverts commit 4488ee259064532dda24024a7e96037fe9a3c0d9, as it is
built on top of https://reviews.llvm.org/D148216 which is broken.

See also https://github.com/llvm/llvm-project/issues/63746
2023-07-14 13:53:36 -07:00
Johannes Doerfert
5b8b9b39cc Revert "[UTC] Adapt version matcher to glob CLANG_VENDOR"
This reverts commit 68f5d1be3d8f9b2ee2f25098203b24a32057b4e6 as it is
built on top of https://reviews.llvm.org/D148216 which is broken.

See also https://github.com/llvm/llvm-project/issues/63746
2023-07-14 13:53:36 -07:00
Paul Robinson
c2bed2a170 [UTC] Add do-not-autogenerate capability
Differential Revision: https://reviews.llvm.org/D154383
2023-07-06 10:56:42 -07:00
Henrik G. Olsson
68f5d1be3d [UTC] Adapt version matcher to glob CLANG_VENDOR
Both the pattern for finding the clang version metadata, and the emitted
checker, are now more robust, to handle a vendor prefix.

Differential Revision: https://reviews.llvm.org/D154520
2023-07-05 17:10:47 +00:00
Nikita Popov
4488ee2590 [UTC] Generalize version regex
The suffix for the git revision may not be present (or may not be
a git revision).
2023-07-05 16:15:47 +02:00
Henrik G. Olsson
6d64faf3b1 [UTC] Fix git URL regex
The previous git URL regex only matched SSH urls, starting with 'git@'.
If the repo was cloned using a https URL it would not match.

rdar://105239218
2023-07-05 14:38:02 +02:00
Henrik G. Olsson
8a3fdf7b90 [UTC] Add fallback support for specific metadata, and check their defs
This prevents update_cc_tests.py from emitting hard-coded identifiers
for metadata (global variable checkers still check hard-coded
identifiers). Instead it emits regex checkers that match even if the
identifiers change. Also adds a new mode for --check-globals: instead of
simply being on or off, it now has the options 'none', 'smart' and
'all', with 'none' and 'all' corresponding to the previous modes.

The 'smart' mode only emits checks for global definitions referenced
in the IR or other metadata that itself has a definition checker
emitted, making the rule transitive. It does not emit checks for
attribute sets, since that is better checked by --check-attributes. This
mode is made the new default. To make the change in default mode
backwards compatible a version bump is introduced (to v3), and the
default remains 'none' in v1 & v2.

This will result in metadata checks being emitted more often, so filters
are added to not check absolute file paths and compiler version git
hashes.

rdar://105239218
2023-07-05 14:04:50 +02:00
Tobias Hieta
b71edfaa4e
[NFC][Py Reformat] Reformat python files in llvm
This is the first commit in a series that will reformat
all the python files in the LLVM repository.

Reformatting is done with `black`.

See more information here:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, JDevlieghere, MatzeB

Differential Revision: https://reviews.llvm.org/D150545
2023-05-17 10:48:52 +02:00
Nikita Popov
fb309041f0 [UTC] Enable --function-signature by default
This patch enables --function-signature by default under --version 2
and makes --version 2 the default. This means that all newly created
tests will check the function signature, while leaving old tests alone.

There's two motivations for this change:

* Without --function-signature, the generated check lines may fail
  in a very hard to understand way if the test both includes a
  function definition and a call to that function. (Though we could
  address this by making the CHECK-LABEL stricter, without checking
  the full signature.)
* This actually checks that uses of the arguments in the function
  body use the correct argument, instead of matching against any
  variable.

This is a replacement for D139006 and D140212 based on the
--version mechanism.

I did not include an opt-out flag --no-function-signature because
I'm not sure we need it. Would be happy to include it though,
if desired.

Differential Revision: https://reviews.llvm.org/D145149
2023-03-07 10:27:52 +01:00
Nikita Popov
a26d3031cf [UTC] Include return type/attributes under --version 2
If --function-signature is used with --version 2, then also include
the return type/attributes in the check lines. This is the
implementation of D133943 rebased on the --version mechanism from
D142473.

This doesn't bump the default version yet, because I'd like to do
that together with D140212 (which enables --function-signature by
default), as these changes seem closely related. For now this
functionality can be accessed by explicitly passing --version 2
to UTC.

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

Differential Revision: https://reviews.llvm.org/D144963
2023-03-02 09:59:22 +01:00
Shengchen Kan
ae691c3812 [UpdateTestChecks][NFC] Share the code to get CHECK prefix between all scripts
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D143307
2023-02-04 10:44:14 +08:00
Nikita Popov
5375b638be [UTC] Add --version argument
We have a number of pending changes to update_test_checks.py
(and friends) that are essentially blocked on test churn:
If the output of UTC for an existing flag combination changes,
then the next time a test is regenerated, it will contain many
spurious changes. This makes changes to UTC default
behavior essentially impossible.

Examples of such changes are:

* D133943/D142373 want --function-signature to also check the
  return type/attributes.
* D139006/D140212 want to make --function-signature the default
  behavior.
* D142452 wants to add wildcards for block labels.

This patch tries to resolve this issue by adding a --version
argument, which works as follows:

* When regenerating an old test, the default version is 1.
* When generating a new test, the default version is the newest.
 When an explicit version is specified, that of course wins.

This means that any currently existing tests will keep using
--version 1 format, while any new tests will automatically embed
--version N where N is the latest version, and then keep using
that test format from then on.

This patch only implements the --version flag without bumping
the default version, so it does not have any visible behavior
change by itself.

Differential Revision: https://reviews.llvm.org/D142473
2023-01-30 09:57:26 +01:00
Nicolai Hähnle
5b39387fb8 UpdateTestChecks: cleanup NamelessValues constructor
Remove global_ir_{prefix,prefix_regexp} (one of which is misnamed),
since they are really quite redundant with ir_{prefix,regexp} and
default the is_before_functions argument, which basically just adds
noise to the table of NamelessValues.

Differential Revision: https://reviews.llvm.org/D142451
2023-01-25 10:06:06 +01:00
Nikita Popov
72dc033fa6 [SROA] Check TBAA metadata in tests (NFC)
By switching to --check-globals. Also make sure that the
!tbaa.struct metadata mapping is preserved.
2023-01-19 17:15:56 +01:00
Alex Richardson
9b2276c004 [UpdateTestChecks] Do not add --force-update to UTC_ARGS
Persisting this flag only introduces test churn.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D141124
2023-01-06 13:35:43 +00:00
Roman Lebedev
6ffbb3f27b
[UpdateTestChecks] Handle !DIAssignID metadata 2022-12-15 21:21:03 +03:00
Nikita Popov
697bfa40a3 Revert "[UpdateTestChecks] Match define for labels"
This reverts commit a888825aeef8d6592c6cf5f4e5854cc39af49633.

This changes the default output of UTC, and as such introduces
spurious changes whenever existing tests are regenerated.

I've indicated in https://reviews.llvm.org/D139006#3989954 how
this can be implemented without causing test churn.
2022-12-13 09:15:35 +01:00
Sebastian Neubauer
a888825aee [UpdateTestChecks] Match define for labels
Previously, the label also matched function calls with the function
name, which caused tests to fail because the label matched on the wrong
line.
Add the `define` prefix, so only function defines are matched.

Differential Revision: https://reviews.llvm.org/D139006
2022-12-12 12:29:54 +01:00
Nicolai Hähnle
cba252de08 update_test_checks: fix typos
Found by our downstream CI.
2022-11-29 23:08:47 +01:00
Mircea Trofin
255e7e1c21 [UpdateTestChecks] Fix update_*_test_checks.py to add "unused" prefixes
The support introduced in D124306 was only added to
update_llc_test_checks.py, but the motivating usecases (see
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
cover update_test_checks.py, update_cc_test_checks.py, and
update_analyze_test_checks.py, too.

Issue #59220.

Differential Revision: https://reviews.llvm.org/D138836
2022-11-28 13:24:32 -08:00
Nikita Popov
304f1d59ca [IR] Switch everything to use memory attribute
This switches everything to use the memory attribute proposed in
https://discourse.llvm.org/t/rfc-unify-memory-effect-attributes/65579.
The old argmemonly, inaccessiblememonly and inaccessiblemem_or_argmemonly
attributes are dropped. The readnone, readonly and writeonly attributes
are restricted to parameters only.

The old attributes are auto-upgraded both in bitcode and IR.
The bitcode upgrade is a policy requirement that has to be retained
indefinitely. The IR upgrade is mainly there so it's not necessary
to update all tests using memory attributes in this patch, which
is already large enough. We could drop that part after migrating
tests, or retain it longer term, to make it easier to import IR
from older LLVM versions.

High-level Function/CallBase APIs like doesNotAccessMemory() or
setDoesNotAccessMemory() are mapped transparently to the memory
attribute. Code that directly manipulates attributes (e.g. via
AttributeList) on the other hand needs to switch to working with
the memory attribute instead.

Differential Revision: https://reviews.llvm.org/D135780
2022-11-04 10:21:38 +01:00
Nicolai Hähnle
0b779494a8 update_test_checks.py: allow use with custom tools
We have a downstream project with a command-line utility that operates
pretty much exactly like `opt`. So it would make sense for us to
maintain tests with update_test_checks.py with our custom tool
substituted for `opt`, as this change allows.

Differential Revision: https://reviews.llvm.org/D136329
2022-10-27 10:06:01 +02:00
Nicolai Hähnle
5a4033c367 update-test-checks: safely handle tests with #if's
There is at least one Clang test (clang/test/CodeGen/arm_acle.c) which
has functions guarded by #if's that cause those functions to be compiled
only for a subset of RUN lines.

This results in a case where one RUN line has a body for the function
and another doesn't. Treat this case as a conflict for any prefixes that
the two RUN lines have in common.

This change exposed a bug where functions with '$' in the name weren't
properly recognized in ARM assembly (despite there being a test case
that was supposed to catch the problem!). This bug is fixed as well.

Differential Revision: https://reviews.llvm.org/D130089
2022-07-20 11:23:49 +02:00
Prabhdeep Singh Soni
ac892c70a4 [OMPIRBuilder] Add support for simdlen clause
This patch adds OMPIRBuilder support for the simdlen clause for the
simd directive. It uses the simdlen support in OpenMPIRBuilder when
it is enabled in Clang. Simdlen is lowered by OpenMPIRBuilder by
generating the loop.vectorize.width metadata.

Reviewed By: jdoerfert, Meinersbur

Differential Revision: https://reviews.llvm.org/D129149
2022-07-11 13:29:06 -04:00
Johannes Doerfert
b0ce93226c [UpdateTestChecks] Handle prefix reuse for appended check lines
When we appended check lines at the end we could not share prefixes
before. This patch should make it possible and allow us to reduce
some check line counts (especially for Clang/OpenMP tests).

See also: https://reviews.llvm.org/D128686

Differential Revision: https://reviews.llvm.org/D128684
2022-06-28 17:18:12 -05:00
Mircea Trofin
6ddc4cd1c2 Fix break introduced by D124306
argparse.BooleanOptionalAction is not supported until python 3.9.
2022-05-26 11:55:19 -07:00
Mircea Trofin
f15c60218d [UpdateTestChecks] Auto-generate stub bodies for unused prefixes
This is scoped to autogenerated tests.

The goal is to support having each RUN line specify a list of
check-prefixes where one can specify potentially redundant prefixes. For example,
for X86, if one specified prefixes for  both AVX1 and AVX2, and the codegen happened to
match today, one of the prefixes would be used and the onther one not.
If the unused prefix were dropped, and later, codegen differences were
introduced, one would have to go figure out where to add what prefix
(paraphrasing
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)

To avoid getting errors due to unused prefixes, whole directories can be
opted out (as discussed on that thread), but that means that tests that
aren't autogenerated in such directories could have undetected unused
prefix bugs.

This patch proposes an alternative that both avoids the above, dir-level
optout, and supports the main autogen scenario discussed first. The autogen
tool appends at the end of the test file the list of unused prefixes,
together with a note explaining that is the case. Each prefix is set up
to always pass.

This way, unexpected unused prefixes are easily discoverable, and
expected cases "just work".

Differential Revision: https://reviews.llvm.org/D124306
2022-05-26 10:23:10 -07:00
Alex Richardson
996873cdcb [UpdateTestChecks] Use a counter for unpredictable FileCheck variables
Variable captures such as `<MCInst #` can change based on unrelated changes
to the LLVM backends, to avoid the generated test cases being different
use an incrementing counter for variable names instead of using the
actual value from the output file.
This change may also be beneficial for some nameless IR variables
(especially when combined with filtering of output), but for now I've
restricted this change to the obvious candidates (--asm-show-inst output).

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D125405
2022-05-14 14:40:50 +00:00
Alex Richardson
37a68497f1 [update_llc_test_checks] Use FileCheck captures for MCInst/MCReg output
To avoid test churn when backends add/rename new instructions/registers,
it makes sense to use FileCheck captures for the exact MCInst/Reg number.
This is motivated by D125307, where I use --asm-show-inst to differentiate
the output for multiple instructions with the same mnemonic.

This does not quite fix the churn issue yet: While files with the generated
checks will be immune to the numbers changing, the update script test
still suffers from this problem since the number is encoded in the
FileCheck variable name. I plan to address this in a follow-up patch.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D125307
2022-05-14 14:15:37 +00:00
Alex Richardson
4b5ad57d67 [UpdateTestChecks] Change global functions to NamelessValue members. NFCI
This avoids repeated calls to get_idx_from_ir_value_match() and will make
it easier for a future patch that adds new assembly-level nameless values
in addition to the IR ones.

Differential Revision: https://reviews.llvm.org/D125390
2022-05-14 14:15:36 +00:00