[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
@@ -2011,8 +2011,9 @@ const StringMap sys::getHostCPUFeatures() { const StringMap sys::getHostCPUFeatures() { unsigned long hwcap = getauxval(AT_HWCAP); bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU - uint32_t cpucfg2 = 0x2; + const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3; SixWeining wrote: Should already be fixed. https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
@@ -2011,8 +2011,9 @@ const StringMap sys::getHostCPUFeatures() { const StringMap sys::getHostCPUFeatures() { unsigned long hwcap = getauxval(AT_HWCAP); bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU - uint32_t cpucfg2 = 0x2; + const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3; SixWeining wrote: Oh, my bad. I'll fix it now. https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
@@ -2011,8 +2011,9 @@ const StringMap sys::getHostCPUFeatures() { const StringMap sys::getHostCPUFeatures() { unsigned long hwcap = getauxval(AT_HWCAP); bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU - uint32_t cpucfg2 = 0x2; + const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3; dtcxzyw wrote: I encountered a compilation error with gcc 13.2: ``` [1/371] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o FAILED: lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o ccache /usr/bin/g++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/dtcxzyw/llvm-build/lib/TargetParser -I/home/dtcxzyw/llvm-project/llvm/lib/TargetParser -I/home/dtcxzyw/llvm-build/include -I/home/dtcxzyw/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -MF lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o.d -o lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -c /home/dtcxzyw/llvm-project/llvm/lib/TargetParser/Host.cpp /home/dtcxzyw/llvm-project/llvm/lib/TargetParser/Host.cpp: In function ‘const llvm::StringMap llvm::sys::getHostCPUFeatures()’: /home/dtcxzyw/llvm-project/llvm/lib/TargetParser/Host.cpp:2015:3: error: read-only variable ‘cpucfg2’ used as ‘asm’ output 2015 | __asm__("cpucfg %[cpucfg2], %[cpucfg2]\n\t" : [cpucfg2] "+r"(cpucfg2)); | ^~~ /home/dtcxzyw/llvm-project/llvm/lib/TargetParser/Host.cpp:2016:3: error: read-only variable ‘cpucfg3’ used as ‘asm’ output 2016 | __asm__("cpucfg %[cpucfg3], %[cpucfg3]\n\t" : [cpucfg3] "+r"(cpucfg3)); | ^~~ ninja: build stopped: subcommand failed. ``` https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building `clang,llvm` at step 10 "Add check check-offload". Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/8976 Here is the relevant piece of the build log for the reference ``` Step 10 (Add check check-offload) failure: 1200 seconds without output running [b'ninja', b'-j 32', b'check-offload'], attempting to kill ... PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug53727.cpp (947 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug47654.cpp (948 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49779.cpp (949 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/test_libc.cpp (950 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/wtime.c (951 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/bug49021.cpp (952 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/std_complex_arithmetic.cpp (953 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/complex_reduction.cpp (954 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49021.cpp (955 of 960) PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/std_complex_arithmetic.cpp (956 of 960) command timed out: 1200 seconds without output running [b'ninja', b'-j 32', b'check-offload'], attempting to kill process killed by signal 9 program finished with exit code -1 elapsedTime=1238.823334 ``` https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
https://github.com/SixWeining closed https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
https://github.com/SixWeining approved this pull request. https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
@@ -2011,8 +2011,9 @@ const StringMap sys::getHostCPUFeatures() { const StringMap sys::getHostCPUFeatures() { unsigned long hwcap = getauxval(AT_HWCAP); bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU - uint32_t cpucfg2 = 0x2; + uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3; SixWeining wrote: ```suggestion const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3; ``` https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
https://github.com/SixWeining edited https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
https://github.com/SixWeining approved this pull request. LGTM except a nit. https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
https://github.com/SixWeining approved this pull request. LGTM. But we can also add this feature in `sys::getHostCPUFeatures` in this PR. https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: None (tangaac) Changes Two options for clang -mld-seq-sa: Do not generate load-load barrier instructions (dbar 0x700) -mno-ld-seq-sa: Generate load-load barrier instructions (dbar 0x700) The default is -mno-ld-seq-sa --- Patch is 76.37 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/116762.diff 13 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+4) - (modified) clang/lib/Basic/Targets/LoongArch.cpp (+6-1) - (modified) clang/lib/Basic/Targets/LoongArch.h (+2) - (modified) clang/lib/Driver/ToolChains/Arch/LoongArch.cpp (+9) - (modified) clang/test/Driver/loongarch-march.c (+4-4) - (added) clang/test/Driver/loongarch-mld-seq-sa.c (+30) - (modified) clang/test/Preprocessor/init-loongarch.c (+22-8) - (modified) llvm/include/llvm/TargetParser/LoongArchTargetParser.def (+2-1) - (modified) llvm/include/llvm/TargetParser/LoongArchTargetParser.h (+4) - (modified) llvm/lib/Target/LoongArch/LoongArch.td (+5) - (modified) llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp (+3-1) - (modified) llvm/lib/TargetParser/LoongArchTargetParser.cpp (+1) - (modified) llvm/test/CodeGen/LoongArch/ir-instruction/atomic-cmpxchg.ll (+1145) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d7230dd7272fd6..3ebb682397a0b6 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5416,6 +5416,10 @@ def mlam_bh : Flag<["-"], "mlam-bh">, Group, HelpText<"Enable amswap[_db].{b/h} and amadd[_db].{b/h}">; def mno_lam_bh : Flag<["-"], "mno-lam-bh">, Group, HelpText<"Disable amswap[_db].{b/h} and amadd[_db].{b/h}">; +def mld_seq_sa : Flag<["-"], "mld-seq-sa">, Group, + HelpText<"Do not generate load-load barrier instructions (dbar 0x700)">; +def mno_ld_seq_sa : Flag<["-"], "mno-ld-seq-sa">, Group, + HelpText<"Generate load-load barrier instructions (dbar 0x700)">; def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, Group, HelpText<"Enable annotate table jump instruction to correlate it with the jump table.">; def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, Group, diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp index 07b22b35f603ce..3f2d7317532aaf 100644 --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -205,7 +205,7 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, // 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 && HasFeatureLAM_BH) + if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLD_SEQ_SA) Builder.defineMacro("__loongarch_arch", Twine('"') + "la64v1.1" + Twine('"')); else @@ -239,6 +239,9 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, if (HasFeatureLAM_BH) Builder.defineMacro("__loongarch_lam_bh", Twine(1)); + if (HasFeatureLD_SEQ_SA) +Builder.defineMacro("__loongarch_ld_seq_sa", Twine(1)); + StringRef ABI = getABI(); if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s") Builder.defineMacro("__loongarch_lp64"); @@ -317,6 +320,8 @@ bool LoongArchTargetInfo::handleTargetFeatures( HasFeatureFrecipe = true; else if (Feature == "+lam-bh") HasFeatureLAM_BH = true; +else if (Feature == "+ld-seq-sa") + HasFeatureLD_SEQ_SA = true; } return true; } diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h index 3585e9f7968b4b..e5eae7a8fcf677 100644 --- a/clang/lib/Basic/Targets/LoongArch.h +++ b/clang/lib/Basic/Targets/LoongArch.h @@ -31,6 +31,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { bool HasFeatureLASX; bool HasFeatureFrecipe; bool HasFeatureLAM_BH; + bool HasFeatureLD_SEQ_SA; public: LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &) @@ -41,6 +42,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { HasFeatureLASX = false; HasFeatureFrecipe = false; HasFeatureLAM_BH = false; +HasFeatureLD_SEQ_SA = 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 987db4638fca88..67b71a3ec623e4 100644 --- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -274,6 +274,15 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, else Features.push_back("-lam-bh"); } + + // Select ld-seq-sa feat
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
@@ -100,99 +101,99 @@ define void @cmpxchg_i64_acquire_acquire(ptr %ptr, i64 %cmp, i64 %val) nounwind } define void @cmpxchg_i8_acquire_monotonic(ptr %ptr, i8 %cmp, i8 %val) nounwind { SixWeining wrote: This test doesn't have `LA64` check? https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
@@ -1,5 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py ; RUN: llc --mtriple=loongarch64 -mattr=+d < %s | FileCheck %s --check-prefix=LA64 +; RUN: llc --mtriple=loongarch64 -mattr=+d,+ld-seq-sa < %s | FileCheck %s --check-prefix=LA64-LD-SEQ-SA SixWeining wrote: To reduce test lines: ``` ; RUN: llc --mtriple=loongarch64 -mattr=+d,-ld-seq-sa < %s | FileCheck %s --check-prefixes=LA64,NO-LD-SEQ-SA ; RUN: llc --mtriple=loongarch64 -mattr=+d,+ld-seq-sa < %s | FileCheck %s --check-prefix=LA64 ``` https://github.com/llvm/llvm-project/pull/116762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
llvmbot wrote: @llvm/pr-subscribers-backend-loongarch Author: None (tangaac) Changes Two options for clang -mld-seq-sa: Do not generate load-load barrier instructions (dbar 0x700) -mno-ld-seq-sa: Generate load-load barrier instructions (dbar 0x700) The default is -mno-ld-seq-sa --- Patch is 76.37 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/116762.diff 13 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+4) - (modified) clang/lib/Basic/Targets/LoongArch.cpp (+6-1) - (modified) clang/lib/Basic/Targets/LoongArch.h (+2) - (modified) clang/lib/Driver/ToolChains/Arch/LoongArch.cpp (+9) - (modified) clang/test/Driver/loongarch-march.c (+4-4) - (added) clang/test/Driver/loongarch-mld-seq-sa.c (+30) - (modified) clang/test/Preprocessor/init-loongarch.c (+22-8) - (modified) llvm/include/llvm/TargetParser/LoongArchTargetParser.def (+2-1) - (modified) llvm/include/llvm/TargetParser/LoongArchTargetParser.h (+4) - (modified) llvm/lib/Target/LoongArch/LoongArch.td (+5) - (modified) llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp (+3-1) - (modified) llvm/lib/TargetParser/LoongArchTargetParser.cpp (+1) - (modified) llvm/test/CodeGen/LoongArch/ir-instruction/atomic-cmpxchg.ll (+1145) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d7230dd7272fd6..3ebb682397a0b6 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5416,6 +5416,10 @@ def mlam_bh : Flag<["-"], "mlam-bh">, Group, HelpText<"Enable amswap[_db].{b/h} and amadd[_db].{b/h}">; def mno_lam_bh : Flag<["-"], "mno-lam-bh">, Group, HelpText<"Disable amswap[_db].{b/h} and amadd[_db].{b/h}">; +def mld_seq_sa : Flag<["-"], "mld-seq-sa">, Group, + HelpText<"Do not generate load-load barrier instructions (dbar 0x700)">; +def mno_ld_seq_sa : Flag<["-"], "mno-ld-seq-sa">, Group, + HelpText<"Generate load-load barrier instructions (dbar 0x700)">; def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, Group, HelpText<"Enable annotate table jump instruction to correlate it with the jump table.">; def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, Group, diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp index 07b22b35f603ce..3f2d7317532aaf 100644 --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -205,7 +205,7 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, // 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 && HasFeatureLAM_BH) + if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLD_SEQ_SA) Builder.defineMacro("__loongarch_arch", Twine('"') + "la64v1.1" + Twine('"')); else @@ -239,6 +239,9 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, if (HasFeatureLAM_BH) Builder.defineMacro("__loongarch_lam_bh", Twine(1)); + if (HasFeatureLD_SEQ_SA) +Builder.defineMacro("__loongarch_ld_seq_sa", Twine(1)); + StringRef ABI = getABI(); if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s") Builder.defineMacro("__loongarch_lp64"); @@ -317,6 +320,8 @@ bool LoongArchTargetInfo::handleTargetFeatures( HasFeatureFrecipe = true; else if (Feature == "+lam-bh") HasFeatureLAM_BH = true; +else if (Feature == "+ld-seq-sa") + HasFeatureLD_SEQ_SA = true; } return true; } diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h index 3585e9f7968b4b..e5eae7a8fcf677 100644 --- a/clang/lib/Basic/Targets/LoongArch.h +++ b/clang/lib/Basic/Targets/LoongArch.h @@ -31,6 +31,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { bool HasFeatureLASX; bool HasFeatureFrecipe; bool HasFeatureLAM_BH; + bool HasFeatureLD_SEQ_SA; public: LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &) @@ -41,6 +42,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { HasFeatureLASX = false; HasFeatureFrecipe = false; HasFeatureLAM_BH = false; +HasFeatureLD_SEQ_SA = 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 987db4638fca88..67b71a3ec623e4 100644 --- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -274,6 +274,15 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, else Features.push_back("-lam-bh"); } + + // Select ld-seq-sa feature determined by -m[n
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
https://github.com/tangaac updated https://github.com/llvm/llvm-project/pull/116762 >From eef0e50043c45ea6ca22af266bcc833ce9bbaf0d Mon Sep 17 00:00:00 2001 From: tangaac Date: Fri, 1 Nov 2024 17:28:38 +0800 Subject: [PATCH] [LoongArch] Support feature ld-seq-sa that don't generate dbar 0x700. --- clang/include/clang/Driver/Options.td |4 + clang/lib/Basic/Targets/LoongArch.cpp |7 +- clang/lib/Basic/Targets/LoongArch.h |2 + .../lib/Driver/ToolChains/Arch/LoongArch.cpp |9 + clang/test/Driver/loongarch-march.c |8 +- clang/test/Driver/loongarch-mld-seq-sa.c | 30 + clang/test/Preprocessor/init-loongarch.c | 25 +- .../TargetParser/LoongArchTargetParser.def|3 +- .../llvm/TargetParser/LoongArchTargetParser.h |4 + llvm/lib/Target/LoongArch/LoongArch.td|5 + .../LoongArchExpandAtomicPseudoInsts.cpp |4 +- .../TargetParser/LoongArchTargetParser.cpp|1 + .../ir-instruction/atomic-cmpxchg.ll | 1145 + 13 files changed, 1232 insertions(+), 15 deletions(-) create mode 100644 clang/test/Driver/loongarch-mld-seq-sa.c diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d7230dd7272fd6..3ebb682397a0b6 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5416,6 +5416,10 @@ def mlam_bh : Flag<["-"], "mlam-bh">, Group, HelpText<"Enable amswap[_db].{b/h} and amadd[_db].{b/h}">; def mno_lam_bh : Flag<["-"], "mno-lam-bh">, Group, HelpText<"Disable amswap[_db].{b/h} and amadd[_db].{b/h}">; +def mld_seq_sa : Flag<["-"], "mld-seq-sa">, Group, + HelpText<"Do not generate load-load barrier instructions (dbar 0x700)">; +def mno_ld_seq_sa : Flag<["-"], "mno-ld-seq-sa">, Group, + HelpText<"Generate load-load barrier instructions (dbar 0x700)">; def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, Group, HelpText<"Enable annotate table jump instruction to correlate it with the jump table.">; def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, Group, diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp index 07b22b35f603ce..3f2d7317532aaf 100644 --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -205,7 +205,7 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, // 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 && HasFeatureLAM_BH) + if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLD_SEQ_SA) Builder.defineMacro("__loongarch_arch", Twine('"') + "la64v1.1" + Twine('"')); else @@ -239,6 +239,9 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, if (HasFeatureLAM_BH) Builder.defineMacro("__loongarch_lam_bh", Twine(1)); + if (HasFeatureLD_SEQ_SA) +Builder.defineMacro("__loongarch_ld_seq_sa", Twine(1)); + StringRef ABI = getABI(); if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s") Builder.defineMacro("__loongarch_lp64"); @@ -317,6 +320,8 @@ bool LoongArchTargetInfo::handleTargetFeatures( HasFeatureFrecipe = true; else if (Feature == "+lam-bh") HasFeatureLAM_BH = true; +else if (Feature == "+ld-seq-sa") + HasFeatureLD_SEQ_SA = true; } return true; } diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h index 3585e9f7968b4b..e5eae7a8fcf677 100644 --- a/clang/lib/Basic/Targets/LoongArch.h +++ b/clang/lib/Basic/Targets/LoongArch.h @@ -31,6 +31,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { bool HasFeatureLASX; bool HasFeatureFrecipe; bool HasFeatureLAM_BH; + bool HasFeatureLD_SEQ_SA; public: LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &) @@ -41,6 +42,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { HasFeatureLASX = false; HasFeatureFrecipe = false; HasFeatureLAM_BH = false; +HasFeatureLD_SEQ_SA = 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 987db4638fca88..67b71a3ec623e4 100644 --- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -274,6 +274,15 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, else Features.push_back("-lam-bh"); } + + // Select ld-seq-sa feature determined by -m[no-]ld-seq-sa. + if (const Arg *A = Args.getLastArg(options::OPT_mld_seq_sa, + options::OPT_mno_ld_seq_sa)) { +if (A->getOption()
[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)
https://github.com/tangaac created https://github.com/llvm/llvm-project/pull/116762 Two options for clang -mld-seq-sa: Do not generate load-load barrier instructions (dbar 0x700) -mno-ld-seq-sa: Generate load-load barrier instructions (dbar 0x700) The default is -mno-ld-seq-sa >From c70cfa3b2e35eadfe80e3b8388e7554f398f8645 Mon Sep 17 00:00:00 2001 From: tangaac Date: Fri, 1 Nov 2024 17:28:38 +0800 Subject: [PATCH] [LoongArch] Support feature ld-seq-sa that don't generate dbar 0x700. --- clang/include/clang/Driver/Options.td |4 + clang/lib/Basic/Targets/LoongArch.cpp |7 +- clang/lib/Basic/Targets/LoongArch.h |2 + .../lib/Driver/ToolChains/Arch/LoongArch.cpp |9 + clang/test/Driver/loongarch-march.c |8 +- clang/test/Driver/loongarch-mld-seq-sa.c | 30 + clang/test/Preprocessor/init-loongarch.c | 30 +- .../TargetParser/LoongArchTargetParser.def|3 +- .../llvm/TargetParser/LoongArchTargetParser.h |4 + llvm/lib/Target/LoongArch/LoongArch.td|5 + .../LoongArchExpandAtomicPseudoInsts.cpp |4 +- .../TargetParser/LoongArchTargetParser.cpp|1 + .../ir-instruction/atomic-cmpxchg.ll | 1145 + 13 files changed, 1237 insertions(+), 15 deletions(-) create mode 100644 clang/test/Driver/loongarch-mld-seq-sa.c diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d7230dd7272fd6..3ebb682397a0b6 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5416,6 +5416,10 @@ def mlam_bh : Flag<["-"], "mlam-bh">, Group, HelpText<"Enable amswap[_db].{b/h} and amadd[_db].{b/h}">; def mno_lam_bh : Flag<["-"], "mno-lam-bh">, Group, HelpText<"Disable amswap[_db].{b/h} and amadd[_db].{b/h}">; +def mld_seq_sa : Flag<["-"], "mld-seq-sa">, Group, + HelpText<"Do not generate load-load barrier instructions (dbar 0x700)">; +def mno_ld_seq_sa : Flag<["-"], "mno-ld-seq-sa">, Group, + HelpText<"Generate load-load barrier instructions (dbar 0x700)">; def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, Group, HelpText<"Enable annotate table jump instruction to correlate it with the jump table.">; def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, Group, diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp index 07b22b35f603ce..3f2d7317532aaf 100644 --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -205,7 +205,7 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, // 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 && HasFeatureLAM_BH) + if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLD_SEQ_SA) Builder.defineMacro("__loongarch_arch", Twine('"') + "la64v1.1" + Twine('"')); else @@ -239,6 +239,9 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, if (HasFeatureLAM_BH) Builder.defineMacro("__loongarch_lam_bh", Twine(1)); + if (HasFeatureLD_SEQ_SA) +Builder.defineMacro("__loongarch_ld_seq_sa", Twine(1)); + StringRef ABI = getABI(); if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s") Builder.defineMacro("__loongarch_lp64"); @@ -317,6 +320,8 @@ bool LoongArchTargetInfo::handleTargetFeatures( HasFeatureFrecipe = true; else if (Feature == "+lam-bh") HasFeatureLAM_BH = true; +else if (Feature == "+ld-seq-sa") + HasFeatureLD_SEQ_SA = true; } return true; } diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h index 3585e9f7968b4b..e5eae7a8fcf677 100644 --- a/clang/lib/Basic/Targets/LoongArch.h +++ b/clang/lib/Basic/Targets/LoongArch.h @@ -31,6 +31,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { bool HasFeatureLASX; bool HasFeatureFrecipe; bool HasFeatureLAM_BH; + bool HasFeatureLD_SEQ_SA; public: LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &) @@ -41,6 +42,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { HasFeatureLASX = false; HasFeatureFrecipe = false; HasFeatureLAM_BH = false; +HasFeatureLD_SEQ_SA = 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 987db4638fca88..67b71a3ec623e4 100644 --- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -274,6 +274,15 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, else Features.push_back("-lam-bh"); }