r256069 - [CMake] Support a simple case for bootstrap builds to generate PGO data

Chris Bieneman via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 18 16:56:10 PST 2015


Author: cbieneman
Date: Fri Dec 18 18:56:10 2015
New Revision: 256069

URL: http://llvm.org/viewvc/llvm-project?rev=256069&view=rev
Log:
[CMake] Support a simple case for bootstrap builds to generate PGO data

Summary:
This patch adds support for the clang multi-stage bootstrapping to support PGO profdata generation, and can build a 2 or 3 stage compiler.

With this patch applied you can configure your build directory with the following invocation of CMake:

cmake -G <generator> -C <path_to_clang>/cmake/caches/PGO.cmake <source dir>

After configuration the following additional targets will be generated:

stage2-instrumented:
Builds a stage1 x86 compiler, runtime, and required tools (llvm-config, llvm-profdata) then uses that compiler to build an instrumented stage2 compiler.

stage2-instrumented-generate-profdata:
Depends on "stage2-instrumented" and will use the instrumented compiler to generate profdata based on the training files in <clang>/utils/perf-training

stage2:
Depends on "stage2-instrumented-generate-profdata" and will use the stage1 compiler with the stage2 profdata to build a PGO-optimized compiler.

stage2-check-llvm:
Depends on stage2 and runs check-llvm using the stage3 compiler.

stage2-check-clang:
Depends on stage2 and runs check-clang using the stage3 compiler.

stage2-check-all:
Depends on stage2 and runs check-all using the stage3 compiler.

stage2-test-suite:
Depends on stage2 and runs the test-suite using the stage3 compiler (requires in-tree test-suite).

Reviewers: bogner, silvas, chandlerc

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D15584

Added:
    cfe/trunk/cmake/caches/PGO-stage2.cmake
    cfe/trunk/cmake/caches/PGO-stage3.cmake
    cfe/trunk/cmake/caches/PGO.cmake
Modified:
    cfe/trunk/CMakeLists.txt

Modified: cfe/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=256069&r1=256068&r2=256069&view=diff
==============================================================================
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Fri Dec 18 18:56:10 2015
@@ -631,11 +631,19 @@ if (CLANG_ENABLE_BOOTSTRAP)
 
   string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}")
   if(MATCHED_STAGE)
-    math(EXPR STAGE_NUM "${MATCHED_STAGE} + 1")
-    set(NEXT_CLANG_STAGE stage${STAGE_NUM})
+    if(NOT LLVM_BUILD_INSTRUMENTED)
+      math(EXPR STAGE_NUM "${CMAKE_MATCH_1} + 1")
+      set(NEXT_CLANG_STAGE stage${STAGE_NUM})
+    else()
+      set(NEXT_CLANG_STAGE stage${CMAKE_MATCH_1})
+    endif()
   else()
     set(NEXT_CLANG_STAGE bootstrap)
   endif()
+
+  if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
+    set(NEXT_CLANG_STAGE ${NEXT_CLANG_STAGE}-instrumented)
+  endif()
   message(STATUS "Setting next clang stage to: ${NEXT_CLANG_STAGE}")
   
   
@@ -681,6 +689,26 @@ if (CLANG_ENABLE_BOOTSTRAP)
     set(RUNTIME_DEP compiler-rt)
   endif()
 
+  set(COMPILER_OPTIONS
+    -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+    -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
+    -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
+
+  if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
+    set(PGO_DEP llvm-profdata)
+    set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
+  endif()
+
+  if(LLVM_BUILD_INSTRUMENTED)
+    set(PGO_DEP generate-profdata)
+    set(PGO_OPT -DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+    set(COMPILER_OPTIONS
+      -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
+      -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+      -DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER})
+    set(RUNTIME_DEP) # Don't set runtime dependencies
+  endif()
+
   # Find all variables that start with BOOTSTRAP_ and populate a variable with
   # them.
   get_cmake_property(variableNames VARIABLES)
@@ -703,7 +731,7 @@ if (CLANG_ENABLE_BOOTSTRAP)
   endforeach()
 
   ExternalProject_Add(${NEXT_CLANG_STAGE}
-    DEPENDS clang ${LTO_DEP} ${RUNTIME_DEP}
+    DEPENDS clang ${LTO_DEP} ${RUNTIME_DEP} ${PGO_DEP}
     PREFIX ${NEXT_CLANG_STAGE}
     SOURCE_DIR ${CMAKE_SOURCE_DIR}
     STAMP_DIR ${STAMP_DIR}
@@ -715,11 +743,9 @@ if (CLANG_ENABLE_BOOTSTRAP)
                 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
                 ${CLANG_BOOTSTRAP_CMAKE_ARGS}
                 ${PASSTHROUGH_VARIABLES}
-                -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
-                -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-                -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-                -DCLANG_STAGE=${NEXT_CLANG_STAGE}
-                ${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} ${verbose}
+                 -DCLANG_STAGE=${NEXT_CLANG_STAGE}
+                ${COMPILER_OPTIONS}
+                ${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} ${verbose} ${PGO_OPT}
     INSTALL_COMMAND ""
     STEP_TARGETS configure build
     ${cmake_3_4_USES_TERMINAL_OPTIONS}

Added: cfe/trunk/cmake/caches/PGO-stage2.cmake
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/PGO-stage2.cmake?rev=256069&view=auto
==============================================================================
--- cfe/trunk/cmake/caches/PGO-stage2.cmake (added)
+++ cfe/trunk/cmake/caches/PGO-stage2.cmake Fri Dec 18 18:56:10 2015
@@ -0,0 +1,9 @@
+set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(LLVM_BUILD_EXTERNAL_COMPILER_RT ON CACHE BOOL "")
+
+set(CLANG_BOOTSTRAP_TARGETS check-all check-llvm check-clang test-suite CACHE STRING "")
+
+set(CLANG_BOOTSTRAP_CMAKE_ARGS
+  -C ${CMAKE_CURRENT_LIST_DIR}/PGO-stage3.cmake
+  CACHE STRING "")

Added: cfe/trunk/cmake/caches/PGO-stage3.cmake
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/PGO-stage3.cmake?rev=256069&view=auto
==============================================================================
--- cfe/trunk/cmake/caches/PGO-stage3.cmake (added)
+++ cfe/trunk/cmake/caches/PGO-stage3.cmake Fri Dec 18 18:56:10 2015
@@ -0,0 +1,2 @@
+set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
+set(LLVM_BUILD_EXTERNAL_COMPILER_RT ON CACHE BOOL "")

Added: cfe/trunk/cmake/caches/PGO.cmake
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/PGO.cmake?rev=256069&view=auto
==============================================================================
--- cfe/trunk/cmake/caches/PGO.cmake (added)
+++ cfe/trunk/cmake/caches/PGO.cmake Fri Dec 18 18:56:10 2015
@@ -0,0 +1,17 @@
+set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(LLVM_BUILD_EXTERNAL_COMPILER_RT ON CACHE BOOL "")
+
+set(LLVM_TARGETS_TO_BUILD X86 CACHE STRING "")
+set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_TARGETS
+  generate-profdata
+  stage2
+  stage2-check-all
+  stage2-check-llvm
+  stage2-check-clang
+  stage2-test-suite CACHE STRING "")
+
+set(CLANG_BOOTSTRAP_CMAKE_ARGS
+  -C ${CMAKE_CURRENT_LIST_DIR}/PGO-stage2.cmake
+  CACHE STRING "")




More information about the cfe-commits mailing list