diff --git a/llvm/utils/opt-viewer/opt-viewer.py b/llvm/utils/opt-viewer/opt-viewer.py index 7fd93600f005..d29b74f0023f 100755 --- a/llvm/utils/opt-viewer/opt-viewer.py +++ b/llvm/utils/opt-viewer/opt-viewer.py @@ -24,6 +24,8 @@ def demangle(name): return p.stdout.readline().rstrip() class Remark(yaml.YAMLObject): + max_hotness = 0 + @property def File(self): return self.DebugLoc['File'] @@ -60,6 +62,10 @@ class Remark(yaml.YAMLObject): values = [self.getArgString(mapping.items()[0]) for mapping in self.Args] return demangle("".join(values)) + @property + def RelativeHotness(self): + return int(round(self.Hotness * 100 / Remark.max_hotness)) + class Analysis(Remark): yaml_tag = '!Analysis' @@ -102,7 +108,7 @@ class SourceFileRenderer: print(''' -{r.Hotness} +{r.RelativeHotness}% {r.Pass} {r.message} '''.format(**locals()), file=self.stream) @@ -143,7 +149,7 @@ class IndexRenderer: print(''' {r.DebugLocString} -{r.Hotness}% +{r.RelativeHotness}% {r.DemangledFunctionName} {r.Pass} '''.format(**locals()), file=self.stream) @@ -181,6 +187,7 @@ for input_file in args.yaml_files: if hasattr(remark, 'Hotness'): 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)