OSDN Git Service

[opt-viewer] Suppress noisy Swift remarks
authorAdam Nemet <anemet@apple.com>
Wed, 6 Dec 2017 16:50:50 +0000 (16:50 +0000)
committerAdam Nemet <anemet@apple.com>
Wed, 6 Dec 2017 16:50:50 +0000 (16:50 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319902 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/opt-viewer/Inputs/suppress/s.opt.yaml [new file with mode: 0644]
test/tools/opt-viewer/Inputs/suppress/s.swift [new file with mode: 0644]
test/tools/opt-viewer/Outputs/suppress/index.html [new file with mode: 0644]
test/tools/opt-viewer/Outputs/suppress/s.swift.html [new file with mode: 0644]
test/tools/opt-viewer/suppress.test [new file with mode: 0644]
tools/opt-viewer/opt-viewer.py
tools/opt-viewer/optrecord.py

diff --git a/test/tools/opt-viewer/Inputs/suppress/s.opt.yaml b/test/tools/opt-viewer/Inputs/suppress/s.opt.yaml
new file mode 100644 (file)
index 0000000..de161bf
--- /dev/null
@@ -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:          ')'
+...
diff --git a/test/tools/opt-viewer/Inputs/suppress/s.swift b/test/tools/opt-viewer/Inputs/suppress/s.swift
new file mode 100644 (file)
index 0000000..a1b17a9
--- /dev/null
@@ -0,0 +1,11 @@
+import Swift
+
+var s: [Int] = [1, 2, 3, 4]
+
+func f() {
+  for i in 0..<4 {
+    print(s[i])
+  }
+}
+
+f()
diff --git a/test/tools/opt-viewer/Outputs/suppress/index.html b/test/tools/opt-viewer/Outputs/suppress/index.html
new file mode 100644 (file)
index 0000000..5648b4b
--- /dev/null
@@ -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>
diff --git a/test/tools/opt-viewer/Outputs/suppress/s.swift.html b/test/tools/opt-viewer/Outputs/suppress/s.swift.html
new file mode 100644 (file)
index 0000000..f3d43c8
--- /dev/null
@@ -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)&nbsp;</span></td>
+<td class="column-entry-yellow">main</td>
+</tr>
+
+</tbody>
+</table>
+</body>
+</html>
diff --git a/test/tools/opt-viewer/suppress.test b/test/tools/opt-viewer/suppress.test
new file mode 100644 (file)
index 0000000..33226e5
--- /dev/null
@@ -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
index 3000fb1..4c09ef8 100755 (executable)
@@ -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>
index ce66529..2256b4d 100644 (file)
@@ -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: