https://github.com/heiher created https://github.com/llvm/llvm-project/pull/172619
This patch adds support for LoongArch32, as introduced in la-toolchain-conventions v1.2. Link: https://github.com/loongson/la-toolchain-conventions/releases/tag/releases%2Fv1.2 Link: https://gcc.gnu.org/pipermail/gcc-patches/2025-December/703312.html >From c328fd9936868f6f224a7cce53284c600212ea5a Mon Sep 17 00:00:00 2001 From: WANG Rui <[email protected]> Date: Sat, 6 Dec 2025 12:04:15 +0800 Subject: [PATCH] [clang][LoongArch] Add support for LoongArch32 This patch adds support for LoongArch32, as introduced in la-toolchain-conventions v1.2. Co-authored-by: Sun Haiyong <[email protected]> Link: https://github.com/loongson/la-toolchain-conventions/releases/tag/releases%2Fv1.2 Link: https://gcc.gnu.org/pipermail/gcc-patches/2025-December/703312.html --- clang/lib/Basic/Targets/LoongArch.cpp | 18 ++++++++-- clang/lib/Basic/Targets/LoongArch.h | 2 ++ .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 3 +- clang/lib/Driver/ToolChains/Gnu.cpp | 18 ++++++++-- clang/lib/Driver/ToolChains/Linux.cpp | 14 ++++++++ .../test/CodeGen/LoongArch/targetattr-la32.c | 35 +++++++++++++++++++ .../{targetattr.c => targetattr-la64.c} | 8 ++--- clang/test/Driver/loongarch-features.c | 2 +- clang/test/Driver/loongarch-march.c | 8 ++--- clang/test/Driver/loongarch-relax-features.c | 6 ++-- .../TargetParser/LoongArchTargetParser.def | 3 ++ .../llvm/TargetParser/LoongArchTargetParser.h | 6 ++++ llvm/lib/Target/LoongArch/LoongArch.td | 4 +++ .../MCTargetDesc/LoongArchBaseInfo.cpp | 8 ++--- .../TargetParser/LoongArchTargetParser.cpp | 11 ++++-- llvm/test/CodeGen/LoongArch/target-abi.ll | 8 ++--- 16 files changed, 125 insertions(+), 29 deletions(-) create mode 100644 clang/test/CodeGen/LoongArch/targetattr-la32.c rename clang/test/CodeGen/LoongArch/{targetattr.c => targetattr-la64.c} (90%) diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp index 5863af3f3b920..eabb1498a4935 100644 --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -228,6 +228,13 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + Twine('"')); } + } else if (ArchName == "loongarch32") { + if (HasFeature32S) + Builder.defineMacro("__loongarch_arch", + Twine('"') + "la32v1.0" + Twine('"')); + else + Builder.defineMacro("__loongarch_arch", + Twine('"') + "la32rv1.0" + Twine('"')); } else { Builder.defineMacro("__loongarch_arch", Twine('"') + ArchName + Twine('"')); } @@ -268,6 +275,8 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, StringRef ABI = getABI(); if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s") Builder.defineMacro("__loongarch_lp64"); + else if (ABI == "ilp32d" || ABI == "ilp32f" || ABI == "ilp32s") + Builder.defineMacro("__loongarch_ilp32"); if (ABI == "lp64d" || ABI == "ilp32d") { Builder.defineMacro("__loongarch_hard_float"); @@ -356,6 +365,7 @@ bool LoongArchTargetInfo::hasFeature(StringRef Feature) const { .Case("loongarch64", Is64Bit) .Case("32bit", !Is64Bit) .Case("64bit", Is64Bit) + .Case("32s", HasFeature32S) .Case("lsx", HasFeatureLSX) .Case("lasx", HasFeatureLASX) .Default(false); @@ -373,7 +383,9 @@ LoongArchTargetInfo::getTargetBuiltins() const { bool LoongArchTargetInfo::handleTargetFeatures( std::vector<std::string> &Features, DiagnosticsEngine &Diags) { for (const auto &Feature : Features) { - if (Feature == "+d" || Feature == "+f") { + if (Feature == "+32s") { + HasFeature32S = true; + } else if (Feature == "+d" || Feature == "+f") { // "d" implies "f". HasFeatureF = true; if (Feature == "+d") { @@ -430,7 +442,7 @@ LoongArchTargetInfo::parseTargetAttr(StringRef Features) const { switch (Kind) { case AttrFeatureKind::Arch: { if (llvm::LoongArch::isValidArchName(Value) || Value == "la64v1.0" || - Value == "la64v1.1") { + Value == "la64v1.1" || Value == "la32v1.0" || Value == "la32rv1.0") { std::vector<llvm::StringRef> ArchFeatures; if (llvm::LoongArch::getArchFeatures(Value, ArchFeatures)) { Ret.Features.insert(Ret.Features.end(), ArchFeatures.begin(), @@ -441,6 +453,8 @@ LoongArchTargetInfo::parseTargetAttr(StringRef Features) const { Ret.Duplicate = "arch="; else if (Value == "la64v1.0" || Value == "la64v1.1") Ret.CPU = "loongarch64"; + else if (Value == "la32v1.0" || Value == "la32rv1.0") + Ret.CPU = "loongarch32"; else Ret.CPU = Value; } else { diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h index 31afd3eed96f9..bb1c2edacf103 100644 --- a/clang/lib/Basic/Targets/LoongArch.h +++ b/clang/lib/Basic/Targets/LoongArch.h @@ -25,6 +25,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { protected: std::string ABI; std::string CPU; + bool HasFeature32S; bool HasFeatureD; bool HasFeatureF; bool HasFeatureLSX; @@ -39,6 +40,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { public: LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &) : TargetInfo(Triple) { + HasFeature32S = false; HasFeatureD = false; HasFeatureF = false; HasFeatureLSX = false; diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp index da084bdabaee3..cc256d86c5800 100644 --- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -306,7 +306,8 @@ std::string loongarch::getLoongArchTargetCPU(const llvm::opt::ArgList &Args, // If we have -march, use that. if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { Arch = A->getValue(); - if (Arch == "la64v1.0" || Arch == "la64v1.1") + if (Arch == "la64v1.0" || Arch == "la64v1.1" || Arch == "la32v1.0" || + Arch == "la32rv1.0") CPU = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64()); else CPU = Arch; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 1bfcd1f4f3a7c..ec60fe47bbfde 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -751,7 +751,12 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C, break; } - // TODO: handle loongarch32. + case llvm::Triple::loongarch32: { + StringRef ABIName = + loongarch::getLoongArchABI(D, Args, getToolChain().getTriple()); + CmdArgs.push_back(Args.MakeArgString("-mabi=" + ABIName)); + break; + } case llvm::Triple::loongarch64: { StringRef ABIName = loongarch::getLoongArchABI(D, Args, getToolChain().getTriple()); @@ -2368,6 +2373,12 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( "i586-suse-linux", "i686-montavista-linux", }; + static const char *const LoongArch32LibDirs[] = {"/lib32", "/lib"}; + static const char *const LoongArch32Triples[] = { + "loongarch32-linux-gnu", "loongarch32-unknown-linux-gnu", + "loongarch32-linux-gnuf32", "loongarch32-unknown-linux-gnuf32", + "loongarch32-linux-gnusf", "loongarch32-unknown-linux-gnusf"}; + static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"}; static const char *const LoongArch64Triples[] = { "loongarch64-linux-gnu", "loongarch64-unknown-linux-gnu"}; @@ -2638,7 +2649,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( BiarchTripleAliases.append(begin(X32Triples), end(X32Triples)); } break; - // TODO: Handle loongarch32. + case llvm::Triple::loongarch32: + LibDirs.append(begin(LoongArch32LibDirs), end(LoongArch32LibDirs)); + TripleAliases.append(begin(LoongArch32Triples), end(LoongArch32Triples)); + break; case llvm::Triple::loongarch64: LibDirs.append(begin(LoongArch64LibDirs), end(LoongArch64LibDirs)); TripleAliases.append(begin(LoongArch64Triples), end(LoongArch64Triples)); diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index cdbf21fb90263..222c6601fa600 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -206,6 +206,20 @@ static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { if (Triple.getArch() == llvm::Triple::riscv32) return "lib32"; + if (Triple.getArch() == llvm::Triple::loongarch32){ + switch (Triple.getEnvironment()) { + default: + return "lib32"; + case llvm::Triple::GNUSF: + case llvm::Triple::MuslSF: + return "lib32/sf"; + case llvm::Triple::GNUF32: + case llvm::Triple::MuslF32: + return "lib32/f32"; + } + + } + return Triple.isArch32Bit() ? "lib" : "lib64"; } diff --git a/clang/test/CodeGen/LoongArch/targetattr-la32.c b/clang/test/CodeGen/LoongArch/targetattr-la32.c new file mode 100644 index 0000000000000..2183f2f2cb8ce --- /dev/null +++ b/clang/test/CodeGen/LoongArch/targetattr-la32.c @@ -0,0 +1,35 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --version 5 +// RUN: %clang_cc1 -triple loongarch32 -emit-llvm %s -o - | FileCheck %s + +__attribute__((target("arch=loongarch32"))) +// CHECK-LABEL: define dso_local void @testLoongarch32( +// CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: ret void +// +void testLoongarch32() {} + +__attribute__((target("arch=la32v1.0"))) +// CHECK-LABEL: define dso_local void @testLa32v10( +// CHECK-SAME: ) #[[ATTR1:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: ret void +// +void testLa32v10() {} + +__attribute__((target("arch=la32rv1.0"))) +// CHECK-LABEL: define dso_local void @testLa32rv10( +// CHECK-SAME: ) #[[ATTR2:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: ret void +// +void testLa32rv10() {} + +//. +// CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch32" "target-features"="+32bit,+d,+f" } +// CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch32" "target-features"="+32bit,+32s,+d" } +// CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch32" "target-features"="+32bit,+d" } +//. +// CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} +//. diff --git a/clang/test/CodeGen/LoongArch/targetattr.c b/clang/test/CodeGen/LoongArch/targetattr-la64.c similarity index 90% rename from clang/test/CodeGen/LoongArch/targetattr.c rename to clang/test/CodeGen/LoongArch/targetattr-la64.c index 91156e6006e75..5ae5d95b90644 100644 --- a/clang/test/CodeGen/LoongArch/targetattr.c +++ b/clang/test/CodeGen/LoongArch/targetattr-la64.c @@ -78,11 +78,11 @@ void archLa464tuneLa664() {} // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch64" "target-features"="+64bit,+d,+f,+ual" } // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch64" "target-features"="+64bit,+d,+lsx,+ual" } // CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch64" "target-features"="+64bit,+d,+div32,+frecipe,+lam-bh,+lamcas,+ld-seq-sa,+lsx,+scq,+ual" } -// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la464" "target-features"="+64bit,+d,+f,+lasx,+lsx,+ual" } -// CHECK: attributes #[[ATTR5]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la664" "target-features"="+64bit,+d,+div32,+f,+frecipe,+lam-bh,+lamcas,+lasx,+ld-seq-sa,+lsx,+scq,+ual" } -// CHECK: attributes #[[ATTR6]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la664" "target-features"="+64bit,+d,+f,+frecipe,+lam-bh,+lamcas,+lasx,+ld-seq-sa,+lsx,+scq,+ual,-div32" } +// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la464" "target-features"="+32s,+64bit,+d,+f,+lasx,+lsx,+ual" } +// CHECK: attributes #[[ATTR5]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la664" "target-features"="+32s,+64bit,+d,+div32,+f,+frecipe,+lam-bh,+lamcas,+lasx,+ld-seq-sa,+lsx,+scq,+ual" } +// CHECK: attributes #[[ATTR6]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la664" "target-features"="+32s,+64bit,+d,+f,+frecipe,+lam-bh,+lamcas,+lasx,+ld-seq-sa,+lsx,+scq,+ual,-div32" } // CHECK: attributes #[[ATTR7]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit" "tune-cpu"="la464" } -// CHECK: attributes #[[ATTR8]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la464" "target-features"="+64bit,+d,+f,+lasx,+lsx,+ual" "tune-cpu"="la664" } +// CHECK: attributes #[[ATTR8]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="la464" "target-features"="+32s,+64bit,+d,+f,+lasx,+lsx,+ual" "tune-cpu"="la664" } //. // CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} // CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} diff --git a/clang/test/Driver/loongarch-features.c b/clang/test/Driver/loongarch-features.c index 6f40ed71c2c0e..0ed1ef596ad48 100644 --- a/clang/test/Driver/loongarch-features.c +++ b/clang/test/Driver/loongarch-features.c @@ -1,7 +1,7 @@ // RUN: %clang --target=loongarch32 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA32 // RUN: %clang --target=loongarch64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64 -// LA32: "target-features"="+32bit" +// LA32: "target-features"="+32bit,+d,+f" // LA64: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual" int foo(void) { diff --git a/clang/test/Driver/loongarch-march.c b/clang/test/Driver/loongarch-march.c index 87cdffd8d3a02..6997c5ff35add 100644 --- a/clang/test/Driver/loongarch-march.c +++ b/clang/test/Driver/loongarch-march.c @@ -27,7 +27,7 @@ // CC1-LA464: "-target-cpu" "la464" // CC1-LA464-NOT: "-target-feature" -// 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: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" "-target-feature" "+32s" // CC1-LA464-NOT: "-target-feature" // CC1-LA464: "-target-abi" "lp64d" @@ -45,15 +45,15 @@ // CC1-LA664: "-target-cpu" "la664" // CC1-LA664-NOT: "-target-feature" -// 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: "-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" "-target-feature" "+32s" // CC1-LA664-NOT: "-target-feature" // CC1-LA664: "-target-abi" "lp64d" // 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-LA464: attributes #[[#]] ={{.*}}"target-cpu"="la464" {{.*}}"target-features"="+32s,+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" +// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+32s,+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 2f032516462df..7b14c83d48797 100644 --- a/clang/test/Driver/loongarch-relax-features.c +++ b/clang/test/Driver/loongarch-relax-features.c @@ -16,13 +16,13 @@ // RUN: not %clang -c --target=loongarch64-linux-gnu -mrelax -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefix=ERR-SPLIT-DWARF // RUN: not %clang -c --target=loongarch64 -mrelax -gsplit-dwarf=single %s 2>&1 | FileCheck %s --check-prefix=ERR-SPLIT-DWARF -// LA32: "target-features"="+32bit" +// LA32: "target-features"="+32bit,+d,+f" // LA64: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual" -// LA32-NORELAX: "target-features"="+32bit,-relax" +// LA32-NORELAX: "target-features"="+32bit,+d,+f,-relax" // LA64-NORELAX: "target-features"="+64bit,+d,+f,+lsx,+ual,-relax" -// LA32-RELAX: "target-features"="+32bit,+relax" +// LA32-RELAX: "target-features"="+32bit,+d,+f,+relax" // LA64-RELAX: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual" // SPLIT-DWARF: "-split-dwarf-file" diff --git a/llvm/include/llvm/TargetParser/LoongArchTargetParser.def b/llvm/include/llvm/TargetParser/LoongArchTargetParser.def index 1bcf65b37f201..e57f5d19cdff2 100644 --- a/llvm/include/llvm/TargetParser/LoongArchTargetParser.def +++ b/llvm/include/llvm/TargetParser/LoongArchTargetParser.def @@ -2,6 +2,7 @@ #define LOONGARCH_FEATURE(NAME, KIND) #endif +LOONGARCH_FEATURE("+32bit", FK_32BIT) LOONGARCH_FEATURE("+64bit", FK_64BIT) LOONGARCH_FEATURE("+f", FK_FP32) LOONGARCH_FEATURE("+d", FK_FP64) @@ -16,6 +17,7 @@ LOONGARCH_FEATURE("+lamcas", FK_LAMCAS) LOONGARCH_FEATURE("+ld-seq-sa", FK_LD_SEQ_SA) LOONGARCH_FEATURE("+div32", FK_DIV32) LOONGARCH_FEATURE("+scq", FK_SCQ) +LOONGARCH_FEATURE("+32s", FK_32S) #undef LOONGARCH_FEATURE @@ -23,6 +25,7 @@ LOONGARCH_FEATURE("+scq", FK_SCQ) #define LOONGARCH_ARCH(NAME, KIND, FEATURES) #endif +LOONGARCH_ARCH("loongarch32", AK_LOONGARCH32, FK_32BIT | FK_FP32 | FK_FP64) LOONGARCH_ARCH("loongarch64", AK_LOONGARCH64, FK_64BIT | FK_FP32 | FK_FP64 | FK_UAL) LOONGARCH_ARCH("la464", AK_LA464, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | FK_LASX | FK_UAL) LOONGARCH_ARCH("la664", AK_LA664, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | FK_LASX | FK_UAL | FK_FRECIPE | FK_LAM_BH | FK_LAMCAS | FK_LD_SEQ_SA | FK_DIV32 | FK_SCQ) diff --git a/llvm/include/llvm/TargetParser/LoongArchTargetParser.h b/llvm/include/llvm/TargetParser/LoongArchTargetParser.h index 1357d74744592..12730b0db3bbe 100644 --- a/llvm/include/llvm/TargetParser/LoongArchTargetParser.h +++ b/llvm/include/llvm/TargetParser/LoongArchTargetParser.h @@ -24,6 +24,9 @@ class StringRef; namespace LoongArch { enum FeatureKind : uint32_t { + // 32-bit ISA is available. + FK_32BIT = 1 << 0, + // 64-bit ISA is available. FK_64BIT = 1 << 1, @@ -67,6 +70,9 @@ enum FeatureKind : uint32_t { // sc.q is available. FK_SCQ = 1 << 14, + + // 32-bit standard variant is available. + FK_32S = 1 << 5, }; struct FeatureInfo { diff --git a/llvm/lib/Target/LoongArch/LoongArch.td b/llvm/lib/Target/LoongArch/LoongArch.td index 67f07f0a0370e..652e6452a4a02 100644 --- a/llvm/lib/Target/LoongArch/LoongArch.td +++ b/llvm/lib/Target/LoongArch/LoongArch.td @@ -171,6 +171,10 @@ def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit, FeatureUAL, FeatureExtLSX]>; +// Generic 32-bit processor with double-precision floating-point support. +def : ProcessorModel<"loongarch32", NoSchedModel, [Feature32Bit, + FeatureBasicD]>; + // Generic 64-bit processor with double-precision floating-point support. def : ProcessorModel<"loongarch64", NoSchedModel, [Feature64Bit, FeatureUAL, diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp index 7cefb3f8119b8..cf8552fde3ca5 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp @@ -26,18 +26,14 @@ namespace LoongArchABI { static ABI checkABIStandardized(ABI Abi) { StringRef ABIName; switch (Abi) { - case ABI_ILP32S: - ABIName = "ilp32s"; - break; case ABI_ILP32F: ABIName = "ilp32f"; break; - case ABI_ILP32D: - ABIName = "ilp32d"; - break; case ABI_LP64F: ABIName = "lp64f"; break; + case ABI_ILP32S: + case ABI_ILP32D: case ABI_LP64S: case ABI_LP64D: return Abi; diff --git a/llvm/lib/TargetParser/LoongArchTargetParser.cpp b/llvm/lib/TargetParser/LoongArchTargetParser.cpp index 572a278a39fce..0bd8beeb7a4cb 100644 --- a/llvm/lib/TargetParser/LoongArchTargetParser.cpp +++ b/llvm/lib/TargetParser/LoongArchTargetParser.cpp @@ -74,6 +74,14 @@ bool LoongArch::getArchFeatures(StringRef Arch, return true; } + if (Arch == "la32v1.0" || Arch == "la32rv1.0") { + Features.push_back("+32bit"); + Features.push_back("+d"); + if (Arch == "la32v1.0") + Features.push_back("+32s"); + return true; + } + return false; } @@ -85,6 +93,5 @@ void LoongArch::fillValidCPUList(SmallVectorImpl<StringRef> &Values) { } StringRef LoongArch::getDefaultArch(bool Is64Bit) { - // TODO: use a real 32-bit arch name. - return Is64Bit ? "loongarch64" : ""; + return Is64Bit ? "loongarch64" : "loongarch32"; } diff --git a/llvm/test/CodeGen/LoongArch/target-abi.ll b/llvm/test/CodeGen/LoongArch/target-abi.ll index de834c152b180..033a47027b85e 100644 --- a/llvm/test/CodeGen/LoongArch/target-abi.ll +++ b/llvm/test/CodeGen/LoongArch/target-abi.ll @@ -1,12 +1,12 @@ -; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32s < %s 2>&1 \ -; RUN: | FileCheck %s -DABI=ilp32s --check-prefixes=CHECK,WARNING ; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32f < %s 2>&1 \ ; RUN: | FileCheck %s -DABI=ilp32f --check-prefixes=CHECK,WARNING -; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32d < %s 2>&1 \ -; RUN: | FileCheck %s -DABI=ilp32d --check-prefixes=CHECK,WARNING ; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64f < %s 2>&1 \ ; RUN: | FileCheck %s -DABI=lp64f --check-prefixes=CHECK,WARNING +; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32s < %s 2>&1 \ +; RUN: | FileCheck %s --check-prefixes=CHECK,NO-WARNING +; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32d < %s 2>&1 \ +; RUN: | FileCheck %s --check-prefixes=CHECK,NO-WARNING ; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64s < %s 2>&1 \ ; RUN: | FileCheck %s --check-prefixes=CHECK,NO-WARNING ; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64d < %s 2>&1 \ _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
