Skip to content

Commit

Permalink
Fix some opt-viewer test issues and disable on Windows.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D41784

llvm-svn: 321905
  • Loading branch information
Zachary Turner committed Jan 5, 2018
1 parent 4ed8ef6 commit 7f5fb67
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
8 changes: 8 additions & 0 deletions 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
3 changes: 1 addition & 2 deletions llvm/tools/opt-viewer/opt-diff.py
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/opt-viewer/opt-stats.py
Expand Up @@ -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(
Expand Down
35 changes: 24 additions & 11 deletions llvm/tools/opt-viewer/opt-viewer.py
Expand Up @@ -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
Expand All @@ -52,6 +52,7 @@ def __init__(self, source_dir, output_dir, filename):
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)
Expand All @@ -69,7 +70,7 @@ def __init__(self, source_dir, output_dir, filename):
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(
Expand Down Expand Up @@ -157,9 +158,10 @@ def render(self, line_remarks):


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)
Expand Down Expand Up @@ -189,8 +191,8 @@ def render(self, all_remarks):
</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):
Expand All @@ -201,11 +203,11 @@ def render(self, all_remarks):
</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):
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -273,7 +277,7 @@ def generate_report(all_remarks,
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(
Expand Down Expand Up @@ -301,6 +305,10 @@ def generate_report(all_remarks,
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
Expand All @@ -321,6 +329,11 @@ def generate_report(all_remarks,
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()
2 changes: 1 addition & 1 deletion llvm/tools/opt-viewer/optpmap.py
Expand Up @@ -41,7 +41,7 @@ def pmap(func, iterable, processes, should_print_progress, *args, **kwargs):
_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,
Expand Down

0 comments on commit 7f5fb67

Please sign in to comment.