diff options
Diffstat (limited to 'llvm/tools/opt-viewer')
| -rwxr-xr-x | llvm/tools/opt-viewer/opt-viewer.py | 9 | ||||
| -rw-r--r-- | llvm/tools/opt-viewer/optpmap.py | 8 | ||||
| -rw-r--r-- | llvm/tools/opt-viewer/optrecord.py | 14 |
3 files changed, 22 insertions, 9 deletions
diff --git a/llvm/tools/opt-viewer/opt-viewer.py b/llvm/tools/opt-viewer/opt-viewer.py index 8aec321b959..4c105886cfd 100755 --- a/llvm/tools/opt-viewer/opt-viewer.py +++ b/llvm/tools/opt-viewer/opt-viewer.py @@ -239,7 +239,7 @@ class IndexRenderer: </html>''', file=self.stream) -def _render_file(source_dir, output_dir, ctx, no_highlight, entry): +def _render_file(source_dir, output_dir, ctx, no_highlight, entry, filter_): global context context = ctx filename, remarks = entry @@ -344,6 +344,11 @@ def main(): '--demangler', help='Set the demangler to be used (defaults to %s)' % optrecord.Remark.default_demangler) + parser.add_argument( + '--filter', + default='', + help='Only display remarks from passes matching filter expression') + # Do not make this a global variable. Values needed to be propagated through # to individual classes and functions to be portable with multiprocessing across # Windows and non-Windows. @@ -359,7 +364,7 @@ def main(): sys.exit(1) all_remarks, file_remarks, should_display_hotness = \ - optrecord.gather_results(files, args.jobs, print_progress) + optrecord.gather_results(files, args.jobs, print_progress, args.filter) map_remarks(all_remarks) diff --git a/llvm/tools/opt-viewer/optpmap.py b/llvm/tools/opt-viewer/optpmap.py index ff3e683f3d0..8124c8c9036 100644 --- a/llvm/tools/opt-viewer/optpmap.py +++ b/llvm/tools/opt-viewer/optpmap.py @@ -14,7 +14,7 @@ def _init(current, total): def _wrapped_func(func_and_args): - func, argument, should_print_progress = func_and_args + func, argument, should_print_progress, filter_ = func_and_args if should_print_progress: with _current.get_lock(): @@ -22,10 +22,10 @@ def _wrapped_func(func_and_args): sys.stdout.write('\r\t{} of {}'.format(_current.value, _total.value)) sys.stdout.flush() - return func(argument) + return func(argument, filter_) -def pmap(func, iterable, processes, should_print_progress, *args, **kwargs): +def pmap(func, iterable, processes, should_print_progress, filter_=None, *args, **kwargs): """ A parallel map function that reports on its progress. @@ -40,7 +40,7 @@ def pmap(func, iterable, processes, should_print_progress, *args, **kwargs): _current = multiprocessing.Value('i', 0) _total = multiprocessing.Value('i', len(iterable)) - func_and_args = [(func, arg, should_print_progress,) for arg in iterable] + func_and_args = [(func, arg, should_print_progress, filter_) for arg in iterable] if processes == 1: result = list(map(_wrapped_func, func_and_args, *args, **kwargs)) else: diff --git a/llvm/tools/opt-viewer/optrecord.py b/llvm/tools/opt-viewer/optrecord.py index 0193d25704c..e952d1befd6 100644 --- a/llvm/tools/opt-viewer/optrecord.py +++ b/llvm/tools/opt-viewer/optrecord.py @@ -24,6 +24,8 @@ try: except: pass +import re + import optpmap try: @@ -263,18 +265,24 @@ class Missed(Remark): return "red" -def get_remarks(input_file): +def get_remarks(input_file, filter_): max_hotness = 0 all_remarks = dict() file_remarks = defaultdict(functools.partial(defaultdict, list)) with open(input_file) as f: docs = yaml.load_all(f, Loader=Loader) + + filter_e = re.compile(filter_) for remark in docs: remark.canonicalize() # Avoid remarks withoug debug location or if they are duplicated if not hasattr(remark, 'DebugLoc') or remark.key in all_remarks: continue + + if filter_ and not filter_e.search(remark.Pass): + continue + all_remarks[remark.key] = remark file_remarks[remark.File][remark.Line].append(remark) @@ -289,13 +297,13 @@ def get_remarks(input_file): return max_hotness, all_remarks, file_remarks -def gather_results(filenames, num_jobs, should_print_progress): +def gather_results(filenames, num_jobs, should_print_progress, filter_): if should_print_progress: print('Reading YAML files...') if not Remark.demangler_proc: Remark.set_demangler(Remark.default_demangler) remarks = optpmap.pmap( - get_remarks, filenames, num_jobs, should_print_progress) + get_remarks, filenames, num_jobs, should_print_progress, filter_) max_hotness = max(entry[0] for entry in remarks) def merge_file_remarks(file_remarks_job, all_remarks, merged): |

