[llvm-branch-commits] [clang] [llvm] Backport some fixes for building the release binaries (PR #91095)

2024-05-04 Thread Aiden Grossman via llvm-branch-commits


@@ -2,7 +2,7 @@
 
 __author__ = "Daniel Dunbar"
 __email__ = "dan...@minormatter.com"
-__versioninfo__ = (18, 1, 5)
+__versioninfo__ = (18, 1, 6)

boomanaiden154 wrote:

Ditto here?

https://github.com/llvm/llvm-project/pull/91095
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Backport some fixes for building the release binaries (PR #91095)

2024-05-04 Thread Aiden Grossman via llvm-branch-commits


@@ -22,7 +22,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
   set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
-  set(LLVM_VERSION_PATCH 5)
+  set(LLVM_VERSION_PATCH 6)

boomanaiden154 wrote:

Is this supposed to be included in this PR?

https://github.com/llvm/llvm-project/pull/91095
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Backport some fixes for building the release binaries (PR #91095)

2024-05-04 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 edited 
https://github.com/llvm/llvm-project/pull/91095
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Backport some fixes for building the release binaries (PR #91095)

2024-05-04 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 approved this pull request.

Seems reasonable enough to me.

https://github.com/llvm/llvm-project/pull/91095
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [workflows] Fix libclang-abi-tests to work with new version scheme (PR #91096)

2024-05-04 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 commented:

Given this only runs on the release branches, this patch should probably land 
in `main` as well?

https://github.com/llvm/llvm-project/pull/91096
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: github-upload-release.py: Fix bug preventing release creation (#84571) (PR #88425)

2024-04-12 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/88425
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [workflows] Fix permissions check for creating new releases (#81163) (PR #82453)

2024-02-20 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/82453
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Use container on Linux to run llvm-project-tests workflow (#81349) (PR #81807)

2024-02-14 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/81807
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] PR for llvm/llvm-project#80348 (PR #80585)

2024-02-04 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 commented:

This is incorrectly formatted (sorry for not catching that in my initial 
review).

It should be the following:
```yaml
on:
  pull_request_target:
branches:
  - main
```

I pushed a fixup to main 4b34558f43121df9b863ff2492f74fb2e65a5af1.

https://github.com/llvm/llvm-project/pull/80585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] PR for llvm/llvm-project#80580 (PR #80584)

2024-02-03 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/80584
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [clang] PR for llvm/llvm-project#80565 (PR #80566)

2024-02-03 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 approved this pull request.

LGTM! Will be nice to have this available in the release branch for the release 
builds and the CI container.

https://github.com/llvm/llvm-project/pull/80566
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [MLGO] Remove absl dependency from scripts (PR #78880)

2024-01-20 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/78880

>From 9dfc0ac712315f232e69496b7f8c0aed20421626 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 21 Jan 2024 06:08:28 +
Subject: [PATCH 1/2] [MLGO] Remove absl dependency from scripts

This patch removes the absl dependency from the mlgo-utils scripts. We
were only using absl.logging, and absl.flags, so this patch just
consists of mechanically converting the absl flags parsing to Python's
builtin argparse as Python's logging is a drop in replacement for
absl.logging.
---
 .../mlgo/corpus/combine_training_corpus.py|  27 +--
 .../mlgo-utils/mlgo/corpus/extract_ir.py  | 204 +-
 .../mlgo-utils/mlgo/corpus/make_corpus.py |  45 ++--
 3 files changed, 137 insertions(+), 139 deletions(-)

diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py 
b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
index 9aabd87b4688e0..cc21061cbbef5e 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
@@ -23,26 +23,21 @@
 and corpus2 are combined into combinedcorpus.
 """
 
-from absl import app
-from absl import flags
+import argparse
 
 from mlgo.corpus import combine_training_corpus_lib
 
-flags.DEFINE_string("root_dir", "", "root dir of module paths to combine.")
 
-FLAGS = flags.FLAGS
-
-
-def main(argv):
-if len(argv) > 1:
-raise app.UsageError("Too many command-line arguments.")
-
-combine_training_corpus_lib.combine_corpus(FLAGS.root_dir)
-
-
-def entrypoint():
-app.run(main)
+def main(args):
+combine_training_corpus_lib.combine_corpus(args.root_dir)
 
 
 if __name__ == "__main__":
-entrypoint()
+parser = argparse.ArgumentParser(
+description="A tool for combining multiple training corpora"
+)
+parser.add_argument(
+"--root_dir", type=str, help="The root dir of module paths to combine."
+)
+args = parser.parse_args()
+main(args)
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py 
b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
index 9463e61dc534fe..4426463e22b0e7 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
@@ -26,127 +26,59 @@
 
 import json
 import multiprocessing
-
-from absl import app
-from absl import flags
-from absl import logging
+import logging
+import argparse
 
 from mlgo.corpus import extract_ir_lib
 
-flags.DEFINE_string(
-"input",
-None,
-"Input file or directory - either compile_commands.json, a linker 
parameter"
-"list, or a path to a directory containing object files.",
-)
-flags.DEFINE_enum(
-"input_type",
-"json",
-["json", "params", "directory"],
-"Input file type - json, params, or directory. params latter refers to lld"
-"params.",
-)
-flags.DEFINE_string("output_dir", None, "Output directory")
-flags.DEFINE_integer(
-"num_workers",
-None,
-"Number of parallel workers for objcopy. `None` for maximum available.",
-)
-flags.DEFINE_string("llvm_objcopy_path", "llvm-objcopy", "Path to 
llvm-objcopy")
-flags.DEFINE_string(
-"obj_base_dir",
-"",
-"Base directory for object files. Defaults to current working dir.",
-)
-flags.DEFINE_string(
-"cmd_filter",
-None,
-"Include only those modules with a command line matching this regexp. "
-"Setting it to None for not filtering. Note that the regexp is applied "
-"independently for each separate command line option. For example, ^-Oz$ "
-"will match Oz - built binaries. Does not work with thinlto_build=lld.",
-)
-flags.DEFINE_enum(
-"thinlto_build",
-None,
-["distributed", "local"],
-"Set if the build was performed with either 'distributed' or "
-"'local' ThinLTO. This ensures the thinlto.bc files are also copied. "
-"The build is assumed to have had "
-"-mllvm -lto-embed-bitcode=post-merge-pre-opt passed in the distributed "
-"case, or -Wl,--save-temps=import and -Wl,--thinlto-emit-index-files "
-"passed in the local case.",
-)
-flags.DEFINE_string(
-"cmd_section_name",
-".llvmcmd",
-"The section name passed to llvm-objcopy. For ELF object files, the "
-"default .llvmcmd is correct. For Mach-O object files, one should use "
-"something like __LLVM,__cmdline",
-)
-flags.DEFINE_string(
-"bitcode_section_name",
-".llvmbc",
-"The section name passed to llvm-objcopy. For ELF object files, the "
-"default .llvmbc is correct. For Mach-O object files, one should use "
-"__LLVM,__bitcode",
-)
-
-flags.mark_flag_as_required("output_dir")
-
-FLAGS = flags.FLAGS
-
-
-def main(argv):
-if len(argv) > 1:
-raise app.UsageError("Too many command-line arguments.")
 
+def main(args):
 objs = []
-if FLAGS.input is not None and FLAGS.thinlto_build == "local":
+if args.input is not None and args.thinlto_build 

[llvm-branch-commits] [llvm] [MLGO] Remove absl dependency from scripts (PR #78880)

2024-01-20 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/78880

This patch removes the absl dependency from the mlgo-utils scripts. We were 
only using absl.logging, and absl.flags, so this patch just consists of 
mechanically converting the absl flags parsing to Python's builtin argparse as 
Python's logging is a drop in replacement for absl.logging.

>From 9dfc0ac712315f232e69496b7f8c0aed20421626 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 21 Jan 2024 06:08:28 +
Subject: [PATCH] [MLGO] Remove absl dependency from scripts

This patch removes the absl dependency from the mlgo-utils scripts. We
were only using absl.logging, and absl.flags, so this patch just
consists of mechanically converting the absl flags parsing to Python's
builtin argparse as Python's logging is a drop in replacement for
absl.logging.
---
 .../mlgo/corpus/combine_training_corpus.py|  27 +--
 .../mlgo-utils/mlgo/corpus/extract_ir.py  | 204 +-
 .../mlgo-utils/mlgo/corpus/make_corpus.py |  45 ++--
 3 files changed, 137 insertions(+), 139 deletions(-)

diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py 
b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
index 9aabd87b4688e0..cc21061cbbef5e 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
@@ -23,26 +23,21 @@
 and corpus2 are combined into combinedcorpus.
 """
 
-from absl import app
-from absl import flags
+import argparse
 
 from mlgo.corpus import combine_training_corpus_lib
 
-flags.DEFINE_string("root_dir", "", "root dir of module paths to combine.")
 
-FLAGS = flags.FLAGS
-
-
-def main(argv):
-if len(argv) > 1:
-raise app.UsageError("Too many command-line arguments.")
-
-combine_training_corpus_lib.combine_corpus(FLAGS.root_dir)
-
-
-def entrypoint():
-app.run(main)
+def main(args):
+combine_training_corpus_lib.combine_corpus(args.root_dir)
 
 
 if __name__ == "__main__":
-entrypoint()
+parser = argparse.ArgumentParser(
+description="A tool for combining multiple training corpora"
+)
+parser.add_argument(
+"--root_dir", type=str, help="The root dir of module paths to combine."
+)
+args = parser.parse_args()
+main(args)
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py 
b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
index 9463e61dc534fe..4426463e22b0e7 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
@@ -26,127 +26,59 @@
 
 import json
 import multiprocessing
-
-from absl import app
-from absl import flags
-from absl import logging
+import logging
+import argparse
 
 from mlgo.corpus import extract_ir_lib
 
-flags.DEFINE_string(
-"input",
-None,
-"Input file or directory - either compile_commands.json, a linker 
parameter"
-"list, or a path to a directory containing object files.",
-)
-flags.DEFINE_enum(
-"input_type",
-"json",
-["json", "params", "directory"],
-"Input file type - json, params, or directory. params latter refers to lld"
-"params.",
-)
-flags.DEFINE_string("output_dir", None, "Output directory")
-flags.DEFINE_integer(
-"num_workers",
-None,
-"Number of parallel workers for objcopy. `None` for maximum available.",
-)
-flags.DEFINE_string("llvm_objcopy_path", "llvm-objcopy", "Path to 
llvm-objcopy")
-flags.DEFINE_string(
-"obj_base_dir",
-"",
-"Base directory for object files. Defaults to current working dir.",
-)
-flags.DEFINE_string(
-"cmd_filter",
-None,
-"Include only those modules with a command line matching this regexp. "
-"Setting it to None for not filtering. Note that the regexp is applied "
-"independently for each separate command line option. For example, ^-Oz$ "
-"will match Oz - built binaries. Does not work with thinlto_build=lld.",
-)
-flags.DEFINE_enum(
-"thinlto_build",
-None,
-["distributed", "local"],
-"Set if the build was performed with either 'distributed' or "
-"'local' ThinLTO. This ensures the thinlto.bc files are also copied. "
-"The build is assumed to have had "
-"-mllvm -lto-embed-bitcode=post-merge-pre-opt passed in the distributed "
-"case, or -Wl,--save-temps=import and -Wl,--thinlto-emit-index-files "
-"passed in the local case.",
-)
-flags.DEFINE_string(
-"cmd_section_name",
-".llvmcmd",
-"The section name passed to llvm-objcopy. For ELF object files, the "
-"default .llvmcmd is correct. For Mach-O object files, one should use "
-"something like __LLVM,__cmdline",
-)
-flags.DEFINE_string(
-"bitcode_section_name",
-".llvmbc",
-"The section name passed to llvm-objcopy. For ELF object files, the "
-"default .llvmbc is correct. For Mach-O object files, one should use "
-"__LLVM,__bitcode",
-)
-
-flags.mark_flag_as_required("output_dir")
-

[llvm-branch-commits] [llvm] [clang-tools-extra] [libc] [lld] [lldb] [clang] [libcxx] [libcxxabi] [flang] [compiler-rt] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits

boomanaiden154 wrote:

@legrosbuffle I saw you approved the two prerequisite PRs. Do you have any 
additional comments on this one?

https://github.com/llvm/llvm-project/pull/76653
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [lldb] [clang-tools-extra] [llvm] [compiler-rt] [libc] [libcxxabi] [clang] [lld] [flang] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 edited 
https://github.com/llvm/llvm-project/pull/76653
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lldb] [clang-tools-extra] [lld] [compiler-rt] [clang] [llvm] [libc] [libcxxabi] [flang] [libcxx] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits


@@ -112,9 +116,11 @@ class Counter {
   PerfEvent Event;
   int FileDescriptor = -1;
   bool IsDummyEvent;
+  std::vector ValidationEvents;

boomanaiden154 wrote:

Done. I've split some of the refactoring into separate patches to try and keep 
the diffs a little bit more clean and make reviewing a little bit easier. The 
two new patches that perform the refactorings:
#77887
#77900

https://github.com/llvm/llvm-project/pull/76653
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lldb] [clang-tools-extra] [lld] [compiler-rt] [clang] [llvm] [libc] [libcxxabi] [flang] [libcxx] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 0196a8780f2d3a378f0fd3b86a6e6b6590ca02de Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 15:37:56 -0800
Subject: [PATCH 01/15] [llvm-exegesis] Remove unused Counter::read method

This method was simply a wrapper around readOrError. All users within
the llvm-exegesis code base should have been processing an actual error
rather than using the wrapper. This patch removes the wrapper and
rewrites the users (just 1) to use the readOrError method.
---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp |  6 +-
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp  | 13 -
 llvm/tools/llvm-exegesis/lib/PerfHelper.h|  3 ---
 3 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 1ee59a86ebbdcf..c57fce970b2139 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -356,7 +356,11 @@ class SubProcessFunctionExecutorImpl
   if (ChildExitCode == 0) {
 // The child exited succesfully, read counter values and return
 // success
-CounterValues[0] = Counter->read();
+auto CounterValueOrErr = Counter->readOrError();
+if (!CounterValueOrErr)
+  return CounterValueOrErr.takeError();
+CounterValues.swap(*CounterValueOrErr);
+
 return Error::success();
   }
   // The child exited, but not successfully
diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp 
b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
index 3ff1745e9e0629..314de1ec32366f 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
@@ -148,17 +148,6 @@ void Counter::stop() {
 ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, 0);
 }
 
-int64_t Counter::read() const {
-  auto ValueOrError = readOrError();
-  if (ValueOrError) {
-if (!ValueOrError.get().empty())
-  return ValueOrError.get()[0];
-errs() << "Counter has no reading\n";
-  } else
-errs() << ValueOrError.takeError() << "\n";
-  return -1;
-}
-
 llvm::Expected>
 Counter::readOrError(StringRef /*unused*/) const {
   int64_t Count = 0;
@@ -187,8 +176,6 @@ void Counter::start() {}
 
 void Counter::stop() {}
 
-int64_t Counter::read() const { return 42; }
-
 llvm::Expected>
 Counter::readOrError(StringRef /*unused*/) const {
   if (IsDummyEvent) {
diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.h 
b/llvm/tools/llvm-exegesis/lib/PerfHelper.h
index a50974f0a67be9..894aac1f197ed1 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.h
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.h
@@ -95,9 +95,6 @@ class Counter {
   /// Stops the measurement of the event.
   void stop();
 
-  /// Returns the current value of the counter or -1 if it cannot be read.
-  int64_t read() const;
-
   /// Returns the current value of the counter or error if it cannot be read.
   /// FunctionBytes: The benchmark function being executed.
   /// This is used to filter out the measurements to ensure they are only

>From 75261b9626878b92fa4bde2b4801815251238748 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 17:03:59 -0800
Subject: [PATCH 02/15] [llvm-exegesis] Add tablegen support for validation
 counters

---
 llvm/include/llvm/Target/TargetPfmCounters.td | 19 +
 llvm/lib/Target/X86/X86PfmCounters.td |  6 
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 13 +
 llvm/tools/llvm-exegesis/lib/Target.h | 11 
 llvm/utils/TableGen/ExegesisEmitter.cpp   | 28 +--
 5 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index b00f3e19c35f90..72f6b39f4878f4 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -28,6 +28,22 @@ class PfmIssueCounter
   string ResourceName = resource_name;
 }
 
+class ValidationEvent  {
+  int EventNumber = event_number;
+}
+
+def L1DCacheLoadMiss: ValidationEvent<0>;
+def InstructionRetired  : ValidationEvent<1>;
+def DataTLBLoadMiss : ValidationEvent<2>;
+def DataTLBStoreMiss: ValidationEvent<3>;
+
+// Validation counters can be tied to a specific event
+class PfmValidationCounter
+: PfmCounter {
+  // The name of the event that the validation counter detects.
+  ValidationEvent EventType = event_type;
+}
+
 def NoPfmCounter : PfmCounter <""> {}
 
 // Set of PfmCounters for measuring sched model characteristics.
@@ -38,6 +54,9 @@ class ProcPfmCounters {
   PfmCounter UopsCounter = NoPfmCounter;
   // Processors can define how to measure issued uops by defining 
IssueCounters.
   list IssueCounters = [];
+  // Processor can list mappings between validation events and real counters
+  // to measure 

[llvm-branch-commits] [lldb] [clang-tools-extra] [lld] [compiler-rt] [clang] [llvm] [libc] [libcxxabi] [flang] [libcxx] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 edited 
https://github.com/llvm/llvm-project/pull/76653
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Refactor individual counter data to ConfiguredEvent (PR #77900)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/77900

This further sets things up for validation events. Having a separate 
abstraction for a configured event that is setup as a counter allows for much 
easier creation of more events in the future within a single counter group 
(like validation counters) without duplicating any code.

>From 4300851b24c9ce9372648b6e5ee55417b3920608 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Fri, 12 Jan 2024 01:35:33 -0800
Subject: [PATCH] [llvm-exegesis] Refactor individual counter data to
 ConfiguredEvent

This further sets things up for validation events. Having a separate
abstraction for a configured event that is setup as a counter allows for
much easier creation of more events in the future within a single
counter group (like validation counters) without duplicating any code.
---
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 80 ---
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 32 ++--
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  8 +-
 3 files changed, 81 insertions(+), 39 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp 
b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
index f6e091bdff9aec..1dab8809d30280 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
@@ -107,21 +107,18 @@ StringRef PerfEvent::getPfmEventString() const {
   return FullQualifiedEventString;
 }
 
-CounterGroup::CounterGroup(PerfEvent &, pid_t ProcessID)
-: Event(std::move(E)) {
+ConfiguredEvent::ConfiguredEvent(PerfEvent &)
+: Event(std::move(EventToConfigure)) {
   assert(Event.valid());
-  IsDummyEvent = Event.name() == PerfEvent::DummyEventString;
-  if (!IsDummyEvent)
-initRealEvent(E, ProcessID);
 }
 
 #ifdef HAVE_LIBPFM
-void CounterGroup::initRealEvent(const PerfEvent , pid_t ProcessID) {
-  const int Cpu = -1; // measure any processor.
-  const int GroupFd = -1; // no grouping of counters.
+void ConfiguredEvent::initRealEvent(const pid_t ProcessID) {
+  const int CPU = -1;
+  const int GroupFD = -1;
   const uint32_t Flags = 0;
   perf_event_attr AttrCopy = *Event.attribute();
-  FileDescriptor = perf_event_open(, ProcessID, Cpu, GroupFd, Flags);
+  FileDescriptor = perf_event_open(, ProcessID, CPU, GroupFD, Flags);
   if (FileDescriptor == -1) {
 errs() << "Unable to open event. ERRNO: " << strerror(errno)
<< ". Make sure your kernel allows user "
@@ -134,44 +131,67 @@ void CounterGroup::initRealEvent(const PerfEvent , 
pid_t ProcessID) {
   assert(FileDescriptor != -1 && "Unable to open event");
 }
 
-CounterGroup::~CounterGroup() {
+Expected>
+ConfiguredEvent::readOrError(StringRef /*unused*/) const {
+  int64_t Count = 0;
+  ssize_t ReadSize = ::read(FileDescriptor, , sizeof(Count));
+
+  if (ReadSize != sizeof(Count))
+return llvm::make_error("Failed to read event counter",
+   llvm::errc::io_error);
+
+  SmallVector Result;
+  Result.push_back(Count);
+  return Result;
+}
+
+ConfiguredEvent::~ConfiguredEvent() { close(FileDescriptor); }
+#else
+void ConfiguredEvent::initRealEvent(pid_t ProcessID) {}
+
+Expected>
+ConfiguredEvent::readOrError(StringRef /*unused*/) const {
+  return make_error("Not implemented",
+ errc::function_not_supported);
+}
+
+ConfiguredEvent::~ConfiguredEvent() = default;
+#endif // HAVE_LIBPFM
+
+CounterGroup::CounterGroup(PerfEvent &, pid_t ProcessID)
+: EventCounter(std::move(E)) {
+  IsDummyEvent = EventCounter.isDummyEvent();
   if (!IsDummyEvent)
-close(FileDescriptor);
+initRealEvent(ProcessID);
+}
+
+#ifdef HAVE_LIBPFM
+void CounterGroup::initRealEvent(pid_t ProcessID) {
+  EventCounter.initRealEvent(ProcessID);
 }
 
 void CounterGroup::start() {
   if (!IsDummyEvent)
-ioctl(FileDescriptor, PERF_EVENT_IOC_RESET, 0);
+ioctl(getFileDescriptor(), PERF_EVENT_IOC_RESET, 0);
 }
 
 void CounterGroup::stop() {
   if (!IsDummyEvent)
-ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, 0);
+ioctl(getFileDescriptor(), PERF_EVENT_IOC_DISABLE, 0);
 }
 
 llvm::Expected>
-CounterGroup::readOrError(StringRef /*unused*/) const {
-  int64_t Count = 0;
-  if (!IsDummyEvent) {
-ssize_t ReadSize = ::read(FileDescriptor, , sizeof(Count));
-if (ReadSize != sizeof(Count))
-  return llvm::make_error("Failed to read event 
counter",
- llvm::errc::io_error);
-  } else {
-Count = 42;
-  }
-
-  llvm::SmallVector Result;
-  Result.push_back(Count);
-  return Result;
+CounterGroup::readOrError(StringRef FunctionBytes) const {
+  if (!IsDummyEvent)
+return EventCounter.readOrError(FunctionBytes);
+  else
+return SmallVector(1, 42);
 }
 
 int CounterGroup::numValues() const { return 1; }
 #else
 
-void CounterGroup::initRealEvent(const PerfEvent &, pid_t ProcessID) {}
-
-CounterGroup::~CounterGroup() = default;
+void 

[llvm-branch-commits] [lldb] [libc] [lld] [libcxx] [clang] [compiler-rt] [flang] [clang-tools-extra] [llvm] [libcxxabi] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 0196a8780f2d3a378f0fd3b86a6e6b6590ca02de Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 15:37:56 -0800
Subject: [PATCH 01/15] [llvm-exegesis] Remove unused Counter::read method

This method was simply a wrapper around readOrError. All users within
the llvm-exegesis code base should have been processing an actual error
rather than using the wrapper. This patch removes the wrapper and
rewrites the users (just 1) to use the readOrError method.
---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp |  6 +-
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp  | 13 -
 llvm/tools/llvm-exegesis/lib/PerfHelper.h|  3 ---
 3 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 1ee59a86ebbdcf..c57fce970b2139 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -356,7 +356,11 @@ class SubProcessFunctionExecutorImpl
   if (ChildExitCode == 0) {
 // The child exited succesfully, read counter values and return
 // success
-CounterValues[0] = Counter->read();
+auto CounterValueOrErr = Counter->readOrError();
+if (!CounterValueOrErr)
+  return CounterValueOrErr.takeError();
+CounterValues.swap(*CounterValueOrErr);
+
 return Error::success();
   }
   // The child exited, but not successfully
diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp 
b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
index 3ff1745e9e0629..314de1ec32366f 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
@@ -148,17 +148,6 @@ void Counter::stop() {
 ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, 0);
 }
 
-int64_t Counter::read() const {
-  auto ValueOrError = readOrError();
-  if (ValueOrError) {
-if (!ValueOrError.get().empty())
-  return ValueOrError.get()[0];
-errs() << "Counter has no reading\n";
-  } else
-errs() << ValueOrError.takeError() << "\n";
-  return -1;
-}
-
 llvm::Expected>
 Counter::readOrError(StringRef /*unused*/) const {
   int64_t Count = 0;
@@ -187,8 +176,6 @@ void Counter::start() {}
 
 void Counter::stop() {}
 
-int64_t Counter::read() const { return 42; }
-
 llvm::Expected>
 Counter::readOrError(StringRef /*unused*/) const {
   if (IsDummyEvent) {
diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.h 
b/llvm/tools/llvm-exegesis/lib/PerfHelper.h
index a50974f0a67be9..894aac1f197ed1 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.h
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.h
@@ -95,9 +95,6 @@ class Counter {
   /// Stops the measurement of the event.
   void stop();
 
-  /// Returns the current value of the counter or -1 if it cannot be read.
-  int64_t read() const;
-
   /// Returns the current value of the counter or error if it cannot be read.
   /// FunctionBytes: The benchmark function being executed.
   /// This is used to filter out the measurements to ensure they are only

>From 75261b9626878b92fa4bde2b4801815251238748 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 17:03:59 -0800
Subject: [PATCH 02/15] [llvm-exegesis] Add tablegen support for validation
 counters

---
 llvm/include/llvm/Target/TargetPfmCounters.td | 19 +
 llvm/lib/Target/X86/X86PfmCounters.td |  6 
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 13 +
 llvm/tools/llvm-exegesis/lib/Target.h | 11 
 llvm/utils/TableGen/ExegesisEmitter.cpp   | 28 +--
 5 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index b00f3e19c35f90..72f6b39f4878f4 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -28,6 +28,22 @@ class PfmIssueCounter
   string ResourceName = resource_name;
 }
 
+class ValidationEvent  {
+  int EventNumber = event_number;
+}
+
+def L1DCacheLoadMiss: ValidationEvent<0>;
+def InstructionRetired  : ValidationEvent<1>;
+def DataTLBLoadMiss : ValidationEvent<2>;
+def DataTLBStoreMiss: ValidationEvent<3>;
+
+// Validation counters can be tied to a specific event
+class PfmValidationCounter
+: PfmCounter {
+  // The name of the event that the validation counter detects.
+  ValidationEvent EventType = event_type;
+}
+
 def NoPfmCounter : PfmCounter <""> {}
 
 // Set of PfmCounters for measuring sched model characteristics.
@@ -38,6 +54,9 @@ class ProcPfmCounters {
   PfmCounter UopsCounter = NoPfmCounter;
   // Processors can define how to measure issued uops by defining 
IssueCounters.
   list IssueCounters = [];
+  // Processor can list mappings between validation events and real counters
+  // to measure 

[llvm-branch-commits] [llvm] [clang-tools-extra] [compiler-rt] [clang] [libcxx] [lld] [flang] [libc] [lldb] [libcxxabi] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 0196a8780f2d3a378f0fd3b86a6e6b6590ca02de Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 15:37:56 -0800
Subject: [PATCH 01/14] [llvm-exegesis] Remove unused Counter::read method

This method was simply a wrapper around readOrError. All users within
the llvm-exegesis code base should have been processing an actual error
rather than using the wrapper. This patch removes the wrapper and
rewrites the users (just 1) to use the readOrError method.
---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp |  6 +-
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp  | 13 -
 llvm/tools/llvm-exegesis/lib/PerfHelper.h|  3 ---
 3 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 1ee59a86ebbdcf..c57fce970b2139 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -356,7 +356,11 @@ class SubProcessFunctionExecutorImpl
   if (ChildExitCode == 0) {
 // The child exited succesfully, read counter values and return
 // success
-CounterValues[0] = Counter->read();
+auto CounterValueOrErr = Counter->readOrError();
+if (!CounterValueOrErr)
+  return CounterValueOrErr.takeError();
+CounterValues.swap(*CounterValueOrErr);
+
 return Error::success();
   }
   // The child exited, but not successfully
diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp 
b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
index 3ff1745e9e0629..314de1ec32366f 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
@@ -148,17 +148,6 @@ void Counter::stop() {
 ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, 0);
 }
 
-int64_t Counter::read() const {
-  auto ValueOrError = readOrError();
-  if (ValueOrError) {
-if (!ValueOrError.get().empty())
-  return ValueOrError.get()[0];
-errs() << "Counter has no reading\n";
-  } else
-errs() << ValueOrError.takeError() << "\n";
-  return -1;
-}
-
 llvm::Expected>
 Counter::readOrError(StringRef /*unused*/) const {
   int64_t Count = 0;
@@ -187,8 +176,6 @@ void Counter::start() {}
 
 void Counter::stop() {}
 
-int64_t Counter::read() const { return 42; }
-
 llvm::Expected>
 Counter::readOrError(StringRef /*unused*/) const {
   if (IsDummyEvent) {
diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.h 
b/llvm/tools/llvm-exegesis/lib/PerfHelper.h
index a50974f0a67be9..894aac1f197ed1 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.h
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.h
@@ -95,9 +95,6 @@ class Counter {
   /// Stops the measurement of the event.
   void stop();
 
-  /// Returns the current value of the counter or -1 if it cannot be read.
-  int64_t read() const;
-
   /// Returns the current value of the counter or error if it cannot be read.
   /// FunctionBytes: The benchmark function being executed.
   /// This is used to filter out the measurements to ensure they are only

>From 75261b9626878b92fa4bde2b4801815251238748 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 17:03:59 -0800
Subject: [PATCH 02/14] [llvm-exegesis] Add tablegen support for validation
 counters

---
 llvm/include/llvm/Target/TargetPfmCounters.td | 19 +
 llvm/lib/Target/X86/X86PfmCounters.td |  6 
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 13 +
 llvm/tools/llvm-exegesis/lib/Target.h | 11 
 llvm/utils/TableGen/ExegesisEmitter.cpp   | 28 +--
 5 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index b00f3e19c35f90..72f6b39f4878f4 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -28,6 +28,22 @@ class PfmIssueCounter
   string ResourceName = resource_name;
 }
 
+class ValidationEvent  {
+  int EventNumber = event_number;
+}
+
+def L1DCacheLoadMiss: ValidationEvent<0>;
+def InstructionRetired  : ValidationEvent<1>;
+def DataTLBLoadMiss : ValidationEvent<2>;
+def DataTLBStoreMiss: ValidationEvent<3>;
+
+// Validation counters can be tied to a specific event
+class PfmValidationCounter
+: PfmCounter {
+  // The name of the event that the validation counter detects.
+  ValidationEvent EventType = event_type;
+}
+
 def NoPfmCounter : PfmCounter <""> {}
 
 // Set of PfmCounters for measuring sched model characteristics.
@@ -38,6 +54,9 @@ class ProcPfmCounters {
   PfmCounter UopsCounter = NoPfmCounter;
   // Processors can define how to measure issued uops by defining 
IssueCounters.
   list IssueCounters = [];
+  // Processor can list mappings between validation events and real counters
+  // to measure 

[llvm-branch-commits] [llvm] [lld] [clang-tools-extra] [clang] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-12 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 edited 
https://github.com/llvm/llvm-project/pull/76653
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [clang] [clang-tools-extra] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-10 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 76f199f4fc7244c3d972736595c685d7316c5203 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 18:18:12 -0800
Subject: [PATCH 1/6] [llvm-exegesis] Add support for validation counters

This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 52 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +-
 .../llvm-exegesis/lib/BenchmarkRunner.cpp | 52 +--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.h |  8 ++-
 .../lib/LatencyBenchmarkRunner.cpp| 46 
 .../lib/LatencyBenchmarkRunner.h  |  3 ++
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 37 +++--
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 10 +++-
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 35 +
 llvm/tools/llvm-exegesis/lib/Target.h | 13 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.cpp | 37 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.h   |  9 +++-
 llvm/tools/llvm-exegesis/lib/X86/Target.cpp   | 11 +++-
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++-
 .../tools/llvm-exegesis/ClusteringTest.cpp| 36 ++---
 .../Mips/BenchmarkResultTest.cpp  | 12 ++---
 .../llvm-exegesis/X86/BenchmarkResultTest.cpp | 12 ++---
 18 files changed, 311 insertions(+), 97 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 02c4da11e032d6..1079df24b457b8 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -192,6 +193,56 @@ template <> struct 
SequenceElementTraits {
   static const bool flow = false;
 };
 
+const char *validationEventToString(exegesis::ValidationEvent VE) {
+  switch (VE) {
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-load-miss";
+  case exegesis::ValidationEvent::InstructionRetired:
+return "instructions-retired";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  }
+}
+
+Expected stringToValidationEvent(StringRef Input) {
+  if (Input == "l1d-load-miss")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "instructions-retired")
+return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else
+return make_error("Invalid validation event string",
+   errc::invalid_argument);
+}
+
+template <>
+struct CustomMappingTraits<
+std::unordered_map> {
+  static void
+  inputOne(IO , StringRef KeyStr,
+   std::unordered_map ) {
+Expected Key = stringToValidationEvent(KeyStr);
+if (!Key) {
+  Io.setError("Key is not a valid validation event");
+  return;
+}
+Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
+  }
+
+  static void
+  output(IO , std::unordered_map ) {
+for (auto  : VI) {
+  Io.mapRequired(validationEventToString(IndividualVI.first),
+ IndividualVI.second);
+}
+  }
+};
+
 // exegesis::Measure is rendererd as a flow instead of a list.
 // e.g. { "key": "the key", "value": 0123 }
 template <> struct MappingTraits {
@@ -203,6 +254,7 @@ template <> struct 
MappingTraits {
 }
 Io.mapRequired("value", Obj.PerInstructionValue);
 Io.mapOptional("per_snippet_value", Obj.PerSnippetValue);
+Io.mapOptional("validation_counters", Obj.ValidationCounters);
   }
   static const bool flow = true;
 };
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 0d08febae20cb3..f142da07e0a47d 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -32,6 +32,13 @@ class Error;
 
 namespace exegesis {
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 enum class 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-04 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 76f199f4fc7244c3d972736595c685d7316c5203 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 18:18:12 -0800
Subject: [PATCH 1/6] [llvm-exegesis] Add support for validation counters

This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 52 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +-
 .../llvm-exegesis/lib/BenchmarkRunner.cpp | 52 +--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.h |  8 ++-
 .../lib/LatencyBenchmarkRunner.cpp| 46 
 .../lib/LatencyBenchmarkRunner.h  |  3 ++
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 37 +++--
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 10 +++-
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 35 +
 llvm/tools/llvm-exegesis/lib/Target.h | 13 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.cpp | 37 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.h   |  9 +++-
 llvm/tools/llvm-exegesis/lib/X86/Target.cpp   | 11 +++-
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++-
 .../tools/llvm-exegesis/ClusteringTest.cpp| 36 ++---
 .../Mips/BenchmarkResultTest.cpp  | 12 ++---
 .../llvm-exegesis/X86/BenchmarkResultTest.cpp | 12 ++---
 18 files changed, 311 insertions(+), 97 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 02c4da11e032d6..1079df24b457b8 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -192,6 +193,56 @@ template <> struct 
SequenceElementTraits {
   static const bool flow = false;
 };
 
+const char *validationEventToString(exegesis::ValidationEvent VE) {
+  switch (VE) {
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-load-miss";
+  case exegesis::ValidationEvent::InstructionRetired:
+return "instructions-retired";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  }
+}
+
+Expected stringToValidationEvent(StringRef Input) {
+  if (Input == "l1d-load-miss")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "instructions-retired")
+return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else
+return make_error("Invalid validation event string",
+   errc::invalid_argument);
+}
+
+template <>
+struct CustomMappingTraits<
+std::unordered_map> {
+  static void
+  inputOne(IO , StringRef KeyStr,
+   std::unordered_map ) {
+Expected Key = stringToValidationEvent(KeyStr);
+if (!Key) {
+  Io.setError("Key is not a valid validation event");
+  return;
+}
+Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
+  }
+
+  static void
+  output(IO , std::unordered_map ) {
+for (auto  : VI) {
+  Io.mapRequired(validationEventToString(IndividualVI.first),
+ IndividualVI.second);
+}
+  }
+};
+
 // exegesis::Measure is rendererd as a flow instead of a list.
 // e.g. { "key": "the key", "value": 0123 }
 template <> struct MappingTraits {
@@ -203,6 +254,7 @@ template <> struct 
MappingTraits {
 }
 Io.mapRequired("value", Obj.PerInstructionValue);
 Io.mapOptional("per_snippet_value", Obj.PerSnippetValue);
+Io.mapOptional("validation_counters", Obj.ValidationCounters);
   }
   static const bool flow = true;
 };
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 0d08febae20cb3..f142da07e0a47d 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -32,6 +32,13 @@ class Error;
 
 namespace exegesis {
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 enum class 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add additional validation counters (PR #76788)

2024-01-03 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76788

>From c665ef230d082dc6dddbe6707f0ad43fe28d680c Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Tue, 2 Jan 2024 22:54:35 -0800
Subject: [PATCH 1/2] [llvm-exegesis] Add additional validation counters

This patch adds support for additional types of validation counters and
also adds mappings between these new validation counter types and
physical counters on the hardware for microarchitectures that I have the
ability to test on.
---
 llvm/include/llvm/Target/TargetPfmCounters.td |  7 ++
 llvm/lib/Target/X86/X86PfmCounters.td | 10 
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 24 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h |  6 +
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 +++---
 5 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index d162327afea2cf..0bfefd5d31211e 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -33,6 +33,13 @@ class ValidationEvent  {
 }
 
 def InstructionRetired  : ValidationEvent<0>;
+def L1DCacheLoadMiss : ValidationEvent<1>;
+def L1DCacheStoreMiss : ValidationEvent<2>;
+def L1ICacheLoadMiss : ValidationEvent<3>;
+def DataTLBLoadMiss : ValidationEvent<4>;
+def DataTLBStoreMiss : ValidationEvent<5>;
+def InstructionTLBLoadMiss : ValidationEvent<6>;
+
 
 // Validation counters can be tied to a specific event
 class PfmValidationCounter
diff --git a/llvm/lib/Target/X86/X86PfmCounters.td 
b/llvm/lib/Target/X86/X86PfmCounters.td
index 48d68954970915..e6b8cdc430e549 100644
--- a/llvm/lib/Target/X86/X86PfmCounters.td
+++ b/llvm/lib/Target/X86/X86PfmCounters.td
@@ -20,6 +20,11 @@ def : PfmCountersDefaultBinding;
 // Intel X86 Counters.
 defvar DefaultIntelPfmValidationCounters = [
   PfmValidationCounter
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter
 ];
 
 def PentiumPfmCounters : ProcPfmCounters {
@@ -201,6 +206,11 @@ def : PfmCountersBinding<"tigerlake", IceLakePfmCounters>;
 // AMD X86 Counters.
 defvar DefaultAMDPfmValidationCounters = [
   PfmValidationCounter
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter
 ];
 
 // Set basic counters for AMD cpus that we know libpfm4 supports.
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index d3f69beb19c46f..bec96c13672782 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -197,12 +197,36 @@ const char 
*validationEventToString(exegesis::ValidationEvent VE) {
   switch (VE) {
   case exegesis::ValidationEvent::InstructionRetired:
 return "instructions-retired";
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-cache-load-misses";
+  case exegesis::ValidationEvent::L1DCacheStoreMiss:
+return "l1d-cache-store-misses";
+  case exegesis::ValidationEvent::L1ICacheLoadMiss:
+return "l1i-cache-load-misses";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  case exegesis::ValidationEvent::InstructionTLBLoadMiss:
+return "instruction-tlb-load-misses";
   }
 }
 
 Expected stringToValidationEvent(StringRef Input) {
   if (Input == "instructions-retired")
 return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "l1d-cache-load-misses")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "l1d-cache-store-misses")
+return exegesis::ValidationEvent::L1DCacheStoreMiss;
+  else if (Input == "l1i-cache-load-misses")
+return exegesis::ValidationEvent::L1ICacheLoadMiss;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else if (Input == "instruction-tlb-load-misses")
+return exegesis::ValidationEvent::InstructionTLBLoadMiss;
   else
 return make_error("Invalid validation event string",
errc::invalid_argument);
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 9fc5d851b29abb..56d907cea0f78a 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -34,6 +34,12 @@ namespace exegesis {
 
 enum ValidationEvent {
   InstructionRetired,
+  L1DCacheLoadMiss,
+  L1DCacheStoreMiss,
+  L1ICacheLoadMiss,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss,
+  InstructionTLBLoadMiss
 };
 
 enum class BenchmarkPhaseSelectorE {
diff --git 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-03 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 76f199f4fc7244c3d972736595c685d7316c5203 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 18:18:12 -0800
Subject: [PATCH 1/5] [llvm-exegesis] Add support for validation counters

This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 52 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +-
 .../llvm-exegesis/lib/BenchmarkRunner.cpp | 52 +--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.h |  8 ++-
 .../lib/LatencyBenchmarkRunner.cpp| 46 
 .../lib/LatencyBenchmarkRunner.h  |  3 ++
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 37 +++--
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 10 +++-
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 35 +
 llvm/tools/llvm-exegesis/lib/Target.h | 13 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.cpp | 37 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.h   |  9 +++-
 llvm/tools/llvm-exegesis/lib/X86/Target.cpp   | 11 +++-
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++-
 .../tools/llvm-exegesis/ClusteringTest.cpp| 36 ++---
 .../Mips/BenchmarkResultTest.cpp  | 12 ++---
 .../llvm-exegesis/X86/BenchmarkResultTest.cpp | 12 ++---
 18 files changed, 311 insertions(+), 97 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 02c4da11e032d6..1079df24b457b8 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -192,6 +193,56 @@ template <> struct 
SequenceElementTraits {
   static const bool flow = false;
 };
 
+const char *validationEventToString(exegesis::ValidationEvent VE) {
+  switch (VE) {
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-load-miss";
+  case exegesis::ValidationEvent::InstructionRetired:
+return "instructions-retired";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  }
+}
+
+Expected stringToValidationEvent(StringRef Input) {
+  if (Input == "l1d-load-miss")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "instructions-retired")
+return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else
+return make_error("Invalid validation event string",
+   errc::invalid_argument);
+}
+
+template <>
+struct CustomMappingTraits<
+std::unordered_map> {
+  static void
+  inputOne(IO , StringRef KeyStr,
+   std::unordered_map ) {
+Expected Key = stringToValidationEvent(KeyStr);
+if (!Key) {
+  Io.setError("Key is not a valid validation event");
+  return;
+}
+Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
+  }
+
+  static void
+  output(IO , std::unordered_map ) {
+for (auto  : VI) {
+  Io.mapRequired(validationEventToString(IndividualVI.first),
+ IndividualVI.second);
+}
+  }
+};
+
 // exegesis::Measure is rendererd as a flow instead of a list.
 // e.g. { "key": "the key", "value": 0123 }
 template <> struct MappingTraits {
@@ -203,6 +254,7 @@ template <> struct 
MappingTraits {
 }
 Io.mapRequired("value", Obj.PerInstructionValue);
 Io.mapOptional("per_snippet_value", Obj.PerSnippetValue);
+Io.mapOptional("validation_counters", Obj.ValidationCounters);
   }
   static const bool flow = true;
 };
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 0d08febae20cb3..f142da07e0a47d 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -32,6 +32,13 @@ class Error;
 
 namespace exegesis {
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 enum class 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add additional validation counters (PR #76788)

2024-01-03 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76788

>From 0c45220a79dcada7e1d0f54490b452e02a2b8e4f Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Tue, 2 Jan 2024 22:54:35 -0800
Subject: [PATCH 1/2] [llvm-exegesis] Add additional validation counters

This patch adds support for additional types of validation counters and
also adds mappings between these new validation counter types and
physical counters on the hardware for microarchitectures that I have the
ability to test on.
---
 llvm/include/llvm/Target/TargetPfmCounters.td |  7 ++
 llvm/lib/Target/X86/X86PfmCounters.td | 10 
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 24 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h |  6 +
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 +++---
 5 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index d162327afea2cf..0bfefd5d31211e 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -33,6 +33,13 @@ class ValidationEvent  {
 }
 
 def InstructionRetired  : ValidationEvent<0>;
+def L1DCacheLoadMiss : ValidationEvent<1>;
+def L1DCacheStoreMiss : ValidationEvent<2>;
+def L1ICacheLoadMiss : ValidationEvent<3>;
+def DataTLBLoadMiss : ValidationEvent<4>;
+def DataTLBStoreMiss : ValidationEvent<5>;
+def InstructionTLBLoadMiss : ValidationEvent<6>;
+
 
 // Validation counters can be tied to a specific event
 class PfmValidationCounter
diff --git a/llvm/lib/Target/X86/X86PfmCounters.td 
b/llvm/lib/Target/X86/X86PfmCounters.td
index 48d68954970915..e6b8cdc430e549 100644
--- a/llvm/lib/Target/X86/X86PfmCounters.td
+++ b/llvm/lib/Target/X86/X86PfmCounters.td
@@ -20,6 +20,11 @@ def : PfmCountersDefaultBinding;
 // Intel X86 Counters.
 defvar DefaultIntelPfmValidationCounters = [
   PfmValidationCounter
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter
 ];
 
 def PentiumPfmCounters : ProcPfmCounters {
@@ -201,6 +206,11 @@ def : PfmCountersBinding<"tigerlake", IceLakePfmCounters>;
 // AMD X86 Counters.
 defvar DefaultAMDPfmValidationCounters = [
   PfmValidationCounter
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter
 ];
 
 // Set basic counters for AMD cpus that we know libpfm4 supports.
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index d3f69beb19c46f..bec96c13672782 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -197,12 +197,36 @@ const char 
*validationEventToString(exegesis::ValidationEvent VE) {
   switch (VE) {
   case exegesis::ValidationEvent::InstructionRetired:
 return "instructions-retired";
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-cache-load-misses";
+  case exegesis::ValidationEvent::L1DCacheStoreMiss:
+return "l1d-cache-store-misses";
+  case exegesis::ValidationEvent::L1ICacheLoadMiss:
+return "l1i-cache-load-misses";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  case exegesis::ValidationEvent::InstructionTLBLoadMiss:
+return "instruction-tlb-load-misses";
   }
 }
 
 Expected stringToValidationEvent(StringRef Input) {
   if (Input == "instructions-retired")
 return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "l1d-cache-load-misses")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "l1d-cache-store-misses")
+return exegesis::ValidationEvent::L1DCacheStoreMiss;
+  else if (Input == "l1i-cache-load-misses")
+return exegesis::ValidationEvent::L1ICacheLoadMiss;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else if (Input == "instruction-tlb-load-misses")
+return exegesis::ValidationEvent::InstructionTLBLoadMiss;
   else
 return make_error("Invalid validation event string",
errc::invalid_argument);
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 9fc5d851b29abb..56d907cea0f78a 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -34,6 +34,12 @@ namespace exegesis {
 
 enum ValidationEvent {
   InstructionRetired,
+  L1DCacheLoadMiss,
+  L1DCacheStoreMiss,
+  L1ICacheLoadMiss,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss,
+  InstructionTLBLoadMiss
 };
 
 enum class BenchmarkPhaseSelectorE {
diff --git 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add additional validation counters (PR #76788)

2024-01-03 Thread Aiden Grossman via llvm-branch-commits


@@ -121,7 +121,12 @@ def HaswellPfmCounters : ProcPfmCounters {
 PfmIssueCounter<"HWPort7", "uops_executed_port:port_7">
   ];
   let ValidationCounters = [
-PfmValidationCounter
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter
   ];

boomanaiden154 wrote:

Thanks for the suggestion! I've refactored everything into a default counters 
set that's split across AMD/Intel (as the counters between them differ). We 
might need to adapt as newer/older architectures are brought up, but this 
should be reasonably scalable.

https://github.com/llvm/llvm-project/pull/76788
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Add additional validation counters (PR #76788)

2024-01-03 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76788

>From 0c45220a79dcada7e1d0f54490b452e02a2b8e4f Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Tue, 2 Jan 2024 22:54:35 -0800
Subject: [PATCH] [llvm-exegesis] Add additional validation counters

This patch adds support for additional types of validation counters and
also adds mappings between these new validation counter types and
physical counters on the hardware for microarchitectures that I have the
ability to test on.
---
 llvm/include/llvm/Target/TargetPfmCounters.td |  7 ++
 llvm/lib/Target/X86/X86PfmCounters.td | 10 
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 24 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h |  6 +
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 +++---
 5 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index d162327afea2cf..0bfefd5d31211e 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -33,6 +33,13 @@ class ValidationEvent  {
 }
 
 def InstructionRetired  : ValidationEvent<0>;
+def L1DCacheLoadMiss : ValidationEvent<1>;
+def L1DCacheStoreMiss : ValidationEvent<2>;
+def L1ICacheLoadMiss : ValidationEvent<3>;
+def DataTLBLoadMiss : ValidationEvent<4>;
+def DataTLBStoreMiss : ValidationEvent<5>;
+def InstructionTLBLoadMiss : ValidationEvent<6>;
+
 
 // Validation counters can be tied to a specific event
 class PfmValidationCounter
diff --git a/llvm/lib/Target/X86/X86PfmCounters.td 
b/llvm/lib/Target/X86/X86PfmCounters.td
index 48d68954970915..e6b8cdc430e549 100644
--- a/llvm/lib/Target/X86/X86PfmCounters.td
+++ b/llvm/lib/Target/X86/X86PfmCounters.td
@@ -20,6 +20,11 @@ def : PfmCountersDefaultBinding;
 // Intel X86 Counters.
 defvar DefaultIntelPfmValidationCounters = [
   PfmValidationCounter
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter
 ];
 
 def PentiumPfmCounters : ProcPfmCounters {
@@ -201,6 +206,11 @@ def : PfmCountersBinding<"tigerlake", IceLakePfmCounters>;
 // AMD X86 Counters.
 defvar DefaultAMDPfmValidationCounters = [
   PfmValidationCounter
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter,
+  PfmValidationCounter
 ];
 
 // Set basic counters for AMD cpus that we know libpfm4 supports.
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index d3f69beb19c46f..bec96c13672782 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -197,12 +197,36 @@ const char 
*validationEventToString(exegesis::ValidationEvent VE) {
   switch (VE) {
   case exegesis::ValidationEvent::InstructionRetired:
 return "instructions-retired";
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-cache-load-misses";
+  case exegesis::ValidationEvent::L1DCacheStoreMiss:
+return "l1d-cache-store-misses";
+  case exegesis::ValidationEvent::L1ICacheLoadMiss:
+return "l1i-cache-load-misses";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  case exegesis::ValidationEvent::InstructionTLBLoadMiss:
+return "instruction-tlb-load-misses";
   }
 }
 
 Expected stringToValidationEvent(StringRef Input) {
   if (Input == "instructions-retired")
 return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "l1d-cache-load-misses")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "l1d-cache-store-misses")
+return exegesis::ValidationEvent::L1DCacheStoreMiss;
+  else if (Input == "l1i-cache-load-misses")
+return exegesis::ValidationEvent::L1ICacheLoadMiss;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else if (Input == "instruction-tlb-load-misses")
+return exegesis::ValidationEvent::InstructionTLBLoadMiss;
   else
 return make_error("Invalid validation event string",
errc::invalid_argument);
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 9fc5d851b29abb..56d907cea0f78a 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -34,6 +34,12 @@ namespace exegesis {
 
 enum ValidationEvent {
   InstructionRetired,
+  L1DCacheLoadMiss,
+  L1DCacheStoreMiss,
+  L1ICacheLoadMiss,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss,
+  InstructionTLBLoadMiss
 };
 
 enum class BenchmarkPhaseSelectorE {
diff --git 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-03 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 76f199f4fc7244c3d972736595c685d7316c5203 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 18:18:12 -0800
Subject: [PATCH 1/4] [llvm-exegesis] Add support for validation counters

This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 52 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +-
 .../llvm-exegesis/lib/BenchmarkRunner.cpp | 52 +--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.h |  8 ++-
 .../lib/LatencyBenchmarkRunner.cpp| 46 
 .../lib/LatencyBenchmarkRunner.h  |  3 ++
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 37 +++--
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 10 +++-
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 35 +
 llvm/tools/llvm-exegesis/lib/Target.h | 13 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.cpp | 37 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.h   |  9 +++-
 llvm/tools/llvm-exegesis/lib/X86/Target.cpp   | 11 +++-
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++-
 .../tools/llvm-exegesis/ClusteringTest.cpp| 36 ++---
 .../Mips/BenchmarkResultTest.cpp  | 12 ++---
 .../llvm-exegesis/X86/BenchmarkResultTest.cpp | 12 ++---
 18 files changed, 311 insertions(+), 97 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 02c4da11e032d6..1079df24b457b8 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -192,6 +193,56 @@ template <> struct 
SequenceElementTraits {
   static const bool flow = false;
 };
 
+const char *validationEventToString(exegesis::ValidationEvent VE) {
+  switch (VE) {
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-load-miss";
+  case exegesis::ValidationEvent::InstructionRetired:
+return "instructions-retired";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  }
+}
+
+Expected stringToValidationEvent(StringRef Input) {
+  if (Input == "l1d-load-miss")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "instructions-retired")
+return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else
+return make_error("Invalid validation event string",
+   errc::invalid_argument);
+}
+
+template <>
+struct CustomMappingTraits<
+std::unordered_map> {
+  static void
+  inputOne(IO , StringRef KeyStr,
+   std::unordered_map ) {
+Expected Key = stringToValidationEvent(KeyStr);
+if (!Key) {
+  Io.setError("Key is not a valid validation event");
+  return;
+}
+Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
+  }
+
+  static void
+  output(IO , std::unordered_map ) {
+for (auto  : VI) {
+  Io.mapRequired(validationEventToString(IndividualVI.first),
+ IndividualVI.second);
+}
+  }
+};
+
 // exegesis::Measure is rendererd as a flow instead of a list.
 // e.g. { "key": "the key", "value": 0123 }
 template <> struct MappingTraits {
@@ -203,6 +254,7 @@ template <> struct 
MappingTraits {
 }
 Io.mapRequired("value", Obj.PerInstructionValue);
 Io.mapOptional("per_snippet_value", Obj.PerSnippetValue);
+Io.mapOptional("validation_counters", Obj.ValidationCounters);
   }
   static const bool flow = true;
 };
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 0d08febae20cb3..f142da07e0a47d 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -32,6 +32,13 @@ class Error;
 
 namespace exegesis {
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 enum class 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add additional validation counters (PR #76788)

2024-01-03 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/76788

This patch adds support for additional types of validation counters and also 
adds mappings between these new validation counter types and physical counters 
on the hardware for microarchitectures that I have the ability to test on.

>From 05901b26b1225dc631a4b89950b3816fbe542e3b Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Tue, 2 Jan 2024 22:54:35 -0800
Subject: [PATCH] [llvm-exegesis] Add additional validation counters

This patch adds support for additional types of validation counters and
also adds mappings between these new validation counter types and
physical counters on the hardware for microarchitectures that I have the
ability to test on.
---
 llvm/include/llvm/Target/TargetPfmCounters.td |  7 
 llvm/lib/Target/X86/X86PfmCounters.td | 42 ---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 24 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h |  6 +++
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++--
 5 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index d162327afea2cf..0bfefd5d31211e 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -33,6 +33,13 @@ class ValidationEvent  {
 }
 
 def InstructionRetired  : ValidationEvent<0>;
+def L1DCacheLoadMiss : ValidationEvent<1>;
+def L1DCacheStoreMiss : ValidationEvent<2>;
+def L1ICacheLoadMiss : ValidationEvent<3>;
+def DataTLBLoadMiss : ValidationEvent<4>;
+def DataTLBStoreMiss : ValidationEvent<5>;
+def InstructionTLBLoadMiss : ValidationEvent<6>;
+
 
 // Validation counters can be tied to a specific event
 class PfmValidationCounter
diff --git a/llvm/lib/Target/X86/X86PfmCounters.td 
b/llvm/lib/Target/X86/X86PfmCounters.td
index 52c86b1f74c1cb..4403b9845be920 100644
--- a/llvm/lib/Target/X86/X86PfmCounters.td
+++ b/llvm/lib/Target/X86/X86PfmCounters.td
@@ -121,7 +121,12 @@ def HaswellPfmCounters : ProcPfmCounters {
 PfmIssueCounter<"HWPort7", "uops_executed_port:port_7">
   ];
   let ValidationCounters = [
-PfmValidationCounter
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter
   ];
 }
 def : PfmCountersBinding<"haswell", HaswellPfmCounters>;
@@ -140,7 +145,12 @@ def BroadwellPfmCounters : ProcPfmCounters {
 PfmIssueCounter<"BWPort7", "uops_executed_port:port_7">
   ];
   let ValidationCounters = [
-PfmValidationCounter
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter
   ];
 }
 def : PfmCountersBinding<"broadwell", BroadwellPfmCounters>;
@@ -159,7 +169,12 @@ def SkylakeClientPfmCounters : ProcPfmCounters {
 PfmIssueCounter<"SKLPort7", "uops_dispatched_port:port_7">
   ];
   let ValidationCounters = [
-PfmValidationCounter
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter
   ];
 }
 def : PfmCountersBinding<"skylake", SkylakeClientPfmCounters>;
@@ -178,7 +193,12 @@ def SkylakeServerPfmCounters : ProcPfmCounters {
 PfmIssueCounter<"SKXPort7", "uops_dispatched_port:port_7">
   ];
   let ValidationCounters = [
-PfmValidationCounter
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter
   ];
 }
 def : PfmCountersBinding<"skylake-avx512", SkylakeServerPfmCounters>;
@@ -297,7 +317,12 @@ def ZnVer2PfmCounters : ProcPfmCounters {
 PfmIssueCounter<"Zn2Divider", "div_op_count">
   ];
   let ValidationCounters = [
-PfmValidationCounter
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter
   ];
 }
 def : PfmCountersBinding<"znver2", ZnVer2PfmCounters>;
@@ -313,7 +338,12 @@ def ZnVer3PfmCounters : ProcPfmCounters {
 PfmIssueCounter<"Zn3Divider", "div_op_count">
   ];
   let ValidationCounters = [
-PfmValidationCounter
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter,
+PfmValidationCounter
   ];
 }
 def : PfmCountersBinding<"znver3", ZnVer3PfmCounters>;
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index d3f69beb19c46f..bec96c13672782 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -197,12 +197,36 @@ const char 
*validationEventToString(exegesis::ValidationEvent VE) {
   switch (VE) {
   case exegesis::ValidationEvent::InstructionRetired:
   

[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-02 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 76f199f4fc7244c3d972736595c685d7316c5203 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 18:18:12 -0800
Subject: [PATCH 1/3] [llvm-exegesis] Add support for validation counters

This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 52 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +-
 .../llvm-exegesis/lib/BenchmarkRunner.cpp | 52 +--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.h |  8 ++-
 .../lib/LatencyBenchmarkRunner.cpp| 46 
 .../lib/LatencyBenchmarkRunner.h  |  3 ++
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 37 +++--
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 10 +++-
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 35 +
 llvm/tools/llvm-exegesis/lib/Target.h | 13 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.cpp | 37 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.h   |  9 +++-
 llvm/tools/llvm-exegesis/lib/X86/Target.cpp   | 11 +++-
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++-
 .../tools/llvm-exegesis/ClusteringTest.cpp| 36 ++---
 .../Mips/BenchmarkResultTest.cpp  | 12 ++---
 .../llvm-exegesis/X86/BenchmarkResultTest.cpp | 12 ++---
 18 files changed, 311 insertions(+), 97 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 02c4da11e032d6..1079df24b457b8 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -192,6 +193,56 @@ template <> struct 
SequenceElementTraits {
   static const bool flow = false;
 };
 
+const char *validationEventToString(exegesis::ValidationEvent VE) {
+  switch (VE) {
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-load-miss";
+  case exegesis::ValidationEvent::InstructionRetired:
+return "instructions-retired";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  }
+}
+
+Expected stringToValidationEvent(StringRef Input) {
+  if (Input == "l1d-load-miss")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "instructions-retired")
+return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else
+return make_error("Invalid validation event string",
+   errc::invalid_argument);
+}
+
+template <>
+struct CustomMappingTraits<
+std::unordered_map> {
+  static void
+  inputOne(IO , StringRef KeyStr,
+   std::unordered_map ) {
+Expected Key = stringToValidationEvent(KeyStr);
+if (!Key) {
+  Io.setError("Key is not a valid validation event");
+  return;
+}
+Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
+  }
+
+  static void
+  output(IO , std::unordered_map ) {
+for (auto  : VI) {
+  Io.mapRequired(validationEventToString(IndividualVI.first),
+ IndividualVI.second);
+}
+  }
+};
+
 // exegesis::Measure is rendererd as a flow instead of a list.
 // e.g. { "key": "the key", "value": 0123 }
 template <> struct MappingTraits {
@@ -203,6 +254,7 @@ template <> struct 
MappingTraits {
 }
 Io.mapRequired("value", Obj.PerInstructionValue);
 Io.mapOptional("per_snippet_value", Obj.PerSnippetValue);
+Io.mapOptional("validation_counters", Obj.ValidationCounters);
   }
   static const bool flow = true;
 };
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 0d08febae20cb3..f142da07e0a47d 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -32,6 +32,13 @@ class Error;
 
 namespace exegesis {
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 enum class 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-02 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 76f199f4fc7244c3d972736595c685d7316c5203 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 18:18:12 -0800
Subject: [PATCH 1/2] [llvm-exegesis] Add support for validation counters

This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 52 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +-
 .../llvm-exegesis/lib/BenchmarkRunner.cpp | 52 +--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.h |  8 ++-
 .../lib/LatencyBenchmarkRunner.cpp| 46 
 .../lib/LatencyBenchmarkRunner.h  |  3 ++
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 37 +++--
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 10 +++-
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 35 +
 llvm/tools/llvm-exegesis/lib/Target.h | 13 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.cpp | 37 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.h   |  9 +++-
 llvm/tools/llvm-exegesis/lib/X86/Target.cpp   | 11 +++-
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++-
 .../tools/llvm-exegesis/ClusteringTest.cpp| 36 ++---
 .../Mips/BenchmarkResultTest.cpp  | 12 ++---
 .../llvm-exegesis/X86/BenchmarkResultTest.cpp | 12 ++---
 18 files changed, 311 insertions(+), 97 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 02c4da11e032d6..1079df24b457b8 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -192,6 +193,56 @@ template <> struct 
SequenceElementTraits {
   static const bool flow = false;
 };
 
+const char *validationEventToString(exegesis::ValidationEvent VE) {
+  switch (VE) {
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-load-miss";
+  case exegesis::ValidationEvent::InstructionRetired:
+return "instructions-retired";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  }
+}
+
+Expected stringToValidationEvent(StringRef Input) {
+  if (Input == "l1d-load-miss")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "instructions-retired")
+return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else
+return make_error("Invalid validation event string",
+   errc::invalid_argument);
+}
+
+template <>
+struct CustomMappingTraits<
+std::unordered_map> {
+  static void
+  inputOne(IO , StringRef KeyStr,
+   std::unordered_map ) {
+Expected Key = stringToValidationEvent(KeyStr);
+if (!Key) {
+  Io.setError("Key is not a valid validation event");
+  return;
+}
+Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
+  }
+
+  static void
+  output(IO , std::unordered_map ) {
+for (auto  : VI) {
+  Io.mapRequired(validationEventToString(IndividualVI.first),
+ IndividualVI.second);
+}
+  }
+};
+
 // exegesis::Measure is rendererd as a flow instead of a list.
 // e.g. { "key": "the key", "value": 0123 }
 template <> struct MappingTraits {
@@ -203,6 +254,7 @@ template <> struct 
MappingTraits {
 }
 Io.mapRequired("value", Obj.PerInstructionValue);
 Io.mapOptional("per_snippet_value", Obj.PerSnippetValue);
+Io.mapOptional("validation_counters", Obj.ValidationCounters);
   }
   static const bool flow = true;
 };
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 0d08febae20cb3..f142da07e0a47d 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -32,6 +32,13 @@ class Error;
 
 namespace exegesis {
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 enum class 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add tablegen support for validation counters (PR #76652)

2024-01-02 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76652

>From 75261b9626878b92fa4bde2b4801815251238748 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 17:03:59 -0800
Subject: [PATCH 1/2] [llvm-exegesis] Add tablegen support for validation
 counters

---
 llvm/include/llvm/Target/TargetPfmCounters.td | 19 +
 llvm/lib/Target/X86/X86PfmCounters.td |  6 
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 13 +
 llvm/tools/llvm-exegesis/lib/Target.h | 11 
 llvm/utils/TableGen/ExegesisEmitter.cpp   | 28 +--
 5 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index b00f3e19c35f90..72f6b39f4878f4 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -28,6 +28,22 @@ class PfmIssueCounter
   string ResourceName = resource_name;
 }
 
+class ValidationEvent  {
+  int EventNumber = event_number;
+}
+
+def L1DCacheLoadMiss: ValidationEvent<0>;
+def InstructionRetired  : ValidationEvent<1>;
+def DataTLBLoadMiss : ValidationEvent<2>;
+def DataTLBStoreMiss: ValidationEvent<3>;
+
+// Validation counters can be tied to a specific event
+class PfmValidationCounter
+: PfmCounter {
+  // The name of the event that the validation counter detects.
+  ValidationEvent EventType = event_type;
+}
+
 def NoPfmCounter : PfmCounter <""> {}
 
 // Set of PfmCounters for measuring sched model characteristics.
@@ -38,6 +54,9 @@ class ProcPfmCounters {
   PfmCounter UopsCounter = NoPfmCounter;
   // Processors can define how to measure issued uops by defining 
IssueCounters.
   list IssueCounters = [];
+  // Processor can list mappings between validation events and real counters
+  // to measure the specified events.
+  list ValidationCounters = [];
 }
 
 // A binding of a set of counters to a CPU.
diff --git a/llvm/lib/Target/X86/X86PfmCounters.td 
b/llvm/lib/Target/X86/X86PfmCounters.td
index 49ef6efc6aecf2..99cac504f157d3 100644
--- a/llvm/lib/Target/X86/X86PfmCounters.td
+++ b/llvm/lib/Target/X86/X86PfmCounters.td
@@ -275,6 +275,9 @@ def ZnVer2PfmCounters : ProcPfmCounters {
 PfmIssueCounter<"Zn2AGU", "ls_dispatch:ld_st_dispatch + 
ls_dispatch:ld_dispatch + ls_dispatch:store_dispatch">,
 PfmIssueCounter<"Zn2Divider", "div_op_count">
   ];
+  let ValidationCounters = [
+PfmValidationCounter
+  ];
 }
 def : PfmCountersBinding<"znver2", ZnVer2PfmCounters>;
 
@@ -288,6 +291,9 @@ def ZnVer3PfmCounters : ProcPfmCounters {
 PfmIssueCounter<"Zn3Store", "ls_dispatch:store_dispatch">,
 PfmIssueCounter<"Zn3Divider", "div_op_count">
   ];
+  let ValidationCounters = [
+PfmValidationCounter
+  ];
 }
 def : PfmCountersBinding<"znver3", ZnVer3PfmCounters>;
 
diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp 
b/llvm/tools/llvm-exegesis/lib/Target.cpp
index 23c80e5b98953a..20b4afb9b8f676 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -147,13 +147,14 @@ std::unique_ptr 
ExegesisTarget::createUopsBenchmarkRunner(
ExecutionMode);
 }
 
-static_assert(std::is_trivial_v,
-  "We shouldn't have dynamic initialization here");
-const PfmCountersInfo PfmCountersInfo::Default = {nullptr, nullptr, nullptr,
-  0u};
+const PfmCountersInfo PfmCountersInfo::Default = {
+nullptr, nullptr, nullptr, 0u, {}};
 const PfmCountersInfo PfmCountersInfo::Dummy = {
-pfm::PerfEvent::DummyEventString, pfm::PerfEvent::DummyEventString, 
nullptr,
-0u};
+pfm::PerfEvent::DummyEventString,
+pfm::PerfEvent::DummyEventString,
+nullptr,
+0u,
+{}};
 
 const PfmCountersInfo ::getPfmCounters(StringRef CpuName) const 
{
   assert(llvm::is_sorted(
diff --git a/llvm/tools/llvm-exegesis/lib/Target.h 
b/llvm/tools/llvm-exegesis/lib/Target.h
index c37dd8b7082162..3956bc983181f6 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.h
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -32,6 +32,8 @@
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include "llvm/TargetParser/Triple.h"
 
+#include 
+
 namespace llvm {
 namespace exegesis {
 
@@ -39,6 +41,13 @@ extern cl::OptionCategory Options;
 extern cl::OptionCategory BenchmarkOptions;
 extern cl::OptionCategory AnalysisOptions;
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 struct PfmCountersInfo {
   // An optional name of a performance counter that can be used to measure
   // cycles.
@@ -59,6 +68,8 @@ struct PfmCountersInfo {
   const IssueCounter *IssueCounters;
   unsigned NumIssueCounters;
 
+  std::unordered_map ValidationCounters;
+
   static const PfmCountersInfo Default;
   static const PfmCountersInfo Dummy;
 };
diff --git 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2023-12-30 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/76653

>From 76f199f4fc7244c3d972736595c685d7316c5203 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 18:18:12 -0800
Subject: [PATCH 1/2] [llvm-exegesis] Add support for validation counters

This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 52 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +-
 .../llvm-exegesis/lib/BenchmarkRunner.cpp | 52 +--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.h |  8 ++-
 .../lib/LatencyBenchmarkRunner.cpp| 46 
 .../lib/LatencyBenchmarkRunner.h  |  3 ++
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 37 +++--
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 10 +++-
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 35 +
 llvm/tools/llvm-exegesis/lib/Target.h | 13 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.cpp | 37 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.h   |  9 +++-
 llvm/tools/llvm-exegesis/lib/X86/Target.cpp   | 11 +++-
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++-
 .../tools/llvm-exegesis/ClusteringTest.cpp| 36 ++---
 .../Mips/BenchmarkResultTest.cpp  | 12 ++---
 .../llvm-exegesis/X86/BenchmarkResultTest.cpp | 12 ++---
 18 files changed, 311 insertions(+), 97 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 02c4da11e032d6..1079df24b457b8 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -192,6 +193,56 @@ template <> struct 
SequenceElementTraits {
   static const bool flow = false;
 };
 
+const char *validationEventToString(exegesis::ValidationEvent VE) {
+  switch (VE) {
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-load-miss";
+  case exegesis::ValidationEvent::InstructionRetired:
+return "instructions-retired";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  }
+}
+
+Expected stringToValidationEvent(StringRef Input) {
+  if (Input == "l1d-load-miss")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "instructions-retired")
+return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else
+return make_error("Invalid validation event string",
+   errc::invalid_argument);
+}
+
+template <>
+struct CustomMappingTraits<
+std::unordered_map> {
+  static void
+  inputOne(IO , StringRef KeyStr,
+   std::unordered_map ) {
+Expected Key = stringToValidationEvent(KeyStr);
+if (!Key) {
+  Io.setError("Key is not a valid validation event");
+  return;
+}
+Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
+  }
+
+  static void
+  output(IO , std::unordered_map ) {
+for (auto  : VI) {
+  Io.mapRequired(validationEventToString(IndividualVI.first),
+ IndividualVI.second);
+}
+  }
+};
+
 // exegesis::Measure is rendererd as a flow instead of a list.
 // e.g. { "key": "the key", "value": 0123 }
 template <> struct MappingTraits {
@@ -203,6 +254,7 @@ template <> struct 
MappingTraits {
 }
 Io.mapRequired("value", Obj.PerInstructionValue);
 Io.mapOptional("per_snippet_value", Obj.PerSnippetValue);
+Io.mapOptional("validation_counters", Obj.ValidationCounters);
   }
   static const bool flow = true;
 };
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 0d08febae20cb3..f142da07e0a47d 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -32,6 +32,13 @@ class Error;
 
 namespace exegesis {
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 enum class 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2023-12-30 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/76653

This patch adds support for validation counters. Validation counters can be 
used to measure events that occur during snippet execution like cache misses to 
ensure that certain assumed invariants about the benchmark actually hold. 
Validation counters are setup within a perf event group, so are turned on and 
off at exactly the same time as the "group leader" counter that measures the 
desired value.

>From 76f199f4fc7244c3d972736595c685d7316c5203 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 18:18:12 -0800
Subject: [PATCH] [llvm-exegesis] Add support for validation counters

This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
---
 .../llvm-exegesis/lib/BenchmarkResult.cpp | 52 +++
 .../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +-
 .../llvm-exegesis/lib/BenchmarkRunner.cpp | 52 +--
 .../tools/llvm-exegesis/lib/BenchmarkRunner.h |  8 ++-
 .../lib/LatencyBenchmarkRunner.cpp| 46 
 .../lib/LatencyBenchmarkRunner.h  |  3 ++
 llvm/tools/llvm-exegesis/lib/PerfHelper.cpp   | 37 +++--
 llvm/tools/llvm-exegesis/lib/PerfHelper.h | 10 +++-
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 35 +
 llvm/tools/llvm-exegesis/lib/Target.h | 13 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.cpp | 37 ++---
 .../llvm-exegesis/lib/UopsBenchmarkRunner.h   |  9 +++-
 llvm/tools/llvm-exegesis/lib/X86/Target.cpp   | 11 +++-
 .../llvm-exegesis/lib/X86/X86Counter.cpp  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 18 ++-
 .../tools/llvm-exegesis/ClusteringTest.cpp| 36 ++---
 .../Mips/BenchmarkResultTest.cpp  | 12 ++---
 .../llvm-exegesis/X86/BenchmarkResultTest.cpp | 12 ++---
 18 files changed, 311 insertions(+), 97 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 02c4da11e032d6..1079df24b457b8 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/bit.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -192,6 +193,56 @@ template <> struct 
SequenceElementTraits {
   static const bool flow = false;
 };
 
+const char *validationEventToString(exegesis::ValidationEvent VE) {
+  switch (VE) {
+  case exegesis::ValidationEvent::L1DCacheLoadMiss:
+return "l1d-load-miss";
+  case exegesis::ValidationEvent::InstructionRetired:
+return "instructions-retired";
+  case exegesis::ValidationEvent::DataTLBLoadMiss:
+return "data-tlb-load-misses";
+  case exegesis::ValidationEvent::DataTLBStoreMiss:
+return "data-tlb-store-misses";
+  }
+}
+
+Expected stringToValidationEvent(StringRef Input) {
+  if (Input == "l1d-load-miss")
+return exegesis::ValidationEvent::L1DCacheLoadMiss;
+  else if (Input == "instructions-retired")
+return exegesis::ValidationEvent::InstructionRetired;
+  else if (Input == "data-tlb-load-misses")
+return exegesis::ValidationEvent::DataTLBLoadMiss;
+  else if (Input == "data-tlb-store-misses")
+return exegesis::ValidationEvent::DataTLBStoreMiss;
+  else
+return make_error("Invalid validation event string",
+   errc::invalid_argument);
+}
+
+template <>
+struct CustomMappingTraits<
+std::unordered_map> {
+  static void
+  inputOne(IO , StringRef KeyStr,
+   std::unordered_map ) {
+Expected Key = stringToValidationEvent(KeyStr);
+if (!Key) {
+  Io.setError("Key is not a valid validation event");
+  return;
+}
+Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
+  }
+
+  static void
+  output(IO , std::unordered_map ) {
+for (auto  : VI) {
+  Io.mapRequired(validationEventToString(IndividualVI.first),
+ IndividualVI.second);
+}
+  }
+};
+
 // exegesis::Measure is rendererd as a flow instead of a list.
 // e.g. { "key": "the key", "value": 0123 }
 template <> struct MappingTraits {
@@ -203,6 +254,7 @@ template <> struct 
MappingTraits {
 }
 Io.mapRequired("value", Obj.PerInstructionValue);
 Io.mapOptional("per_snippet_value", Obj.PerSnippetValue);
+Io.mapOptional("validation_counters", Obj.ValidationCounters);
   }
   static const bool flow = true;
 };
diff --git 

[llvm-branch-commits] [llvm] [llvm-exegesis] Add tablegen support for validation counters (PR #76652)

2023-12-30 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/76652

This patch adds support in the llvm-exegesis tablegen emitter for validation 
counters. Full support for validation counters in llvm-exegesis is added in a 
future patch.

>From 75261b9626878b92fa4bde2b4801815251238748 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 30 Dec 2023 17:03:59 -0800
Subject: [PATCH] [llvm-exegesis] Add tablegen support for validation counters

---
 llvm/include/llvm/Target/TargetPfmCounters.td | 19 +
 llvm/lib/Target/X86/X86PfmCounters.td |  6 
 llvm/tools/llvm-exegesis/lib/Target.cpp   | 13 +
 llvm/tools/llvm-exegesis/lib/Target.h | 11 
 llvm/utils/TableGen/ExegesisEmitter.cpp   | 28 +--
 5 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td 
b/llvm/include/llvm/Target/TargetPfmCounters.td
index b00f3e19c35f90..72f6b39f4878f4 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -28,6 +28,22 @@ class PfmIssueCounter
   string ResourceName = resource_name;
 }
 
+class ValidationEvent  {
+  int EventNumber = event_number;
+}
+
+def L1DCacheLoadMiss: ValidationEvent<0>;
+def InstructionRetired  : ValidationEvent<1>;
+def DataTLBLoadMiss : ValidationEvent<2>;
+def DataTLBStoreMiss: ValidationEvent<3>;
+
+// Validation counters can be tied to a specific event
+class PfmValidationCounter
+: PfmCounter {
+  // The name of the event that the validation counter detects.
+  ValidationEvent EventType = event_type;
+}
+
 def NoPfmCounter : PfmCounter <""> {}
 
 // Set of PfmCounters for measuring sched model characteristics.
@@ -38,6 +54,9 @@ class ProcPfmCounters {
   PfmCounter UopsCounter = NoPfmCounter;
   // Processors can define how to measure issued uops by defining 
IssueCounters.
   list IssueCounters = [];
+  // Processor can list mappings between validation events and real counters
+  // to measure the specified events.
+  list ValidationCounters = [];
 }
 
 // A binding of a set of counters to a CPU.
diff --git a/llvm/lib/Target/X86/X86PfmCounters.td 
b/llvm/lib/Target/X86/X86PfmCounters.td
index 49ef6efc6aecf2..99cac504f157d3 100644
--- a/llvm/lib/Target/X86/X86PfmCounters.td
+++ b/llvm/lib/Target/X86/X86PfmCounters.td
@@ -275,6 +275,9 @@ def ZnVer2PfmCounters : ProcPfmCounters {
 PfmIssueCounter<"Zn2AGU", "ls_dispatch:ld_st_dispatch + 
ls_dispatch:ld_dispatch + ls_dispatch:store_dispatch">,
 PfmIssueCounter<"Zn2Divider", "div_op_count">
   ];
+  let ValidationCounters = [
+PfmValidationCounter
+  ];
 }
 def : PfmCountersBinding<"znver2", ZnVer2PfmCounters>;
 
@@ -288,6 +291,9 @@ def ZnVer3PfmCounters : ProcPfmCounters {
 PfmIssueCounter<"Zn3Store", "ls_dispatch:store_dispatch">,
 PfmIssueCounter<"Zn3Divider", "div_op_count">
   ];
+  let ValidationCounters = [
+PfmValidationCounter
+  ];
 }
 def : PfmCountersBinding<"znver3", ZnVer3PfmCounters>;
 
diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp 
b/llvm/tools/llvm-exegesis/lib/Target.cpp
index 23c80e5b98953a..20b4afb9b8f676 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -147,13 +147,14 @@ std::unique_ptr 
ExegesisTarget::createUopsBenchmarkRunner(
ExecutionMode);
 }
 
-static_assert(std::is_trivial_v,
-  "We shouldn't have dynamic initialization here");
-const PfmCountersInfo PfmCountersInfo::Default = {nullptr, nullptr, nullptr,
-  0u};
+const PfmCountersInfo PfmCountersInfo::Default = {
+nullptr, nullptr, nullptr, 0u, {}};
 const PfmCountersInfo PfmCountersInfo::Dummy = {
-pfm::PerfEvent::DummyEventString, pfm::PerfEvent::DummyEventString, 
nullptr,
-0u};
+pfm::PerfEvent::DummyEventString,
+pfm::PerfEvent::DummyEventString,
+nullptr,
+0u,
+{}};
 
 const PfmCountersInfo ::getPfmCounters(StringRef CpuName) const 
{
   assert(llvm::is_sorted(
diff --git a/llvm/tools/llvm-exegesis/lib/Target.h 
b/llvm/tools/llvm-exegesis/lib/Target.h
index c37dd8b7082162..3956bc983181f6 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.h
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -32,6 +32,8 @@
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include "llvm/TargetParser/Triple.h"
 
+#include 
+
 namespace llvm {
 namespace exegesis {
 
@@ -39,6 +41,13 @@ extern cl::OptionCategory Options;
 extern cl::OptionCategory BenchmarkOptions;
 extern cl::OptionCategory AnalysisOptions;
 
+enum ValidationEvent {
+  L1DCacheLoadMiss,
+  InstructionRetired,
+  DataTLBLoadMiss,
+  DataTLBStoreMiss
+};
+
 struct PfmCountersInfo {
   // An optional name of a performance counter that can be used to measure
   // cycles.
@@ -59,6 +68,8 @@ struct PfmCountersInfo {
   const IssueCounter *IssueCounters;
   unsigned NumIssueCounters;
 
+  

[llvm-branch-commits] [llvm] [llvm-exegesis] Minor changes for downstream consumers (PR #74211)

2023-12-07 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 closed 
https://github.com/llvm/llvm-project/pull/74211
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Minor changes for downstream consumers (PR #74211)

2023-12-07 Thread Aiden Grossman via llvm-branch-commits

boomanaiden154 wrote:

Closed in favor of #74711. Will add the getter as part of #74210.

https://github.com/llvm/llvm-project/pull/74211
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Minor changes for downstream consumers (PR #74211)

2023-12-07 Thread Aiden Grossman via llvm-branch-commits

boomanaiden154 wrote:

Bump on this when reviewers have a chance. Thanks!

https://github.com/llvm/llvm-project/pull/74211
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Minor changes for downstream consumers (PR #74211)

2023-12-02 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/74211

>From 2bddb1011489651cb2e5f2f94d5fae89ddf63216 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 2 Dec 2023 14:18:50 -0800
Subject: [PATCH 1/2] [llvm-exegesis] Minor changes for downstream consumers

This patch adjust the runConfiguration function to allow passing a
parameter to force returning SnippetCrashes as errors rather than
serializing them as strings in the returned Benchmark object. In
addition, this patch adds a getter for the signal information address in
the SnippetCrash object.

These are both needed to allow for downstream consumption of the
exegesis library within Gematria.
---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 7 ---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h   | 6 +++---
 llvm/tools/llvm-exegesis/lib/Error.h | 2 ++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index f5d73a8bd6a31..51c9c6cd09358 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -545,9 +545,10 @@ BenchmarkRunner::createFunctionExecutor(
   llvm_unreachable("ExecutionMode is outside expected range");
 }
 
-Expected BenchmarkRunner::runConfiguration(
-RunnableConfiguration &,
-const std::optional ) const {
+Expected
+BenchmarkRunner::runConfiguration(RunnableConfiguration &,
+  const std::optional ,
+  bool ErrorOnSnippetCrash /*= false*/) const {
   Benchmark  = RC.InstrBenchmark;
   object::OwningBinary  = RC.ObjectFile;
 
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
index 24f2086289408..eb8c9f55722ca 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
@@ -65,9 +65,9 @@ class BenchmarkRunner {
unsigned NumRepetitions, unsigned LoopUnrollFactor,
const SnippetRepetitor ) const;
 
-  Expected
-  runConfiguration(RunnableConfiguration &,
-   const std::optional ) const;
+  Expected runConfiguration(RunnableConfiguration &,
+   const std::optional 
,
+   bool ErrorOnSnippetCrash = false) const;
 
   // Scratch space to run instructions that touch memory.
   struct ScratchSpace {
diff --git a/llvm/tools/llvm-exegesis/lib/Error.h 
b/llvm/tools/llvm-exegesis/lib/Error.h
index 8d3f394ed8d6e..8c95439d63ac6 100644
--- a/llvm/tools/llvm-exegesis/lib/Error.h
+++ b/llvm/tools/llvm-exegesis/lib/Error.h
@@ -52,6 +52,8 @@ class SnippetCrash : public ErrorInfo {
 
   std::error_code convertToErrorCode() const override;
 
+  intptr_t GetCrashAddress() const { return SIAddress; }
+
 private:
   std::string Msg;
   intptr_t SIAddress;

>From f13b5d31450a095d6e11176b3db787f1e0894337 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 2 Dec 2023 14:31:33 -0800
Subject: [PATCH 2/2] Actually update code

---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 51c9c6cd09358..bda7fb8b6ba9c 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -576,7 +576,7 @@ BenchmarkRunner::runConfiguration(RunnableConfiguration 
&,
   auto NewMeasurements = runMeasurements(**Executor);
 
   if (Error E = NewMeasurements.takeError()) {
-if (!E.isA())
+if (!E.isA() || ErrorOnSnippetCrash)
   return std::move(E);
 InstrBenchmark.Error = toString(std::move(E));
 return std::move(InstrBenchmark);

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] f13b5d3 - Actually update code

2023-12-02 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-12-02T14:31:33-08:00
New Revision: f13b5d31450a095d6e11176b3db787f1e0894337

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

LOG: Actually update code

Added: 


Modified: 
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

Removed: 




diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 51c9c6cd0935..bda7fb8b6ba9 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -576,7 +576,7 @@ BenchmarkRunner::runConfiguration(RunnableConfiguration 
&,
   auto NewMeasurements = runMeasurements(**Executor);
 
   if (Error E = NewMeasurements.takeError()) {
-if (!E.isA())
+if (!E.isA() || ErrorOnSnippetCrash)
   return std::move(E);
 InstrBenchmark.Error = toString(std::move(E));
 return std::move(InstrBenchmark);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Minor changes for downstream consumers (PR #74211)

2023-12-02 Thread Aiden Grossman via llvm-branch-commits

boomanaiden154 wrote:

This seemed to be the most minimally invasive set of changes to achieve what I 
needed to be able to use things downstream. I tried a couple alternatives, but 
couldn't get them to work or they weren't as clean. Happy if there are other 
suggestions that make things cleaner however.

https://github.com/llvm/llvm-project/pull/74211
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Minor changes for downstream consumers (PR #74211)

2023-12-02 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/74211

This patch adjust the runConfiguration function to allow passing a parameter to 
force returning SnippetCrashes as errors rather than serializing them as 
strings in the returned Benchmark object. In addition, this patch adds a getter 
for the signal information address in the SnippetCrash object.

These are both needed to allow for downstream consumption of the exegesis 
library within Gematria.

>From 2bddb1011489651cb2e5f2f94d5fae89ddf63216 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 2 Dec 2023 14:18:50 -0800
Subject: [PATCH] [llvm-exegesis] Minor changes for downstream consumers

This patch adjust the runConfiguration function to allow passing a
parameter to force returning SnippetCrashes as errors rather than
serializing them as strings in the returned Benchmark object. In
addition, this patch adds a getter for the signal information address in
the SnippetCrash object.

These are both needed to allow for downstream consumption of the
exegesis library within Gematria.
---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 7 ---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h   | 6 +++---
 llvm/tools/llvm-exegesis/lib/Error.h | 2 ++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index f5d73a8bd6a31..51c9c6cd09358 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -545,9 +545,10 @@ BenchmarkRunner::createFunctionExecutor(
   llvm_unreachable("ExecutionMode is outside expected range");
 }
 
-Expected BenchmarkRunner::runConfiguration(
-RunnableConfiguration &,
-const std::optional ) const {
+Expected
+BenchmarkRunner::runConfiguration(RunnableConfiguration &,
+  const std::optional ,
+  bool ErrorOnSnippetCrash /*= false*/) const {
   Benchmark  = RC.InstrBenchmark;
   object::OwningBinary  = RC.ObjectFile;
 
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
index 24f2086289408..eb8c9f55722ca 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
@@ -65,9 +65,9 @@ class BenchmarkRunner {
unsigned NumRepetitions, unsigned LoopUnrollFactor,
const SnippetRepetitor ) const;
 
-  Expected
-  runConfiguration(RunnableConfiguration &,
-   const std::optional ) const;
+  Expected runConfiguration(RunnableConfiguration &,
+   const std::optional 
,
+   bool ErrorOnSnippetCrash = false) const;
 
   // Scratch space to run instructions that touch memory.
   struct ScratchSpace {
diff --git a/llvm/tools/llvm-exegesis/lib/Error.h 
b/llvm/tools/llvm-exegesis/lib/Error.h
index 8d3f394ed8d6e..8c95439d63ac6 100644
--- a/llvm/tools/llvm-exegesis/lib/Error.h
+++ b/llvm/tools/llvm-exegesis/lib/Error.h
@@ -52,6 +52,8 @@ class SnippetCrash : public ErrorInfo {
 
   std::error_code convertToErrorCode() const override;
 
+  intptr_t GetCrashAddress() const { return SIAddress; }
+
 private:
   std::string Msg;
   intptr_t SIAddress;

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 2bddb10 - [llvm-exegesis] Minor changes for downstream consumers

2023-12-02 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-12-02T14:20:11-08:00
New Revision: 2bddb1011489651cb2e5f2f94d5fae89ddf63216

URL: 
https://github.com/llvm/llvm-project/commit/2bddb1011489651cb2e5f2f94d5fae89ddf63216
DIFF: 
https://github.com/llvm/llvm-project/commit/2bddb1011489651cb2e5f2f94d5fae89ddf63216.diff

LOG: [llvm-exegesis] Minor changes for downstream consumers

This patch adjust the runConfiguration function to allow passing a
parameter to force returning SnippetCrashes as errors rather than
serializing them as strings in the returned Benchmark object. In
addition, this patch adds a getter for the signal information address in
the SnippetCrash object.

These are both needed to allow for downstream consumption of the
exegesis library within Gematria.

Added: 


Modified: 
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
llvm/tools/llvm-exegesis/lib/Error.h

Removed: 




diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index f5d73a8bd6a31..51c9c6cd09358 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -545,9 +545,10 @@ BenchmarkRunner::createFunctionExecutor(
   llvm_unreachable("ExecutionMode is outside expected range");
 }
 
-Expected BenchmarkRunner::runConfiguration(
-RunnableConfiguration &,
-const std::optional ) const {
+Expected
+BenchmarkRunner::runConfiguration(RunnableConfiguration &,
+  const std::optional ,
+  bool ErrorOnSnippetCrash /*= false*/) const {
   Benchmark  = RC.InstrBenchmark;
   object::OwningBinary  = RC.ObjectFile;
 

diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
index 24f2086289408..eb8c9f55722ca 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
@@ -65,9 +65,9 @@ class BenchmarkRunner {
unsigned NumRepetitions, unsigned LoopUnrollFactor,
const SnippetRepetitor ) const;
 
-  Expected
-  runConfiguration(RunnableConfiguration &,
-   const std::optional ) const;
+  Expected runConfiguration(RunnableConfiguration &,
+   const std::optional 
,
+   bool ErrorOnSnippetCrash = false) const;
 
   // Scratch space to run instructions that touch memory.
   struct ScratchSpace {

diff  --git a/llvm/tools/llvm-exegesis/lib/Error.h 
b/llvm/tools/llvm-exegesis/lib/Error.h
index 8d3f394ed8d6e..8c95439d63ac6 100644
--- a/llvm/tools/llvm-exegesis/lib/Error.h
+++ b/llvm/tools/llvm-exegesis/lib/Error.h
@@ -52,6 +52,8 @@ class SnippetCrash : public ErrorInfo {
 
   std::error_code convertToErrorCode() const override;
 
+  intptr_t GetCrashAddress() const { return SIAddress; }
+
 private:
   std::string Msg;
   intptr_t SIAddress;



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 592ab21 - [llvm-exegesis] Add explicit error message with segfault address

2023-12-02 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-12-02T13:33:18-08:00
New Revision: 592ab2122dbe5c38712b5b9fc17126308783467a

URL: 
https://github.com/llvm/llvm-project/commit/592ab2122dbe5c38712b5b9fc17126308783467a
DIFF: 
https://github.com/llvm/llvm-project/commit/592ab2122dbe5c38712b5b9fc17126308783467a.diff

LOG: [llvm-exegesis] Add explicit error message with segfault address

This patch special cases the segfault case for the subprocess executor,
giving the exact address of a segfault when one occurs in the
subprocess. This makes it a lot easier to debug where things are going
wrong in the snippet.

Added: 


Modified: 
llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/Error.cpp
llvm/tools/llvm-exegesis/lib/Error.h

Removed: 




diff  --git a/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s 
b/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
index 92b08e1c18c62..db04f8522e4e0 100644
--- a/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
+++ b/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
@@ -2,7 +2,7 @@
 
 # RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mode=latency 
-snippets-file=%s -execution-mode=subprocess | FileCheck %s
 
-# CHECK: error:   'The benchmarking subprocess sent unexpected signal: 
Segmentation fault'
+# CHECK: error:   The snippet crashed with signal Segmentation fault 
at address 1
 
-# LLVM-EXEGESIS-DEFREG RBX 0
+# LLVM-EXEGESIS-DEFREG RBX 1
 movq (%rbx), %rax

diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 85375dec2a44c..f5d73a8bd6a31 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -374,8 +374,8 @@ class SubProcessFunctionExecutorImpl
 }
 
 return make_error(
-"The benchmarking subprocess sent unexpected signal: " +
-Twine(strsignal(ChildSignalInfo.si_signo)));
+ChildSignalInfo.si_signo,
+reinterpret_cast(ChildSignalInfo.si_addr));
   }
 
   [[noreturn]] void prepareAndRunBenchmark(int Pipe,

diff  --git a/llvm/tools/llvm-exegesis/lib/Error.cpp 
b/llvm/tools/llvm-exegesis/lib/Error.cpp
index 51ce41bf00bf5..213e54e3bcf53 100644
--- a/llvm/tools/llvm-exegesis/lib/Error.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Error.cpp
@@ -8,6 +8,10 @@
 
 #include "Error.h"
 
+#ifdef LLVM_ON_UNIX
+#include 
+#endif // LLVM_ON_UNIX
+
 namespace llvm {
 namespace exegesis {
 
@@ -21,7 +25,18 @@ std::error_code ClusteringError::convertToErrorCode() const {
 
 char SnippetCrash::ID;
 
-void SnippetCrash::log(raw_ostream ) const { OS << Msg; }
+void SnippetCrash::log(raw_ostream ) const {
+  if (SISignalNumber == -1) {
+OS << Msg;
+return;
+  }
+#ifdef LLVM_ON_UNIX
+  OS << "The snippet crashed with signal " << strsignal(SISignalNumber)
+ << " at address " << Twine::utohexstr(SIAddress);
+#else
+  OS << "The snippet crashed with a signal";
+#endif // LLVM_ON_UNIX
+}
 
 std::error_code SnippetCrash::convertToErrorCode() const {
   return inconvertibleErrorCode();

diff  --git a/llvm/tools/llvm-exegesis/lib/Error.h 
b/llvm/tools/llvm-exegesis/lib/Error.h
index e5fa093e6e125..8d3f394ed8d6e 100644
--- a/llvm/tools/llvm-exegesis/lib/Error.h
+++ b/llvm/tools/llvm-exegesis/lib/Error.h
@@ -12,6 +12,8 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Error.h"
 
+#include 
+
 namespace llvm {
 namespace exegesis {
 
@@ -41,7 +43,10 @@ class ClusteringError : public ErrorInfo {
 class SnippetCrash : public ErrorInfo {
 public:
   static char ID;
-  SnippetCrash(const Twine ) : Msg(S.str()) {}
+  SnippetCrash(const Twine )
+  : Msg(S.str()), SIAddress(-1), SISignalNumber(-1) {}
+  SnippetCrash(int SISignalNumber_, intptr_t SIAddress_)
+  : Msg(""), SIAddress(SIAddress_), SISignalNumber(SISignalNumber_) {}
 
   void log(raw_ostream ) const override;
 
@@ -49,6 +54,8 @@ class SnippetCrash : public ErrorInfo {
 
 private:
   std::string Msg;
+  intptr_t SIAddress;
+  int SISignalNumber;
 };
 
 } // namespace exegesis



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 2f81917 - [JumpThreading] Remove LVI printer flag

2023-11-26 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-26T23:35:55-08:00
New Revision: 2f81917739dd7931059bb65311160a44d9404d5a

URL: 
https://github.com/llvm/llvm-project/commit/2f81917739dd7931059bb65311160a44d9404d5a
DIFF: 
https://github.com/llvm/llvm-project/commit/2f81917739dd7931059bb65311160a44d9404d5a.diff

LOG: [JumpThreading] Remove LVI printer flag

This patch removes the -print-lvi-after-jump-threading flag now that we
can print everything in the LVI cache using the print
pass.

Added: 


Modified: 
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp 
b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 59a8b8ad494566c..dfc197ec745fa2d 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -102,11 +102,6 @@ static cl::opt PhiDuplicateThreshold(
 cl::desc("Max PHIs in BB to duplicate for jump threading"), cl::init(76),
 cl::Hidden);
 
-static cl::opt PrintLVIAfterJumpThreading(
-"print-lvi-after-jump-threading",
-cl::desc("Print the LazyValueInfo cache after JumpThreading"), 
cl::init(false),
-cl::Hidden);
-
 static cl::opt ThreadAcrossLoopHeaders(
 "jump-threading-across-loop-headers",
 cl::desc("Allow JumpThreading to thread across loop headers, for testing"),
@@ -257,11 +252,6 @@ PreservedAnalyses JumpThreadingPass::run(Function ,
   , nullptr, DomTreeUpdater::UpdateStrategy::Lazy),
   std::nullopt, std::nullopt);
 
-  if (PrintLVIAfterJumpThreading) {
-dbgs() << "LVI for function '" << F.getName() << "':\n";
-LVI.printLVI(F, getDomTreeUpdater()->getDomTree(), dbgs());
-  }
-
   if (!Changed)
 return PreservedAnalyses::all();
 

diff  --git a/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll 
b/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
index 418b575a186bb8f..847882febdbb0a5 100644
--- a/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
+++ b/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
@@ -1,5 +1,4 @@
-; RUN: opt < %s -passes=jump-threading -print-lvi-after-jump-threading 
-disable-output 2>&1 | FileCheck %s
-; RUN: opt < %s -passes=jump-threading -print-lvi-after-jump-threading 
-disable-output 2>&1 | FileCheck %s
+; RUN: opt < %s -passes="jump-threading,print" 
-disable-output 2>&1 | FileCheck %s
 
 ; Testing LVI cache after jump-threading
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [JumpThreading] Remove LVI printer flag (PR #73426)

2023-11-25 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/73426

This patch removes the -print-lvi-after-jump-threading flag now that we can 
print everything in the LVI cache using the print pass.

>From 7317f7018ce98afa2e58c7c8af166a849b4a1674 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 25 Nov 2023 21:29:11 -0800
Subject: [PATCH] [JumpThreading] Remove LVI printer flag

This patch removes the -print-lvi-after-jump-threading flag now that we
can print everything in the LVI cache using the print
pass.
---
 llvm/lib/Transforms/Scalar/JumpThreading.cpp   | 10 --
 .../LazyValueAnalysis/lvi-after-jumpthreading.ll   |  3 +--
 2 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp 
b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index d7d503427ec3d20..57a80854ee2b52b 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -102,11 +102,6 @@ static cl::opt PhiDuplicateThreshold(
 cl::desc("Max PHIs in BB to duplicate for jump threading"), cl::init(76),
 cl::Hidden);
 
-static cl::opt PrintLVIAfterJumpThreading(
-"print-lvi-after-jump-threading",
-cl::desc("Print the LazyValueInfo cache after JumpThreading"), 
cl::init(false),
-cl::Hidden);
-
 static cl::opt ThreadAcrossLoopHeaders(
 "jump-threading-across-loop-headers",
 cl::desc("Allow JumpThreading to thread across loop headers, for testing"),
@@ -257,11 +252,6 @@ PreservedAnalyses JumpThreadingPass::run(Function ,
   , nullptr, DomTreeUpdater::UpdateStrategy::Lazy),
   std::nullopt, std::nullopt);
 
-  if (PrintLVIAfterJumpThreading) {
-dbgs() << "LVI for function '" << F.getName() << "':\n";
-LVI.printLVI(F, getDomTreeUpdater()->getDomTree(), dbgs());
-  }
-
   if (!Changed)
 return PreservedAnalyses::all();
 
diff --git a/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll 
b/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
index 418b575a186bb8f..847882febdbb0a5 100644
--- a/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
+++ b/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
@@ -1,5 +1,4 @@
-; RUN: opt < %s -passes=jump-threading -print-lvi-after-jump-threading 
-disable-output 2>&1 | FileCheck %s
-; RUN: opt < %s -passes=jump-threading -print-lvi-after-jump-threading 
-disable-output 2>&1 | FileCheck %s
+; RUN: opt < %s -passes="jump-threading,print" 
-disable-output 2>&1 | FileCheck %s
 
 ; Testing LVI cache after jump-threading
 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 7317f70 - [JumpThreading] Remove LVI printer flag

2023-11-25 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-25T21:29:11-08:00
New Revision: 7317f7018ce98afa2e58c7c8af166a849b4a1674

URL: 
https://github.com/llvm/llvm-project/commit/7317f7018ce98afa2e58c7c8af166a849b4a1674
DIFF: 
https://github.com/llvm/llvm-project/commit/7317f7018ce98afa2e58c7c8af166a849b4a1674.diff

LOG: [JumpThreading] Remove LVI printer flag

This patch removes the -print-lvi-after-jump-threading flag now that we
can print everything in the LVI cache using the print
pass.

Added: 


Modified: 
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp 
b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index d7d503427ec3d20..57a80854ee2b52b 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -102,11 +102,6 @@ static cl::opt PhiDuplicateThreshold(
 cl::desc("Max PHIs in BB to duplicate for jump threading"), cl::init(76),
 cl::Hidden);
 
-static cl::opt PrintLVIAfterJumpThreading(
-"print-lvi-after-jump-threading",
-cl::desc("Print the LazyValueInfo cache after JumpThreading"), 
cl::init(false),
-cl::Hidden);
-
 static cl::opt ThreadAcrossLoopHeaders(
 "jump-threading-across-loop-headers",
 cl::desc("Allow JumpThreading to thread across loop headers, for testing"),
@@ -257,11 +252,6 @@ PreservedAnalyses JumpThreadingPass::run(Function ,
   , nullptr, DomTreeUpdater::UpdateStrategy::Lazy),
   std::nullopt, std::nullopt);
 
-  if (PrintLVIAfterJumpThreading) {
-dbgs() << "LVI for function '" << F.getName() << "':\n";
-LVI.printLVI(F, getDomTreeUpdater()->getDomTree(), dbgs());
-  }
-
   if (!Changed)
 return PreservedAnalyses::all();
 

diff  --git a/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll 
b/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
index 418b575a186bb8f..847882febdbb0a5 100644
--- a/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
+++ b/llvm/test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll
@@ -1,5 +1,4 @@
-; RUN: opt < %s -passes=jump-threading -print-lvi-after-jump-threading 
-disable-output 2>&1 | FileCheck %s
-; RUN: opt < %s -passes=jump-threading -print-lvi-after-jump-threading 
-disable-output 2>&1 | FileCheck %s
+; RUN: opt < %s -passes="jump-threading,print" 
-disable-output 2>&1 | FileCheck %s
 
 ; Testing LVI cache after jump-threading
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 0276bc1 - [LVI] Add NewPM printer pass

2023-11-25 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-25T21:20:29-08:00
New Revision: 0276bc121c06eebe3a031d72a971d84a20c7f1b5

URL: 
https://github.com/llvm/llvm-project/commit/0276bc121c06eebe3a031d72a971d84a20c7f1b5
DIFF: 
https://github.com/llvm/llvm-project/commit/0276bc121c06eebe3a031d72a971d84a20c7f1b5.diff

LOG: [LVI] Add NewPM printer pass

This patch adds a NewPM printer pass for the LazyValueAnalysis.

Added: 
llvm/test/Analysis/LazyValueAnalysis/print.ll

Modified: 
llvm/include/llvm/Analysis/LazyValueInfo.h
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/lib/Passes/PassRegistry.def

Removed: 




diff  --git a/llvm/include/llvm/Analysis/LazyValueInfo.h 
b/llvm/include/llvm/Analysis/LazyValueInfo.h
index f013a4a75d3d6ad..ead9f5f0225cd09 100644
--- a/llvm/include/llvm/Analysis/LazyValueInfo.h
+++ b/llvm/include/llvm/Analysis/LazyValueInfo.h
@@ -151,6 +151,17 @@ class LazyValueAnalysis : public 
AnalysisInfoMixin {
   friend struct AnalysisInfoMixin;
 };
 
+/// Printer pass for the LazyValueAnalysis results.
+class LazyValueInfoPrinterPass
+: public PassInfoMixin {
+  raw_ostream 
+
+public:
+  explicit LazyValueInfoPrinterPass(raw_ostream ) : OS(OS) {}
+
+  PreservedAnalyses run(Function , FunctionAnalysisManager );
+};
+
 /// Wrapper around LazyValueInfo.
 class LazyValueInfoWrapperPass : public FunctionPass {
   LazyValueInfoWrapperPass(const LazyValueInfoWrapperPass&) = delete;

diff  --git a/llvm/lib/Analysis/LazyValueInfo.cpp 
b/llvm/lib/Analysis/LazyValueInfo.cpp
index 5cb207c8036d40a..868824285301a09 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -2087,6 +2087,15 @@ void LazyValueInfoAnnotatedWriter::emitInstructionAnnot(
 
 }
 
+PreservedAnalyses LazyValueInfoPrinterPass::run(Function ,
+FunctionAnalysisManager ) {
+  OS << "LVI for function '" << F.getName() << "':\n";
+  auto  = AM.getResult(F);
+  auto  = AM.getResult(F);
+  LVI.printLVI(F, DTree, OS);
+  return PreservedAnalyses::all();
+}
+
 namespace {
 // Printer class for LazyValueInfo results.
 class LazyValueInfoPrinter : public FunctionPass {

diff  --git a/llvm/lib/Passes/PassRegistry.def 
b/llvm/lib/Passes/PassRegistry.def
index 2067fc473b522db..199a8e4622e35a3 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -400,6 +400,7 @@ FUNCTION_PASS("print", 
FunctionPropertiesPrinterPass(dbgs()))
 FUNCTION_PASS("print", InlineCostAnnotationPrinterPass(dbgs()))
 FUNCTION_PASS("print",
   InlineSizeEstimatorAnalysisPrinterPass(dbgs()))
+FUNCTION_PASS("print", LazyValueInfoPrinterPass(dbgs()))
 FUNCTION_PASS("print", LoopPrinterPass(dbgs()))
 FUNCTION_PASS("print", MemorySSAWalkerPrinterPass(dbgs()))
 FUNCTION_PASS("print", PhiValuesPrinterPass(dbgs()))

diff  --git a/llvm/test/Analysis/LazyValueAnalysis/print.ll 
b/llvm/test/Analysis/LazyValueAnalysis/print.ll
new file mode 100644
index 000..6b4938a5fd9e07b
--- /dev/null
+++ b/llvm/test/Analysis/LazyValueAnalysis/print.ll
@@ -0,0 +1,49 @@
+; RUN: opt %s -disable-output -passes="jump-threading,print" 
2>&1 | FileCheck %s
+
+; first to populate the values.
+
+define i32 @constraint(i32 %a) {
+; CHECK-LABEL: LVI for function 'constraint':
+chklt64:
+; CHECK-LABEL: chklt64:
+; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: overdefined
+; CHECK-NEXT: ; LatticeVal for: '  %cmp = icmp slt i32 %a, 64' in BB: 
'%chklt64' is: overdefined
+; CHECK-NEXT: ; LatticeVal for: '  %cmp = icmp slt i32 %a, 64' in BB: 
'%chkgt0' is: constantrange<-1, 0>
+; CHECK-NEXT: ; LatticeVal for: '  %cmp = icmp slt i32 %a, 64' in BB: 
'%notinbounds' is: overdefined
+; CHECK-NEXT:   %cmp = icmp slt i32 %a, 64
+; CHECK-NEXT: ; LatticeVal for: '  br i1 %cmp, label %chkgt0, label 
%notinbounds' in BB: '%chklt64' is: overdefined
+; CHECK-NEXT: ; LatticeVal for: '  br i1 %cmp, label %chkgt0, label 
%notinbounds' in BB: '%chkgt0' is: overdefined
+; CHECK-NEXT: ; LatticeVal for: '  br i1 %cmp, label %chkgt0, label 
%notinbounds' in BB: '%notinbounds' is: overdefined
+; CHECK-NEXT:   br i1 %cmp, label %chkgt0, label %notinbounds
+  %cmp = icmp slt i32 %a, 64
+  br i1 %cmp, label %chkgt0, label %notinbounds
+
+chkgt0:
+; CHECK-LABEL: chkgt0:
+; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: constantrange<-2147483648, 64>
+; CHECK-NEXT: ; LatticeVal for: '  %cmp1 = icmp sgt i32 %a, 0' in BB: 
'%chkgt0' is: overdefined
+; CHECK-NEXT: ; LatticeVal for: '  %cmp1 = icmp sgt i32 %a, 0' in BB: 
'%inbounds' is: constantrange<-1, 0>
+; CHECK-NEXT:   %cmp1 = icmp sgt i32 %a, 0
+; CHECK-NEXT: ; LatticeVal for: '  br i1 %cmp1, label %inbounds, label 
%notinbounds' in BB: '%chkgt0' is: overdefined
+; CHECK-NEXT: ; LatticeVal for: '  br i1 %cmp1, label %inbounds, label 
%notinbounds' in BB: '%inbounds' is: overdefined
+; CHECK-NEXT:   br i1 %cmp1, label %inbounds, label %notinbounds
+  %cmp1 = icmp sgt i32 %a, 0
+  br i1 

[llvm-branch-commits] [llvm] b76d51e - Assert symbol name, add comment about symbol naming

2023-11-24 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-24T02:17:07-08:00
New Revision: b76d51ee7c4bbc942e2860ab5fc0383f7a0d2fe1

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

LOG: Assert symbol name, add comment about symbol naming

Added: 


Modified: 
llvm/tools/llvm-exegesis/lib/Assembler.cpp

Removed: 




diff  --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp 
b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 54ba29ed04c6f95..903ecbe47b8da0f 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -332,7 +332,11 @@ Expected ExecutableFunction::create(
   std::unique_ptr Ctx = std::make_unique();
 
   auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
+  // Get the size of the function that we want to call into (with the name of
+  // FunctionID). This should always be the third symbol returned by
+  // calculateSymbolSizes.
   assert(SymbolSizes.size() == 3);
+  assert(cantFail(std::get<0>(SymbolSizes[2]).getName()) == FunctionID);
   uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);
 
   auto EJITOrErr = orc::LLJITBuilder().create();



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 4afbf8b - [llvm-exegesis] Switch from MCJIT to LLJIT

2023-11-24 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-24T02:17:07-08:00
New Revision: 4afbf8b5534ebcd15b488b738c242f012e224941

URL: 
https://github.com/llvm/llvm-project/commit/4afbf8b5534ebcd15b488b738c242f012e224941
DIFF: 
https://github.com/llvm/llvm-project/commit/4afbf8b5534ebcd15b488b738c242f012e224941.diff

LOG: [llvm-exegesis] Switch from MCJIT to LLJIT

This patch switches from using MCJIT to LLJIT as MCJIT is going to be
deprecated soon.

Added: 


Modified: 
llvm/tools/llvm-exegesis/lib/Assembler.cpp
llvm/tools/llvm-exegesis/lib/Assembler.h
llvm/tools/llvm-exegesis/lib/CMakeLists.txt

Removed: 




diff  --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp 
b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 9ff33258e965f7e..54ba29ed04c6f95 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -21,11 +21,12 @@
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/MC/MCInstrInfo.h"
+#include "llvm/Object/SymbolSize.h"
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
@@ -105,7 +106,7 @@ MachineFunction (StringRef 
FunctionName,
   FunctionType *FunctionType =
   FunctionType::get(ReturnType, {MemParamType}, false);
   Function *const F = Function::Create(
-  FunctionType, GlobalValue::InternalLinkage, FunctionName, Module);
+  FunctionType, GlobalValue::ExternalLinkage, FunctionName, Module);
   BasicBlock *BB = BasicBlock::Create(Module->getContext(), "", F);
   new UnreachableInst(Module->getContext(), BB);
   return MMI->getOrCreateMachineFunction(*F);
@@ -324,66 +325,44 @@ object::OwningBinary 
getObjectFromFile(StringRef Filename) {
   return cantFail(object::ObjectFile::createObjectFile(Filename));
 }
 
-namespace {
-
-// Implementation of this class relies on the fact that a single object with a
-// single function will be loaded into memory.
-class TrackingSectionMemoryManager : public SectionMemoryManager {
-public:
-  explicit TrackingSectionMemoryManager(uintptr_t *CodeSize)
-  : CodeSize(CodeSize) {}
-
-  uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
-   unsigned SectionID,
-   StringRef SectionName) override {
-*CodeSize = Size;
-return SectionMemoryManager::allocateCodeSection(Size, Alignment, 
SectionID,
- SectionName);
-  }
-
-private:
-  uintptr_t *const CodeSize = nullptr;
-};
-
-} // namespace
-
 Expected ExecutableFunction::create(
 std::unique_ptr TM,
 object::OwningBinary &) {
   assert(ObjectFileHolder.getBinary() && "cannot create object file");
   std::unique_ptr Ctx = std::make_unique();
-  // Initializing the execution engine.
-  // We need to use the JIT EngineKind to be able to add an object file.
-  LLVMLinkInMCJIT();
-  uintptr_t CodeSize = 0;
-  std::string Error;
-  std::unique_ptr EE(
-  EngineBuilder(createModule(Ctx, TM->createDataLayout()))
-  .setErrorStr()
-  .setMCPU(TM->getTargetCPU())
-  .setEngineKind(EngineKind::JIT)
-  .setMCJITMemoryManager(
-  std::make_unique())
-  .create(TM.release()));
-  if (!EE)
-return make_error(Twine(Error), inconvertibleErrorCode());
-  // Adding the generated object file containing the assembled function.
-  // The ExecutionEngine makes sure the object file is copied into an
-  // executable page.
-  EE->addObjectFile(std::move(ObjectFileHolder));
-  // Fetching function bytes.
-  const uint64_t FunctionAddress = EE->getFunctionAddress(FunctionID);
+
+  auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
+  assert(SymbolSizes.size() == 3);
+  uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);
+
+  auto EJITOrErr = orc::LLJITBuilder().create();
+  if (!EJITOrErr)
+return EJITOrErr.takeError();
+
+  auto EJIT = std::move(*EJITOrErr);
+
+  if (auto ObjErr =
+  EJIT->addObjectFile(std::get<1>(ObjectFileHolder.takeBinary(
+return ObjErr;
+
+  auto FunctionAddressOrErr = EJIT->lookup(FunctionID);
+  if (!FunctionAddressOrErr)
+return FunctionAddressOrErr.takeError();
+
+  const uint64_t FunctionAddress = FunctionAddressOrErr->getValue();
+
   assert(isAligned(kFunctionAlignment, FunctionAddress) &&
  "function is not properly aligned");
+
   StringRef FBytes =
   StringRef(reinterpret_cast(FunctionAddress), CodeSize);
-  return ExecutableFunction(std::move(Ctx), std::move(EE), FBytes);
+  return ExecutableFunction(std::move(Ctx), std::move(EJIT), FBytes);
 

[llvm-branch-commits] [llvm] [llvm-exegesis] Switch from MCJIT to LLJIT (PR #72838)

2023-11-24 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/72838

>From 9dfa6f5607ab945e2ba36da148c3669cdf723dc2 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Mon, 20 Nov 2023 00:42:01 -0800
Subject: [PATCH 1/2] [llvm-exegesis] Switch from MCJIT to LLJIT

This patch switches from using MCJIT to LLJIT as MCJIT is going to be
deprecated soon.
---
 llvm/tools/llvm-exegesis/lib/Assembler.cpp  | 77 -
 llvm/tools/llvm-exegesis/lib/Assembler.h|  7 +-
 llvm/tools/llvm-exegesis/lib/CMakeLists.txt |  2 +-
 3 files changed, 32 insertions(+), 54 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp 
b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 9ff33258e965f7e..54ba29ed04c6f95 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -21,11 +21,12 @@
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/MC/MCInstrInfo.h"
+#include "llvm/Object/SymbolSize.h"
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
@@ -105,7 +106,7 @@ MachineFunction (StringRef 
FunctionName,
   FunctionType *FunctionType =
   FunctionType::get(ReturnType, {MemParamType}, false);
   Function *const F = Function::Create(
-  FunctionType, GlobalValue::InternalLinkage, FunctionName, Module);
+  FunctionType, GlobalValue::ExternalLinkage, FunctionName, Module);
   BasicBlock *BB = BasicBlock::Create(Module->getContext(), "", F);
   new UnreachableInst(Module->getContext(), BB);
   return MMI->getOrCreateMachineFunction(*F);
@@ -324,66 +325,44 @@ object::OwningBinary 
getObjectFromFile(StringRef Filename) {
   return cantFail(object::ObjectFile::createObjectFile(Filename));
 }
 
-namespace {
-
-// Implementation of this class relies on the fact that a single object with a
-// single function will be loaded into memory.
-class TrackingSectionMemoryManager : public SectionMemoryManager {
-public:
-  explicit TrackingSectionMemoryManager(uintptr_t *CodeSize)
-  : CodeSize(CodeSize) {}
-
-  uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
-   unsigned SectionID,
-   StringRef SectionName) override {
-*CodeSize = Size;
-return SectionMemoryManager::allocateCodeSection(Size, Alignment, 
SectionID,
- SectionName);
-  }
-
-private:
-  uintptr_t *const CodeSize = nullptr;
-};
-
-} // namespace
-
 Expected ExecutableFunction::create(
 std::unique_ptr TM,
 object::OwningBinary &) {
   assert(ObjectFileHolder.getBinary() && "cannot create object file");
   std::unique_ptr Ctx = std::make_unique();
-  // Initializing the execution engine.
-  // We need to use the JIT EngineKind to be able to add an object file.
-  LLVMLinkInMCJIT();
-  uintptr_t CodeSize = 0;
-  std::string Error;
-  std::unique_ptr EE(
-  EngineBuilder(createModule(Ctx, TM->createDataLayout()))
-  .setErrorStr()
-  .setMCPU(TM->getTargetCPU())
-  .setEngineKind(EngineKind::JIT)
-  .setMCJITMemoryManager(
-  std::make_unique())
-  .create(TM.release()));
-  if (!EE)
-return make_error(Twine(Error), inconvertibleErrorCode());
-  // Adding the generated object file containing the assembled function.
-  // The ExecutionEngine makes sure the object file is copied into an
-  // executable page.
-  EE->addObjectFile(std::move(ObjectFileHolder));
-  // Fetching function bytes.
-  const uint64_t FunctionAddress = EE->getFunctionAddress(FunctionID);
+
+  auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
+  assert(SymbolSizes.size() == 3);
+  uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);
+
+  auto EJITOrErr = orc::LLJITBuilder().create();
+  if (!EJITOrErr)
+return EJITOrErr.takeError();
+
+  auto EJIT = std::move(*EJITOrErr);
+
+  if (auto ObjErr =
+  EJIT->addObjectFile(std::get<1>(ObjectFileHolder.takeBinary(
+return ObjErr;
+
+  auto FunctionAddressOrErr = EJIT->lookup(FunctionID);
+  if (!FunctionAddressOrErr)
+return FunctionAddressOrErr.takeError();
+
+  const uint64_t FunctionAddress = FunctionAddressOrErr->getValue();
+
   assert(isAligned(kFunctionAlignment, FunctionAddress) &&
  "function is not properly aligned");
+
   StringRef FBytes =
   StringRef(reinterpret_cast(FunctionAddress), CodeSize);
-  return ExecutableFunction(std::move(Ctx), std::move(EE), FBytes);
+  return ExecutableFunction(std::move(Ctx), std::move(EJIT), FBytes);
 }
 
 ExecutableFunction::ExecutableFunction(std::unique_ptr Ctx,
- 

[llvm-branch-commits] [llvm] 1408ee2 - Assert symbol name, add comment about symbol naming

2023-11-24 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-24T02:03:29-08:00
New Revision: 1408ee2eedd4af7cbf94d6e7570c0272e92a8846

URL: 
https://github.com/llvm/llvm-project/commit/1408ee2eedd4af7cbf94d6e7570c0272e92a8846
DIFF: 
https://github.com/llvm/llvm-project/commit/1408ee2eedd4af7cbf94d6e7570c0272e92a8846.diff

LOG: Assert symbol name, add comment about symbol naming

Added: 


Modified: 
llvm/tools/llvm-exegesis/lib/Assembler.cpp

Removed: 




diff  --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp 
b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 54ba29ed04c6f95..903ecbe47b8da0f 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -332,7 +332,11 @@ Expected ExecutableFunction::create(
   std::unique_ptr Ctx = std::make_unique();
 
   auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
+  // Get the size of the function that we want to call into (with the name of
+  // FunctionID). This should always be the third symbol returned by
+  // calculateSymbolSizes.
   assert(SymbolSizes.size() == 3);
+  assert(cantFail(std::get<0>(SymbolSizes[2]).getName()) == FunctionID);
   uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);
 
   auto EJITOrErr = orc::LLJITBuilder().create();



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Switch from MCJIT to LLJIT (PR #72838)

2023-11-23 Thread Aiden Grossman via llvm-branch-commits

boomanaiden154 wrote:

@legrosbuffle can you review this when you get a chance? It's a stacked patch 
against https://github.com/llvm/llvm-project/pull/72837 and should be 
relatively mechanical maintenance.

https://github.com/llvm/llvm-project/pull/72838
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Switch from MCJIT to LLJIT (PR #72838)

2023-11-20 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/72838

This patch switches from using MCJIT to LLJIT as MCJIT is going to be 
deprecated soon.

>From 9dfa6f5607ab945e2ba36da148c3669cdf723dc2 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Mon, 20 Nov 2023 00:42:01 -0800
Subject: [PATCH] [llvm-exegesis] Switch from MCJIT to LLJIT

This patch switches from using MCJIT to LLJIT as MCJIT is going to be
deprecated soon.
---
 llvm/tools/llvm-exegesis/lib/Assembler.cpp  | 77 -
 llvm/tools/llvm-exegesis/lib/Assembler.h|  7 +-
 llvm/tools/llvm-exegesis/lib/CMakeLists.txt |  2 +-
 3 files changed, 32 insertions(+), 54 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp 
b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 9ff33258e965f7e..54ba29ed04c6f95 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -21,11 +21,12 @@
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/MC/MCInstrInfo.h"
+#include "llvm/Object/SymbolSize.h"
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
@@ -105,7 +106,7 @@ MachineFunction (StringRef 
FunctionName,
   FunctionType *FunctionType =
   FunctionType::get(ReturnType, {MemParamType}, false);
   Function *const F = Function::Create(
-  FunctionType, GlobalValue::InternalLinkage, FunctionName, Module);
+  FunctionType, GlobalValue::ExternalLinkage, FunctionName, Module);
   BasicBlock *BB = BasicBlock::Create(Module->getContext(), "", F);
   new UnreachableInst(Module->getContext(), BB);
   return MMI->getOrCreateMachineFunction(*F);
@@ -324,66 +325,44 @@ object::OwningBinary 
getObjectFromFile(StringRef Filename) {
   return cantFail(object::ObjectFile::createObjectFile(Filename));
 }
 
-namespace {
-
-// Implementation of this class relies on the fact that a single object with a
-// single function will be loaded into memory.
-class TrackingSectionMemoryManager : public SectionMemoryManager {
-public:
-  explicit TrackingSectionMemoryManager(uintptr_t *CodeSize)
-  : CodeSize(CodeSize) {}
-
-  uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
-   unsigned SectionID,
-   StringRef SectionName) override {
-*CodeSize = Size;
-return SectionMemoryManager::allocateCodeSection(Size, Alignment, 
SectionID,
- SectionName);
-  }
-
-private:
-  uintptr_t *const CodeSize = nullptr;
-};
-
-} // namespace
-
 Expected ExecutableFunction::create(
 std::unique_ptr TM,
 object::OwningBinary &) {
   assert(ObjectFileHolder.getBinary() && "cannot create object file");
   std::unique_ptr Ctx = std::make_unique();
-  // Initializing the execution engine.
-  // We need to use the JIT EngineKind to be able to add an object file.
-  LLVMLinkInMCJIT();
-  uintptr_t CodeSize = 0;
-  std::string Error;
-  std::unique_ptr EE(
-  EngineBuilder(createModule(Ctx, TM->createDataLayout()))
-  .setErrorStr()
-  .setMCPU(TM->getTargetCPU())
-  .setEngineKind(EngineKind::JIT)
-  .setMCJITMemoryManager(
-  std::make_unique())
-  .create(TM.release()));
-  if (!EE)
-return make_error(Twine(Error), inconvertibleErrorCode());
-  // Adding the generated object file containing the assembled function.
-  // The ExecutionEngine makes sure the object file is copied into an
-  // executable page.
-  EE->addObjectFile(std::move(ObjectFileHolder));
-  // Fetching function bytes.
-  const uint64_t FunctionAddress = EE->getFunctionAddress(FunctionID);
+
+  auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
+  assert(SymbolSizes.size() == 3);
+  uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);
+
+  auto EJITOrErr = orc::LLJITBuilder().create();
+  if (!EJITOrErr)
+return EJITOrErr.takeError();
+
+  auto EJIT = std::move(*EJITOrErr);
+
+  if (auto ObjErr =
+  EJIT->addObjectFile(std::get<1>(ObjectFileHolder.takeBinary(
+return ObjErr;
+
+  auto FunctionAddressOrErr = EJIT->lookup(FunctionID);
+  if (!FunctionAddressOrErr)
+return FunctionAddressOrErr.takeError();
+
+  const uint64_t FunctionAddress = FunctionAddressOrErr->getValue();
+
   assert(isAligned(kFunctionAlignment, FunctionAddress) &&
  "function is not properly aligned");
+
   StringRef FBytes =
   StringRef(reinterpret_cast(FunctionAddress), CodeSize);
-  return ExecutableFunction(std::move(Ctx), std::move(EE), FBytes);
+  return ExecutableFunction(std::move(Ctx), std::move(EJIT), FBytes);
 }
 
 

[llvm-branch-commits] [llvm] 9dfa6f5 - [llvm-exegesis] Switch from MCJIT to LLJIT

2023-11-20 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-20T00:47:24-08:00
New Revision: 9dfa6f5607ab945e2ba36da148c3669cdf723dc2

URL: 
https://github.com/llvm/llvm-project/commit/9dfa6f5607ab945e2ba36da148c3669cdf723dc2
DIFF: 
https://github.com/llvm/llvm-project/commit/9dfa6f5607ab945e2ba36da148c3669cdf723dc2.diff

LOG: [llvm-exegesis] Switch from MCJIT to LLJIT

This patch switches from using MCJIT to LLJIT as MCJIT is going to be
deprecated soon.

Added: 


Modified: 
llvm/tools/llvm-exegesis/lib/Assembler.cpp
llvm/tools/llvm-exegesis/lib/Assembler.h
llvm/tools/llvm-exegesis/lib/CMakeLists.txt

Removed: 




diff  --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp 
b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 9ff33258e965f7e..54ba29ed04c6f95 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -21,11 +21,12 @@
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/MC/MCInstrInfo.h"
+#include "llvm/Object/SymbolSize.h"
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
@@ -105,7 +106,7 @@ MachineFunction (StringRef 
FunctionName,
   FunctionType *FunctionType =
   FunctionType::get(ReturnType, {MemParamType}, false);
   Function *const F = Function::Create(
-  FunctionType, GlobalValue::InternalLinkage, FunctionName, Module);
+  FunctionType, GlobalValue::ExternalLinkage, FunctionName, Module);
   BasicBlock *BB = BasicBlock::Create(Module->getContext(), "", F);
   new UnreachableInst(Module->getContext(), BB);
   return MMI->getOrCreateMachineFunction(*F);
@@ -324,66 +325,44 @@ object::OwningBinary 
getObjectFromFile(StringRef Filename) {
   return cantFail(object::ObjectFile::createObjectFile(Filename));
 }
 
-namespace {
-
-// Implementation of this class relies on the fact that a single object with a
-// single function will be loaded into memory.
-class TrackingSectionMemoryManager : public SectionMemoryManager {
-public:
-  explicit TrackingSectionMemoryManager(uintptr_t *CodeSize)
-  : CodeSize(CodeSize) {}
-
-  uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
-   unsigned SectionID,
-   StringRef SectionName) override {
-*CodeSize = Size;
-return SectionMemoryManager::allocateCodeSection(Size, Alignment, 
SectionID,
- SectionName);
-  }
-
-private:
-  uintptr_t *const CodeSize = nullptr;
-};
-
-} // namespace
-
 Expected ExecutableFunction::create(
 std::unique_ptr TM,
 object::OwningBinary &) {
   assert(ObjectFileHolder.getBinary() && "cannot create object file");
   std::unique_ptr Ctx = std::make_unique();
-  // Initializing the execution engine.
-  // We need to use the JIT EngineKind to be able to add an object file.
-  LLVMLinkInMCJIT();
-  uintptr_t CodeSize = 0;
-  std::string Error;
-  std::unique_ptr EE(
-  EngineBuilder(createModule(Ctx, TM->createDataLayout()))
-  .setErrorStr()
-  .setMCPU(TM->getTargetCPU())
-  .setEngineKind(EngineKind::JIT)
-  .setMCJITMemoryManager(
-  std::make_unique())
-  .create(TM.release()));
-  if (!EE)
-return make_error(Twine(Error), inconvertibleErrorCode());
-  // Adding the generated object file containing the assembled function.
-  // The ExecutionEngine makes sure the object file is copied into an
-  // executable page.
-  EE->addObjectFile(std::move(ObjectFileHolder));
-  // Fetching function bytes.
-  const uint64_t FunctionAddress = EE->getFunctionAddress(FunctionID);
+
+  auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
+  assert(SymbolSizes.size() == 3);
+  uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);
+
+  auto EJITOrErr = orc::LLJITBuilder().create();
+  if (!EJITOrErr)
+return EJITOrErr.takeError();
+
+  auto EJIT = std::move(*EJITOrErr);
+
+  if (auto ObjErr =
+  EJIT->addObjectFile(std::get<1>(ObjectFileHolder.takeBinary(
+return ObjErr;
+
+  auto FunctionAddressOrErr = EJIT->lookup(FunctionID);
+  if (!FunctionAddressOrErr)
+return FunctionAddressOrErr.takeError();
+
+  const uint64_t FunctionAddress = FunctionAddressOrErr->getValue();
+
   assert(isAligned(kFunctionAlignment, FunctionAddress) &&
  "function is not properly aligned");
+
   StringRef FBytes =
   StringRef(reinterpret_cast(FunctionAddress), CodeSize);
-  return ExecutableFunction(std::move(Ctx), std::move(EE), FBytes);
+  return ExecutableFunction(std::move(Ctx), std::move(EJIT), FBytes);
 

[llvm-branch-commits] [llvm] 6d0afd5 - [llvm-exegesis] Refactor ExecutableFunction to use a named constructor

2023-11-20 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-20T00:44:54-08:00
New Revision: 6d0afd5b1c4564255e76b1caf06b0ad51b329372

URL: 
https://github.com/llvm/llvm-project/commit/6d0afd5b1c4564255e76b1caf06b0ad51b329372
DIFF: 
https://github.com/llvm/llvm-project/commit/6d0afd5b1c4564255e76b1caf06b0ad51b329372.diff

LOG: [llvm-exegesis] Refactor ExecutableFunction to use a named constructor

This patch refactors ExecutableFunction to use a named constructor
pattern, namely adding the create function, so that errors occurring
during the creation of an ExecutableFunction can be propogated back up
rather than having to deal with them in report_fatal_error.

Added: 


Modified: 
llvm/tools/llvm-exegesis/lib/Assembler.cpp
llvm/tools/llvm-exegesis/lib/Assembler.h
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h

Removed: 




diff  --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp 
b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 167fb6373377c28..9ff33258e965f7e 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -347,38 +347,44 @@ class TrackingSectionMemoryManager : public 
SectionMemoryManager {
 
 } // namespace
 
-ExecutableFunction::ExecutableFunction(
+Expected ExecutableFunction::create(
 std::unique_ptr TM,
-object::OwningBinary &)
-: Context(std::make_unique()) {
+object::OwningBinary &) {
   assert(ObjectFileHolder.getBinary() && "cannot create object file");
+  std::unique_ptr Ctx = std::make_unique();
   // Initializing the execution engine.
   // We need to use the JIT EngineKind to be able to add an object file.
   LLVMLinkInMCJIT();
   uintptr_t CodeSize = 0;
   std::string Error;
-  ExecEngine.reset(
-  EngineBuilder(createModule(Context, TM->createDataLayout()))
+  std::unique_ptr EE(
+  EngineBuilder(createModule(Ctx, TM->createDataLayout()))
   .setErrorStr()
   .setMCPU(TM->getTargetCPU())
   .setEngineKind(EngineKind::JIT)
   .setMCJITMemoryManager(
   std::make_unique())
   .create(TM.release()));
-  if (!ExecEngine)
-report_fatal_error(Twine(Error));
+  if (!EE)
+return make_error(Twine(Error), inconvertibleErrorCode());
   // Adding the generated object file containing the assembled function.
   // The ExecutionEngine makes sure the object file is copied into an
   // executable page.
-  ExecEngine->addObjectFile(std::move(ObjectFileHolder));
+  EE->addObjectFile(std::move(ObjectFileHolder));
   // Fetching function bytes.
-  const uint64_t FunctionAddress = ExecEngine->getFunctionAddress(FunctionID);
+  const uint64_t FunctionAddress = EE->getFunctionAddress(FunctionID);
   assert(isAligned(kFunctionAlignment, FunctionAddress) &&
  "function is not properly aligned");
-  FunctionBytes =
+  StringRef FBytes =
   StringRef(reinterpret_cast(FunctionAddress), CodeSize);
+  return ExecutableFunction(std::move(Ctx), std::move(EE), FBytes);
 }
 
+ExecutableFunction::ExecutableFunction(std::unique_ptr Ctx,
+   std::unique_ptr EE,
+   StringRef FB)
+: FunctionBytes(FB), Context(std::move(Ctx)), ExecEngine(std::move(EE)) {}
+
 Error getBenchmarkFunctionBytes(const StringRef InputData,
 std::vector ) {
   const auto Holder = getObjectFromBuffer(InputData);

diff  --git a/llvm/tools/llvm-exegesis/lib/Assembler.h 
b/llvm/tools/llvm-exegesis/lib/Assembler.h
index 7c2a002967af720..5f1bf8cdfb7ad6c 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.h
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.h
@@ -106,10 +106,11 @@ object::OwningBinary 
getObjectFromFile(StringRef Filename);
 
 // Consumes an ObjectFile containing a `void foo(char*)` function and make it
 // executable.
-struct ExecutableFunction {
-  explicit ExecutableFunction(
-  std::unique_ptr TM,
-  object::OwningBinary &);
+class ExecutableFunction {
+public:
+  static Expected
+  create(std::unique_ptr TM,
+ object::OwningBinary &);
 
   // Retrieves the function as an array of bytes.
   StringRef getFunctionBytes() const { return FunctionBytes; }
@@ -119,9 +120,15 @@ struct ExecutableFunction {
 ((void (*)(char *))(intptr_t)FunctionBytes.data())(Memory);
   }
 
+  StringRef FunctionBytes;
+
+private:
+  ExecutableFunction(std::unique_ptr Ctx,
+ std::unique_ptr EE,
+ StringRef FunctionBytes);
+
   std::unique_ptr Context;
   std::unique_ptr ExecEngine;
-  StringRef FunctionBytes;
 };
 
 // Copies benchmark function's bytes from benchmark object.

diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 7ec24eb2f866f86..bd116ccb1df4866 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ 

[llvm-branch-commits] [llvm] add2053 - Reland "[llvm-exegesis] Fix preservation of RDI in subprocess mode (#72458)"

2023-11-17 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-11-16T14:03:07-08:00
New Revision: add20537cc764b8afb97df85acba7c21d6537ae3

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

LOG: Reland "[llvm-exegesis] Fix preservation of RDI in subprocess mode 
(#72458)"

This reverts commit 186db1bcb0096a6af348d7e17866c68fa2004068.

This relands commit 0718c1a8405ac130d72cd3525befed2911618cc7.

The REQUIRES flag in the test that was added only specified that the
machine needed to have the capability to execute the snippet rather than
actually run it with performance counters. This would work with
--dummy-perf-counters, but that is not currently supported in the
subprocess execution mode. So for now, we require the ability to
actually perform measurements to prevent test failures in configurations
that don't have libpfm or access to performance counters.

Added: 
llvm/test/tools/llvm-exegesis/X86/latency/subprocess-preserved-registers.s

Modified: 
llvm/tools/llvm-exegesis/lib/X86/Target.cpp

Removed: 




diff  --git 
a/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-preserved-registers.s 
b/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-preserved-registers.s
new file mode 100644
index 000..320d1d7db38f422
--- /dev/null
+++ b/llvm/test/tools/llvm-exegesis/X86/latency/subprocess-preserved-registers.s
@@ -0,0 +1,30 @@
+# REQUIRES: exegesis-can-measure-latency, x86_64-linux
+
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mode=latency 
-snippets-file=%s -execution-mode=subprocess | FileCheck %s
+
+# See comment in ./subprocess-abnormal-exit-code.s on the transient
+# PTRACE_ATTACH failure.
+# ALLOW_RETRIES: 2
+
+# Check that the value of the registers preserved in subprocess mode while
+# making the ioctl system call are actually preserved correctly.
+
+# LLVM-EXEGESIS-DEFREG RAX 11
+# LLVM-EXEGESIS-DEFREG RDI 13
+# LLVM-EXEGESIS-DEFREG RSI 17
+# LLVM-EXEGESIS-DEFREG R13 0
+# LLVM-EXEGESIS-DEFREG R12 127
+
+cmpq $0x11, %rax
+cmovneq %r12, %r13
+cmpq $0x13, %rdi
+cmovneq %r12, %r13
+cmpq $0x17, %rsi
+cmovneq %r12, %r13
+
+movq $60, %rax
+movq %r13, %rdi
+syscall
+
+# CHECK-NOT: error:   'Child benchmarking process exited with non-zero 
exit code: Child process returned with unknown exit code'
+

diff  --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp 
b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index ac99e98cc851f34..bf8fd9ec7066478 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -1205,7 +1205,7 @@ ExegesisX86Target::configurePerfCounter(long Request, 
bool SaveRegisters) const
   if(SaveRegisters) {
 // Restore RAX, RDI, and RSI, in reverse order.
 generateRegisterStackPop(X86::RSI, ConfigurePerfCounterCode);
-generateRegisterStackPop(X86::RIP, ConfigurePerfCounterCode);
+generateRegisterStackPop(X86::RDI, ConfigurePerfCounterCode);
 generateRegisterStackPop(X86::RAX, ConfigurePerfCounterCode);
   }
   return ConfigurePerfCounterCode;



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] c1f87dc - Refactored getSectionAndRelocations

2023-02-25 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-02-25T10:30:32Z
New Revision: c1f87dca0e8e13964ccd04718792da5cf4b3ca49

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

LOG: Refactored getSectionAndRelocations

Added: 


Modified: 
llvm/include/llvm/Object/ELF.h
llvm/lib/Object/ELF.cpp
llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 




diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index 1664ff96542f..aaa0418b9ffa 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -14,6 +14,7 @@
 #define LLVM_OBJECT_ELF_H
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -392,6 +393,9 @@ class ELFFile {
   Expected> getSectionContents(const Elf_Shdr ) const;
   Expected> getSegmentContents(const Elf_Phdr ) const;
   Expected> decodeBBAddrMap(const Elf_Shdr ) const;
+  Error getSectionAndRelocations(
+  std::function(const Elf_Shdr &)> IsMatch,
+  llvm::MapVector ) 
const;
 
   void createFakeSections();
 };

diff  --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 81c9a097170d..c6a9e13e4265 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -706,6 +706,43 @@ ELFFile::decodeBBAddrMap(const Elf_Shdr ) const {
   return FunctionEntries;
 }
 
+template 
+Error ELFFile::getSectionAndRelocations(
+std::function(const Elf_Shdr &)> IsMatch,
+llvm::MapVector ) const {
+  Error IsSuccess = Error::success();
+  for (const Elf_Shdr  : cantFail(this->sections())) {
+Expected DoesSectionMatch = IsMatch(Sec);
+if(!DoesSectionMatch)
+  return joinErrors(std::move(IsSuccess), DoesSectionMatch.takeError());
+if (*DoesSectionMatch)
+  if (SecToRelocMap.insert(std::make_pair(, (const Elf_Shdr *)nullptr))
+  .second)
+continue;
+
+if (Sec.sh_type != ELF::SHT_RELA && Sec.sh_type != ELF::SHT_REL)
+  continue;
+
+Expected RelSecOrErr = this->getSection(Sec.sh_info);
+if (!RelSecOrErr) {
+  IsSuccess = joinErrors(
+  std::move(IsSuccess),
+  make_error(std::error_code(),
+  describe(*this, Sec) +
+  ": failed to get a relocated section: " +
+  toString(RelSecOrErr.takeError(;
+  continue;
+}
+const Elf_Shdr *ContentsSec = *RelSecOrErr;
+Expected DoesRelTargetMatch = IsMatch(*ContentsSec);
+if(!DoesRelTargetMatch)
+  return DoesRelTargetMatch.takeError();
+if (*DoesRelTargetMatch)
+  SecToRelocMap[ContentsSec] = 
+  }
+  return IsSuccess;
+}
+
 template class llvm::object::ELFFile;
 template class llvm::object::ELFFile;
 template class llvm::object::ELFFile;

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp 
b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 45fff0cc4a76..37394ae60572 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -326,7 +326,7 @@ template  class ELFDumper : public ObjDumper 
{
   /// Retrieves sections with corresponding relocation sections based on
   /// IsMatch.
   void getSectionAndRelocations(
-  std::function IsMatch,
+  std::function(const Elf_Shdr &)> IsMatch,
   llvm::MapVector );
 
   const object::ELFObjectFile 
@@ -6198,28 +6198,12 @@ void ELFDumper::printNonRelocatableStackSizes(
 
 template 
 void ELFDumper::getSectionAndRelocations(
-std::function IsMatch,
+std::function(const Elf_Shdr &)> IsMatch,
 llvm::MapVector ) {
-  for (const Elf_Shdr  : cantFail(Obj.sections())) {
-if (IsMatch(Sec))
-  if (SecToRelocMap.insert(std::make_pair(, (const Elf_Shdr *)nullptr))
-  .second)
-continue;
-
-if (Sec.sh_type != ELF::SHT_RELA && Sec.sh_type != ELF::SHT_REL)
-  continue;
-
-Expected RelSecOrErr = Obj.getSection(Sec.sh_info);
-if (!RelSecOrErr) {
-  reportUniqueWarning(describe(Sec) +
-  ": failed to get a relocated section: " +
-  toString(RelSecOrErr.takeError()));
-  continue;
-}
-const Elf_Shdr *ContentsSec = *RelSecOrErr;
-if (IsMatch(*ContentsSec))
-  SecToRelocMap[ContentsSec] = 
-  }
+  Error RecoverableErrors = Obj.getSectionAndRelocations(IsMatch, 
SecToRelocMap);
+  handleAllErrors(std::move(RecoverableErrors), [&](const StringError ) {
+reportUniqueWarning(SE.getMessage());
+  });
 }
 
 template 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] d77d2b7 - [Propeller] Make decoding BBAddrMaps trace through relocations

2023-02-25 Thread Aiden Grossman via llvm-branch-commits

Author: Aiden Grossman
Date: 2023-02-25T10:30:37Z
New Revision: d77d2b71558dd8de68c8d718a2dca17c1704b661

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

LOG: [Propeller] Make decoding BBAddrMaps trace through relocations

Currently when using the LLVM tools (eg llvm-readobj, llvm-objdump) to
find information about basic block locations using the propeller tooling
in relocatable object files function addresses are not mapped properly
which causes problems. In llvm-readobj this means that incorrect
function names will be pulled. In llvm-objdum this means that most BBs
won't show up in the output if --symbolize-operands is used. This patch
changes the behavior of decodeBBAddrMap to trace through relocations
to get correct function addresses if it is going through a relocatable
object file. This fixes the behavior in both tools and also other
consumers of decodeBBAddrMap. Some helper functions have been added
in/refactoring done to aid in grabbing BB address map sections now that
in some cases both relocation and BB address map sections need to be
obtained at the same time.

Regression tests moved around/added.

Differential Revision: https://reviews.llvm.org/D143841

Added: 
llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml
llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test

Modified: 
llvm/include/llvm/Object/ELF.h
llvm/lib/Object/ELF.cpp
llvm/lib/Object/ELFObjectFile.cpp

llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml
llvm/tools/llvm-readobj/ELFDumper.cpp
llvm/unittests/Object/ELFObjectFileTest.cpp

Removed: 




diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index aaa0418b9ffa..8e69fb03e074 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -392,7 +392,9 @@ class ELFFile {
   Expected> getSectionContentsAsArray(const Elf_Shdr ) const;
   Expected> getSectionContents(const Elf_Shdr ) const;
   Expected> getSegmentContents(const Elf_Phdr ) const;
-  Expected> decodeBBAddrMap(const Elf_Shdr ) const;
+  Expected>
+  decodeBBAddrMap(const Elf_Shdr ,
+  const std::optional  = {}) const;
   Error getSectionAndRelocations(
   std::function(const Elf_Shdr &)> IsMatch,
   llvm::MapVector ) 
const;

diff  --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index c6a9e13e4265..67f234bc2a65 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -639,8 +639,19 @@ ELFFile::toMappedAddr(uint64_t VAddr, WarningHandler 
WarnHandler) const {
 }
 
 template 
-Expected>
-ELFFile::decodeBBAddrMap(const Elf_Shdr ) const {
+Expected> ELFFile::decodeBBAddrMap(
+const Elf_Shdr , const std::optional ) const {
+  bool IsRelocatable = getHeader().e_type == ELF::ET_REL;
+  assert(!IsRelocatable || (IsRelocatable && RelaSec));
+  llvm::DenseMap BBAddrMapTranslations;
+  if(IsRelocatable && RelaSec) {
+Expected Relas = this->relas(*RelaSec);
+if(!Relas) 
+  return Relas.takeError();
+for (Elf_Rela Rela: *Relas) {
+  BBAddrMapTranslations[Rela.r_offset] = Rela.r_addend;
+}
+  }
   Expected> ContentsOrErr = getSectionContents(Sec);
   if (!ContentsOrErr)
 return ContentsOrErr.takeError();
@@ -680,7 +691,12 @@ ELFFile::decodeBBAddrMap(const Elf_Shdr ) const {
Twine(static_cast(Version)));
   Data.getU8(Cur); // Feature byte
 }
+uint64_t SectionOffset = Cur.tell();
 uintX_t Address = static_cast(Data.getAddress(Cur));
+if(IsRelocatable) {
+  assert(Address == 0);
+  Address = BBAddrMapTranslations[SectionOffset];
+}
 uint32_t NumBlocks = ReadULEB128AsUInt32();
 std::vector BBEntries;
 uint32_t PrevBBEndOffset = 0;

diff  --git a/llvm/lib/Object/ELFObjectFile.cpp 
b/llvm/lib/Object/ELFObjectFile.cpp
index 4ce240324b19..aa9570071bec 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -681,24 +681,36 @@ template 
 Expected> static readBBAddrMapImpl(
 const ELFFile , std::optional TextSectionIndex) {
   using Elf_Shdr = typename ELFT::Shdr;
+  bool IsRelocatable = EF.getHeader().e_type == ELF::ET_REL;
   std::vector BBAddrMaps;
+  llvm::MapVector SectionRelocMap;
+
   const auto  = cantFail(EF.sections());
-  for (const Elf_Shdr  : Sections) {
+  auto IsMatch = [&](const Elf_Shdr ) -> Expected {
 if (Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP &&
 Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP_V0)
-  continue;
-if (TextSectionIndex) {
+  return false;
+if(TextSectionIndex) {
   Expected TextSecOrErr = EF.getSection(Sec.sh_link);
   if (!TextSecOrErr)
-return createError("unable to get the linked-to section for " +
-