Chromium Code Reviews| Index: tools/clang/scripts/update.py |
| diff --git a/tools/clang/scripts/update.py b/tools/clang/scripts/update.py |
| index 2ea0d6d3d21b8651672061f4e6df6abc2cd3ae42..a71b4a5706c03b49a9b90880ae47b229ad233e27 100755 |
| --- a/tools/clang/scripts/update.py |
| +++ b/tools/clang/scripts/update.py |
| @@ -283,7 +283,6 @@ def CreateChromeToolsShim(): |
| f.write('# two arg version to specify where build artifacts go. CMake\n') |
| f.write('# disallows reuse of the same binary dir for multiple source\n') |
| f.write('# dirs, so the build artifacts need to go into a subdirectory.\n') |
| - f.write('# dirs, so the build artifacts need to go into a subdirectory.\n') |
|
Nico
2017/04/07 15:58:53
Also a good change, but also unrelated.
|
| f.write('if (CHROMIUM_TOOLS_SRC)\n') |
| f.write(' add_subdirectory(${CHROMIUM_TOOLS_SRC} ' + |
| '${CMAKE_CURRENT_BINARY_DIR}/a)\n') |
| @@ -376,6 +375,62 @@ def CopyDiaDllTo(target_dir): |
| CopyFile(dia_dll, target_dir) |
| +def GetNewCCAndCXX(install_dir): |
| + if sys.platform == 'win32': |
| + cc = os.path.join(install_dir, 'bin', 'clang-cl.exe') |
| + cxx = os.path.join(install_dir, 'bin', 'clang-cl.exe') |
| + # CMake has a hard time with backslashes in compiler paths: |
| + # https://stackoverflow.com/questions/13050827 |
| + cc = cc.replace('\\', '/') |
| + cxx = cxx.replace('\\', '/') |
| + else: |
| + cc = os.path.join(install_dir, 'bin', 'clang') |
| + cxx = os.path.join(install_dir, 'bin', 'clang++') |
| + |
| + return cc, cxx |
| + |
| + |
| +def BuildLLVMgold(args, install_dir, base_cmake_args, binutils_incdir, cc, cxx): |
| + # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%. |
| + # We only use LTO for Linux now. |
| + print 'Building LTO LLVM Gold plugin' |
| + if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR): |
| + RmTree(LLVM_LTO_GOLD_PLUGIN_DIR) |
| + EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR) |
| + os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR) |
| + |
| + # Create a symlink to LLVMgold.so build in the previous step so that ar |
| + # and ranlib could find it while linking LLVMgold.so with LTO. |
| + EnsureDirExists(BFD_PLUGINS_DIR) |
| + RunCommand(['ln', '-sf', |
| + os.path.join(install_dir, 'lib', 'LLVMgold.so'), |
| + os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')]) |
| + |
| + lto_cflags = ['-flto=thin'] |
| + lto_ldflags = ['-fuse-ld=lld'] |
| + if args.gcc_toolchain: |
| + # Tell the bootstrap compiler to use a specific gcc prefix to search |
| + # for standard library headers and shared object files. |
| + lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain] |
| + lto_cmake_args = base_cmake_args + [ |
| + '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, |
| + '-DCMAKE_C_COMPILER=' + cc, |
| + '-DCMAKE_CXX_COMPILER=' + cxx, |
| + '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags), |
| + '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags), |
| + '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags), |
| + '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags), |
| + '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)] |
| + |
| + # We need to use the proper binutils which support LLVM Gold plugin. |
| + lto_env = os.environ.copy() |
| + lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '') |
| + |
| + RmCmakeCache('.') |
| + RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env) |
| + RunCommand(['ninja', 'LLVMgold', 'lld'], env=lto_env) |
| + |
| + |
| def VeryifyVersionOfBuiltClangMatchesVERSION(): |
| """Checks that `clang --version` outputs VERSION. If this fails, VERSION |
| in this file is out-of-date and needs to be updated (possibly in an |
| @@ -464,6 +519,10 @@ def UpdateClang(args): |
| # make sure it's not around on future builds. |
| RmTree(LLD_DIR) |
| Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) |
| + if args.enable_pgo and sys.platform != 'win32': |
| + # PGO requires compiler-rt. |
| + Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', |
| + os.path.join(LLVM_DIR, 'projects', 'compiler-rt')) |
|
Nico
2017/04/07 15:58:53
IIRC package.py packages based on blacklists inste
matthewtff.asm
2017/04/11 12:14:43
The only diff I've got is one header file:
lib/cla
|
| if sys.platform == 'darwin': |
| # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes |
| # (i.e. this is needed for bootstrap builds). |
| @@ -530,17 +589,7 @@ def UpdateClang(args): |
| # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap |
| # compiler can start. |
| CopyFile(libstdcpp, os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib')) |
| - |
| - if sys.platform == 'win32': |
| - cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang-cl.exe') |
| - cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang-cl.exe') |
| - # CMake has a hard time with backslashes in compiler paths: |
| - # https://stackoverflow.com/questions/13050827 |
| - cc = cc.replace('\\', '/') |
| - cxx = cxx.replace('\\', '/') |
| - else: |
| - cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang') |
| - cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang++') |
| + cc, cxx = GetNewCCAndCXX(LLVM_BOOTSTRAP_INSTALL_DIR) |
| if args.gcc_toolchain: |
| # Tell the bootstrap compiler to use a specific gcc prefix to search |
| @@ -549,46 +598,9 @@ def UpdateClang(args): |
| cxxflags = ['--gcc-toolchain=' + args.gcc_toolchain] |
| print 'Building final compiler' |
| - # Build LLVM gold plugin with LTO. That speeds up the linker by ~10%. |
| - # We only use LTO for Linux now. |
| if args.bootstrap and args.lto_gold_plugin: |
|
Nico
2017/04/07 15:58:53
This is now never true (assuming we default to PGO
|
| - print 'Building LTO LLVM Gold plugin' |
| - if os.path.exists(LLVM_LTO_GOLD_PLUGIN_DIR): |
| - RmTree(LLVM_LTO_GOLD_PLUGIN_DIR) |
| - EnsureDirExists(LLVM_LTO_GOLD_PLUGIN_DIR) |
| - os.chdir(LLVM_LTO_GOLD_PLUGIN_DIR) |
| - |
| - # Create a symlink to LLVMgold.so build in the previous step so that ar |
| - # and ranlib could find it while linking LLVMgold.so with LTO. |
| - EnsureDirExists(BFD_PLUGINS_DIR) |
| - RunCommand(['ln', '-sf', |
| - os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'lib', 'LLVMgold.so'), |
| - os.path.join(BFD_PLUGINS_DIR, 'LLVMgold.so')]) |
| - |
| - lto_cflags = ['-flto=thin'] |
| - lto_ldflags = ['-fuse-ld=lld'] |
| - if args.gcc_toolchain: |
| - # Tell the bootstrap compiler to use a specific gcc prefix to search |
| - # for standard library headers and shared object files. |
| - lto_cflags += ['--gcc-toolchain=' + args.gcc_toolchain] |
| - lto_cmake_args = base_cmake_args + [ |
| - '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, |
| - '-DCMAKE_C_COMPILER=' + cc, |
| - '-DCMAKE_CXX_COMPILER=' + cxx, |
| - '-DCMAKE_C_FLAGS=' + ' '.join(lto_cflags), |
| - '-DCMAKE_CXX_FLAGS=' + ' '.join(lto_cflags), |
| - '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(lto_ldflags), |
| - '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(lto_ldflags), |
| - '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(lto_ldflags)] |
| - |
| - # We need to use the proper binutils which support LLVM Gold plugin. |
| - lto_env = os.environ.copy() |
| - lto_env['PATH'] = BINUTILS_BIN_DIR + os.pathsep + lto_env.get('PATH', '') |
| - |
| - RmCmakeCache('.') |
| - RunCommand(['cmake'] + lto_cmake_args + [LLVM_DIR], env=lto_env) |
| - RunCommand(['ninja', 'LLVMgold', 'lld'], env=lto_env) |
| - |
| + BuildLLVMgold(args, LLVM_BOOTSTRAP_INSTALL_DIR, binutils_incdir, |
| + base_cmake_args, cc, cxx) |
| # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is |
| # needed, on OS X it requires libc++. clang only automatically links to libc++ |
| @@ -596,7 +608,7 @@ def UpdateClang(args): |
| # on OS X versions as old as 10.7. |
| deployment_target = '' |
| - if sys.platform == 'darwin' and args.bootstrap: |
| + if sys.platform == 'darwin' and (args.bootstrap or args.enable_pgo): |
| # When building on 10.9, /usr/include usually doesn't exist, and while |
| # Xcode's clang automatically sets a sysroot, self-built clangs don't. |
| cflags = ['-isysroot', subprocess.check_output( |
| @@ -604,10 +616,11 @@ def UpdateClang(args): |
| cxxflags = ['-stdlib=libc++'] + cflags |
| ldflags += ['-stdlib=libc++'] |
| deployment_target = '10.7' |
| - # Running libc++ tests takes a long time. Since it was only needed for |
| - # the install step above, don't build it as part of the main build. |
| - # This makes running package.py over 10% faster (30 min instead of 34 min) |
| - RmTree(LIBCXX_DIR) |
| + if not args.enable_pgo: |
|
Nico
2017/04/07 15:58:53
Why this change?
matthewtff.asm
2017/04/11 12:14:43
We need to build clang with libcxx checked out in
|
| + # Running libc++ tests takes a long time. Since it was only needed for |
| + # the install step above, don't build it as part of the main build. |
| + # This makes running package.py over 10% faster (30 min instead of 34 min) |
| + RmTree(LIBCXX_DIR) |
| # Build clang. |
| @@ -638,6 +651,30 @@ def UpdateClang(args): |
| if cc is not None: cc_args.append('-DCMAKE_C_COMPILER=' + cc) |
| if cxx is not None: cc_args.append('-DCMAKE_CXX_COMPILER=' + cxx) |
| chrome_tools = list(set(['plugins', 'blink_gc_plugin'] + args.extra_tools)) |
| + |
| + |
| + if args.enable_pgo: |
| + pgo_cache_path = os.path.join( |
| + LLVM_DIR, 'tools', 'clang', 'cmake', 'caches', 'PGO.cmake') |
| + pgo_stage2_cache = os.path.join( |
| + CHROMIUM_DIR, 'tools', 'clang', 'PGO-stage2.cmake') |
| + cmake_args += [ |
| + '-DBOOTSTRAP_BOOTSTRAP_CHROMIUM_TOOLS=%s' % ','.join(chrome_tools), |
| + '-DCMAKE_VERBOSE_MAKEFILE=ON', |
| + '-DBOOTSTRAP_CMAKE_VERBOSE_MAKEFILE=ON', |
| + '-DBOOTSTRAP_BOOTSTRAP_CMAKE_VERBOSE_MAKEFILE=ON', |
| + '-DPGO_BUILD_CONFIGURATION=%s' % pgo_stage2_cache, |
| + '-C', pgo_cache_path, |
| + '-DBOOTSTRAP_LLVM_BINUTILS_INCDIR=' + binutils_incdir, |
| + '-DBOOTSTRAP_CMAKE_C_FLAGS=' + ' '.join(cflags), |
| + '-DBOOTSTRAP_CMAKE_CXX_FLAGS=' + ' '.join(cxxflags), |
| + '-DBOOTSTRAP_BOOTSTRAP_LLVM_BINUTILS_INCDIR=' + binutils_incdir, |
| + '-DBOOTSTRAP_BOOTSTRAP_CMAKE_C_FLAGS=' + ' '.join(cflags), |
| + '-DBOOTSTRAP_BOOTSTRAP_CMAKE_CXX_FLAGS=' + ' '.join(cxxflags), |
| + '-DBOOTSTRAP_BOOTSTRAP_CMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags), |
| + '-DBOOTSTRAP_BOOTSTRAP_CMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags), |
| + '-DBOOTSTRAP_BOOTSTRAP_CMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags), |
| + ] |
| cmake_args += base_cmake_args + [ |
| '-DLLVM_ENABLE_THREADS=OFF', |
| '-DLLVM_BINUTILS_INCDIR=' + binutils_incdir, |
| @@ -651,7 +688,7 @@ def UpdateClang(args): |
| # explicitly, https://crbug.com/622775 |
| '-DENABLE_LINKER_BUILD_ID=ON', |
| '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(CHROMIUM_DIR, 'tools', 'clang'), |
| - '-DCHROMIUM_TOOLS=%s' % ';'.join(chrome_tools)] |
| + '-DCHROMIUM_TOOLS=%s' % ','.join(chrome_tools)] |
| EnsureDirExists(LLVM_BUILD_DIR) |
| os.chdir(LLVM_BUILD_DIR) |
| @@ -659,6 +696,14 @@ def UpdateClang(args): |
| RunCommand(['cmake'] + cmake_args + [LLVM_DIR], |
| msvc_arch='x64', env=deployment_env) |
| + ninja_target = 'stage2' if args.enable_pgo else 'all' |
| + RunCommand(['ninja', ninja_target], env=deployment_env, msvc_arch='x64') |
| + |
| + if args.enable_pgo: |
| + global LLVM_BUILD_DIR |
| + LLVM_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, 'tools', 'clang', |
| + 'stage2-instrumented-bins', 'tools', 'clang', 'stage2-bins') |
| + |
| if args.gcc_toolchain: |
| # Copy in the right stdlibc++.so.6 so clang can start. |
| if not os.path.exists(os.path.join(LLVM_BUILD_DIR, 'lib')): |
| @@ -667,17 +712,20 @@ def UpdateClang(args): |
| [cxx] + cxxflags + ['-print-file-name=libstdc++.so.6']).rstrip() |
| CopyFile(libstdcpp, os.path.join(LLVM_BUILD_DIR, 'lib')) |
| - RunCommand(['ninja'], msvc_arch='x64') |
| - |
| - # Copy LTO-optimized lld, if any. |
| - if args.bootstrap and args.lto_gold_plugin: |
| - CopyFile(os.path.join(LLVM_LTO_GOLD_PLUGIN_DIR, 'bin', 'lld'), |
| - os.path.join(LLVM_BUILD_DIR, 'bin')) |
| - |
| if chrome_tools: |
| # If any Chromium tools were built, install those now. |
| RunCommand(['ninja', 'cr-install'], msvc_arch='x64') |
| + # Copy LTO-optimized lld, if any. |
| + if args.lto_gold_plugin: |
| + if args.enable_pgo: |
| + cc, cxx = GetNewCCAndCXX(LLVM_BUILD_DIR) |
| + BuildLLVMgold(args, LLVM_BUILD_DIR, base_cmake_args, |
| + binutils_incdir, cc, cxx) |
| + if args.bootstrap or args.enable_pgo: |
| + CopyFile(os.path.join(LLVM_LTO_GOLD_PLUGIN_DIR, 'bin', 'lld'), |
| + os.path.join(LLVM_BUILD_DIR, 'bin')) |
| + |
| if sys.platform == 'darwin': |
| # See http://crbug.com/256342 |
| RunCommand(['strip', '-x', os.path.join(LLVM_BUILD_DIR, 'bin', 'clang')]) |
| @@ -865,14 +913,25 @@ def main(): |
| help='don\'t build Android ASan runtime (linux only)', |
| dest='with_android', |
| default=sys.platform.startswith('linux')) |
| + parser.add_argument('--enable-pgo', action='store_true', |
| + help='build clang in 2 stages using PGO') |
| args = parser.parse_args() |
| - if args.lto_gold_plugin and not args.bootstrap: |
| - print '--lto-gold-plugin requires --bootstrap' |
| + if args.lto_gold_plugin and (not args.bootstrap and not args.enable_pgo): |
| + print '--lto-gold-plugin requires --bootstrap or --enable-pgo' |
| return 1 |
| if args.lto_gold_plugin and not sys.platform.startswith('linux'): |
| print '--lto-gold-plugin is only effective on Linux. Ignoring the option.' |
| args.lto_gold_plugin = False |
| + if args.enable_pgo: |
| + if args.bootstrap: |
| + print '--bootstrap makes no sense with --enable-pgo specified' |
| + return 1 |
| + if not args.force_local_build: |
| + print '--enable-pgo makes no sense without --force-local-build' |
| + return 1 |
| + if sys.platform == 'win32': |
| + print '--enable-pgo not supported on Windows' |
| if args.if_needed: |
| # TODO(thakis): Can probably remove this and --if-needed altogether. |