[llvm] 0603737 - [llvm-remarkutil] Fix issues after #66214 and its fixups

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 14 12:07:04 PDT 2023


Author: Fangrui Song
Date: 2023-10-14T12:06:59-07:00
New Revision: 0603737ac0f73ff33326d0274b3152cc5a81e1ec

URL: https://github.com/llvm/llvm-project/commit/0603737ac0f73ff33326d0274b3152cc5a81e1ec
DIFF: https://github.com/llvm/llvm-project/commit/0603737ac0f73ff33326d0274b3152cc5a81e1ec.diff

LOG: [llvm-remarkutil] Fix issues after #66214 and its fixups

Don't use reserved identifier (_GroupBy)
Fix GCC 7.4/7.5 builds (return Filter => return std::move(Filter))
Remove trailing spaces

Added: 
    

Modified: 
    llvm/docs/CommandGuide/llvm-remarkutil.rst
    llvm/test/tools/llvm-remarkutil/Inputs/annotation-count-with-dbg-loc.yaml
    llvm/test/tools/llvm-remarkutil/Inputs/annotation-count.yaml
    llvm/test/tools/llvm-remarkutil/count/Inputs/remark-count-by.yaml
    llvm/test/tools/llvm-remarkutil/count/Inputs/remark-filter-by.yaml
    llvm/test/tools/llvm-remarkutil/count/Inputs/remark-group-by.yaml
    llvm/test/tools/llvm-remarkutil/count/count-by-keys.test
    llvm/test/tools/llvm-remarkutil/count/count-by-remark.test
    llvm/test/tools/llvm-remarkutil/count/filter-by-pass-name.test
    llvm/test/tools/llvm-remarkutil/count/filter-by-remark-name.test
    llvm/test/tools/llvm-remarkutil/count/filter-by-type.test
    llvm/test/tools/llvm-remarkutil/count/group-by-function.test
    llvm/tools/llvm-remarkutil/RemarkCounter.cpp
    llvm/tools/llvm-remarkutil/RemarkCounter.h

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-remarkutil.rst b/llvm/docs/CommandGuide/llvm-remarkutil.rst
index 2e4953eb188ae7b..6fd739e844c4a39 100644
--- a/llvm/docs/CommandGuide/llvm-remarkutil.rst
+++ b/llvm/docs/CommandGuide/llvm-remarkutil.rst
@@ -75,7 +75,7 @@ CSV format is as follows:
   Function,InstructionCount
   foo,123
 
-if `--use-debug-loc` is passed then the CSV will include the source path, line number and column. 
+if `--use-debug-loc` is passed then the CSV will include the source path, line number and column.
 
 ::
   Source,Function,InstructionCount
@@ -104,7 +104,7 @@ CSV format is as follows:
   Function,Count
   foo,123
 
-if `--use-debug-loc` is passed then the CSV will include the source path, line number and column. 
+if `--use-debug-loc` is passed then the CSV will include the source path, line number and column.
 
 ::
   Source,Function,Count
@@ -122,7 +122,7 @@ USAGE: :program:`llvm-remarkutil` count [*options*] <input file>
 Summary
 ^^^^^^^
 
-:program:`llvm-remarkutil count` counts `remarks <https://llvm.org/docs/Remarks.html>` based on specified properties. 
+:program:`llvm-remarkutil count` counts `remarks <https://llvm.org/docs/Remarks.html>` based on specified properties.
 By default the tool counts remarks based on how many occour in a source file or function or total for the generated remark file.
 The tool also supports collecting count based on specific remark arguments. The specified arguments should have an integer value to be able to report a count.
 
@@ -143,15 +143,15 @@ OPTIONS
 
 .. option:: --group-by=<value>
   group count of remarks by property.
-  * ``source``: Count will be collected per source path. Remarks with no debug location will not be counted. 
+  * ``source``: Count will be collected per source path. Remarks with no debug location will not be counted.
   * ``function``: Count is collected per function.
-  * ``function-with-loc``: Count is collected per function per source. Remarks with no debug location will not be counted. 
+  * ``function-with-loc``: Count is collected per function per source. Remarks with no debug location will not be counted.
   * ``Total``: Report a count for the provided remark file.
 
 .. option:: --args[=arguments]
   If `count-by` is set to `arg` this flag can be used to collect from specified remark arguments represented as a comma seperated string.
   The arguments must have a numeral value to be able to count remarks by
-  
+
 .. option:: --rargs[=arguments]
   If `count-by` is set to `arg` this flag can be used to collect from specified remark arguments using regular expression.
   The arguments must have a numeral value to be able to count remarks by
