Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Actions: Extend PGO to C++ parts of LDC #3982

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
10 changes: 7 additions & 3 deletions .github/actions/1-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ runs:
libcurl4 libcurl4:i386 \
curl gdb=8.1.1-0ubuntu1 p7zip-full tzdata unzip zip python3-pip

- name: 'Linux: Download & extract clang' # into ../clang
if: runner.os == 'Linux'
- name: 'Posix: Download & extract clang' # into ../clang
if: runner.os != 'Windows'
shell: bash
run: |
set -eux
cd ..
os="linux-gnu-ubuntu-18.04"
if [[ '${{ runner.os }}' == macOS ]]; then
os="apple-darwin"
fi
curl -fL --retry 3 --max-time 300 -o clang.tar.xz \
https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ inputs.clang_version }}/clang+llvm-${{ inputs.clang_version }}-x86_64-linux-gnu-ubuntu-18.04.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ inputs.clang_version }}/clang+llvm-${{ inputs.clang_version }}-x86_64-$os.tar.xz
mkdir clang
tar -xf clang.tar.xz --strip 1 -C clang
rm clang.tar.xz
Expand Down
6 changes: 6 additions & 0 deletions .github/actions/2-build-bootstrap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ inputs:
cmake_flags:
required: false
default: ''
extra_d_flags: # applying to the D executables, not the runtime
required: false
default: ''
arch:
required: false # Windows only
runs:
Expand All @@ -24,6 +27,9 @@ runs:
cmake_flags: >-
-DBUILD_SHARED_LIBS=OFF
${{ inputs.cmake_flags }}
"-DCMAKE_C_COMPILER=${{ runner.os != 'Windows' && '$PWD/../clang/bin/clang' || 'clang-cl' }}"
"-DCMAKE_CXX_COMPILER=${{ runner.os != 'Windows' && '$PWD/../clang/bin/clang++' || 'clang-cl' }}"
extra_d_flags: ${{ inputs.extra_d_flags }}
arch: ${{ inputs.arch }}

- run: ../bootstrap-ldc/bin/ldc2 --version
Expand Down
13 changes: 10 additions & 3 deletions .github/actions/2a-build-pgo/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Build LDC with PGO instrumentation & gather profile from compiling default libs
inputs:
cmake_flags:
extra_d_flags: # applying to the D executables, not the runtime
required: false
default: ''
lto_mode: # full | thin | none
required: false
default: full
arch:
required: false # Windows only
runs:
Expand All @@ -17,8 +20,12 @@ runs:
# tweak -vp-counters-per-site to avoid `LLVM Profile Warning: Unable to track new values: Running out of static counters.`
cmake_flags: >-
-DBUILD_SHARED_LIBS=OFF
"-DDFLAGS_LDC=-fprofile-generate -vp-counters-per-site=1.5"
${{ inputs.cmake_flags }}
"-DCMAKE_C_COMPILER=${{ runner.os != 'Windows' && '$PWD/../clang/bin/clang' || 'clang-cl' }}"
"-DCMAKE_CXX_COMPILER=${{ runner.os != 'Windows' && '$PWD/../clang/bin/clang++' || 'clang-cl' }}"
"-DEXTRA_DFLAGS_LDC=-fprofile-generate -vp-counters-per-site=1.5"
extra_d_flags: ${{ inputs.extra_d_flags }}
extra_cxx_flags: -fprofile-generate -mllvm -vp-counters-per-site=1.5
lto_mode: ${{ inputs.lto_mode }}
arch: ${{ inputs.arch }}
env:
LLVM_PROFILE_FILE: ${{ github.workspace }}/../pgo-ldc/%p.profraw
Expand Down
12 changes: 10 additions & 2 deletions .github/actions/3-build-cross/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ inputs:
cmake_flags:
required: false
default: ''
extra_d_flags: # applying to the D executables, not the runtime
required: false
default: ''
lto_mode: # full | thin | none
required: false
default: none
with_pgo:
required: false
default: false
Expand Down Expand Up @@ -141,8 +147,10 @@ runs:
specify_install_dir: true
cmake_flags: >-
-DCMAKE_CROSSCOMPILING=True
${{ inputs.os == 'osx' && '-DALTERNATIVE_MALLOC_O="$PWD/../build-mimalloc/CMakeFiles/mimalloc-obj.dir/src/static.c.o"' || '' }}
${{ inputs.cmake_flags }}
${{ inputs.with_pgo == 'true' && '-DDFLAGS_LDC=-fprofile-use=../pgo-ldc/merged.profdata' || '' }}
${{ env.CROSS_CMAKE_FLAGS }}
extra_d_flags: ${{ inputs.extra_d_flags }}
with_mimalloc: ${{ inputs.os == 'osx' }}
lto_mode: ${{ inputs.lto_mode }}
with_pgo: ${{ inputs.with_pgo }}
build_targets: ldc2 ldmd2 ldc-build-runtime ldc-profdata ldc-prune-cache
21 changes: 16 additions & 5 deletions .github/actions/3-build-native/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ inputs:
cmake_flags:
required: false
default: ''
extra_d_flags: # applying to the D executables, not the runtime
required: false
default: ''
lto_mode: # full | thin | none
required: false
default: full
arch:
required: false # Windows only
with_pgo:
required: false
default: false
runs:
using: composite
steps:

