[llvm] r321905 - Fix some opt-viewer test issues and disable on Windows.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 14:05:13 PST 2018


Author: zturner
Date: Fri Jan  5 14:05:13 2018
New Revision: 321905

URL: http://llvm.org/viewvc/llvm-project?rev=321905&view=rev
Log:
Fix some opt-viewer test issues and disable on Windows.

Differential Revision: https://reviews.llvm.org/D41784

Modified:
    llvm/trunk/test/tools/opt-viewer/lit.local.cfg
    llvm/trunk/tools/opt-viewer/opt-diff.py
    llvm/trunk/tools/opt-viewer/opt-stats.py
    llvm/trunk/tools/opt-viewer/opt-viewer.py
    llvm/trunk/tools/opt-viewer/optpmap.py

Modified: llvm/trunk/test/tools/opt-viewer/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/opt-viewer/lit.local.cfg?rev=321905&r1=321904&r2=321905&view=diff
==============================================================================
--- llvm/trunk/test/tools/opt-viewer/lit.local.cfg (original)
+++ llvm/trunk/test/tools/opt-viewer/lit.local.cfg Fri Jan  5 14:05:13 2018
@@ -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

Modified: llvm/trunk/tools/opt-viewer/opt-diff.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt-viewer/opt-diff.py?rev=321905&r1=321904&r2=321905&view=diff
==============================================================================
--- llvm/trunk/tools/opt-viewer/opt-diff.py (original)
+++ llvm/trunk/tools/opt-viewer/opt-diff.py Fri Jan  5 14:05:13 2018
@@ -19,7 +19,6 @@ except ImportError:
 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 @@ if __name__ == '__main__':
     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(

Modified: llvm/trunk/tools/opt-viewer/opt-stats.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt-viewer/opt-stats.py?rev=321905&r1=321904&r2=321905&view=diff
==============================================================================
--- llvm/trunk/tools/opt-viewer/opt-stats.py (original)
+++ llvm/trunk/tools/opt-viewer/opt-stats.py Fri Jan  5 14:05:13 2018
@@ -30,7 +30,7 @@ if __name__ == '__main__':
     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(

Modified: llvm/trunk/tools/opt-viewer/opt-viewer.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt-viewer/opt-viewer.py?rev=321905&r1=321904&r2=321905&view=diff
==============================================================================
--- llvm/trunk/tools/opt-viewer/opt-viewer.py (original)
+++ llvm/trunk/tools/opt-viewer/opt-viewer.py Fri Jan  5 14:05:13 2018
@@ -43,7 +43,7 @@ def suppress(remark):
     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 @@ class SourceFileRenderer:
             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 @@ class SourceFileRenderer:
     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 SourceFileRenderer:
 
 
 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 @@ class IndexRenderer:
 </tr>''', 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 @@ class IndexRenderer:
 </html>''', 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 @@ def generate_report(all_remarks,
                     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 @@ def generate_report(all_remarks,
         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 @@ def generate_report(all_remarks,
         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 @@ if __name__ == '__main__':
     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 @@ if __name__ == '__main__':
     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 @@ if __name__ == '__main__':
                     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()

Modified: llvm/trunk/tools/opt-viewer/optpmap.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt-viewer/optpmap.py?rev=321905&r1=321904&r2=321905&view=diff
==============================================================================
--- llvm/trunk/tools/opt-viewer/optpmap.py (original)
+++ llvm/trunk/tools/opt-viewer/optpmap.py Fri Jan  5 14:05:13 2018
@@ -41,7 +41,7 @@ def pmap(func, iterable, processes, shou
     _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,




More information about the llvm-commits mailing list