@@ -177,12 +177,12 @@ OPTIONS
 .. option:: --remark-type=<value>
   Filter remarks by type with the following options.
   * ``unknown``
-  * ``passed``               
-  * ``missed``               
-  * ``analysis``             
+  * ``passed``
+  * ``missed``
+  * ``analysis``
   * ``analysis-fp-commute``
-  * ``analysis-aliasing``    
-  * ``failure``              
+  * ``analysis-aliasing``
+  * ``failure``
 
 .. _size-
diff _subcommand:
 

diff  --git a/llvm/test/tools/llvm-remarkutil/Inputs/annotation-count-with-dbg-loc.yaml b/llvm/test/tools/llvm-remarkutil/Inputs/annotation-count-with-dbg-loc.yaml
index 6262ee262f4997d..ebdd722774d4dbe 100644
--- a/llvm/test/tools/llvm-remarkutil/Inputs/annotation-count-with-dbg-loc.yaml
+++ b/llvm/test/tools/llvm-remarkutil/Inputs/annotation-count-with-dbg-loc.yaml
@@ -12,7 +12,7 @@ Args:
 Pass:            annotation-remarks
 Name:            AnnotationSummary
 DebugLoc:        { File: path/to/anno2.c, Line: 1, Column: 2 }
-Function:        func2 
+Function:        func2
 Args:
   - String:          'Annotated '
   - count:           '2'

diff  --git a/llvm/test/tools/llvm-remarkutil/Inputs/annotation-count.yaml b/llvm/test/tools/llvm-remarkutil/Inputs/annotation-count.yaml
index f29808a7772cf47..9b428f013c00c23 100644
--- a/llvm/test/tools/llvm-remarkutil/Inputs/annotation-count.yaml
+++ b/llvm/test/tools/llvm-remarkutil/Inputs/annotation-count.yaml
@@ -1,7 +1,7 @@
 --- !Analysis
 Pass:            annotation-remarks
 Name:            AnnotationSummary
-Function:        func1 
+Function:        func1
 Args:
   - String:          'Annotated '
   - count:           '1'
@@ -10,7 +10,7 @@ Args:
 --- !Analysis
 Pass:            annotation-remarks
 Name:            AnnotationSummary
-Function:        func2 
+Function:        func2
 Args:
   - String:          'Annotated '
   - count:           '2'

diff  --git a/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-count-by.yaml b/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-count-by.yaml
index 3bd0783b7a0a12b..7d1b76eaf0ada9d 100644
--- a/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-count-by.yaml
+++ b/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-count-by.yaml
@@ -1,6 +1,6 @@
 --- !Analysis
 Pass:            generic-remarks-pass
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func1
 Args:
@@ -23,7 +23,7 @@ Args:
   - type:            remark
 --- !Analysis
 Pass:            generic-remarks-pass
-Name:            Remark3 
+Name:            Remark3
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func1
 Args:
@@ -32,7 +32,7 @@ Args:
   - type:            remark
 --- !Analysis
 Pass:            generic-remarks-pass
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func2
 Args:

diff  --git a/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-filter-by.yaml b/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-filter-by.yaml
index e9267bd9404848e..b4318370b29536a 100644
--- a/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-filter-by.yaml
+++ b/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-filter-by.yaml
@@ -1,6 +1,6 @@
 --- !Analysis
 Pass:            generic-remarks-pass
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno2.c, Line: 1, Column: 2 }
 Function:        func1
 Args:
@@ -20,7 +20,7 @@ Args:
   - type:            remark
 --- !Missed
 Pass:            generic-remarks-pass
-Name:            Remark3 
+Name:            Remark3
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func1
 Args:
@@ -29,7 +29,7 @@ Args:
   - type:            remark
 --- !Passed
 Pass:            generic-remarks-pass
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func1
 Args:

diff  --git a/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-group-by.yaml b/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-group-by.yaml
index 5f9222214f2c7bf..a61870a87e5e2b2 100644
--- a/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-group-by.yaml
+++ b/llvm/test/tools/llvm-remarkutil/count/Inputs/remark-group-by.yaml
@@ -1,6 +1,6 @@
 --- !Analysis
 Pass:            generic-remarks-pass
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func1
 Args:
@@ -9,7 +9,7 @@ Args:
   - type:            remark
 --- !Missed
 Pass:            generic-remarks-pass
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func1
 Args:
@@ -18,7 +18,7 @@ Args:
   - type:            remark
 --- !Passed
 Pass:            generic-remarks-pass
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func2
 Args:
