aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-11-14 09:03:54 +0100
committerGitHub <noreply@github.com>2023-11-14 09:03:54 +0100
commita3eeef82da8be7f2cfa6dc7bed0fe4c11d585180 (patch)
treecd2a9a756cdf6ea65245ee28b1588fc0a227b8e3 /llvm/lib/FileCheck/FileCheck.cpp
parentc9832da35092e8733d505a4856f2b3dca5bd05b1 (diff)
downloadllvm-a3eeef82da8be7f2cfa6dc7bed0fe4c11d585180.zip
llvm-a3eeef82da8be7f2cfa6dc7bed0fe4c11d585180.tar.gz
llvm-a3eeef82da8be7f2cfa6dc7bed0fe4c11d585180.tar.bz2
[FileCheck] Avoid capturing group for {{regex}} (#72136)
For `{{regex}}` we don't really need a capturing group, and only add it to properly handle cases like `{{foo|bar}}`. This is problematic, because the use of capturing groups makes our regex implementation slower (we have to go through the "dissect" stage, which can have quadratic complexity). Unfortunately, our regex implementation does not support non-capturing groups like `(?:regex)`. So instead, avoid adding the group entirely if the regex doesn't contain any alternations. This causes a slight difference in escaping behavior, where previously it was possible to write `{{{{}}` and get the same behavior as `{{\{\{}}`. This will no longer work. I don't think this is a problem, especially as we recently taught update_analyze_test_checks.py to emit `{{\{\{}}`, so this shouldn't get introduced in any new tests. For CodeGen/X86/vector-interleaved-store-i16-stride-7.ll (our slowest X86 test) this drops FileCheck time from 6s to 5s (the remainder is spent in a different regex issue). I expect similar speedups in other tests using a lot of `{{}}`.
Diffstat (limited to 'llvm/lib/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/lib/FileCheck/FileCheck.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 49fda8f..bef6dd6 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -832,12 +832,16 @@ bool Pattern::parsePattern(StringRef PatternStr, StringRef Prefix,
// capturing the result for any purpose. This is required in case the
// expression contains an alternation like: CHECK: abc{{x|z}}def. We
// want this to turn into: "abc(x|z)def" not "abcx|zdef".
- RegExStr += '(';
- ++CurParen;
+ bool HasAlternation = PatternStr.contains('|');
+ if (HasAlternation) {
+ RegExStr += '(';
+ ++CurParen;
+ }
if (AddRegExToRegEx(PatternStr.substr(2, End - 2), CurParen, SM))
return true;
- RegExStr += ')';
+ if (HasAlternation)
+ RegExStr += ')';
PatternStr = PatternStr.substr(End + 2);
continue;