Skip to content

Commit 669f704

Browse files
authored
[Flang][LoongArch] Enable clang command-line options in flang. (#118244)
Mainly including the following LoongArch specific options: -m[no-]lsx, -m[no-]lasx, -msimd=, -m[no-]frecipe, -m[no-]lam-bh, -m[no-]lamcas, -m[no-]ld-seq-sa, -m[no-]div32, -m[no-]annotate-tablejump
1 parent 078b60d commit 669f704

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def m_riscv_Features_Group : OptionGroup<"<riscv features group>">,
240240
def m_ve_Features_Group : OptionGroup<"<ve features group>">,
241241
Group<m_Group>, DocName<"VE">;
242242
def m_loongarch_Features_Group : OptionGroup<"<loongarch features group>">,
243-
Group<m_Group>, DocName<"LoongArch">;
243+
Group<m_Group>, DocName<"LoongArch">,
244+
Visibility<[ClangOption, CLOption, FlangOption]>;
244245

245246
def m_libc_Group : OptionGroup<"<m libc group>">, Group<m_mips_Features_Group>,
246247
Flags<[HelpHidden]>;

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ void Flang::AddLoongArch64TargetArgs(const ArgList &Args,
213213
D.Diag(diag::err_drv_argument_not_allowed_with) << "-mabi" << V;
214214
}
215215
}
216+
217+
if (const Arg *A = Args.getLastArg(options::OPT_mannotate_tablejump,
218+
options::OPT_mno_annotate_tablejump)) {
219+
if (A->getOption().matches(options::OPT_mannotate_tablejump)) {
220+
CmdArgs.push_back("-mllvm");
221+
CmdArgs.push_back("-loongarch-annotate-tablejump");
222+
}
223+
}
216224
}
217225

218226
void Flang::AddPPCTargetArgs(const ArgList &Args,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
!! This test tests options from clang, which are also supported by flang in LoongArch.
2+
3+
! RUN: %flang -c --target=loongarch64-unknown-linux -mlsx %s -### 2>&1 | FileCheck --check-prefixes=LSX,NOLASX %s
4+
! RUN: %flang -c --target=loongarch64-unknown-linux -mno-lsx %s -### 2>&1 | FileCheck --check-prefixes=NOLSX,NOLASX %s
5+
! RUN: %flang -c --target=loongarch64-unknown-linux -mlasx %s -### 2>&1 | FileCheck --check-prefixes=LSX,LASX %s
6+
! RUN: %flang -c --target=loongarch64-unknown-linux -mno-lasx %s -### 2>&1 | FileCheck --check-prefixes=LSX,NOLASX %s
7+
! RUN: %flang -c --target=loongarch64-unknown-linux -msimd=none %s -### 2>&1 | FileCheck --check-prefixes=NOLSX,NOLASX %s
8+
! RUN: %flang -c --target=loongarch64-unknown-linux -msimd=lsx %s -### 2>&1 | FileCheck --check-prefixes=LSX,NOLASX %s
9+
! RUN: %flang -c --target=loongarch64-unknown-linux -msimd=lasx %s -### 2>&1 | FileCheck --check-prefixes=LSX,LASX %s
10+
! RUN: not %flang -c --target=loongarch64-unknown-linux -msimd=supper %s -### 2>&1 | FileCheck --check-prefix=MSIMD-INVALID %s
11+
! RUN: %flang -c --target=loongarch64-unknown-linux -mfrecipe %s -### 2>&1 | FileCheck --check-prefix=FRECIPE %s
12+
! RUN: %flang -c --target=loongarch64-unknown-linux -mno-frecipe %s -### 2>&1 | FileCheck --check-prefix=NOFRECIPE %s
13+
! RUN: %flang -c --target=loongarch64-unknown-linux -mlam-bh %s -### 2>&1 | FileCheck --check-prefix=LAMBH %s
14+
! RUN: %flang -c --target=loongarch64-unknown-linux -mno-lam-bh %s -### 2>&1 | FileCheck --check-prefix=NOLAMBH %s
15+
! RUN: %flang -c --target=loongarch64-unknown-linux -mlamcas %s -### 2>&1 | FileCheck --check-prefix=LAMCAS %s
16+
! RUN: %flang -c --target=loongarch64-unknown-linux -mno-lamcas %s -### 2>&1 | FileCheck --check-prefix=NOLAMCAS %s
17+
! RUN: %flang -c --target=loongarch64-unknown-linux -mld-seq-sa %s -### 2>&1 | FileCheck --check-prefix=LD-SEQ-SA %s
18+
! RUN: %flang -c --target=loongarch64-unknown-linux -mno-ld-seq-sa %s -### 2>&1 | FileCheck --check-prefix=NOLD-SEQ-SA %s
19+
! RUN: %flang -c --target=loongarch64-unknown-linux -mdiv32 %s -### 2>&1 | FileCheck --check-prefix=DIV32 %s
20+
! RUN: %flang -c --target=loongarch64-unknown-linux -mno-div32 %s -### 2>&1 | FileCheck --check-prefix=NODIV32 %s
21+
! RUN: %flang -c --target=loongarch64-unknown-linux -mannotate-tablejump %s -### 2>&1 | FileCheck --check-prefix=ANOTATE %s
22+
! RUN: %flang -c --target=loongarch64-unknown-linux -mno-annotate-tablejump %s -### 2>&1 | FileCheck --check-prefix=NOANOTATE %s
23+
24+
! MSIMD-INVALID: error: invalid argument 'supper' to -msimd=; must be one of: none, lsx, lasx
25+
! FRECIPE: "-target-feature" "+frecipe"
26+
! NOFRECIPE-NOT: "-target-feature" "+frecipe"
27+
! LAMBH: "-target-feature" "+lam-bh"
28+
! NOLAMBH-NOT: "-target-feature" "+lam-bh"
29+
! LAMCAS: "-target-feature" "+lamcas"
30+
! NOLAMCAS-NOT: "-target-feature" "+lamcas"
31+
! LD-SEQ-SA: "-target-feature" "+ld-seq-sa"
32+
! NOLD-SEQ-SA-NOT: "-target-feature" "+ld-seq-sa"
33+
! DIV32: "-target-feature" "+div32"
34+
! NODIV32-NOT: "-target-feature" "+div32"
35+
! ANOTATE: "-mllvm" "-loongarch-annotate-tablejump"
36+
! NOANOTATE-NOT: "-loongarch-annotate-tablejump"
37+
38+
! NOLSX-NOT: "-target-feature" "+lsx"
39+
! NOLASX-NOT: "-target-feature" "+lasx"
40+
! LSX-DAG: "-target-feature" "+lsx"
41+
! LASX-DAG: "-target-feature" "+lasx"
42+
! NOLSX-NOT: "-target-feature" "+lsx"
43+
! NOLASX-NOT: "-target-feature" "+lasx"

0 commit comments

Comments
 (0)