- name: 'Posix: Build mimalloc'
if: runner.os != 'Windows'
uses: ./.github/actions/helper-mimalloc
with:
cmake_flags: >-
"-DCMAKE_C_COMPILER=${{ runner.os != 'Windows' && '$PWD/../clang/bin/clang' || 'clang-cl' }}"
"-DCMAKE_CXX_COMPILER=${{ runner.os != 'Windows' && '$PWD/../clang/bin/clang++' || 'clang-cl' }}"

- name: Build LDC & LDC D unittests & defaultlib unittest runners
uses: ./.github/actions/helper-build-ldc
Expand All @@ -23,9 +30,13 @@ runs:
host_dc: ../bootstrap-ldc/bin/ldmd2
specify_install_dir: true
cmake_flags: >-
${{ runner.os != 'Windows' && '-DALTERNATIVE_MALLOC_O="$PWD/../build-mimalloc/CMakeFiles/mimalloc-obj.dir/src/static.c.o"' || '' }}
${{ inputs.cmake_flags }}
${{ inputs.with_pgo == 'true' && '-DDFLAGS_LDC=-fprofile-use=../pgo-ldc/merged.profdata' || '' }}
"-DCMAKE_C_COMPILER=${{ runner.os != 'Windows' && '$PWD/../clang/bin/clang' || 'clang-cl' }}"
"-DCMAKE_CXX_COMPILER=${{ runner.os != 'Windows' && '$PWD/../clang/bin/clang++' || 'clang-cl' }}"
extra_d_flags: ${{ inputs.extra_d_flags }}
with_mimalloc: ${{ runner.os != 'Windows' }}
lto_mode: ${{ inputs.lto_mode }}
with_pgo: true
build_targets: all ldc2-unittest all-test-runners
arch: ${{ inputs.arch }}

Expand Down
56 changes: 52 additions & 4 deletions .github/actions/helper-build-ldc/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ inputs:
cmake_flags:
required: false
default: ''
extra_d_flags: # applying to the D executables, not the runtime
required: false
default: ''
extra_cxx_flags: # for the ldc2 executable
required: false
default: ''
with_mimalloc:
required: false
default: false
lto_mode: # full | thin | none
required: false
default: none
with_pgo:
required: false
default: false
build_targets:
required: false
default: '' # all
Expand All @@ -22,6 +37,39 @@ runs:
using: composite
steps:

- name: Compute advanced CMake flags
id: compute_advanced_cmake_flags
shell: bash
run: |
set -eux
lto_mode='${{ inputs.lto_mode }}'
with_pgo='${{ inputs.with_pgo }}'
flags=''

if [[ '${{ inputs.with_mimalloc }}' == true ]]; then
flags+="-DALTERNATIVE_MALLOC_O=../build-mimalloc/CMakeFiles/mimalloc-obj.dir/src/static.c.o "
fi

d_flags=(${{ inputs.extra_d_flags }})
cxx_flags=(${{ inputs.extra_cxx_flags }})
if [[ "$lto_mode" != none ]]; then
d_flags+=(-O -flto="$lto_mode" -defaultlib=phobos2-ldc-lto,druntime-ldc-lto)
cxx_flags+=(-flto="$lto_mode")
fi
if [[ "$with_pgo" == true ]]; then
flags+="-DEXTRA_DFLAGS_LDC=-fprofile-use=../pgo-ldc/merged.profdata "
cxx_flags+=(-fprofile-use=../pgo-ldc/merged.profdata)
fi

if [[ "${#d_flags[@]}" -gt 0 ]]; then
flags+="\"-DD_COMPILER_FLAGS=${d_flags[*]}\" "
fi
if [[ "${#cxx_flags[@]}" -gt 0 ]]; then
flags+="\"-DEXTRA_CXXFLAGS=${cxx_flags[*]}\" "
fi

echo "::set-output name=CMAKE_FLAGS::$flags"

- if: runner.os != 'Windows'
shell: bash
run: |
Expand All @@ -37,7 +85,8 @@ runs:
-DLDC_LINK_MANUALLY=OFF \
${{ inputs.specify_install_dir == 'true' && '-DCMAKE_INSTALL_PREFIX="$installDir"' || '' }} \
${{ inputs.specify_install_dir == 'true' && '-DINCLUDE_INSTALL_DIR="$installDir/import"' || '' }} \
${{ inputs.cmake_flags }}
${{ inputs.cmake_flags }} \
${{ steps.compute_advanced_cmake_flags.outputs.CMAKE_FLAGS }}

ninja ${{ inputs.build_targets }}

Expand All @@ -55,11 +104,10 @@ runs:
-DCMAKE_BUILD_TYPE=Release ^
"-DLLVM_ROOT_DIR=%CD%\..\${{ inputs.llvm_dir }}" ^
"-DD_COMPILER=${{ inputs.host_dc }}" ^
-DCMAKE_C_COMPILER=clang-cl ^
-DCMAKE_CXX_COMPILER=clang-cl ^
${{ inputs.specify_install_dir == 'true' && '"-DCMAKE_INSTALL_PREFIX=%installDir%"' || '' }} ^
${{ inputs.specify_install_dir == 'true' && '"-DINCLUDE_INSTALL_DIR=%installDir%\import"' || '' }} ^
${{ inputs.cmake_flags }}
${{ inputs.cmake_flags }} ^
${{ steps.compute_advanced_cmake_flags.outputs.CMAKE_FLAGS }}
if %errorlevel% neq 0 exit /b %errorlevel%

ninja ${{ inputs.build_targets }} || exit /b
67 changes: 20 additions & 47 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,25 @@ jobs:
fail-fast: false
matrix:
include:

- job_name: Linux x86_64 multilib
os: ubuntu-18.04
arch: x86_64
bootstrap_cmake_flags: -DBUILD_LTO_LIBS=ON
# To improve portability of the generated binaries, link the C++ standard library statically.
extra_cmake_flags: >-
-DMULTILIB=ON
-DBUILD_LTO_LIBS=ON
-DCMAKE_C_COMPILER=/home/runner/work/ldc/clang/bin/clang
-DCMAKE_CXX_COMPILER=/home/runner/work/ldc/clang/bin/clang++
-DCMAKE_EXE_LINKER_FLAGS=-static-libstdc++
-DJITRT_EXTRA_LDFLAGS=-static-libstdc++
-DD_COMPILER_FLAGS="-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto"
-DEXTRA_CXXFLAGS=-flto=full
with_pgo: true

- job_name: macOS x86_64
os: macos-11
arch: x86_64
bootstrap_cmake_flags: >-
-DBUILD_LTO_LIBS=ON
-DD_COMPILER_FLAGS=-gcc=/usr/bin/c++
extra_cmake_flags: >-
-DBUILD_LTO_LIBS=ON
-DD_COMPILER_FLAGS="-gcc=/usr/bin/c++ -O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto"
-DEXTRA_CXXFLAGS=-flto=full
with_pgo: true

extra_d_flags: -gcc=/usr/bin/c++
- job_name: Windows x64
os: windows-2019
arch: x64
bootstrap_cmake_flags: -DBUILD_LTO_LIBS=ON
extra_cmake_flags: >-
-DBUILD_LTO_LIBS=ON
"-DD_COMPILER_FLAGS=-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto"
-DEXTRA_CXXFLAGS=-flto=full
with_pgo: true

- job_name: Windows x86
os: windows-2019
arch: x86
bootstrap_cmake_flags: -DBUILD_LTO_LIBS=ON
# Undefined symbol errors with FullLTO; ThinLTO works.
extra_cmake_flags: >-
-DBUILD_LTO_LIBS=ON
"-DD_COMPILER_FLAGS=-O -flto=thin -defaultlib=phobos2-ldc-lto,druntime-ldc-lto"
-DEXTRA_CXXFLAGS=-flto=thin
with_pgo: true

