6 def 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
13 def 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")
22 return_code = subprocess.call(
23 [llvm_exegesis_exe, "-mode", mode, "-snippets-file", "/dev/null"]
25 stdout=subprocess.DEVNULL,
26 stderr=subprocess.DEVNULL,
28 return return_code == 0
30 print("could not exec llvm-exegesis")
34 for arch in ["aarch64", "mips", "powerpc", "x86_64"]:
35 if can_execute_generated_snippets(arch):
36 config.available_features.add("exegesis-can-execute-%s" % arch)
38 if can_use_perf_counters("latency"):
39 config.available_features.add("exegesis-can-measure-latency")
41 if can_use_perf_counters("uops"):
42 config.available_features.add("exegesis-can-measure-uops")
44 if 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"]
49 config.available_features.add("exegesis-can-measure-latency-lbr")