diff --git a/clang/docs/ClangFormattedStatus.rst b/clang/docs/ClangFormattedStatus.rst --- a/clang/docs/ClangFormattedStatus.rst +++ b/clang/docs/ClangFormattedStatus.rst @@ -5869,11 +5869,6 @@ - `39` - `1` - :part:`97%` - * - llvm/tools/llvm-remark-size-diff - - `1` - - `1` - - `0` - - :good:`100%` * - llvm/tools/llvm-rtdyld - `1` - `0` diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt --- a/clang/docs/tools/clang-formatted-files.txt +++ b/clang/docs/tools/clang-formatted-files.txt @@ -7142,7 +7142,6 @@ llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.h llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.h -llvm/tools/llvm-remark-size-diff/RemarkSizeDiff.cpp llvm/tools/llvm-rust-demangle-fuzzer/DummyDemanglerFuzzer.cpp llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp llvm/tools/llvm-shlib/libllvm.cpp diff --git a/llvm/docs/CommandGuide/index.rst b/llvm/docs/CommandGuide/index.rst --- a/llvm/docs/CommandGuide/index.rst +++ b/llvm/docs/CommandGuide/index.rst @@ -96,5 +96,4 @@ .. toctree:: :maxdepth: 1 - llvm-remark-size-diff llvm-remarkutil diff --git a/llvm/docs/CommandGuide/llvm-remark-size-diff.rst b/llvm/docs/CommandGuide/llvm-remark-size-diff.rst deleted file mode 100644 --- a/llvm/docs/CommandGuide/llvm-remark-size-diff.rst +++ /dev/null @@ -1,222 +0,0 @@ -llvm-remark-size-diff - diff size remarks -========================================= - -.. program:: llvm-remark-size-diff - -SYNOPSIS --------- - -:program:`llvm-remark-size-diff` [*options*] *file_a* *file_b* **--parser** *parser* - -DESCRIPTION ------------ - -:program:`llvm-remark-size-diff` diffs size -`remarks `_ in two remark files: ``file_a`` -and ``file_b``. - -:program:`llvm-remark-size-diff` can be used to gain insight into which -functions were impacted the most by code generation changes. - -In most common use-cases ``file_a`` and ``file_b`` will be remarks output by -compiling a **fixed source** with **differing compilers** or -**differing optimization settings**. - -:program:`llvm-remark-size-diff` handles both -`YAML `_ and -`bitstream `_ -remarks. - -OPTIONS -------- - -.. option:: --parser= - - Select the type of input remark parser. Required. - * ``yaml``: The tool will parse YAML remarks. - * ``bitstream``: The tool will parse bitstream remarks. - -.. option:: --report-style= - - Output style. - * ``human``: Human-readable textual report. Default option. - * ``json``: JSON report. - -.. option:: --pretty - - Pretty-print JSON output. Optional. - - If output is not set to JSON, this does nothing. - -.. option:: -o= - - Output file for the report. Outputs to stdout by default. - -HUMAN-READABLE OUTPUT ---------------------- - -The human-readable format for :program:`llvm-remark-size-diff` is composed of -two sections: - -* Per-function changes. -* A high-level summary of all changes. - -Changed Function Section -######################## - -Suppose you are comparing two remark files OLD and NEW. - -For each function with a **changed instruction count** in OLD and NEW, -:program:`llvm-remark-size-diff` will emit a line like below: - -:: - - (++|--|==) (>|<) function_name, N instrs, M stack B - -A breakdown of the format is below: - -``(++|--|==)`` - Which of OLD and NEW the ``function_name`` is present in. - - * ``++``: Only in NEW. ("Added") - * ``--``: Only in OLD. ("Removed") - * ``==``: In both. - -``(>|<)`` - Denotes if ``function_name`` has more instructions or fewer instructions in - the second file. - - * ``>``: More instructions in second file than first file. - * ``<``: Fewer instructions in second file than in first file. - -``function_name`` - The name of the changed function. - -``N instrs`` - Second file instruction count - first file instruction count. - -``M stack B`` - Second file stack byte count - first file stack byte count. - -Summary Section -############### - -:program:`llvm-remark-size-diff` will output a high-level summary after -printing all changed functions. - -:: - - instruction count: N (inst_pct_change%) - stack byte usage: M (sb_pct_change%) - -``N`` - Sum of all instruction count changes between the second and first file. - -``inst_pct_change%`` - Percent increase or decrease in instruction count between the second and first - file. - -``M`` - Sum of all stack byte count changes between the second and first file. - -``sb_pct_change%`` - Percent increase or decrease in stack byte usage between the second and first - file. - -JSON OUTPUT ------------ - -High-Level view -############### - -Suppose we are comparing two files, OLD and NEW. - -:program:`llvm-remark-size-diff` will output JSON as follows. - -:: - - "Files": [ - "A": "path/to/OLD", - "B": "path/to/NEW" - ] - - "InBoth": [ - ... - ], - - "OnlyInA": [ - ... - ], - - "OnlyInB": [ - ... - ] - - -``Files`` - Original paths to remark files. - - * ``A``: Path to the first file. - * ``B``: Path to the second file. - -``InBoth`` - Functions present in both files. - -``OnlyInA`` - Functions only present in the first file. - -``OnlyInB`` - Functions only present in the second file. - -Function JSON -############# - -The ``InBoth``, ``OnlyInA``, and ``OnlyInB`` sections contain size information -for each function in the input remark files. - -:: - - { - "FunctionName" : "function_name" - "InstCount": [ - INST_COUNT_A, - INST_COUNT_B - ], - "StackSize": [ - STACK_BYTES_A, - STACK_BYTES_B - ], - } - -``FunctionName`` - Name of the function. - -``InstCount`` - Instruction counts for the function. - - * ``INST_COUNT_A``: Instruction count in OLD. - * ``INST_COUNT_B``: Instruction count in NEW. - -``StackSize`` - Stack byte counts for the function. - - * ``STACK_BYTES_A``: Stack bytes in OLD. - * ``STACK_BYTES_B``: Stack bytes in NEW. - -Computing Diffs From Function JSON -********************************** - -Function JSON does not contain the diffs. Tools consuming JSON output from -:program:`llvm-remark-size-diff` are responsible for computing the diffs -separately. - -**To compute the diffs:** - -* Instruction count diff: ``INST_COUNT_B - INST_COUNT_A`` -* Stack byte count diff: ``STACK_BYTES_B - STACK_BYTES_A`` - -EXIT STATUS ------------ - -:program:`llvm-remark-size-diff` returns 0 on success, and a non-zero value -otherwise. diff --git a/llvm/docs/CommandGuide/llvm-remarkutil.rst b/llvm/docs/CommandGuide/llvm-remarkutil.rst --- a/llvm/docs/CommandGuide/llvm-remarkutil.rst +++ b/llvm/docs/CommandGuide/llvm-remarkutil.rst @@ -21,6 +21,7 @@ * :ref:`yaml2bitstream_subcommand` - Reserialize YAML remarks to bitstream. * :ref:`instruction-count_subcommand` - Output function instruction counts. * :ref:`annotation-count_subcommand` - Output remark type count from annotation remarks. + * :ref: `size-diff_subcommand` - Compute diff in size remarks. .. _bitstream2yaml_subcommand: @@ -108,3 +109,223 @@ :: Source,Function,Count path:line:column,foo,3 + +.. _size-diff_subcommand: + +size-diff +~~~~~~~~~ +.. program:: llvm-remarkutil size-diff + +USAGE: :program:`llvm-remarkutil` size-diff [*options*] *file_a* *file_b* **--parser** *parser* + +Summary +^^^^^^^ + +:program:`llvm-remarkutil size-diff` diffs size `remarks `_ in two remark files: ``file_a`` +and ``file_b``. + +:program:`llvm-remarkutil size-diff` can be used to gain insight into which +functions were impacted the most by code generation changes. + +In most common use-cases ``file_a`` and ``file_b`` will be remarks output by +compiling a **fixed source** with **differing compilers** or +**differing optimization settings**. + +:program:`llvm-remarkutil size-diff` handles both +`YAML `_ and +`bitstream `_ +remarks. + +OPTIONS +------- + +.. option:: --parser= + + Select the type of input remark parser. Required. + * ``yaml``: The tool will parse YAML remarks. + * ``bitstream``: The tool will parse bitstream remarks. + +.. option:: --report-style= + + Output style. + * ``human``: Human-readable textual report. Default option. + * ``json``: JSON report. + +.. option:: --pretty + + Pretty-print JSON output. Optional. + + If output is not set to JSON, this does nothing. + +.. option:: -o= + + Output file for the report. Outputs to stdout by default. + +HUMAN-READABLE OUTPUT +--------------------- + +The human-readable format for :program:`llvm-remarkutil size-diff` is composed of +two sections: + +* Per-function changes. +* A high-level summary of all changes. + +Changed Function Section +######################## + +Suppose you are comparing two remark files OLD and NEW. + +For each function with a **changed instruction count** in OLD and NEW, +:program:`llvm-remarkutil size-diff` will emit a line like below: + +:: + + (++|--|==) (>|<) function_name, N instrs, M stack B + +A breakdown of the format is below: + +``(++|--|==)`` + Which of OLD and NEW the ``function_name`` is present in. + + * ``++``: Only in NEW. ("Added") + * ``--``: Only in OLD. ("Removed") + * ``==``: In both. + +``(>|<)`` + Denotes if ``function_name`` has more instructions or fewer instructions in + the second file. + + * ``>``: More instructions in second file than first file. + * ``<``: Fewer instructions in second file than in first file. + +``function_name`` + The name of the changed function. + +``N instrs`` + Second file instruction count - first file instruction count. + +``M stack B`` + Second file stack byte count - first file stack byte count. + +Summary Section +############### + +:program:`llvm-remarkutil size-diff` will output a high-level summary after +printing all changed functions. + +:: + + instruction count: N (inst_pct_change%) + stack byte usage: M (sb_pct_change%) + +``N`` + Sum of all instruction count changes between the second and first file. + +``inst_pct_change%`` + Percent increase or decrease in instruction count between the second and first + file. + +``M`` + Sum of all stack byte count changes between the second and first file. + +``sb_pct_change%`` + Percent increase or decrease in stack byte usage between the second and first + file. + +JSON OUTPUT +----------- + +High-Level view +############### + +Suppose we are comparing two files, OLD and NEW. + +:program:`llvm-remarkutil size-diff` will output JSON as follows. + +:: + + "Files": [ + "A": "path/to/OLD", + "B": "path/to/NEW" + ] + + "InBoth": [ + ... + ], + + "OnlyInA": [ + ... + ], + + "OnlyInB": [ + ... + ] + + +``Files`` + Original paths to remark files. + + * ``A``: Path to the first file. + * ``B``: Path to the second file. + +``InBoth`` + Functions present in both files. + +``OnlyInA`` + Functions only present in the first file. + +``OnlyInB`` + Functions only present in the second file. + +Function JSON +############# + +The ``InBoth``, ``OnlyInA``, and ``OnlyInB`` sections contain size information +for each function in the input remark files. + +:: + + { + "FunctionName" : "function_name" + "InstCount": [ + INST_COUNT_A, + INST_COUNT_B + ], + "StackSize": [ + STACK_BYTES_A, + STACK_BYTES_B + ], + } + +``FunctionName`` + Name of the function. + +``InstCount`` + Instruction counts for the function. + + * ``INST_COUNT_A``: Instruction count in OLD. + * ``INST_COUNT_B``: Instruction count in NEW. + +``StackSize`` + Stack byte counts for the function. + + * ``STACK_BYTES_A``: Stack bytes in OLD. + * ``STACK_BYTES_B``: Stack bytes in NEW. + +Computing Diffs From Function JSON +********************************** + +Function JSON does not contain the diffs. Tools consuming JSON output from +:program:`llvm-remarkutil size-diff` are responsible for computing the diffs +separately. + +**To compute the diffs:** + +* Instruction count diff: ``INST_COUNT_B - INST_COUNT_A`` +* Stack byte count diff: ``STACK_BYTES_B - STACK_BYTES_A`` + +EXIT STATUS +----------- + +:program:`llvm-remarkutil size-diff` returns 0 on success, and a non-zero value +otherwise. diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt --- a/llvm/test/CMakeLists.txt +++ b/llvm/test/CMakeLists.txt @@ -120,7 +120,6 @@ llvm-readobj llvm-readelf llvm-reduce - llvm-remark-size-diff llvm-remarkutil llvm-rtdyld llvm-sim diff --git a/llvm/test/lit.cfg.py b/llvm/test/lit.cfg.py --- a/llvm/test/lit.cfg.py +++ b/llvm/test/lit.cfg.py @@ -216,7 +216,6 @@ "llvm-rc", "llvm-readelf", "llvm-readobj", - "llvm-remark-size-diff", "llvm-rtdyld", "llvm-sim", "llvm-size", diff --git a/llvm/test/tools/llvm-remark-size-diff/empty-file.test b/llvm/test/tools/llvm-remark-size-diff/empty-file.test deleted file mode 100644 --- a/llvm/test/tools/llvm-remark-size-diff/empty-file.test +++ /dev/null @@ -1,4 +0,0 @@ -RUN: not llvm-remark-size-diff %p/Inputs/empty-file.yaml %p/Inputs/1-func-2-instr-2-stack.yaml --parser=yaml 2>&1 | FileCheck %s -RUN: not llvm-remark-size-diff %p/Inputs/1-func-2-instr-2-stack.yaml %p/Inputs/empty-file.yaml --parser=yaml 2>&1 | FileCheck %s - -; CHECK: error: document root is not of mapping type. diff --git a/llvm/test/tools/llvm-remark-size-diff/inconvertible-integer.test b/llvm/test/tools/llvm-remark-size-diff/inconvertible-integer.test deleted file mode 100644 --- a/llvm/test/tools/llvm-remark-size-diff/inconvertible-integer.test +++ /dev/null @@ -1,3 +0,0 @@ -RUN: not llvm-remark-size-diff %p/Inputs/inconvertible-integer.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml 2>&1 | FileCheck %s - -; CHECK: Could not convert string to signed integer: a diff --git a/llvm/test/tools/llvm-remark-size-diff/increase-decrease-inst-count.test b/llvm/test/tools/llvm-remark-size-diff/increase-decrease-inst-count.test deleted file mode 100644 --- a/llvm/test/tools/llvm-remark-size-diff/increase-decrease-inst-count.test +++ /dev/null @@ -1,12 +0,0 @@ -RUN: llvm-remark-size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/1-func-2-instr-2-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s --check-prefix=INCREASE -RUN: llvm-remark-size-diff %p/Inputs/1-func-2-instr-2-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s --check-prefix=DECREASE - -; Test a size increase/decrease of one instruction + 1 stack byte. - -; INCREASE: == > func0, 1 instrs, 1 stack B -; INCREASE-DAG: instruction count: 1 (100.00%) -; INCREASE-NEXT: stack byte usage: 1 (100.00%) - -; DECREASE: == < func0, -1 instrs, -1 stack B -; DECREASE-DAG: instruction count: -1 (-50.00%) -; DECREASE-NEXT: stack byte usage: -1 (-50.00%) diff --git a/llvm/test/tools/llvm-remark-size-diff/no-difference.test b/llvm/test/tools/llvm-remark-size-diff/no-difference.test deleted file mode 100644 --- a/llvm/test/tools/llvm-remark-size-diff/no-difference.test +++ /dev/null @@ -1,7 +0,0 @@ -RUN: llvm-remark-size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s - -; Same file passed twice -> no changes reported. - -; CHECK-NOT: {{[0-9]+}} -; CHECK: instruction count: None -; CHECK: stack byte usage: None diff --git a/llvm/test/tools/llvm-remark-size-diff/no-instruction-count-remarks.test b/llvm/test/tools/llvm-remark-size-diff/no-instruction-count-remarks.test deleted file mode 100644 --- a/llvm/test/tools/llvm-remark-size-diff/no-instruction-count-remarks.test +++ /dev/null @@ -1,3 +0,0 @@ -RUN: not llvm-remark-size-diff %p/Inputs/no-instruction-count-remarks.yaml %p/Inputs/no-instruction-count-remarks.yaml --parser=yaml 2>&1 | FileCheck %s - -; CHECK: error: File {{.*}} did not contain any instruction-count remarks! diff --git a/llvm/test/tools/llvm-remark-size-diff/unexpected-key.test b/llvm/test/tools/llvm-remark-size-diff/unexpected-key.test deleted file mode 100644 --- a/llvm/test/tools/llvm-remark-size-diff/unexpected-key.test +++ /dev/null @@ -1,3 +0,0 @@ -RUN: not llvm-remark-size-diff %p/Inputs/unexpected-key.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml 2>&1 | FileCheck %s - -; CHECK: Expected 'NumInstructions', got 'Wrong' diff --git a/llvm/test/tools/llvm-remark-size-diff/Inputs/1-func-1-instr-1-stack.yaml b/llvm/test/tools/llvm-remarkutil/size-diff/Inputs/1-func-1-instr-1-stack.yaml rename from llvm/test/tools/llvm-remark-size-diff/Inputs/1-func-1-instr-1-stack.yaml rename to llvm/test/tools/llvm-remarkutil/size-diff/Inputs/1-func-1-instr-1-stack.yaml diff --git a/llvm/test/tools/llvm-remark-size-diff/Inputs/1-func-2-instr-2-stack.yaml b/llvm/test/tools/llvm-remarkutil/size-diff/Inputs/1-func-2-instr-2-stack.yaml rename from llvm/test/tools/llvm-remark-size-diff/Inputs/1-func-2-instr-2-stack.yaml rename to llvm/test/tools/llvm-remarkutil/size-diff/Inputs/1-func-2-instr-2-stack.yaml diff --git a/llvm/test/tools/llvm-remark-size-diff/Inputs/2-identical-func-1-instr-1-stack.yaml b/llvm/test/tools/llvm-remarkutil/size-diff/Inputs/2-identical-func-1-instr-1-stack.yaml rename from llvm/test/tools/llvm-remark-size-diff/Inputs/2-identical-func-1-instr-1-stack.yaml rename to llvm/test/tools/llvm-remarkutil/size-diff/Inputs/2-identical-func-1-instr-1-stack.yaml diff --git a/llvm/test/tools/llvm-remark-size-diff/Inputs/empty-file.yaml b/llvm/test/tools/llvm-remarkutil/size-diff/Inputs/empty-file.yaml rename from llvm/test/tools/llvm-remark-size-diff/Inputs/empty-file.yaml rename to llvm/test/tools/llvm-remarkutil/size-diff/Inputs/empty-file.yaml diff --git a/llvm/test/tools/llvm-remark-size-diff/Inputs/inconvertible-integer.yaml b/llvm/test/tools/llvm-remarkutil/size-diff/Inputs/inconvertible-integer.yaml rename from llvm/test/tools/llvm-remark-size-diff/Inputs/inconvertible-integer.yaml rename to llvm/test/tools/llvm-remarkutil/size-diff/Inputs/inconvertible-integer.yaml diff --git a/llvm/test/tools/llvm-remark-size-diff/Inputs/no-instruction-count-remarks.yaml b/llvm/test/tools/llvm-remarkutil/size-diff/Inputs/no-instruction-count-remarks.yaml rename from llvm/test/tools/llvm-remark-size-diff/Inputs/no-instruction-count-remarks.yaml rename to llvm/test/tools/llvm-remarkutil/size-diff/Inputs/no-instruction-count-remarks.yaml diff --git a/llvm/test/tools/llvm-remark-size-diff/Inputs/unexpected-key.yaml b/llvm/test/tools/llvm-remarkutil/size-diff/Inputs/unexpected-key.yaml rename from llvm/test/tools/llvm-remark-size-diff/Inputs/unexpected-key.yaml rename to llvm/test/tools/llvm-remarkutil/size-diff/Inputs/unexpected-key.yaml diff --git a/llvm/test/tools/llvm-remark-size-diff/add-remove-func.test b/llvm/test/tools/llvm-remarkutil/size-diff/add-remove-func.test rename from llvm/test/tools/llvm-remark-size-diff/add-remove-func.test rename to llvm/test/tools/llvm-remarkutil/size-diff/add-remove-func.test --- a/llvm/test/tools/llvm-remark-size-diff/add-remove-func.test +++ b/llvm/test/tools/llvm-remarkutil/size-diff/add-remove-func.test @@ -1,5 +1,5 @@ -RUN: llvm-remark-size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/2-identical-func-1-instr-1-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s --check-prefix=ADD -RUN: llvm-remark-size-diff %p/Inputs/2-identical-func-1-instr-1-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s --check-prefix=REMOVE +RUN: llvm-remarkutil size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/2-identical-func-1-instr-1-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s --check-prefix=ADD +RUN: llvm-remarkutil size-diff %p/Inputs/2-identical-func-1-instr-1-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s --check-prefix=REMOVE ; The "two-identical-one-instr-funcs" file contains a single-instruction ; function which does not appear in the other file. diff --git a/llvm/test/tools/llvm-remarkutil/size-diff/empty-file.test b/llvm/test/tools/llvm-remarkutil/size-diff/empty-file.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-remarkutil/size-diff/empty-file.test @@ -0,0 +1,4 @@ +RUN: not llvm-remarkutil size-diff %p/Inputs/empty-file.yaml %p/Inputs/1-func-2-instr-2-stack.yaml --parser=yaml 2>&1 | FileCheck %s +RUN: not llvm-remarkutil size-diff %p/Inputs/1-func-2-instr-2-stack.yaml %p/Inputs/empty-file.yaml --parser=yaml 2>&1 | FileCheck %s + +; CHECK: error: document root is not of mapping type. diff --git a/llvm/test/tools/llvm-remarkutil/size-diff/inconvertible-integer.test b/llvm/test/tools/llvm-remarkutil/size-diff/inconvertible-integer.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-remarkutil/size-diff/inconvertible-integer.test @@ -0,0 +1,3 @@ +RUN: not llvm-remarkutil size-diff %p/Inputs/inconvertible-integer.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml 2>&1 | FileCheck %s + +; CHECK: Could not convert string to signed integer: a diff --git a/llvm/test/tools/llvm-remarkutil/size-diff/increase-decrease-inst-count.test b/llvm/test/tools/llvm-remarkutil/size-diff/increase-decrease-inst-count.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-remarkutil/size-diff/increase-decrease-inst-count.test @@ -0,0 +1,12 @@ +RUN: llvm-remarkutil size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/1-func-2-instr-2-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s --check-prefix=INCREASE +RUN: llvm-remarkutil size-diff %p/Inputs/1-func-2-instr-2-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s --check-prefix=DECREASE + +; Test a size increase/decrease of one instruction + 1 stack byte. + +; INCREASE: == > func0, 1 instrs, 1 stack B +; INCREASE-DAG: instruction count: 1 (100.00%) +; INCREASE-NEXT: stack byte usage: 1 (100.00%) + +; DECREASE: == < func0, -1 instrs, -1 stack B +; DECREASE-DAG: instruction count: -1 (-50.00%) +; DECREASE-NEXT: stack byte usage: -1 (-50.00%) diff --git a/llvm/test/tools/llvm-remark-size-diff/json-add-remove-func.test b/llvm/test/tools/llvm-remarkutil/size-diff/json-add-remove-func.test rename from llvm/test/tools/llvm-remark-size-diff/json-add-remove-func.test rename to llvm/test/tools/llvm-remarkutil/size-diff/json-add-remove-func.test --- a/llvm/test/tools/llvm-remark-size-diff/json-add-remove-func.test +++ b/llvm/test/tools/llvm-remarkutil/size-diff/json-add-remove-func.test @@ -1,5 +1,5 @@ -RUN: llvm-remark-size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/2-identical-func-1-instr-1-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s --check-prefix=ADD -RUN: llvm-remark-size-diff %p/Inputs/2-identical-func-1-instr-1-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s --check-prefix=REMOVE +RUN: llvm-remarkutil size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/2-identical-func-1-instr-1-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s --check-prefix=ADD +RUN: llvm-remarkutil size-diff %p/Inputs/2-identical-func-1-instr-1-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s --check-prefix=REMOVE ; The "two-identical-one-instr-funcs" file contains a single-instruction ; function which does not appear in the other file. diff --git a/llvm/test/tools/llvm-remark-size-diff/json-increase-decrease-inst-count.test b/llvm/test/tools/llvm-remarkutil/size-diff/json-increase-decrease-inst-count.test rename from llvm/test/tools/llvm-remark-size-diff/json-increase-decrease-inst-count.test rename to llvm/test/tools/llvm-remarkutil/size-diff/json-increase-decrease-inst-count.test --- a/llvm/test/tools/llvm-remark-size-diff/json-increase-decrease-inst-count.test +++ b/llvm/test/tools/llvm-remarkutil/size-diff/json-increase-decrease-inst-count.test @@ -1,5 +1,5 @@ -RUN: llvm-remark-size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/1-func-2-instr-2-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s --check-prefix=INCREASE -RUN: llvm-remark-size-diff %p/Inputs/1-func-2-instr-2-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s --check-prefix=DECREASE +RUN: llvm-remarkutil size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/1-func-2-instr-2-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s --check-prefix=INCREASE +RUN: llvm-remarkutil size-diff %p/Inputs/1-func-2-instr-2-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s --check-prefix=DECREASE ; Test a size increase/decrease of one instruction + 1 stack byte. diff --git a/llvm/test/tools/llvm-remark-size-diff/json-no-difference.test b/llvm/test/tools/llvm-remarkutil/size-diff/json-no-difference.test rename from llvm/test/tools/llvm-remark-size-diff/json-no-difference.test rename to llvm/test/tools/llvm-remarkutil/size-diff/json-no-difference.test --- a/llvm/test/tools/llvm-remark-size-diff/json-no-difference.test +++ b/llvm/test/tools/llvm-remarkutil/size-diff/json-no-difference.test @@ -1,4 +1,4 @@ -RUN: llvm-remark-size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s +RUN: llvm-remarkutil size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml --report_style=json --pretty | FileCheck -strict-whitespace %s ; CHECK-LABEL: "Files": ; CHECK: "A":{{.*}}1-func-1-instr-1-stack.yaml diff --git a/llvm/test/tools/llvm-remarkutil/size-diff/no-difference.test b/llvm/test/tools/llvm-remarkutil/size-diff/no-difference.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-remarkutil/size-diff/no-difference.test @@ -0,0 +1,7 @@ +RUN: llvm-remarkutil size-diff %p/Inputs/1-func-1-instr-1-stack.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml | FileCheck -strict-whitespace %s + +; Same file passed twice -> no changes reported. + +; CHECK-NOT: {{[0-9]+}} +; CHECK: instruction count: None +; CHECK: stack byte usage: None diff --git a/llvm/test/tools/llvm-remarkutil/size-diff/no-instruction-count-remarks.test b/llvm/test/tools/llvm-remarkutil/size-diff/no-instruction-count-remarks.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-remarkutil/size-diff/no-instruction-count-remarks.test @@ -0,0 +1,3 @@ +RUN: not llvm-remarkutil size-diff %p/Inputs/no-instruction-count-remarks.yaml %p/Inputs/no-instruction-count-remarks.yaml --parser=yaml 2>&1 | FileCheck %s + +; CHECK: error: File {{.*}} did not contain any instruction-count remarks! diff --git a/llvm/test/tools/llvm-remarkutil/size-diff/unexpected-key.test b/llvm/test/tools/llvm-remarkutil/size-diff/unexpected-key.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-remarkutil/size-diff/unexpected-key.test @@ -0,0 +1,3 @@ +RUN: not llvm-remarkutil size-diff %p/Inputs/unexpected-key.yaml %p/Inputs/1-func-1-instr-1-stack.yaml --parser=yaml 2>&1 | FileCheck %s + +; CHECK: Expected 'NumInstructions', got 'Wrong' diff --git a/llvm/tools/llvm-remark-size-diff/CMakeLists.txt b/llvm/tools/llvm-remark-size-diff/CMakeLists.txt deleted file mode 100644 --- a/llvm/tools/llvm-remark-size-diff/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -set(LLVM_LINK_COMPONENTS - Demangle - Remarks - Support - ) - -add_llvm_tool(llvm-remark-size-diff - RemarkSizeDiff.cpp - ) diff --git a/llvm/tools/llvm-remarkutil/CMakeLists.txt b/llvm/tools/llvm-remarkutil/CMakeLists.txt --- a/llvm/tools/llvm-remarkutil/CMakeLists.txt +++ b/llvm/tools/llvm-remarkutil/CMakeLists.txt @@ -7,6 +7,7 @@ add_llvm_tool(llvm-remarkutil RemarkConvert.cpp RemarkCount.cpp + RemarkSizeDiff.cpp RemarkUtil.cpp RemarkUtilHelpers.cpp RemarkUtilRegistry.cpp diff --git a/llvm/tools/llvm-remark-size-diff/RemarkSizeDiff.cpp b/llvm/tools/llvm-remarkutil/RemarkSizeDiff.cpp rename from llvm/tools/llvm-remark-size-diff/RemarkSizeDiff.cpp rename to llvm/tools/llvm-remarkutil/RemarkSizeDiff.cpp --- a/llvm/tools/llvm-remark-size-diff/RemarkSizeDiff.cpp +++ b/llvm/tools/llvm-remarkutil/RemarkSizeDiff.cpp @@ -1,4 +1,4 @@ -//===-------------- llvm-remark-size-diff/RemarkSizeDiff.cpp --------------===// +//===-------------- RemarkSizeDiff.cpp ------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -14,51 +14,38 @@ /// //===----------------------------------------------------------------------===// -#include "llvm-c/Remarks.h" -#include "llvm/ADT/STLExtras.h" +#include "RemarkUtilHelpers.h" +#include "RemarkUtilRegistry.h" #include "llvm/ADT/SmallSet.h" -#include "llvm/Remarks/Remark.h" -#include "llvm/Remarks/RemarkParser.h" -#include "llvm/Remarks/RemarkSerializer.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/Compiler.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" -#include "llvm/Support/InitLLVM.h" #include "llvm/Support/JSON.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/ToolOutputFile.h" -#include "llvm/Support/WithColor.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; - -enum ParserFormatOptions { yaml, bitstream }; +using namespace remarks; +using namespace remarkutil; +static cl::SubCommand + RemarkSizeDiffUtil("size-diff", + "Diff instruction count and stack size remarks " + "between two remark files"); enum ReportStyleOptions { human_output, json_output }; -static cl::OptionCategory SizeDiffCategory("llvm-remark-size-diff options"); static cl::opt InputFileNameA(cl::Positional, cl::Required, - cl::cat(SizeDiffCategory), + cl::sub(RemarkSizeDiffUtil), cl::desc("remarks_a")); static cl::opt InputFileNameB(cl::Positional, cl::Required, - cl::cat(SizeDiffCategory), + cl::sub(RemarkSizeDiffUtil), cl::desc("remarks_b")); static cl::opt OutputFilename("o", cl::init("-"), - cl::cat(SizeDiffCategory), + cl::sub(RemarkSizeDiffUtil), cl::desc("Output"), cl::value_desc("file")); -static cl::opt - ParserFormat("parser", cl::cat(SizeDiffCategory), cl::init(bitstream), - cl::desc("Set the remark parser format:"), - cl::values(clEnumVal(yaml, "YAML format"), - clEnumVal(bitstream, "Bitstream format"))); +INPUT_FORMAT_COMMAND_LINE_OPTIONS(RemarkSizeDiffUtil) static cl::opt ReportStyle( - "report_style", cl::cat(SizeDiffCategory), + "report_style", cl::sub(RemarkSizeDiffUtil), cl::init(ReportStyleOptions::human_output), cl::desc("Choose the report output format:"), cl::values(clEnumValN(human_output, "human", "Human-readable format"), clEnumValN(json_output, "json", "JSON format"))); -static cl::opt PrettyPrint("pretty", cl::cat(SizeDiffCategory), +static cl::opt PrettyPrint("pretty", cl::sub(RemarkSizeDiffUtil), cl::init(false), cl::desc("Pretty-print JSON")); @@ -300,14 +287,12 @@ static Error readFileAndProcessRemarks( StringRef InputFileName, StringMap &FuncNameToSizeInfo) { - auto Buf = MemoryBuffer::getFile(InputFileName); - if (auto EC = Buf.getError()) - return createStringError( - EC, Twine("Cannot open file '" + InputFileName + "': " + EC.message())); - auto MaybeParser = remarks::createRemarkParserFromMeta( - ParserFormat == bitstream ? remarks::Format::Bitstream - : remarks::Format::YAML, - (*Buf)->getBuffer()); + + auto MaybeBuf = getInputMemoryBuffer(InputFileName); + if (!MaybeBuf) + return MaybeBuf.takeError(); + auto MaybeParser = + createRemarkParserFromMeta(InputFormat, (*MaybeBuf)->getBuffer()); if (!MaybeParser) return MaybeParser.takeError(); auto &Parser = **MaybeParser; @@ -340,17 +325,13 @@ /// /// \returns true if readFileAndProcessRemarks returned no errors. False /// otherwise. -static bool tryReadFileAndProcessRemarks( +static Error tryReadFileAndProcessRemarks( StringRef InputFileName, StringMap &FuncNameToSizeInfo) { if (Error E = readFileAndProcessRemarks(InputFileName, FuncNameToSizeInfo)) { - handleAllErrors(std::move(E), [&](const ErrorInfoBase &PE) { - PE.log(WithColor::error()); - errs() << '\n'; - }); - return false; + return E; } - return true; + return Error::success(); } /// Populates \p FuncDiffs with the difference between \p @@ -489,33 +470,32 @@ } /// Boolean wrapper for outputDiff which handles errors. -static bool +static Error tryOutputAllDiffs(StringRef InputFileNameA, StringRef InputFileNameB, DiffsCategorizedByFilesPresent &DiffsByFilesPresent) { if (Error E = outputAllDiffs(InputFileNameA, InputFileNameB, DiffsByFilesPresent)) { - handleAllErrors(std::move(E), [&](const ErrorInfoBase &PE) { - PE.log(WithColor::error()); - errs() << '\n'; - }); - return false; + return E; } - return true; + return Error::success(); } -int main(int argc, const char **argv) { - InitLLVM X(argc, argv); - cl::HideUnrelatedOptions(SizeDiffCategory); - cl::ParseCommandLineOptions(argc, argv, - "Diff instruction count and stack size remarks " - "between two remark files.\n"); +static Error trySizeSiff() { StringMap FuncNameToSizeInfoA; StringMap FuncNameToSizeInfoB; - if (!tryReadFileAndProcessRemarks(InputFileNameA, FuncNameToSizeInfoA) || - !tryReadFileAndProcessRemarks(InputFileNameB, FuncNameToSizeInfoB)) - return 1; + if (auto E = + tryReadFileAndProcessRemarks(InputFileNameA, FuncNameToSizeInfoA)) + return E; + if (auto E = + tryReadFileAndProcessRemarks(InputFileNameB, FuncNameToSizeInfoB)) + return E; DiffsCategorizedByFilesPresent DiffsByFilesPresent; computeDiff(FuncNameToSizeInfoA, FuncNameToSizeInfoB, DiffsByFilesPresent); - if (!tryOutputAllDiffs(InputFileNameA, InputFileNameB, DiffsByFilesPresent)) - return 1; + if (auto E = tryOutputAllDiffs(InputFileNameA, InputFileNameB, + DiffsByFilesPresent)) + return E; + return Error::success(); } + +static CommandRegistration RemarkSizeSiffRegister(&RemarkSizeDiffUtil, + trySizeSiff); \ No newline at end of file diff --git a/llvm/utils/gn/secondary/llvm/test/BUILD.gn b/llvm/utils/gn/secondary/llvm/test/BUILD.gn --- a/llvm/utils/gn/secondary/llvm/test/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/test/BUILD.gn @@ -298,7 +298,6 @@ "//llvm/tools/llvm-rc:symlinks", "//llvm/tools/llvm-readobj:symlinks", "//llvm/tools/llvm-reduce", - "//llvm/tools/llvm-remark-size-diff", "//llvm/tools/llvm-remarkutil", "//llvm/tools/llvm-rtdyld", "//llvm/tools/llvm-sim", diff --git a/llvm/utils/gn/secondary/llvm/tools/llvm-remark-size-diff/BUILD.gn b/llvm/utils/gn/secondary/llvm/tools/llvm-remark-size-diff/BUILD.gn deleted file mode 100644 --- a/llvm/utils/gn/secondary/llvm/tools/llvm-remark-size-diff/BUILD.gn +++ /dev/null @@ -1,10 +0,0 @@ -executable("llvm-remark-size-diff") { - deps = [ - "//llvm/lib/Demangle", - "//llvm/lib/IR", - "//llvm/lib/Object", - "//llvm/lib/Remarks", - "//llvm/lib/Support", - ] - sources = [ "RemarkSizeDiff.cpp" ] -} diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel @@ -4443,24 +4443,6 @@ ], ) -cc_binary( - name = "llvm-remark-size-diff", - srcs = glob([ - "tools/llvm-remark-size-diff/**/*.cpp", - "tools/llvm-remark-size-diff/**/*.h", - ]), - copts = llvm_copts, - includes = ["tools/llvm-reark-size-diff"], - stamp = 0, - deps = [ - ":Core", - ":Demangle", - ":Object", - ":Remarks", - ":Support", - ], -) - cc_binary( name = "llvm-rtdyld", srcs = glob([