Skip to content

Commit fcec298

Browse files
authored
[LoongArch] Support la664 (#100068)
A new ProcessorModel called `la664` is defined in LoongArch.td to support `-march/-mtune=la664`.
1 parent 70e7d26 commit fcec298

File tree

8 files changed

+43
-0
lines changed

8 files changed

+43
-0
lines changed

clang/test/Driver/loongarch-march.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// RUN: FileCheck %s --check-prefix=CC1-LA64V1P0
77
// RUN: %clang --target=loongarch64 -march=la64v1.1 -fsyntax-only %s -### 2>&1 | \
88
// RUN: FileCheck %s --check-prefix=CC1-LA64V1P1
9+
// RUN: %clang --target=loongarch64 -march=la664 -fsyntax-only %s -### 2>&1 | \
10+
// RUN: FileCheck %s --check-prefix=CC1-LA664
911
// RUN: %clang --target=loongarch64 -march=loongarch64 -S -emit-llvm %s -o - | \
1012
// RUN: FileCheck %s --check-prefix=IR-LOONGARCH64
1113
// RUN: %clang --target=loongarch64 -march=la464 -S -emit-llvm %s -o - | \
@@ -14,6 +16,8 @@
1416
// RUN: FileCheck %s --check-prefix=IR-LA64V1P0
1517
// RUN: %clang --target=loongarch64 -march=la64v1.1 -S -emit-llvm %s -o - | \
1618
// RUN: FileCheck %s --check-prefix=IR-LA64V1P1
19+
// RUN: %clang --target=loongarch64 -march=la664 -S -emit-llvm %s -o - | \
20+
// RUN: FileCheck %s --check-prefix=IR-LA664
1721

1822
// CC1-LOONGARCH64: "-target-cpu" "loongarch64"
1923
// CC1-LOONGARCH64-NOT: "-target-feature"
@@ -39,10 +43,17 @@
3943
// CC1-LA64V1P1-NOT: "-target-feature"
4044
// CC1-LA64V1P1: "-target-abi" "lp64d"
4145

46+
// CC1-LA664: "-target-cpu" "la664"
47+
// 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"
49+
// CC1-LA664-NOT: "-target-feature"
50+
// CC1-LA664: "-target-abi" "lp64d"
51+
4252
// IR-LOONGARCH64: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+f,+ual"
4353
// IR-LA464: attributes #[[#]] ={{.*}}"target-cpu"="la464" {{.*}}"target-features"="+64bit,+d,+f,+lasx,+lsx,+ual"
4454
// IR-LA64V1P0: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+lsx,+ual"
4555
// IR-LA64V1P1: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+frecipe,+lsx,+ual"
56+
// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+f,+frecipe,+lasx,+lsx,+ual"
4657

4758
int foo(void) {
4859
return 3;

clang/test/Driver/loongarch-mtune.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// RUN: %clang --target=loongarch64 -mtune=la464 -S -emit-llvm %s -o - | \
99
// RUN: FileCheck %s --check-prefix=IRATTR -DCPU=la464
1010

11+
// RUN: %clang --target=loongarch64 -mtune=la664 -fsyntax-only %s -### 2>&1 | \
12+
// RUN: FileCheck %s --check-prefix=CC1ARG -DCPU=la664
13+
// RUN: %clang --target=loongarch64 -mtune=la664 -S -emit-llvm %s -o - | \
14+
// RUN: FileCheck %s --check-prefix=IRATTR -DCPU=la664
15+
1116
// RUN: %clang --target=loongarch64 -mtune=invalidcpu -fsyntax-only %s -### 2>&1 | \
1217
// RUN: FileCheck %s --check-prefix=CC1ARG -DCPU=invalidcpu
1318
// RUN: not %clang --target=loongarch64 -mtune=invalidcpu -S -emit-llvm %s -o /dev/null 2>&1 | \

clang/test/Preprocessor/init-loongarch.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,14 @@
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.1 -DTUNE=loongarch64 %s
835+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 | \
836+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la664 -DTUNE=la664 %s
837+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=la664 | \
838+
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s
839+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -mtune=la664 | \
840+
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la664 %s
841+
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la664 -mtune=loongarch64 | \
842+
// RUN: FileCheck --match-full-lines --check-prefixes=ARCH-TUNE,FRECIPE -DARCH=la664 -DTUNE=loongarch64 %s
835843

836844
// ARCH-TUNE: #define __loongarch_arch "[[ARCH]]"
837845
// FRECIPE: #define __loongarch_frecipe 1

llvm/include/llvm/TargetParser/LoongArchTargetParser.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LOONGARCH_FEATURE("+lasx", FK_LASX)
1010
LOONGARCH_FEATURE("+lbt", FK_LBT)
1111
LOONGARCH_FEATURE("+lvz", FK_LVZ)
1212
LOONGARCH_FEATURE("+ual", FK_UAL)
13+
LOONGARCH_FEATURE("+frecipe", FK_FRECIPE)
1314

1415
#undef LOONGARCH_FEATURE
1516

@@ -19,5 +20,6 @@ LOONGARCH_FEATURE("+ual", FK_UAL)
1920

2021
LOONGARCH_ARCH("loongarch64", AK_LOONGARCH64, FK_64BIT | FK_FP32 | FK_FP64 | FK_UAL)
2122
LOONGARCH_ARCH("la464", AK_LA464, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | FK_LASX | FK_UAL)
23+
LOONGARCH_ARCH("la664", AK_LA664, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | FK_LASX | FK_UAL | FK_FRECIPE)
2224

2325
#undef LOONGARCH_ARCH

llvm/include/llvm/TargetParser/LoongArchTargetParser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ enum FeatureKind : uint32_t {
4646

4747
// Allow memory accesses to be unaligned.
4848
FK_UAL = 1 << 8,
49+
50+
// Floating-point approximate reciprocal instructions are available.
51+
FK_FRECIPE = 1 << 9,
4952
};
5053

5154
struct FeatureInfo {

llvm/lib/Target/LoongArch/LoongArch.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ def : ProcessorModel<"la464", NoSchedModel, [Feature64Bit,
151151
FeatureExtLVZ,
152152
FeatureExtLBT]>;
153153

154+
def : ProcessorModel<"la664", NoSchedModel, [Feature64Bit,
155+
FeatureUAL,
156+
FeatureExtLASX,
157+
FeatureExtLVZ,
158+
FeatureExtLBT,
159+
FeatureFrecipe]>;
160+
154161
//===----------------------------------------------------------------------===//
155162
// Define the LoongArch target.
156163
//===----------------------------------------------------------------------===//

llvm/lib/TargetParser/Host.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,8 @@ StringRef sys::getHostCPUName() {
15621562
switch (processor_id & 0xf000) {
15631563
case 0xc000: // Loongson 64bit, 4-issue
15641564
return "la464";
1565+
case 0xd000: // Loongson 64bit, 6-issue
1566+
return "la664";
15651567
// TODO: Others.
15661568
default:
15671569
break;

llvm/test/CodeGen/LoongArch/cpus.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=loongarch64 2>&1 | FileCheck %s
55
; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=la464 2>&1 | FileCheck %s
6+
; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=la664 2>&1 | FileCheck %s
67
; RUN: llc < %s --mtriple=loongarch64 -mattr=+d 2>&1 | FileCheck %s
78

89
; CHECK-NOT: {{.*}} is not a recognized processor for this target
@@ -18,3 +19,7 @@ define void @tune_cpu_loongarch64() "tune-cpu"="loongarch64" {
1819
define void @tune_cpu_la464() "tune-cpu"="la464" {
1920
ret void
2021
}
22+
23+
define void @tune_cpu_la664() "tune-cpu"="la664" {
24+
ret void
25+
}

0 commit comments

Comments
 (0)