llvm-project
622 строки · 19.5 Кб
1# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os6import sys7import re8import platform9import subprocess10
11import lit.util12import lit.formats13from lit.llvm import llvm_config14from lit.llvm.subst import FindTool15from lit.llvm.subst import ToolSubst16
17# name: The name of this test suite.
18config.name = "LLVM"19
20# testFormat: The test format to use to interpret tests.
21config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)22
23# suffixes: A list of file extensions to treat as test files. This is overriden
24# by individual lit.local.cfg files in the test subdirectories.
25config.suffixes = [".ll", ".c", ".test", ".txt", ".s", ".mir", ".yaml"]26
27# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
28# subdirectories contain auxiliary inputs for various tests in their parent
29# directories.
30config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"]31
32# test_source_root: The root path where tests are located.
33config.test_source_root = os.path.dirname(__file__)34
35# test_exec_root: The root path where tests should be run.
36config.test_exec_root = os.path.join(config.llvm_obj_root, "test")37
38# Tweak the PATH to include the tools dir.
39llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)40
41# Propagate some variables from the host environment.
42llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])43
44
45# Set up OCAMLPATH to include newly built OCaml libraries.
46top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml")47llvm_ocaml_lib = os.path.join(top_ocaml_lib, "llvm")48
49llvm_config.with_system_environment("OCAMLPATH")50llvm_config.with_environment("OCAMLPATH", top_ocaml_lib, append_path=True)51llvm_config.with_environment("OCAMLPATH", llvm_ocaml_lib, append_path=True)52
53llvm_config.with_system_environment("CAML_LD_LIBRARY_PATH")54llvm_config.with_environment("CAML_LD_LIBRARY_PATH", llvm_ocaml_lib, append_path=True)55
56# Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
57llvm_config.with_environment("OCAMLRUNPARAM", "b")58
59# Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
60# available. This is darwin specific since it's currently only needed on darwin.
61
62
63def get_asan_rtlib():64if (65not "Address" in config.llvm_use_sanitizer66or not "Darwin" in config.host_os67or not "x86" in config.host_triple68):69return ""70try:71import glob72except:73print("glob module not found, skipping get_asan_rtlib() lookup")74return ""75# The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative76# path from the host cc.77host_lib_dir = os.path.join(os.path.dirname(config.host_cc), "../lib")78asan_dylib_dir_pattern = (79host_lib_dir + "/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"80)81found_dylibs = glob.glob(asan_dylib_dir_pattern)82if len(found_dylibs) != 1:83return ""84return found_dylibs[0]85
86
87llvm_config.use_default_substitutions()88
89# Add site-specific substitutions.
90config.substitutions.append(("%llvmshlibdir", config.llvm_shlib_dir))91config.substitutions.append(("%shlibext", config.llvm_shlib_ext))92config.substitutions.append(("%pluginext", config.llvm_plugin_ext))93config.substitutions.append(("%exeext", config.llvm_exe_ext))94
95
96lli_args = []97# The target triple used by default by lli is the process target triple (some
98# triple appropriate for generating code for the current process) but because
99# we don't support COFF in MCJIT well enough for the tests, force ELF format on
100# Windows. FIXME: the process target triple should be used here, but this is
101# difficult to obtain on Windows.
102if re.search(r"cygwin|windows-gnu|windows-msvc", config.host_triple):103lli_args = ["-mtriple=" + config.host_triple + "-elf"]104
105llc_args = []106
107# Similarly, have a macro to use llc with DWARF even when the host is Windows
108if re.search(r"windows-msvc", config.target_triple):109llc_args = [" -mtriple=" + config.target_triple.replace("-msvc", "-gnu")]110
111# Provide the path to asan runtime lib if available. On darwin, this lib needs
112# to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
113# to be linked contain instrumented sanitizer code.
114ld64_cmd = config.ld64_executable115asan_rtlib = get_asan_rtlib()116if asan_rtlib:117ld64_cmd = "DYLD_INSERT_LIBRARIES={} {}".format(asan_rtlib, ld64_cmd)118if config.osx_sysroot:119ld64_cmd = "{} -syslibroot {}".format(ld64_cmd, config.osx_sysroot)120
121ocamlc_command = "%s ocamlc -cclib -L%s %s" % (122config.ocamlfind_executable,123config.llvm_lib_dir,124config.ocaml_flags,125)
126ocamlopt_command = "true"127if config.have_ocamlopt:128ocamlopt_command = "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" % (129config.ocamlfind_executable,130config.llvm_lib_dir,131config.llvm_lib_dir,132config.ocaml_flags,133)134
135opt_viewer_cmd = "%s %s/tools/opt-viewer/opt-viewer.py" % (136sys.executable,137config.llvm_src_root,138)
139
140llvm_original_di_preservation_cmd = os.path.join(141config.llvm_src_root, "utils", "llvm-original-di-preservation.py"142)
143config.substitutions.append(144(145"%llvm-original-di-preservation",146"'%s' %s" % (config.python_executable, llvm_original_di_preservation_cmd),147)148)
149
150llvm_locstats_tool = os.path.join(config.llvm_tools_dir, "llvm-locstats")151config.substitutions.append(152("%llvm-locstats", "'%s' %s" % (config.python_executable, llvm_locstats_tool))153)
154config.llvm_locstats_used = os.path.exists(llvm_locstats_tool)155
156tools = [157ToolSubst("%llvm", FindTool("llvm"), unresolved="ignore"),158ToolSubst("%lli", FindTool("lli"), post=".", extra_args=lli_args),159ToolSubst("%llc_dwarf", FindTool("llc"), extra_args=llc_args),160ToolSubst("%gold", config.gold_executable, unresolved="ignore"),161ToolSubst("%ld64", ld64_cmd, unresolved="ignore"),162ToolSubst("%ocamlc", ocamlc_command, unresolved="ignore"),163ToolSubst("%ocamlopt", ocamlopt_command, unresolved="ignore"),164ToolSubst("%opt-viewer", opt_viewer_cmd),165ToolSubst("%llvm-objcopy", FindTool("llvm-objcopy")),166ToolSubst("%llvm-strip", FindTool("llvm-strip")),167ToolSubst("%llvm-install-name-tool", FindTool("llvm-install-name-tool")),168ToolSubst("%llvm-bitcode-strip", FindTool("llvm-bitcode-strip")),169ToolSubst("%split-file", FindTool("split-file")),170]
171
172# FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
173tools.extend(174[175"dsymutil",176"lli",177"lli-child-target",178"llvm-ar",179"llvm-as",180"llvm-addr2line",181"llvm-bcanalyzer",182"llvm-bitcode-strip",183"llvm-config",184"llvm-cov",185"llvm-cxxdump",186"llvm-cvtres",187"llvm-debuginfod-find",188"llvm-debuginfo-analyzer",189"llvm-diff",190"llvm-dis",191"llvm-dwarfdump",192"llvm-dwarfutil",193"llvm-dwp",194"llvm-dlltool",195"llvm-exegesis",196"llvm-extract",197"llvm-isel-fuzzer",198"llvm-ifs",199"llvm-install-name-tool",200"llvm-jitlink",201"llvm-opt-fuzzer",202"llvm-lib",203"llvm-link",204"llvm-lto",205"llvm-lto2",206"llvm-mc",207"llvm-mca",208"llvm-modextract",209"llvm-nm",210"llvm-objcopy",211"llvm-objdump",212"llvm-otool",213"llvm-pdbutil",214"llvm-profdata",215"llvm-profgen",216"llvm-ranlib",217"llvm-rc",218"llvm-readelf",219"llvm-readobj",220"llvm-rtdyld",221"llvm-sim",222"llvm-size",223"llvm-split",224"llvm-stress",225"llvm-strings",226"llvm-strip",227"llvm-tblgen",228"llvm-readtapi",229"llvm-undname",230"llvm-windres",231"llvm-c-test",232"llvm-cxxfilt",233"llvm-xray",234"yaml2obj",235"obj2yaml",236"yaml-bench",237"verify-uselistorder",238"bugpoint",239"llc",240"llvm-symbolizer",241"opt",242"sancov",243"sanstats",244"llvm-remarkutil",245]246)
247
248# The following tools are optional
249tools.extend(250[251ToolSubst("llvm-mt", unresolved="ignore"),252ToolSubst("llvm-debuginfod", unresolved="ignore"),253ToolSubst("Kaleidoscope-Ch3", unresolved="ignore"),254ToolSubst("Kaleidoscope-Ch4", unresolved="ignore"),255ToolSubst("Kaleidoscope-Ch5", unresolved="ignore"),256ToolSubst("Kaleidoscope-Ch6", unresolved="ignore"),257ToolSubst("Kaleidoscope-Ch7", unresolved="ignore"),258ToolSubst("Kaleidoscope-Ch8", unresolved="ignore"),259ToolSubst("LLJITWithThinLTOSummaries", unresolved="ignore"),260ToolSubst("LLJITWithRemoteDebugging", unresolved="ignore"),261ToolSubst("OrcV2CBindingsBasicUsage", unresolved="ignore"),262ToolSubst("OrcV2CBindingsAddObjectFile", unresolved="ignore"),263ToolSubst("OrcV2CBindingsRemovableCode", unresolved="ignore"),264ToolSubst("OrcV2CBindingsLazy", unresolved="ignore"),265ToolSubst("OrcV2CBindingsVeryLazy", unresolved="ignore"),266ToolSubst("dxil-dis", unresolved="ignore"),267]268)
269
270# Find (major, minor) version of ptxas
271def ptxas_version(ptxas):272ptxas_cmd = subprocess.Popen([ptxas, "--version"], stdout=subprocess.PIPE)273ptxas_out = ptxas_cmd.stdout.read().decode("ascii")274ptxas_cmd.wait()275match = re.search(r"release (\d+)\.(\d+)", ptxas_out)276if match:277return (int(match.group(1)), int(match.group(2)))278print("couldn't determine ptxas version")279return None280
281
282# Enable %ptxas and %ptxas-verify tools.
283# %ptxas-verify defaults to sm_60 architecture. It can be overriden
284# by specifying required one, for instance: %ptxas-verify -arch=sm_80.
285def enable_ptxas(ptxas_executable):286version = ptxas_version(ptxas_executable)287if version:288# ptxas is supposed to be backward compatible with previous289# versions, so add a feature for every known version prior to290# the current one.291ptxas_known_versions = [292(9, 0),293(9, 1),294(9, 2),295(10, 0),296(10, 1),297(10, 2),298(11, 0),299(11, 1),300(11, 2),301(11, 3),302(11, 4),303(11, 5),304(11, 6),305(11, 7),306(11, 8),307(12, 0),308(12, 1),309(12, 2),310(12, 3),311(12, 4),312]313
314def version_int(ver):315return ver[0] * 100 + ver[1]316
317# ignore ptxas if its version is below the minimum supported318# version319min_version = ptxas_known_versions[0]320if version_int(version) < version_int(min_version):321print(322"Warning: ptxas version {}.{} is not supported".format(323version[0], version[1]324)325)326return327
328for known_version in ptxas_known_versions:329if version_int(known_version) <= version_int(version):330major, minor = known_version331config.available_features.add("ptxas-{}.{}".format(major, minor))332
333config.available_features.add("ptxas")334tools.extend(335[336ToolSubst("%ptxas", ptxas_executable),337ToolSubst("%ptxas-verify", "{} -arch=sm_60 -c -".format(ptxas_executable)),338]339)340
341
342ptxas_executable = (343os.environ.get("LLVM_PTXAS_EXECUTABLE", None) or config.ptxas_executable344)
345if ptxas_executable:346enable_ptxas(ptxas_executable)347
348llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)349
350# Targets
351
352config.targets = frozenset(config.targets_to_build.split())353
354for arch in config.targets_to_build.split():355config.available_features.add(arch.lower() + "-registered-target")356
357# Features
358known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]359if config.host_ldflags.find("-m32") < 0 and any(360config.llvm_host_triple.startswith(x) for x in known_arches361):362config.available_features.add("llvm-64-bits")363
364config.available_features.add("host-byteorder-" + sys.byteorder + "-endian")365
366if sys.platform in ["win32"]:367# ExecutionEngine, no weak symbols in COFF.368config.available_features.add("uses_COFF")369else:370# Others/can-execute.txt371config.available_features.add("can-execute")372
373# Loadable module
374if config.has_plugins:375config.available_features.add("plugins")376
377if config.build_examples:378config.available_features.add("examples")379
380if config.linked_bye_extension:381config.substitutions.append(("%llvmcheckext", "CHECK-EXT"))382config.substitutions.append(("%loadbye", ""))383config.substitutions.append(("%loadnewpmbye", ""))384else:385config.substitutions.append(("%llvmcheckext", "CHECK-NOEXT"))386config.substitutions.append(387(388"%loadbye",389"-load={}/Bye{}".format(config.llvm_shlib_dir, config.llvm_shlib_ext),390)391)392config.substitutions.append(393(394"%loadnewpmbye",395"-load-pass-plugin={}/Bye{}".format(396config.llvm_shlib_dir, config.llvm_shlib_ext397),398)399)400
401if config.linked_exampleirtransforms_extension:402config.substitutions.append(("%loadexampleirtransforms", ""))403else:404config.substitutions.append(405(406"%loadexampleirtransforms",407"-load-pass-plugin={}/ExampleIRTransforms{}".format(408config.llvm_shlib_dir, config.llvm_shlib_ext409),410)411)412
413# Static libraries are not built if BUILD_SHARED_LIBS is ON.
414if not config.build_shared_libs and not config.link_llvm_dylib:415config.available_features.add("static-libs")416
417if config.link_llvm_dylib:418config.available_features.add("llvm-dylib")419config.substitutions.append(420(421# libLLVM.so.19.0git422"%llvmdylib",423"{}/libLLVM{}.{}".format(424config.llvm_shlib_dir, config.llvm_shlib_ext, config.llvm_dylib_version425)426)427)428
429if config.have_tf_aot:430config.available_features.add("have_tf_aot")431
432if config.have_tflite:433config.available_features.add("have_tflite")434
435if config.llvm_inliner_model_autogenerated:436config.available_features.add("llvm_inliner_model_autogenerated")437
438if config.llvm_raevict_model_autogenerated:439config.available_features.add("llvm_raevict_model_autogenerated")440
441
442def have_cxx_shared_library():443readobj_exe = lit.util.which("llvm-readobj", config.llvm_tools_dir)444if not readobj_exe:445print("llvm-readobj not found")446return False447
448try:449readobj_cmd = subprocess.Popen(450[readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE451)452except OSError:453print("could not exec llvm-readobj")454return False455
456readobj_out = readobj_cmd.stdout.read().decode("ascii")457readobj_cmd.wait()458
459regex = re.compile(r"(libc\+\+|libstdc\+\+|msvcp).*\.(so|dylib|dll)")460needed_libs = False461for line in readobj_out.splitlines():462if "NeededLibraries [" in line:463needed_libs = True464if "]" in line:465needed_libs = False466if needed_libs and regex.search(line.lower()):467return True468return False469
470
471if have_cxx_shared_library():472config.available_features.add("cxx-shared-library")473
474if config.libcxx_used:475config.available_features.add("libcxx-used")476
477# LLVM can be configured with an empty default triple
478# Some tests are "generic" and require a valid default triple
479if config.target_triple:480config.available_features.add("default_triple")481# Direct object generation482if not config.target_triple.startswith(("nvptx", "xcore")):483config.available_features.add("object-emission")484
485if config.have_llvm_driver:486config.available_features.add("llvm-driver")487
488import subprocess489
490
491def have_ld_plugin_support():492if not os.path.exists(493os.path.join(config.llvm_shlib_dir, "LLVMgold" + config.llvm_shlib_ext)494):495return False496
497ld_cmd = subprocess.Popen(498[config.gold_executable, "--help"], stdout=subprocess.PIPE, env={"LANG": "C"}499)500ld_out = ld_cmd.stdout.read().decode()501ld_cmd.wait()502
503if not "-plugin" in ld_out:504return False505
506# check that the used emulations are supported.507emu_line = [l for l in ld_out.split("\n") if "supported emulations" in l]508if len(emu_line) != 1:509return False510emu_line = emu_line[0]511fields = emu_line.split(":")512if len(fields) != 3:513return False514emulations = fields[2].split()515if "elf_x86_64" not in emulations:516return False517if "elf32ppc" in emulations:518config.available_features.add("ld_emu_elf32ppc")519
520ld_version = subprocess.Popen(521[config.gold_executable, "--version"], stdout=subprocess.PIPE, env={"LANG": "C"}522)523if not "GNU gold" in ld_version.stdout.read().decode():524return False525ld_version.wait()526
527return True528
529
530if have_ld_plugin_support():531config.available_features.add("ld_plugin")532
533
534def have_ld64_plugin_support():535if not os.path.exists(536os.path.join(config.llvm_shlib_dir, "libLTO" + config.llvm_shlib_ext)537):538return False539
540if config.ld64_executable == "":541return False542
543ld_cmd = subprocess.Popen([config.ld64_executable, "-v"], stderr=subprocess.PIPE)544ld_out = ld_cmd.stderr.read().decode()545ld_cmd.wait()546
547if "ld64" not in ld_out or "LTO" not in ld_out:548return False549
550return True551
552
553if have_ld64_plugin_support():554config.available_features.add("ld64_plugin")555
556# Ask llvm-config about asserts
557llvm_config.feature_config(558[559("--assertion-mode", {"ON": "asserts"}),560("--build-mode", {"[Dd][Ee][Bb][Uu][Gg]": "debug"}),561]562)
563
564if "darwin" == sys.platform:565cmd = ["sysctl", "hw.optional.fma"]566sysctl_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE)567
568# Non zero return, probably a permission issue569if sysctl_cmd.wait():570print(571'Warning: sysctl exists but calling "{}" failed, defaulting to no fma3.'.format(572" ".join(cmd)573)574)575else:576result = sysctl_cmd.stdout.read().decode("ascii")577if "hw.optional.fma: 1" in result:578config.available_features.add("fma3")579
580if not hasattr(sys, "getwindowsversion") or sys.getwindowsversion().build >= 17063:581config.available_features.add("unix-sockets")582
583# .debug_frame is not emitted for targeting Windows x64, aarch64/arm64, AIX, or Apple Silicon Mac.
584if not re.match(585r"^(x86_64|aarch64|arm64|powerpc|powerpc64).*-(windows-gnu|windows-msvc|aix)",586config.target_triple,587) and not re.match(r"^arm64(e)?-apple-(macos|darwin)", config.target_triple):588config.available_features.add("debug_frame")589
590if config.enable_threads:591config.available_features.add("thread_support")592
593if config.have_libxml2:594config.available_features.add("libxml2")595
596if config.have_curl:597config.available_features.add("curl")598
599if config.have_httplib:600config.available_features.add("httplib")601
602if config.have_opt_viewer_modules:603config.available_features.add("have_opt_viewer_modules")604
605if config.expensive_checks:606config.available_features.add("expensive_checks")607
608if "MemoryWithOrigins" in config.llvm_use_sanitizer:609config.available_features.add("use_msan_with_origins")610
611
612# Some tools support an environment variable "OBJECT_MODE" on AIX OS, which
613# controls the kind of objects they will support. If there is no "OBJECT_MODE"
614# environment variable specified, the default behaviour is to support 32-bit
615# objects only. In order to not affect most test cases, which expect to support
616# 32-bit and 64-bit objects by default, set the environment variable
617# "OBJECT_MODE" to 'any' by default on AIX OS.
618if "system-aix" in config.available_features:619config.environment["OBJECT_MODE"] = "any"620
621if config.has_logf128:622config.available_features.add("has_logf128")623