3 # Configuration file for the 'lit' test runner.
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.
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"]
27 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
28 # subdirectories contain auxiliary inputs for various tests in their parent
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.
65 not "Address" in config
.llvm_use_sanitizer
66 or not "Darwin" in config
.host_os
67 or not "x86" in config
.host_triple
73 print("glob module not found, skipping get_asan_rtlib() lookup")
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:
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
))
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"]
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()
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
,
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
,
135 opt_viewer_cmd
= "%s %s/tools/opt-viewer/opt-viewer.py" % (
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
)
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?
182 "llvm-bitcode-strip",
187 "llvm-debuginfod-find",
188 "llvm-debuginfo-analyzer",
198 "llvm-install-name-tool",
236 "verify-uselistorder",
247 # The following tools are optional
250 ToolSubst("llvm-mt", unresolved
="ignore"),
251 ToolSubst("llvm-debuginfod", unresolved
="ignore"),
252 ToolSubst("Kaleidoscope-Ch3", unresolved
="ignore"),
253 ToolSubst("Kaleidoscope-Ch4", unresolved
="ignore"),
254 ToolSubst("Kaleidoscope-Ch5", unresolved
="ignore"),
255 ToolSubst("Kaleidoscope-Ch6", unresolved
="ignore"),
256 ToolSubst("Kaleidoscope-Ch7", unresolved
="ignore"),
257 ToolSubst("Kaleidoscope-Ch8", unresolved
="ignore"),
258 ToolSubst("LLJITWithThinLTOSummaries", unresolved
="ignore"),
259 ToolSubst("LLJITWithRemoteDebugging", unresolved
="ignore"),
260 ToolSubst("OrcV2CBindingsBasicUsage", unresolved
="ignore"),
261 ToolSubst("OrcV2CBindingsAddObjectFile", unresolved
="ignore"),
262 ToolSubst("OrcV2CBindingsRemovableCode", unresolved
="ignore"),
263 ToolSubst("OrcV2CBindingsLazy", unresolved
="ignore"),
264 ToolSubst("OrcV2CBindingsVeryLazy", unresolved
="ignore"),
265 ToolSubst("dxil-dis", unresolved
="ignore"),
269 # Find (major, minor) version of ptxas
270 def ptxas_version(ptxas
):
271 ptxas_cmd
= subprocess
.Popen([ptxas
, "--version"], stdout
=subprocess
.PIPE
)
272 ptxas_out
= ptxas_cmd
.stdout
.read().decode("ascii")
274 match
= re
.search(r
"release (\d+)\.(\d+)", ptxas_out
)
276 return (int(match
.group(1)), int(match
.group(2)))
277 print("couldn't determine ptxas version")
281 # Enable %ptxas and %ptxas-verify tools.
282 # %ptxas-verify defaults to sm_60 architecture. It can be overriden
283 # by specifying required one, for instance: %ptxas-verify -arch=sm_80.
284 def enable_ptxas(ptxas_executable
):
285 version
= ptxas_version(ptxas_executable
)
287 # ptxas is supposed to be backward compatible with previous
288 # versions, so add a feature for every known version prior to
290 ptxas_known_versions
= [
310 def version_int(ver
):
311 return ver
[0] * 100 + ver
[1]
313 # ignore ptxas if its version is below the minimum supported
315 min_version
= ptxas_known_versions
[0]
316 if version_int(version
) < version_int(min_version
):
318 "Warning: ptxas version {}.{} is not supported".format(
319 version
[0], version
[1]
324 for known_version
in ptxas_known_versions
:
325 if version_int(known_version
) <= version_int(version
):
326 major
, minor
= known_version
327 config
.available_features
.add("ptxas-{}.{}".format(major
, minor
))
329 config
.available_features
.add("ptxas")
332 ToolSubst("%ptxas", ptxas_executable
),
333 ToolSubst("%ptxas-verify", "{} -arch=sm_60 -c -".format(ptxas_executable
)),
339 os
.environ
.get("LLVM_PTXAS_EXECUTABLE", None) or config
.ptxas_executable
342 enable_ptxas(ptxas_executable
)
344 llvm_config
.add_tool_substitutions(tools
, config
.llvm_tools_dir
)
348 config
.targets
= frozenset(config
.targets_to_build
.split())
350 for arch
in config
.targets_to_build
.split():
351 config
.available_features
.add(arch
.lower() + "-registered-target")
354 known_arches
= ["x86_64", "mips64", "ppc64", "aarch64"]
355 if config
.host_ldflags
.find("-m32") < 0 and any(
356 config
.llvm_host_triple
.startswith(x
) for x
in known_arches
358 config
.available_features
.add("llvm-64-bits")
360 config
.available_features
.add("host-byteorder-" + sys
.byteorder
+ "-endian")
362 if sys
.platform
in ["win32"]:
363 # ExecutionEngine, no weak symbols in COFF.
364 config
.available_features
.add("uses_COFF")
366 # Others/can-execute.txt
367 config
.available_features
.add("can-execute")
370 if config
.has_plugins
:
371 config
.available_features
.add("plugins")
373 if config
.build_examples
:
374 config
.available_features
.add("examples")
376 if config
.linked_bye_extension
:
377 config
.substitutions
.append(("%llvmcheckext", "CHECK-EXT"))
378 config
.substitutions
.append(("%loadbye", ""))
379 config
.substitutions
.append(("%loadnewpmbye", ""))
381 config
.substitutions
.append(("%llvmcheckext", "CHECK-NOEXT"))
382 config
.substitutions
.append(
385 "-load={}/Bye{}".format(config
.llvm_shlib_dir
, config
.llvm_shlib_ext
),
388 config
.substitutions
.append(
391 "-load-pass-plugin={}/Bye{}".format(
392 config
.llvm_shlib_dir
, config
.llvm_shlib_ext
397 if config
.linked_exampleirtransforms_extension
:
398 config
.substitutions
.append(("%loadexampleirtransforms", ""))
400 config
.substitutions
.append(
402 "%loadexampleirtransforms",
403 "-load-pass-plugin={}/ExampleIRTransforms{}".format(
404 config
.llvm_shlib_dir
, config
.llvm_shlib_ext
409 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
410 if not config
.build_shared_libs
and not config
.link_llvm_dylib
:
411 config
.available_features
.add("static-libs")
413 if config
.link_llvm_dylib
:
414 config
.available_features
.add("llvm-dylib")
415 config
.substitutions
.append(
418 "{}/libLLVM-{}{}".format(
419 config
.llvm_shlib_dir
, config
.llvm_dylib_version
, config
.llvm_shlib_ext
424 if config
.have_tf_aot
:
425 config
.available_features
.add("have_tf_aot")
427 if config
.have_tflite
:
428 config
.available_features
.add("have_tflite")
430 if config
.llvm_inliner_model_autogenerated
:
431 config
.available_features
.add("llvm_inliner_model_autogenerated")
433 if config
.llvm_raevict_model_autogenerated
:
434 config
.available_features
.add("llvm_raevict_model_autogenerated")
437 def have_cxx_shared_library():
438 readobj_exe
= lit
.util
.which("llvm-readobj", config
.llvm_tools_dir
)
440 print("llvm-readobj not found")
444 readobj_cmd
= subprocess
.Popen(
445 [readobj_exe
, "--needed-libs", readobj_exe
], stdout
=subprocess
.PIPE
448 print("could not exec llvm-readobj")
451 readobj_out
= readobj_cmd
.stdout
.read().decode("ascii")
454 regex
= re
.compile(r
"(libc\+\+|libstdc\+\+|msvcp).*\.(so|dylib|dll)")
456 for line
in readobj_out
.splitlines():
457 if "NeededLibraries [" in line
:
461 if needed_libs
and regex
.search(line
.lower()):
466 if have_cxx_shared_library():
467 config
.available_features
.add("cxx-shared-library")
469 if config
.libcxx_used
:
470 config
.available_features
.add("libcxx-used")
472 # LLVM can be configured with an empty default triple
473 # Some tests are "generic" and require a valid default triple
474 if config
.target_triple
:
475 config
.available_features
.add("default_triple")
476 # Direct object generation
477 if not config
.target_triple
.startswith(("nvptx", "xcore")):
478 config
.available_features
.add("object-emission")
480 if config
.have_llvm_driver
:
481 config
.available_features
.add("llvm-driver")
486 def have_ld_plugin_support():
487 if not os
.path
.exists(
488 os
.path
.join(config
.llvm_shlib_dir
, "LLVMgold" + config
.llvm_shlib_ext
)
492 ld_cmd
= subprocess
.Popen(
493 [config
.gold_executable
, "--help"], stdout
=subprocess
.PIPE
, env
={"LANG": "C"}
495 ld_out
= ld_cmd
.stdout
.read().decode()
498 if not "-plugin" in ld_out
:
501 # check that the used emulations are supported.
502 emu_line
= [l
for l
in ld_out
.split("\n") if "supported emulations" in l
]
503 if len(emu_line
) != 1:
505 emu_line
= emu_line
[0]
506 fields
= emu_line
.split(":")
509 emulations
= fields
[2].split()
510 if "elf_x86_64" not in emulations
:
512 if "elf32ppc" in emulations
:
513 config
.available_features
.add("ld_emu_elf32ppc")
515 ld_version
= subprocess
.Popen(
516 [config
.gold_executable
, "--version"], stdout
=subprocess
.PIPE
, env
={"LANG": "C"}
518 if not "GNU gold" in ld_version
.stdout
.read().decode():
525 if have_ld_plugin_support():
526 config
.available_features
.add("ld_plugin")
529 def have_ld64_plugin_support():
530 if not os
.path
.exists(
531 os
.path
.join(config
.llvm_shlib_dir
, "libLTO" + config
.llvm_shlib_ext
)
535 if config
.ld64_executable
== "":
538 ld_cmd
= subprocess
.Popen([config
.ld64_executable
, "-v"], stderr
=subprocess
.PIPE
)
539 ld_out
= ld_cmd
.stderr
.read().decode()
542 if "ld64" not in ld_out
or "LTO" not in ld_out
:
548 if have_ld64_plugin_support():
549 config
.available_features
.add("ld64_plugin")
551 # Ask llvm-config about asserts
552 llvm_config
.feature_config(
554 ("--assertion-mode", {"ON": "asserts"}),
555 ("--build-mode", {"[Dd][Ee][Bb][Uu][Gg]": "debug"}),
559 if "darwin" == sys
.platform
:
560 cmd
= ["sysctl", "hw.optional.fma"]
561 sysctl_cmd
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
)
563 # Non zero return, probably a permission issue
564 if sysctl_cmd
.wait():
566 'Warning: sysctl exists but calling "{}" failed, defaulting to no fma3.'.format(
571 result
= sysctl_cmd
.stdout
.read().decode("ascii")
572 if "hw.optional.fma: 1" in result
:
573 config
.available_features
.add("fma3")
575 if not hasattr(sys
, "getwindowsversion") or sys
.getwindowsversion().build
>= 17063:
576 config
.available_features
.add("unix-sockets")
578 # .debug_frame is not emitted for targeting Windows x64, aarch64/arm64, AIX, or Apple Silicon Mac.
580 r
"^(x86_64|aarch64|arm64|powerpc|powerpc64).*-(windows-gnu|windows-msvc|aix)",
581 config
.target_triple
,
582 ) and not re
.match(r
"^arm64(e)?-apple-(macos|darwin)", config
.target_triple
):
583 config
.available_features
.add("debug_frame")
585 if config
.enable_threads
:
586 config
.available_features
.add("thread_support")
588 if config
.have_libxml2
:
589 config
.available_features
.add("libxml2")
592 config
.available_features
.add("curl")
594 if config
.have_httplib
:
595 config
.available_features
.add("httplib")
597 if config
.have_opt_viewer_modules
:
598 config
.available_features
.add("have_opt_viewer_modules")
600 if config
.expensive_checks
:
601 config
.available_features
.add("expensive_checks")
603 if "MemoryWithOrigins" in config
.llvm_use_sanitizer
:
604 config
.available_features
.add("use_msan_with_origins")
607 # Some tools support an environment variable "OBJECT_MODE" on AIX OS, which
608 # controls the kind of objects they will support. If there is no "OBJECT_MODE"
609 # environment variable specified, the default behaviour is to support 32-bit
610 # objects only. In order to not affect most test cases, which expect to support
611 # 32-bit and 64-bit objects by default, set the environment variable
612 # "OBJECT_MODE" to 'any' by default on AIX OS.
613 if "system-aix" in config
.available_features
:
614 config
.environment
["OBJECT_MODE"] = "any"