Skip to content

Commit 5bf012b

Browse files
committed
[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. llvm-svn: 286537
1 parent 01823ea commit 5bf012b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llvm/utils/opt-viewer/opt-viewer.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def demangle(name):
2929

3030
class Remark(yaml.YAMLObject):
3131
max_hotness = 1
32+
# Map function names to their source location for function where inlining happened
33+
caller_loc = dict()
3234

3335
@property
3436
def File(self):
@@ -149,12 +151,19 @@ def render_source_line(self, linenum, line):
149151
</tr>'''.format(**locals()), file=self.stream)
150152

151153
def render_inline_remarks(self, r):
154+
inlining_context = r.DemangledFunctionName
155+
dl = Remark.caller_loc.get(r.Function)
156+
if dl:
157+
link = Remark.make_link(dl['File'], dl['Line'] - 2)
158+
inlining_context = "<a href={link}>{r.DemangledFunctionName}</a>".format(**locals())
159+
152160
print('''
153161
<tr>
154162
<td></td>
155163
<td>{r.RelativeHotness}%</td>
156164
<td class=\"column-entry-{r.color}\">{r.Pass}</td>
157165
<td class=\"column-entry-yellow\">{r.message}</td>
166+
<td class=\"column-entry-yellow\">{inlining_context}</td>
158167
</tr>'''.format(**locals()), file=self.stream)
159168

160169
def render(self, line_remarks):
@@ -174,6 +183,7 @@ def render(self, line_remarks):
174183
<td>Hotness</td>
175184
<td>Optimization</td>
176185
<td>Source</td>
186+
<td>Inline Context</td>
177187
</tr>''', file=self.stream)
178188
for (linenum, line) in enumerate(self.source_stream.readlines(), start=1):
179189
self.render_source_line(linenum, line)
@@ -241,6 +251,14 @@ def render(self, all_remarks):
241251

242252
Remark.max_hotness = max(Remark.max_hotness, remark.Hotness)
243253

254+
# Set up a map between function names and their source location for function where inlining happened
255+
for remark in all_remarks.itervalues():
256+
if type(remark) == Passed and remark.Pass == "inline" and remark.Name == "Inlined":
257+
for arg in remark.Args:
258+
caller = arg.get('Caller')
259+
if caller:
260+
Remark.caller_loc[caller] = arg['DebugLoc']
261+
244262
sorted_remarks = sorted(all_remarks.itervalues(), key=lambda r: r.Hotness, reverse=True)
245263

246264
if not os.path.exists(args.output_dir):

0 commit comments

Comments
 (0)