5 def get_required_attr(config, attr_name):
6 attr_value = getattr(config, attr_name, None)
9 "No attribute %r in test configuration! You may need to run "
10 "tests from your build directory or add this attribute "
11 "to lit.site.cfg " % attr_name)
15 config.name = 'Profile-' + config.target_arch
18 config.test_source_root = os.path.dirname(__file__)
20 # Setup executable root.
21 if hasattr(config, 'profile_lit_binary_dir') and \
22 config.profile_lit_binary_dir is not None:
23 config.test_exec_root = os.path.join(config.profile_lit_binary_dir, config.name)
25 # If the above check didn't work, we're probably in the source tree. Use some
26 # magic to re-execute from the build tree.
27 if config.test_exec_root is None:
28 # The magic relies on knowing compilerrt_site_basedir.
29 compilerrt_basedir = lit_config.params.get('compilerrt_site_basedir', None)
30 if compilerrt_basedir:
31 site_cfg = os.path.join(compilerrt_basedir, 'profile', 'lit.site.cfg')
32 if os.path.exists(site_cfg):
33 lit_config.load_config(config, site_cfg)
36 if config.host_os in ['Linux']:
37 extra_link_flags = ["-ldl"]
42 config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm', '.ll', '.test']
45 config.excludes = ['Inputs']
48 target_cflags=[get_required_attr(config, "target_cflags")]
49 clang_cflags = target_cflags + extra_link_flags
50 clang_cxxflags = config.cxx_mode_flags + clang_cflags
52 def build_invocation(compile_flags, with_lto = False):
55 if with_lto and config.lto_supported:
56 lto_flags += config.lto_flags
57 lto_prefix += config.lto_launch
58 return " " + " ".join(lto_prefix + [config.clang] + lto_flags + compile_flags) + " "
60 # Add clang substitutions.
61 config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
62 config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )
63 config.substitutions.append( ("%clang_profgen ", build_invocation(clang_cflags) + " -fprofile-instr-generate ") )
64 config.substitutions.append( ("%clang_profgen=", build_invocation(clang_cflags) + " -fprofile-instr-generate=") )
65 config.substitutions.append( ("%clang_pgogen ", build_invocation(clang_cflags) + " -fprofile-generate ") )
66 config.substitutions.append( ("%clang_pgogen=", build_invocation(clang_cflags) + " -fprofile-generate=") )
68 config.substitutions.append( ("%clangxx_profgen ", build_invocation(clang_cxxflags) + " -fprofile-instr-generate ") )
69 config.substitutions.append( ("%clangxx_profgen=", build_invocation(clang_cxxflags) + " -fprofile-instr-generate=") )
70 config.substitutions.append( ("%clangxx_pgogen ", build_invocation(clang_cxxflags) + " -fprofile-generate ") )
71 config.substitutions.append( ("%clangxx_pgogen=", build_invocation(clang_cxxflags) + " -fprofile-generate=") )
73 config.substitutions.append( ("%clang_profgen_gcc=", build_invocation(clang_cflags) + " -fprofile-generate=") )
74 config.substitutions.append( ("%clang_profuse_gcc=", build_invocation(clang_cflags) + " -fprofile-use=") )
76 config.substitutions.append( ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=") )
77 config.substitutions.append( ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") )
79 config.substitutions.append( ("%clang_lto_profgen=", build_invocation(clang_cflags, True) + " -fprofile-instr-generate=") )
81 if config.host_os not in ['Darwin', 'FreeBSD', 'Linux']:
82 config.unsupported = True
84 if config.target_arch in ['armv7l']:
85 config.unsupported = True