@@ -27,7 +27,7 @@ Args:
   - type:            remark
 --- !Analysis
 Pass:            generic-remarks-pass2
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno3.c, Line: 1, Column: 2 }
 Function:        func1
 Args:
@@ -36,7 +36,7 @@ Args:
   - type:            remark
 --- !Analysis
 Pass:            generic-remarks-pass3
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno.c, Line: 1, Column: 2 }
 Function:        func2
 Args:
@@ -45,7 +45,7 @@ Args:
   - type:            remark
 --- !Analysis
 Pass:            generic-remarks-pass4
-Name:            Remark 
+Name:            Remark
 DebugLoc:        { File: path/to/anno2.c, Line: 1, Column: 2 }
 Function:        func3
 Args:

diff  --git a/llvm/test/tools/llvm-remarkutil/count/count-by-keys.test b/llvm/test/tools/llvm-remarkutil/count/count-by-keys.test
index dc414620c3aa550..c0dfbec501ccd41 100644
--- a/llvm/test/tools/llvm-remarkutil/count/count-by-keys.test
+++ b/llvm/test/tools/llvm-remarkutil/count/count-by-keys.test
@@ -1,7 +1,7 @@
 RUN: llvm-remarkutil count --parser=yaml --count-by=arg --group-by=source %p/Inputs/remark-count-by.yaml | FileCheck %s
 RUN: llvm-remarkutil count --parser=yaml --count-by=arg --group-by=function %p/Inputs/remark-count-by.yaml | FileCheck %s --check-prefix=CHECKFUNC
 RUN: llvm-remarkutil count --parser=yaml --count-by=arg --group-by=function-with-loc %p/Inputs/remark-count-by.yaml | FileCheck %s --check-prefix=CHECKFUNCLOC
-RUN: llvm-remarkutil count --parser=yaml --count-by=arg --group-by=total %p/Inputs/remark-count-by.yaml | FileCheck %s --check-prefix=CHECKTOTAL 
+RUN: llvm-remarkutil count --parser=yaml --count-by=arg --group-by=total %p/Inputs/remark-count-by.yaml | FileCheck %s --check-prefix=CHECKTOTAL
 
 ; CHECK-LABEL: Source,count1,count2,count3,count4
 ; CHECK: path/to/anno.c,3,4,6,4

diff  --git a/llvm/test/tools/llvm-remarkutil/count/count-by-remark.test b/llvm/test/tools/llvm-remarkutil/count/count-by-remark.test
index b0248b9b6ec7111..607ef78669473ea 100644
--- a/llvm/test/tools/llvm-remarkutil/count/count-by-remark.test
+++ b/llvm/test/tools/llvm-remarkutil/count/count-by-remark.test
@@ -1,7 +1,7 @@
 RUN: llvm-remarkutil count --parser=yaml --count-by=remark-name --group-by=source %p/Inputs/remark-count-by.yaml | FileCheck %s
 RUN: llvm-remarkutil count --parser=yaml --count-by=remark-name --group-by=function %p/Inputs/remark-count-by.yaml | FileCheck %s --check-prefix=CHECKFUNC
 RUN: llvm-remarkutil count --parser=yaml --count-by=remark-name --group-by=function-with-loc %p/Inputs/remark-count-by.yaml | FileCheck %s --check-prefix=CHECKFUNCLOC
-RUN: llvm-remarkutil count --parser=yaml --count-by=remark-name --group-by=total %p/Inputs/remark-count-by.yaml | FileCheck %s --check-prefix=CHECKTOTAL 
+RUN: llvm-remarkutil count --parser=yaml --count-by=remark-name --group-by=total %p/Inputs/remark-count-by.yaml | FileCheck %s --check-prefix=CHECKTOTAL
 
 ; CHECK-LABEL: Source,Count
 ; CHECK: path/to/anno.c,3

diff  --git a/llvm/test/tools/llvm-remarkutil/count/filter-by-pass-name.test b/llvm/test/tools/llvm-remarkutil/count/filter-by-pass-name.test
index 481d6fd2f5820b8..caf630484caf221 100644
--- a/llvm/test/tools/llvm-remarkutil/count/filter-by-pass-name.test
+++ b/llvm/test/tools/llvm-remarkutil/count/filter-by-pass-name.test
@@ -1,5 +1,5 @@
-RUN: llvm-remarkutil count --parser=yaml --pass-name=generic-remarks-pass %p/Inputs/remark-filter-by.yaml | FileCheck %s 
-RUN: llvm-remarkutil count --parser=yaml --rpass-name=.* %p/Inputs/remark-filter-by.yaml | FileCheck %s --check-prefix=CHECKALL 
+RUN: llvm-remarkutil count --parser=yaml --pass-name=generic-remarks-pass %p/Inputs/remark-filter-by.yaml | FileCheck %s
+RUN: llvm-remarkutil count --parser=yaml --rpass-name=.* %p/Inputs/remark-filter-by.yaml | FileCheck %s --check-prefix=CHECKALL
 
 ; CHECK-LABEL: Source,Count
 ; CHECK: path/to/anno.c,2

