7 def get_required_attr(config
, attr_name
):
8 attr_value
= getattr(config
, attr_name
, None)
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
19 config
.name
= "Profile-" + config
.target_arch
22 config
.test_source_root
= os
.path
.dirname(__file__
)
24 # Setup executable root.
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"]
36 # InstrProf is incompatible with incremental linking. Disable it as a
38 extra_link_flags
= ["-Wl,-incremental:no"]
43 config
.suffixes
= [".c", ".cpp", ".m", ".mm", ".ll", ".test"]
46 config
.excludes
= ["Inputs"]
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
60 flag
.replace("-stdlib=libc++", "").replace("-stdlib=libstdc++", "")
61 for flag
in clang_cflags
65 def build_invocation(compile_flags
, with_lto
=False):
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
):
77 f
= open(source_path
, "r")
80 # -fprofile-instr-generate and rpath are not supported on AIX, exclude all tests with them.
82 "%clang_profgen" in data
83 or "%clangxx_profgen" in data
86 config
.excludes
+= [filename
]
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(
104 build_invocation(clang_cxxflags
) + " -fprofile-instr-generate ",
107 config
.substitutions
.append(
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 [
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
181 config
.unsupported
= True