xref: /llvm-project/llvm/test/tools/llvm-exegesis/lit.local.cfg (revision 43b8e86bf76648bf0f34f34bc0a606e527decc43)
1import subprocess
2import re
3import lit.util
4
5
6def can_execute_generated_snippets(arch):
7    is_host_arch = arch in config.root.host_triple
8    # 'native' feature is defined as "host arch == default triple arch"
9    is_native_codegen = "native" in config.available_features
10    return is_host_arch and is_native_codegen
11
12
13def can_use_perf_counters(mode, extra_options=[]):
14    # We need libpfm to be installed and allow reading perf counters. We can
15    # only know that at runtime, so we try to measure an empty code snippet
16    # and bail out on error.
17    llvm_exegesis_exe = lit.util.which("llvm-exegesis", config.llvm_tools_dir)
18    if llvm_exegesis_exe is None:
19        print("could not find llvm-exegesis")
20        return False
21    try:
22        return_code = subprocess.call(
23            [llvm_exegesis_exe, "-mode", mode, "-snippets-file", "/dev/null"]
24            + extra_options,
25            stdout=subprocess.DEVNULL,
26            stderr=subprocess.DEVNULL,
27        )
28        return return_code == 0
29    except OSError:
30        print("could not exec llvm-exegesis")
31        return False
32
33
34for arch in ["aarch64", "mips", "powerpc", "x86_64"]:
35    if can_execute_generated_snippets(arch):
36        config.available_features.add("exegesis-can-execute-%s" % arch)
37
38if can_use_perf_counters("latency"):
39    config.available_features.add("exegesis-can-measure-latency")
40
41if can_use_perf_counters("uops"):
42    config.available_features.add("exegesis-can-measure-uops")
43
44if can_execute_generated_snippets("x86_64"):
45    # Check for support of LBR format with cycles.
46    if can_use_perf_counters(
47        "latency", ["-x86-lbr-sample-period", "123", "-repetition-mode", "loop"]
48    ):
49        config.available_features.add("exegesis-can-measure-latency-lbr")
50
51