From 5bf012baba4edb844664958dcd0209896ef61bb2 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Fri, 11 Nov 2016 01:25:04 +0000 Subject: [PATCH] [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 --- llvm/utils/opt-viewer/opt-viewer.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/llvm/utils/opt-viewer/opt-viewer.py b/llvm/utils/opt-viewer/opt-viewer.py index 5c23ba1..510302b 100755 --- a/llvm/utils/opt-viewer/opt-viewer.py +++ b/llvm/utils/opt-viewer/opt-viewer.py @@ -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: '''.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 = "{r.DemangledFunctionName}".format(**locals()) + print(''' {r.RelativeHotness}% {r.Pass} {r.message} +{inlining_context} '''.format(**locals()), file=self.stream) def render(self, line_remarks): @@ -174,6 +183,7 @@ class SourceFileRenderer: Hotness Optimization Source +Inline Context ''', 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): -- 2.7.4