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 index 00000000000..de161bf95f8 --- /dev/null +++ b/test/tools/opt-viewer/Inputs/suppress/s.opt.yaml @@ -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.Type) -> CountableRange' +... +--- !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) -> IndexingIterator>' +... +--- !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>) -> Optional' +... +--- !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(_:)"' + - String: ' with type ' + - FuncType: '(Builtin.Word) -> (@owned Array, 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' +... +--- !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(_:)"' + - String: ' with type ' + - FuncType: '(Builtin.Word) -> (@owned Array, 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, @thin Array.Type) -> @owned Array' +... +--- !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 index 00000000000..a1b17a97945 --- /dev/null +++ b/test/tools/opt-viewer/Inputs/suppress/s.swift @@ -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 index 00000000000..5648b4b2d4e --- /dev/null +++ b/test/tools/opt-viewer/Outputs/suppress/index.html @@ -0,0 +1,25 @@ + + + + + + +
+ + + + + + + + + + + + + + + +
Source LocationHotnessFunctionPass
s.swift:12:1mainsil-inliner
+ + 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 index 00000000000..f3d43c82b59 --- /dev/null +++ b/test/tools/opt-viewer/Outputs/suppress/s.swift.html @@ -0,0 +1,115 @@ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Line +Hotness +Optimization +Source +Inline Context +
1
import Swift
2
3
var s: [Int] = [1, 2, 3, 4]
4
5
func f() {
6
  for i in 0..<4 {
7
    print(s[i])
8
  }
9
}
10
11
f()
12
sil-inliner
 "s.f()" inlined into "main" (cost = 20, benefit = 20) 
main
+ + diff --git a/test/tools/opt-viewer/suppress.test b/test/tools/opt-viewer/suppress.test new file mode 100644 index 00000000000..33226e53953 --- /dev/null +++ b/test/tools/opt-viewer/suppress.test @@ -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 diff --git a/tools/opt-viewer/opt-viewer.py b/tools/opt-viewer/opt-viewer.py index 3000fb12f0b..4c09ef86869 100755 --- a/tools/opt-viewer/opt-viewer.py +++ b/tools/opt-viewer/opt-viewer.py @@ -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: '''.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(''' diff --git a/tools/opt-viewer/optrecord.py b/tools/opt-viewer/optrecord.py index ce665299e17..2256b4dd243 100644 --- a/tools/opt-viewer/optrecord.py +++ b/tools/opt-viewer/optrecord.py @@ -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: