[RemarkUtil] Refactor llvm-remarkutil to include size-diff

This change follows from https://reviews.llvm.org/D156416 We include
`llvm-remark-size-diff` as a part of `llvm-remarkutil` under a
subcommand `size-diff`.

Differential Revision: https://reviews.llvm.org/D156515
This commit is contained in:
Zain Jaffal
2023-07-27 13:13:55 +01:00
parent 9a370a1e58
commit 24f320e48c
36 changed files with 302 additions and 369 deletions

View File

@@ -5869,11 +5869,6 @@ tree in terms of conformance to :doc:`ClangFormat` as of: March 06, 2022 17:32:2
- `39`
- `1`
- :part:`97%`
* - llvm/tools/llvm-remark-size-diff
- `1`
- `1`
- `0`
- :good:`100%`
* - llvm/tools/llvm-rtdyld
- `1`
- `0`

View File

@@ -7142,7 +7142,6 @@ llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
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

View File

@@ -96,5 +96,4 @@ Remarks Tools
.. toctree::
:maxdepth: 1
llvm-remark-size-diff
llvm-remarkutil

View File

@@ -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 <https://llvm.org/docs/Remarks.html>`_ 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 <https://llvm.org/docs/Remarks.html#yaml-remarks>`_ and
`bitstream <https://llvm.org/docs/Remarks.html#llvm-bitstream-remarks>`_
remarks.
OPTIONS
-------
.. option:: --parser=<yaml|bitstream>
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=<human|json>
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=<file>
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.

View File

@@ -21,6 +21,7 @@ Subcommands
* :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 @@ if `--use-debug-loc` is passed then the CSV will include the source path, line n
::
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 <https://llvm.org/docs/Remarks.html>`_ 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 <https://llvm.org/docs/Remarks.html#yaml-remarks>`_ and
`bitstream <https://llvm.org/docs/Remarks.html#llvm-bitstream-remarks>`_
remarks.
OPTIONS
-------
.. option:: --parser=<yaml|bitstream>
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=<human|json>
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=<file>
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.

View File

@@ -120,7 +120,6 @@ set(LLVM_TEST_DEPENDS
llvm-readobj
llvm-readelf
llvm-reduce
llvm-remark-size-diff
llvm-remarkutil
llvm-rtdyld
llvm-sim

View File

@@ -216,7 +216,6 @@ tools.extend(
"llvm-rc",
"llvm-readelf",
"llvm-readobj",
"llvm-remark-size-diff",
"llvm-rtdyld",
"llvm-sim",
"llvm-size",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,9 +0,0 @@
set(LLVM_LINK_COMPONENTS
Demangle
Remarks
Support
)
add_llvm_tool(llvm-remark-size-diff
RemarkSizeDiff.cpp
)

View File

@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(llvm-remarkutil
RemarkConvert.cpp
RemarkCount.cpp
RemarkSizeDiff.cpp
RemarkUtil.cpp
RemarkUtilHelpers.cpp
RemarkUtilRegistry.cpp

View File

@@ -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<std::string> InputFileNameA(cl::Positional, cl::Required,
cl::cat(SizeDiffCategory),
cl::sub(RemarkSizeDiffUtil),
cl::desc("remarks_a"));
static cl::opt<std::string> InputFileNameB(cl::Positional, cl::Required,
cl::cat(SizeDiffCategory),
cl::sub(RemarkSizeDiffUtil),
cl::desc("remarks_b"));
static cl::opt<std::string> OutputFilename("o", cl::init("-"),
cl::cat(SizeDiffCategory),
cl::sub(RemarkSizeDiffUtil),
cl::desc("Output"),
cl::value_desc("file"));
static cl::opt<ParserFormatOptions>
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<ReportStyleOptions> 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<bool> PrettyPrint("pretty", cl::cat(SizeDiffCategory),
static cl::opt<bool> PrettyPrint("pretty", cl::sub(RemarkSizeDiffUtil),
cl::init(false),
cl::desc("Pretty-print JSON"));
@@ -300,14 +287,12 @@ static Error processRemark(const remarks::Remark &Remark,
static Error readFileAndProcessRemarks(
StringRef InputFileName,
StringMap<InstCountAndStackSize> &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 @@ static Error readFileAndProcessRemarks(
///
/// \returns true if readFileAndProcessRemarks returned no errors. False
/// otherwise.
static bool tryReadFileAndProcessRemarks(
static Error tryReadFileAndProcessRemarks(
StringRef InputFileName,
StringMap<InstCountAndStackSize> &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 @@ outputAllDiffs(StringRef InputFileNameA, StringRef InputFileNameB,
}
/// 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<InstCountAndStackSize> FuncNameToSizeInfoA;
StringMap<InstCountAndStackSize> 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);

View File

@@ -299,7 +299,6 @@ group("test") {
"//llvm/tools/llvm-readobj:symlinks",
"//llvm/tools/llvm-readtapi",
"//llvm/tools/llvm-reduce",
"//llvm/tools/llvm-remark-size-diff",
"//llvm/tools/llvm-remarkutil",
"//llvm/tools/llvm-rtdyld",
"//llvm/tools/llvm-sim",

View File

@@ -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" ]
}

View File

@@ -4461,24 +4461,6 @@ cc_binary(
],
)
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([