1# -*- Python -*- 2 3import os 4 5def get_required_attr(config, attr_name): 6 attr_value = getattr(config, attr_name, None) 7 if attr_value == None: 8 lit_config.fatal( 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.py " % attr_name) 12 return attr_value 13 14# Setup config name. 15config.name = 'Profile-' + config.target_arch 16 17# Setup source root. 18config.test_source_root = os.path.dirname(__file__) 19 20# Setup executable root. 21if 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) 24 25if config.host_os in ['Linux']: 26 extra_link_flags = ["-ldl"] 27elif config.host_os in ['Windows']: 28 # InstrProf is incompatible with incremental linking. Disable it as a 29 # workaround. 30 extra_link_flags = ["-Wl,-incremental:no"] 31else: 32 extra_link_flags = [] 33 34# Test suffixes. 35config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.test'] 36 37# What to exclude. 38config.excludes = ['Inputs'] 39 40# Clang flags. 41target_cflags=[get_required_attr(config, "target_cflags")] 42clang_cflags = target_cflags + extra_link_flags 43clang_cxxflags = config.cxx_mode_flags + clang_cflags 44 45def build_invocation(compile_flags, with_lto = False): 46 lto_flags = [] 47 lto_prefix = [] 48 if with_lto and config.lto_supported: 49 lto_flags += config.lto_flags 50 lto_prefix += config.lto_launch 51 return " " + " ".join(lto_prefix + [config.clang] + lto_flags + compile_flags) + " " 52 53# Add clang substitutions. 54config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) ) 55config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) ) 56config.substitutions.append( ("%clang_profgen ", build_invocation(clang_cflags) + " -fprofile-instr-generate ") ) 57config.substitutions.append( ("%clang_profgen=", build_invocation(clang_cflags) + " -fprofile-instr-generate=") ) 58config.substitutions.append( ("%clang_pgogen ", build_invocation(clang_cflags) + " -fprofile-generate ") ) 59config.substitutions.append( ("%clang_pgogen=", build_invocation(clang_cflags) + " -fprofile-generate=") ) 60 61config.substitutions.append( ("%clangxx_profgen ", build_invocation(clang_cxxflags) + " -fprofile-instr-generate ") ) 62config.substitutions.append( ("%clangxx_profgen=", build_invocation(clang_cxxflags) + " -fprofile-instr-generate=") ) 63config.substitutions.append( ("%clangxx_pgogen ", build_invocation(clang_cxxflags) + " -fprofile-generate ") ) 64config.substitutions.append( ("%clangxx_pgogen=", build_invocation(clang_cxxflags) + " -fprofile-generate=") ) 65 66config.substitutions.append( ("%clang_profgen_gcc=", build_invocation(clang_cflags) + " -fprofile-generate=") ) 67config.substitutions.append( ("%clang_profuse_gcc=", build_invocation(clang_cflags) + " -fprofile-use=") ) 68 69config.substitutions.append( ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=") ) 70config.substitutions.append( ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") ) 71 72config.substitutions.append( ("%clang_lto_profgen=", build_invocation(clang_cflags, True) + " -fprofile-instr-generate=") ) 73 74if config.host_os not in ['Windows', 'Darwin', 'FreeBSD', 'Linux', 'NetBSD', 'SunOS']: 75 config.unsupported = True 76 77if config.target_arch in ['armv7l']: 78 config.unsupported = True 79 80if config.android: 81 config.unsupported = True 82