diff  --git a/llvm/test/tools/llvm-remarkutil/count/filter-by-remark-name.test b/llvm/test/tools/llvm-remarkutil/count/filter-by-remark-name.test
index 20684d57f648cd6..24d0399e36aef5b 100644
--- a/llvm/test/tools/llvm-remarkutil/count/filter-by-remark-name.test
+++ b/llvm/test/tools/llvm-remarkutil/count/filter-by-remark-name.test
@@ -1,5 +1,5 @@
-RUN: llvm-remarkutil count --parser=yaml --remark-name=Remark %p/Inputs/remark-filter-by.yaml | FileCheck %s 
-RUN: llvm-remarkutil count --parser=yaml --rremark-name=R.* %p/Inputs/remark-filter-by.yaml | FileCheck %s --check-prefix=CHECKALL 
+RUN: llvm-remarkutil count --parser=yaml --remark-name=Remark %p/Inputs/remark-filter-by.yaml | FileCheck %s
+RUN: llvm-remarkutil count --parser=yaml --rremark-name=R.* %p/Inputs/remark-filter-by.yaml | FileCheck %s --check-prefix=CHECKALL
 
 ; CHECK-LABEL: Source,Count
 ; CHECK: path/to/anno.c,1

diff  --git a/llvm/test/tools/llvm-remarkutil/count/filter-by-type.test b/llvm/test/tools/llvm-remarkutil/count/filter-by-type.test
index c392fe43aa199e5..db4f4610ae55907 100644
--- a/llvm/test/tools/llvm-remarkutil/count/filter-by-type.test
+++ b/llvm/test/tools/llvm-remarkutil/count/filter-by-type.test
@@ -13,4 +13,4 @@ RUN: llvm-remarkutil count --parser=yaml --remark-type=unknown %p/Inputs/remark-
 ; ANALYSIS: path/to/anno2.c,2
 
 ; UNKNOWN: Source,Count
-; UNKNOWN-EMPTY: 
+; UNKNOWN-EMPTY:

diff  --git a/llvm/test/tools/llvm-remarkutil/count/group-by-function.test b/llvm/test/tools/llvm-remarkutil/count/group-by-function.test
index f3d04bb00c269a9..67643089d41030c 100644
--- a/llvm/test/tools/llvm-remarkutil/count/group-by-function.test
+++ b/llvm/test/tools/llvm-remarkutil/count/group-by-function.test
@@ -4,4 +4,4 @@ RUN: llvm-remarkutil count --parser=yaml --group-by=function %p/Inputs/remark-gr
 ; CHECK-LABEL: Function,Count
 ; CHECK: func1,3
 ; CHECK: func2,2
-; CHECK: func3,1 
+; CHECK: func3,1

diff  --git a/llvm/tools/llvm-remarkutil/RemarkCounter.cpp b/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
index 8bde0b883018284..dc0685f342886ab 100644
--- a/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
@@ -166,8 +166,7 @@ Error ArgumentCounter::getAllMatchingArgumentsInRemark(
 }
 
 std::optional<std::string> Counter::getGroupByKey(const Remark &Remark) {
-
-  switch (_GroupBy) {
+  switch (Group) {
   case GroupBy::PER_FUNCTION:
     return Remark.FunctionName.str();
   case GroupBy::TOTAL:
@@ -177,7 +176,7 @@ std::optional<std::string> Counter::getGroupByKey(const Remark &Remark) {
     if (!Remark.Loc.has_value())
       return std::nullopt;
 
-    if (_GroupBy == GroupBy::PER_FUNCTION_WITH_DEBUG_LOC)
+    if (Group == GroupBy::PER_FUNCTION_WITH_DEBUG_LOC)
       return Remark.Loc->SourceFilePath.str() + ":" + Remark.FunctionName.str();
     return Remark.Loc->SourceFilePath.str();
   }
@@ -214,7 +213,7 @@ Error ArgumentCounter::print(StringRef OutputFileName) {
     return MaybeOF.takeError();
 
   auto OF = std::move(*MaybeOF);
-  OF->os() << groupByToStr(_GroupBy) << ",";
+  OF->os() << groupByToStr(Group) << ",";
   unsigned Idx = 0;
   for (auto [Key, _] : ArgumentSetIdxMap) {
     OF->os() << Key;
@@ -244,7 +243,7 @@ Error RemarkCounter::print(StringRef OutputFileName) {
     return MaybeOF.takeError();
 
   auto OF = std::move(*MaybeOF);
-  OF->os() << groupByToStr(_GroupBy) << ","
+  OF->os() << groupByToStr(Group) << ","
            << "Count\n";
   for (auto [Key, Count] : CountedByRemarksMap)
     OF->os() << Key << "," << Count << "\n";

diff  --git a/llvm/tools/llvm-remarkutil/RemarkCounter.h b/llvm/tools/llvm-remarkutil/RemarkCounter.h
index 54bba8d7cc99550..3dd06622bc03f36 100644
--- a/llvm/tools/llvm-remarkutil/RemarkCounter.h
+++ b/llvm/tools/llvm-remarkutil/RemarkCounter.h
@@ -88,7 +88,7 @@ struct Filters {
     Filter.RemarkTypeFilter = std::move(RemarkTypeFilter);
     if (auto E = Filter.regexArgumentsValid())
       return std::move(E);
-    return Filter;
+    return std::move(Filter);
   }
   /// Returns true if \p Remark satisfies all the provided filters.
   bool filterRemark(const Remark &Remark);
@@ -110,15 +110,15 @@ inline Error checkRegex(const Regex &Regex) {
 /// Abstract counter class used to define the general required methods for
 /// counting a remark.
 struct Counter {
-  GroupBy _GroupBy;
-  Counter(){};
-  Counter(enum GroupBy GroupBy) : _GroupBy(GroupBy) {}
+  GroupBy Group = GroupBy::TOTAL;
+  Counter() = default;
+  Counter(enum GroupBy GroupBy) : Group(GroupBy) {}
   /// Obtain the field for collecting remark info based on how we are
   /// collecting. Remarks are grouped by FunctionName, Source, Source and
   /// Function or collect by file.
   std::optional<std::string> getGroupByKey(const Remark &Remark);
 
-  /// Collect count information from \p Remark organized based on \p GroupBy
+  /// Collect count information from \p Remark organized based on \p Group
   /// property.
   virtual void collect(const Remark &) = 0;
   /// Output the final count to the file \p OutputFileName
@@ -158,10 +158,10 @@ struct ArgumentCounter : Counter {
   /// vector then we need to check that the provided regular expressions are
   /// valid if not we return an Error.
   static Expected<ArgumentCounter>
-  createArgumentCounter(enum GroupBy GroupBy, ArrayRef<FilterMatcher> Arguments,
+  createArgumentCounter(GroupBy Group, ArrayRef<FilterMatcher> Arguments,
                         StringRef Buffer, Filters &Filter) {
     ArgumentCounter AC;
-    AC._GroupBy = GroupBy;
+    AC.Group = Group;
     for (auto &Arg : Arguments) {
       if (Arg.IsRegex) {
         if (auto E = checkRegex(Arg.FilterRE))
@@ -178,7 +178,7 @@ struct ArgumentCounter : Counter {
   void collect(const Remark &) override;
 
   /// Print a CSV table consisting of an index which is specified by \p
-  /// `GroupBy` and can be a function name, source file name or function name
+  /// `Group` and can be a function name, source file name or function name
   /// with the full source path and columns of user specified remark arguments
   /// to collect the count for.
   Error print(StringRef OutputFileName) override;
@@ -194,19 +194,19 @@ struct ArgumentCounter : Counter {
 };
 
 /// Collect remarks based by counting the existance of individual remarks. The
-/// reported table will be structured based on the provided \p GroupBy argument
+/// reported table will be structured based on the provided \p Group argument
 /// by reporting count for functions, source or total count for the provided
 /// remark file.
 struct RemarkCounter : Counter {
   std::map<std::string, unsigned> CountedByRemarksMap;
-  RemarkCounter(enum GroupBy GroupBy) : Counter(GroupBy) {}
+  RemarkCounter(GroupBy Group) : Counter(Group) {}
 
-  /// Advance the internal map count broken by \p GroupBy when
+  /// Advance the internal map count broken by \p Group when
   /// seeing \p Remark.
   void collect(const Remark &) override;
 
   /// Print a CSV table consisting of an index which is specified by \p
-  /// `GroupBy` and can be a function name, source file name or function name
+  /// `Group` and can be a function name, source file name or function name
   /// with the full source path and a counts column corresponding to the count
   /// of each individual remark at th index.
   Error print(StringRef OutputFileName) override;


        


More information about the llvm-commits mailing list