Skip to content

Commit a4f4d5e

Browse files
authored
[Driver][LoongArch] Enable linker relaxation by default for loongarch64 (#156315)
1 parent 33a583d commit a4f4d5e

File tree

6 files changed

+27
-29
lines changed

6 files changed

+27
-29
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ Windows Support
391391

392392
LoongArch Support
393393
^^^^^^^^^^^^^^^^^
394+
- Enable linker relaxation by default for loongarch64.
394395

395396
RISC-V Support
396397
^^^^^^^^^^^^^^

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,19 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
134134
(!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ)))
135135
Features.push_back("+lsx");
136136

137-
// FIXME: Now we must use -mrelax to enable relax, maybe -mrelax will be set
138-
// as default in the future.
139-
if (const Arg *A =
140-
Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax)) {
141-
if (A->getOption().matches(options::OPT_mrelax)) {
142-
Features.push_back("+relax");
143-
// -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing
144-
// into .debug_addr, which is currently not implemented.
145-
Arg *A;
146-
if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None)
147-
D.Diag(
148-
clang::diag::err_drv_loongarch_unsupported_with_linker_relaxation)
149-
<< A->getAsString(Args);
150-
} else {
151-
Features.push_back("-relax");
152-
}
137+
// -mrelax is default, unless -mno-relax is specified.
138+
// FIXME: Only for loongarch64, loongarch32 has not been fully verified.
139+
if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax,
140+
Triple.isLoongArch64() ? true : false)) {
141+
Features.push_back("+relax");
142+
// -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing
143+
// into .debug_addr, which is currently not implemented.
144+
Arg *A;
145+
if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None)
146+
D.Diag(clang::diag::err_drv_loongarch_unsupported_with_linker_relaxation)
147+
<< A->getAsString(Args);
148+
} else if (Args.getLastArg(options::OPT_mno_relax)) {
149+
Features.push_back("-relax");
153150
}
154151

155152
std::string ArchName;

clang/test/Driver/loongarch-features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %clang --target=loongarch64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64
33

44
// LA32: "target-features"="+32bit"
5-
// LA64: "target-features"="+64bit,+d,+f,+lsx,+ual"
5+
// LA64: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual"
66

77
int foo(void) {
88
return 3;

clang/test/Driver/loongarch-march.c

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

2222
// CC1-LOONGARCH64: "-target-cpu" "loongarch64"
2323
// CC1-LOONGARCH64-NOT: "-target-feature"
24-
// CC1-LOONGARCH64: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual"
24+
// CC1-LOONGARCH64: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual"
2525
// CC1-LOONGARCH64-NOT: "-target-feature"
2626
// CC1-LOONGARCH64: "-target-abi" "lp64d"
2727

2828
// CC1-LA464: "-target-cpu" "la464"
2929
// CC1-LA464-NOT: "-target-feature"
30-
// CC1-LA464: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual"
30+
// CC1-LA464: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual"
3131
// CC1-LA464-NOT: "-target-feature"
3232
// CC1-LA464: "-target-abi" "lp64d"
3333

3434
// CC1-LA64V1P0: "-target-cpu" "loongarch64"
3535
// CC1-LA64V1P0-NOT: "-target-feature"
36-
// CC1-LA64V1P0: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual"
36+
// CC1-LA64V1P0: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual"
3737
// CC1-LA64V1P0-NOT: "-target-feature"
3838
// CC1-LA64V1P0: "-target-abi" "lp64d"
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" "-target-feature" "+lamcas" "-target-feature" "+ld-seq-sa" "-target-feature" "+div32" "-target-feature" "+scq"
42+
// CC1-LA64V1P1: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" "-target-feature" "+frecipe" "-target-feature" "+lam-bh" "-target-feature" "+lamcas" "-target-feature" "+ld-seq-sa" "-target-feature" "+div32" "-target-feature" "+scq"
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" "-target-feature" "+lamcas" "-target-feature" "+ld-seq-sa" "-target-feature" "+div32" "-target-feature" "+scq"
48+
// CC1-LA664: "-target-feature" "+relax" "-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" "+lamcas" "-target-feature" "+ld-seq-sa" "-target-feature" "+div32" "-target-feature" "+scq"
4949
// CC1-LA664-NOT: "-target-feature"
5050
// CC1-LA664: "-target-abi" "lp64d"
5151

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

5858
int foo(void) {
5959
return 3;

clang/test/Driver/loongarch-relax-features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// RUN: not %clang -c --target=loongarch64 -mrelax -gsplit-dwarf=single %s 2>&1 | FileCheck %s --check-prefix=ERR-SPLIT-DWARF
1818

1919
// LA32: "target-features"="+32bit"
20-
// LA64: "target-features"="+64bit,+d,+f,+lsx,+ual"
20+
// LA64: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual"
2121

2222
// LA32-NORELAX: "target-features"="+32bit,-relax"
2323
// LA64-NORELAX: "target-features"="+64bit,+d,+f,+lsx,+ual,-relax"

flang/test/Driver/target-cpu-features.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
! CHECK-AMDGPU-R600-SAME: "-target-cpu" "cayman"
9696

9797
! CHECK-LOONGARCH64: "-fc1" "-triple" "loongarch64-unknown-linux-gnu"
98-
! CHECK-LOONGARCH64-SAME: "-target-cpu" "loongarch64" "-target-feature" "+lsx" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual"
98+
! CHECK-LOONGARCH64-SAME: "-target-cpu" "loongarch64" "-target-feature" "+lsx" "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual"
9999

100100
! CHECK-SPARC-VIS: "-fc1" "-triple" "sparc64-{{[^"]+}}"
101101
! CHECK-SPARC-VIS-SAME: "-target-feature" "+vis"

0 commit comments

Comments
 (0)