Skip to content

Commit 1d46020

Browse files
authored
[LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (llvm#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
1 parent 05fcdd5 commit 1d46020

File tree

14 files changed

+745
-344
lines changed

14 files changed

+745
-344
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5413,6 +5413,10 @@ def mlam_bh : Flag<["-"], "mlam-bh">, Group<m_loongarch_Features_Group>,
54135413
HelpText<"Enable amswap[_db].{b/h} and amadd[_db].{b/h}">;
54145414
def mno_lam_bh : Flag<["-"], "mno-lam-bh">, Group<m_loongarch_Features_Group>,
54155415
HelpText<"Disable amswap[_db].{b/h} and amadd[_db].{b/h}">;
5416+
def mld_seq_sa : Flag<["-"], "mld-seq-sa">, Group<m_loongarch_Features_Group>,
5417+
HelpText<"Do not generate load-load barrier instructions (dbar 0x700)">;
5418+
def mno_ld_seq_sa : Flag<["-"], "mno-ld-seq-sa">, Group<m_loongarch_Features_Group>,
5419+
HelpText<"Generate load-load barrier instructions (dbar 0x700)">;
54165420
def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, Group<m_loongarch_Features_Group>,
54175421
HelpText<"Enable annotate table jump instruction to correlate it with the jump table.">;
54185422
def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, Group<m_loongarch_Features_Group>,

clang/lib/Basic/Targets/LoongArch.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
205205
// TODO: As more features of the V1.1 ISA are supported, a unified "v1.1"
206206
// arch feature set will be used to include all sub-features belonging to
207207
// the V1.1 ISA version.
208-
if (HasFeatureFrecipe && HasFeatureLAM_BH)
208+
if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLD_SEQ_SA)
209209
Builder.defineMacro("__loongarch_arch",
210210
Twine('"') + "la64v1.1" + Twine('"'));
211211
else
@@ -239,6 +239,9 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
239239
if (HasFeatureLAM_BH)
240240
Builder.defineMacro("__loongarch_lam_bh", Twine(1));
241241

242+
if (HasFeatureLD_SEQ_SA)
243+
Builder.defineMacro("__loongarch_ld_seq_sa", Twine(1));
244+
242245
StringRef ABI = getABI();
243246
if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
244247
Builder.defineMacro("__loongarch_lp64");
@@ -317,6 +320,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
317320
HasFeatureFrecipe = true;
318321
else if (Feature == "+lam-bh")
319322
HasFeatureLAM_BH = true;
323+
else if (Feature == "+ld-seq-sa")
324+
HasFeatureLD_SEQ_SA = true;
320325
}
321326
return true;
322327
}

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
3131
bool HasFeatureLASX;
3232
bool HasFeatureFrecipe;
3333
bool HasFeatureLAM_BH;
34+
bool HasFeatureLD_SEQ_SA;
3435

3536
public:
3637
LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -41,6 +42,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
4142
HasFeatureLASX = false;
4243
HasFeatureFrecipe = false;
4344
HasFeatureLAM_BH = false;
45+
HasFeatureLD_SEQ_SA = false;
4446
LongDoubleWidth = 128;
4547
LongDoubleAlign = 128;
4648
LongDoubleFormat = &llvm::APFloat::IEEEquad();

clang/lib/Driver/ToolChains/Arch/LoongArch.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
274274
else
275275
Features.push_back("-lam-bh");
276276
}
277+
278+
// Select ld-seq-sa feature determined by -m[no-]ld-seq-sa.
279+
if (const Arg *A = Args.getLastArg(options::OPT_mld_seq_sa,
280+
options::OPT_mno_ld_seq_sa)) {
281+
if (A->getOption().matches(options::OPT_mld_seq_sa))
282+
Features.push_back("+ld-seq-sa");
283+
else
284+
Features.push_back("-ld-seq-sa");
285+
}
277286
}
278287

279288
std::string loongarch::postProcessTargetCPUString(const std::string &CPU,

clang/test/Driver/loongarch-march.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@
3939

4040
// CC1-LA64V1P1: "-target-cpu" "loongarch64"
4141
// CC1-LA64V1P1-NOT: "-target-feature"
42-
// CC1-LA64V1P1: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" "-target-feature" "+frecipe" "-target-feature" "+lam-bh"
42+
// CC1-LA64V1P1: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" "-target-feature" "+frecipe" "-target-feature" "+lam-bh" "-target-feature" "+ld-seq-sa"
4343
// CC1-LA64V1P1-NOT: "-target-feature"
4444
// CC1-LA64V1P1: "-target-abi" "lp64d"
4545

4646
// CC1-LA664: "-target-cpu" "la664"
4747
// CC1-LA664-NOT: "-target-feature"
48-
// CC1-LA664: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" "-target-feature" "+frecipe" "-target-feature" "+lam-bh"
48+
// CC1-LA664: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" "-target-feature" "+frecipe" "-target-feature" "+lam-bh" "-target-feature" "+ld-seq-sa"
4949
// CC1-LA664-NOT: "-target-feature"
5050
// CC1-LA664: "-target-abi" "lp64d"
5151

5252
// IR-LOONGARCH64: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+f,+ual"
5353
// IR-LA464: attributes #[[#]] ={{.*}}"target-cpu"="la464" {{.*}}"target-features"="+64bit,+d,+f,+lasx,+lsx,+ual"
5454
// IR-LA64V1P0: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+lsx,+ual"
55-
// IR-LA64V1P1: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+frecipe,+lam-bh,+lsx,+ual"
56-
// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+f,+frecipe,+lam-bh,+lasx,+lsx,+ual"
55+
// IR-LA64V1P1: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+frecipe,+lam-bh,+ld-seq-sa,+lsx,+ual"
56+
// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+f,+frecipe,+lam-bh,+lasx,+ld-seq-sa,+lsx,+ual"
5757

5858
int foo(void) {
5959
return 3;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// Test -m[no]ld-seq-sa options.
2+
3+
// RUN: %clang --target=loongarch64 -mld-seq-sa -fsyntax-only %s -### 2>&1 | \
4+
// RUN: FileCheck %s --check-prefix=CC1-ld-seq-sa
5+
// RUN: %clang --target=loongarch64 -mno-ld-seq-sa -fsyntax-only %s -### 2>&1 | \
6+
// RUN: FileCheck %s --check-prefix=CC1-NO-ld-seq-sa
7+
// RUN: %clang --target=loongarch64 -mno-ld-seq-sa -mld-seq-sa -fsyntax-only %s -### 2>&1 | \
8+
// RUN: FileCheck %s --check-prefix=CC1-ld-seq-sa
9+
// RUN: %clang --target=loongarch64 -mld-seq-sa -mno-ld-seq-sa -fsyntax-only %s -### 2>&1 | \
10+
// RUN: FileCheck %s --check-prefix=CC1-NO-ld-seq-sa
11+
12+
// RUN: %clang --target=loongarch64 -mld-seq-sa -S -emit-llvm %s -o - | \
13+
// RUN: FileCheck %s --check-prefix=IR-ld-seq-sa
14+
// RUN: %clang --target=loongarch64 -mno-ld-seq-sa -S -emit-llvm %s -o - | \
15+
// RUN: FileCheck %s --check-prefix=IR-NO-ld-seq-sa
16+
// RUN: %clang --target=loongarch64 -mno-ld-seq-sa -mld-seq-sa -S -emit-llvm %s -o - | \
17+
// RUN: FileCheck %s --check-prefix=IR-ld-seq-sa
18+
// RUN: %clang --target=loongarch64 -mld-seq-sa -mno-ld-seq-sa -S -emit-llvm %s -o - | \
19+
// RUN: FileCheck %s --check-prefix=IR-NO-ld-seq-sa
20+
21+
22+
// CC1-ld-seq-sa: "-target-feature" "+ld-seq-sa"
23+
// CC1-NO-ld-seq-sa: "-target-feature" "-ld-seq-sa"
24+
25+
// IR-ld-seq-sa: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+ld-seq-sa{{(,.*)?}}"
26+
// IR-NO-ld-seq-sa: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-ld-seq-sa{{(,.*)?}}"
27+
28+
int foo(void) {
29+
return 42;
30+
}

clang/test/Preprocessor/init-loongarch.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@
798798
// LA64-FPU0-LP64S-NOT: #define __loongarch_single_float
799799
// LA64-FPU0-LP64S: #define __loongarch_soft_float 1
800800

801-
/// Check __loongarch_arch{_tune/_frecipe/_lam_bh}.
801+
/// Check __loongarch_arch{_tune/_frecipe/_lam_bh/_ld_seq_sa}.
802802

803803
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - | \
804804
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
@@ -823,37 +823,46 @@
823823
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx | \
824824
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
825825
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 | \
826-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH -DARCH=la64v1.1 -DTUNE=loongarch64 %s
826+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH,LD-SEQ-SA -DARCH=la64v1.1 -DTUNE=loongarch64 %s
827827
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -frecipe | \
828-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.0 -DTUNE=loongarch64 %s
828+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH,LD-SEQ-SA -DARCH=la64v1.0 -DTUNE=loongarch64 %s
829829
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -lsx | \
830-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH -DARCH=loongarch64 -DTUNE=loongarch64 %s
830+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH,LD-SEQ-SA -DARCH=loongarch64 -DTUNE=loongarch64 %s
831831
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +frecipe | \
832832
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=loongarch64 -DTUNE=loongarch64 %s
833833
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx -Xclang -target-feature -Xclang +frecipe | \
834834
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
835835
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang +lam-bh | \
836836
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.0 -DTUNE=loongarch64 %s
837837
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -lam-bh | \
838-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.0 -DTUNE=loongarch64 %s
838+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LD-SEQ-SA -DARCH=la64v1.0 -DTUNE=loongarch64 %s
839839
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lam-bh | \
840840
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=loongarch64 -DTUNE=loongarch64 %s
841841
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx -Xclang -target-feature -Xclang +lam-bh | \
842842
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LAM-BH -DARCH=la64v1.0 -DTUNE=loongarch64 %s
843-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang +frecipe -Xclang -target-feature -Xclang +lam-bh | \
843+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang +ld-seq-sa | \
844+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LD-SEQ-SA -DARCH=la64v1.0 -DTUNE=loongarch64 %s
845+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.1 -Xclang -target-feature -Xclang -ld-seq-sa | \
846+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH -DARCH=la64v1.0 -DTUNE=loongarch64 %s
847+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +ld-seq-sa | \
848+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LD-SEQ-SA -DARCH=loongarch64 -DTUNE=loongarch64 %s
849+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx -Xclang -target-feature -Xclang +ld-seq-sa | \
850+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,LD-SEQ-SA -DARCH=la64v1.0 -DTUNE=loongarch64 %s
851+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la64v1.0 -Xclang -target-feature -Xclang +frecipe -Xclang -target-feature -Xclang +lam-bh -Xclang -target-feature -Xclang +ld-seq-sa | \
844852
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE -DARCH=la64v1.1 -DTUNE=loongarch64 %s
845853
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 | \
846-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH -DARCH=la664 -DTUNE=la664 %s
854+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH,LD-SEQ-SA -DARCH=la664 -DTUNE=la664 %s
847855
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=la664 | \
848856
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la64v1.0 -DTUNE=la664 %s
849857
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -mtune=la664 | \
850858
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s
851859
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 -mtune=loongarch64 | \
852-
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH -DARCH=la664 -DTUNE=loongarch64 %s
860+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE,LAM-BH,LD-SEQ-SA -DARCH=la664 -DTUNE=loongarch64 %s
853861

854862
// ARCH-TUNE: #define __loongarch_arch "[[ARCH]]"
855863
// FRECIPE: #define __loongarch_frecipe 1
856864
// LAM-BH: #define __loongarch_lam_bh 1
865+
// LD-SEQ-SA: #define __loongarch_ld_seq_sa 1
857866
// ARCH-TUNE: #define __loongarch_tune "[[TUNE]]"
858867

859868
// RUN: %clang --target=loongarch64 -mlsx -x c -E -dM %s -o - \

llvm/include/llvm/TargetParser/LoongArchTargetParser.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LOONGARCH_FEATURE("+lvz", FK_LVZ)
1212
LOONGARCH_FEATURE("+ual", FK_UAL)
1313
LOONGARCH_FEATURE("+frecipe", FK_FRECIPE)
1414
LOONGARCH_FEATURE("+lam-bh", FK_LAM_BH)
15+
LOONGARCH_FEATURE("+ld-seq-sa", FK_LD_SEQ_SA)
1516

1617
#undef LOONGARCH_FEATURE
1718

@@ -21,6 +22,6 @@ LOONGARCH_FEATURE("+lam-bh", FK_LAM_BH)
2122

2223
LOONGARCH_ARCH("loongarch64", AK_LOONGARCH64, FK_64BIT | FK_FP32 | FK_FP64 | FK_UAL)
2324
LOONGARCH_ARCH("la464", AK_LA464, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | FK_LASX | FK_UAL)
24-
LOONGARCH_ARCH("la664", AK_LA664, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | FK_LASX | FK_UAL | FK_FRECIPE | FK_LAM_BH)
25+
LOONGARCH_ARCH("la664", AK_LA664, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | FK_LASX | FK_UAL | FK_FRECIPE | FK_LAM_BH | FK_LD_SEQ_SA)
2526

2627
#undef LOONGARCH_ARCH

llvm/include/llvm/TargetParser/LoongArchTargetParser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ enum FeatureKind : uint32_t {
5353
// Atomic memory swap and add instructions for byte and half word are
5454
// available.
5555
FK_LAM_BH = 1 << 10,
56+
57+
// Do not generate load-load barrier instructions (dbar 0x700).
58+
FK_LD_SEQ_SA = 1 << 12,
59+
5660
};
5761

5862
struct FeatureInfo {

llvm/lib/Target/LoongArch/LoongArch.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ def FeatureLAM_BH
118118
"Support amswap[_db].{b/h} and amadd[_db].{b/h} instructions.">;
119119
def HasLAM_BH : Predicate<"Subtarget->hasLAM_BH()">;
120120

121+
def FeatureLD_SEQ_SA
122+
: SubtargetFeature<"ld-seq-sa", "HasLD_SEQ_SA", "true",
123+
"Don't use load-load barrier (dbar 0x700).">;
124+
def HasLD_SEQ_SA : Predicate<"Subtarget->hasLD_SEQ_SA()">;
125+
121126
def TunePreferWInst
122127
: SubtargetFeature<"prefer-w-inst", "PreferWInst", "true",
123128
"Prefer instructions with W suffix">;

llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicCmpXchg(
588588

589589
// .tail:
590590
// dbar 0x700 | acquire
591-
BuildMI(TailMBB, DL, TII->get(LoongArch::DBAR)).addImm(hint);
591+
592+
if (!(hint == 0x700 && MF->getSubtarget<LoongArchSubtarget>().hasLD_SEQ_SA()))
593+
BuildMI(TailMBB, DL, TII->get(LoongArch::DBAR)).addImm(hint);
592594

593595
NextMBBI = MBB.end();
594596
MI.eraseFromParent();

llvm/lib/TargetParser/Host.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,8 +2011,9 @@ const StringMap<bool> sys::getHostCPUFeatures() {
20112011
const StringMap<bool> sys::getHostCPUFeatures() {
20122012
unsigned long hwcap = getauxval(AT_HWCAP);
20132013
bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU
2014-
uint32_t cpucfg2 = 0x2;
2014+
const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3;
20152015
__asm__("cpucfg %[cpucfg2], %[cpucfg2]\n\t" : [cpucfg2] "+r"(cpucfg2));
2016+
__asm__("cpucfg %[cpucfg3], %[cpucfg3]\n\t" : [cpucfg3] "+r"(cpucfg3));
20162017

20172018
StringMap<bool> Features;
20182019

@@ -2026,12 +2027,13 @@ const StringMap<bool> sys::getHostCPUFeatures() {
20262027
Features["frecipe"] = cpucfg2 & (1U << 25); // CPUCFG.2.FRECIPE
20272028
Features["lam-bh"] = cpucfg2 & (1U << 27); // CPUCFG.2.LAM_BH
20282029

2030+
Features["ld-seq-sa"] = cpucfg3 & (1U << 23); // CPUCFG.3.LD_SEQ_SA
2031+
20292032
// TODO: Need to complete.
20302033
// Features["div32"] = cpucfg2 & (1U << 26); // CPUCFG.2.DIV32
20312034
// Features["lamcas"] = cpucfg2 & (1U << 28); // CPUCFG.2.LAMCAS
20322035
// Features["llacq-screl"] = cpucfg2 & (1U << 29); // CPUCFG.2.LLACQ_SCREL
20332036
// Features["scq"] = cpucfg2 & (1U << 30); // CPUCFG.2.SCQ
2034-
// Features["ld-seq-sa"] = cpucfg3 & (1U << 23); // CPUCFG.3.LD_SEQ_SA
20352037
return Features;
20362038
}
20372039
#elif defined(__linux__) && defined(__riscv)

llvm/lib/TargetParser/LoongArchTargetParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ bool LoongArch::getArchFeatures(StringRef Arch,
5353
if (Arch == "la64v1.1") {
5454
Features.push_back("+frecipe");
5555
Features.push_back("+lam-bh");
56+
Features.push_back("+ld-seq-sa");
5657
}
5758
return true;
5859
}

0 commit comments

Comments
 (0)