From 752af60afc7fd9cc986adf280d4d03714228fb04 Mon Sep 17 00:00:00 2001 From: liyunfei Date: Tue, 16 Jan 2024 14:47:02 +0800 Subject: [PATCH 1/3] add BUILD_FOR_OPENEULER build option to clang --- clang/CMakeLists.txt | 5 +++++ clang/include/clang/Driver/CMakeLists.txt | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index f7936d72e088..d558b0522e82 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -317,6 +317,11 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE) endif() endif () +option(BUILD_FOR_OPENEULER "Add gcc compatible options for openEuler toolchain" OFF) +if (BUILD_FOR_OPENEULER) + add_definitions( -DBUILD_FOR_OPENEULER ) +endif() + # Determine HOST_LINK_VERSION on Darwin. set(HOST_LINK_VERSION) if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*") diff --git a/clang/include/clang/Driver/CMakeLists.txt b/clang/include/clang/Driver/CMakeLists.txt index a9d988047920..ea55ba0f1f27 100644 --- a/clang/include/clang/Driver/CMakeLists.txt +++ b/clang/include/clang/Driver/CMakeLists.txt @@ -1,3 +1,7 @@ set(LLVM_TARGET_DEFINITIONS Options.td) +if (BUILD_FOR_OPENEULER) +tablegen(LLVM Options.inc -gen-opt-parser-defs -DBUILD_FOR_OPENEULER) +else() tablegen(LLVM Options.inc -gen-opt-parser-defs) +endif() add_public_tablegen_target(ClangDriverOptions) -- Gitee From 6503d6b87786e005c0557961aadba739d833f80c Mon Sep 17 00:00:00 2001 From: liyunfei Date: Tue, 16 Jan 2024 14:48:53 +0800 Subject: [PATCH 2/3] add gcc compatible in BUILD_FOR_OPENEULER --- clang/include/clang/Driver/Options.td | 14 ++++++++++++++ clang/lib/Driver/Driver.cpp | 8 ++++++++ clang/lib/Driver/ToolChains/Clang.cpp | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 37e8c56b2d29..d4f7315bf8cb 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1786,6 +1786,12 @@ def fmemory_profile_use_EQ : Joined<["-"], "fmemory-profile-use=">, HelpText<"Use memory profile for profile-guided memory optimization">, MarshallingInfoString>; +#ifdef BUILD_FOR_OPENEULER +def fgcc_compatible : Flag<["-"], "fgcc-compatible">, Group, + HelpText<"Enable gcc compatibility for openEuler.">; +def fno_gcc_compatible : Flag<["-"], "fno-gcc-compatible">, Group; +#endif + // Begin sanitizer flags. These should all be core options exposed in all driver // modes. let Flags = [CC1Option, CoreOption] in { @@ -5152,6 +5158,14 @@ def falign_jumps_EQ : Joined<["-"], "falign-jumps=">, Group, Group; +defm peephole2 : BooleanFFlag<"peephole2">, Group; +defm aggressive_loop_optiomizations : BooleanFFlag<"aggressive-loop-optiomizations">, Group; +def flto_partition_EQ : Joined<["-"], "flto-partition=">, Group; +#endif + defm check_new : BoolOption<"f", "check-new", LangOpts<"CheckNew">, DefaultFalse, PosFlag, diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index bdbdad9362e1..87736112fb76 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1491,6 +1491,14 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Populate the tool chains for the offloading devices, if any. CreateOffloadingDeviceToolChains(*C, Inputs); +#ifdef BUILD_FOR_OPENEULER + if(C->getArgs().hasFlag(options::OPT_fgcc_compatible, + options::OPT_fno_gcc_compatible, true)) { + getDiags().setDiagnosticGroupWarningAsError("unused-command-line-argument", 0); + getDiags().setDiagnosticGroupWarningAsError("ignored-optimization-argument", 0); + } +#endif + // Construct the list of abstract actions to perform for this compilation. On // MachO targets this uses the driver-driver and universal actions. if (TC.getTriple().isOSBinFormatMachO()) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 37a07b8f224d..0921e6071d26 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4680,6 +4680,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-triple"); CmdArgs.push_back(Args.MakeArgString(TripleStr)); +#ifdef BUILD_FOR_OPENEULER + if (Args.hasFlag(options::OPT_fgcc_compatible, + options::OPT_fno_gcc_compatible, true)) { + CmdArgs.push_back("-Wno-error=unknown-warning-option"); + CmdArgs.push_back("-Wno-error=unused-parameter"); + CmdArgs.push_back("-Wno-error=unused-function"); + CmdArgs.push_back("-Wno-error=unused-but-set-parameter"); + CmdArgs.push_back("-Wno-error=unused-but-set-variable"); + } +#endif + if (const Arg *MJ = Args.getLastArg(options::OPT_MJ)) { DumpCompilationDatabase(C, MJ->getValue(), TripleStr, Output, Input, Args); Args.ClaimAllArgs(options::OPT_MJ); -- Gitee From 5a77aac2c23bd873394e8a5f7facc7399a03200e Mon Sep 17 00:00:00 2001 From: liyunfei Date: Tue, 16 Jan 2024 16:21:05 +0800 Subject: [PATCH 3/3] add BUILD_FOR_OPENEULER to build.sh --- build.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 7b6b7908abbd..f8402bbe9fb2 100755 --- a/build.sh +++ b/build.sh @@ -7,6 +7,7 @@ CXX_COMPILER_PATH=g++ # Initialize our own variables: buildtype=RelWithDebInfo backends="ARM;AArch64;X86" +build_for_openeuler="0" enabled_projects="clang;lld;compiler-rt;openmp;clang-tools-extra" embedded_toolchain="0" split_dwarf=on @@ -48,6 +49,7 @@ Options: -b type Specify CMake build type (default: $buildtype). -c Use ccache (default: $use_ccache). -e Build for embedded cross tool chain. + -E Build for opeEuler. -h Display this help message. -i Install the build (default: $do_install). -I name Specify install directory name (default: "$install_dir_name"). @@ -63,7 +65,7 @@ EOF # Process command-line options. Remember the options for passing to the # containerized build script. -while getopts :b:cehiI:j:orstvX: optchr; do +while getopts :b:ceEhiI:j:orstvX: optchr; do case "$optchr" in b) buildtype="$OPTARG" @@ -85,6 +87,9 @@ while getopts :b:cehiI:j:orstvX: optchr; do e) embedded_toolchain="1" ;; + E) + build_for_openeuler="1" + ;; h) usage exit @@ -155,6 +160,11 @@ if [ $install_toolchain_only == "1" ]; then CMAKE_OPTIONS="$CMAKE_OPTIONS -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON" fi +if [ $build_for_openeuler == "1"]; then + echo "Build for openEuler" + CMAKE_OPTIONS="$CMAKE_OPTIONS -DBUILD_FOR_OPENEULER=ON" +fi + # Build and install if [ $clean -eq 1 -a -e "$install_prefix" ]; then rm -rf "$install_prefix" -- Gitee