brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 89110ed Raw
51 lines · plain
1import subprocess2import re3import lit.util4 5 6def can_execute_generated_snippets(arch):7    is_host_arch = arch in config.root.host_triple8    # 'native' feature is defined as "host arch == default triple arch"9    is_native_codegen = "native" in config.available_features10    return is_host_arch and is_native_codegen11 12 13def can_use_perf_counters(mode, extra_options=[]):14    # We need libpfm to be installed and allow reading perf counters. We can15    # only know that at runtime, so we try to measure an empty code snippet16    # 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 False21    try:22        return_code = subprocess.call(23            [llvm_exegesis_exe, "-mode", mode, "-opcode-name=ADD64rr"]24            + extra_options,25            stdout=subprocess.DEVNULL,26            stderr=subprocess.DEVNULL,27        )28        return return_code == 029    except OSError:30        print("could not exec llvm-exegesis")31        return False32 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