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

Add ldc-profgen tool #4536

Merged
merged 5 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/actions/3-build-cross/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,20 @@ runs:
else
tag=CI
fi

if [[ '${{ inputs.os }}' == android ]]; then
assertsSuffix=""
else
# Use assertions for untagged builds. Must be the same as for the host LLVM package, because
# llvm-config of host package will be used for the cross build configuration.
assertsSuffix="-withAsserts"
if [[ '${{ github.ref }}' = refs/tags/* ]]; then
assertsSuffix=""
fi
fi

curl -fL --retry 3 --max-time 300 -o llvm-cross.tar.xz \
https://github.com/ldc-developers/llvm-project/releases/download/$tag/llvm-$version-${{ inputs.os }}-${{ inputs.arch }}.tar.xz
https://github.com/ldc-developers/llvm-project/releases/download/$tag/llvm-$version-${{ inputs.os }}-${{ inputs.arch }}$assertsSuffix.tar.xz
mkdir llvm-cross
tar -xf llvm-cross.tar.xz --strip 1 -C llvm-cross
rm llvm-cross.tar.xz
Expand Down Expand Up @@ -145,4 +157,4 @@ runs:
${{ inputs.cmake_flags }}
${{ inputs.with_pgo == 'true' && '-DDFLAGS_LDC=-fprofile-use=../pgo-ldc/merged.profdata' || '' }}
${{ env.CROSS_CMAKE_FLAGS }}
build_targets: ldc2 ldmd2 ldc-build-runtime ldc-build-plugin ldc-profdata ldc-prune-cache timetrace2txt
build_targets: ldc2 ldmd2 ldc-build-runtime ldc-build-plugin ldc-profdata ldc-profgen ldc-prune-cache timetrace2txt
2 changes: 1 addition & 1 deletion .github/actions/5-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ runs:
cd ..
else
mkdir -p install/bin
cp build-cross/bin/{ldc2,ldmd2,ldc-build-runtime,ldc-profdata,ldc-prune-cache,timetrace2txt} install/bin/
cp build-cross/bin/{ldc2,ldmd2,ldc-build-runtime,ldc-profdata,ldc-profgen,ldc-prune-cache,timetrace2txt} install/bin/
cp build-cross/bin/ldc-build-plugin install/bin/ || true
cp -R build-cross-libs/lib install/
cp build-cross/lib/{libldc_rt.*,libLTO-ldc.dylib,LLVMgold-ldc.so} install/lib/ || true
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#### Big news
- Frontend, druntime and Phobos are at version [2.106.0](https://dlang.org/changelog/2.106.0.html). (#4522)
- New command-line options `-fno-{exceptions,moduleinfo,rtti}` to selectively enable some `-betterC` effects. (#4522)
- New command-line option `-fprofile-sample-use` for using sample-based profile data for optimization. Functionality and usage is identical to Clang's option with same name. (#4531).
- New command-line option `-fprofile-sample-use` for using sample-based profile data for optimization. Functionality and usage is identical to Clang's option with same name. (#4531)
- New `ldc-profgen` tool for sample-based PGO, a copy of LLVM's [llvm-profgen](https://llvm.org/docs/CommandGuide/llvm-profgen.html). (#4536)

#### Platform support

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ find_package(LLVM 11.0 REQUIRED
instcombine ipo instrumentation irreader libdriver linker lto mc
mcdisassembler mcparser objcarcopts object option profiledata scalaropts
selectiondag support tablegen target transformutils vectorize
windowsdriver windowsmanifest ${EXTRA_LLVM_MODULES})
windowsdriver windowsmanifest symbolize ${EXTRA_LLVM_MODULES})
math(EXPR LDC_LLVM_VER ${LLVM_VERSION_MAJOR}*100+${LLVM_VERSION_MINOR})
message(STATUS "Using LLVM Version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
# Remove LLVMTableGen library from list of libraries
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set( LDC2_BIN ${PROJECT_BINARY_DIR}/bin/${LDC_EXE} )
set( LDCPROFDATA_BIN ${PROJECT_BINARY_DIR}/bin/ldc-profdata )
set( LDCPROFGEN_BIN ${PROJECT_BINARY_DIR}/bin/ldc-profgen )
set( LDCPRUNECACHE_BIN ${PROJECT_BINARY_DIR}/bin/${LDCPRUNECACHE_EXE} )
set( LDCBUILDPLUGIN_BIN ${PROJECT_BINARY_DIR}/bin/${LDC_BUILD_PLUGIN_EXE} )
set( TIMETRACE2TXT_BIN ${PROJECT_BINARY_DIR}/bin/${TIMETRACE2TXT_EXE} )
Expand Down
2 changes: 2 additions & 0 deletions tests/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ OFF = False
## Auto-initialized variables by cmake:
config.ldc2_bin = "@LDC2_BIN@"
config.ldcprofdata_bin = "@LDCPROFDATA_BIN@"
config.ldcprofgen_bin = "@LDCPROFGEN_BIN@"
config.ldcprunecache_bin = "@LDCPRUNECACHE_BIN@"
config.ldcbuildplugin_bin = "@LDCBUILDPLUGIN_BIN@"
config.timetrace2txt_bin = "@TIMETRACE2TXT_BIN@"
Expand Down Expand Up @@ -156,6 +157,7 @@ config.environment['PATH'] = path
config.substitutions.append( ('%ldc', config.ldc2_bin) )
config.substitutions.append( ('%gnu_make', config.gnu_make_bin) )
config.substitutions.append( ('%profdata', config.ldcprofdata_bin) )
config.substitutions.append( ('%profgen', config.ldcprofgen_bin) )
config.substitutions.append( ('%prunecache', config.ldcprunecache_bin) )
config.substitutions.append( ('%buildplugin', config.ldcbuildplugin_bin + " --ldcSrcDir=" + config.ldc2_source_dir ) )
config.substitutions.append( ('%timetrace2txt', config.timetrace2txt_bin) )
Expand Down
26 changes: 26 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ else()
message(WARNING "ldc-profdata source (${LDCPROFDATA_SRC}) not found")
endif()

#############################################################################
# Build ldc-profgen utility that generates a profile data file from given perf script
# data files for sample-based profile guided optimization (-fprofile-sample-use).
# https://llvm.org/docs/CommandGuide/llvm-profgen.html
# The source in ldc-profgen/ldc-profgen-xx.x is an unmodified copy of llvm's llvm-profgen source dir.
if(LDC_LLVM_VER GREATER_EQUAL 1400)
macro(add_llvm_tool llvm_name)
string(REPLACE "llvm-" "ldc-" ldc_name ${llvm_name})
message(STATUS "Configuring ${ldc_name} build target")
add_executable(${ldc_name} ${ARGN})
set_target_properties(
${ldc_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
COMPILE_FLAGS "${LLVM_CXXFLAGS} ${LDC_CXXFLAGS}"
LINK_FLAGS "${SANITIZE_LDFLAGS}"
)
target_link_libraries(${ldc_name} ${LLVM_LIBRARIES} ${CMAKE_DL_LIBS} ${LLVM_LDFLAGS})
install(TARGETS ${ldc_name} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endmacro()
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ldc-profgen/ldc-profgen-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR})
add_subdirectory(ldc-profgen/ldc-profgen-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR})
else()
message(WARNING "ldc-profgen source not found (${CMAKE_CURRENT_SOURCE_DIR}/ldc-profgen/ldc-profgen-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR})")
endif()
endif()

#############################################################################
# Build timetrace2txt
set(TIMETRACE2TXT_EXE timetrace2txt)
Expand Down
2 changes: 2 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ The `/tools` directory contains user tools that accompany LDC and that should be

`ldc-profdata` converts raw profiling data to a profile data format that can be used by LDC. The source is copied from LLVM (`llvm-profdata`), and is versioned for each LLVM version that we support because the version has to match exactly with LDC's LLVM version.

`ldc-profgen` converts perf sample profiling data to a profile data format that can be used by LDC. The source is copied from LLVM (`llvm-profgen`), and is versioned for each LLVM version that we support because the version has to match exactly with LDC's LLVM version.

`timetrace2txt` converts the .timetrace output of `--ftime-trace` (which is in [Chromium's trace event JSON format](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool/)) to a text file that is easier for humans to read.
23 changes: 23 additions & 0 deletions tools/ldc-profgen/ldc-profgen-14.0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

set(LLVM_LINK_COMPONENTS
AllTargetsDescs
AllTargetsDisassemblers
AllTargetsInfos
DebugInfoDWARF
Core
MC
IPO
MCDisassembler
Object
ProfileData
Support
Symbolize
)

add_llvm_tool(llvm-profgen
llvm-profgen.cpp
PerfReader.cpp
CSPreInliner.cpp
ProfiledBinary.cpp
ProfileGenerator.cpp
)
Loading