[llvm] r306306 - [opt-viewer] Python 3 support in opt-stats.py
Brian Gesiak via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 26 09:51:24 PDT 2017
Author: modocache
Date: Mon Jun 26 09:51:24 2017
New Revision: 306306
URL: http://llvm.org/viewvc/llvm-project?rev=306306&view=rev
Log:
[opt-viewer] Python 3 support in opt-stats.py
Summary: Minor changes that allow opt-stats.py to support both Python 2 and 3.
Reviewers: anemet, davidxl
Reviewed By: anemet
Subscribers: llvm-commits, fhahn
Differential Revision: https://reviews.llvm.org/D34564
Modified:
llvm/trunk/utils/opt-viewer/opt-stats.py
llvm/trunk/utils/opt-viewer/optrecord.py
Modified: llvm/trunk/utils/opt-viewer/opt-stats.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/opt-viewer/opt-stats.py?rev=306306&r1=306305&r2=306306&view=diff
==============================================================================
--- llvm/trunk/utils/opt-viewer/opt-stats.py (original)
+++ llvm/trunk/utils/opt-viewer/opt-stats.py Mon Jun 26 09:51:24 2017
@@ -34,7 +34,7 @@ if __name__ == '__main__':
bypass = defaultdict(int)
byname = defaultdict(int)
- for r in all_remarks.itervalues():
+ for r in optrecord.itervalues(all_remarks):
bypass[r.Pass] += 1
byname[r.Pass + "/" + r.Name] += 1
Modified: llvm/trunk/utils/opt-viewer/optrecord.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/opt-viewer/optrecord.py?rev=306306&r1=306305&r2=306306&view=diff
==============================================================================
--- llvm/trunk/utils/opt-viewer/optrecord.py (original)
+++ llvm/trunk/utils/opt-viewer/optrecord.py Mon Jun 26 09:51:24 2017
@@ -24,14 +24,32 @@ p = subprocess.Popen(['c++filt', '-n'],
p_lock = Lock()
+try:
+ dict.iteritems
+except AttributeError:
+ # Python 3
+ def itervalues(d):
+ return iter(d.values())
+ def iteritems(d):
+ return iter(d.items())
+else:
+ # Python 2
+ def itervalues(d):
+ return d.itervalues()
+ def iteritems(d):
+ return d.iteritems()
+
+
def demangle(name):
with p_lock:
p.stdin.write(name + '\n')
return p.stdout.readline().rstrip()
+
def html_file_name(filename):
return filename.replace('/', '_') + ".html"
+
def make_link(File, Line):
return "\"{}#L{}\"".format(html_file_name(File), Line)
@@ -117,7 +135,7 @@ class Remark(yaml.YAMLObject):
def key(self):
k = (self.__class__, self.PassWithDiffPrefix, self.Name, self.File, self.Line, self.Column, self.Function)
for arg in self.Args:
- for (key, value) in arg.iteritems():
+ for (key, value) in iteritems(arg):
if type(value) is dict:
value = tuple(value.items())
k += (key, value)
@@ -196,8 +214,8 @@ def gather_results(pmap, filenames):
max_hotness = max(entry[0] for entry in remarks)
def merge_file_remarks(file_remarks_job, all_remarks, merged):
- for filename, d in file_remarks_job.iteritems():
- for line, remarks in d.iteritems():
+ for filename, d in iteritems(file_remarks_job):
+ for line, remarks in iteritems(d):
for remark in remarks:
# Bring max_hotness into the remarks so that
# RelativeHotness does not depend on an external global.
More information about the llvm-commits
mailing list