Index: llvm/test/tools/opt-viewer/lit.local.cfg =================================================================== --- llvm/test/tools/opt-viewer/lit.local.cfg +++ llvm/test/tools/opt-viewer/lit.local.cfg @@ -1,2 +1,10 @@ +import sys + if 'have_opt_viewer_modules' not in config.available_features: config.unsupported = True + +# Windows has different multiprocessing behavior than non-Windows, which causes +# all of the tests to fail presently under Windows. Disable this until those +# can be resolved. +if sys.platform == 'win32': + config.unsupported = True Index: llvm/tools/opt-viewer/opt-diff.py =================================================================== --- llvm/tools/opt-viewer/opt-diff.py +++ llvm/tools/opt-viewer/opt-diff.py @@ -19,7 +19,6 @@ import optrecord import argparse from collections import defaultdict -from multiprocessing import cpu_count, Pool if __name__ == '__main__': parser = argparse.ArgumentParser(description=desc) @@ -34,7 +33,7 @@ parser.add_argument( '--jobs', '-j', - default=cpu_count(), + default=None, type=int, help='Max job count (defaults to %(default)s, the current CPU count)') parser.add_argument( Index: llvm/tools/opt-viewer/opt-stats.py =================================================================== --- llvm/tools/opt-viewer/opt-stats.py +++ llvm/tools/opt-viewer/opt-stats.py @@ -30,7 +30,7 @@ parser.add_argument( '--jobs', '-j', - default=cpu_count(), + default=None, type=int, help='Max job count (defaults to %(default)s, the current CPU count)') parser.add_argument( Index: llvm/tools/opt-viewer/opt-viewer.py =================================================================== --- llvm/tools/opt-viewer/opt-viewer.py +++ llvm/tools/opt-viewer/opt-viewer.py @@ -43,7 +43,7 @@ return False class SourceFileRenderer: - def __init__(self, source_dir, output_dir, filename): + def __init__(self, source_dir, output_dir, filename, no_highlight): existing_filename = None if os.path.exists(filename): existing_filename = filename @@ -52,6 +52,7 @@ if os.path.exists(fn): existing_filename = fn + self.no_highlight = no_highlight self.stream = codecs.open(os.path.join(output_dir, optrecord.html_file_name(filename)), 'w', encoding='utf-8') if existing_filename: self.source_stream = open(existing_filename) @@ -69,7 +70,7 @@ def render_source_lines(self, stream, line_remarks): file_text = stream.read() - if args.no_highlight: + if self.no_highlight: html_highlighted = file_text.decode('utf-8') else: html_highlighted = highlight( @@ -157,9 +158,10 @@ class IndexRenderer: - def __init__(self, output_dir, should_display_hotness): + def __init__(self, output_dir, should_display_hotness, max_hottest_remarks_on_index): self.stream = codecs.open(os.path.join(output_dir, 'index.html'), 'w', encoding='utf-8') self.should_display_hotness = should_display_hotness + self.max_hottest_remarks_on_index = max_hottest_remarks_on_index def render_entry(self, r, odd): escaped_name = cgi.escape(r.DemangledFunctionName) @@ -189,8 +191,8 @@ ''', file=self.stream) max_entries = None - if should_display_hotness: - max_entries = args.max_hottest_remarks_on_index + if self.should_display_hotness: + max_entries = self.max_hottest_remarks_on_index for i, remark in enumerate(all_remarks[:max_entries]): if not suppress(remark): @@ -201,11 +203,11 @@ ''', file=self.stream) -def _render_file(source_dir, output_dir, ctx, entry): +def _render_file(source_dir, output_dir, ctx, no_highlight, entry): global context context = ctx filename, remarks = entry - SourceFileRenderer(source_dir, output_dir, filename).render(remarks) + SourceFileRenderer(source_dir, output_dir, filename, no_highlight).render(remarks) def map_remarks(all_remarks): @@ -227,7 +229,9 @@ file_remarks, source_dir, output_dir, + no_highlight, should_display_hotness, + max_hottest_remarks_on_index, num_jobs, should_print_progress): try: @@ -238,7 +242,7 @@ else: raise - _render_file_bound = functools.partial(_render_file, source_dir, output_dir, context) + _render_file_bound = functools.partial(_render_file, source_dir, output_dir, context, no_highlight) if should_print_progress: print('Rendering HTML files...') optpmap.pmap(_render_file_bound, @@ -250,13 +254,13 @@ sorted_remarks = sorted(optrecord.itervalues(all_remarks), key=lambda r: (r.Hotness, r.File, r.Line, r.Column, r.PassWithDiffPrefix, r.yaml_tag, r.Function), reverse=True) else: sorted_remarks = sorted(optrecord.itervalues(all_remarks), key=lambda r: (r.File, r.Line, r.Column, r.PassWithDiffPrefix, r.yaml_tag, r.Function)) - IndexRenderer(args.output_dir, should_display_hotness).render(sorted_remarks) + IndexRenderer(output_dir, should_display_hotness, max_hottest_remarks_on_index).render(sorted_remarks) shutil.copy(os.path.join(os.path.dirname(os.path.realpath(__file__)), "style.css"), output_dir) -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser(description=desc) parser.add_argument( 'yaml_dirs_or_files', @@ -273,7 +277,7 @@ parser.add_argument( '--jobs', '-j', - default=cpu_count(), + default=None, type=int, help='Max job count (defaults to %(default)s, the current CPU count)') parser.add_argument( @@ -301,6 +305,10 @@ parser.add_argument( '--demangler', help='Set the demangler to be used (defaults to %s)' % optrecord.Remark.default_demangler) + + # 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. args = parser.parse_args() print_progress = not args.no_progress_indicator @@ -321,6 +329,11 @@ file_remarks, args.source_dir, args.output_dir, + args.no_highlight, should_display_hotness, + args.max_hottest_remarks_on_index, args.jobs, print_progress) + +if __name__ == '__main__': + main() Index: llvm/tools/opt-viewer/optpmap.py =================================================================== --- llvm/tools/opt-viewer/optpmap.py +++ llvm/tools/opt-viewer/optpmap.py @@ -41,7 +41,7 @@ _total = multiprocessing.Value('i', len(iterable)) func_and_args = [(func, arg, should_print_progress,) for arg in iterable] - if processes <= 1: + if processes == 1: result = map(_wrapped_func, func_and_args, *args, **kwargs) else: pool = multiprocessing.Pool(initializer=_init,