From: Adam Nemet Date: Fri, 11 Nov 2016 01:25:04 +0000 (+0000) Subject: [opt-viewer] Display inlining context X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9295796ca7c069748263f35655c40c1decade2ed;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286537 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/opt-viewer/opt-viewer.py b/utils/opt-viewer/opt-viewer.py index 5c23ba1d265..510302b0c22 100755 --- a/utils/opt-viewer/opt-viewer.py +++ b/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):