[TTI] getTypeBasedIntrinsicInstrCost - add basic handling for strided load/store...
[llvm-project.git] / llvm / test / lit.cfg.py
blob3c0069d10412a5ff013806adc6e7aad9fc6a2254
1 # -*- Python -*-
3 # Configuration file for the 'lit' test runner.
5 import os
6 import sys
7 import re
8 import platform
9 import subprocess
11 import lit.util
12 import lit.formats
13 from lit.llvm import llvm_config
14 from lit.llvm.subst import FindTool
15 from lit.llvm.subst import ToolSubst
17 # name: The name of this test suite.
18 config.name = "LLVM"
20 # testFormat: The test format to use to interpret tests.
21 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
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.
25 config.suffixes = [".ll", ".c", ".test", ".txt", ".s", ".mir", ".yaml", ".spv"]
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.
30 config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"]
32 # test_source_root: The root path where tests are located.
33 config.test_source_root = os.path.dirname(__file__)
35 # test_exec_root: The root path where tests should be run.
36 config.test_exec_root = os.path.join(config.llvm_obj_root, "test")
38 # Tweak the PATH to include the tools dir.
39 llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
41 # Propagate some variables from the host environment.
42 llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
45 # Set up OCAMLPATH to include newly built OCaml libraries.
46 top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml")
47 llvm_ocaml_lib = os.path.join(top_ocaml_lib, "llvm")
49 llvm_config.with_system_environment("OCAMLPATH")
50 llvm_config.with_environment("OCAMLPATH", top_ocaml_lib, append_path=True)
51 llvm_config.with_environment("OCAMLPATH", llvm_ocaml_lib, append_path=True)
53 llvm_config.with_system_environment("CAML_LD_LIBRARY_PATH")
54 llvm_config.with_environment("CAML_LD_LIBRARY_PATH", llvm_ocaml_lib, append_path=True)
56 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
57 llvm_config.with_environment("OCAMLRUNPARAM", "b")
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.
63 def get_asan_rtlib():
64 if (
65 not "Address" in config.llvm_use_sanitizer
66 or not "Darwin" in config.host_os
67 or not "x86" in config.host_triple
69 return ""
70 try:
71 import glob
72 except:
73 print("glob module not found, skipping get_asan_rtlib() lookup")
74 return ""
75 # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
76 # path from the host cc.
77 host_lib_dir = os.path.join(os.path.dirname(config.host_cc), "../lib")
78 asan_dylib_dir_pattern = (
79 host_lib_dir + "/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"
81 found_dylibs = glob.glob(asan_dylib_dir_pattern)
82 if len(found_dylibs) != 1:
83 return ""
84 return found_dylibs[0]
87 llvm_config.use_default_substitutions()
89 # Add site-specific substitutions.
90 config.substitutions.append(("%llvmshlibdir", config.llvm_shlib_dir))
91 config.substitutions.append(("%shlibext", config.llvm_shlib_ext))
92 config.substitutions.append(("%pluginext", config.llvm_plugin_ext))
93 config.substitutions.append(("%exeext", config.llvm_exe_ext))
96 lli_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.
102 if re.search(r"cygwin|windows-gnu|windows-msvc", config.host_triple):
103 lli_args = ["-mtriple=" + config.host_triple + "-elf"]
105 llc_args = []
107 # Similarly, have a macro to use llc with DWARF even when the host is Windows
108 if re.search(r"windows-msvc", config.target_triple):
109 llc_args = [" -mtriple=" + config.target_triple.replace("-msvc", "-gnu")]
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.
114 ld64_cmd = config.ld64_executable
115 asan_rtlib = get_asan_rtlib()
116 if asan_rtlib:
117 ld64_cmd = "DYLD_INSERT_LIBRARIES={} {}".format(asan_rtlib, ld64_cmd)
118 if config.osx_sysroot:
119 ld64_cmd = "{} -syslibroot {}".format(ld64_cmd, config.osx_sysroot)
121 ocamlc_command = "%s ocamlc -cclib -L%s %s" % (
122 config.ocamlfind_executable,
123 config.llvm_lib_dir,
124 config.ocaml_flags,
126 ocamlopt_command = "true"
127 if config.have_ocamlopt:
128 ocamlopt_command = "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" % (
129 config.ocamlfind_executable,
130 config.llvm_lib_dir,
131 config.llvm_lib_dir,
132 config.ocaml_flags,
135 opt_viewer_cmd = "%s %s/tools/opt-viewer/opt-viewer.py" % (
136 sys.executable,
137 config.llvm_src_root,
140 llvm_original_di_preservation_cmd = os.path.join(
141 config.llvm_src_root, "utils", "llvm-original-di-preservation.py"
143 config.substitutions.append(
145 "%llvm-original-di-preservation",
146 "'%s' %s" % (config.python_executable, llvm_original_di_preservation_cmd),
150 llvm_locstats_tool = os.path.join(config.llvm_tools_dir, "llvm-locstats")
151 config.substitutions.append(
152 ("%llvm-locstats", "'%s' %s" % (config.python_executable, llvm_locstats_tool))
154 config.llvm_locstats_used = os.path.exists(llvm_locstats_tool)
156 tools = [
157 ToolSubst("%llvm", FindTool("llvm"), unresolved="ignore"),
158 ToolSubst("%lli", FindTool("lli"), post=".", extra_args=lli_args),
159 ToolSubst("%llc_dwarf", FindTool("llc"), extra_args=llc_args),
160 ToolSubst("%gold", config.gold_executable, unresolved="ignore"),
161 ToolSubst("%ld64", ld64_cmd, unresolved="ignore"),
162 ToolSubst("%ocamlc", ocamlc_command, unresolved="ignore"),
163 ToolSubst("%ocamlopt", ocamlopt_command, unresolved="ignore"),
164 ToolSubst("%opt-viewer", opt_viewer_cmd),
165 ToolSubst("%llvm-objcopy", FindTool("llvm-objcopy")),
166 ToolSubst("%llvm-strip", FindTool("llvm-strip")),
167 ToolSubst("%llvm-install-name-tool", FindTool("llvm-install-name-tool")),
168 ToolSubst("%llvm-bitcode-strip", FindTool("llvm-bitcode-strip")),
169 ToolSubst("%split-file", FindTool("split-file")),
172 # FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
173 tools.extend(
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-cgdata",
184 "llvm-config",
185 "llvm-cov",
186 "llvm-ctxprof-util",
187 "llvm-cxxdump",
188 "llvm-cvtres",
189 "llvm-debuginfod-find",
190 "llvm-debuginfo-analyzer",
191 "llvm-diff",
192 "llvm-dis",
193 "llvm-dwarfdump",
194 "llvm-dwarfutil",
195 "llvm-dwp",
196 "llvm-dlltool",
197 "llvm-exegesis",
198 "llvm-extract",
199 "llvm-isel-fuzzer",
200 "llvm-ifs",
201 "llvm-install-name-tool",
202 "llvm-jitlink",
203 "llvm-opt-fuzzer",
204 "llvm-lib",
205 "llvm-link",
206 "llvm-lto",
207 "llvm-lto2",
208 "llvm-mc",
209 "llvm-mca",
210 "llvm-modextract",
211 "llvm-nm",
212 "llvm-objcopy",
213 "llvm-objdump",
214 "llvm-otool",
215 "llvm-pdbutil",
216 "llvm-profdata",
217 "llvm-profgen",
218 "llvm-ranlib",
219 "llvm-rc",
220 "llvm-readelf",
221 "llvm-readobj",
222 "llvm-rtdyld",
223 "llvm-sim",
224 "llvm-size",
225 "llvm-split",
226 "llvm-stress",
227 "llvm-strings",
228 "llvm-strip",
229 "llvm-tblgen",
230 "llvm-readtapi",
231 "llvm-undname",
232 "llvm-windres",
233 "llvm-c-test",
234 "llvm-cxxfilt",
235 "llvm-xray",
236 "yaml2obj",
237 "obj2yaml",
238 "yaml-bench",
239 "verify-uselistorder",
240 "bugpoint",
241 "llc",
242 "llvm-symbolizer",
243 "opt",
244 "sancov",
245 "sanstats",
246 "llvm-remarkutil",
250 # The following tools are optional
251 tools.extend(
253 ToolSubst("llvm-mt", unresolved="ignore"),
254 ToolSubst("llvm-debuginfod", unresolved="ignore"),
255 ToolSubst("Kaleidoscope-Ch3", unresolved="ignore"),
256 ToolSubst("Kaleidoscope-Ch4", unresolved="ignore"),
257 ToolSubst("Kaleidoscope-Ch5", unresolved="ignore"),
258 ToolSubst("Kaleidoscope-Ch6", unresolved="ignore"),
259 ToolSubst("Kaleidoscope-Ch7", unresolved="ignore"),
260 ToolSubst("Kaleidoscope-Ch8", unresolved="ignore"),
261 ToolSubst("LLJITWithThinLTOSummaries", unresolved="ignore"),
262 ToolSubst("LLJITWithRemoteDebugging", unresolved="ignore"),
263 ToolSubst("OrcV2CBindingsBasicUsage", unresolved="ignore"),
264 ToolSubst("OrcV2CBindingsAddObjectFile", unresolved="ignore"),
265 ToolSubst("OrcV2CBindingsRemovableCode", unresolved="ignore"),
266 ToolSubst("OrcV2CBindingsLazy", unresolved="ignore"),
267 ToolSubst("OrcV2CBindingsVeryLazy", unresolved="ignore"),
268 ToolSubst("dxil-dis", unresolved="ignore"),
272 # Find (major, minor) version of ptxas
273 def ptxas_version(ptxas):
274 ptxas_cmd = subprocess.Popen([ptxas, "--version"], stdout=subprocess.PIPE)
275 ptxas_out = ptxas_cmd.stdout.read().decode("ascii")
276 ptxas_cmd.wait()
277 match = re.search(r"release (\d+)\.(\d+)", ptxas_out)
278 if match:
279 return (int(match.group(1)), int(match.group(2)))
280 print("couldn't determine ptxas version")
281 return None
284 # Enable %ptxas and %ptxas-verify tools.
285 # %ptxas-verify defaults to sm_60 architecture. It can be overriden
286 # by specifying required one, for instance: %ptxas-verify -arch=sm_80.
287 def enable_ptxas(ptxas_executable):
288 version = ptxas_version(ptxas_executable)
289 if version:
290 # ptxas is supposed to be backward compatible with previous
291 # versions, so add a feature for every known version prior to
292 # the current one.
293 ptxas_known_versions = [
294 (9, 0),
295 (9, 1),
296 (9, 2),
297 (10, 0),
298 (10, 1),
299 (10, 2),
300 (11, 0),
301 (11, 1),
302 (11, 2),
303 (11, 3),
304 (11, 4),
305 (11, 5),
306 (11, 6),
307 (11, 7),
308 (11, 8),
309 (12, 0),
310 (12, 1),
311 (12, 2),
312 (12, 3),
313 (12, 4),
314 (12, 5),
315 (12, 6),
316 (12, 8),
319 def version_int(ver):
320 return ver[0] * 100 + ver[1]
322 # ignore ptxas if its version is below the minimum supported
323 # version
324 min_version = ptxas_known_versions[0]
325 if version_int(version) < version_int(min_version):
326 print(
327 "Warning: ptxas version {}.{} is not supported".format(
328 version[0], version[1]
331 return
333 for known_version in ptxas_known_versions:
334 if version_int(known_version) <= version_int(version):
335 major, minor = known_version
336 config.available_features.add("ptxas-{}.{}".format(major, minor))
338 config.available_features.add("ptxas")
339 tools.extend(
341 ToolSubst("%ptxas", ptxas_executable),
342 ToolSubst("%ptxas-verify", "{} -arch=sm_60 -c -".format(ptxas_executable)),
347 ptxas_executable = (
348 os.environ.get("LLVM_PTXAS_EXECUTABLE", None) or config.ptxas_executable
350 if ptxas_executable:
351 enable_ptxas(ptxas_executable)
353 llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
355 # Targets
357 config.targets = frozenset(config.targets_to_build.split())
359 for arch in config.targets_to_build.split():
360 config.available_features.add(arch.lower() + "-registered-target")
362 # Features
363 known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]
364 if config.host_ldflags.find("-m32") < 0 and any(
365 config.llvm_host_triple.startswith(x) for x in known_arches
367 config.available_features.add("llvm-64-bits")
369 config.available_features.add("host-byteorder-" + sys.byteorder + "-endian")
370 if config.target_triple:
371 if re.match(
372 r"(aarch64_be|arc|armeb|bpfeb|lanai|m68k|mips|mips64|powerpc|powerpc64|sparc|sparcv9|s390x|s390|tce|thumbeb)-.*",
373 config.target_triple,
375 config.available_features.add("target-byteorder-big-endian")
376 else:
377 config.available_features.add("target-byteorder-little-endian")
379 if sys.platform in ["win32"]:
380 # ExecutionEngine, no weak symbols in COFF.
381 config.available_features.add("uses_COFF")
382 else:
383 # Others/can-execute.txt
384 config.available_features.add("can-execute")
386 # Loadable module
387 if config.has_plugins:
388 config.available_features.add("plugins")
390 if config.build_examples:
391 config.available_features.add("examples")
393 if config.linked_bye_extension:
394 config.substitutions.append(("%llvmcheckext", "CHECK-EXT"))
395 config.substitutions.append(("%loadbye", ""))
396 config.substitutions.append(("%loadnewpmbye", ""))
397 else:
398 config.substitutions.append(("%llvmcheckext", "CHECK-NOEXT"))
399 config.substitutions.append(
401 "%loadbye",
402 "-load={}/Bye{}".format(config.llvm_shlib_dir, config.llvm_shlib_ext),
405 config.substitutions.append(
407 "%loadnewpmbye",
408 "-load-pass-plugin={}/Bye{}".format(
409 config.llvm_shlib_dir, config.llvm_shlib_ext
414 if config.linked_exampleirtransforms_extension:
415 config.substitutions.append(("%loadexampleirtransforms", ""))
416 else:
417 config.substitutions.append(
419 "%loadexampleirtransforms",
420 "-load-pass-plugin={}/ExampleIRTransforms{}".format(
421 config.llvm_shlib_dir, config.llvm_shlib_ext
426 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
427 if not config.build_shared_libs and not config.link_llvm_dylib:
428 config.available_features.add("static-libs")
430 if config.link_llvm_dylib:
431 config.available_features.add("llvm-dylib")
432 config.substitutions.append(
434 # libLLVM.so.19.0git
435 "%llvmdylib",
436 "{}/libLLVM{}.{}".format(
437 config.llvm_shlib_dir, config.llvm_shlib_ext, config.llvm_dylib_version
442 if config.have_tf_aot:
443 config.available_features.add("have_tf_aot")
445 if config.have_tflite:
446 config.available_features.add("have_tflite")
448 if config.llvm_inliner_model_autogenerated:
449 config.available_features.add("llvm_inliner_model_autogenerated")
451 if config.llvm_raevict_model_autogenerated:
452 config.available_features.add("llvm_raevict_model_autogenerated")
455 def have_cxx_shared_library():
456 readobj_exe = lit.util.which("llvm-readobj", config.llvm_tools_dir)
457 if not readobj_exe:
458 print("llvm-readobj not found")
459 return False
461 try:
462 readobj_cmd = subprocess.Popen(
463 [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE
465 except OSError:
466 print("could not exec llvm-readobj")
467 return False
469 readobj_out = readobj_cmd.stdout.read().decode("ascii")
470 readobj_cmd.wait()
472 regex = re.compile(r"(libc\+\+|libstdc\+\+|msvcp).*\.(so|dylib|dll)")
473 needed_libs = False
474 for line in readobj_out.splitlines():
475 if "NeededLibraries [" in line:
476 needed_libs = True
477 if "]" in line:
478 needed_libs = False
479 if needed_libs and regex.search(line.lower()):
480 return True
481 return False
484 if have_cxx_shared_library():
485 config.available_features.add("cxx-shared-library")
487 if config.libcxx_used:
488 config.available_features.add("libcxx-used")
490 # LLVM can be configured with an empty default triple
491 # Some tests are "generic" and require a valid default triple
492 if config.target_triple:
493 config.available_features.add("default_triple")
494 # Direct object generation
495 if not config.target_triple.startswith(("nvptx", "xcore")):
496 config.available_features.add("object-emission")
498 if config.have_llvm_driver:
499 config.available_features.add("llvm-driver")
501 import subprocess
504 def have_ld_plugin_support():
505 if not os.path.exists(
506 os.path.join(config.llvm_shlib_dir, "LLVMgold" + config.llvm_shlib_ext)
508 return False
510 ld_cmd = subprocess.Popen(
511 [config.gold_executable, "--help"], stdout=subprocess.PIPE, env={"LANG": "C"}
513 ld_out = ld_cmd.stdout.read().decode()
514 ld_cmd.wait()
516 if not "-plugin" in ld_out:
517 return False
519 # check that the used emulations are supported.
520 emu_line = [l for l in ld_out.split("\n") if "supported emulations" in l]
521 if len(emu_line) != 1:
522 return False
523 emu_line = emu_line[0]
524 fields = emu_line.split(":")
525 if len(fields) != 3:
526 return False
527 emulations = fields[2].split()
528 if "elf_x86_64" not in emulations:
529 return False
530 if "elf32ppc" in emulations:
531 config.available_features.add("ld_emu_elf32ppc")
533 ld_version = subprocess.Popen(
534 [config.gold_executable, "--version"], stdout=subprocess.PIPE, env={"LANG": "C"}
536 if not "GNU gold" in ld_version.stdout.read().decode():
537 return False
538 ld_version.wait()
540 return True
543 if have_ld_plugin_support():
544 config.available_features.add("ld_plugin")
547 def have_ld64_plugin_support():
548 if not os.path.exists(
549 os.path.join(config.llvm_shlib_dir, "libLTO" + config.llvm_shlib_ext)
551 return False
553 if config.ld64_executable == "":
554 return False
556 ld_cmd = subprocess.Popen([config.ld64_executable, "-v"], stderr=subprocess.PIPE)
557 ld_out = ld_cmd.stderr.read().decode()
558 ld_cmd.wait()
560 if "ld64" not in ld_out or "LTO" not in ld_out:
561 return False
563 return True
566 if have_ld64_plugin_support():
567 config.available_features.add("ld64_plugin")
569 # Ask llvm-config about asserts
570 llvm_config.feature_config(
572 ("--assertion-mode", {"ON": "asserts"}),
573 ("--build-mode", {"[Dd][Ee][Bb][Uu][Gg]": "debug"}),
577 if "darwin" == sys.platform:
578 cmd = ["sysctl", "hw.optional.fma"]
579 sysctl_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE)
581 # Non zero return, probably a permission issue
582 if sysctl_cmd.wait():
583 print(
584 'Warning: sysctl exists but calling "{}" failed, defaulting to no fma3.'.format(
585 " ".join(cmd)
588 else:
589 result = sysctl_cmd.stdout.read().decode("ascii")
590 if "hw.optional.fma: 1" in result:
591 config.available_features.add("fma3")
593 if not hasattr(sys, "getwindowsversion") or sys.getwindowsversion().build >= 17063:
594 config.available_features.add("unix-sockets")
596 # .debug_frame is not emitted for targeting Windows x64, aarch64/arm64, AIX, or Apple Silicon Mac.
597 if not re.match(
598 r"^(x86_64|aarch64|arm64|powerpc|powerpc64).*-(windows-gnu|windows-msvc|aix)",
599 config.target_triple,
600 ) and not re.match(r"^arm64(e)?-apple-(macos|darwin)", config.target_triple):
601 config.available_features.add("debug_frame")
603 if config.enable_backtrace:
604 config.available_features.add("backtrace")
606 if config.enable_threads:
607 config.available_features.add("thread_support")
609 if config.have_libxml2:
610 config.available_features.add("libxml2")
612 if config.have_curl:
613 config.available_features.add("curl")
615 if config.have_httplib:
616 config.available_features.add("httplib")
618 if config.have_opt_viewer_modules:
619 config.available_features.add("have_opt_viewer_modules")
621 if config.expensive_checks:
622 config.available_features.add("expensive_checks")
624 if "MemoryWithOrigins" in config.llvm_use_sanitizer:
625 config.available_features.add("use_msan_with_origins")
628 # Some tools support an environment variable "OBJECT_MODE" on AIX OS, which
629 # controls the kind of objects they will support. If there is no "OBJECT_MODE"
630 # environment variable specified, the default behaviour is to support 32-bit
631 # objects only. In order to not affect most test cases, which expect to support
632 # 32-bit and 64-bit objects by default, set the environment variable
633 # "OBJECT_MODE" to 'any' by default on AIX OS.
634 if "system-aix" in config.available_features:
635 config.environment["OBJECT_MODE"] = "any"
637 if config.has_logf128:
638 config.available_features.add("has_logf128")