[llvm] 2d68a42 - [llvm-exegesis] Improve test flexibility by using available_features
Pavel Kosov via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 27 04:43:46 PDT 2023
Author: Pavel Kosov
Date: 2023-03-27T14:43:08+03:00
New Revision: 2d68a42f084a460007b368eab191cf0ff1b976d7
URL: https://github.com/llvm/llvm-project/commit/2d68a42f084a460007b368eab191cf0ff1b976d7
DIFF: https://github.com/llvm/llvm-project/commit/2d68a42f084a460007b368eab191cf0ff1b976d7.diff
LOG: [llvm-exegesis] Improve test flexibility by using available_features
Currently, all llvm-exegesis regression tests are target-specific and
they are organized so that the entire subdirectories of
llvm/test/tools/llvm-exegesis are enabled or disabled as a whole.
After the commit e0ad2af691 ("Skip codegen" dry-run mode), at least two
kinds of tests are possible:
1) ensure that a snippet can be *generated* for the particular opcode
2) tests involving actual snippet execution inside the llvm-exegesis
process
Thus, for the particular target subdirectory, some tests should run only
on the particular host architecture and other tests only need the target
being among LLVM_TARGETS_TO_BUILD.
This commit defines a bunch of exegesis-specific features that can be
referenced in REQUIRES, UNSUPPORTED, etc. on a test-by-test basis.
~~
Huawei RRI
Reviewed By: courbet
Differential Revision: https://reviews.llvm.org/D146302
Added:
llvm/test/tools/llvm-exegesis/lit.local.cfg
Modified:
llvm/test/tools/llvm-exegesis/AArch64/latency-by-opcode-name.s
llvm/test/tools/llvm-exegesis/AArch64/lit.local.cfg
llvm/test/tools/llvm-exegesis/Mips/latency-GPR64.s
llvm/test/tools/llvm-exegesis/Mips/latency-by-opcode-name.s
llvm/test/tools/llvm-exegesis/Mips/lit.local.cfg
llvm/test/tools/llvm-exegesis/X86/lbr/mov-add.s
Removed:
llvm/test/tools/llvm-exegesis/X86/lbr/lit.local.cfg
################################################################################
diff --git a/llvm/test/tools/llvm-exegesis/AArch64/latency-by-opcode-name.s b/llvm/test/tools/llvm-exegesis/AArch64/latency-by-opcode-name.s
index 1d719ce1609dd..653f544e36ce2 100644
--- a/llvm/test/tools/llvm-exegesis/AArch64/latency-by-opcode-name.s
+++ b/llvm/test/tools/llvm-exegesis/AArch64/latency-by-opcode-name.s
@@ -1,4 +1,5 @@
# RUN: llvm-exegesis -mode=latency -opcode-name=ADDXrr | FileCheck %s
+# REQUIRES: exegesis-can-execute-aarch64, exegesis-can-measure-latency
CHECK: ---
CHECK-NEXT: mode: latency
diff --git a/llvm/test/tools/llvm-exegesis/AArch64/lit.local.cfg b/llvm/test/tools/llvm-exegesis/AArch64/lit.local.cfg
index a768323e2d078..2c80c84ef2ccf 100644
--- a/llvm/test/tools/llvm-exegesis/AArch64/lit.local.cfg
+++ b/llvm/test/tools/llvm-exegesis/AArch64/lit.local.cfg
@@ -1,32 +1,3 @@
-import subprocess
-import lit.util
-
-if 'native' not in config.available_features:
- config.unsupported = True
-
-elif not ('AArch64' in config.root.targets):
+if not ('AArch64' in config.root.targets):
# We need support for AArch64.
config.unsupported = True
-
-elif not ('aarch64' in config.root.host_triple):
- # We need to be running on an AArch64 host.
- config.unsupported = True
-
-else:
- # We need libpfm to be installed and allow reading perf counters. We can
- # only know that at runtime, so we try to measure the latency of an empty
- # code snippet and bail out on error.
- llvm_exegesis_exe = lit.util.which('llvm-exegesis', config.llvm_tools_dir)
- if not llvm_exegesis_exe:
- print('llvm-exegesis not found')
- config.unsupported = True
- else:
- try:
- with open(os.devnull, 'w') as quiet:
- check_llvm_exegesis_result = subprocess.call(
- [llvm_exegesis_exe, '-mode', 'latency', '-snippets-file', '/dev/null'], stdout=quiet, stderr=quiet)
- except OSError:
- print('could not exec llvm-exegesis')
- config.unsupported = True
- if not check_llvm_exegesis_result == 0:
- config.unsupported = True
diff --git a/llvm/test/tools/llvm-exegesis/Mips/latency-GPR64.s b/llvm/test/tools/llvm-exegesis/Mips/latency-GPR64.s
index 3be96581f96f3..f9b4860c3f4a0 100644
--- a/llvm/test/tools/llvm-exegesis/Mips/latency-GPR64.s
+++ b/llvm/test/tools/llvm-exegesis/Mips/latency-GPR64.s
@@ -1,4 +1,5 @@
# RUN: llvm-exegesis -mode=latency -opcode-name=AND64 | FileCheck %s
+# REQUIRES: exegesis-can-execute-mips, exegesis-can-measure-latency
CHECK: ---
CHECK-NEXT: mode: latency
diff --git a/llvm/test/tools/llvm-exegesis/Mips/latency-by-opcode-name.s b/llvm/test/tools/llvm-exegesis/Mips/latency-by-opcode-name.s
index 365608a368d8d..f3853eaa62ea7 100644
--- a/llvm/test/tools/llvm-exegesis/Mips/latency-by-opcode-name.s
+++ b/llvm/test/tools/llvm-exegesis/Mips/latency-by-opcode-name.s
@@ -1,4 +1,5 @@
# RUN: llvm-exegesis -mode=latency -opcode-name=ADD | FileCheck %s
+# REQUIRES: exegesis-can-execute-mips, exegesis-can-measure-latency
CHECK: ---
CHECK-NEXT: mode: latency
diff --git a/llvm/test/tools/llvm-exegesis/Mips/lit.local.cfg b/llvm/test/tools/llvm-exegesis/Mips/lit.local.cfg
index 766ae9cc0c535..9e3b40229e9ae 100644
--- a/llvm/test/tools/llvm-exegesis/Mips/lit.local.cfg
+++ b/llvm/test/tools/llvm-exegesis/Mips/lit.local.cfg
@@ -1,32 +1,3 @@
-import subprocess
-import lit.util
-
-if 'native' not in config.available_features:
- config.unsupported = True
-
-elif not ('Mips' in config.root.targets):
+if not ('Mips' in config.root.targets):
# We need support for Mips.
config.unsupported = True
-
-elif not ('mips' in config.root.host_triple):
- # We need to be running on an Mips host.
- config.unsupported = True
-
-else:
- # We need libpfm to be installed and allow reading perf counters. We can
- # only know that at runtime, so we try to measure the latency of an empty
- # code snippet and bail out on error.
- llvm_exegesis_exe = lit.util.which('llvm-exegesis', config.llvm_tools_dir)
- if not llvm_exegesis_exe:
- print('llvm-exegesis not found')
- config.unsupported = True
- else:
- try:
- with open(os.devnull, 'w') as quiet:
- check_llvm_exegesis_result = subprocess.call(
- [llvm_exegesis_exe, '-mode', 'latency', '-snippets-file', '/dev/null'], stdout=quiet, stderr=quiet)
- except OSError:
- print('could not exec llvm-exegesis')
- config.unsupported = True
- if not check_llvm_exegesis_result == 0:
- config.unsupported = True
diff --git a/llvm/test/tools/llvm-exegesis/X86/lbr/lit.local.cfg b/llvm/test/tools/llvm-exegesis/X86/lbr/lit.local.cfg
deleted file mode 100644
index a188cb2c36fab..0000000000000
--- a/llvm/test/tools/llvm-exegesis/X86/lbr/lit.local.cfg
+++ /dev/null
@@ -1,30 +0,0 @@
-import subprocess
-import lit.util
-
-if 'native' not in config.available_features:
- config.unsupported = True
-
-elif not ('X86' in config.root.targets):
- # We need support for X86.
- config.unsupported = True
-
-elif not ('x86_64' in config.root.host_triple):
- # We need to be running on an X86 host.
- config.unsupported = True
-
-else:
- # We need libpfm to be installed and the host to be support LBR format with cycles.
- llvm_exegesis_exe = lit.util.which('llvm-exegesis', config.llvm_tools_dir)
- if not llvm_exegesis_exe:
- print('llvm-exegesis not found')
- config.unsupported = True
- else:
- try:
- with open(os.devnull, 'w') as quiet:
- check_llvm_exegesis_latency_result = subprocess.call(
- [llvm_exegesis_exe, '-mode', 'latency', '-x86-lbr-sample-period', '123', '-repetition-mode', 'loop', '-snippets-file', '/dev/null'], stdout=quiet, stderr=quiet)
- except OSError:
- print('could not exec llvm-exegesis')
- config.unsupported = True
- if not check_llvm_exegesis_latency_result == 0:
- config.unsupported = True
diff --git a/llvm/test/tools/llvm-exegesis/X86/lbr/mov-add.s b/llvm/test/tools/llvm-exegesis/X86/lbr/mov-add.s
index 6f0762b9e5ac4..af1662d93a744 100644
--- a/llvm/test/tools/llvm-exegesis/X86/lbr/mov-add.s
+++ b/llvm/test/tools/llvm-exegesis/X86/lbr/mov-add.s
@@ -1,4 +1,5 @@
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --repetition-mode=loop --x86-lbr-sample-period=521 --snippets-file=%p/Inputs/mov_add.att
+# REQUIRES: exegesis-can-execute-x86_64, exegesis-can-measure-latency-lbr
CHECK: ---
diff --git a/llvm/test/tools/llvm-exegesis/lit.local.cfg b/llvm/test/tools/llvm-exegesis/lit.local.cfg
new file mode 100644
index 0000000000000..a932f3270ca8d
--- /dev/null
+++ b/llvm/test/tools/llvm-exegesis/lit.local.cfg
@@ -0,0 +1,40 @@
+import subprocess
+import lit.util
+
+
+def can_execute_generated_snippets(arch):
+ is_host_arch = arch in config.root.host_triple
+ # 'native' feature is defined as "host arch == default triple arch"
+ is_native_codegen = 'native' in config.available_features
+ return is_host_arch and is_native_codegen
+
+
+def can_use_perf_counters(mode, extra_options=[]):
+ # We need libpfm to be installed and allow reading perf counters. We can
+ # only know that at runtime, so we try to measure an empty code snippet
+ # and bail out on error.
+ llvm_exegesis_exe = lit.util.which('llvm-exegesis', config.llvm_tools_dir)
+ try:
+ return_code = subprocess.call(
+ [llvm_exegesis_exe, '-mode', mode, '-snippets-file', '/dev/null'] + extra_options,
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ return return_code == 0
+ except OSError:
+ print('could not exec llvm-exegesis')
+ return False
+
+
+for arch in ['aarch64', 'mips', 'powerpc', 'x86_64']:
+ if can_execute_generated_snippets(arch):
+ config.available_features.add('exegesis-can-execute-%s' % arch)
+
+if can_use_perf_counters('latency'):
+ config.available_features.add('exegesis-can-measure-latency')
+
+if can_use_perf_counters('uops'):
+ config.available_features.add('exegesis-can-measure-uops')
+
+if can_execute_generated_snippets('x86_64'):
+ # Check for support of LBR format with cycles.
+ if can_use_perf_counters('latency', ['-x86-lbr-sample-period', '123', '-repetition-mode', 'loop']):
+ config.available_features.add('exegesis-can-measure-latency-lbr')
More information about the llvm-commits
mailing list