Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / profile / lit.cfg.py
blobd3ba115731c5dcbf7820a8715e714fec0be03033
1 # -*- Python -*-
3 import os
4 import re
7 def get_required_attr(config, attr_name):
8 attr_value = getattr(config, attr_name, None)
9 if attr_value == None:
10 lit_config.fatal(
11 "No attribute %r in test configuration! You may need to run "
12 "tests from your build directory or add this attribute "
13 "to lit.site.cfg.py " % attr_name
15 return attr_value
18 # Setup config name.
19 config.name = "Profile-" + config.target_arch
21 # Setup source root.
22 config.test_source_root = os.path.dirname(__file__)
24 # Setup executable root.
25 if (
26 hasattr(config, "profile_lit_binary_dir")
27 and config.profile_lit_binary_dir is not None
29 config.test_exec_root = os.path.join(config.profile_lit_binary_dir, config.name)
31 target_is_msvc = bool(re.match(r".*-windows-msvc$", config.target_triple))
33 if config.host_os in ["Linux"]:
34 extra_link_flags = ["-ldl"]
35 elif target_is_msvc:
36 # InstrProf is incompatible with incremental linking. Disable it as a
37 # workaround.
38 extra_link_flags = ["-Wl,-incremental:no"]
39 else:
40 extra_link_flags = []
42 # Test suffixes.
43 config.suffixes = [".c", ".cpp", ".m", ".mm", ".ll", ".test"]
45 # What to exclude.
46 config.excludes = ["Inputs"]
48 # Clang flags.
49 target_cflags = [get_required_attr(config, "target_cflags")]
50 clang_cflags = target_cflags + extra_link_flags
51 clang_cxxflags = config.cxx_mode_flags + clang_cflags
53 # TODO: target_cflags can sometimes contain C++ only flags like -stdlib=<FOO>, which are
54 # ignored when compiling as C code. Passing this flag when compiling as C results in
55 # warnings that break tests that use -Werror.
56 # We remove -stdlib= from the cflags here to avoid problems, but the interaction between
57 # CMake and compiler-rt's tests should be reworked so that cflags don't contain C++ only
58 # flags.
59 clang_cflags = [
60 flag.replace("-stdlib=libc++", "").replace("-stdlib=libstdc++", "")
61 for flag in clang_cflags
65 def build_invocation(compile_flags, with_lto=False):
66 lto_flags = []
67 if with_lto and config.lto_supported:
68 lto_flags += config.lto_flags
69 return " " + " ".join([config.clang] + lto_flags + compile_flags) + " "
72 def exclude_unsupported_files_for_aix(dirname):
73 for filename in os.listdir(dirname):
74 source_path = os.path.join(dirname, filename)
75 if os.path.isdir(source_path):
76 continue
77 f = open(source_path, "r")
78 try:
79 data = f.read()
80 # -fprofile-instr-generate and rpath are not supported on AIX, exclude all tests with them.
81 if (
82 "%clang_profgen" in data
83 or "%clangxx_profgen" in data
84 or "-rpath" in data
86 config.excludes += [filename]
87 finally:
88 f.close()
91 # Add clang substitutions.
92 config.substitutions.append(("%clang ", build_invocation(clang_cflags)))
93 config.substitutions.append(("%clangxx ", build_invocation(clang_cxxflags)))
95 config.substitutions.append(
96 ("%clang_profgen ", build_invocation(clang_cflags) + " -fprofile-instr-generate ")
98 config.substitutions.append(
99 ("%clang_profgen=", build_invocation(clang_cflags) + " -fprofile-instr-generate=")
101 config.substitutions.append(
103 "%clangxx_profgen ",
104 build_invocation(clang_cxxflags) + " -fprofile-instr-generate ",
107 config.substitutions.append(
109 "%clangxx_profgen=",
110 build_invocation(clang_cxxflags) + " -fprofile-instr-generate=",
114 config.substitutions.append(
115 ("%clang_pgogen ", build_invocation(clang_cflags) + " -fprofile-generate ")
117 config.substitutions.append(
118 ("%clang_pgogen=", build_invocation(clang_cflags) + " -fprofile-generate=")
120 config.substitutions.append(
121 ("%clangxx_pgogen ", build_invocation(clang_cxxflags) + " -fprofile-generate ")
123 config.substitutions.append(
124 ("%clangxx_pgogen=", build_invocation(clang_cxxflags) + " -fprofile-generate=")
127 config.substitutions.append(
128 ("%clang_cspgogen ", build_invocation(clang_cflags) + " -fcs-profile-generate ")
130 config.substitutions.append(
131 ("%clang_cspgogen=", build_invocation(clang_cflags) + " -fcs-profile-generate=")
133 config.substitutions.append(
134 ("%clangxx_cspgogen ", build_invocation(clang_cxxflags) + " -fcs-profile-generate ")
136 config.substitutions.append(
137 ("%clangxx_cspgogen=", build_invocation(clang_cxxflags) + " -fcs-profile-generate=")
140 config.substitutions.append(
141 ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=")
143 config.substitutions.append(
144 ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=")
147 config.substitutions.append(
148 ("%clang_pgouse=", build_invocation(clang_cflags) + " -fprofile-use=")
150 config.substitutions.append(
151 ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=")
154 config.substitutions.append(
156 "%clang_lto_profgen=",
157 build_invocation(clang_cflags, True) + " -fprofile-instr-generate=",
161 if config.host_os not in [
162 "Windows",
163 "Darwin",
164 "FreeBSD",
165 "Linux",
166 "NetBSD",
167 "SunOS",
168 "AIX",
170 config.unsupported = True
172 if config.host_os in ["AIX"]:
173 config.available_features.add("system-aix")
174 exclude_unsupported_files_for_aix(config.test_source_root)
175 exclude_unsupported_files_for_aix(config.test_source_root + "/Posix")
177 if config.target_arch in ["armv7l"]:
178 config.unsupported = True
180 if config.android:
181 config.unsupported = True