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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- 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 --- /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')