diff --git a/test/tools/llvm-opt-report/Inputs/dm.c b/test/tools/llvm-opt-report/Inputs/dm.c new file mode 100644 index 00000000000..b031cd2b029 --- /dev/null +++ b/test/tools/llvm-opt-report/Inputs/dm.c @@ -0,0 +1,13 @@ +void bar(void); +void foo(int n) { + if (n) { bar(); } else { while (1) {} } +} + +void quack(void) { + foo(0); +} + +void quack2(void) { + foo(4); +} + diff --git a/test/tools/llvm-opt-report/Inputs/dm.yaml b/test/tools/llvm-opt-report/Inputs/dm.yaml new file mode 100644 index 00000000000..5e6cc54a0a3 --- /dev/null +++ b/test/tools/llvm-opt-report/Inputs/dm.yaml @@ -0,0 +1,104 @@ +--- !Missed +Pass: inline +Name: NoDefinition +DebugLoc: { File: Inputs/dm.c, Line: 3, Column: 12 } +Function: foo +Args: + - Callee: bar + - String: ' will not be inlined into ' + - Caller: foo + DebugLoc: { File: Inputs/dm.c, Line: 2, Column: 0 } + - String: ' because its definition is unavailable' +... +--- !Analysis +Pass: inline +Name: CanBeInlined +DebugLoc: { File: Inputs/dm.c, Line: 7, Column: 3 } +Function: quack +Args: + - Callee: foo + DebugLoc: { File: Inputs/dm.c, Line: 2, Column: 0 } + - String: ' can be inlined into ' + - Caller: quack + DebugLoc: { File: Inputs/dm.c, Line: 6, Column: 0 } + - String: ' with cost=' + - Cost: '-35' + - String: ' (threshold=' + - Threshold: '375' + - String: ')' +... +--- !Passed +Pass: inline +Name: Inlined +DebugLoc: { File: Inputs/dm.c, Line: 7, Column: 3 } +Function: quack +Args: + - Callee: foo + DebugLoc: { File: Inputs/dm.c, Line: 2, Column: 0 } + - String: ' inlined into ' + - Caller: quack + DebugLoc: { File: Inputs/dm.c, Line: 6, Column: 0 } +... +--- !Analysis +Pass: inline +Name: CanBeInlined +DebugLoc: { File: Inputs/dm.c, Line: 11, Column: 3 } +Function: quack2 +Args: + - Callee: foo + DebugLoc: { File: Inputs/dm.c, Line: 2, Column: 0 } + - String: ' can be inlined into ' + - Caller: quack2 + DebugLoc: { File: Inputs/dm.c, Line: 10, Column: 0 } + - String: ' with cost=' + - Cost: '-5' + - String: ' (threshold=' + - Threshold: '375' + - String: ')' +... +--- !Passed +Pass: inline +Name: Inlined +DebugLoc: { File: Inputs/dm.c, Line: 11, Column: 3 } +Function: quack2 +Args: + - Callee: foo + DebugLoc: { File: Inputs/dm.c, Line: 2, Column: 0 } + - String: ' inlined into ' + - Caller: quack2 + DebugLoc: { File: Inputs/dm.c, Line: 10, Column: 0 } +... +--- !Analysis +Pass: loop-vectorize +Name: CFGNotUnderstood +DebugLoc: { File: Inputs/dm.c, Line: 3, Column: 28 } +Function: foo +Args: + - String: 'loop not vectorized: ' + - String: loop control flow is not understood by vectorizer +... +--- !Missed +Pass: loop-vectorize +Name: MissedDetails +DebugLoc: { File: Inputs/dm.c, Line: 3, Column: 28 } +Function: foo +Args: + - String: loop not vectorized +... +--- !Analysis +Pass: loop-vectorize +Name: CFGNotUnderstood +DebugLoc: { File: Inputs/dm.c, Line: 3, Column: 28 } +Function: quack +Args: + - String: 'loop not vectorized: ' + - String: loop control flow is not understood by vectorizer +... +--- !Missed +Pass: loop-vectorize +Name: MissedDetails +DebugLoc: { File: Inputs/dm.c, Line: 3, Column: 28 } +Function: quack +Args: + - String: loop not vectorized +... diff --git a/test/tools/llvm-opt-report/func-dm.test b/test/tools/llvm-opt-report/func-dm.test new file mode 100644 index 00000000000..133386e2b15 --- /dev/null +++ b/test/tools/llvm-opt-report/func-dm.test @@ -0,0 +1,17 @@ +RUN: llvm-opt-report -r %p %p/Inputs/dm.yaml | FileCheck -strict-whitespace %s + +; CHECK: < {{.*[/\]}}dm.c +; CHECK-NEXT: 1 | void bar(void); +; CHECK-NEXT: 2 | void foo(int n) { +; CHECK-NEXT: 3 | if (n) { bar(); } else { while (1) {} } +; CHECK-NEXT: 4 | } +; CHECK-NEXT: 5 | +; CHECK-NEXT: 6 | void quack(void) { +; CHECK-NEXT: 7 I | foo(0); +; CHECK-NEXT: 8 | } +; CHECK-NEXT: 9 | +; CHECK-NEXT: 10 | void quack2(void) { +; CHECK-NEXT: 11 I | foo(4); +; CHECK-NEXT: 12 | } +; CHECK-NEXT: 13 | + diff --git a/tools/llvm-opt-report/OptReport.cpp b/tools/llvm-opt-report/OptReport.cpp index d067df5ecad..4f45dd9f2aa 100644 --- a/tools/llvm-opt-report/OptReport.cpp +++ b/tools/llvm-opt-report/OptReport.cpp @@ -358,7 +358,7 @@ static bool writeReport(LocationInfoTy &LocationInfo) { std::map ColsInfo; unsigned InlinedCols = 0, UnrolledCols = 0, VectorizedCols = 0; - if (LII != FileInfo.end()) { + if (LII != FileInfo.end() && !FuncNameSet.empty()) { const auto &LineInfo = LII->second; for (auto &CI : LineInfo.find(*FuncNameSet.begin())->second) { @@ -475,13 +475,21 @@ static bool writeReport(LocationInfoTy &LocationInfo) { std::map, std::set> UniqueLIs; + OptReportLocationInfo AllLI; if (LII != FileInfo.end()) { const auto &FuncLineInfo = LII->second; - for (const auto &FLII : FuncLineInfo) + for (const auto &FLII : FuncLineInfo) { UniqueLIs[FLII.second].insert(FLII.first); + + for (const auto &OI : FLII.second) + AllLI |= OI.second; + } } - if (UniqueLIs.size() > 1) { + bool NothingHappened = !AllLI.Inlined.Transformed && + !AllLI.Unrolled.Transformed && + !AllLI.Vectorized.Transformed; + if (UniqueLIs.size() > 1 && !NothingHappened) { OS << " [[\n"; for (const auto &FSLI : UniqueLIs) PrintLine(true, FSLI.second);