[llvm] r319902 - [opt-viewer] Suppress noisy Swift remarks

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 08:50:51 PST 2017


Author: anemet
Date: Wed Dec  6 08:50:50 2017
New Revision: 319902

URL: http://llvm.org/viewvc/llvm-project?rev=319902&view=rev
Log:
[opt-viewer] Suppress noisy Swift remarks

Most likely, this is not how we want to handle this in the long term.  This
code should probably be in the Swift repo and somehow plugged into the
opt-viewer.  This is still however very experimental at this point so I don't
want to over-engineer it at this point.

Added:
    llvm/trunk/test/tools/opt-viewer/Inputs/suppress/
    llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.opt.yaml
    llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.swift
    llvm/trunk/test/tools/opt-viewer/Outputs/suppress/
    llvm/trunk/test/tools/opt-viewer/Outputs/suppress/index.html
    llvm/trunk/test/tools/opt-viewer/Outputs/suppress/s.swift.html
    llvm/trunk/test/tools/opt-viewer/suppress.test
Modified:
    llvm/trunk/tools/opt-viewer/opt-viewer.py
    llvm/trunk/tools/opt-viewer/optrecord.py

Added: llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.opt.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.opt.yaml?rev=319902&view=auto
==============================================================================
--- llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.opt.yaml (added)
+++ llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.opt.yaml Wed Dec  6 08:50:50 2017
@@ -0,0 +1,186 @@
+--- !Passed
+Pass:            sil-generic-specializer
+Name:            sil.Specialized
+DebugLoc:
+  File:            s.swift
+  Line:            7
+  Column:          13
+Function:        'f()'
+Args:
+  - String:          'Specialized function '
+  - Function:        '"Swift.CountableRange.init(uncheckedBounds:)"'
+  - String:          ' with type '
+  - FuncType:        '(Int, Int, @thin CountableRange<Int>.Type) -> CountableRange<Int>'
+...
+--- !Passed
+Pass:            sil-generic-specializer
+Name:            sil.Specialized
+DebugLoc:
+  File:            s.swift
+  Line:            7
+  Column:          12
+Function:        'f()'
+Args:
+  - String:          'Specialized function '
+  - Function:        '"Swift.Collection<>.makeIterator()"'
+  - String:          ' with type '
+  - FuncType:        '(@in_guaranteed CountableRange<Int>) -> IndexingIterator<CountableRange<Int>>'
+...
+--- !Passed
+Pass:            sil-generic-specializer
+Name:            sil.Specialized
+DebugLoc:
+  File:            s.swift
+  Line:            7
+  Column:          9
+Function:        'f()'
+Args:
+  - String:          'Specialized function '
+  - Function:        '"Swift.IndexingIterator.next()"'
+  - String:          ' with type '
+  - FuncType:        '(@inout IndexingIterator<CountableRange<Int>>) -> Optional<Int>'
+...
+--- !Passed
+Pass:            sil-generic-specializer
+Name:            sil.Specialized
+DebugLoc:
+  File:            s.swift
+  Line:            8
+  Column:          12
+Function:        'f()'
+Args:
+  - String:          'Specialized function '
+  - Function:        '"Swift._allocateUninitializedArray<A>(_:)"'
+  - String:          ' with type '
+  - FuncType:        '(Builtin.Word) -> (@owned Array<Any>, Builtin.RawPointer)'
+...
+--- !Passed
+Pass:            sil-generic-specializer
+Name:            sil.Specialized
+DebugLoc:
+  File:            s.swift
+  Line:            8
+  Column:          12
+Function:        'f()'
+Args:
+  - String:          'Specialized function '
+  - Function:        '"Swift.Array.subscript.getter"'
+  - String:          ' with type '
+  - FuncType:        '(Int, @guaranteed Array<Int>) -> Int'
+...
+--- !Passed
+Pass:            sil-inliner
+Name:            sil.Inlined
+DebugLoc:
+  File:            s.swift
+  Line:            7
+  Column:          13
+Function:        'f()'
+Args:
+  - Callee:          '"specialized Swift.CountableRange.init(uncheckedBounds:)"'
+    DebugLoc:
+      File:            blah.swift
+      Line:            6
+      Column:          6
+  - String:          ' inlined into '
+  - Caller:          '"s.f()"'
+    DebugLoc:
+      File:            s.swift
+      Line:            6
+      Column:          6
+  - String:          ' (cost = '
+  - Cost:            '0'
+  - String:          ', benefit = '
+  - Benefit:         '20'
+  - String:          ')'
+...
+--- !Passed
+Pass:            sil-inliner
+Name:            sil.Inlined
+DebugLoc:
+  File:            s.swift
+  Line:            8
+  Column:          12
+Function:        'f()'
+Args:
+  - Callee:          '"specialized Swift.Array.subscript.getter"'
+  - String:          ' inlined into '
+  - Caller:          '"s.f()"'
+    DebugLoc:
+      File:            s.swift
+      Line:            6
+      Column:          6
+  - String:          ' (cost = '
+  - Cost:            '3'
+  - String:          ', benefit = '
+  - Benefit:         '52'
+  - String:          ')'
+...
+--- !Passed
+Pass:            sil-generic-specializer
+Name:            sil.Specialized
+DebugLoc:
+  File:            s.swift
+  Line:            4
+  Column:          17
+Function:        main
+Args:
+  - String:          'Specialized function '
+  - Function:        '"Swift._allocateUninitializedArray<A>(_:)"'
+  - String:          ' with type '
+  - FuncType:        '(Builtin.Word) -> (@owned Array<Int>, Builtin.RawPointer)'
+...
+--- !Passed
+Pass:            sil-generic-specializer
+Name:            sil.Specialized
+DebugLoc:
+  File:            s.swift
+  Line:            4
+  Column:          16
+Function:        main
+Args:
+  - String:          'Specialized function '
+  - Function:        '"Swift.Array.init(arrayLiteral:)"'
+  - String:          ' with type '
+  - FuncType:        '(@owned Array<Int>, @thin Array<Int>.Type) -> @owned Array<Int>'
+...
+--- !Passed
+Pass:            sil-inliner
+Name:            sil.Inlined
+DebugLoc:
+  File:            s.swift
+  Line:            4
+  Column:          16
+Function:        main
+Args:
+  - Callee:          '"specialized Swift.Array.init(arrayLiteral:)"'
+  - String:          ' inlined into '
+  - Caller:          '"main"'
+  - String:          ' (cost = '
+  - Cost:            '0'
+  - String:          ', benefit = '
+  - Benefit:         '20'
+  - String:          ')'
+...
+--- !Passed
+Pass:            sil-inliner
+Name:            sil.Inlined
+DebugLoc:
+  File:            s.swift
+  Line:            12
+  Column:          1
+Function:        main
+Args:
+  - Callee:          '"s.f()"'
+    DebugLoc:
+      File:            s.swift
+      Line:            6
+      Column:          6
+  - String:          ' inlined into '
+  - Caller:          '"main"'
+  - String:          ' (cost = '
+  - Cost:            '20'
+  - String:          ', benefit = '
+  - Benefit:         '20'
+  - String:          ')'
+...

Added: llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.swift
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.swift?rev=319902&view=auto
==============================================================================
--- llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.swift (added)
+++ llvm/trunk/test/tools/opt-viewer/Inputs/suppress/s.swift Wed Dec  6 08:50:50 2017
@@ -0,0 +1,11 @@
+import Swift
+
+var s: [Int] = [1, 2, 3, 4]
+
+func f() {
+  for i in 0..<4 {
+    print(s[i])
+  }
+}
+
+f()

Added: llvm/trunk/test/tools/opt-viewer/Outputs/suppress/index.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/opt-viewer/Outputs/suppress/index.html?rev=319902&view=auto
==============================================================================
--- llvm/trunk/test/tools/opt-viewer/Outputs/suppress/index.html (added)
+++ llvm/trunk/test/tools/opt-viewer/Outputs/suppress/index.html Wed Dec  6 08:50:50 2017
@@ -0,0 +1,25 @@
+
+<html>
+<head>
+<link rel='stylesheet' type='text/css' href='style.css'>
+</head>
+<body>
+<div class="centered">
+<table>
+<tr>
+<td>Source Location</td>
+<td>Hotness</td>
+<td>Function</td>
+<td>Pass</td>
+</tr>
+
+<tr>
+<td class="column-entry-0"><a href="s.swift.html#L12">s.swift:12:1</a></td>
+<td class="column-entry-0"></td>
+<td class="column-entry-0">main</td>
+<td class="column-entry-green">sil-inliner</td>
+</tr>
+
+</table>
+</body>
+</html>

Added: llvm/trunk/test/tools/opt-viewer/Outputs/suppress/s.swift.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/opt-viewer/Outputs/suppress/s.swift.html?rev=319902&view=auto
==============================================================================
--- llvm/trunk/test/tools/opt-viewer/Outputs/suppress/s.swift.html (added)
+++ llvm/trunk/test/tools/opt-viewer/Outputs/suppress/s.swift.html Wed Dec  6 08:50:50 2017
@@ -0,0 +1,115 @@
+
+<html>
+<head>
+<link rel='stylesheet' type='text/css' href='style.css'>
+</head>
+<body>
+<div class="centered">
+<table class="source">
+<thead>
+<tr>
+<th style="width: 2%">Line</td>
+<th style="width: 3%">Hotness</td>
+<th style="width: 10%">Optimization</td>
+<th style="width: 70%">Source</td>
+<th style="width: 15%">Inline Context</td>
+</tr>
+</thead>
+<tbody>
+
+<tr>
+<td><a name="L1">1</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre>import Swift</pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L2">2</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre></pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L3">3</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre>var s: [Int] = [1, 2, 3, 4]</pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L4">4</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre></pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L5">5</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre>func f() {</pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L6">6</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre>  for i in 0..<4 {</pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L7">7</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre>    print(s[i])</pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L8">8</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre>  }</pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L9">9</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre>}</pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L10">10</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre></pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L11">11</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre>f()</pre></div></td>
+</tr>
+
+<tr>
+<td><a name="L12">12</a></td>
+<td></td>
+<td></td>
+<td><div class="highlight"><pre></pre></div></td>
+</tr>
+
+<tr>
+<td></td>
+<td></td>
+<td class="column-entry-green">sil-inliner</td>
+<td><pre style="display:inline"></pre><span class="column-entry-yellow"> <a href="s.swift.html#L6">"s.f()"</a> inlined into "main" (cost = 20, benefit = 20) </span></td>
+<td class="column-entry-yellow">main</td>
+</tr>
+
+</tbody>
+</table>
+</body>
+</html>

Added: llvm/trunk/test/tools/opt-viewer/suppress.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/opt-viewer/suppress.test?rev=319902&view=auto
==============================================================================
--- llvm/trunk/test/tools/opt-viewer/suppress.test (added)
+++ llvm/trunk/test/tools/opt-viewer/suppress.test Wed Dec  6 08:50:50 2017
@@ -0,0 +1,3 @@
+RUN: %opt-viewer -s %p/Inputs/suppress -o %t %p/Inputs/suppress/s.opt.yaml --no-highlight --demangler=llvm-cxxfilt
+RUN: diff %p/Outputs/suppress/index.html %t/index.html
+RUN: diff %p/Outputs/suppress/s.swift.html %t/s.swift.html

Modified: llvm/trunk/tools/opt-viewer/opt-viewer.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt-viewer/opt-viewer.py?rev=319902&r1=319901&r2=319902&view=diff
==============================================================================
--- llvm/trunk/tools/opt-viewer/opt-viewer.py (original)
+++ llvm/trunk/tools/opt-viewer/opt-viewer.py Wed Dec  6 08:50:50 2017
@@ -34,6 +34,13 @@ class Context:
 
 context = Context()
 
+def suppress(remark):
+    if remark.Name == 'sil.Specialized':
+        return remark.getArgDict()['Function'][0].startswith('\"Swift.')
+    elif remark.Name == 'sil.Inlined':
+        return remark.getArgDict()['Callee'][0].startswith(('\"Swift.', '\"specialized Swift.'))
+    return False
+
 class SourceFileRenderer:
     def __init__(self, source_dir, output_dir, filename):
         existing_filename = None
@@ -88,7 +95,8 @@ class SourceFileRenderer:
 </tr>'''.format(**locals()), file=self.stream)
 
             for remark in line_remarks.get(linenum, []):
-                self.render_inline_remarks(remark, html_line)
+                if not suppress(remark):
+                    self.render_inline_remarks(remark, html_line)
 
     def render_inline_remarks(self, r, line):
         inlining_context = r.DemangledFunctionName
@@ -179,7 +187,8 @@ class IndexRenderer:
             max_entries = args.max_hottest_remarks_on_index
 
         for i, remark in enumerate(all_remarks[:max_entries]):
-            self.render_entry(remark, i % 2)
+            if not suppress(remark):
+                self.render_entry(remark, i % 2)
         print('''
 </table>
 </body>

Modified: llvm/trunk/tools/opt-viewer/optrecord.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt-viewer/optrecord.py?rev=319902&r1=319901&r2=319902&view=diff
==============================================================================
--- llvm/trunk/tools/opt-viewer/optrecord.py (original)
+++ llvm/trunk/tools/opt-viewer/optrecord.py Wed Dec  6 08:50:50 2017
@@ -161,6 +161,32 @@ class Remark(yaml.YAMLObject):
         else:
             return value
 
+    # Return a cached dictionary for the arguments.  The key for each entry is
+    # the argument key (e.g. 'Callee' for inlining remarks.  The value is a
+    # list containing the value (e.g. for 'Callee' the function) and
+    # optionally a DebugLoc.
+    def getArgDict(self):
+        if hasattr(self, 'ArgDict'):
+            return self.ArgDict
+        self.ArgDict = {}
+        for arg in self.Args:
+            if len(arg) == 2:
+                if arg[0][0] == 'DebugLoc':
+                    dbgidx = 0
+                else:
+                    assert(arg[1][0] == 'DebugLoc')
+                    dbgidx = 1
+
+                key = arg[1 - dbgidx][0]
+                entry = (arg[1 - dbgidx][1], arg[dbgidx][1])
+            else:
+                arg = arg[0]
+                key = arg[0]
+                entry = (arg[1], )
+
+            self.ArgDict[key] = entry
+        return self.ArgDict
+
     def getDiffPrefix(self):
         if hasattr(self, 'Added'):
             if self.Added:




More information about the llvm-commits mailing list