[llvm-opt-report] Fix context-sensitive lines where nothing happened

Don't print a line multiple times, each for different inlining contexts, if
nothing happened in any context. This prevents situations like this:

 [[
  > main:
 65     |       if ((i * ni + j) % 20 == 0) fprintf
  > print_array:
 65     |       if ((i * ni + j) % 20 == 0) fprintf
 ]]

which could happen if different optimizations were missed in different inlining
contexts.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291361 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Hal Finkel 2017-01-07 20:21:17 +00:00
parent 071eccb255
commit 41b81eb904
4 changed files with 145 additions and 3 deletions

View File

@ -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);
}

View File

@ -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
...

View File

@ -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 |

View File

@ -358,7 +358,7 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
std::map<int, OptReportLocationInfo> 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::map<int, OptReportLocationInfo>,
std::set<std::string>> 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);