Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -430,6 +430,18 @@ set(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION FALSE CACHE INTERNAL "For Visual Studio 2013, manually copy natvis files to Documents\\Visual Studio 2013\\Visualizers" FORCE) endif() +if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE) + if(NOT LLVM_PROFILE_DATA_DIR) + message(FATAL_ERROR "Must set LLVM_PROFILE_DATA_DIR to point to a directory") + endif() + if(NOT LLVM_PROFILE_MERGE_POOL_SIZE) + set(LLVM_PROFILE_MERGE_POOL_SIZE "9") + endif() + if(NOT LLVM_PROFILE_FILE_PATTERN) + file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN) + endif() +endif() + # All options referred to from HandleLLVMOptions have to be specified # BEFORE this include, otherwise options will not be correctly set on # first cmake run Index: cmake/modules/HandleLLVMOptions.cmake =================================================================== --- cmake/modules/HandleLLVMOptions.cmake +++ cmake/modules/HandleLLVMOptions.cmake @@ -598,7 +598,15 @@ option(LLVM_BUILD_INSTRUMENTED "Build LLVM and tools with PGO instrumentation (experimental)" Off) mark_as_advanced(LLVM_BUILD_INSTRUMENTED) -append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate" +append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate=${LLVM_PROFILE_FILE_PATTERN}" + CMAKE_CXX_FLAGS + CMAKE_C_FLAGS + CMAKE_EXE_LINKER_FLAGS + CMAKE_SHARED_LINKER_FLAGS) + +option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation (experimental)" Off) +mark_as_advanced(LLVM_BUILD_INSTRUMENTED_COVERAGE) +append_if(LLVM_BUILD_INSTRUMENTED_COVERAGE "-fprofile-instr-generate=${LLVM_PROFILE_FILE_PATTERN} -fcoverage-mapping" CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_EXE_LINKER_FLAGS Index: utils/prepare-code-coverage-artifact.sh =================================================================== --- /dev/null +++ utils/prepare-code-coverage-artifact.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +if [ "$#" -ne 4 ]; then + echo "Usage:" + echo "$0 " + exit 1 +fi + +HOST_LLVM_PROFDATA=$1 +HOST_LLVM_COV=$2 +LLVM_PROFILE_DATA_DIR=$3 +LLVM_BIN_DIR=$4 + +echo ":: llvm-profdata = " $HOST_LLVM_PROFDATA +echo ":: llvm-cov = " $HOST_LLVM_COV + +echo ":: Merging raw profiles in $LLVM_PROFILE_DATA_DIR" +find $LLVM_PROFILE_DATA_DIR -name \*.profraw > $LLVM_PROFILE_DATA_DIR/profiles.list +$HOST_LLVM_PROFDATA merge -sparse -f $LLVM_PROFILE_DATA_DIR/profiles.list -o $LLVM_PROFILE_DATA_DIR/Coverage.profdata + +echo ":: Deleting raw profiles in $LLVM_PROFILE_DATA_DIR" +find $LLVM_PROFILE_DATA_DIR -name \*.profraw -exec rm {} \; + +echo ":: Copying covmappings from $LLVM_BIN_DIR into $LLVM_PROFILE_DATA_DIR" +for prog in $(find $LLVM_BIN_DIR -type f | grep -v llvm-lit); do + $HOST_LLVM_COV convert-for-testing $prog -o $LLVM_PROFILE_DATA_DIR/$(basename $prog).covmapping +done