https://github.com/Ami-zhang updated https://github.com/llvm/llvm-project/pull/100068
>From 97051ad2c670bb0b8ae2160b032b7ab95a7b43ea Mon Sep 17 00:00:00 2001 From: Ami-zhang <zhangli...@loongson.cn> Date: Mon, 29 Apr 2024 16:58:15 +0800 Subject: [PATCH] [LoongArch] Support la664 A new ProcessorModel called `la664` is defined in LoongArch.td to support `-march/-mtune=la664`. --- clang/test/Driver/loongarch-march.c | 11 +++++++++++ clang/test/Driver/loongarch-mtune.c | 5 +++++ clang/test/Preprocessor/init-loongarch.c | 8 ++++++++ .../llvm/TargetParser/LoongArchTargetParser.def | 2 ++ .../include/llvm/TargetParser/LoongArchTargetParser.h | 3 +++ llvm/lib/Target/LoongArch/LoongArch.td | 7 +++++++ llvm/lib/TargetParser/Host.cpp | 2 ++ llvm/test/CodeGen/LoongArch/cpus.ll | 5 +++++ 8 files changed, 43 insertions(+) diff --git a/clang/test/Driver/loongarch-march.c b/clang/test/Driver/loongarch-march.c index d06da72a755cb..ad173539cb0c0 100644 --- a/clang/test/Driver/loongarch-march.c +++ b/clang/test/Driver/loongarch-march.c @@ -6,6 +6,8 @@ // RUN: FileCheck %s --check-prefix=CC1-LA64V1P0 // RUN: %clang --target=loongarch64 -march=la64v1.1 -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1-LA64V1P1 +// RUN: %clang --target=loongarch64 -march=la664 -fsyntax-only %s -### 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CC1-LA664 // RUN: %clang --target=loongarch64 -march=loongarch64 -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IR-LOONGARCH64 // RUN: %clang --target=loongarch64 -march=la464 -S -emit-llvm %s -o - | \ @@ -14,6 +16,8 @@ // RUN: FileCheck %s --check-prefix=IR-LA64V1P0 // RUN: %clang --target=loongarch64 -march=la64v1.1 -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IR-LA64V1P1 +// RUN: %clang --target=loongarch64 -march=la664 -S -emit-llvm %s -o - | \ +// RUN: FileCheck %s --check-prefix=IR-LA664 // CC1-LOONGARCH64: "-target-cpu" "loongarch64" // CC1-LOONGARCH64-NOT: "-target-feature" @@ -39,10 +43,17 @@ // 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" +// 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,+frecipe,+lsx,+ual" +// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+f,+lasx,+lsx,+ual,+frecipe" int foo(void) { return 3; diff --git a/clang/test/Driver/loongarch-mtune.c b/clang/test/Driver/loongarch-mtune.c index 6f3f39e9bbd86..face12e1a1a82 100644 --- a/clang/test/Driver/loongarch-mtune.c +++ b/clang/test/Driver/loongarch-mtune.c @@ -8,6 +8,11 @@ // RUN: %clang --target=loongarch64 -mtune=la464 -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IRATTR -DCPU=la464 +// RUN: %clang --target=loongarch64 -mtune=la664 -fsyntax-only %s -### 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CC1ARG -DCPU=la664 +// RUN: %clang --target=loongarch64 -mtune=la664 -S -emit-llvm %s -o - | \ +// RUN: FileCheck %s --check-prefix=IRATTR -DCPU=la664 + // RUN: %clang --target=loongarch64 -mtune=invalidcpu -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1ARG -DCPU=invalidcpu // RUN: not %clang --target=loongarch64 -mtune=invalidcpu -S -emit-llvm %s -o /dev/null 2>&1 | \ diff --git a/clang/test/Preprocessor/init-loongarch.c b/clang/test/Preprocessor/init-loongarch.c index 788faac2f857e..3d111d77769ed 100644 --- a/clang/test/Preprocessor/init-loongarch.c +++ b/clang/test/Preprocessor/init-loongarch.c @@ -832,6 +832,14 @@ // RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=loongarch64 -DTUNE=loongarch64 %s // RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -Xclang -target-feature -Xclang +lsx -Xclang -target-feature -Xclang +frecipe | \ // RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la64v1.1 -DTUNE=loongarch64 %s +// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 | \ +// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la664 -DTUNE=la664 %s +// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=la664 | \ +// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s +// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -mtune=la664 | \ +// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s +// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 -mtune=loongarch64 | \ +// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la664 -DTUNE=loongarch64 %s // ARCH-TUNE: #define __loongarch_arch "[[ARCH]]" // FRECIPE: #define __loongarch_frecipe 1 diff --git a/llvm/include/llvm/TargetParser/LoongArchTargetParser.def b/llvm/include/llvm/TargetParser/LoongArchTargetParser.def index b20d124953f88..101a48cbd5399 100644 --- a/llvm/include/llvm/TargetParser/LoongArchTargetParser.def +++ b/llvm/include/llvm/TargetParser/LoongArchTargetParser.def @@ -10,6 +10,7 @@ LOONGARCH_FEATURE("+lasx", FK_LASX) LOONGARCH_FEATURE("+lbt", FK_LBT) LOONGARCH_FEATURE("+lvz", FK_LVZ) LOONGARCH_FEATURE("+ual", FK_UAL) +LOONGARCH_FEATURE("+frecipe", FK_FRECIPE) #undef LOONGARCH_FEATURE @@ -19,5 +20,6 @@ LOONGARCH_FEATURE("+ual", FK_UAL) 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) #undef LOONGARCH_ARCH diff --git a/llvm/include/llvm/TargetParser/LoongArchTargetParser.h b/llvm/include/llvm/TargetParser/LoongArchTargetParser.h index 028844187584b..c0bb15a5163b1 100644 --- a/llvm/include/llvm/TargetParser/LoongArchTargetParser.h +++ b/llvm/include/llvm/TargetParser/LoongArchTargetParser.h @@ -46,6 +46,9 @@ enum FeatureKind : uint32_t { // Allow memory accesses to be unaligned. FK_UAL = 1 << 8, + + // Floating-point approximate reciprocal instructions are available. + FK_FRECIPE = 1 << 9, }; struct FeatureInfo { diff --git a/llvm/lib/Target/LoongArch/LoongArch.td b/llvm/lib/Target/LoongArch/LoongArch.td index 8a628157c6018..70bc1a582cd3e 100644 --- a/llvm/lib/Target/LoongArch/LoongArch.td +++ b/llvm/lib/Target/LoongArch/LoongArch.td @@ -151,6 +151,13 @@ def : ProcessorModel<"la464", NoSchedModel, [Feature64Bit, FeatureExtLVZ, FeatureExtLBT]>; +def : ProcessorModel<"la664", NoSchedModel, [Feature64Bit, + FeatureUAL, + FeatureExtLASX, + FeatureExtLVZ, + FeatureExtLBT, + FeatureFrecipe]>; + //===----------------------------------------------------------------------===// // Define the LoongArch target. //===----------------------------------------------------------------------===// diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index 82c1731f58f0a..7b5dfc67660d6 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1562,6 +1562,8 @@ StringRef sys::getHostCPUName() { switch (processor_id & 0xf000) { case 0xc000: // Loongson 64bit, 4-issue return "la464"; + case 0xd000: // Loongson 64bit, 6-issue + return "la664"; // TODO: Others. default: break; diff --git a/llvm/test/CodeGen/LoongArch/cpus.ll b/llvm/test/CodeGen/LoongArch/cpus.ll index 41ff1be496e3b..be3e05e394ff9 100644 --- a/llvm/test/CodeGen/LoongArch/cpus.ll +++ b/llvm/test/CodeGen/LoongArch/cpus.ll @@ -3,6 +3,7 @@ ; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=loongarch64 2>&1 | FileCheck %s ; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=la464 2>&1 | FileCheck %s +; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=la664 2>&1 | FileCheck %s ; RUN: llc < %s --mtriple=loongarch64 -mattr=+d 2>&1 | FileCheck %s ; CHECK-NOT: {{.*}} is not a recognized processor for this target @@ -18,3 +19,7 @@ define void @tune_cpu_loongarch64() "tune-cpu"="loongarch64" { define void @tune_cpu_la464() "tune-cpu"="la464" { ret void } + +define void @tune_cpu_la664() "tune-cpu"="la664" { + ret void +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits