Author: ZhaoQi Date: 2025-09-05T14:14:21+08:00 New Revision: a4f4d5ed94cb2cf8082d02f0b39d08fd5ccb33ba
URL: https://github.com/llvm/llvm-project/commit/a4f4d5ed94cb2cf8082d02f0b39d08fd5ccb33ba DIFF: https://github.com/llvm/llvm-project/commit/a4f4d5ed94cb2cf8082d02f0b39d08fd5ccb33ba.diff LOG: [Driver][LoongArch] Enable linker relaxation by default for loongarch64 (#156315) Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Driver/ToolChains/Arch/LoongArch.cpp clang/test/Driver/loongarch-features.c clang/test/Driver/loongarch-march.c clang/test/Driver/loongarch-relax-features.c flang/test/Driver/target-cpu-features.f90 Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index bec001bf8e353..780e8a31cae6d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -391,6 +391,7 @@ Windows Support LoongArch Support ^^^^^^^^^^^^^^^^^ +- Enable linker relaxation by default for loongarch64. RISC-V Support ^^^^^^^^^^^^^^ diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp index ee7b0d10c24ba..156ea03045569 100644 --- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -134,22 +134,19 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, (!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ))) Features.push_back("+lsx"); - // FIXME: Now we must use -mrelax to enable relax, maybe -mrelax will be set - // as default in the future. - if (const Arg *A = - Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax)) { - if (A->getOption().matches(options::OPT_mrelax)) { - Features.push_back("+relax"); - // -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing - // into .debug_addr, which is currently not implemented. - Arg *A; - if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None) - D.Diag( - clang::diag::err_drv_loongarch_unsupported_with_linker_relaxation) - << A->getAsString(Args); - } else { - Features.push_back("-relax"); - } + // -mrelax is default, unless -mno-relax is specified. + // FIXME: Only for loongarch64, loongarch32 has not been fully verified. + if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, + Triple.isLoongArch64() ? true : false)) { + Features.push_back("+relax"); + // -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing + // into .debug_addr, which is currently not implemented. + Arg *A; + if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None) + D.Diag(clang::diag::err_drv_loongarch_unsupported_with_linker_relaxation) + << A->getAsString(Args); + } else if (Args.getLastArg(options::OPT_mno_relax)) { + Features.push_back("-relax"); } std::string ArchName; diff --git a/clang/test/Driver/loongarch-features.c b/clang/test/Driver/loongarch-features.c index 90634bbcf0035..6f40ed71c2c0e 100644 --- a/clang/test/Driver/loongarch-features.c +++ b/clang/test/Driver/loongarch-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,+lsx,+ual" +// LA64: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual" int foo(void) { return 3; diff --git a/clang/test/Driver/loongarch-march.c b/clang/test/Driver/loongarch-march.c index b52cdb330716f..87cdffd8d3a02 100644 --- a/clang/test/Driver/loongarch-march.c +++ b/clang/test/Driver/loongarch-march.c @@ -21,39 +21,39 @@ // CC1-LOONGARCH64: "-target-cpu" "loongarch64" // CC1-LOONGARCH64-NOT: "-target-feature" -// CC1-LOONGARCH64: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual" +// CC1-LOONGARCH64: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual" // CC1-LOONGARCH64-NOT: "-target-feature" // CC1-LOONGARCH64: "-target-abi" "lp64d" // CC1-LA464: "-target-cpu" "la464" // CC1-LA464-NOT: "-target-feature" -// CC1-LA464: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" +// CC1-LA464: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" // 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: "-target-feature" "+relax" "-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" "-target-feature" "+lam-bh" "-target-feature" "+lamcas" "-target-feature" "+ld-seq-sa" "-target-feature" "+div32" "-target-feature" "+scq" +// 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" // 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" "-target-feature" "+lam-bh" "-target-feature" "+lamcas" "-target-feature" "+ld-seq-sa" "-target-feature" "+div32" "-target-feature" "+scq" +// 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" // 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,+div32,+frecipe,+lam-bh,+lamcas,+ld-seq-sa,+lsx,+scq,+ual" -// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+div32,+f,+frecipe,+lam-bh,+lamcas,+lasx,+ld-seq-sa,+lsx,+scq,+ual" +// IR-LOONGARCH64: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+f,+relax,+ual" +// IR-LA464: attributes #[[#]] ={{.*}}"target-cpu"="la464" {{.*}}"target-features"="+64bit,+d,+f,+lasx,+lsx,+relax,+ual" +// IR-LA64V1P0: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+lsx,+relax,+ual" +// IR-LA64V1P1: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+div32,+frecipe,+lam-bh,+lamcas,+ld-seq-sa,+lsx,+relax,+scq,+ual" +// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+div32,+f,+frecipe,+lam-bh,+lamcas,+lasx,+ld-seq-sa,+lsx,+relax,+scq,+ual" int foo(void) { return 3; diff --git a/clang/test/Driver/loongarch-relax-features.c b/clang/test/Driver/loongarch-relax-features.c index c6ef15a8fcff0..2f032516462df 100644 --- a/clang/test/Driver/loongarch-relax-features.c +++ b/clang/test/Driver/loongarch-relax-features.c @@ -17,7 +17,7 @@ // RUN: not %clang -c --target=loongarch64 -mrelax -gsplit-dwarf=single %s 2>&1 | FileCheck %s --check-prefix=ERR-SPLIT-DWARF // LA32: "target-features"="+32bit" -// LA64: "target-features"="+64bit,+d,+f,+lsx,+ual" +// LA64: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual" // LA32-NORELAX: "target-features"="+32bit,-relax" // LA64-NORELAX: "target-features"="+64bit,+d,+f,+lsx,+ual,-relax" diff --git a/flang/test/Driver/target-cpu-features.f90 b/flang/test/Driver/target-cpu-features.f90 index e7da964184c85..17b8be49d9168 100644 --- a/flang/test/Driver/target-cpu-features.f90 +++ b/flang/test/Driver/target-cpu-features.f90 @@ -95,7 +95,7 @@ ! CHECK-AMDGPU-R600-SAME: "-target-cpu" "cayman" ! CHECK-LOONGARCH64: "-fc1" "-triple" "loongarch64-unknown-linux-gnu" -! CHECK-LOONGARCH64-SAME: "-target-cpu" "loongarch64" "-target-feature" "+lsx" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual" +! CHECK-LOONGARCH64-SAME: "-target-cpu" "loongarch64" "-target-feature" "+lsx" "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual" ! CHECK-SPARC-VIS: "-fc1" "-triple" "sparc64-{{[^"]+}}" ! CHECK-SPARC-VIS-SAME: "-target-feature" "+vis" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits