Projects
openEuler:24.03:SP1:Everything:64G
clang
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
_service:tar_scm:clang.spec
Changed
@@ -1,6 +1,12 @@ %bcond_without sys_llvm %bcond_without check %bcond_with classic_flang +%bcond_with toolchain_clang +%bcond_without bisheng_autotuner + +%if %{with toolchain_clang} +%global toolchain clang +%endif %global maj_ver 17 %global min_ver 0 @@ -37,7 +43,7 @@ Name: %{pkg_name} Version: %{clang_version} -Release: 16 +Release: 24 Summary: A C language family front-end for LLVM License: NCSA @@ -60,6 +66,12 @@ Patch12: 0012-Fix-declaration-definition-mismatch-for-classic-flang.patch Patch13: 0013-Ignored-option-Wa-generate-missing-build-notes.patch Patch14: 0014-Update-llvm-lit-config-to-support-build_for_openeule.patch +Patch15: 0015-Backport-Defer-the-instantiation-of-explicit-specifier-until-.patch +Patch16: 0016-Add-BiSheng-Autotuner-support-for-LLVM-compiler.patch +Patch17: 0017-fix-for-missing-DENABLE_AUTOTUNER.patch +Patch18: 0018-backport-Clang-Fix-build-with-GCC-14-on-ARM-78704.patch +Patch19: 0019-AArch64-Support-HiSilicon-s-HIP09-Processor.patch +Patch20: 0020-Backport-LoongArch-fix-and-add-some-new-support.patch # Patches for clang-tools-extra # See https://reviews.llvm.org/D120301 @@ -107,6 +119,9 @@ BuildRequires: perl(Term::ANSIColor) BuildRequires: perl(Text::ParseWords) BuildRequires: perl(Sys::Hostname) +%if %{with toolchain_clang} +BuildRequires: clang +%endif Requires: %{name}-libs%{?_isa} = %{version}-%{release} @@ -267,7 +282,14 @@ %if %{with classic_flang} -DLLVM_ENABLE_CLASSIC_FLANG=ON \ %endif +%if %{with bisheng_autotuner} + -DLLVM_ENABLE_AUTOTUNER=ON \ +%endif -DBUILD_FOR_OPENEULER=ON \ +%if "%{toolchain}" == "clang" + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ +%endif -DCLANG_DEFAULT_UNWINDLIB=libgcc %ninja_build @@ -394,6 +416,31 @@ %{install_bindir}/git-clang-format %changelog +* Mon Sep 23 2024 zhanglimin <zhanglimin@loongson.cn> - 17.0.6-24 +- LoongArch Backport some new support + +* Tue Sep 10 2024 xiajingze <xiajingze1@huawei.com> - 17.0.6-23 +- AArch64 Support HiSilicon's HIP09 Processor + +* Tue Sep 03 2024 eastb233 <xiezhiheng@huawei.com> - 17.0.6-22 +- Fix build with GCC that supports SME. + +* Tue Aug 20 2024 liyunfei <liyunfei33@huawei.com> - 17.0.6-21 +- Fix for missing -DENABLE_AUTOTUNER in compilation. + +* Tue Jul 30 2024 liyunfei <liyunfei33@huawei.com> - 17.0.6-20 +- Disable toolchain_clang build for BiSheng Autotuner support temporary. + +* Tue Jul 16 2024 liyunfei <liyunfei33@huawei.com> - 17.0.6-19 +- Add BiSheng Autotuner support. + +* Fri Jul 5 2024 liyunfei <liyunfei33@huawei.com> - 17.0.6-18 +- Add toolchain_clang build support + +* Tue Jun 04 2024 Zhao Mengmeng <zhaomengmeng@kylinos.cn> - 17.0.6-17 +- Fix the too-early instantiation of conditional "explict" by applying the patch + of https://github.com/llvm/llvm-project/commit/128b3b61fe6768c724975fd1df2be0abec848cf6 + * Mon Apr 29 2024 wangqiang <wangqiang1@kylinos.cn> - 17.0.6-16 - Ignored the `-Wa,--generate-missing-build-notes=` option, update llvm-lit config to support macro `build_for_openeuler`
View file
_service:tar_scm:0015-Backport-Defer-the-instantiation-of-explicit-specifier-until-.patch
Added
@@ -0,0 +1,259 @@ +From c2668403868559918b54671d3d31527fb2f04486 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=E5=88=98=E9=9B=A8=E5=9F=B9?= <liuyupei951018@hotmail.com> +Date: Wed, 1 Nov 2023 21:45:48 +0800 +Subject: PATCH Defer the instantiation of explicit-specifier until + constraint checking completes (#70548) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Modifications: + +- Skip the instantiation of the explicit-specifier during Decl +substitution if we are deducing template arguments and the +explicit-specifier is value dependent. + +- Instantiate the explicit-specifier after the constraint checking +completes. + +- Make `instantiateExplicitSpecifier` a member function in order to +instantiate the explicit-specifier in different stages. + +This PR doesn’t defer the instantiation of the explicit specifier for +deduction guides, because I’m not familiar with deduction guides yet. +I’ll dig into it after this PR. + +According to my local test, GCC 13 tuple works with this PR. + +Fixes #59827. + +--------- + +Co-authored-by: Erich Keane <ekeane@nvidia.com> +--- + docs/ReleaseNotes.rst | 4 ++ + include/clang/Sema/Sema.h | 3 ++ + lib/Sema/SemaTemplateDeduction.cpp | 53 +++++++++++++++++++ + lib/Sema/SemaTemplateInstantiateDecl.cpp | 40 +++++++++----- + test/SemaCXX/cxx2a-explicit-bool-deferred.cpp | 31 +++++++++++ + 5 files changed, 117 insertions(+), 14 deletions(-) + create mode 100644 test/SemaCXX/cxx2a-explicit-bool-deferred.cpp + +diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst +index 5086a56e..05dad41c 100644 +--- a/clang/docs/ReleaseNotes.rst ++++ b/clang/docs/ReleaseNotes.rst +@@ -860,6 +860,10 @@ Bug Fixes to C++ Support + (`#64172 <https://github.com/llvm/llvm-project/issues/64172>`_) and + (`#64723 <https://github.com/llvm/llvm-project/issues/64723>`_). + ++- Clang now defers the instantiation of explicit specifier until constraint checking ++ completes (except deduction guides). Fixes: ++ (`#59827 <https://github.com/llvm/llvm-project/issues/59827>`_) ++ + Bug Fixes to AST Handling + ^^^^^^^^^^^^^^^^^^^^^^^^^ + +diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h +index 3752a23f..b2ab6d0f 100644 +--- a/clang/include/clang/Sema/Sema.h ++++ b/clang/include/clang/Sema/Sema.h +@@ -10293,6 +10293,9 @@ public: + const CXXConstructorDecl *Tmpl, + const MultiLevelTemplateArgumentList &TemplateArgs); + ++ ExplicitSpecifier instantiateExplicitSpecifier( ++ const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier ES); ++ + NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, + const MultiLevelTemplateArgumentList &TemplateArgs, + bool FindingInstantiatedContext = false); +diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp +index 31ea7be2..58dd1b78 100644 +--- a/clang/lib/Sema/SemaTemplateDeduction.cpp ++++ b/clang/lib/Sema/SemaTemplateDeduction.cpp +@@ -3546,6 +3546,48 @@ static unsigned getPackIndexForParam(Sema &S, + llvm_unreachable("parameter index would not be produced from template"); + } + ++// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`, ++// we'll try to instantiate and update its explicit specifier after constraint ++// checking. ++static Sema::TemplateDeductionResult instantiateExplicitSpecifierDeferred( ++ Sema &S, FunctionDecl *Specialization, ++ const MultiLevelTemplateArgumentList &SubstArgs, ++ TemplateDeductionInfo &Info, FunctionTemplateDecl *FunctionTemplate, ++ ArrayRef<TemplateArgument> DeducedArgs) { ++ auto GetExplicitSpecifier = (FunctionDecl *D) { ++ return isa<CXXConstructorDecl>(D) ++ ? cast<CXXConstructorDecl>(D)->getExplicitSpecifier() ++ : cast<CXXConversionDecl>(D)->getExplicitSpecifier(); ++ }; ++ auto SetExplicitSpecifier = (FunctionDecl *D, ExplicitSpecifier ES) { ++ isa<CXXConstructorDecl>(D) ++ ? cast<CXXConstructorDecl>(D)->setExplicitSpecifier(ES) ++ : cast<CXXConversionDecl>(D)->setExplicitSpecifier(ES); ++ }; ++ ++ ExplicitSpecifier ES = GetExplicitSpecifier(Specialization); ++ Expr *ExplicitExpr = ES.getExpr(); ++ if (!ExplicitExpr) ++ return Sema::TDK_Success; ++ if (!ExplicitExpr->isValueDependent()) ++ return Sema::TDK_Success; ++ ++ Sema::InstantiatingTemplate Inst( ++ S, Info.getLocation(), FunctionTemplate, DeducedArgs, ++ Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info); ++ if (Inst.isInvalid()) ++ return Sema::TDK_InstantiationDepth; ++ Sema::SFINAETrap Trap(S); ++ const ExplicitSpecifier InstantiatedES = ++ S.instantiateExplicitSpecifier(SubstArgs, ES); ++ if (InstantiatedES.isInvalid() || Trap.hasErrorOccurred()) { ++ Specialization->setInvalidDecl(true); ++ return Sema::TDK_SubstitutionFailure; ++ } ++ SetExplicitSpecifier(Specialization, InstantiatedES); ++ return Sema::TDK_Success; ++} ++ + /// Finish template argument deduction for a function template, + /// checking the deduced template arguments for completeness and forming + /// the function template specialization. +@@ -3675,6 +3717,17 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( + } + } + ++ // We skipped the instantiation of the explicit-specifier during the ++ // substitution of `FD` before. So, we try to instantiate it back if ++ // `Specialization` is either a constructor or a conversion function. ++ if (isa<CXXConstructorDecl, CXXConversionDecl>(Specialization)) { ++ if (TDK_Success != instantiateExplicitSpecifierDeferred( ++ *this, Specialization, SubstArgs, Info, ++ FunctionTemplate, DeducedArgs)) { ++ return TDK_SubstitutionFailure; ++ } ++ } ++ + if (OriginalCallArgs) { + // C++ temp.deduct.callp4: + // In general, the deduction process attempts to find template argument +diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +index f78d46f5..a40510ce 100644 +--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp ++++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +@@ -555,18 +555,16 @@ static void instantiateDependentAMDGPUFlatWorkGroupSizeAttr( + S.addAMDGPUFlatWorkGroupSizeAttr(New, Attr, MinExpr, MaxExpr); + } + +-static ExplicitSpecifier +-instantiateExplicitSpecifier(Sema &S, +- const MultiLevelTemplateArgumentList &TemplateArgs, +- ExplicitSpecifier ES, FunctionDecl *New) { ++ExplicitSpecifier Sema::instantiateExplicitSpecifier( ++ const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier ES) { + if (!ES.getExpr()) + return ES; + Expr *OldCond = ES.getExpr(); + Expr *Cond = nullptr; + { + EnterExpressionEvaluationContext Unevaluated( +- S, Sema::ExpressionEvaluationContext::ConstantEvaluated); +- ExprResult SubstResult = S.SubstExpr(OldCond, TemplateArgs); ++ *this, Sema::ExpressionEvaluationContext::ConstantEvaluated); ++ ExprResult SubstResult = SubstExpr(OldCond, TemplateArgs); + if (SubstResult.isInvalid()) { + return ExplicitSpecifier::Invalid(); + } +@@ -574,7 +572,7 @@ instantiateExplicitSpecifier(Sema &S, + } + ExplicitSpecifier Result(Cond, ES.getKind()); + if (!Cond->isTypeDependent()) +- S.tryResolveExplicitSpecifier(Result); ++ tryResolveExplicitSpecifier(Result); + return Result; + } + +@@ -2065,8 +2063,8 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( + + ExplicitSpecifier InstantiatedExplicitSpecifier; + if (auto *DGuide = dyn_cast<CXXDeductionGuideDecl>(D)) { +- InstantiatedExplicitSpecifier = instantiateExplicitSpecifier( +- SemaRef, TemplateArgs, DGuide->getExplicitSpecifier(), DGuide); ++ InstantiatedExplicitSpecifier = SemaRef.instantiateExplicitSpecifier( ++ TemplateArgs, DGuide->getExplicitSpecifier()); + if (InstantiatedExplicitSpecifier.isInvalid()) + return nullptr; + } +@@ -2440,11 +2438,25 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( + } + } + +- ExplicitSpecifier InstantiatedExplicitSpecifier = +- instantiateExplicitSpecifier(SemaRef, TemplateArgs, +- ExplicitSpecifier::getFromDecl(D), D); +- if (InstantiatedExplicitSpecifier.isInvalid()) +- return nullptr; ++ auto InstantiatedExplicitSpecifier = ExplicitSpecifier::getFromDecl(D); ++ // deduction guides need this ++ const bool CouldInstantiate = ++ InstantiatedExplicitSpecifier.getExpr() == nullptr || ++ !InstantiatedExplicitSpecifier.getExpr()->isValueDependent(); ++ ++ // Delay the instantiation of the explicit-specifier until after the ++ // constraints are checked during template argument deduction. ++ if (CouldInstantiate || ++ SemaRef.CodeSynthesisContexts.back().Kind != ++ Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution) { ++ InstantiatedExplicitSpecifier = SemaRef.instantiateExplicitSpecifier( ++ TemplateArgs, InstantiatedExplicitSpecifier); ++ ++ if (InstantiatedExplicitSpecifier.isInvalid()) ++ return nullptr; ++ } else { ++ InstantiatedExplicitSpecifier.setKind(ExplicitSpecKind::Unresolved); ++ } + + // Implicit destructors/constructors created for local classes in + // DeclareImplicit* (see SemaDeclCXX.cpp) might not have an associated TSI. +diff --git a/clang/test/SemaCXX/cxx2a-explicit-bool-deferred.cpp b/clang/test/SemaCXX/cxx2a-explicit-bool-deferred.cpp +new file mode 100644 +index 00000000..4d667008 +--- /dev/null ++++ b/clang/test/SemaCXX/cxx2a-explicit-bool-deferred.cpp +@@ -0,0 +1,31 @@ ++// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s ++ ++template <typename T1, typename T2> struct is_same { ++ static constexpr bool value = false; ++}; ++ ++template <typename T> struct is_same<T, T> { ++ static constexpr bool value = true; ++}; ++ ++template <class T, class U> ++concept SameHelper = is_same<T, U>::value; ++template <class T, class U> ++concept same_as = SameHelper<T, U> && SameHelper<U, T>; ++ ++namespace deferred_instantiation { ++template <class X> constexpr X do_not_instantiate() { return nullptr; } ++ ++struct T { ++ template <same_as<float> X> explicit(do_not_instantiate<X>()) T(X) {} ++ ++ T(int) {} ++}; ++ ++T t(5); ++// expected-error@17{{cannot initialize}} ++// expected-note@20{{in instantiation of function template specialization}} ++// expected-note@30{{while substituting deduced template arguments}} ++// expected-note@30{{in instantiation of function template specialization}} ++T t2(5.0f); ++} // namespace deferred_instantiation +-- +2.33.0 +
View file
_service:tar_scm:0016-Add-BiSheng-Autotuner-support-for-LLVM-compiler.patch
Added
@@ -0,0 +1,739 @@ +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: 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. +--- + clang/include/clang/Basic/CMakeLists.txt | 15 ++ + .../clang/Basic/DiagnosticDriverKinds.td | 9 ++ + .../clang/Basic/DiagnosticFrontendKinds.td | 8 + + clang/include/clang/Driver/CMakeLists.txt | 6 +- + clang/include/clang/Driver/Driver.h | 36 +++++ + clang/include/clang/Driver/Options.td | 13 ++ + clang/lib/CodeGen/BackendUtil.cpp | 58 +++++++ + clang/lib/Driver/Driver.cpp | 82 ++++++++++ + clang/lib/Driver/ToolChains/Clang.cpp | 21 +++ + clang/lib/Driver/ToolChains/CommonArgs.cpp | 113 ++++++++++++++ + clang/lib/Driver/ToolChains/CommonArgs.h | 8 + + clang/lib/Driver/ToolChains/Gnu.cpp | 34 ++++ + .../ExecuteCompilerInvocation.cpp | 27 ++++ + .../autotune_datadir/baseline-config.yaml | 9 ++ + .../autotune_datadir/random-config.yaml | 9 ++ + .../BaselineConfig/apply-baseline-config.c | 32 ++++ + .../test/Autotuning/Driver/Inputs/config.yaml | 3 + + .../Autotuning/Driver/Inputs/template.yaml | 9 ++ + .../Driver/autotune-generate-pipeline.c | 146 ++++++++++++++++++ + .../Driver/autotune-pipeline-thin-lto.c | 42 +++++ + .../Autotuning/Driver/autotune-pipeline.c | 131 ++++++++++++++++ + .../test/Autotuning/GenerateOpp/generate.cpp | 25 +++ + .../Inputs/template.yaml | 9 ++ + .../IncrementalCompilation/Inputs/test1.c | 3 + + .../IncrementalCompilation/Inputs/test2.c | 17 ++ + .../IncrementalCompilation/Inputs/test3.c | 6 + + .../inc-compile-generate-input.cpp | 44 ++++++ + .../Inputs/datadir/corse_grain_config.yaml | 1 + + .../LTO/Inputs/datadir/fine_grain_a.out.yaml | 4 + + .../LTO/Inputs/datadir/fine_grain_output.yaml | 1 + + .../LTO/apply_config_coarse_grain.cpp | 41 +++++ + .../LTO/apply_config_fine_grain.cpp | 58 +++++++ + .../Autotuning/LTO/generate_opportunity.cpp | 56 +++++++ + .../PhaseOrdering/Inputs/template.yaml | 8 + + .../Autotuning/PhaseOrdering/pass-order.cpp | 48 ++++++ + 42 files changed, 1170 insertions(+), 1 deletion(-) + +diff --git a/clang/include/clang/Basic/CMakeLists.txt b/clang/include/clang/Basic/CMakeLists.txt +index f010e04f62cd..e449d2790597 100644 +--- a/clang/include/clang/Basic/CMakeLists.txt ++++ b/clang/include/clang/Basic/CMakeLists.txt +@@ -1,6 +1,12 @@ ++set(CLANG_BASIC_OPTIONS) ++if(LLVM_ENABLE_AUTOTUNER) ++ list(APPEND CLANG_BASIC_OPTIONS "-DENABLE_AUTOTUNER") ++endif() ++ + macro(clang_diag_gen component) + clang_tablegen(Diagnostic${component}Kinds.inc + -gen-clang-diags-defs -clang-component=${component} ++ ${CLANG_BASIC_OPTIONS} + SOURCE Diagnostic.td + TARGET ClangDiagnostic${component}) + endmacro(clang_diag_gen) +@@ -18,20 +24,24 @@ clang_diag_gen(Refactoring) + clang_diag_gen(Sema) + clang_diag_gen(Serialization) + clang_tablegen(DiagnosticGroups.inc -gen-clang-diag-groups ++ ${CLANG_BASIC_OPTIONS} + SOURCE Diagnostic.td + TARGET ClangDiagnosticGroups) + + clang_tablegen(DiagnosticIndexName.inc -gen-clang-diags-index-name ++ ${CLANG_BASIC_OPTIONS} + SOURCE Diagnostic.td + TARGET ClangDiagnosticIndexName) + + clang_tablegen(AttrList.inc -gen-clang-attr-list + -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ ++ ${CLANG_BASIC_OPTIONS} + SOURCE Attr.td + TARGET ClangAttrList) + + clang_tablegen(AttrSubMatchRulesList.inc -gen-clang-attr-subject-match-rule-list + -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ ++ ${CLANG_BASIC_OPTIONS} + SOURCE Attr.td + TARGET ClangAttrSubjectMatchRuleList) + +@@ -43,6 +53,7 @@ clang_tablegen(AttrTokenKinds.inc -gen-clang-attr-token-kinds + + clang_tablegen(AttrHasAttributeImpl.inc -gen-clang-attr-has-attribute-impl + -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ ++ ${CLANG_BASIC_OPTIONS} + SOURCE Attr.td + TARGET ClangAttrHasAttributeImpl + ) +@@ -67,15 +78,19 @@ clang_tablegen(arm_mve_builtin_aliases.inc -gen-arm-mve-builtin-aliases + SOURCE arm_mve.td + TARGET ClangARMMveBuiltinAliases) + clang_tablegen(arm_sve_builtins.inc -gen-arm-sve-builtins ++ ${CLANG_BASIC_OPTIONS} + SOURCE arm_sve.td + TARGET ClangARMSveBuiltins) + clang_tablegen(arm_sve_builtin_cg.inc -gen-arm-sve-builtin-codegen ++ ${CLANG_BASIC_OPTIONS} + SOURCE arm_sve.td + TARGET ClangARMSveBuiltinCG) + clang_tablegen(arm_sve_typeflags.inc -gen-arm-sve-typeflags ++ ${CLANG_BASIC_OPTIONS} + SOURCE arm_sve.td + TARGET ClangARMSveTypeFlags) + clang_tablegen(arm_sve_sema_rangechecks.inc -gen-arm-sve-sema-rangechecks ++ ${CLANG_BASIC_OPTIONS} + SOURCE arm_sve.td + TARGET ClangARMSveSemaRangeChecks) + clang_tablegen(arm_sme_builtins.inc -gen-arm-sme-builtins +diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td +index 37586242953f..6b68bc458b93 100644 +--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td ++++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td +@@ -248,6 +248,15 @@ def err_drv_cannot_read_config_file : Error< + "cannot read configuration file '%0': %1">; + def err_drv_arg_requires_bitcode_input: Error< + "option '%0' requires input to be LLVM bitcode">; ++#ifdef ENABLE_AUTOTUNER ++def err_drv_autotune_generic : Error<"%0">; ++def err_drv_autotune_disabled_O0 : Error< ++ "-fautotune/-fautotune-generate should not be enabled at -O0">; ++def err_drv_autotune_incorrect_env : Error< ++ "incorrect argument '%0' in environment variable used">; ++def err_drv_autotune_no_filter_types : Error< ++ "no types added for filtering with %0">; ++#endif + + def err_target_unsupported_arch + : Error<"the target architecture '%0' is not supported by the target '%1'">; +diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td +index 9ed9a88fa3d6..11022962ae9e 100644 +--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td ++++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td +@@ -346,4 +346,12 @@ def warn_profile_data_misexpect : Warning< + def err_extract_api_ignores_file_not_found : + Error<"file '%0' specified by '--extract-api-ignores=' not found">, DefaultFatal; + ++#ifdef ENABLE_AUTOTUNER ++let CategoryName = "AutoTuning Issues" in { ++def err_auto_tuning_error_reading : Error<"'%0'">; ++def err_auto_tuning_error_dumping : Error<"'%0'">; ++def err_unable_to_create_pass : Error< ++ "cannot create pass '%0' from AutoTuning input file">; ++} // end of autoTuning issue category ++#endif + } +diff --git a/clang/include/clang/Driver/CMakeLists.txt b/clang/include/clang/Driver/CMakeLists.txt +index 8c0af1528a96..56fff6a2504e 100644 +--- a/clang/include/clang/Driver/CMakeLists.txt ++++ b/clang/include/clang/Driver/CMakeLists.txt +@@ -8,7 +8,11 @@ endif() + if (LLVM_ENABLE_CLASSIC_FLANG) + list(APPEND CLANG_DRIVER_OPTIONS -DENABLE_CLASSIC_FLANG ) + endif() +- ++ ++if (LLVM_ENABLE_AUTOTUNER) ++ list(APPEND CLANG_DRIVER_OPTIONS "-DENABLE_AUTOTUNER" ) ++endif() ++ + tablegen(LLVM Options.inc ${CLANG_DRIVER_OPTIONS} -gen-opt-parser-defs ) + + add_public_tablegen_target(ClangDriverOptions) +diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h +index e3e98bad9912..dcecb473b516 100644 +--- a/clang/include/clang/Driver/Driver.h ++++ b/clang/include/clang/Driver/Driver.h +@@ -72,6 +72,14 @@ enum ModuleHeaderMode { + HeaderMode_System + }; + ++#if defined(ENABLE_AUTOTUNER) ++enum AutoTuneKind { ++ AutoTuneNone, ++ AutoTuneGenerate, ++ AutoTuneNext, ++}; ++#endif ++ + /// Driver - Encapsulate logic for constructing compilation processes + /// from a set of gcc-driver-like command line arguments. + class Driver { +@@ -119,6 +127,11 @@ class Driver { + /// LTO mode selected via -f(no-offload-)?lto(=.*)? options. + LTOKind OffloadLTOMode; + ++#if defined(ENABLE_AUTOTUNER) ++ /// AutoTune mode selected via -fautotune or -fautotune-generate option ++ AutoTuneKind AutoTuneMode; ++#endif ++ + public: + enum OpenMPRuntimeKind { + /// An unknown OpenMP runtime. We can't generate effective OpenMP code +@@ -191,6 +204,21 @@ public: + /// Information about the host which can be overridden by the user. + std::string HostBits, HostMachine, HostSystem, HostRelease; + ++#if defined(ENABLE_AUTOTUNER) ++ /// The path to the llvm-autotune data directory. ++ std::string AutoTuneDirDataPath; ++ /// Path for project base directory. Base directory is removed from absolute ++ /// path and relative path is used as (coarse-grain) code region name. This ++ /// allow to port a config file from one machine/location to another. ++ std::string AutoTuneProjectDir; ++ ++ /// Whether to prepare the compiler to produce additional metadata ++ /// that will be consumed by Autotuner's ML model ++ bool IsMLTuningEnabled; ++ ++ std::string AutoTuneOptions; ++#endif ++ + /// The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled. + std::string CCPrintStatReportFilename; + +@@ -705,6 +733,14 @@ public: + return IsOffload ? OffloadLTOMode : LTOMode; + } + ++#if defined(ENABLE_AUTOTUNER) ++ /// Returns true if we are performing any kind of AutoTune. ++ bool isUsingAutoTune() const { return AutoTuneMode != AutoTuneNone; } ++ ++ /// Get the specific kind of AutoTune being performed. ++ AutoTuneKind getAutoTuneMode() const { return AutoTuneMode; } ++#endif ++ + private: + + /// Tries to load options from configuration files. +diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td +index c5cc66c58f25..71d6ed66ab96 100644 +--- a/clang/include/clang/Driver/Options.td ++++ b/clang/include/clang/Driver/Options.td +@@ -1795,6 +1795,19 @@ def fmemory_profile_use_EQ : Joined<"-", "fmemory-profile-use=">, + Group<f_Group>, Flags<CC1Option, CoreOption>, MetaVarName<"<pathname>">, + HelpText<"Use memory profile for profile-guided memory optimization">, + MarshallingInfoString<CodeGenOpts<"MemoryProfileUsePath">>; ++#ifdef ENABLE_AUTOTUNER ++// Auto-tuning flags. ++def fautotune : Flag<"-", "fautotune">, Group<f_Group>, ++ HelpText<"Auto-tune with the compiler configuration under 'autotune_datadir' (overridden by AUTOTUNE_DATADIR env var)">; ++def fautotune_EQ : Joined<"-", "fautotune=">, Group<f_Group>, ++ HelpText<"Auto-tune with the compiler configuration of the specified id under 'autotune_datadir' (overridden by AUTOTUNE_DATADIR env var)">; ++def fautotune_generate : Flag<"-", "fautotune-generate">, Group<f_Group>, ++ HelpText<"Generate initial compiler configuration for Function/Loop code regions under 'autotune_datadir' (overridden by AUTOTUNE_DATADIR env var)">; ++def fautotune_generate_EQ : CommaJoined<"-", "fautotune-generate=">, Group<f_Group>, ++ HelpText<"Generate initial compiler configuration for the given comma-separated list of code regions under 'autotune_datadir' (overridden by AUTOTUNE_DATADIR env var)">, Values<"Other,Function,Loop,MachineBasicBlock">; ++def fautotune_rank : Flag<"-", "fautotune-rank">, Group<f_Group>, ++ HelpText<"Generate files necessary for ML-guided ranking">; ++#endif + + #ifdef BUILD_FOR_OPENEULER + def fgcc_compatible : Flag<"-", "fgcc-compatible">, Group<f_Group>, +diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp +index f962d60870d1..cef5e0d16ba7 100644 +--- a/clang/lib/CodeGen/BackendUtil.cpp ++++ b/clang/lib/CodeGen/BackendUtil.cpp +@@ -88,6 +88,10 @@ using namespace llvm; + llvm::PassPluginLibraryInfo get##Ext##PluginInfo(); + #include "llvm/Support/Extension.def" + ++#if defined(ENABLE_AUTOTUNER) ++#include "llvm/Analysis/AutotuningDump.h" ++#endif ++ + namespace llvm { + extern cl::opt<bool> DebugInfoCorrelate; + +@@ -1021,6 +1025,27 @@ void EmitAssemblyHelper::RunOptimizationPipeline( + }); + } + ++#if defined(ENABLE_AUTOTUNER) ++ bool Changed = false; ++ // If autotuning is enabled (for applying configuration), use AutoTuner ++ // generated pass ordering instead of passes in compilation pipeline. Passes ++ // before and after the compilation pipeline will be intact. ++ if (autotuning::Engine.isEnabled()) { ++ std::vector<std::string> PassesList; ++ Changed = autotuning::Engine.lookUpGlobalParams("OptPass", PassesList); ++ if (Changed && PassesList.size()) { ++ std::string PassPipeline = ""; ++ for (auto PassName : PassesList) ++ PassPipeline.append(PassName + ","); ++ PassPipeline.pop_back(); ++ ++ if (auto Err = PB.parsePassPipeline(MPM, PassPipeline)) ++ errs() << "AutoTuner: cannot add pass:" << toString(std::move(Err)) ++ << "\n"; ++ } ++ } ++ if (!Changed) { ++#endif + if (IsThinLTO || (IsLTO && CodeGenOpts.UnifiedLTO)) { + MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level); + } else if (IsLTO) { +@@ -1028,6 +1053,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline( + } else { + MPM = PB.buildPerModuleDefaultPipeline(Level); + } ++#if defined(ENABLE_AUTOTUNER) ++ } ++#endif + } + + // Add a verifier pass if requested. We don't have to do this if the action +@@ -1078,6 +1106,12 @@ void EmitAssemblyHelper::RunOptimizationPipeline( + } + } + ++#if defined(ENABLE_AUTOTUNER) ++ // Please ensure this pass is added after all optimization passes. ++ if (autotuning::Engine.isEnabled()) ++ MPM.addPass(RequireAnalysisPass<AutotuningDumpAnalysis, llvm::Module>()); ++#endif ++ + // Now that we have all of the passes ready, run them. + { + PrettyStackTraceString CrashInfo("Optimizer"); +@@ -1125,6 +1159,22 @@ void EmitAssemblyHelper::RunCodegenPipeline( + void EmitAssemblyHelper::EmitAssembly(BackendAction Action, + std::unique_ptr<raw_pwrite_stream> OS) { + TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime : nullptr); ++ ++#if defined(ENABLE_AUTOTUNER) ++ // AUTO-TUNING - auto-tuning initialization for this module. ++ // Initialize it before parsing command-line options because we want to ++ // overwrite the llvm options using the config file. ++ if (Error E = autotuning::Engine.init(TheModule->getModuleIdentifier())) { ++ Diags.Report(diag::err_auto_tuning_error_reading) << 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 ++ + setCommandLineOpts(CodeGenOpts); + + bool RequiresCodeGen = actionRequiresCodeGen(Action); +@@ -1142,6 +1192,14 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, + RunOptimizationPipeline(Action, OS, ThinLinkOS); + RunCodegenPipeline(Action, OS, DwoOS); + ++#if defined(ENABLE_AUTOTUNER) ++ // AUTO-TUNING - auto-tuning finalization for this module ++ if (Error E = autotuning::Engine.finalize()) { ++ Diags.Report(diag::err_auto_tuning_error_dumping) << toString(std::move(E)); ++ return; ++ } ++#endif ++ + if (ThinLinkOS) + ThinLinkOS->keep(); + if (DwoOS) +diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp +index 819d7703b2e7..bd9db7714f95 100644 +--- a/clang/lib/Driver/Driver.cpp ++++ b/clang/lib/Driver/Driver.cpp +@@ -104,6 +104,14 @@ + #if LLVM_ON_UNIX + #include <unistd.h> // getpid + #endif ++#if defined(ENABLE_AUTOTUNER) ++// Constant definition for environment variable to enable AutoTuner and set ++// the mode to generate opportunities or apply configurations. ++const std::string AutoTuneModeStr = "AUTOTUNE_MODE"; ++// Constant definition for environment variable to specify the project base ++// directory. ++const std::string AutoTunePrjDirStr = "AUTOTUNE_PROJECT_DIR"; ++#endif + + using namespace clang::driver; + using namespace clang; +@@ -200,6 +208,9 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple, + SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), + Offload(OffloadHostDevice), CXX20HeaderType(HeaderMode_None), + ModulesModeCXX20(false), LTOMode(LTOK_None), ++#if defined(ENABLE_AUTOTUNER) ++ AutoTuneMode(AutoTuneNone), ++#endif + ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT), + DriverTitle(Title), CCCPrintBindings(false), CCPrintOptions(false), + CCLogDiagnostics(false), CCGenDiagnostics(false), +@@ -1379,6 +1390,77 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) { + + setLTOMode(Args); + ++#if defined(ENABLE_AUTOTUNER) ++ // Process -fautotune and -fautotune-generate flags. ++ bool IsAutoTuneGenerate = Args.hasArg(options::OPT_fautotune_generate, ++ options::OPT_fautotune_generate_EQ); ++ bool IsAutoTune = ++ Args.hasArg(options::OPT_fautotune, options::OPT_fautotune_EQ); ++ // Check if the environment variable AUTOTUNE_MODE is used instead of ++ // -fautotune-generate/-fautotune. ++ if (!IsAutoTuneGenerate && !IsAutoTune) { ++ if (std::optional<std::string> MaybeMode = ++ llvm::sys::Process::GetEnv(AutoTuneModeStr)) { ++ StringRef Mode = *MaybeMode; ++ StringRef OrgMode = *MaybeMode; ++ if (Mode.consume_front("-fautotune-generate")) { ++ if (Mode.empty() || Mode.startswith("=")) ++ IsAutoTuneGenerate = true; ++ else ++ Diags.Report(diag::err_drv_autotune_incorrect_env) << OrgMode; ++ } else if (Mode.consume_front("-fautotune")) { ++ if (Mode.empty() || Mode.startswith("=")) ++ IsAutoTune = true; ++ else ++ Diags.Report(diag::err_drv_autotune_incorrect_env) << OrgMode; ++ } else { ++ Diags.Report(diag::err_drv_autotune_incorrect_env) << OrgMode; ++ } ++ ++ if (Mode.consume_front("=")) { ++ if (Mode.empty()) ++ Diags.Report(diag::err_drv_autotune_no_filter_types) ++ << (IsAutoTuneGenerate ? "-fautotune-generate=" : "-fautotune="); ++ ++ AutoTuneOptions = Mode.str(); ++ } ++ } ++ } ++ ++ IsMLTuningEnabled = Args.hasArg(options::OPT_fautotune_rank); ++ ++ if (IsAutoTuneGenerate && IsAutoTune) ++ Diags.Report(diag::err_drv_argument_not_allowed_with) ++ << "-fautotune" ++ << "-fautotune-generate"; ++ ++ if (IsMLTuningEnabled && !(IsAutoTuneGenerate || IsAutoTune)) ++ Diags.Report(diag::err_drv_argument_only_allowed_with) ++ << "-fautotune-rank" ++ << "-fautotune or -fautotune-generate"; ++ ++ if (IsAutoTuneGenerate || IsAutoTune) { ++ // Check if the environment variable AUTOTUNE_DATADIR is set. ++ if (std::optional<std::string> MaybePath = ++ llvm::sys::Process::GetEnv("AUTOTUNE_DATADIR")) ++ AutoTuneDirDataPath = *MaybePath; ++ else ++ AutoTuneDirDataPath = "autotune_datadir"; ++ ++ // Check if the environment variable AUTOTUNE_PROJECT_DIR is set. ++ if (std::optional<std::string> MaybeProjectDIR = ++ llvm::sys::Process::GetEnv(AutoTunePrjDirStr)) ++ AutoTuneProjectDir = *MaybeProjectDIR; ++ else ++ AutoTuneProjectDir = ""; ++ ++ if (IsAutoTuneGenerate) ++ AutoTuneMode = AutoTuneGenerate; ++ if (IsAutoTune) ++ AutoTuneMode = AutoTuneNext; ++ } ++#endif ++ + // Process -fembed-bitcode= flags. + if (Arg *A = Args.getLastArg(options::OPT_fembed_bitcode_EQ)) { + StringRef Name = A->getValue(); +diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp +index a4af991b5ff3..933661685117 100644 +--- a/clang/lib/Driver/ToolChains/Clang.cpp ++++ b/clang/lib/Driver/ToolChains/Clang.cpp +@@ -5990,6 +5990,27 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, + if (!Triple.isNVPTX() && !Triple.isAMDGCN()) + addPGOAndCoverageFlags(TC, C, JA, Output, Args, SanitizeArgs, CmdArgs); + ++#if defined(ENABLE_AUTOTUNER) ++ // Add Auto-tuning options. ++ if (C.getDriver().isUsingAutoTune()) { ++ Arg *A = Args.getLastArg(options::OPT_O_Group); ++ if (!A || A->getOption().matches(options::OPT_O0)) ++ D.Diag(clang::diag::err_drv_autotune_disabled_O0); ++ ++ // Enable debug info when Auto-tuning options are specified. ++ CmdArgs.push_back("-debug-info-kind=line-tables-only"); ++ if (!D.AutoTuneProjectDir.empty()) { ++ CmdArgs.push_back("-mllvm"); ++ CmdArgs.push_back(Args.MakeArgString(Twine("-autotuning-project-dir=") + ++ D.AutoTuneProjectDir)); ++ } ++ if (D.getAutoTuneMode() == AutoTuneKind::AutoTuneGenerate) ++ AddAutoTuningOpportunities(Args, D, CmdArgs); ++ else if (D.getAutoTuneMode() == AutoTuneKind::AutoTuneNext) ++ AddAutoTuningInput(Args, D, CmdArgs); ++ } ++#endif ++ + Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ); + + if (getLastProfileSampleUseArg(Args) && +diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp +index 1ccc83a468ce..e01b21e102b1 100644 +--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp ++++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp +@@ -2429,6 +2429,119 @@ void tools::addMachineOutlinerArgs(const Driver &D, + } + } + ++#if defined(ENABLE_AUTOTUNER) ++static bool isAcceptableThinLTOCodeRegion(StringRef CR) { ++ if ((CR.equals("CallSite") || CR.equals("Loop") || CR.equals("Function") || ++ CR.equals("MachineBasicBlock"))) ++ return false; ++ return true; ++} ++ ++static bool processOpportunitiesOptions(StringRef CR, bool IsThinLTO, ++ std::string &CodeRegionsFilterStr) { ++ // Check if the argument has a valid value. ++ if (!(CR.equals("Other") || CR.equals("LLVMParam") || CR.equals("CallSite") || ++ CR.equals("Function") || CR.equals("Loop") || ++ CR.equals("MachineBasicBlock") || CR.equals("Switch") || ++ CR.equals("ProgramParam"))) ++ return false; ++ ++ // Disable fine grain tuning for thin LTO during link time optimization. ++ if (IsThinLTO && !isAcceptableThinLTOCodeRegion(CR)) { ++ llvm::errs() ++ << "error: fine-grained autotuning not supported in ThinLTO mode\n"; ++ return false; ++ } ++ ++ if (!CodeRegionsFilterStr.empty()) ++ CodeRegionsFilterStr += ','; ++ CodeRegionsFilterStr += CR; ++ return true; ++} ++ ++// Add AutoTuner options for generating tuning opporutnities. ++// IsThinLTO will only be true during link time optimization for -flto=thin. ++void tools::AddAutoTuningOpportunities(const ArgList &Args, const Driver &D, ++ ArgStringList &CmdArgs, bool IsThinLTO) { ++ // Dump CodeRegions into opportunity files. ++ CmdArgs.push_back("-mllvm"); ++ SmallString<128> OppPath = StringRef(D.AutoTuneDirDataPath); ++ llvm::sys::path::append(OppPath, "opp"); ++ StringRef RawTypeFilterStr = D.AutoTuneOptions; ++ CmdArgs.push_back(Args.MakeArgString(Twine("-auto-tuning-opp=") + OppPath)); ++ if (D.IsMLTuningEnabled) { ++ // Baseline config is -1 ++ CmdArgs.push_back("-mllvm"); ++ CmdArgs.push_back(Args.MakeArgString(Twine("-auto-tuning-config-id=-1"))); ++ } ++ // Filter CodeRegions by type. ++ std::string CodeRegionsFilterStr; ++ if (Arg *A = Args.getLastArg(options::OPT_fautotune_generate_EQ)) { ++ for (StringRef CR : A->getValues()) { ++ if (!processOpportunitiesOptions(CR, IsThinLTO, CodeRegionsFilterStr)) ++ D.Diag(diag::err_drv_unsupported_option_argument) ++ << A->getOption().getName() << CR; ++ } ++ } else if (!RawTypeFilterStr.empty()) { ++ SmallVector<StringRef, 8> TypeFilters; ++ RawTypeFilterStr.split(TypeFilters, ','); ++ for (StringRef CR : TypeFilters) { ++ if (!processOpportunitiesOptions(CR, IsThinLTO, CodeRegionsFilterStr)) ++ D.Diag(diag::err_drv_unsupported_option_argument) ++ << "fautotune-generate" << CR; ++ } ++ } else { ++ if (IsThinLTO) ++ D.Diag(diag::err_drv_autotune_generic) ++ << "AutoTuner: no valid code region type specified for ThinLTO mode"; ++ // Otherwise by default, dump CodeRegions of Function and Loop type. ++ CodeRegionsFilterStr = "CallSite,Function,Loop"; ++ } ++ CmdArgs.push_back("-mllvm"); ++ CmdArgs.push_back( ++ Args.MakeArgString("-auto-tuning-type-filter=" + CodeRegionsFilterStr)); ++} ++ ++static bool processInputOptions(StringRef Options, SmallString<128> &Path, ++ const ArgList &Args, const Driver &D, ++ llvm::opt::ArgStringList &CmdArgs) { ++ unsigned Value = 0; ++ // Check if the argument is an integer type. ++ if (Options.getAsInteger(10, Value)) ++ return false; ++ llvm::sys::path::append(Path, "config-" + Twine(Value) + ".yaml"); ++ if (D.IsMLTuningEnabled) { ++ CmdArgs.push_back("-mllvm"); ++ CmdArgs.push_back( ++ Args.MakeArgString(Twine("-auto-tuning-config-id=" + Twine(Value)))); ++ } ++ return true; ++} ++ ++void tools::AddAutoTuningInput(const ArgList &Args, const Driver &D, ++ llvm::opt::ArgStringList &CmdArgs) { ++ SmallString<128> InputPath = StringRef(D.AutoTuneDirDataPath); ++ StringRef RawOptionsStr = D.AutoTuneOptions; ++ ++ if (Arg *A = Args.getLastArg(options::OPT_fautotune_EQ)) { ++ if (!processInputOptions(StringRef(A->getValue()), InputPath, Args, D, ++ CmdArgs)) ++ D.Diag(diag::err_drv_invalid_int_value) ++ << A->getAsString(Args) << A->getValue(); ++ } else if (!RawOptionsStr.empty()) { ++ if (!processInputOptions(RawOptionsStr, InputPath, Args, D, CmdArgs)) ++ D.Diag(diag::err_drv_invalid_int_value) ++ << "-fautotune=" + RawOptionsStr.str() << RawOptionsStr; ++ } else { ++ llvm::sys::path::append(InputPath, "config.yaml"); ++ } ++ CmdArgs.push_back("-mllvm"); ++ CmdArgs.push_back( ++ Args.MakeArgString(Twine("-auto-tuning-input=") + InputPath)); ++ setenv("AUTOTUNE_INPUT", Args.MakeArgString(InputPath), 1); ++} ++#endif ++ + void tools::addOpenMPDeviceRTL(const Driver &D, + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args, +diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h +index bd5cb1bb866e..36103655c522 100644 +--- a/clang/lib/Driver/ToolChains/CommonArgs.h ++++ b/clang/lib/Driver/ToolChains/CommonArgs.h +@@ -240,6 +240,14 @@ void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args, + const llvm::Triple &Triple, bool IsLTO, + const StringRef PluginOptPrefix = ""); + ++#if defined(ENABLE_AUTOTUNER) ++void AddAutoTuningOpportunities(const llvm::opt::ArgList &Args, const Driver &D, ++ llvm::opt::ArgStringList &CmdArgs, ++ bool isThinLTO = false); ++void AddAutoTuningInput(const llvm::opt::ArgList &Args, const Driver &D, ++ llvm::opt::ArgStringList &CmdArgs); ++#endif ++ + void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args, + StringRef BitcodeSuffix, const llvm::Triple &Triple); +diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp +index 42050dced99c..91a9eda9d78c 100644 +--- a/clang/lib/Driver/ToolChains/Gnu.cpp ++++ b/clang/lib/Driver/ToolChains/Gnu.cpp +@@ -682,6 +682,40 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + + Args.AddAllArgs(CmdArgs, options::OPT_T); + ++#if defined(ENABLE_AUTOTUNER) ++ // AutoTuner related features will only be enabled for LTO build during ++ // linking phase. Otherwise, non LTO build will require lld linker ++ // unnecessarily (other linkers do not support AutoTuner). ++ if (D.isUsingAutoTune() && D.isUsingLTO()) { ++ bool LinkerIsLLD = false; ++ (void) ToolChain.GetLinkerPath(&LinkerIsLLD); ++ // AutoTuner support is only available for LLD Linker. ++ if (!LinkerIsLLD) ++ D.Diag(clang::diag::err_drv_lto_without_lld); ++ ++ bool IsThinLTO = D.getLTOMode() == LTOK_Thin; ++ if (!D.AutoTuneProjectDir.empty()) { ++ CmdArgs.push_back("-mllvm"); ++ CmdArgs.push_back(Args.MakeArgString(Twine("-autotuning-project-dir=") + ++ D.AutoTuneProjectDir)); ++ } ++ // Enable tuning of callsites cause all of the callsites will have local ++ // linkage during LTO and they are not tuned by default. ++ CmdArgs.push_back(Args.MakeArgString("-mllvm")); ++ CmdArgs.push_back( ++ Args.MakeArgString("-auto-tuning-enable-local-callsite-tuning=true")); ++ if (D.getAutoTuneMode() == AutoTuneKind::AutoTuneGenerate) { ++ AddAutoTuningOpportunities(Args, D, CmdArgs, IsThinLTO); ++ } else if (D.getAutoTuneMode() == AutoTuneKind::AutoTuneNext) { ++ AddAutoTuningInput(Args, D, CmdArgs); ++ if (IsThinLTO) { ++ CmdArgs.push_back("-mllvm"); ++ CmdArgs.push_back("-autotuning-thin-lto=true"); ++ } ++ } ++ } ++#endif ++ + const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), +diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +index 310f67774a66..92beeef9bd5e 100644 +--- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp ++++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +@@ -222,6 +222,33 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) { + // This should happen AFTER plugins have been loaded! + if (!Clang->getFrontendOpts().LLVMArgs.empty()) { + unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size(); ++#if defined(ENABLE_AUTOTUNER) ++ // Both incremental compilation (for AutoTuner) and 'opt-bisect-limit' ++ // changes the behavior of compilation pipeline. If incremental compilation ++ // is used along with 'opt-bisect-limit' then 'opt-bisect-limit' is ++ // preferred and incremental compilation is disabled. ++ unsigned BisectLimitFound = 0; ++ unsigned CompileModeFound = 0; ++ for (unsigned Idx = 0; Idx != NumArgs; ++Idx) { ++ if (Clang->getFrontendOpts().LLVMArgsIdx.find("-opt-bisect-limit=") != ++ std::string::npos) ++ BisectLimitFound = Idx; ++ if (Clang->getFrontendOpts().LLVMArgsIdx.find( ++ "-auto-tuning-compile-mode=") != std::string::npos) ++ CompileModeFound = Idx; ++ if (BisectLimitFound && CompileModeFound) ++ break; ++ } ++ if (BisectLimitFound && CompileModeFound && ++ Clang->getFrontendOpts().LLVMArgsCompileModeFound.compare( ++ "-auto-tuning-compile-mode=Inactive") != 0) { ++ Clang->getFrontendOpts().LLVMArgsCompileModeFound = ++ "-auto-tuning-compile-mode=Inactive"; ++ llvm::errs() << "AutoTunerCompile: Incremental compilation cannot work " ++ "with '-opt-bisect-limit' flag.\n" ++ "Disabling incremental compilation.\n"; ++ } ++#endif + auto Args = std::make_unique<const char*>(NumArgs + 2); + Args0 = "clang (LLVM option parsing)"; + for (unsigned i = 0; i != NumArgs; ++i) +-- +2.33.0 +
View file
_service:tar_scm:0017-fix-for-missing-DENABLE_AUTOTUNER.patch
Added
@@ -0,0 +1,17 @@ +diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt +index 949f12d3ce8c..98fcb6ea1a07 100644 +--- a/clang/CMakeLists.txt ++++ b/clang/CMakeLists.txt +@@ -322,6 +322,10 @@ if (BUILD_FOR_OPENEULER) + add_definitions( -DBUILD_FOR_OPENEULER ) + endif() + ++if (LLVM_ENABLE_AUTOTUNER) ++ add_definitions( -DENABLE_AUTOTUNER ) ++endif() ++ + # Determine HOST_LINK_VERSION on Darwin. + set(HOST_LINK_VERSION) + if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*") + -- + \ No newline at end of file
View file
_service:tar_scm:0018-backport-Clang-Fix-build-with-GCC-14-on-ARM-78704.patch
Added
@@ -0,0 +1,64 @@ +From 505323d49f4621e5f7210d99fd52dd33a6223fa8 Mon Sep 17 00:00:00 2001 +From: eastb233 <xiezhiheng@huawei.com> +Date: Tue, 3 Sep 2024 11:59:57 +0800 +Subject: PATCH backportClang Fix build with GCC 14 on ARM (#78704) + +Reference: https://github.com/llvm/llvm-project/pull/78704 + +GCC 14 defines `__arm_streaming` as a macro expanding to +`arm::streaming`. Due to the nested macro use, this gets expanded +prior to concatenation. + +It doesn't look like C++ has a really clean way to prevent macro +expansion. The best I have found is to use `EMPTY ## X` where `EMPTY` is +an empty macro argument, so this is the hack I'm implementing here. + +Fixes https://github.com/llvm/llvm-project/issues/78691. +--- + clang/include/clang/Basic/TokenKinds.def | 2 +- + clang/include/clang/Basic/TokenKinds.h | 2 +- + clang/utils/TableGen/ClangAttrEmitter.cpp | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def +index ef0dad0f2dcd..afd101b007b4 100644 +--- a/clang/include/clang/Basic/TokenKinds.def ++++ b/clang/include/clang/Basic/TokenKinds.def +@@ -753,7 +753,7 @@ KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL) + + // Keywords defined by Attr.td. + #ifndef KEYWORD_ATTRIBUTE +-#define KEYWORD_ATTRIBUTE(X) KEYWORD(X, KEYALL) ++#define KEYWORD_ATTRIBUTE(X, EMPTY) KEYWORD(EMPTY ## X, KEYALL) + #endif + #include "clang/Basic/AttrTokenKinds.inc" + +diff --git a/clang/include/clang/Basic/TokenKinds.h b/clang/include/clang/Basic/TokenKinds.h +index e4857405bc7f..ff117bd5afc5 100644 +--- a/clang/include/clang/Basic/TokenKinds.h ++++ b/clang/include/clang/Basic/TokenKinds.h +@@ -109,7 +109,7 @@ bool isPragmaAnnotation(TokenKind K); + + inline constexpr bool isRegularKeywordAttribute(TokenKind K) { + return (false +-#define KEYWORD_ATTRIBUTE(X) || (K == tok::kw_##X) ++#define KEYWORD_ATTRIBUTE(X, ...) || (K == tok::kw_##X) + #include "clang/Basic/AttrTokenKinds.inc" + ); + } +diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp +index b5813c6abc2b..79db17501b64 100644 +--- a/clang/utils/TableGen/ClangAttrEmitter.cpp ++++ b/clang/utils/TableGen/ClangAttrEmitter.cpp +@@ -3430,7 +3430,7 @@ void EmitClangAttrTokenKinds(RecordKeeper &Records, raw_ostream &OS) { + "RegularKeyword attributes with arguments are not " + "yet supported"); + OS << "KEYWORD_ATTRIBUTE(" +- << S.getSpellingRecord().getValueAsString("Name") << ")\n"; ++ << S.getSpellingRecord().getValueAsString("Name") << ", )\n"; + } + OS << "#undef KEYWORD_ATTRIBUTE\n"; + } +-- +2.38.1.windows.1 +
View file
_service:tar_scm:0019-AArch64-Support-HiSilicon-s-HIP09-Processor.patch
Added
@@ -0,0 +1,176 @@ +From cac43828d26b178807d194b4bd7c5df69603df29 Mon Sep 17 00:00:00 2001 +From: xiajingze <xiajingze1@huawei.com> +Date: Wed, 31 Jul 2024 18:37:29 +0800 +Subject: PATCH AArch64 Support HiSilicon's HIP09 Processor + +Signed-off-by: xiajingze <xiajingze1@huawei.com> +--- + clang/test/CMakeLists.txt | 1 ++ + clang/test/Driver/aarch64-hip09.c | 9 ++ + .../test/Misc/target-invalid-cpu-note-hip09.c | 97 +++++++++++++++++++ + clang/test/Misc/target-invalid-cpu-note.c | 1 + + clang/test/lit.site.cfg.py.in | 4 + + 5 files changed, 112 insertions(+), 0 deletion(-) + create mode 100644 clang/test/Driver/aarch64-hip09.c + create mode 100644 clang/test/Misc/target-invalid-cpu-note-hip09.c + +diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt +index b88694deb..25e4e1f30 100644 +--- a/clang/test/CMakeLists.txt ++++ b/clang/test/CMakeLists.txt +@@ -19,6 +19,7 @@ llvm_canonicalize_cmake_booleans( + LLVM_WITH_Z3 + PPC_LINUX_DEFAULT_IEEELONGDOUBLE + LLVM_TOOL_LLVM_DRIVER_BUILD ++ LLVM_ENABLE_AARCH64_HIP09 + ) + + configure_lit_site_cfg( +diff --git a/clang/test/Driver/aarch64-hip09.c b/clang/test/Driver/aarch64-hip09.c +new file mode 100644 +index 000000000..156be3f38 +--- /dev/null ++++ b/clang/test/Driver/aarch64-hip09.c +@@ -0,0 +1,9 @@ ++// REQUIRES: enable_enable_aarch64_hip09 ++// RUN: %clang -target aarch64_be -mcpu=hip09 -### -c %s 2>&1 | FileCheck -check-prefix=hip09-BE %s ++// RUN: %clang -target aarch64 -mbig-endian -mcpu=hip09 -### -c %s 2>&1 | FileCheck -check-prefix=hip09-BE %s ++// RUN: %clang -target aarch64_be -mbig-endian -mcpu=hip09 -### -c %s 2>&1 | FileCheck -check-prefix=hip09-BE %s ++// RUN: %clang -target aarch64_be -mtune=hip09 -### -c %s 2>&1 | FileCheck -check-prefix=hip09-BE-TUNE %s ++// RUN: %clang -target aarch64 -mbig-endian -mtune=hip09 -### -c %s 2>&1 | FileCheck -check-prefix=hip09-BE-TUNE %s ++// RUN: %clang -target aarch64_be -mbig-endian -mtune=hip09 -### -c %s 2>&1 | FileCheck -check-prefix=hip09-BE-TUNE %s ++// hip09-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" "hip09" ++// hip09-BE-TUNE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" "generic" +diff --git a/clang/test/Misc/target-invalid-cpu-note-hip09.c b/clang/test/Misc/target-invalid-cpu-note-hip09.c +new file mode 100644 +index 000000000..f2561a089 +--- /dev/null ++++ b/clang/test/Misc/target-invalid-cpu-note-hip09.c +@@ -0,0 +1,97 @@ ++// REQUIRES: enable_enable_aarch64_hip09 ++// Use CHECK-NEXT instead of multiple CHECK-SAME to ensure we will fail if there is anything extra in the output. ++// RUN: not %clang_cc1 -triple armv5--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix ARM ++// ARM: error: unknown target CPU 'not-a-cpu' ++// ARM-NEXT: note: valid target CPU values are: arm8, arm810, strongarm, strongarm110, strongarm1100, strongarm1110, arm7tdmi, arm7tdmi-s, arm710t, arm720t, arm9, arm9tdmi, arm920, arm920t, arm922t, arm940t, ep9312, arm10tdmi, arm1020t, arm9e, arm946e-s, arm966e-s, arm968e-s, arm10e, arm1020e, arm1022e, arm926ej-s, arm1136j-s, arm1136jf-s, mpcore, mpcorenovfp, arm1176jz-s, arm1176jzf-s, arm1156t2-s, arm1156t2f-s, cortex-m0, cortex-m0plus, cortex-m1, sc000, cortex-a5, cortex-a7, cortex-a8, cortex-a9, cortex-a12, cortex-a15, cortex-a17, krait, cortex-r4, cortex-r4f, cortex-r5, cortex-r7, cortex-r8, cortex-r52, sc300, cortex-m3, cortex-m4, cortex-m7, cortex-m23, cortex-m33, cortex-m35p, cortex-m55, cortex-m85, cortex-a32, cortex-a35, cortex-a53, cortex-a55, cortex-a57, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-x1, cortex-x1c, neoverse-n1, neoverse-n2, neoverse-v1, cyclone, exynos-m3, exynos-m4, exynos-m5, kryo, iwmmxt, xscale, swift{{$}} ++ ++// RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AARCH64 ++// AARCH64: error: unknown target CPU 'not-a-cpu' ++// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, hip09, grace{{$}} ++ ++// RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix TUNE_AARCH64 ++// TUNE_AARCH64: error: unknown target CPU 'not-a-cpu' ++// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, hip09, grace{{$}} ++ ++// RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix X86 ++// X86: error: unknown target CPU 'not-a-cpu' ++// X86-NEXT: note: valid target CPU values are: i386, i486, winchip-c6, winchip2, c3, i586, pentium, pentium-mmx, pentiumpro, i686, pentium2, pentium3, pentium3m, pentium-m, c3-2, yonah, pentium4, pentium4m, prescott, nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, rocketlake, icelake-server, tigerlake, sapphirerapids, alderlake, raptorlake, meteorlake, sierraforest, grandridge, graniterapids, graniterapids-d, emeraldrapids, knl, knm, lakemont, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, znver4, x86-64, x86-64-v2, x86-64-v3, x86-64-v4, geode{{$}} ++ ++// RUN: not %clang_cc1 -triple x86_64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix X86_64 ++// X86_64: error: unknown target CPU 'not-a-cpu' ++// X86_64-NEXT: note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, rocketlake, icelake-server, tigerlake, sapphirerapids, alderlake, raptorlake, meteorlake, sierraforest, grandridge, graniterapids, graniterapids-d, emeraldrapids, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, znver4, x86-64, x86-64-v2, x86-64-v3, x86-64-v4{{$}} ++ ++// RUN: not %clang_cc1 -triple i386--- -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix TUNE_X86 ++// TUNE_X86: error: unknown target CPU 'not-a-cpu' ++// TUNE_X86-NEXT: note: valid target CPU values are: i386, i486, winchip-c6, winchip2, c3, i586, pentium, pentium-mmx, pentiumpro, i686, pentium2, pentium3, pentium3m, pentium-m, c3-2, yonah, pentium4, pentium4m, prescott, nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, rocketlake, icelake-server, tigerlake, sapphirerapids, alderlake, raptorlake, meteorlake, sierraforest, grandridge, graniterapids, graniterapids-d, emeraldrapids, knl, knm, lakemont, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, znver4, x86-64, geode{{$}} ++ ++// RUN: not %clang_cc1 -triple x86_64--- -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix TUNE_X86_64 ++// TUNE_X86_64: error: unknown target CPU 'not-a-cpu' ++// TUNE_X86_64-NEXT: note: valid target CPU values are: i386, i486, winchip-c6, winchip2, c3, i586, pentium, pentium-mmx, pentiumpro, i686, pentium2, pentium3, pentium3m, pentium-m, c3-2, yonah, pentium4, pentium4m, prescott, nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, rocketlake, icelake-server, tigerlake, sapphirerapids, alderlake, raptorlake, meteorlake, sierraforest, grandridge, graniterapids, graniterapids-d, emeraldrapids, knl, knm, lakemont, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, znver4, x86-64, geode{{$}} ++ ++// RUN: not %clang_cc1 -triple nvptx--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix NVPTX ++// NVPTX: error: unknown target CPU 'not-a-cpu' ++// NVPTX-NEXT: note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35, sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72, sm_75, sm_80, sm_86, sm_87, sm_89, sm_90, gfx600, gfx601, gfx602, gfx700, gfx701, gfx702, gfx703, gfx704, gfx705, gfx801, gfx802, gfx803, gfx805, gfx810, gfx900, gfx902, gfx904, gfx906, gfx908, gfx909, gfx90a, gfx90c, gfx940, gfx941, gfx942, gfx1010, gfx1011, gfx1012, gfx1013, gfx1030, gfx1031, gfx1032, gfx1033, gfx1034, gfx1035, gfx1036, gfx1100, gfx1101, gfx1102, gfx1103, gfx1150, gfx1151{{$}} ++ ++// RUN: not %clang_cc1 -triple r600--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix R600 ++// R600: error: unknown target CPU 'not-a-cpu' ++// R600-NEXT: note: valid target CPU values are: r600, rv630, rv635, r630, rs780, rs880, rv610, rv620, rv670, rv710, rv730, rv740, rv770, cedar, palm, cypress, hemlock, juniper, redwood, sumo, sumo2, barts, caicos, aruba, cayman, turks{{$}} ++ ++// RUN: not %clang_cc1 -triple amdgcn--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AMDGCN ++// AMDGCN: error: unknown target CPU 'not-a-cpu' ++// AMDGCN-NEXT: note: valid target CPU values are: gfx600, tahiti, gfx601, pitcairn, verde, gfx602, hainan, oland, gfx700, kaveri, gfx701, hawaii, gfx702, gfx703, kabini, mullins, gfx704, bonaire, gfx705, gfx801, carrizo, gfx802, iceland, tonga, gfx803, fiji, polaris10, polaris11, gfx805, tongapro, gfx810, stoney, gfx900, gfx902, gfx904, gfx906, gfx908, gfx909, gfx90a, gfx90c, gfx940, gfx941, gfx942, gfx1010, gfx1011, gfx1012, gfx1013, gfx1030, gfx1031, gfx1032, gfx1033, gfx1034, gfx1035, gfx1036, gfx1100, gfx1101, gfx1102, gfx1103, gfx1150, gfx1151{{$}} ++ ++// RUN: not %clang_cc1 -triple wasm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix WEBASM ++// WEBASM: error: unknown target CPU 'not-a-cpu' ++// WEBASM-NEXT: note: valid target CPU values are: mvp, bleeding-edge, generic{{$}} ++ ++// RUN: not %clang_cc1 -triple systemz--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix SYSTEMZ ++// SYSTEMZ: error: unknown target CPU 'not-a-cpu' ++// SYSTEMZ-NEXT: note: valid target CPU values are: arch8, z10, arch9, z196, arch10, zEC12, arch11, z13, arch12, z14, arch13, z15, arch14, z16{{$}} ++ ++// RUN: not %clang_cc1 -triple sparc--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix SPARC ++// SPARC: error: unknown target CPU 'not-a-cpu' ++// SPARC-NEXT: note: valid target CPU values are: v8, supersparc, sparclite, f934, hypersparc, sparclite86x, sparclet, tsc701, v9, ultrasparc, ultrasparc3, niagara, niagara2, niagara3, niagara4, ma2100, ma2150, ma2155, ma2450, ma2455, ma2x5x, ma2080, ma2085, ma2480, ma2485, ma2x8x, myriad2, myriad2.1, myriad2.2, myriad2.3, leon2, at697e, at697f, leon3, ut699, gr712rc, leon4, gr740{{$}} ++ ++// RUN: not %clang_cc1 -triple sparcv9--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix SPARCV9 ++// SPARCV9: error: unknown target CPU 'not-a-cpu' ++// SPARCV9-NEXT: note: valid target CPU values are: v9, ultrasparc, ultrasparc3, niagara, niagara2, niagara3, niagara4{{$}} ++ ++// RUN: not %clang_cc1 -triple powerpc--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix PPC ++// PPC: error: unknown target CPU 'not-a-cpu' ++// PPC-NEXT: note: valid target CPU values are: generic, 440, 450, 601, 602, 603, 603e, 603ev, 604, 604e, 620, 630, g3, 7400, g4, 7450, g4+, 750, 8548, 970, g5, a2, e500, e500mc, e5500, power3, pwr3, power4, pwr4, power5, pwr5, power5x, pwr5x, power6, pwr6, power6x, pwr6x, power7, pwr7, power8, pwr8, power9, pwr9, power10, pwr10, powerpc, ppc, ppc32, powerpc64, ppc64, powerpc64le, ppc64le, future{{$}} ++ ++// RUN: not %clang_cc1 -triple mips--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix MIPS ++// MIPS: error: unknown target CPU 'not-a-cpu' ++// MIPS-NEXT: note: valid target CPU values are: mips1, mips2, mips3, mips4, mips5, mips32, mips32r2, mips32r3, mips32r5, mips32r6, mips64, mips64r2, mips64r3, mips64r5, mips64r6, octeon, octeon+, p5600{{$}} ++ ++// RUN: not %clang_cc1 -triple lanai--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix LANAI ++// LANAI: error: unknown target CPU 'not-a-cpu' ++// LANAI-NEXT: note: valid target CPU values are: v11{{$}} ++ ++// RUN: not %clang_cc1 -triple hexagon--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix HEXAGON ++// HEXAGON: error: unknown target CPU 'not-a-cpu' ++// HEXAGON-NEXT: note: valid target CPU values are: hexagonv5, hexagonv55, hexagonv60, hexagonv62, hexagonv65, hexagonv66, hexagonv67, hexagonv67t, hexagonv68, hexagonv69, hexagonv71, hexagonv71t, hexagonv73{{$}} ++ ++// RUN: not %clang_cc1 -triple bpf--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix BPF ++// BPF: error: unknown target CPU 'not-a-cpu' ++// BPF-NEXT: note: valid target CPU values are: generic, v1, v2, v3, probe{{$}} ++ ++// RUN: not %clang_cc1 -triple avr--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AVR ++// AVR: error: unknown target CPU 'not-a-cpu' ++// AVR-NEXT: note: valid target CPU values are: avr1, at90s1200, attiny11, attiny12, attiny15, attiny28, avr2, at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at86rf401, at90s4414, at90s4433, at90s4434, at90s8515, at90c8534, at90s8535, avr25, ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a, attiny24, attiny24a, attiny4313, attiny44, attiny44a, attiny84, attiny84a, attiny25, attiny45, attiny85, attiny261, attiny261a, attiny441, attiny461, attiny461a, attiny841, attiny861, attiny861a, attiny87, attiny43u, attiny48, attiny88, attiny828, avr3, at43usb355, at76c711, avr31, atmega103, at43usb320, avr35, attiny167, at90usb82, at90usb162, ata5505, ata6617c, ata664251, atmega8u2, atmega16u2, atmega32u2, attiny1634, avr4, atmega8, ata6289, atmega8a, ata6285, ata6286, ata6612c, atmega48, atmega48a, atmega48pa, atmega48pb, atmega48p, atmega88, atmega88a, atmega88p, atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1, at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81, avr5, ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831, ata6613c, ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162, atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a, atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa, atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega32, atmega32a, atmega323, atmega324a, atmega324p, atmega324pa, atmega324pb, atmega325, atmega325a, atmega325p, atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328, atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa, atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega406, atmega64, atmega64a, atmega640, atmega644, atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p, atmega649, atmega649a, atmega649p, atmega6450, atmega6450a, atmega6450p, atmega6490, atmega6490a, atmega6490p, atmega64rfr2, atmega644rfr2, atmega16hva, atmega16hva2, atmega16hvb, atmega16hvbrevb, atmega32hvb, atmega32hvbrevb, atmega64hve, atmega64hve2, at90can32, at90can64, at90pwm161, at90pwm216, at90pwm316, atmega32c1, atmega64c1, atmega16m1, atmega32m1, atmega64m1, atmega16u4, atmega32u4, atmega32u6, at90usb646, at90usb647, at90scr100, at94k, m3000, avr51, atmega128, atmega128a, atmega1280, atmega1281, atmega1284, atmega1284p, atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286, at90usb1287, avr6, atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2, avrxmega2, atxmega16a4, atxmega16a4u, atxmega16c4, atxmega16d4, atxmega32a4, atxmega32a4u, atxmega32c3, atxmega32c4, atxmega32d3, atxmega32d4, atxmega32e5, atxmega16e5, atxmega8e5, avrxmega4, atxmega64a3, atxmega64a3u, atxmega64a4u, atxmega64b1, atxmega64b3, atxmega64c3, atxmega64d3, atxmega64d4, avrxmega5, atxmega64a1, atxmega64a1u, avrxmega6, atxmega128a3, atxmega128a3u, atxmega128b1, atxmega128b3, atxmega128c3, atxmega128d3, atxmega128d4, atxmega192a3, atxmega192a3u, atxmega192c3, atxmega192d3, atxmega256a3, atxmega256a3u, atxmega256a3b, atxmega256a3bu, atxmega256c3, atxmega256d3, atxmega384c3, atxmega384d3, avrxmega7, atxmega128a1, atxmega128a1u, atxmega128a4u, avrtiny, attiny4, attiny5, attiny9, attiny10, attiny20, attiny40, attiny102, attiny104, avrxmega3, attiny202, attiny402, attiny204, attiny404, attiny804, attiny1604, attiny406, attiny806, attiny1606, attiny807, attiny1607, attiny212, attiny412, attiny214, attiny414, attiny814, attiny1614, attiny416, attiny816, attiny1616, attiny3216, attiny417, attiny817, attiny1617, attiny3217, attiny1624, attiny1626, attiny1627, atmega808, atmega809, atmega1608, atmega1609, atmega3208, atmega3209, atmega4808, atmega4809 ++ ++// RUN: not %clang_cc1 -triple riscv32 -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix RISCV32 ++// RISCV32: error: unknown target CPU 'not-a-cpu' ++// RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, syntacore-scr1-base, syntacore-scr1-max{{$}} ++ ++// RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix RISCV64 ++// RISCV64: error: unknown target CPU 'not-a-cpu' ++// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, sifive-x280{{$}} ++ ++// RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix TUNE-RISCV32 ++// TUNE-RISCV32: error: unknown target CPU 'not-a-cpu' ++// TUNE-RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, syntacore-scr1-base, syntacore-scr1-max, generic, rocket, sifive-7-series{{$}} ++ ++// RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix TUNE-RISCV64 ++// TUNE-RISCV64: error: unknown target CPU 'not-a-cpu' ++// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, sifive-x280, generic, rocket, sifive-7-series{{$}} +diff --git a/clang/test/Misc/target-invalid-cpu-note.c b/clang/test/Misc/target-invalid-cpu-note.c +index cd1b0bc15..466b26263 100644 +--- a/clang/test/Misc/target-invalid-cpu-note.c ++++ b/clang/test/Misc/target-invalid-cpu-note.c +@@ -1,3 +1,4 @@ ++// UNSUPPORTED: enable_enable_aarch64_hip09 + // Use CHECK-NEXT instead of multiple CHECK-SAME to ensure we will fail if there is anything extra in the output. + // RUN: not %clang_cc1 -triple armv5--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix ARM + // ARM: error: unknown target CPU 'not-a-cpu' +diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in +index 89b7cafdc..7728be7d4 100644 +--- a/clang/test/lit.site.cfg.py.in ++++ b/clang/test/lit.site.cfg.py.in +@@ -44,9 +44,13 @@ config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@ + config.use_classic_flang = @LLVM_ENABLE_CLASSIC_FLANG@ + config.build_for_openeuler = @BUILD_FOR_OPENEULER@ ++config.enable_enable_aarch64_hip09 = @LLVM_ENABLE_AARCH64_HIP09@ + + import lit.llvm + lit.llvm.initialize(lit_config, config) + ++if config.enable_enable_aarch64_hip09: ++ config.available_features.add("enable_enable_aarch64_hip09") ++ + # Let the main config do the real work. + lit_config.load_config( + config, os.path.join(config.clang_src_dir, "test/lit.cfg.py")) +-- +2.19.1 +
View file
_service:tar_scm:0020-Backport-LoongArch-fix-and-add-some-new-support.patch
Added
@@ -0,0 +1,1715 @@ +From 0cae10595a7521e2c430c605c1f830570b3c9682 Mon Sep 17 00:00:00 2001 +From: Lu Weining <luweining@loongson.cn> +Date: Thu, 30 Nov 2023 14:08:45 +0800 +Subject: PATCH 1/9 Driver Support -mcmodel= for LoongArch (#72514) + +7e42545 rejects unsupported mcmodel options, but normal/medium/extreme +should be supported models for LoongArch according to gcc +document(https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html). + +The mappings among `gcc`, `clang driver`, `clang cc1` and `LLVM (i.e. +llc --code-model=)` are: + +| gcc | clang driver | clang cc1 | LLVM | +| ------------- | ------------------ | ----------------- | -------------- | +| normal | normal | small | small | +| medium | medium | medium | medium | +| extreme | extreme | large | large | + +(cherry picked from commit 1296d20adfb0978afe38d67efab9818079d870ca) +--- + clang/lib/Driver/ToolChains/Clang.cpp | 38 ++++++++++++++++++++------- + clang/test/Driver/mcmodel.c | 15 +++++++++++ + 2 files changed, 44 insertions(+), 9 deletions(-) + +diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp +index fac4f03d6193..4e5f689498d6 100644 +--- a/clang/lib/Driver/ToolChains/Clang.cpp ++++ b/clang/lib/Driver/ToolChains/Clang.cpp +@@ -5773,18 +5773,38 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, + + if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { + StringRef CM = A->getValue(); +- if (CM == "small" || CM == "kernel" || CM == "medium" || CM == "large" || +- CM == "tiny") { +- if (Triple.isOSAIX() && CM == "medium") +- CmdArgs.push_back("-mcmodel=large"); +- else if (Triple.isAArch64() && (CM == "kernel" || CM == "medium")) ++ if (Triple.isLoongArch()) { ++ bool Ok = false; ++ if (CM == "extreme" && ++ Args.hasFlagNoClaim(options::OPT_fplt, options::OPT_fno_plt, false)) ++ D.Diag(diag::err_drv_argument_not_allowed_with) ++ << A->getAsString(Args) << "-fplt"; ++ Ok = CM == "normal" || CM == "medium" || CM == "extreme"; ++ // Convert to LLVM recognizable names. ++ if (Ok) { ++ CM = llvm::StringSwitch<StringRef>(CM) ++ .Case("normal", "small") ++ .Case("extreme", "large") ++ .Default(CM); ++ CmdArgs.push_back(Args.MakeArgString("-mcmodel=" + CM)); ++ } else { + D.Diag(diag::err_drv_invalid_argument_to_option) + << CM << A->getOption().getName(); +- else +- A->render(Args, CmdArgs); ++ } + } else { +- D.Diag(diag::err_drv_invalid_argument_to_option) +- << CM << A->getOption().getName(); ++ if (CM == "small" || CM == "kernel" || CM == "medium" || CM == "large" || ++ CM == "tiny") { ++ if (Triple.isOSAIX() && CM == "medium") ++ CmdArgs.push_back("-mcmodel=large"); ++ else if (Triple.isAArch64() && (CM == "kernel" || CM == "medium")) ++ D.Diag(diag::err_drv_invalid_argument_to_option) ++ << CM << A->getOption().getName(); ++ else ++ A->render(Args, CmdArgs); ++ } else { ++ D.Diag(diag::err_drv_invalid_argument_to_option) ++ << CM << A->getOption().getName(); ++ } + } + } + +diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c +index 63b432036159..4aada126cf06 100644 +--- a/clang/test/Driver/mcmodel.c ++++ b/clang/test/Driver/mcmodel.c +@@ -8,6 +8,14 @@ + // RUN: not %clang -c -mcmodel=lager %s 2>&1 | FileCheck --check-prefix=INVALID %s + // RUN: not %clang -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AARCH64-MEDIUM %s + // RUN: not %clang -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AARCH64-KERNEL %s ++// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s ++// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s ++// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-TINY %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-SMALL %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-KERNEL %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=large %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-LARGE %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=extreme -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s + + // TINY: "-mcmodel=tiny" + // SMALL: "-mcmodel=small" +@@ -20,3 +28,10 @@ + + // AARCH64-MEDIUM: error: invalid argument 'medium' to -mcmodel= + // AARCH64-KERNEL: error: invalid argument 'kernel' to -mcmodel= ++ ++// ERR-LOONGARCH64-TINY: error: invalid argument 'tiny' to -mcmodel= ++// ERR-LOONGARCH64-SMALL: error: invalid argument 'small' to -mcmodel= ++// ERR-LOONGARCH64-KERNEL: error: invalid argument 'kernel' to -mcmodel= ++// ERR-LOONGARCH64-LARGE: error: invalid argument 'large' to -mcmodel= ++ ++// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt' +-- +2.20.1 + + +From b0e5225dea19a71b0c2f2168c117ac5032c2d18a Mon Sep 17 00:00:00 2001 +From: Zhaoxin Yang <yangzhaoxin@loongson.cn> +Date: Tue, 9 Jul 2024 14:13:19 +0800 +Subject: PATCH 2/9 LoongArchclang Add support for option `-msimd=` and + macro `__loongarch_simd_width`. (#97984) + +(cherry picked from commit 626c7ce33f850831949e4e724016ddbff3a34990) +--- + .../clang/Basic/DiagnosticDriverKinds.td | 2 + + clang/include/clang/Driver/Options.td | 3 + + clang/lib/Basic/Targets/LoongArch.cpp | 8 +- + .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 29 ++++ + clang/test/Driver/loongarch-msimd.c | 129 ++++++++++++++++++ + clang/test/Preprocessor/init-loongarch.c | 3 + + 6 files changed, 172 insertions(+), 2 deletions(-) + create mode 100644 clang/test/Driver/loongarch-msimd.c + +diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td +index 6b68bc458b93..060f96118364 100644 +--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td ++++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td +@@ -757,6 +757,8 @@ def err_drv_loongarch_wrong_fpu_width_for_lasx : Error< + "wrong fpu width; LASX depends on 64-bit FPU.">; + def err_drv_loongarch_invalid_simd_option_combination : Error< + "invalid option combination; LASX depends on LSX.">; ++def err_drv_loongarch_invalid_msimd_EQ : Error< ++ "invalid argument '%0' to -msimd=; must be one of: none, lsx, lasx">; + + def err_drv_expand_response_file : Error< + "failed to expand response file: %0">; +diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td +index 344c8bd49da7..530bb53ea9b5 100644 +--- a/clang/include/clang/Driver/Options.td ++++ b/clang/include/clang/Driver/Options.td +@@ -4236,6 +4236,9 @@ def mlasx : Flag<"-", "mlasx">, Group<m_loongarch_Features_Group>, + HelpText<"Enable Loongson Advanced SIMD Extension (LASX).">; + def mno_lasx : Flag<"-", "mno-lasx">, Group<m_loongarch_Features_Group>, + HelpText<"Disable Loongson Advanced SIMD Extension (LASX).">; ++def msimd_EQ : Joined<"-", "msimd=">, Group<m_loongarch_Features_Group>, ++ Flags<TargetSpecific>, ++ HelpText<"Select the SIMD extension(s) to be enabled in LoongArch either 'none', 'lsx', 'lasx'.">; + def mnop_mcount : Flag<"-", "mnop-mcount">, HelpText<"Generate mcount/__fentry__ calls as nops. To activate they need to be patched in.">, + Flags<CC1Option>, Group<m_Group>, + MarshallingInfoFlag<CodeGenOpts<"MNopMCount">>; +diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp +index 88537989a051..913404240916 100644 +--- a/clang/lib/Basic/Targets/LoongArch.cpp ++++ b/clang/lib/Basic/Targets/LoongArch.cpp +@@ -208,10 +208,14 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, + TuneCPU = ArchName; + Builder.defineMacro("__loongarch_tune", Twine('"') + TuneCPU + Twine('"')); + +- if (HasFeatureLSX) ++ if (HasFeatureLASX) { ++ Builder.defineMacro("__loongarch_simd_width", "256"); + Builder.defineMacro("__loongarch_sx", Twine(1)); +- if (HasFeatureLASX) + Builder.defineMacro("__loongarch_asx", Twine(1)); ++ } else if (HasFeatureLSX) { ++ Builder.defineMacro("__loongarch_simd_width", "128"); ++ Builder.defineMacro("__loongarch_sx", Twine(1)); ++ } + + StringRef ABI = getABI(); + if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s") +diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +index 31153a67ad28..2d9c3f810a06 100644 +--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp ++++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +@@ -207,6 +207,35 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + } else /*-mno-lasx*/ + Features.push_back("-lasx"); + } ++ ++ // Select lsx/lasx feature determined by -msimd=. ++ // Option -msimd= has lower priority than -mno-lsx and -mno-lasx. ++ if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) { ++ StringRef MSIMD = A->getValue(); ++ if (MSIMD == "lsx") { ++ // Option -msimd=lsx depends on 64-bit FPU. ++ // -m*-float and -mfpu=none/0/32 conflict with -mlsx. ++ if (llvm::find(Features, "-d") != Features.end()) ++ D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0; ++ // The previous option does not contain feature -lsx. ++ else if (llvm::find(Features, "-lsx") == Features.end()) ++ Features.push_back("+lsx"); ++ } else if (MSIMD == "lasx") { ++ // Option -msimd=lasx depends on 64-bit FPU and LSX. ++ // -m*-float and -mfpu=none/0/32 conflict with -mlsx. ++ if (llvm::find(Features, "-d") != Features.end()) ++ D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1; ++ else if (llvm::find(Features, "-lsx") != Features.end()) ++ D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination); ++ // The previous option does not contain feature -lasx. ++ else if (llvm::find(Features, "-lasx") == Features.end()) { ++ Features.push_back("+lsx"); ++ Features.push_back("+lasx"); ++ } ++ } else if (MSIMD != "none") { ++ D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD; ++ } ++ } + } + + std::string loongarch::postProcessTargetCPUString(const std::string &CPU, +diff --git a/clang/test/Driver/loongarch-msimd.c b/clang/test/Driver/loongarch-msimd.c +new file mode 100644 +index 000000000000..984f3e8bf2bf +--- /dev/null ++++ b/clang/test/Driver/loongarch-msimd.c +@@ -0,0 +1,129 @@ ++/// Test -msimd options. ++ ++/// COM: -msimd=none ++// RUN: %clang --target=loongarch64 -mlasx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,LASX ++// RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,LASX ++ ++// RUN: %clang --target=loongarch64 -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++ ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++ ++ ++/// COM: -msimd=lsx ++// RUN: %clang --target=loongarch64 -mlasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,LASX ++// RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,LASX ++ ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++ ++// RUN: %clang --target=loongarch64 -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++ ++ ++/// COM: -msimd=lasx ++// RUN: %clang --target=loongarch64 -msimd=lasx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,LASX ++// RUN: %clang --target=loongarch64 -mlasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,LASX ++// RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,LASX ++// RUN: %clang --target=loongarch64 -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,LASX ++ ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++ ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++// RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ ++// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX ++ ++ ++// LSX: "-target-feature" "+lsx" ++// LASX: "-target-feature" "+lasx" ++// NOLSX-NOT: "-target-feature" "+lsx" ++// NOLASX-NOT: "-target-feature" "+lasx" +diff --git a/clang/test/Preprocessor/init-loongarch.c b/clang/test/Preprocessor/init-loongarch.c +index e235a7283021..154ad82e0f8c 100644 +--- a/clang/test/Preprocessor/init-loongarch.c ++++ b/clang/test/Preprocessor/init-loongarch.c +@@ -817,6 +817,7 @@ + // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s + // MLSX-NOT: #define __loongarch_asx ++// MLSX: #define __loongarch_simd_width 128 + // MLSX: #define __loongarch_sx 1 + + // RUN: %clang --target=loongarch64 -mlasx -x c -E -dM %s -o - \ +@@ -828,6 +829,7 @@ + // RUN: %clang --target=loongarch64 -mlasx -mlsx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s + // MLASX: #define __loongarch_asx 1 ++// MLASX: #define __loongarch_simd_width 256 + // MLASX: #define __loongarch_sx 1 + + // RUN: %clang --target=loongarch64 -mno-lsx -x c -E -dM %s -o - \ +@@ -841,4 +843,5 @@ + // RUN: %clang --target=loongarch64 -mno-lasx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s + // MNO-LSX-NOT: #define __loongarch_asx ++// MNO-LSX-NOT: #define __loongarch_simd_width + // MNO-LSX-NOT: #define __loongarch_sx +-- +2.20.1 + + +From b2f8e92e88bf63e54ace9b2f9b2aa77dcf0c50c4 Mon Sep 17 00:00:00 2001 +From: Zhaoxin Yang <yangzhaoxin@loongson.cn> +Date: Thu, 11 Jul 2024 17:43:38 +0800 +Subject: PATCH 3/9 LoongArchclang Modify `loongarch-msimd.c` to avoid + `grep -o`. NFC (#98442) + +Address buildbot failure: +https://lab.llvm.org/buildbot/#/builders/64/builds/250/steps/6/logs/FAIL__Clang__loongarch-msimd_c + +(cherry picked from commit 74b933c28e777fdc04e50f5f96e4f7a4ad1e79a6) +--- + clang/test/Driver/loongarch-msimd.c | 42 +++-------------------------- + 1 file changed, 4 insertions(+), 38 deletions(-) + +diff --git a/clang/test/Driver/loongarch-msimd.c b/clang/test/Driver/loongarch-msimd.c +index 984f3e8bf2bf..cd463300c874 100644 +--- a/clang/test/Driver/loongarch-msimd.c ++++ b/clang/test/Driver/loongarch-msimd.c +@@ -2,128 +2,94 @@ + + /// COM: -msimd=none + // RUN: %clang --target=loongarch64 -mlasx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + + // RUN: %clang --target=loongarch64 -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + + + /// COM: -msimd=lsx + // RUN: %clang --target=loongarch64 -mlasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + + // RUN: %clang --target=loongarch64 -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + + + /// COM: -msimd=lasx + // RUN: %clang --target=loongarch64 -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + // RUN: %clang --target=loongarch64 -mlasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + // RUN: %clang --target=loongarch64 -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX + + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ +-// RUN: grep -o '"-target-feature" "+:alnum:\+"' | sort -r | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX + + +-// LSX: "-target-feature" "+lsx" +-// LASX: "-target-feature" "+lasx" ++// NOLSX-NOT: "-target-feature" "+lsx" ++// NOLASX-NOT: "-target-feature" "+lasx" ++// LSX-DAG: "-target-feature" "+lsx" ++// LASX-DAG: "-target-feature" "+lasx" + // NOLSX-NOT: "-target-feature" "+lsx" + // NOLASX-NOT: "-target-feature" "+lasx" +-- +2.20.1 + + +From b5d3aa3ac0dcf98fbb5f8d2d9de295be991c9e8f Mon Sep 17 00:00:00 2001 +From: Zhaoxin Yang <yangzhaoxin@loongson.cn> +Date: Tue, 23 Jul 2024 12:06:59 +0800 +Subject: PATCH 4/9 LoongArchCodeGen Implement 128-bit and 256-bit vector + shuffle. (#100054) + +LoongArchCodeGen Implement 128-bit and 256-bit vector shuffle +operations. + +In LoongArch, shuffle operations can be divided into two types: +- Single-vector shuffle: Shuffle using only one vector, with the other +vector being `undef` or not selected by mask. This can be expanded to +instructions such as `vreplvei` and `vshuf4i`. +- Two-vector shuffle: Shuflle using two vectors. This can be expanded to +instructions like `vilvl/h`, `vpackev/od`, `vpickev/od` and the +basic `vshuf`. + +In the future, more optimizations may be added, such as handling 1-bit +vectors and processing single element patterns, etc. + +(cherry picked from commit 464ea880cf7710cc8675c83001d7ae020406cf42) +--- + clang/lib/Driver/ToolChains/Arch/LoongArch.cpp | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +index 2d9c3f810a06..8b3d2837a4e5 100644 +--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp ++++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +@@ -216,7 +216,7 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + // Option -msimd=lsx depends on 64-bit FPU. + // -m*-float and -mfpu=none/0/32 conflict with -mlsx. + if (llvm::find(Features, "-d") != Features.end()) +- D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0; ++ D.Diag(diag::err_drv_loongarch_wrong_fpu_width_for_lsx); + // The previous option does not contain feature -lsx. + else if (llvm::find(Features, "-lsx") == Features.end()) + Features.push_back("+lsx"); +@@ -224,7 +224,7 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + // Option -msimd=lasx depends on 64-bit FPU and LSX. + // -m*-float and -mfpu=none/0/32 conflict with -mlsx. + if (llvm::find(Features, "-d") != Features.end()) +- D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1; ++ D.Diag(diag::err_drv_loongarch_wrong_fpu_width_for_lasx); + else if (llvm::find(Features, "-lsx") != Features.end()) + D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination); + // The previous option does not contain feature -lasx. +-- +2.20.1 + + +From 17f537eeaef8db451c70fc56a921e5ff542f713b Mon Sep 17 00:00:00 2001 +From: Ami-zhang <zhanglimin@loongson.cn> +Date: Tue, 23 Jul 2024 14:02:04 +0800 +Subject: PATCH 5/9 LoongArch Enable 128-bits vector by default (#100056) + +This commit is to enable 128 vector feature by default, in order to be +consistent with gcc. + +(cherry picked from commit b4ef0ba244899a64a1b1e6448eca942cfa5eda18) +--- + .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 76 +++++++++++-------- + .../test/Driver/loongarch-default-features.c | 2 +- + clang/test/Driver/loongarch-mlasx.c | 6 +- + clang/test/Driver/loongarch-msimd.c | 4 +- + clang/test/Driver/loongarch-msingle-float.c | 4 +- + clang/test/Driver/loongarch-msoft-float.c | 4 +- + clang/test/Preprocessor/init-loongarch.c | 8 +- + 7 files changed, 60 insertions(+), 44 deletions(-) + +diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +index 8b3d2837a4e5..87d7b30ef5d3 100644 +--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp ++++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + const llvm::Triple &Triple, + const ArgList &Args, + std::vector<StringRef> &Features) { ++ // Enable the `lsx` feature on 64-bit LoongArch by default. ++ if (Triple.isLoongArch64() && ++ (!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ))) ++ Features.push_back("+lsx"); ++ + std::string ArchName; + if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) + ArchName = A->getValue(); +@@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + } else if (A->getOption().matches(options::OPT_msingle_float)) { + Features.push_back("+f"); + Features.push_back("-d"); ++ Features.push_back("-lsx"); + } else /*Soft-float*/ { + Features.push_back("-f"); + Features.push_back("-d"); ++ Features.push_back("-lsx"); + } + } else if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) { + StringRef FPU = A->getValue(); +@@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + } else if (FPU == "32") { + Features.push_back("+f"); + Features.push_back("-d"); ++ Features.push_back("-lsx"); + } else if (FPU == "0" || FPU == "none") { + Features.push_back("-f"); + Features.push_back("-d"); ++ Features.push_back("-lsx"); + } else { + D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU; + } +@@ -175,6 +184,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + A->ignoreTargetSpecific(); + if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ)) + A->ignoreTargetSpecific(); ++ if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ)) ++ A->ignoreTargetSpecific(); ++ ++ // Select lsx/lasx feature determined by -msimd=. ++ // Option -msimd= precedes -mno-lsx and -mno-lasx. ++ if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) { ++ StringRef MSIMD = A->getValue(); ++ if (MSIMD == "lsx") { ++ // Option -msimd=lsx depends on 64-bit FPU. ++ // -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx. ++ if (llvm::find(Features, "-d") != Features.end()) ++ D.Diag(diag::err_drv_loongarch_wrong_fpu_width_for_lsx); ++ else ++ Features.push_back("+lsx"); ++ } else if (MSIMD == "lasx") { ++ // Option -msimd=lasx depends on 64-bit FPU and LSX. ++ // -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx. ++ if (llvm::find(Features, "-d") != Features.end()) ++ D.Diag(diag::err_drv_loongarch_wrong_fpu_width_for_lasx); ++ else if (llvm::find(Features, "-lsx") != Features.end()) ++ D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination); ++ ++ // The command options do not contain -mno-lasx. ++ if (!Args.getLastArg(options::OPT_mno_lasx)) { ++ Features.push_back("+lsx"); ++ Features.push_back("+lasx"); ++ } ++ } else if (MSIMD == "none") { ++ if (llvm::find(Features, "+lsx") != Features.end()) ++ Features.push_back("-lsx"); ++ if (llvm::find(Features, "+lasx") != Features.end()) ++ Features.push_back("-lasx"); ++ } else { ++ D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD; ++ } ++ } + + // Select lsx feature determined by -mno-lsx. + if (const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) { +@@ -198,8 +243,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + if (A->getOption().matches(options::OPT_mlasx)) { + if (llvm::find(Features, "-d") != Features.end()) + D.Diag(diag::err_drv_loongarch_wrong_fpu_width_for_lasx); +- else if (llvm::find(Features, "-lsx") != Features.end()) +- D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination); + else { /*-mlasx*/ + Features.push_back("+lsx"); + Features.push_back("+lasx"); +@@ -207,35 +250,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, + } else /*-mno-lasx*/ + Features.push_back("-lasx"); + } +- +- // Select lsx/lasx feature determined by -msimd=. +- // Option -msimd= has lower priority than -mno-lsx and -mno-lasx. +- if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) { +- StringRef MSIMD = A->getValue(); +- if (MSIMD == "lsx") { +- // Option -msimd=lsx depends on 64-bit FPU. +- // -m*-float and -mfpu=none/0/32 conflict with -mlsx. +- if (llvm::find(Features, "-d") != Features.end()) +- D.Diag(diag::err_drv_loongarch_wrong_fpu_width_for_lsx); +- // The previous option does not contain feature -lsx. +- else if (llvm::find(Features, "-lsx") == Features.end()) +- Features.push_back("+lsx"); +- } else if (MSIMD == "lasx") { +- // Option -msimd=lasx depends on 64-bit FPU and LSX. +- // -m*-float and -mfpu=none/0/32 conflict with -mlsx. +- if (llvm::find(Features, "-d") != Features.end()) +- D.Diag(diag::err_drv_loongarch_wrong_fpu_width_for_lasx); +- else if (llvm::find(Features, "-lsx") != Features.end()) +- D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination); +- // The previous option does not contain feature -lasx. +- else if (llvm::find(Features, "-lasx") == Features.end()) { +- Features.push_back("+lsx"); +- Features.push_back("+lasx"); +- } +- } else if (MSIMD != "none") { +- D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD; +- } +- } + } + + std::string loongarch::postProcessTargetCPUString(const std::string &CPU, +diff --git a/clang/test/Driver/loongarch-default-features.c b/clang/test/Driver/loongarch-default-features.c +index 3cdf3ba3d23e..90634bbcf003 100644 +--- a/clang/test/Driver/loongarch-default-features.c ++++ b/clang/test/Driver/loongarch-default-features.c +@@ -2,7 +2,7 @@ + // RUN: %clang --target=loongarch64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64 + + // LA32: "target-features"="+32bit" +-// LA64: "target-features"="+64bit,+d,+f,+ual" ++// LA64: "target-features"="+64bit,+d,+f,+lsx,+ual" + + int foo(void) { + return 3; +diff --git a/clang/test/Driver/loongarch-mlasx.c b/clang/test/Driver/loongarch-mlasx.c +index 0b934f125c9e..87634ff5a9a4 100644 +--- a/clang/test/Driver/loongarch-mlasx.c ++++ b/clang/test/Driver/loongarch-mlasx.c +@@ -5,7 +5,7 @@ + // RUN: %clang --target=loongarch64 -mno-lasx -fsyntax-only %s -### 2>&1 | \ + // RUN: FileCheck %s --check-prefix=CC1-NOLASX + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: FileCheck %s --check-prefix=CC1-NOLASX ++// RUN: FileCheck %s --check-prefix=CC1-LSX + // RUN: %clang --target=loongarch64 -mno-lasx -mlasx -fsyntax-only %s -### 2>&1 | \ + // RUN: FileCheck %s --check-prefix=CC1-LASX + // RUN: %clang --target=loongarch64 -mlsx -mlasx -fsyntax-only %s -### 2>&1 | \ +@@ -18,7 +18,7 @@ + // RUN: %clang --target=loongarch64 -mno-lasx -S -emit-llvm %s -o - | \ + // RUN: FileCheck %s --check-prefix=IR-NOLASX + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -S -emit-llvm %s -o - | \ +-// RUN: FileCheck %s --check-prefix=IR-NOLASX ++// RUN: FileCheck %s --check-prefix=IR-LSX + // RUN: %clang --target=loongarch64 -mno-lasx -mlasx -S -emit-llvm %s -o - | \ + // RUN: FileCheck %s --check-prefix=IR-LASX + // RUN: %clang --target=loongarch64 -mlsx -mlasx -S -emit-llvm %s -o - | \ +@@ -26,9 +26,11 @@ + // RUN: %clang --target=loongarch64 -mlasx -mlsx -S -emit-llvm %s -o - | \ + // RUN: FileCheck %s --check-prefix=IR-LASX + ++// CC1-LSX: "-target-feature" "+lsx" + // CC1-LASX: "-target-feature" "+lsx" "-target-feature" "+lasx" + // CC1-NOLASX: "-target-feature" "-lasx" + ++// IR-LSX: attributes ## ={{.*}}"target-features"="{{(.*,)?}}+lsx{{(,.*)?}}" + // IR-LASX: attributes ## ={{.*}}"target-features"="{{(.*,)?}}+lasx{{(,.*)?}}" + // IR-NOLASX: attributes ## ={{.*}}"target-features"="{{(.*,)?}}-lasx{{(,.*)?}}" + +diff --git a/clang/test/Driver/loongarch-msimd.c b/clang/test/Driver/loongarch-msimd.c +index cd463300c874..49d298e1b2e3 100644 +--- a/clang/test/Driver/loongarch-msimd.c ++++ b/clang/test/Driver/loongarch-msimd.c +@@ -75,9 +75,9 @@ + // RUN: FileCheck %s --check-prefixes=LSX,LASX + + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX + // RUN: %clang --target=loongarch64 -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ +-// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX ++// RUN: FileCheck %s --check-prefixes=LSX,NOLASX + + // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ + // RUN: FileCheck %s --check-prefixes=LSX,NOLASX +diff --git a/clang/test/Driver/loongarch-msingle-float.c b/clang/test/Driver/loongarch-msingle-float.c +index bd9b3e8a8c01..4eb0865b53a5 100644 +--- a/clang/test/Driver/loongarch-msingle-float.c ++++ b/clang/test/Driver/loongarch-msingle-float.c +@@ -11,10 +11,10 @@ + // WARN: warning: ignoring '-mabi=lp64s' as it conflicts with that implied by '-msingle-float' (lp64f) + // WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msingle-float' (32) + +-// CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d" ++// CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d" "-target-feature" "-lsx" + // CC1: "-target-abi" "lp64f" + +-// IR: attributes ## ={{.*}}"target-features"="{{(.*,)?}}+f,{{(.*,)?}}-d" ++// IR: attributes ## ={{.*}}"target-features"="{{(.*,)?}}+f,{{(.*,)?}}-d,-lsx" + + int foo(void) { + return 3; +diff --git a/clang/test/Driver/loongarch-msoft-float.c b/clang/test/Driver/loongarch-msoft-float.c +index 0e5121ac84b4..ebf27fb00e30 100644 +--- a/clang/test/Driver/loongarch-msoft-float.c ++++ b/clang/test/Driver/loongarch-msoft-float.c +@@ -11,10 +11,10 @@ + // WARN: warning: ignoring '-mabi=lp64d' as it conflicts with that implied by '-msoft-float' (lp64s) + // WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msoft-float' (0) + +-// CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d" ++// CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d" "-target-feature" "-lsx" + // CC1: "-target-abi" "lp64s" + +-// IR: attributes ## ={{.*}}"target-features"="{{(.*,)?}}-d,{{(.*,)?}}-f{{(,.*)?}}" ++// IR: attributes ## ={{.*}}"target-features"="{{(.*,)?}}-d,{{(.*,)?}}-f,-lsx" + + int foo(void) { + return 3; +diff --git a/clang/test/Preprocessor/init-loongarch.c b/clang/test/Preprocessor/init-loongarch.c +index 154ad82e0f8c..635d029ce9d3 100644 +--- a/clang/test/Preprocessor/init-loongarch.c ++++ b/clang/test/Preprocessor/init-loongarch.c +@@ -814,6 +814,8 @@ + // RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s + // RUN: %clang --target=loongarch64 -mlsx -mno-lasx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s ++// RUN: %clang --target=loongarch64 -mno-lasx -x c -E -dM %s -o - \ ++// RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s + // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s + // MLSX-NOT: #define __loongarch_asx +@@ -822,12 +824,12 @@ + + // RUN: %clang --target=loongarch64 -mlasx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s +-// RUN: %clang --target=loongarch64 -mno-lasx -mlasx -x c -E -dM %s -o - \ +-// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s + // RUN: %clang --target=loongarch64 -mlsx -mlasx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s + // RUN: %clang --target=loongarch64 -mlasx -mlsx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s ++// RUN: %clang --target=loongarch64 -mno-lasx -mlasx -x c -E -dM %s -o - \ ++// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s + // MLASX: #define __loongarch_asx 1 + // MLASX: #define __loongarch_simd_width 256 + // MLASX: #define __loongarch_sx 1 +@@ -840,8 +842,6 @@ + // RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s + // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -x c -E -dM %s -o - \ + // RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s +-// RUN: %clang --target=loongarch64 -mno-lasx -x c -E -dM %s -o - \ +-// RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s + // MNO-LSX-NOT: #define __loongarch_asx + // MNO-LSX-NOT: #define __loongarch_simd_width + // MNO-LSX-NOT: #define __loongarch_sx +-- +2.20.1 + + +From 57eaecf7bdb7a7502580076b365b4f70dde1185d Mon Sep 17 00:00:00 2001 +From: Ami-zhang <zhanglimin@loongson.cn> +Date: Tue, 23 Jan 2024 14:24:58 +0800 +Subject: PATCH 6/9 LoongArch Add definitions and feature 'frecipe' for FP + approximation intrinsics/builtins (#78962) + +This PR adds definitions and 'frecipe' feature for FP approximation +intrinsics/builtins. In additions, this adds and complements relative +testcases. + +(cherry picked from commit fcb8342a219ada8ec641790a4c8a9f969d7d64ee) +--- + .../clang/Basic/BuiltinsLoongArchBase.def | 5 +++ + .../clang/Basic/BuiltinsLoongArchLASX.def | 6 +++ + .../clang/Basic/BuiltinsLoongArchLSX.def | 6 +++ + clang/lib/Headers/larchintrin.h | 12 +++++ + clang/lib/Headers/lasxintrin.h | 24 ++++++++++ + clang/lib/Headers/lsxintrin.h | 24 ++++++++++ + .../LoongArch/builtin-dbl-approximate.c | 45 +++++++++++++++++++ + .../LoongArch/builtin-flt-approximate.c | 45 +++++++++++++++++++ + .../CodeGen/LoongArch/intrinsic-la64-error.c | 21 +++++++++ + .../lasx/builtin-approximate-alias.c | 37 +++++++++++++++ + .../LoongArch/lasx/builtin-approximate.c | 38 ++++++++++++++++ + .../LoongArch/lsx/builtin-approximate-alias.c | 37 +++++++++++++++ + .../LoongArch/lsx/builtin-approximate.c | 38 ++++++++++++++++ + 13 files changed, 338 insertions(+) + create mode 100644 clang/test/CodeGen/LoongArch/builtin-dbl-approximate.c + create mode 100644 clang/test/CodeGen/LoongArch/builtin-flt-approximate.c + create mode 100644 clang/test/CodeGen/LoongArch/lasx/builtin-approximate-alias.c + create mode 100644 clang/test/CodeGen/LoongArch/lasx/builtin-approximate.c + create mode 100644 clang/test/CodeGen/LoongArch/lsx/builtin-approximate-alias.c + create mode 100644 clang/test/CodeGen/LoongArch/lsx/builtin-approximate.c + +diff --git a/clang/include/clang/Basic/BuiltinsLoongArchBase.def b/clang/include/clang/Basic/BuiltinsLoongArchBase.def +index cbb239223aae..a5a07c167908 100644 +--- a/clang/include/clang/Basic/BuiltinsLoongArchBase.def ++++ b/clang/include/clang/Basic/BuiltinsLoongArchBase.def +@@ -51,3 +51,8 @@ TARGET_BUILTIN(__builtin_loongarch_iocsrwr_d, "vUWiUi", "nc", "64bit") + + TARGET_BUILTIN(__builtin_loongarch_lddir_d, "WiWiIUWi", "nc", "64bit") + TARGET_BUILTIN(__builtin_loongarch_ldpte_d, "vWiIUWi", "nc", "64bit") ++ ++TARGET_BUILTIN(__builtin_loongarch_frecipe_s, "ff", "nc", "f,frecipe") ++TARGET_BUILTIN(__builtin_loongarch_frecipe_d, "dd", "nc", "d,frecipe") ++TARGET_BUILTIN(__builtin_loongarch_frsqrte_s, "ff", "nc", "f,frecipe") ++TARGET_BUILTIN(__builtin_loongarch_frsqrte_d, "dd", "nc", "d,frecipe") +diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +index 3de200f665b6..4cf51cc000f6 100644 +--- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def ++++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +@@ -657,9 +657,15 @@ TARGET_BUILTIN(__builtin_lasx_xvfsqrt_d, "V4dV4d", "nc", "lasx") + TARGET_BUILTIN(__builtin_lasx_xvfrecip_s, "V8fV8f", "nc", "lasx") + TARGET_BUILTIN(__builtin_lasx_xvfrecip_d, "V4dV4d", "nc", "lasx") + ++TARGET_BUILTIN(__builtin_lasx_xvfrecipe_s, "V8fV8f", "nc", "lasx,frecipe") ++TARGET_BUILTIN(__builtin_lasx_xvfrecipe_d, "V4dV4d", "nc", "lasx,frecipe") ++ + TARGET_BUILTIN(__builtin_lasx_xvfrsqrt_s, "V8fV8f", "nc", "lasx") + TARGET_BUILTIN(__builtin_lasx_xvfrsqrt_d, "V4dV4d", "nc", "lasx") + ++TARGET_BUILTIN(__builtin_lasx_xvfrsqrte_s, "V8fV8f", "nc", "lasx,frecipe") ++TARGET_BUILTIN(__builtin_lasx_xvfrsqrte_d, "V4dV4d", "nc", "lasx,frecipe") ++ + TARGET_BUILTIN(__builtin_lasx_xvfcvtl_s_h, "V8fV16s", "nc", "lasx") + TARGET_BUILTIN(__builtin_lasx_xvfcvth_s_h, "V8fV16s", "nc", "lasx") + TARGET_BUILTIN(__builtin_lasx_xvfcvtl_d_s, "V4dV8f", "nc", "lasx") +diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +index 8e6aec886c50..c90f4dc5458f 100644 +--- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def ++++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +@@ -641,9 +641,15 @@ TARGET_BUILTIN(__builtin_lsx_vfsqrt_d, "V2dV2d", "nc", "lsx") + TARGET_BUILTIN(__builtin_lsx_vfrecip_s, "V4fV4f", "nc", "lsx") + TARGET_BUILTIN(__builtin_lsx_vfrecip_d, "V2dV2d", "nc", "lsx") + ++TARGET_BUILTIN(__builtin_lsx_vfrecipe_s, "V4fV4f", "nc", "lsx,frecipe") ++TARGET_BUILTIN(__builtin_lsx_vfrecipe_d, "V2dV2d", "nc", "lsx,frecipe") ++ + TARGET_BUILTIN(__builtin_lsx_vfrsqrt_s, "V4fV4f", "nc", "lsx") + TARGET_BUILTIN(__builtin_lsx_vfrsqrt_d, "V2dV2d", "nc", "lsx") + ++TARGET_BUILTIN(__builtin_lsx_vfrsqrte_s, "V4fV4f", "nc", "lsx,frecipe") ++TARGET_BUILTIN(__builtin_lsx_vfrsqrte_d, "V2dV2d", "nc", "lsx,frecipe") ++ + TARGET_BUILTIN(__builtin_lsx_vfcvtl_s_h, "V4fV8s", "nc", "lsx") + TARGET_BUILTIN(__builtin_lsx_vfcvtl_d_s, "V2dV4f", "nc", "lsx") + +diff --git a/clang/lib/Headers/larchintrin.h b/clang/lib/Headers/larchintrin.h +index 24dd29ce91ff..f4218295919a 100644 +--- a/clang/lib/Headers/larchintrin.h ++++ b/clang/lib/Headers/larchintrin.h +@@ -228,6 +228,18 @@ extern __inline void + ((void)__builtin_loongarch_ldpte_d((long int)(_1), (_2))) + #endif + ++#define __frecipe_s(/*float*/ _1) \ ++ (float)__builtin_loongarch_frecipe_s((float)_1) ++ ++#define __frecipe_d(/*double*/ _1) \ ++ (double)__builtin_loongarch_frecipe_d((double)_1) ++ ++#define __frsqrte_s(/*float*/ _1) \ ++ (float)__builtin_loongarch_frsqrte_s((float)_1) ++ ++#define __frsqrte_d(/*double*/ _1) \ ++ (double)__builtin_loongarch_frsqrte_d((double)_1) ++ + #ifdef __cplusplus + } + #endif +diff --git a/clang/lib/Headers/lasxintrin.h b/clang/lib/Headers/lasxintrin.h +index 6b4d5012a24b..dafc2a2f3e6a 100644 +--- a/clang/lib/Headers/lasxintrin.h ++++ b/clang/lib/Headers/lasxintrin.h +@@ -1726,6 +1726,18 @@ extern __inline + return (__m256d)__builtin_lasx_xvfrecip_d((v4f64)_1); + } + ++extern __inline ++ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256 ++ __lasx_xvfrecipe_s(__m256 _1) { ++ return (__m256)__builtin_lasx_xvfrecipe_s((v8f32)_1); ++} ++ ++extern __inline ++ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d ++ __lasx_xvfrecipe_d(__m256d _1) { ++ return (__m256d)__builtin_lasx_xvfrecipe_d((v4f64)_1); ++} ++ + extern __inline + __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256 + __lasx_xvfrint_s(__m256 _1) { +@@ -1750,6 +1762,18 @@ extern __inline + return (__m256d)__builtin_lasx_xvfrsqrt_d((v4f64)_1); + } + ++extern __inline ++ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256 ++ __lasx_xvfrsqrte_s(__m256 _1) { ++ return (__m256)__builtin_lasx_xvfrsqrte_s((v8f32)_1); ++} ++ ++extern __inline ++ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256d ++ __lasx_xvfrsqrte_d(__m256d _1) { ++ return (__m256d)__builtin_lasx_xvfrsqrte_d((v4f64)_1); ++} ++ + extern __inline + __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256 + __lasx_xvflogb_s(__m256 _1) { +diff --git a/clang/lib/Headers/lsxintrin.h b/clang/lib/Headers/lsxintrin.h +index a29bc7757ab5..f347955ce6fb 100644 +--- a/clang/lib/Headers/lsxintrin.h ++++ b/clang/lib/Headers/lsxintrin.h +@@ -1776,6 +1776,18 @@ extern __inline + return (__m128d)__builtin_lsx_vfrecip_d((v2f64)_1); + } + ++extern __inline ++ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m128 ++ __lsx_vfrecipe_s(__m128 _1) { ++ return (__m128)__builtin_lsx_vfrecipe_s((v4f32)_1); ++} ++ ++extern __inline ++ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m128d ++ __lsx_vfrecipe_d(__m128d _1) { ++ return (__m128d)__builtin_lsx_vfrecipe_d((v2f64)_1); ++} ++ + extern __inline + __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m128 + __lsx_vfrint_s(__m128 _1) { +@@ -1800,6 +1812,18 @@ extern __inline + return (__m128d)__builtin_lsx_vfrsqrt_d((v2f64)_1); + } + ++extern __inline ++ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m128 ++ __lsx_vfrsqrte_s(__m128 _1) { ++ return (__m128)__builtin_lsx_vfrsqrte_s((v4f32)_1); ++} ++ ++extern __inline ++ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m128d ++ __lsx_vfrsqrte_d(__m128d _1) { ++ return (__m128d)__builtin_lsx_vfrsqrte_d((v2f64)_1); ++} ++ + extern __inline + __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m128 + __lsx_vflogb_s(__m128 _1) { +diff --git a/clang/test/CodeGen/LoongArch/builtin-dbl-approximate.c b/clang/test/CodeGen/LoongArch/builtin-dbl-approximate.c +new file mode 100644 +index 000000000000..e5fe684346c0 +--- /dev/null ++++ b/clang/test/CodeGen/LoongArch/builtin-dbl-approximate.c +@@ -0,0 +1,45 @@ ++// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 ++// RUN: %clang_cc1 -triple loongarch32 -target-feature +d -target-feature +frecipe -O2 -emit-llvm %s -o - | FileCheck %s ++// RUN: %clang_cc1 -triple loongarch64 -target-feature +d -target-feature +frecipe -O2 -emit-llvm %s -o - | FileCheck %s ++ ++#include <larchintrin.h> ++ ++// CHECK-LABEL: @frecipe_d ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = tail call double @llvm.loongarch.frecipe.d(double A:%.*) ++// CHECK-NEXT: ret double TMP0 ++// ++double frecipe_d (double _1) ++{ ++ return __builtin_loongarch_frecipe_d (_1); ++} ++ ++// CHECK-LABEL: @frsqrte_d ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = tail call double @llvm.loongarch.frsqrte.d(double A:%.*) ++// CHECK-NEXT: ret double TMP0 ++// ++double frsqrte_d (double _1) ++{ ++ return __builtin_loongarch_frsqrte_d (_1); ++} ++ ++// CHECK-LABEL: @frecipe_d_alia ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = tail call double @llvm.loongarch.frecipe.d(double A:%.*) ++// CHECK-NEXT: ret double TMP0 ++// ++double frecipe_d_alia (double _1) ++{ ++ return __frecipe_d (_1); ++} ++ ++// CHECK-LABEL: @frsqrte_d_alia ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = tail call double @llvm.loongarch.frsqrte.d(double A:%.*) ++// CHECK-NEXT: ret double TMP0 ++// ++double frsqrte_d_alia (double _1) ++{ ++ return __frsqrte_d (_1); ++} +diff --git a/clang/test/CodeGen/LoongArch/builtin-flt-approximate.c b/clang/test/CodeGen/LoongArch/builtin-flt-approximate.c +new file mode 100644 +index 000000000000..47bb47084364 +--- /dev/null ++++ b/clang/test/CodeGen/LoongArch/builtin-flt-approximate.c +@@ -0,0 +1,45 @@ ++// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 ++// RUN: %clang_cc1 -triple loongarch32 -target-feature +f -target-feature +frecipe -O2 -emit-llvm %s -o - | FileCheck %s ++// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +frecipe -O2 -emit-llvm %s -o - | FileCheck %s ++ ++#include <larchintrin.h> ++ ++// CHECK-LABEL: @frecipe_s ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = tail call float @llvm.loongarch.frecipe.s(float A:%.*) ++// CHECK-NEXT: ret float TMP0 ++// ++float frecipe_s (float _1) ++{ ++ return __builtin_loongarch_frecipe_s (_1); ++} ++ ++// CHECK-LABEL: @frsqrte_s ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = tail call float @llvm.loongarch.frsqrte.s(float A:%.*) ++// CHECK-NEXT: ret float TMP0 ++// ++float frsqrte_s (float _1) ++{ ++ return __builtin_loongarch_frsqrte_s (_1); ++} ++ ++// CHECK-LABEL: @frecipe_s_alia ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = tail call float @llvm.loongarch.frecipe.s(float A:%.*) ++// CHECK-NEXT: ret float TMP0 ++// ++float frecipe_s_alia (float _1) ++{ ++ return __frecipe_s (_1); ++} ++ ++// CHECK-LABEL: @frsqrte_s_alia ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = tail call float @llvm.loongarch.frsqrte.s(float A:%.*) ++// CHECK-NEXT: ret float TMP0 ++// ++float frsqrte_s_alia (float _1) ++{ ++ return __frsqrte_s (_1); ++} +diff --git a/clang/test/CodeGen/LoongArch/intrinsic-la64-error.c b/clang/test/CodeGen/LoongArch/intrinsic-la64-error.c +index efb3b94175cf..a3242dfd41e9 100644 +--- a/clang/test/CodeGen/LoongArch/intrinsic-la64-error.c ++++ b/clang/test/CodeGen/LoongArch/intrinsic-la64-error.c +@@ -1,7 +1,28 @@ + // RUN: %clang_cc1 -triple loongarch64 -emit-llvm -S -verify %s -o /dev/null ++// RUN: not %clang_cc1 -triple loongarch64 -DFEATURE_CHECK -emit-llvm %s -o /dev/null 2>&1 \ ++// RUN: | FileCheck %s + + #include <larchintrin.h> + ++#ifdef FEATURE_CHECK ++void test_feature(unsigned long *v_ul, int *v_i, float a, double b) { ++// CHECK: error: '__builtin_loongarch_cacop_w' needs target feature 32bit ++ __builtin_loongarch_cacop_w(1, v_ul0, 1024); ++// CHECK: error: '__builtin_loongarch_movfcsr2gr' needs target feature f ++ v_i0 = __builtin_loongarch_movfcsr2gr(1); ++// CHECK: error: '__builtin_loongarch_movgr2fcsr' needs target feature f ++ __builtin_loongarch_movgr2fcsr(1, v_i1); ++// CHECK: error: '__builtin_loongarch_frecipe_s' needs target feature f,frecipe ++ float f1 = __builtin_loongarch_frecipe_s(a); ++// CHECK: error: '__builtin_loongarch_frsqrte_s' needs target feature f,frecipe ++ float f2 = __builtin_loongarch_frsqrte_s(a); ++// CHECK: error: '__builtin_loongarch_frecipe_d' needs target feature d,frecipe ++ double d1 = __builtin_loongarch_frecipe_d(b); ++// CHECK: error: '__builtin_loongarch_frsqrte_d' needs target feature d,frecipe ++ double d2 = __builtin_loongarch_frsqrte_d(b); ++} ++#endif ++ + void csrrd_d(int a) { + __builtin_loongarch_csrrd_d(16384); // expected-error {{argument value 16384 is outside the valid range 0, 16383}} + __builtin_loongarch_csrrd_d(-1); // expected-error {{argument value 4294967295 is outside the valid range 0, 16383}} +diff --git a/clang/test/CodeGen/LoongArch/lasx/builtin-approximate-alias.c b/clang/test/CodeGen/LoongArch/lasx/builtin-approximate-alias.c +new file mode 100644 +index 000000000000..b79f93940399 +--- /dev/null ++++ b/clang/test/CodeGen/LoongArch/lasx/builtin-approximate-alias.c +@@ -0,0 +1,37 @@ ++// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py ++// RUN: %clang_cc1 -triple loongarch64 -target-feature +lasx -target-feature +frecipe -O2 -emit-llvm %s -o - | FileCheck %s ++ ++#include <lasxintrin.h> ++ ++// CHECK-LABEL: @xvfrecipe_s( ++// CHECK-NEXT: entry: ++// CHECK-NEXT: _1:%.* = load <8 x float>, ptr TMP0:%.*, align 32, !tbaa TBAA2:!0-9+ ++// CHECK-NEXT: TMP1:%.* = tail call <8 x float> @llvm.loongarch.lasx.xvfrecipe.s(<8 x float> _1) ++// CHECK-NEXT: store <8 x float> TMP1, ptr AGG_RESULT:%.*, align 32, !tbaa TBAA2 ++// CHECK-NEXT: ret void ++// ++v8f32 xvfrecipe_s(v8f32 _1) { return __lasx_xvfrecipe_s(_1); } ++// CHECK-LABEL: @xvfrecipe_d( ++// CHECK-NEXT: entry: ++// CHECK-NEXT: _1:%.* = load <4 x double>, ptr TMP0:%.*, align 32, !tbaa TBAA2:!0-9+ ++// CHECK-NEXT: TMP1:%.* = tail call <4 x double> @llvm.loongarch.lasx.xvfrecipe.d(<4 x double> _1) ++// CHECK-NEXT: store <4 x double> TMP1, ptr AGG_RESULT:%.*, align 32, !tbaa TBAA2 ++// CHECK-NEXT: ret void ++// ++v4f64 xvfrecipe_d(v4f64 _1) { return __lasx_xvfrecipe_d(_1); } ++// CHECK-LABEL: @xvfrsqrte_s( ++// CHECK-NEXT: entry: ++// CHECK-NEXT: _1:%.* = load <8 x float>, ptr TMP0:%.*, align 32, !tbaa TBAA2:!0-9+ ++// CHECK-NEXT: TMP1:%.* = tail call <8 x float> @llvm.loongarch.lasx.xvfrsqrte.s(<8 x float> _1) ++// CHECK-NEXT: store <8 x float> TMP1, ptr AGG_RESULT:%.*, align 32, !tbaa TBAA2 ++// CHECK-NEXT: ret void ++// ++v8f32 xvfrsqrte_s(v8f32 _1) { return __lasx_xvfrsqrte_s(_1); } ++// CHECK-LABEL: @xvfrsqrte_d( ++// CHECK-NEXT: entry: ++// CHECK-NEXT: _1:%.* = load <4 x double>, ptr TMP0:%.*, align 32, !tbaa TBAA2:!0-9+ ++// CHECK-NEXT: TMP1:%.* = tail call <4 x double> @llvm.loongarch.lasx.xvfrsqrte.d(<4 x double> _1) ++// CHECK-NEXT: store <4 x double> TMP1, ptr AGG_RESULT:%.*, align 32, !tbaa TBAA2 ++// CHECK-NEXT: ret void ++// ++v4f64 xvfrsqrte_d(v4f64 _1) { return __lasx_xvfrsqrte_d(_1); } +diff --git a/clang/test/CodeGen/LoongArch/lasx/builtin-approximate.c b/clang/test/CodeGen/LoongArch/lasx/builtin-approximate.c +new file mode 100644 +index 000000000000..63e9ba639ea2 +--- /dev/null ++++ b/clang/test/CodeGen/LoongArch/lasx/builtin-approximate.c +@@ -0,0 +1,38 @@ ++// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py ++// RUN: %clang_cc1 -triple loongarch64 -target-feature +lasx -target-feature +frecipe -O2 -emit-llvm %s -o - | FileCheck %s ++ ++typedef float v8f32 __attribute__((vector_size(32), aligned(32))); ++typedef double v4f64 __attribute__((vector_size(32), aligned(32))); ++ ++// CHECK-LABEL: @xvfrecipe_s ++// CHECK-NEXT: entry: ++// CHECK-NEXT: _1:%.* = load <8 x float>, ptr TMP0:%.*, align 32, !tbaa TBAA2:!0-9+ ++// CHECK-NEXT: TMP1:%.* = tail call <8 x float> @llvm.loongarch.lasx.xvfrecipe.s(<8 x float> _1) ++// CHECK-NEXT: store <8 x float> TMP1, ptr AGG_RESULT:%.*, align 32, !tbaa TBAA2 ++// CHECK-NEXT: ret void ++// ++v8f32 xvfrecipe_s(v8f32 _1) { return __builtin_lasx_xvfrecipe_s(_1); } ++// CHECK-LABEL: @xvfrecipe_d ++// CHECK-NEXT: entry: ++// CHECK-NEXT: _1:%.* = load <4 x double>, ptr TMP0:%.*, align 32, !tbaa TBAA2:!0-9+ ++// CHECK-NEXT: TMP1:%.* = tail call <4 x double> @llvm.loongarch.lasx.xvfrecipe.d(<4 x double> _1) ++// CHECK-NEXT: store <4 x double> TMP1, ptr AGG_RESULT:%.*, align 32, !tbaa TBAA2 ++// CHECK-NEXT: ret void ++// ++v4f64 xvfrecipe_d(v4f64 _1) { return __builtin_lasx_xvfrecipe_d(_1); } ++// CHECK-LABEL: @xvfrsqrte_s ++// CHECK-NEXT: entry: ++// CHECK-NEXT: _1:%.* = load <8 x float>, ptr TMP0:%.*, align 32, !tbaa TBAA2:!0-9+ ++// CHECK-NEXT: TMP1:%.* = tail call <8 x float> @llvm.loongarch.lasx.xvfrsqrte.s(<8 x float> _1) ++// CHECK-NEXT: store <8 x float> TMP1, ptr AGG_RESULT:%.*, align 32, !tbaa TBAA2 ++// CHECK-NEXT: ret void ++// ++v8f32 xvfrsqrte_s(v8f32 _1) { return __builtin_lasx_xvfrsqrte_s(_1); } ++// CHECK-LABEL: @xvfrsqrte_d ++// CHECK-NEXT: entry: ++// CHECK-NEXT: _1:%.* = load <4 x double>, ptr TMP0:%.*, align 32, !tbaa TBAA2:!0-9+ ++// CHECK-NEXT: TMP1:%.* = tail call <4 x double> @llvm.loongarch.lasx.xvfrsqrte.d(<4 x double> _1) ++// CHECK-NEXT: store <4 x double> TMP1, ptr AGG_RESULT:%.*, align 32, !tbaa TBAA2 ++// CHECK-NEXT: ret void ++// ++v4f64 xvfrsqrte_d(v4f64 _1) { return __builtin_lasx_xvfrsqrte_d(_1); } +diff --git a/clang/test/CodeGen/LoongArch/lsx/builtin-approximate-alias.c b/clang/test/CodeGen/LoongArch/lsx/builtin-approximate-alias.c +new file mode 100644 +index 000000000000..f26f032c878e +--- /dev/null ++++ b/clang/test/CodeGen/LoongArch/lsx/builtin-approximate-alias.c +@@ -0,0 +1,37 @@ ++// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py ++// RUN: %clang_cc1 -triple loongarch64 -target-feature +lsx -target-feature +frecipe -O2 -emit-llvm %s -o - | FileCheck %s ++ ++#include <lsxintrin.h> ++ ++// CHECK-LABEL: @vfrecipe_s( ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = bitcast i128 _1_COERCE:%.* to <4 x float> ++// CHECK-NEXT: TMP1:%.* = tail call <4 x float> @llvm.loongarch.lsx.vfrecipe.s(<4 x float> TMP0) ++// CHECK-NEXT: TMP2:%.* = bitcast <4 x float> TMP1 to i128 ++// CHECK-NEXT: ret i128 TMP2 ++// ++v4f32 vfrecipe_s(v4f32 _1) { return __lsx_vfrecipe_s(_1); } ++// CHECK-LABEL: @vfrecipe_d( ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = bitcast i128 _1_COERCE:%.* to <2 x double> ++// CHECK-NEXT: TMP1:%.* = tail call <2 x double> @llvm.loongarch.lsx.vfrecipe.d(<2 x double> TMP0) ++// CHECK-NEXT: TMP2:%.* = bitcast <2 x double> TMP1 to i128 ++// CHECK-NEXT: ret i128 TMP2 ++// ++v2f64 vfrecipe_d(v2f64 _1) { return __lsx_vfrecipe_d(_1); } ++// CHECK-LABEL: @vfrsqrte_s( ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = bitcast i128 _1_COERCE:%.* to <4 x float> ++// CHECK-NEXT: TMP1:%.* = tail call <4 x float> @llvm.loongarch.lsx.vfrsqrte.s(<4 x float> TMP0) ++// CHECK-NEXT: TMP2:%.* = bitcast <4 x float> TMP1 to i128 ++// CHECK-NEXT: ret i128 TMP2 ++// ++v4f32 vfrsqrte_s(v4f32 _1) { return __lsx_vfrsqrte_s(_1); } ++// CHECK-LABEL: @vfrsqrte_d( ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = bitcast i128 _1_COERCE:%.* to <2 x double> ++// CHECK-NEXT: TMP1:%.* = tail call <2 x double> @llvm.loongarch.lsx.vfrsqrte.d(<2 x double> TMP0) ++// CHECK-NEXT: TMP2:%.* = bitcast <2 x double> TMP1 to i128 ++// CHECK-NEXT: ret i128 TMP2 ++// ++v2f64 vfrsqrte_d(v2f64 _1) { return __lsx_vfrsqrte_d(_1); } +diff --git a/clang/test/CodeGen/LoongArch/lsx/builtin-approximate.c b/clang/test/CodeGen/LoongArch/lsx/builtin-approximate.c +new file mode 100644 +index 000000000000..39fa1663db34 +--- /dev/null ++++ b/clang/test/CodeGen/LoongArch/lsx/builtin-approximate.c +@@ -0,0 +1,38 @@ ++// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py ++// RUN: %clang_cc1 -triple loongarch64 -target-feature +lsx -target-feature +frecipe -O2 -emit-llvm %s -o - | FileCheck %s ++ ++typedef float v4f32 __attribute__ ((vector_size(16), aligned(16))); ++typedef double v2f64 __attribute__ ((vector_size(16), aligned(16))); ++ ++// CHECK-LABEL: @vfrecipe_s ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = bitcast i128 _1_COERCE:%.* to <4 x float> ++// CHECK-NEXT: TMP1:%.* = tail call <4 x float> @llvm.loongarch.lsx.vfrecipe.s(<4 x float> TMP0) ++// CHECK-NEXT: TMP2:%.* = bitcast <4 x float> TMP1 to i128 ++// CHECK-NEXT: ret i128 TMP2 ++// ++v4f32 vfrecipe_s (v4f32 _1) { return __builtin_lsx_vfrecipe_s (_1); } ++// CHECK-LABEL: @vfrecipe_d ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = bitcast i128 _1_COERCE:%.* to <2 x double> ++// CHECK-NEXT: TMP1:%.* = tail call <2 x double> @llvm.loongarch.lsx.vfrecipe.d(<2 x double> TMP0) ++// CHECK-NEXT: TMP2:%.* = bitcast <2 x double> TMP1 to i128 ++// CHECK-NEXT: ret i128 TMP2 ++// ++v2f64 vfrecipe_d (v2f64 _1) { return __builtin_lsx_vfrecipe_d (_1); } ++// CHECK-LABEL: @vfrsqrte_s ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = bitcast i128 _1_COERCE:%.* to <4 x float> ++// CHECK-NEXT: TMP1:%.* = tail call <4 x float> @llvm.loongarch.lsx.vfrsqrte.s(<4 x float> TMP0) ++// CHECK-NEXT: TMP2:%.* = bitcast <4 x float> TMP1 to i128 ++// CHECK-NEXT: ret i128 TMP2 ++// ++v4f32 vfrsqrte_s (v4f32 _1) { return __builtin_lsx_vfrsqrte_s (_1); } ++// CHECK-LABEL: @vfrsqrte_d ++// CHECK-NEXT: entry: ++// CHECK-NEXT: TMP0:%.* = bitcast i128 _1_COERCE:%.* to <2 x double> ++// CHECK-NEXT: TMP1:%.* = tail call <2 x double> @llvm.loongarch.lsx.vfrsqrte.d(<2 x double> TMP0) ++// CHECK-NEXT: TMP2:%.* = bitcast <2 x double> TMP1 to i128 ++// CHECK-NEXT: ret i128 TMP2 ++// ++v2f64 vfrsqrte_d (v2f64 _1) { return __builtin_lsx_vfrsqrte_d (_1); } +-- +2.20.1 + + +From 6f9531b069971dc0f5c6b28bd6a6754c1b5fde72 Mon Sep 17 00:00:00 2001 +From: Ami-zhang <zhanglimin@loongson.cn> +Date: Tue, 23 Jul 2024 14:03:28 +0800 +Subject: PATCH 7/9 LoongArch Support -march=la64v1.0 and -march=la64v1.1 + (#100057) + +The newly added strings `la64v1.0` and `la64v1.1` in `-march` are as +described in LoongArch toolchains conventions (see 1). + +The target-cpu/feature attributes are forwarded to compiler when +specifying particular `-march` parameter. The default cpu `loongarch64` +is returned when archname is `la64v1.0` or `la64v1.1`. + +In addition, this commit adds `la64v1.0`/`la64v1.1` to +"__loongarch_arch" and adds definition for macro "__loongarch_frecipe". + +1: https://github.com/loongson/la-toolchain-conventions + +(cherry picked from commit 5a1b9896ad5a7dcd25a1cc7a4d3fd44155e4b22d) +--- + clang/lib/Basic/Targets/LoongArch.cpp | 23 +++++++++++++++- + clang/lib/Basic/Targets/LoongArch.h | 2 ++ + .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 10 +++++-- + clang/test/Driver/loongarch-march.c | 22 +++++++++++++++ + clang/test/Preprocessor/init-loongarch.c | 27 ++++++++++++++++--- + 5 files changed, 77 insertions(+), 7 deletions(-) + +diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp +index 913404240916..5fede3d7cdc4 100644 +--- a/clang/lib/Basic/Targets/LoongArch.cpp ++++ b/clang/lib/Basic/Targets/LoongArch.cpp +@@ -200,7 +200,24 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, + + // Define __loongarch_arch. + StringRef ArchName = getCPU(); +- Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + Twine('"')); ++ if (ArchName == "loongarch64") { ++ if (HasFeatureLSX) { ++ // TODO: As more features of the V1.1 ISA are supported, a unified "v1.1" ++ // arch feature set will be used to include all sub-features belonging to ++ // the V1.1 ISA version. ++ if (HasFeatureFrecipe) ++ Builder.defineMacro("__loongarch_arch", ++ Twine('"') + "la64v1.1" + Twine('"')); ++ else ++ Builder.defineMacro("__loongarch_arch", ++ Twine('"') + "la64v1.0" + Twine('"')); ++ } else { ++ Builder.defineMacro("__loongarch_arch", ++ Twine('"') + ArchName + Twine('"')); ++ } ++ } else { ++ Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + Twine('"')); ++ } + + // Define __loongarch_tune. + StringRef TuneCPU = getTargetOpts().TuneCPU; +@@ -216,6 +233,8 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, + Builder.defineMacro("__loongarch_simd_width", "128"); + Builder.defineMacro("__loongarch_sx", Twine(1)); + } ++ if (HasFeatureFrecipe) ++ Builder.defineMacro("__loongarch_frecipe", Twine(1)); + + StringRef ABI = getABI(); + if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s") +@@ -289,6 +308,8 @@ bool LoongArchTargetInfo::handleTargetFeatures( + HasFeatureLSX = true; + else if (Feature == "+lasx") + HasFeatureLASX = true; ++ else if (Feature == "+frecipe") ++ HasFeatureFrecipe = true; + } + return true; + } +diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h +index 3313102492cb..4d2965f5b3a3 100644 +--- a/clang/lib/Basic/Targets/LoongArch.h ++++ b/clang/lib/Basic/Targets/LoongArch.h +@@ -29,6 +29,7 @@ protected: + bool HasFeatureF; + bool HasFeatureLSX; + bool HasFeatureLASX; ++ bool HasFeatureFrecipe; + + public: + LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &) +@@ -37,6 +38,7 @@ public: + HasFeatureF = false; + HasFeatureLSX = false; + HasFeatureLASX = false; ++ HasFeatureFrecipe = false; + LongDoubleWidth = 128; + LongDoubleAlign = 128; + LongDoubleFormat = &llvm::APFloat::IEEEquad(); +diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +index 87d7b30ef5d3..21106c425206 100644 +--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp ++++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +@@ -268,8 +268,14 @@ std::string loongarch::postProcessTargetCPUString(const std::string &CPU, + std::string loongarch::getLoongArchTargetCPU(const llvm::opt::ArgList &Args, + const llvm::Triple &Triple) { + std::string CPU; ++ std::string Arch; + // If we have -march, use that. +- if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) +- CPU = A->getValue(); ++ if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { ++ Arch = A->getValue(); ++ if (Arch == "la64v1.0" || Arch == "la64v1.1") ++ CPU = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64()); ++ else ++ CPU = Arch; ++ } + return postProcessTargetCPUString(CPU, Triple); + } +diff --git a/clang/test/Driver/loongarch-march.c b/clang/test/Driver/loongarch-march.c +index 9214130cd034..d06da72a755c 100644 +--- a/clang/test/Driver/loongarch-march.c ++++ b/clang/test/Driver/loongarch-march.c +@@ -2,10 +2,18 @@ + // RUN: FileCheck %s --check-prefix=CC1-LOONGARCH64 + // RUN: %clang --target=loongarch64 -march=la464 -fsyntax-only %s -### 2>&1 | \ + // RUN: FileCheck %s --check-prefix=CC1-LA464 ++// RUN: %clang --target=loongarch64 -march=la64v1.0 -fsyntax-only %s -### 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=CC1-LA64V1P0 ++// RUN: %clang --target=loongarch64 -march=la64v1.1 -fsyntax-only %s -### 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=CC1-LA64V1P1 + // RUN: %clang --target=loongarch64 -march=loongarch64 -S -emit-llvm %s -o - | \ + // RUN: FileCheck %s --check-prefix=IR-LOONGARCH64 + // RUN: %clang --target=loongarch64 -march=la464 -S -emit-llvm %s -o - | \ + // RUN: FileCheck %s --check-prefix=IR-LA464 ++// RUN: %clang --target=loongarch64 -march=la64v1.0 -S -emit-llvm %s -o - | \ ++// RUN: FileCheck %s --check-prefix=IR-LA64V1P0 ++// RUN: %clang --target=loongarch64 -march=la64v1.1 -S -emit-llvm %s -o - | \ ++// RUN: FileCheck %s --check-prefix=IR-LA64V1P1 + + // CC1-LOONGARCH64: "-target-cpu" "loongarch64" + // CC1-LOONGARCH64-NOT: "-target-feature" +@@ -19,8 +27,22 @@ + // CC1-LA464-NOT: "-target-feature" + // CC1-LA464: "-target-abi" "lp64d" + ++// CC1-LA64V1P0: "-target-cpu" "loongarch64" ++// CC1-LA64V1P0-NOT: "-target-feature" ++// CC1-LA64V1P0: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" ++// CC1-LA64V1P0-NOT: "-target-feature" ++// CC1-LA64V1P0: "-target-abi" "lp64d" ++ ++// CC1-LA64V1P1: "-target-cpu" "loongarch64" ++// CC1-LA64V1P1-NOT: "-target-feature" ++// CC1-LA64V1P1: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" "-target-feature" "+frecipe" ++// CC1-LA64V1P1-NOT: "-target-feature" ++// CC1-LA64V1P1: "-target-abi" "lp64d" ++ + // IR-LOONGARCH64: attributes ## ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+f,+ual" + // IR-LA464: attributes ## ={{.*}}"target-cpu"="la464" {{.*}}"target-features"="+64bit,+d,+f,+lasx,+lsx,+ual" ++// IR-LA64V1P0: attributes ## ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+lsx,+ual" ++// IR-LA64V1P1: attributes ## ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+frecipe,+lsx,+ual" + + int foo(void) { + return 3; +diff --git a/clang/test/Preprocessor/init-loongarch.c b/clang/test/Preprocessor/init-loongarch.c +index 635d029ce9d3..cfa3ddb20f10 100644 +--- a/clang/test/Preprocessor/init-loongarch.c ++++ b/clang/test/Preprocessor/init-loongarch.c +@@ -788,24 +788,43 @@ + // LA64-FPU0-LP64S-NOT: #define __loongarch_single_float + // LA64-FPU0-LP64S: #define __loongarch_soft_float 1 + +-/// Check __loongarch_arch and __loongarch_tune. ++/// Check __loongarch_arch{_tune/_frecipe}. + + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - | \ +-// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=loongarch64 %s ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 | \ + // RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=loongarch64 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la464 | \ + // RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la464 -DTUNE=la464 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=loongarch64 | \ +-// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=loongarch64 %s ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=la464 | \ +-// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la464 %s ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=la464 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -mtune=la464 | \ + // RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la464 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la464 -mtune=loongarch64 | \ + // RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la464 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 | \ ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang -lsx | \ ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang +frecipe | \ ++// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.1 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx | \ ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 | \ ++// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.1 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -frecipe | \ ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -lsx | \ ++// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=loongarch64 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +frecipe | \ ++// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=loongarch64 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx -Xclang -target-feature -Xclang +frecipe | \ ++// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.1 -DTUNE=loongarch64 %s + + // ARCH-TUNE: #define __loongarch_arch "ARCH" ++// FRECIPE: #define __loongarch_frecipe 1 + // ARCH-TUNE: #define __loongarch_tune "TUNE" + + // RUN: %clang --target=loongarch64 -mlsx -x c -E -dM %s -o - \ +-- +2.20.1 + + +From 6094875aa6aab1e28a096294783cada0243e95d5 Mon Sep 17 00:00:00 2001 +From: Ami-zhang <zhanglimin@loongson.cn> +Date: Tue, 23 Jul 2024 15:14:20 +0800 +Subject: PATCH 8/9 LoongArch Support la664 (#100068) + +A new ProcessorModel called `la664` is defined in LoongArch.td to +support `-march/-mtune=la664`. + +(cherry picked from commit fcec298087dba0c83f6d0bbafd6cd934c42cbf82) +--- + clang/test/Driver/loongarch-march.c | 11 +++++++++++ + clang/test/Driver/loongarch-mtune.c | 5 +++++ + clang/test/Preprocessor/init-loongarch.c | 8 ++++++++ + 3 files changed, 24 insertions(+) + +diff --git a/clang/test/Driver/loongarch-march.c b/clang/test/Driver/loongarch-march.c +index d06da72a755c..2d5b315d962a 100644 +--- a/clang/test/Driver/loongarch-march.c ++++ b/clang/test/Driver/loongarch-march.c +@@ -6,6 +6,8 @@ + // RUN: FileCheck %s --check-prefix=CC1-LA64V1P0 + // RUN: %clang --target=loongarch64 -march=la64v1.1 -fsyntax-only %s -### 2>&1 | \ + // RUN: FileCheck %s --check-prefix=CC1-LA64V1P1 ++// RUN: %clang --target=loongarch64 -march=la664 -fsyntax-only %s -### 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=CC1-LA664 + // RUN: %clang --target=loongarch64 -march=loongarch64 -S -emit-llvm %s -o - | \ + // RUN: FileCheck %s --check-prefix=IR-LOONGARCH64 + // RUN: %clang --target=loongarch64 -march=la464 -S -emit-llvm %s -o - | \ +@@ -14,6 +16,8 @@ + // RUN: FileCheck %s --check-prefix=IR-LA64V1P0 + // RUN: %clang --target=loongarch64 -march=la64v1.1 -S -emit-llvm %s -o - | \ + // RUN: FileCheck %s --check-prefix=IR-LA64V1P1 ++// RUN: %clang --target=loongarch64 -march=la664 -S -emit-llvm %s -o - | \ ++// RUN: FileCheck %s --check-prefix=IR-LA664 + + // CC1-LOONGARCH64: "-target-cpu" "loongarch64" + // CC1-LOONGARCH64-NOT: "-target-feature" +@@ -39,10 +43,17 @@ + // CC1-LA64V1P1-NOT: "-target-feature" + // CC1-LA64V1P1: "-target-abi" "lp64d" + ++// CC1-LA664: "-target-cpu" "la664" ++// CC1-LA664-NOT: "-target-feature" ++// CC1-LA664: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" "-target-feature" "+frecipe" ++// CC1-LA664-NOT: "-target-feature" ++// CC1-LA664: "-target-abi" "lp64d" ++ + // IR-LOONGARCH64: attributes ## ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+f,+ual" + // IR-LA464: attributes ## ={{.*}}"target-cpu"="la464" {{.*}}"target-features"="+64bit,+d,+f,+lasx,+lsx,+ual" + // IR-LA64V1P0: attributes ## ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+lsx,+ual" + // IR-LA64V1P1: attributes ## ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+frecipe,+lsx,+ual" ++// IR-LA664: attributes ## ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+f,+frecipe,+lasx,+lsx,+ual" + + int foo(void) { + return 3; +diff --git a/clang/test/Driver/loongarch-mtune.c b/clang/test/Driver/loongarch-mtune.c +index 6f3f39e9bbd8..face12e1a1a8 100644 +--- a/clang/test/Driver/loongarch-mtune.c ++++ b/clang/test/Driver/loongarch-mtune.c +@@ -8,6 +8,11 @@ + // RUN: %clang --target=loongarch64 -mtune=la464 -S -emit-llvm %s -o - | \ + // RUN: FileCheck %s --check-prefix=IRATTR -DCPU=la464 + ++// RUN: %clang --target=loongarch64 -mtune=la664 -fsyntax-only %s -### 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=CC1ARG -DCPU=la664 ++// RUN: %clang --target=loongarch64 -mtune=la664 -S -emit-llvm %s -o - | \ ++// RUN: FileCheck %s --check-prefix=IRATTR -DCPU=la664 ++ + // RUN: %clang --target=loongarch64 -mtune=invalidcpu -fsyntax-only %s -### 2>&1 | \ + // RUN: FileCheck %s --check-prefix=CC1ARG -DCPU=invalidcpu + // RUN: not %clang --target=loongarch64 -mtune=invalidcpu -S -emit-llvm %s -o /dev/null 2>&1 | \ +diff --git a/clang/test/Preprocessor/init-loongarch.c b/clang/test/Preprocessor/init-loongarch.c +index cfa3ddb20f10..7ce3d2de8c78 100644 +--- a/clang/test/Preprocessor/init-loongarch.c ++++ b/clang/test/Preprocessor/init-loongarch.c +@@ -822,6 +822,14 @@ + // RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=loongarch64 -DTUNE=loongarch64 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx -Xclang -target-feature -Xclang +frecipe | \ + // RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.1 -DTUNE=loongarch64 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 | \ ++// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la664 -DTUNE=la664 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=la664 | \ ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -mtune=la664 | \ ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s ++// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 -mtune=loongarch64 | \ ++// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la664 -DTUNE=loongarch64 %s + + // ARCH-TUNE: #define __loongarch_arch "ARCH" + // FRECIPE: #define __loongarch_frecipe 1 +-- +2.20.1 + + +From 18f453f2dba969c1fdcbda562079113de7bbcfca Mon Sep 17 00:00:00 2001 +From: Ami-zhang <zhanglimin@loongson.cn> +Date: Tue, 23 Jul 2024 15:20:30 +0800 +Subject: PATCH 9/9 LoongArch Fix test issue of init-loongarch.c + +(cherry picked from commit d59925c39856f255f4dd4427ccc650f2c2692a24) +--- + clang/test/Preprocessor/init-loongarch.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/clang/test/Preprocessor/init-loongarch.c b/clang/test/Preprocessor/init-loongarch.c +index 7ce3d2de8c78..887b6d6af7e1 100644 +--- a/clang/test/Preprocessor/init-loongarch.c ++++ b/clang/test/Preprocessor/init-loongarch.c +@@ -825,7 +825,7 @@ + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 | \ + // RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la664 -DTUNE=la664 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=la664 | \ +-// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s ++// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=la664 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -mtune=la664 | \ + // RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s + // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 -mtune=loongarch64 | \ +-- +2.20.1 +
View file
_service
Changed
@@ -2,7 +2,7 @@ <service name="tar_scm"> <param name="scm">git</param> <param name="url">git@gitee.com:src-openeuler/clang.git</param> - <param name="revision">openEuler-24.03-LTS-Next</param> + <param name="revision">openEuler-24.03-LTS-SP1</param> <param name="exclude">*</param> <param name="extract">*</param> </service>
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2