aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/update_test_checks.py
AgeCommit message (Collapse)AuthorFilesLines
2025-09-10[UTC] Record TBAA semantics when autogenerating check linesAntonio Frighetto1-0/+10
UpdateTestChecks have been updated to take into account TBAA semantics as well, when emitting checks. This is achieved by parsing TBAA metadata for each tool invocation – whose tool is identified by their prefixes –, and maintaining a global dict of prefixes, TBAA nodes.
2025-05-09update_test_checks: indent dbg records (#139230)Orlando Cazalet-Hyams1-2/+5
LLVM prints debug records like `#dbg_value` indented 2 additional spaces.
2025-04-30Change update_xxx_checks to continue on error when processing mutliple ↵Matthias Braun1-262/+265
inputs (#137728) Change llvm/utils/update_xxx_checks.py scripts to: Catch exceptions individually for each test. On exception print which test triggered the exception and continue with the remaining test updates.
2025-02-19UpdateTestChecks: Don't check meta details in func definition w/--global ↵Jinsong Ji1-1/+3
none (#124205) When --check-globals none, we skipped all the globals in check lines. However, we are still checking the meta info in function defintion. The generated checks are still sensitive to metadata changes. This is to scrub the meta info and match them with {{.*}} instead.
2024-09-23update_test_checks: recognize %if in RUN line (#108972)Elvina Yakubova1-1/+7
Recognize %if for target-specific cases in RUN line and keep only tool command with options
2024-05-19update_test_checks: match IR basic block labels (#88979)Nicolai Hähnle1-4/+11
Labels are matched using a regexp of the form '^(pattern):', which requires the addition of a "suffix" concept to NamelessValue. Aside from that, the key challenge is that block labels are values, and we typically capture values including the prefix '%'. However, when labels appear at the start of a basic block, the prefix '%' is not included, so we must capture block label values *without* the prefix '%'. We don't know ahead of time whether an IR value is a label or not. In most cases, they are prefixed by the word "label" (their type), but this isn't the case in phi nodes. We solve this issue by leveraging the two-phase nature of variable generalization: the first pass finds all occurences of a variable and determines whether the '%' prefix can be included or not. The second pass does the actual substitution. This change also unifies the generalization path for assembly with that for IR and analysis, in the hope that any future changes avoid diverging those cases future. I also considered the alternative of trying to detect the phi node case using more regular expression special cases but ultimately decided against that because it seemed more fragile, and perhaps the approach of keeping a tentative prefix that may later be discarded could also be eventually applied to some metadata and attribute cases. Note that an early version of this change was reviewed as https://reviews.llvm.org/D142452, before version numbers were introduced. This is a substantially updated version of that change.
2024-03-08update_test_checks: keep meta variables stable by defaultNicolai Hähnle1-3/+19
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-08Revert "update_test_checks: keep meta variables stable by default"Nicolai Hähnle1-19/+3
This reverts commit fb02f9ac84a6151e41aba8f7391edd132a9aaf14. Looks like some Python version incompatibility, will investigate.
2024-03-08update_test_checks: keep meta variables stable by defaultNicolai Hähnle1-3/+19
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-02-28[UTC] Don't leave dangling CHECK-SAME when removing CHECK lines (#82569)Henrik G. Olsson1-1/+9
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
2023-11-13Recommit changes to global checks (#71171)Henrik G. Olsson1-3/+9
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-07-14Revert "[UTC] Add fallback support for specific metadata, and check their defs"Johannes Doerfert1-9/+3
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-05[UTC] Add fallback support for specific metadata, and check their defsHenrik G. Olsson1-3/+9
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-05-17[NFC][Py Reformat] Reformat python files in llvmTobias Hieta1-212/+281
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-03-02[UTC] Include return type/attributes under --version 2Nikita Popov1-0/+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-02-04[UpdateTestChecks][NFC] Share the code to get CHECK prefix between all scriptsShengchen Kan1-6/+1
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D143307
2023-01-25update_test_checks.py: pick up --tool from UTC_ARGSNicolai Hähnle1-1/+2
It's not clear to me how to write a test for this. The tests run in an environment where the tools may not be in PATH, and so the existing custom-tool.test needs to use --tool-binary when invoking update_test_checks.py. But it can't do so without also using --tool. This change does fix a problem though with using update_any_test_checks.py in an environment where the tools *are* available in PATH. Differential Revision: https://reviews.llvm.org/D142450
2022-11-29update_test_checks: fix typosNicolai Hähnle1-1/+1
Found by our downstream CI.
2022-11-28[UpdateTestChecks] Fix `update_*_test_checks.py` to add "unused" prefixesMircea Trofin1-26/+52
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-10-27update_test_checks.py: allow use with custom toolsNicolai Hähnle1-14/+30
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-07-20update-test-checks: safely handle tests with #if'sNicolai Hähnle1-0/+1
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-08[UpdateTestChecks] Remove outdated help textNikita Popov1-5/+0
Manually modifying the result of update_test_checks.py is discouraged, we prefer unmodified check lines where possible. The output is also considered authoritative nowadays, at least for tests targeting core middle-end components, where not using it is an automatic review rejection. Differential Revision: https://reviews.llvm.org/D129259
2022-01-31[UpdateTestChecks] Re-add --filter and --filter-out optionsDavid Greene1-2/+4
Re-add filtering options with fixes for failed tests. We were not passing the is_filtered argument in all check generator calls in update_cc_test_checks.py Enhance the various update_*_test_checks.py tools to allow filtering the tool output with regular expressions. The --filter option will emit only tool output lines matching the given regular expression while the --filter-out option will emit only tools output lines not matching the given regular expression. Filters are applied in order of appearance on the command line (or in UTC_ARGS) and the first matching filter terminates the search. This allows test authors to create more focused tests by removing irrelevant tool output and checking only the pieces of output necessary to test the desired functionality. Differential Revision: https://reviews.llvm.org/D117694
2022-01-28Revert "[UpdateTestChecks] Add --filter and --filter-out options"David Greene1-4/+2
Broke some update-test-checks tests. Reverting while developing a fix. This reverts commit 030f71698d52f228929da5e3148602f4a3daff7d.
2022-01-28[UpdateTestChecks] Add --filter and --filter-out optionsDavid Greene1-2/+4
Enhance the various update_*_test_checks.py tools to allow filtering the tool output with regular expressions. The --filter option will emit only tool output lines matching the given regular expression while the --filter-out option will emit only tools output lines not matching the given regular expression. Filters are applied in order of appearance on the command line (or in UTC_ARGS) and the first matching filter terminates the search. This allows test authors to create more focused tests by removing irrelevant tool output and checking only the pieces of output necessary to test the desired functionality. Differential Revision: https://reviews.llvm.org/D117694
2021-07-29[Utils] Do not remove comments in llc test scriptSebastian Neubauer1-1/+1
When checking if two prefixes can be merged for a function, update_llc_test_checks.py removed IR comments before comparing llc outputs of different RUN lines. This means, if one RUN line emited lines starting with ';' and another RUN line emited the same lines except the ones starting with ';', both RUNs would be merged (if they share a prefix). However, CHECK-NEXT lines check the comments, otherwise they fail, so the script should not merge RUNs if they contain different comments. Differential Revision: https://reviews.llvm.org/D101312
2021-06-20[UpdateTestUtils] Print test filename when complaining about conflicting prefixRoman Lebedev1-1/+2
Now that FileCheck eagerly complains when prefixes are unused, the update script does the same, and is becoming very common to need to drop some prefixes, yet figuring out the file it complains about isn't obvious unless it actually tells us.
2021-04-28[update_(llc_)test_checks.py] Support pre-processing commandsAlex Richardson1-5/+12
This has been rather useful in our downstream CHERI target where we want to run tests both with addrspace(0) and addrspace(200) pointers. With this patch we can prefix the opt command with `sed -e 's/addrspace(200)/addrspace(0)/g' -e 's/-A200-P200-G200//g'` to test both cases using the same IR input. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D95137
2021-03-11[Utils] Check for more global information in update_test_checksJohannes Doerfert1-11/+23
This allows to check for various globals (metadata/attributes/...) and also resolves problems with globals (metadata/attributes/...) being reused across different prefixes. Reviewed By: sstefan1 Differential Revision: https://reviews.llvm.org/D94741
2020-12-16[NFC] factor update test function test builder as a classMircea Trofin1-13/+12
This allows us to have shared logic over multiple test runs, e.g. do we have unused prefixes, or which function bodies have conflicting outputs for a prefix appearing in different RUN lines. This patch is just wrapping existing functionality, and replacing its uses. A subsequent patch would then fold the current functionality into the newly introduced class. Differential Revision: https://reviews.llvm.org/D93413
2020-11-09[update_test_checks] Allow opt to have .exe file extensionArthur Eubanks1-1/+1
Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D91091
2020-09-18[UpdateCCTestChecks] Include generated functions if askedDavid Greene1-37/+65
Add the --include-generated-funcs option to update_cc_test_checks.py so that any functions created by the compiler that don't exist in the source will also be checked. We need to maintain the output order of generated function checks so that CHECK-LABEL works properly. To do so, maintain a list of functions output for each prefix in the order they are output. Use this list to output checks for generated functions in the proper order. Differential Revision: https://reviews.llvm.org/D83004
2020-08-12[UpdateTestChecks] Match unnamed values like "@[0-9]+" and "![0-9]+"Johannes Doerfert1-1/+3
With this patch we will match most *uses* of "temporary" named things in the IR via regular expressions, not their name at creation time. The new "values" we match are: - "unnamed" globals: `@[0-9]+` - debug metadata: `!dbg ![0-9]+` - loop metadata: `!loop ![0-9]+` - tbaa metadata: `!tbaa ![0-9]+` - range metadata: `!range ![0-9]+` - generic metadata: `metadata ![0-9]+` - attributes groups: `#[0-9]` We still don't match the declarations but that can be done later. This patch can introduce churn when existing check lines contain the old hardcoded versions of the above "values". We can add a flag to opt-out, or opt-in, if necessary. Reviewed By: arichardson, MaskRay Differential Revision: https://reviews.llvm.org/D85099
2020-07-19[Utils] Check function attributes in update_test_checkssstefan11-1/+3
Summary: This introduces new flag to the update_test_checks and update_cc_test_checks that allows for function attributes to be checked in a check-line. If the flag is not set, the behavior should remain the same. Reviewers: jdoerfert Subscribers: arichardson, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D83629
2020-07-08[UpdateTestChecks] Move more update_test_checks.py logic to common.pyAlex Richardson1-64/+19
I intend to reuse this to add UTC_ARGS support for update_llc_test_checks.py and update_cc_test_checks.py in D78478. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D78618
2020-03-24[UpdateTestChecks] Use common ir function name matcher and extend to accept ↵Simon Pilgrim1-9/+1
periods in names (PR37586) Remove the local versions of the IR_FUNCTION_RE matcher (they weren't doing anything different), and ensure all the function name matchers accept '.' and '-'. We don't need to use '\.' inside python regex sets either, or '\-' as long as thats at the end of the set.
2020-02-11[NFC] Fix spellingJohannes Doerfert1-1/+1
2020-02-11[Utils] Allow "on-the-fly" argument changes for update_test_check scriptsJohannes Doerfert1-5/+18
Update test scripts were limited because they performed a single action on the entire file and if that action was controlled by arguments, like the one introduced in D68819, there was no record of it. This patch introduces the capability of changing the arguments passed to the script "on-the-fly" while processing a test file. In addition, an "on/off" switch was added so that processing can be disabled for parts of the file where the content is simply copied. The last extension is a record of the invocation arguments in the auto generated NOTE. These arguments are also picked up in a subsequent invocation, allowing updates with special options enabled without user interaction. To change the arguments the string `UTC_ARGS:` has to be present in a line, followed by "additional command line arguments". That is everything that follows `UTC_ARGS:` will be added to a growing list of "command line arguments" which is reparsed after every update. Reviewed By: arichardson Differential Revision: https://reviews.llvm.org/D69701
2019-12-31[Utils] Allow update_test_checks to scrub attribute annotationsJohannes Doerfert1-0/+9
Attribute annotations on calls, e.g., #0, are not useful on their own. This patch adds a flag to update_test_checks.py to scrub them. Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D68851
2019-12-03[UpdateTestChecks] Change shebang from python to python3Fangrui Song1-1/+1
'python' means Python 2 on some platforms while Python 3 on others. 'python3' is Python 3 only. Python 2.7 End of Life is set to January 1, 2020. Getting rid of Python 2 support reduces maintenance burden. Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D70730
2019-12-02[UpdateTestChecks] Share the code to parse RUN: lines between all scriptsAlex Richardson1-23/+5
Summary: This commit also introduces a common.debug() function to avoid many `if args.verbose:` statements. Depends on D70428. Reviewers: xbolva00, MaskRay, jdoerfert Reviewed By: MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70432
2019-11-20[UptestTestChecks][NFC] Share some common command line options codeAlex Richardson1-5/+1
Summary: Add a function common.parse_commandline_args() that adds options common to all tools (--verbose and --update-only) and returns the parsed commandline arguments. I plan to use the shared parsing of --verbose in a follow-up commit to remove most of the `if args.verbose:` checks in the scripts. Reviewers: xbolva00, MaskRay Reviewed By: MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70428
2019-11-01[Utils] Hide the default behavior change of D68819 under a flagJohannes Doerfert1-1/+1
With D69701, the options used when running the script on a file will be recorded and reused on a rerun. This allows us to hide new features behind flags, starting with the "define" that was introduced in D68819.
2019-10-30[Utils] Allow update_test_checks to check function informationJohannes Doerfert1-1/+4
Summary: This adds a switch to the update_test_checks that triggers arguments and other function annotations, e.g., personality, to be present in the check line. If not set, the behavior should be the same as before. If arguments are recorded, their names are scrubbed from the IR to allow merging. This patch includes D68153. Reviewers: lebedev.ri, greened, spatel, xbolva00, RKSimon, mehdi_amini Subscribers: bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68819
2019-10-07Allow update_test_checks.py to not scrub names.David Greene1-1/+4
Add a --preserve-names option to tell the script not to replace IR names. Sometimes tests want those names. For example if a test is looking for a modification to an existing instruction we'll want to make the names. Differential Revision: https://reviews.llvm.org/D68081 llvm-svn: 373912
2019-09-27[UpdateTestChecks] Fix wildcard support on DOS promptsSimon Pilgrim1-3/+3
D64572 / rL365818 changed the way that the file paths were collected, which meant we lost the file pattern expansion necessary when working with DOS command prompt llvm-svn: 373062
2019-08-07[UpdateTestChecks] Update tests optionDavid Bolvansky1-9/+15
Summary: Port of new feature introduced https://reviews.llvm.org/D65610 to other update scripts. - update_*_checks.py: add an alias -u for --update-only - port --update-only to other update_*_test_checks.py scripts - update script aborts if the test file was generated by another update_*_test_checks.py utility Reviewers: lebedev.ri, RKSimon, MaskRay, reames, gbedwell Reviewed By: MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65793 llvm-svn: 368174
2019-08-06[UpdateTestChecks] Fix an incorrect %s added in r368006Fangrui Song1-1/+1
llvm-svn: 368007
2019-08-06[UpdateTestChecks] Apply some string concatenation cleanupFangrui Song1-8/+8
Some were what I suggested in D65610. llvm-svn: 368006
2019-08-05Robustify update_test_checks.py to non-autogened tests, and add a mode to ↵Philip Reames1-0/+11
skip non-autogenerated ones Intended use case is: ./utils/update_test_checks.py test/Transform/PassDir/* --update-only (i.e. rapidly be able to see changes in autogened filed, before handing non-autogened tests individually) Differential Revision: https://reviews.llvm.org/D65610 llvm-svn: 367900