[llvm] r286489 - [opt-viewer] Avoid duplicated remarks

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 10:42:57 PST 2016


Author: anemet
Date: Thu Nov 10 12:42:56 2016
New Revision: 286489

URL: http://llvm.org/viewvc/llvm-project?rev=286489&view=rev
Log:
[opt-viewer] Avoid duplicated remarks

This can happen if a pass is run multiple times or if the code is in a
header file which is included multiple times.

Modified:
    llvm/trunk/utils/opt-viewer/opt-viewer.py

Modified: llvm/trunk/utils/opt-viewer/opt-viewer.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/opt-viewer/opt-viewer.py?rev=286489&r1=286488&r2=286489&view=diff
==============================================================================
--- llvm/trunk/utils/opt-viewer/opt-viewer.py (original)
+++ llvm/trunk/utils/opt-viewer/opt-viewer.py Thu Nov 10 12:42:56 2016
@@ -82,6 +82,10 @@ class Remark(yaml.YAMLObject):
     def RelativeHotness(self):
         return int(round(self.Hotness * 100 / Remark.max_hotness))
 
+    @property
+    def key(self):
+        return (self.__class__, self.Pass, self.Name, self.File, self.Line, self.Column, self.message)
+
 class Analysis(Remark):
     yaml_tag = '!Analysis'
 
@@ -193,7 +197,7 @@ class IndexRenderer:
 </html>''', file=self.stream)
 
 
-all_remarks = []
+all_remarks = dict()
 file_remarks  = dict()
 
 for input_file in args.yaml_files:
@@ -201,11 +205,16 @@ for input_file in args.yaml_files:
     docs = yaml.load_all(f)
     for remark in docs:
         if hasattr(remark, 'Hotness'):
+            # Avoid duplicated remarks
+            if remark.key in all_remarks:
+                continue
+            all_remarks[remark.key] = remark
+
             file_remarks.setdefault(remark.File, dict()).setdefault(remark.Line, []).append(remark);
-            all_remarks.append(remark)
+
             Remark.max_hotness = max(Remark.max_hotness, remark.Hotness)
 
-all_remarks = sorted(all_remarks, key=lambda r: r.Hotness, reverse=True)
+sorted_remarks = sorted(all_remarks.itervalues(), key=lambda r: r.Hotness, reverse=True)
 
 if not os.path.exists(args.output_dir):
     os.mkdir(args.output_dir)
@@ -213,6 +222,6 @@ if not os.path.exists(args.output_dir):
 for (filename, remarks) in file_remarks.iteritems():
     SourceFileRenderer(filename).render(remarks)
 
-IndexRenderer().render(all_remarks)
+IndexRenderer().render(sorted_remarks)
 
 shutil.copy(os.path.join(os.path.dirname(os.path.realpath(__file__)), "style.css"), args.output_dir)




More information about the llvm-commits mailing list