!14 Add BiSheng Autotuner support

From: @liyunfei33 
Reviewed-by: @cf-zhao 
Signed-off-by: @cf-zhao
This commit is contained in:
openeuler-ci-bot 2024-07-25 02:41:30 +00:00 committed by Gitee
commit 8624c41cf5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 65 additions and 1 deletions

View File

@ -0,0 +1,56 @@
From a9863e2b6e6783aa9be0b9d1d187084fd4b32a3a Mon Sep 17 00:00:00 2001
From: Muhammad Asif Manzoor <muhammad.asif.manzoor1@huawei.com>
Date: Thu, 21 Mar 2024 12:50:38 -0400
Subject: [PATCH] Add BiSheng Autotuner support for LLVM compiler
Automatic tuning is an automatic iterative process that optimizes a given
program by manipulating compilation options for optimal performance.
BiSheng Autotuner provides a resumable interface for tuning process. BiSheng
Autotuner can tune 1) individual code segments/blocks (fine grain turning) like
loops, callsites, instructions, etc. and 2) entire modules/programs (coarse
grain tuning) for compiler flags, pass ordering, etc.
This patch enables LLVM compiler to extract tuneable code regions and then apply
suggested configuration (by Autotuner) to find out the optimal configurations.
---
lld/ELF/Driver.cpp | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index c2059c70e15a..ffd0842b9078 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -341,6 +341,18 @@ void LinkerDriver::addLibrary(StringRef name) {
// Technically this can be delayed until we read bitcode files, but
// we don't bother to do lazily because the initialization is fast.
static void initLLVM() {
+#if defined(ENABLE_AUTOTUNER)
+ // AUTO-TUNING - initialization
+ if (Error E = autotuning::Engine.init(config->outputFile.data())) {
+ error(toString(std::move(E)));
+ return;
+ }
+ if (autotuning::Engine.isEnabled() && autotuning::Engine.isParseInput() &&
+ (autotuning::Engine.LLVMParams.size() ||
+ autotuning::Engine.ProgramParams.size()))
+ llvm::cl::ParseAutoTunerOptions(autotuning::Engine.LLVMParams,
+ autotuning::Engine.ProgramParams);
+#endif
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
@@ -2814,6 +2826,12 @@ void LinkerDriver::link(opt::InputArgList &args) {
reportBackrefs();
writeArchiveStats();
writeWhyExtract();
+#if defined(ENABLE_AUTOTUNER)
+ // AUTO-TUNING - finalization
+ if (Error E = autotuning::Engine.finalize()) {
+ error(toString(std::move(E)));
+ }
+#endif
if (errorCount())
return;
--
2.33.0

View File

@ -1,6 +1,7 @@
%bcond_without sys_llvm
%bcond_without check
%bcond_without toolchain_clang
%bcond_without bisheng_autotuner
%if %{with toolchain_clang}
%global toolchain clang
@ -37,7 +38,7 @@
Name: %{pkg_name}
Version: %{maj_ver}.%{min_ver}.%{patch_ver}
Release: 3
Release: 4
Summary: The LLVM Linker
License: NCSA
@ -49,6 +50,7 @@ Patch2: 0002-Backport-lld-LoongArch-Support-the-R_LARCH_-ADD-SUB-6-relocation-t
Patch3: 0003-Backport-ELF-RISCV-Implement-emit-relocs-with-relaxation.patch
Patch4: 0004-Backport-lld-ELF-Support-relax-R_LARCH_ALIGN.patch
Patch5: 0005-Backport-lld-LoongArch-Support-the-R_LARCH_-ADD-SUB-_ULEB128-relocation-types.patch
Patch6: 0006-Add-BiSheng-Autotuner-support-for-LLVM-compiler.patch
BuildRequires: clang
BuildRequires: cmake
@ -112,6 +114,9 @@ cd _build
%if "%{toolchain}" == "clang"
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
%endif
%if %{with bisheng_autotuner}
-DENABLE_AUTOTUNER=ON \
%endif
-DLLVM_MAIN_SRC_DIR=%{install_prefix}/src
@ -140,6 +145,9 @@ rm %{buildroot}%{install_includedir}/mach-o/compact_unwind_encoding.h
%{install_libdir}/liblld*.so.*
%changelog
* Tue Jul 16 2024 liyunfei <liyunfei33@huawei.com> - 17.0.6-4
- Add BiSheng Autotuner support.
* Fri Jul 5 2024 liyunfei <liyunfei33@huawei.com> - 17.0.6-3
- Add toolchain_clang build support