[llvm] [utils][filecheck-lint]: speedup filecheck_lint by caching edit distance (PR #94191)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 01:18:54 PDT 2024
https://github.com/klensy created https://github.com/llvm/llvm-project/pull/94191
For example:
clang\test\OpenMP\task_codegen.cpp: 0m29.570s -> 0m2.698s
clang\test\Driver: 4m55.917s -> 1m53.789s
Most win from big files.
>From faeba1e67bfb7822fd30f0cab6e129d28c985485 Mon Sep 17 00:00:00 2001
From: klensy <nightouser at gmail.com>
Date: Mon, 3 Jun 2024 11:08:52 +0300
Subject: [PATCH] [utils][filecheck-lint]: speedup filecheck_lint by caching
edit_distance calculations
---
llvm/utils/filecheck_lint/filecheck_lint.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/filecheck_lint/filecheck_lint.py b/llvm/utils/filecheck_lint/filecheck_lint.py
index 837846db83321..d238277c9e01b 100755
--- a/llvm/utils/filecheck_lint/filecheck_lint.py
+++ b/llvm/utils/filecheck_lint/filecheck_lint.py
@@ -228,7 +228,8 @@ def find_best_match(typo):
)
potential_directives = find_potential_directives(content)
-
+ # cache score and best_match to skip recalculating
+ checked_potential_directives = dict()
for filerange, potential_directive in potential_directives:
# TODO(bchetioui): match count directives more finely. We skip directives
# starting with 'CHECK-COUNT-' for the moment as they require more complex
@@ -244,7 +245,11 @@ def find_best_match(typo):
if len(potential_directive) > max(map(len, all_directives)) + threshold:
continue
- score, best_match = find_best_match(potential_directive)
+ if potential_directive not in checked_potential_directives:
+ score, best_match = find_best_match(potential_directive)
+ checked_potential_directives[potential_directive] = (score, best_match)
+ else:
+ score, best_match = checked_potential_directives[potential_directive]
if score == 0: # This is an actual directive, ignore.
continue
elif score <= threshold and best_match not in _ignore:
More information about the llvm-commits
mailing list