[AnnotationRemarks] Use subprogram location for summary remarks.
authorFlorian Hahn <flo@fhahn.com>
Tue, 23 Mar 2021 11:59:08 +0000 (11:59 +0000)
committerFlorian Hahn <flo@fhahn.com>
Tue, 23 Mar 2021 12:05:41 +0000 (12:05 +0000)
The summary remarks are generated on a per-function basis. Using the
first instruction's location is sub-optimal for 2 reasons:
  1. Sometimes the first instruction is missing !dbg
  2. The location of the first instruction may be mis-leading.

Instead, just use the location of the function directly.

llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp
llvm/test/Transforms/Util/annotation-remarks-dbg-info.ll

index bb5270a..c5bdfb4 100644 (file)
@@ -100,9 +100,9 @@ static void runImpl(Function &F, const TargetLibraryInfo &TLI) {
     }
   }
 
-  Instruction *IP = &*F.begin()->begin();
   for (const auto &KV : Mapping)
-    ORE.emit(OptimizationRemarkAnalysis(REMARK_PASS, "AnnotationSummary", IP)
+    ORE.emit(OptimizationRemarkAnalysis(REMARK_PASS, "AnnotationSummary",
+                                        F.getSubprogram(), &F.front())
              << "Annotated " << NV("count", KV.second) << " instructions with "
              << NV("type", KV.first));
 
index 102a435..25e5729 100644 (file)
@@ -9,7 +9,7 @@
 ; CHECK:      --- !Analysis
 ; CHECK-NEXT: Pass:            annotation-remarks
 ; CHECK-NEXT: Name:            AnnotationSummary
-; CHECK-NEXT: DebugLoc: { File: test.c, Line: 400, Column: 3 }
+; CHECK-NEXT: DebugLoc: { File: test.c, Line: 10, Column: 0 }
 ; CHECK-NEXT: Function:        test1
 ; CHECK-NEXT: Args:
 ; CHECK-NEXT:   - String:          'Annotated '
@@ -20,7 +20,7 @@
 ; CHECK-NEXT: --- !Analysis
 ; CHECK-NEXT: Pass:            annotation-remarks
 ; CHECK-NEXT: Name:            AnnotationSummary
-; CHECK-NEXT: DebugLoc: { File: test.c, Line: 400, Column: 3 }
+; CHECK-NEXT: DebugLoc: { File: test.c, Line: 10, Column: 0 }
 ; CHECK-NEXT: Function:        test1
 ; CHECK-NEXT: Args:
 ; CHECK-NEXT:   - String:          'Annotated '
@@ -31,6 +31,7 @@
 ; CHECK-NEXT: --- !Analysis
 ; CHECK-NEXT: Pass:            annotation-remarks
 ; CHECK-NEXT: Name:            AnnotationSummary
+; CHECK-NEXT: DebugLoc: { File: test.c, Line: 20, Column: 0 }
 ; CHECK-NEXT: Function:        test2
 ; CHECK-NEXT: Args:
 ; CHECK-NEXT:   - String:          'Annotated '