From ddc5a010a40a7b85a020a072f9f6b4ae132e94bd Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 17 Feb 2014 23:22:49 +0000 Subject: [PATCH] PGO: llvm-profdata: tool for merging profiles Introducing llvm-profdata, a tool for merging profile data generated by PGO instrumentation in clang. - The name indicates a file extension of .profdata. Eventually profile data output by clang should be changed to that extension. - llvm-profdata merges two profiles. However, the name is more general, since it will likely pick up more tasks (such as summarizing a single profile). - llvm-profdata parses the current text-based format, but will be updated once we settle on a binary format. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201535 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/CommandGuide/index.rst | 1 + docs/CommandGuide/llvm-profdata.rst | 29 +++ test/CMakeLists.txt | 1 + test/lit.cfg | 1 + .../Inputs/bad-function-count.profdata | 2 + .../llvm-profdata/Inputs/bar3-1.profdata | 4 + .../tools/llvm-profdata/Inputs/empty.profdata | 0 .../llvm-profdata/Inputs/extra-word.profdata | 2 + .../llvm-profdata/Inputs/foo3-1.profdata | 4 + .../llvm-profdata/Inputs/foo3-2.profdata | 4 + .../llvm-profdata/Inputs/foo3bar3-1.profdata | 9 + .../llvm-profdata/Inputs/foo3bar3-2.profdata | 9 + .../llvm-profdata/Inputs/foo4-1.profdata | 5 + .../llvm-profdata/Inputs/foo4-2.profdata | 5 + .../Inputs/invalid-count-later.profdata | 2 + .../llvm-profdata/Inputs/overflow.profdata | 2 + .../Inputs/three-words-long.profdata | 1 + test/tools/llvm-profdata/errors.test | 22 +++ test/tools/llvm-profdata/simple.test | 25 +++ tools/CMakeLists.txt | 1 + tools/LLVMBuild.txt | 2 +- tools/Makefile | 2 +- tools/llvm-profdata/CMakeLists.txt | 5 + tools/llvm-profdata/LLVMBuild.txt | 22 +++ tools/llvm-profdata/Makefile | 17 ++ tools/llvm-profdata/llvm-profdata.cpp | 178 ++++++++++++++++++ 26 files changed, 353 insertions(+), 2 deletions(-) create mode 100644 docs/CommandGuide/llvm-profdata.rst create mode 100644 test/tools/llvm-profdata/Inputs/bad-function-count.profdata create mode 100644 test/tools/llvm-profdata/Inputs/bar3-1.profdata create mode 100644 test/tools/llvm-profdata/Inputs/empty.profdata create mode 100644 test/tools/llvm-profdata/Inputs/extra-word.profdata create mode 100644 test/tools/llvm-profdata/Inputs/foo3-1.profdata create mode 100644 test/tools/llvm-profdata/Inputs/foo3-2.profdata create mode 100644 test/tools/llvm-profdata/Inputs/foo3bar3-1.profdata create mode 100644 test/tools/llvm-profdata/Inputs/foo3bar3-2.profdata create mode 100644 test/tools/llvm-profdata/Inputs/foo4-1.profdata create mode 100644 test/tools/llvm-profdata/Inputs/foo4-2.profdata create mode 100644 test/tools/llvm-profdata/Inputs/invalid-count-later.profdata create mode 100644 test/tools/llvm-profdata/Inputs/overflow.profdata create mode 100644 test/tools/llvm-profdata/Inputs/three-words-long.profdata create mode 100644 test/tools/llvm-profdata/errors.test create mode 100644 test/tools/llvm-profdata/simple.test create mode 100644 tools/llvm-profdata/CMakeLists.txt create mode 100644 tools/llvm-profdata/LLVMBuild.txt create mode 100644 tools/llvm-profdata/Makefile create mode 100644 tools/llvm-profdata/llvm-profdata.cpp diff --git a/docs/CommandGuide/index.rst b/docs/CommandGuide/index.rst index d799941aeae..ab4788aee7f 100644 --- a/docs/CommandGuide/index.rst +++ b/docs/CommandGuide/index.rst @@ -25,6 +25,7 @@ Basic Commands llvm-config llvm-diff llvm-cov + llvm-profdata llvm-stress llvm-symbolizer diff --git a/docs/CommandGuide/llvm-profdata.rst b/docs/CommandGuide/llvm-profdata.rst new file mode 100644 index 00000000000..6b8e4d7ed5b --- /dev/null +++ b/docs/CommandGuide/llvm-profdata.rst @@ -0,0 +1,29 @@ +llvm-profdata - work with profile data +====================================== + +SYNOPSIS +-------- + +:program:`llvm-profdata` [-output=output] file1 file2 + +DESCRIPTION +----------- + +The experimental :program:`llvm-profdata` tool reads two profile data files +generated by PGO instrumentation and generates a file with merged data. + +The profile data format itself is currently textual. + +OPTIONS +------- + +.. option:: -output=output + + This option selects the output filename. If not specified, output is to + stdout. + +EXIT STATUS +----------- + +:program:`llvm-profdata` returns 1 if it cannot read input files or there is a +mismatch between their data. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 835579c8f6b..d26d0f3a1ab 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,6 +37,7 @@ set(LLVM_TEST_DEPENDS llvm-mcmarkup llvm-nm llvm-objdump + llvm-profdata llvm-readobj llvm-rtdyld llvm-symbolizer diff --git a/test/lit.cfg b/test/lit.cfg index 962728d0cb4..ac8d4497f09 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -234,6 +234,7 @@ for pattern in [r"\bbugpoint\b(?!-)", r"\bllvm-mcmarkup\b", r"\bllvm-nm\b", r"\bllvm-objdump\b", + r"\bllvm-profdata\b", r"\bllvm-ranlib\b", r"\bllvm-readobj\b", r"\bllvm-rtdyld\b", diff --git a/test/tools/llvm-profdata/Inputs/bad-function-count.profdata b/test/tools/llvm-profdata/Inputs/bad-function-count.profdata new file mode 100644 index 00000000000..7d247626e5a --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/bad-function-count.profdata @@ -0,0 +1,2 @@ +function_count_not 1count +1 diff --git a/test/tools/llvm-profdata/Inputs/bar3-1.profdata b/test/tools/llvm-profdata/Inputs/bar3-1.profdata new file mode 100644 index 00000000000..cb8b409891a --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/bar3-1.profdata @@ -0,0 +1,4 @@ +bar 3 +1 +2 +3 diff --git a/test/tools/llvm-profdata/Inputs/empty.profdata b/test/tools/llvm-profdata/Inputs/empty.profdata new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/tools/llvm-profdata/Inputs/extra-word.profdata b/test/tools/llvm-profdata/Inputs/extra-word.profdata new file mode 100644 index 00000000000..67a662909cf --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/extra-word.profdata @@ -0,0 +1,2 @@ +extra 1 word +1 diff --git a/test/tools/llvm-profdata/Inputs/foo3-1.profdata b/test/tools/llvm-profdata/Inputs/foo3-1.profdata new file mode 100644 index 00000000000..d6f9f648b7b --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/foo3-1.profdata @@ -0,0 +1,4 @@ +foo 3 +1 +2 +3 diff --git a/test/tools/llvm-profdata/Inputs/foo3-2.profdata b/test/tools/llvm-profdata/Inputs/foo3-2.profdata new file mode 100644 index 00000000000..94fd0343915 --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/foo3-2.profdata @@ -0,0 +1,4 @@ +foo 3 +7 +5 +3 diff --git a/test/tools/llvm-profdata/Inputs/foo3bar3-1.profdata b/test/tools/llvm-profdata/Inputs/foo3bar3-1.profdata new file mode 100644 index 00000000000..85b702d4977 --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/foo3bar3-1.profdata @@ -0,0 +1,9 @@ +foo 3 +2 +3 +5 + +bar 3 +7 +11 +13 diff --git a/test/tools/llvm-profdata/Inputs/foo3bar3-2.profdata b/test/tools/llvm-profdata/Inputs/foo3bar3-2.profdata new file mode 100644 index 00000000000..d652781a35c --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/foo3bar3-2.profdata @@ -0,0 +1,9 @@ +foo 3 +17 +19 +23 + +bar 3 +29 +31 +37 diff --git a/test/tools/llvm-profdata/Inputs/foo4-1.profdata b/test/tools/llvm-profdata/Inputs/foo4-1.profdata new file mode 100644 index 00000000000..4d694080bff --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/foo4-1.profdata @@ -0,0 +1,5 @@ +foo 4 +11 +22 +33 +44 diff --git a/test/tools/llvm-profdata/Inputs/foo4-2.profdata b/test/tools/llvm-profdata/Inputs/foo4-2.profdata new file mode 100644 index 00000000000..8d91d8bbef0 --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/foo4-2.profdata @@ -0,0 +1,5 @@ +foo 4 +7 +6 +5 +4 diff --git a/test/tools/llvm-profdata/Inputs/invalid-count-later.profdata b/test/tools/llvm-profdata/Inputs/invalid-count-later.profdata new file mode 100644 index 00000000000..5575df3fda6 --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/invalid-count-later.profdata @@ -0,0 +1,2 @@ +invalid_count 1 +1later diff --git a/test/tools/llvm-profdata/Inputs/overflow.profdata b/test/tools/llvm-profdata/Inputs/overflow.profdata new file mode 100644 index 00000000000..bfb9a52d2ec --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/overflow.profdata @@ -0,0 +1,2 @@ +overflow 1 +9223372036854775808 diff --git a/test/tools/llvm-profdata/Inputs/three-words-long.profdata b/test/tools/llvm-profdata/Inputs/three-words-long.profdata new file mode 100644 index 00000000000..a4d45fb3bfa --- /dev/null +++ b/test/tools/llvm-profdata/Inputs/three-words-long.profdata @@ -0,0 +1 @@ +three words long diff --git a/test/tools/llvm-profdata/errors.test b/test/tools/llvm-profdata/errors.test new file mode 100644 index 00000000000..6335ea95f9e --- /dev/null +++ b/test/tools/llvm-profdata/errors.test @@ -0,0 +1,22 @@ +RUN: not llvm-profdata %p/Inputs/empty.profdata %p/Inputs/foo3-1.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH +RUN: not llvm-profdata %p/Inputs/foo3-1.profdata %p/Inputs/foo3bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH +RUN: not llvm-profdata %p/Inputs/foo4-1.profdata %p/Inputs/empty.profdata 2>&1 | FileCheck %s --check-prefix=LENGTH +LENGTH: error: {{.*}}: truncated file + +RUN: not llvm-profdata %p/Inputs/foo3-1.profdata %p/Inputs/bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=NAME +NAME: error: {{.*}}: function name mismatch + +RUN: not llvm-profdata %p/Inputs/foo3-1.profdata %p/Inputs/foo4-1.profdata 2>&1 | FileCheck %s --check-prefix=COUNT +COUNT: error: {{.*}}: function count mismatch + +RUN: not llvm-profdata %p/Inputs/overflow.profdata %p/Inputs/overflow.profdata 2>&1 | FileCheck %s --check-prefix=OVERFLOW +OVERFLOW: error: {{.*}}: counter overflow + +RUN: not llvm-profdata %p/Inputs/invalid-count-later.profdata %p/Inputs/invalid-count-later.profdata 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER +INVALID-COUNT-LATER: error: {{.*}}: invalid counter + +RUN: not llvm-profdata %p/Inputs/bad-function-count.profdata %p/Inputs/bad-function-count.profdata 2>&1 | FileCheck %s --check-prefix=BAD-FUNCTION-COUNT +BAD-FUNCTION-COUNT: error: {{.*}}: bad function count + +RUN: not llvm-profdata %p/Inputs/three-words-long.profdata %p/Inputs/three-words-long.profdata 2>&1 | FileCheck %s --check-prefix=INVALID-DATA +INVALID-DATA: error: {{.*}}: invalid data diff --git a/test/tools/llvm-profdata/simple.test b/test/tools/llvm-profdata/simple.test new file mode 100644 index 00000000000..87073fad9cf --- /dev/null +++ b/test/tools/llvm-profdata/simple.test @@ -0,0 +1,25 @@ +RUN: llvm-profdata %p/Inputs/foo3-1.profdata %p/Inputs/foo3-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO3 +RUN: llvm-profdata %p/Inputs/foo3-2.profdata %p/Inputs/foo3-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO3 +FOO3: {{^foo 3$}} +FOO3-NEXT: {{^8$}} +FOO3-NEXT: {{^7$}} +FOO3-NEXT: {{^6$}} + +RUN: llvm-profdata %p/Inputs/foo4-1.profdata %p/Inputs/foo4-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO4 +RUN: llvm-profdata %p/Inputs/foo4-2.profdata %p/Inputs/foo4-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO4 +FOO4: {{^foo 4$}} +FOO4-NEXT: {{^18$}} +FOO4-NEXT: {{^28$}} +FOO4-NEXT: {{^38$}} +FOO4-NEXT: {{^48$}} + +RUN: llvm-profdata %p/Inputs/foo3bar3-1.profdata %p/Inputs/foo3bar3-2.profdata 2>&1 | FileCheck %s --check-prefix=FOO3BAR3 +RUN: llvm-profdata %p/Inputs/foo3bar3-2.profdata %p/Inputs/foo3bar3-1.profdata 2>&1 | FileCheck %s --check-prefix=FOO3BAR3 +FOO3BAR3: {{^foo 3$}} +FOO3BAR3-NEXT: {{^19$}} +FOO3BAR3-NEXT: {{^22$}} +FOO3BAR3-NEXT: {{^28$}} +FOO3BAR3: {{^bar 3$}} +FOO3BAR3-NEXT: {{^36$}} +FOO3BAR3-NEXT: {{^42$}} +FOO3BAR3-NEXT: {{^50$}} diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 12e10fd0bbd..5f006594c52 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -15,6 +15,7 @@ add_llvm_tool_subdirectory(llvm-nm) add_llvm_tool_subdirectory(llvm-size) add_llvm_tool_subdirectory(llvm-cov) +add_llvm_tool_subdirectory(llvm-profdata) add_llvm_tool_subdirectory(llvm-link) add_llvm_tool_subdirectory(lli) diff --git a/tools/LLVMBuild.txt b/tools/LLVMBuild.txt index 93b8d98dcba..1b537a372da 100644 --- a/tools/LLVMBuild.txt +++ b/tools/LLVMBuild.txt @@ -16,7 +16,7 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = bugpoint llc lli llvm-ar llvm-as llvm-bcanalyzer llvm-cov llvm-diff llvm-dis llvm-dwarfdump llvm-extract llvm-jitlistener llvm-link llvm-lto llvm-mc llvm-nm llvm-objdump llvm-rtdyld llvm-size macho-dump opt llvm-mcmarkup +subdirectories = bugpoint llc lli llvm-ar llvm-as llvm-bcanalyzer llvm-cov llvm-diff llvm-dis llvm-dwarfdump llvm-extract llvm-jitlistener llvm-link llvm-lto llvm-mc llvm-nm llvm-objdump llvm-profdata llvm-rtdyld llvm-size macho-dump opt llvm-mcmarkup [component_0] type = Group diff --git a/tools/Makefile b/tools/Makefile index be872548e31..2b8c32ee32a 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -31,7 +31,7 @@ PARALLEL_DIRS := opt llvm-as llvm-dis llc llvm-ar llvm-nm llvm-link \ lli llvm-extract llvm-mc bugpoint llvm-bcanalyzer llvm-diff \ macho-dump llvm-objdump llvm-readobj llvm-rtdyld \ llvm-dwarfdump llvm-cov llvm-size llvm-stress llvm-mcmarkup \ - llvm-symbolizer obj2yaml yaml2obj llvm-c-test + llvm-profdata llvm-symbolizer obj2yaml yaml2obj llvm-c-test # If Intel JIT Events support is configured, build an extra tool to test it. ifeq ($(USE_INTEL_JITEVENTS), 1) diff --git a/tools/llvm-profdata/CMakeLists.txt b/tools/llvm-profdata/CMakeLists.txt new file mode 100644 index 00000000000..4b1357d87e1 --- /dev/null +++ b/tools/llvm-profdata/CMakeLists.txt @@ -0,0 +1,5 @@ +set(LLVM_LINK_COMPONENTS core support ) + +add_llvm_tool(llvm-profdata + llvm-profdata.cpp + ) diff --git a/tools/llvm-profdata/LLVMBuild.txt b/tools/llvm-profdata/LLVMBuild.txt new file mode 100644 index 00000000000..fc9e4691997 --- /dev/null +++ b/tools/llvm-profdata/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-profdata/LLVMBuild.txt ----------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-profdata +parent = Tools +required_libraries = Support diff --git a/tools/llvm-profdata/Makefile b/tools/llvm-profdata/Makefile new file mode 100644 index 00000000000..9d7ad527b16 --- /dev/null +++ b/tools/llvm-profdata/Makefile @@ -0,0 +1,17 @@ +##===- tools/llvm-profdata/Makefile ------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL := ../.. +TOOLNAME := llvm-profdata +LINK_COMPONENTS := core support + +# This tool has no plugins, optimize startup time. +TOOL_NO_EXPORTS := 1 + +include $(LEVEL)/Makefile.common diff --git a/tools/llvm-profdata/llvm-profdata.cpp b/tools/llvm-profdata/llvm-profdata.cpp new file mode 100644 index 00000000000..df10356eeff --- /dev/null +++ b/tools/llvm-profdata/llvm-profdata.cpp @@ -0,0 +1,178 @@ +//===- llvm-profdata.cpp - LLVM profile data tool -------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// llvm-profdata merges .profdata files. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Signals.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +static cl::opt Filename1(cl::Positional, cl::Required, + cl::desc("file1")); +static cl::opt Filename2(cl::Positional, cl::Required, + cl::desc("file2")); + +static cl::opt OutputFilename("output", cl::value_desc("output"), + cl::init("-"), + cl::desc("Output file")); +static cl::alias OutputFilenameA("o", cl::desc("Alias for --output"), + cl::aliasopt(OutputFilename)); + +static bool readLine(const char *&Start, const char *End, StringRef &S) { + if (Start == End) + return false; + + for (const char *I = Start; I != End; ++I) { + assert(*I && "unexpected binary data"); + if (*I == '\n') { + S = StringRef(Start, I - Start); + Start = I + 1; + return true; + } + } + + S = StringRef(Start, End - Start); + Start = End; + return true; +} + +static StringRef getWord(const char *&Start, const char *End) { + for (const char *I = Start; I != End; ++I) + if (*I == ' ') { + StringRef S(Start, I - Start); + Start = I + 1; + return S; + } + StringRef S(Start, End - Start); + Start = End; + return S; +} + +static size_t splitWords(const StringRef &Line, std::vector &Words) { + const char *Start = Line.data(); + const char *End = Line.data() + Line.size(); + Words.clear(); + while (Start != End) + Words.push_back(getWord(Start, End)); + return Words.size(); +} + +static bool getNumber(const StringRef &S, uint64_t &N) { + N = 0; + for (StringRef::iterator I = S.begin(), E = S.end(); I != E; ++I) + if (*I >= '0' && *I <= '9') + N = N * 10 + (*I - '0'); + else + return false; + + return true; +} + +static void exitWithError(const std::string &Message, + const std::string &Filename, int64_t Line = -1) { + errs() << "error: " << Filename; + if (Line >= 0) + errs() << ":" << Line; + errs() << ": " << Message << "\n"; + ::exit(1); +} + +//===----------------------------------------------------------------------===// +int main(int argc, char **argv) { + // Print a stack trace if we signal out. + sys::PrintStackTraceOnErrorSignal(); + PrettyStackTraceProgram X(argc, argv); + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + + cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n"); + + OwningPtr File1; + OwningPtr File2; + if (error_code ec = MemoryBuffer::getFile(Filename1, File1)) + exitWithError(ec.message(), Filename1); + if (error_code ec = MemoryBuffer::getFile(Filename2, File2)) + exitWithError(ec.message(), Filename2); + + if (OutputFilename.empty()) + OutputFilename = "-"; + + std::string ErrorInfo; + raw_fd_ostream Output(OutputFilename.data(), ErrorInfo); + if (!ErrorInfo.empty()) + exitWithError(ErrorInfo, OutputFilename); + + const char *Start1 = File1->getBufferStart(); + const char *Start2 = File2->getBufferStart(); + const char *End1 = File1->getBufferEnd(); + const char *End2 = File2->getBufferEnd(); + const char *P1 = Start1; + const char *P2 = Start2; + + StringRef Line1, Line2; + int64_t Num = 0; + while (readLine(P1, End1, Line1)) { + ++Num; + if (!readLine(P2, End2, Line2)) + exitWithError("truncated file", Filename2, Num); + + std::vector Words1, Words2; + if (splitWords(Line1, Words1) != splitWords(Line2, Words2)) + exitWithError("data mismatch", Filename2, Num); + + if (Words1.size() > 2) + exitWithError("invalid data", Filename1, Num); + + if (Words1.empty()) { + Output << "\n"; + continue; + } + + if (Words1.size() == 2) { + if (Words1[0] != Words2[0]) + exitWithError("function name mismatch", Filename2, Num); + + uint64_t N1, N2; + if (!getNumber(Words1[1], N1)) + exitWithError("bad function count", Filename1, Num); + if (!getNumber(Words2[1], N2)) + exitWithError("bad function count", Filename2, Num); + + if (N1 != N2) + exitWithError("function count mismatch", Filename2, Num); + + Output << Line1 << "\n"; + continue; + } + + uint64_t N1, N2; + if (!getNumber(Words1[0], N1)) + exitWithError("invalid counter", Filename1, Num); + if (!getNumber(Words2[0], N2)) + exitWithError("invalid counter", Filename2, Num); + + uint64_t Sum = N1 + N2; + if (Sum < N1) + exitWithError("counter overflow", Filename2, Num); + + Output << N1 + N2 << "\n"; + } + if (readLine(P2, End2, Line2)) + exitWithError("truncated file", Filename1, Num + 1); + + return 0; +} -- 2.34.1