aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/UpdateTestChecks/common.py
AgeCommit message (Collapse)AuthorFilesLines
2023-07-05[UTC] Adapt version matcher to glob CLANG_VENDORHenrik G. Olsson1-6/+5
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[UTC] Generalize version regexNikita Popov1-1/+1
The suffix for the git revision may not be present (or may not be a git revision).
2023-07-05[UTC] Fix git URL regexHenrik G. Olsson1-1/+1
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[UTC] Add fallback support for specific metadata, and check their defsHenrik G. Olsson1-15/+151
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-1138/+1551
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-07[UTC] Enable --function-signature by defaultNikita Popov1-4/+12
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-02[UTC] Include return type/attributes under --version 2Nikita Popov1-14/+32
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-0/+6
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D143307
2023-01-30[UTC] Add --version argumentNikita Popov1-4/+21
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-25UpdateTestChecks: cleanup NamelessValues constructorNicolai Hähnle1-46/+33
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-19[SROA] Check TBAA metadata in tests (NFC)Nikita Popov1-0/+1
By switching to --check-globals. Also make sure that the !tbaa.struct metadata mapping is preserved.
2023-01-06[UpdateTestChecks] Do not add --force-update to UTC_ARGSAlex Richardson1-1/+2
Persisting this flag only introduces test churn. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D141124
2022-12-15[UpdateTestChecks] Handle !DIAssignID metadataRoman Lebedev1-13/+14
2022-12-13Revert "[UpdateTestChecks] Match define for labels"Nikita Popov1-1/+1
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-12[UpdateTestChecks] Match define for labelsSebastian Neubauer1-1/+1
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-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-7/+10
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-04[IR] Switch everything to use memory attributeNikita Popov1-1/+1
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-10-27update_test_checks.py: allow use with custom toolsNicolai Hähnle1-2/+2
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-13/+27
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-11[OMPIRBuilder] Add support for simdlen clausePrabhdeep Singh Soni1-12/+13
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-06-28[UpdateTestChecks] Handle prefix reuse for appended check linesJohannes Doerfert1-5/+9
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-05-26Fix break introduced by D124306Mircea Trofin1-2/+4
argparse.BooleanOptionalAction is not supported until python 3.9.
2022-05-26[UpdateTestChecks] Auto-generate stub bodies for unused prefixesMircea Trofin1-13/+45
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-14[UpdateTestChecks] Use a counter for unpredictable FileCheck variablesAlex Richardson1-21/+36
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[update_llc_test_checks] Use FileCheck captures for MCInst/MCReg outputAlex Richardson1-27/+70
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[UpdateTestChecks] Change global functions to NamelessValue members. NFCIAlex Richardson1-63/+57
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-10Revert "[utils] Avoid hardcoding metadata ids in update_cc_test_checks"Jan Korous1-5/+1
This reverts commit ce583b14b2ec37b1c168bb92020680cb452502b3.
2022-05-10[utils] Avoid hardcoding metadata ids in update_cc_test_checksJan Korous1-1/+5
Specifically for: !tbaa, !tbaa.struct, !annotation, !srcloc, !nosanitize. The goal is to avoid test brittleness caused by hardcoded values. Differential Revision: https://reviews.llvm.org/D123273
2022-04-15[NFC][UpdateTestChecks] Fix whitespace in common.py and asm.pyDaniil Kovalev1-99/+99
While working on D122986, noticed that indentation size varies even within one file. Fixed that - now indentation is 2 spaces everywhere. This indentation Differential Revision: https://reviews.llvm.org/D123859
2022-04-15[UpdateTestChecks] Prevent rapid onset insanity when forced to write ↵Roman Lebedev1-0/+5
LoopVectorize-driven costmodel tests Subj, or on other words, we have a lot of tests that are driven by the LoopVectorizer's debug output, but we don't have any meaningful way to autogenerate checklines in them, which means that an insurmountable amount of manual work is required when modifying the appropriate cost models. That is not sustainable, so this presents a solution. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D121133
2022-04-15[UpdateTestChecks] Add NVPTX support in update_llc_test_checks.pyDaniil Kovalev1-6/+17
This patch makes possible generating NVPTX assembly check lines with update_llc_test_checks.py utility. Differential Revision: https://reviews.llvm.org/D122986
2022-03-07UpdateTestChecks: fix handling of UTC with spacesRoman Lebedev1-1/+2
We can't just split by space, that's not going to give us the same argv we'd have gotten from the shell, it could be in a string, we must actually parse that as argv.
2022-03-07update_analyze_test_checks.py: fix --filter handlingRoman Lebedev1-2/+2
In particular, after filtering the check lines can't necessarily use `-NEXT`, they may not be one directly after another.
2022-03-03[UpdateTestChecks] Don't skip first line with --filterSebastian Neubauer1-1/+1
body_start was never used, resulting in the first filtered line to be skipped. Fixes the --filter option introduced in D117694. Differential Revision: https://reviews.llvm.org/D119704
2022-03-01[UpdateLLCTestChecks] Add support for isel debug output in ↵Yatao Wang1-8/+24
update_llc_test_checks.py Add a check on run lines to pick up isel options in llc commands and allow generating check lines of isel final output other than assembly. If llc command line contains -debug-only=isel, update_llc_test_checks.py will try to scrub isel output, otherwise, the script will fall back on default behaviour, which is try to scrub assembly output instead. The motivation of this change is to allow usage of update_llc_test_checks.py to autogenerate checks of instruction selection results. In this way, we can detect errors at an earlier stage before the compilation goes all the way to assembly. It is an example of having some transparency for the stages between IR and assembly. These generated tests are almost like "unit tests" of isel stage. This patch only implements the initial change to differentiate isel output from assembly output for Lanai. Other targets will not be supported for isel check generation at the moment. Although adding support for it will only require implementing the function regex and scrubber for corresponding targets. The Lanai implementation was chosen mainly for the simplicity of demonstrating the difference between isel checks and asm checks. This patch also do not include the implementation of function prefix, which is required for the generated isel checks to pass. I will put up a follow up revision for the function prefix change to complete isel support. Reviewed By: Flakebi Differential Revision: https://reviews.llvm.org/D119368
2022-01-31[UpdateTestChecks] Re-add --filter and --filter-out optionsDavid Greene1-15/+157
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-157/+15
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-15/+157
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-28[update_test_checks] Fix option name in warning messageJay Foad1-1/+1
2021-11-18Add a breadcrumb comment to make debugging a user error when using ↵Philip Reames1-0/+3
./utils/update_analyze_test_checks.py easier. We won't talk about how long it took me to figure this out. The difference in batch vs interactive on the "did you mean to print bitcode" message made this confusing.
2021-09-28[UpdateTestChecks][NFC] Drop a python2 workaroundAlex Richardson1-7/+1
2021-09-22[Utils] Replace llc with cat for testsSebastian Neubauer1-3/+20
Make the update_llc_test_checks script test independant of llc behavior by using cat with static files to simulate llc output. This allows changing llc without breaking the script test case. The update script is executed in a temporary directory, so the llc-generated assembly files are copied there. %T is deprecated, but it allows copying a file with a predictable filename. Differential Revision: https://reviews.llvm.org/D110143
2021-07-29[Utils] Do not remove comments in llc test scriptSebastian Neubauer1-3/+9
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-07-20[UpdateCCTestChecks] Implement --global-hex-value-regexJoel E. Denny1-1/+10
For example, in OpenMP offload codegen tests, global variables like `.offload_maptypes*` are much easier to read in hex. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D104743
2021-07-20[UpdateCCTestChecks] Implement --global-value-regexJoel E. Denny1-3/+20
`--check-globals` activates checks for all global values, and `--global-value-regex` filters them. For example, I'd like to use it in OpenMP offload codegen tests to check only global variables like `.offload_maptypes*`. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D104742
2021-06-25[UpdateCCTestChecks] Support --check-globalsJoel E. Denny1-0/+2
This option is already supported by update_test_checks.py, but it can also be useful in update_cc_test_checks.py. For example, I'd like to use it in OpenMP offload codegen tests to check global variables like `.offload_maptypes*`. Reviewed By: jdoerfert, arichardson, ggeorgakoudis Differential Revision: https://reviews.llvm.org/D104714
2021-06-23[UpdateCCTestChecks][NFC] Permit other comments in common.pyJoel E. Denny1-7/+7
Some parts of common.py already permit comment styles besides `;`. Handle the remaining cases. Specifically, a future patch will extend update_cc_test_checks.py to call add_global_checks. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D104713
2021-06-21[UpdateCCTestChecks] Fix --replace-value-regex across RUN linesJoel E. Denny1-22/+23
Without this patch, llvm/utils/update_cc_test_checks.py fails to perform `--replace-value-regex` replacements when two RUN lines produce the same output and use the same single FileCheck prefix. The problem is that replacements in a RUN line's output are not performed until after comparing against previous RUN lines' output, where replacements have already been performed. This patch fixes that. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D104566
2021-06-20[UpdateTestUtils] Print test filename when complaining about conflicting prefixRoman Lebedev1-2/+3
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.