lto_mode: thin # undefined symbol errors with full LTO
name: ${{ matrix.job_name }}
runs-on: ${{ matrix.os }}
timeout-minutes: 150
Expand All @@ -88,20 +57,24 @@ jobs:
- name: Build bootstrap LDC
uses: ./.github/actions/2-build-bootstrap
with:
cmake_flags: ${{ matrix.bootstrap_cmake_flags }}
cmake_flags: -DBUILD_LTO_LIBS=ON
extra_d_flags: ${{ matrix.extra_d_flags }}
arch: ${{ matrix.arch }}
- name: Build LDC with PGO instrumentation & gather profile from compiling default libs
if: matrix.with_pgo
uses: ./.github/actions/2a-build-pgo
with:
cmake_flags: ${{ matrix.bootstrap_cmake_flags }}
extra_d_flags: ${{ matrix.extra_d_flags }}
lto_mode: ${{ matrix.lto_mode || 'full' }}
arch: ${{ matrix.arch }}
- name: Build LDC & LDC D unittests & defaultlib unittest runners
uses: ./.github/actions/3-build-native
with:
cmake_flags: ${{ matrix.extra_cmake_flags }}
cmake_flags: >-
-DBUILD_LTO_LIBS=ON
${{ matrix.extra_cmake_flags }}
extra_d_flags: ${{ matrix.extra_d_flags }}
lto_mode: ${{ matrix.lto_mode || 'full' }}
arch: ${{ matrix.arch }}
with_pgo: ${{ matrix.with_pgo }}

- name: Run LDC D unittests
if: success() || failure()
Expand Down Expand Up @@ -156,24 +129,22 @@ jobs:
fail-fast: false
matrix:
include:

- job_name: macOS arm64
host_os: macos-11
os: osx
arch: arm64
bootstrap_cmake_flags: -DD_COMPILER_FLAGS=-gcc=/usr/bin/c++
extra_bootstrap_d_flags: -gcc=/usr/bin/c++
extra_cmake_flags: >-
-DBUILD_LTO_LIBS=ON
-DD_COMPILER_FLAGS="-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto"
-DEXTRA_CXXFLAGS=-flto=full
-DCMAKE_C_COMPILER=/Users/runner/work/ldc/clang/bin/clang
-DCMAKE_CXX_COMPILER=/Users/runner/work/ldc/clang/bin/clang++
lto_mode: full
with_pgo: true

- job_name: Android armv7a
host_os: ubuntu-18.04
os: android
arch: armv7a
android_x86_arch: i686

- job_name: Android aarch64
host_os: ubuntu-18.04
os: android
Expand All @@ -182,7 +153,6 @@ jobs:
extra_cmake_flags: >-
-DLDC_INSTALL_LLVM_RUNTIME_LIBS_OS=linux
-DLDC_INSTALL_LLVM_RUNTIME_LIBS_ARCH=aarch64-android

name: ${{ matrix.job_name }}
runs-on: ${{ matrix.host_os }}
timeout-minutes: 60
Expand All @@ -202,19 +172,22 @@ jobs:
- name: Build bootstrap LDC
uses: ./.github/actions/2-build-bootstrap
with:
cmake_flags: ${{ matrix.bootstrap_cmake_flags }}
cmake_flags: ${{ (matrix.lto_mode || 'none') != 'none' && '-DBUILD_LTO_LIBS=ON' || '' }}
extra_d_flags: ${{ matrix.extra_bootstrap_d_flags }}
- name: Build LDC with PGO instrumentation & gather profile from compiling default libs
if: matrix.with_pgo
uses: ./.github/actions/2a-build-pgo
with:
cmake_flags: ${{ matrix.bootstrap_cmake_flags }}
extra_d_flags: ${{ matrix.extra_bootstrap_d_flags }}
lto_mode: ${{ matrix.lto_mode || 'none' }}
- name: Cross-compile LDC to ${{ matrix.os }}-${{ matrix.arch }}
uses: ./.github/actions/3-build-cross
with:
arch: ${{ matrix.arch }}
os: ${{ matrix.os }}
llvm_version: ${{ env.LLVM_VERSION }}
cmake_flags: ${{ matrix.extra_cmake_flags }}
lto_mode: ${{ matrix.lto_mode || 'none' }}
with_pgo: ${{ matrix.with_pgo }}

- name: Install LDC & make portable
Expand Down
Loading