1# -*- Python -*- 2 3import os 4import re 5 6 7def get_required_attr(config, attr_name): 8 attr_value = getattr(config, attr_name, None) 9 if attr_value is 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 14 ) 15 return attr_value 16 17 18# Setup config name. 19config.name = "Profile-" + config.target_arch 20 21# Setup source root. 22config.test_source_root = os.path.dirname(__file__) 23 24# Setup executable root. 25if ( 26 hasattr(config, "profile_lit_binary_dir") 27 and config.profile_lit_binary_dir is not None 28): 29 config.test_exec_root = os.path.join(config.profile_lit_binary_dir, config.name) 30 31target_is_msvc = bool(re.match(r".*-windows-msvc$", config.target_triple)) 32 33# Whether continous profile collection (%c) requires runtime counter relocation on this platform 34runtime_reloc = bool(config.host_os in ["AIX", "Linux"]) 35 36if config.host_os in ["Linux"]: 37 extra_link_flags = ["-ldl"] 38elif target_is_msvc: 39 # InstrProf is incompatible with incremental linking. Disable it as a 40 # workaround. 41 extra_link_flags = ["-Wl,-incremental:no"] 42else: 43 extra_link_flags = [] 44 45# Test suffixes. 46config.suffixes = [".c", ".cpp", ".m", ".mm", ".ll", ".test"] 47 48# What to exclude. 49config.excludes = ["Inputs"] 50 51# Clang flags. 52target_cflags = [get_required_attr(config, "target_cflags")] 53clang_cflags = target_cflags + extra_link_flags 54clang_cxxflags = config.cxx_mode_flags + clang_cflags 55 56# TODO: target_cflags can sometimes contain C++ only flags like -stdlib=<FOO>, which are 57# ignored when compiling as C code. Passing this flag when compiling as C results in 58# warnings that break tests that use -Werror. 59# We remove -stdlib= from the cflags here to avoid problems, but the interaction between 60# CMake and compiler-rt's tests should be reworked so that cflags don't contain C++ only 61# flags. 62clang_cflags = [ 63 flag.replace("-stdlib=libc++", "").replace("-stdlib=libstdc++", "") 64 for flag in clang_cflags 65] 66 67 68def build_invocation(compile_flags, with_lto=False): 69 lto_flags = [] 70 if with_lto and config.lto_supported: 71 lto_flags += config.lto_flags 72 return " " + " ".join([config.clang] + lto_flags + compile_flags) + " " 73 74 75def exclude_unsupported_files_for_aix(dirname): 76 for filename in os.listdir(dirname): 77 source_path = os.path.join(dirname, filename) 78 if os.path.isdir(source_path): 79 continue 80 f = open(source_path, "r") 81 try: 82 data = f.read() 83 # rpath is not supported on AIX, exclude all tests with them. 84 if ( "-rpath" in data ): 85 config.excludes += [filename] 86 finally: 87 f.close() 88 89 90# Add clang substitutions. 91config.substitutions.append(("%clang ", build_invocation(clang_cflags))) 92config.substitutions.append(("%clangxx ", build_invocation(clang_cxxflags))) 93 94config.substitutions.append( 95 ("%clang_profgen ", build_invocation(clang_cflags) + " -fprofile-instr-generate ") 96) 97config.substitutions.append( 98 ("%clang_profgen=", build_invocation(clang_cflags) + " -fprofile-instr-generate=") 99) 100config.substitutions.append( 101 ( 102 "%clang_profgen_cont ", 103 build_invocation(clang_cflags) 104 + " -fprofile-instr-generate " 105 + ("-mllvm -runtime-counter-relocation " if runtime_reloc else ""), 106 ) 107) 108config.substitutions.append( 109 ( 110 "%clangxx_profgen ", 111 build_invocation(clang_cxxflags) + " -fprofile-instr-generate ", 112 ) 113) 114config.substitutions.append( 115 ( 116 "%clangxx_profgen=", 117 build_invocation(clang_cxxflags) + " -fprofile-instr-generate=", 118 ) 119) 120 121config.substitutions.append( 122 ("%clang_pgogen ", build_invocation(clang_cflags) + " -fprofile-generate ") 123) 124config.substitutions.append( 125 ("%clang_pgogen=", build_invocation(clang_cflags) + " -fprofile-generate=") 126) 127config.substitutions.append( 128 ( 129 "%clang_pgogen_cont ", 130 build_invocation(clang_cflags) 131 + " -fprofile-generate " 132 + ("-mllvm -runtime-counter-relocation " if runtime_reloc else ""), 133 ) 134) 135config.substitutions.append( 136 ("%clangxx_pgogen ", build_invocation(clang_cxxflags) + " -fprofile-generate ") 137) 138config.substitutions.append( 139 ("%clangxx_pgogen=", build_invocation(clang_cxxflags) + " -fprofile-generate=") 140) 141config.substitutions.append( 142 ( 143 "%clangxx_pgogen_cont ", 144 build_invocation(clang_cxxflags) 145 + " -fprofile-generate " 146 + ("-mllvm -runtime-counter-relocation " if runtime_reloc else ""), 147 ) 148) 149 150config.substitutions.append( 151 ("%clang_cspgogen ", build_invocation(clang_cflags) + " -fcs-profile-generate ") 152) 153config.substitutions.append( 154 ("%clang_cspgogen=", build_invocation(clang_cflags) + " -fcs-profile-generate=") 155) 156config.substitutions.append( 157 ("%clangxx_cspgogen ", build_invocation(clang_cxxflags) + " -fcs-profile-generate ") 158) 159config.substitutions.append( 160 ("%clangxx_cspgogen=", build_invocation(clang_cxxflags) + " -fcs-profile-generate=") 161) 162 163config.substitutions.append( 164 ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=") 165) 166config.substitutions.append( 167 ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") 168) 169 170config.substitutions.append( 171 ("%clang_pgouse=", build_invocation(clang_cflags) + " -fprofile-use=") 172) 173config.substitutions.append( 174 ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") 175) 176 177config.substitutions.append( 178 ( 179 "%clang_lto_profgen=", 180 build_invocation(clang_cflags, True) + " -fprofile-instr-generate=", 181 ) 182) 183 184if config.host_os not in [ 185 "Windows", 186 "Darwin", 187 "FreeBSD", 188 "Linux", 189 "NetBSD", 190 "SunOS", 191 "AIX", 192 "Haiku", 193]: 194 config.unsupported = True 195 196config.substitutions.append( 197 ("%shared_lib_flag", "-dynamiclib" if (config.host_os == "Darwin") else "-shared") 198) 199 200if config.host_os in ["AIX"]: 201 config.available_features.add("system-aix") 202 exclude_unsupported_files_for_aix(config.test_source_root) 203 exclude_unsupported_files_for_aix(config.test_source_root + "/Posix") 204 205if config.target_arch in ["armv7l"]: 206 config.unsupported = True 207 208if config.android: 209 config.unsupported = True 210 211if config.have_curl: 212 config.available_features.add("curl") 213 214if config.host_os in ("AIX", "Darwin", "Linux"): 215 config.available_features.add("continuous-mode") 216