[llvm] r286537 - [opt-viewer] Display inlining context

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 17:25:05 PST 2016


Author: anemet
Date: Thu Nov 10 19:25:04 2016
New Revision: 286537

URL: http://llvm.org/viewvc/llvm-project?rev=286537&view=rev
Log:
[opt-viewer] Display inlining context

When a function is inlined, each instance is optimized in their own
inlining context.  This can produce different remarks all pointing to
the same source line.

This adds a new column on the source view to display the inlining
context.

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=286537&r1=286536&r2=286537&view=diff
==============================================================================
--- llvm/trunk/utils/opt-viewer/opt-viewer.py (original)
+++ llvm/trunk/utils/opt-viewer/opt-viewer.py Thu Nov 10 19:25:04 2016
@@ -29,6 +29,8 @@ def demangle(name):
 
 class Remark(yaml.YAMLObject):
     max_hotness = 1
+    # Map function names to their source location for function where inlining happened
+    caller_loc = dict()
 
     @property
     def File(self):
@@ -149,12 +151,19 @@ class SourceFileRenderer:
 </tr>'''.format(**locals()), file=self.stream)
 
     def render_inline_remarks(self, r):
+        inlining_context = r.DemangledFunctionName
+        dl = Remark.caller_loc.get(r.Function)
+        if dl:
+            link = Remark.make_link(dl['File'], dl['Line'] - 2)
+            inlining_context = "<a href={link}>{r.DemangledFunctionName}</a>".format(**locals())
+
         print('''
 <tr>
 <td></td>
 <td>{r.RelativeHotness}%</td>
 <td class=\"column-entry-{r.color}\">{r.Pass}</td>
 <td class=\"column-entry-yellow\">{r.message}</td>
+<td class=\"column-entry-yellow\">{inlining_context}</td>
 </tr>'''.format(**locals()), file=self.stream)
 
     def render(self, line_remarks):
@@ -174,6 +183,7 @@ class SourceFileRenderer:
 <td>Hotness</td>
 <td>Optimization</td>
 <td>Source</td>
+<td>Inline Context</td>
 </tr>''', file=self.stream)
         for (linenum, line) in enumerate(self.source_stream.readlines(), start=1):
             self.render_source_line(linenum, line)
@@ -241,6 +251,14 @@ for input_file in args.yaml_files:
 
             Remark.max_hotness = max(Remark.max_hotness, remark.Hotness)
 
+# Set up a map between function names and their source location for function where inlining happened
+for remark in all_remarks.itervalues():
+    if type(remark) == Passed and remark.Pass == "inline" and remark.Name == "Inlined":
+        for arg in remark.Args:
+            caller = arg.get('Caller')
+            if caller:
+                    Remark.caller_loc[caller] = arg['DebugLoc']
+
 sorted_remarks = sorted(all_remarks.itervalues(), key=lambda r: r.Hotness, reverse=True)
 
 if not os.path.exists(args.output_dir):




More information about the llvm-commits mailing list