Skip to content

[Flang][LoongArch] Enable clang command-line options in flang. #118244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

ylzsx
Copy link
Contributor

@ylzsx ylzsx commented Dec 2, 2024

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

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
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' flang:driver flang Flang issues not falling into any other category labels Dec 2, 2024
@ylzsx ylzsx requested a review from SixWeining December 2, 2024 02:33
@llvmbot
Copy link
Member

llvmbot commented Dec 2, 2024

@llvm/pr-subscribers-flang-driver
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Zhaoxin Yang (ylzsx)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/118244.diff

3 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+2-1)
  • (modified) clang/lib/Driver/ToolChains/Flang.cpp (+8)
  • (added) flang/test/Driver/options-loongarch.f90 (+43)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 9c356c9d2ea4ef..7b8e2660192580 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -240,7 +240,8 @@ def m_riscv_Features_Group : OptionGroup<"<riscv features group>">,
 def m_ve_Features_Group : OptionGroup<"<ve features group>">,
                           Group<m_Group>, DocName<"VE">;
 def m_loongarch_Features_Group : OptionGroup<"<loongarch features group>">,
-                                 Group<m_Group>, DocName<"LoongArch">;
+                                 Group<m_Group>, DocName<"LoongArch">,
+                                 Visibility<[ClangOption, CLOption, FlangOption]>;
 
 def m_libc_Group : OptionGroup<"<m libc group>">, Group<m_mips_Features_Group>,
                    Flags<[HelpHidden]>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 8c18c88fbde7f7..02323b90b65473 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -213,6 +213,14 @@ void Flang::AddLoongArch64TargetArgs(const ArgList &Args,
       D.Diag(diag::err_drv_argument_not_allowed_with) << "-mabi" << V;
     }
   }
+
+  if (const Arg *A = Args.getLastArg(options::OPT_mannotate_tablejump,
+                                     options::OPT_mno_annotate_tablejump)) {
+    if (A->getOption().matches(options::OPT_mannotate_tablejump)) {
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-loongarch-annotate-tablejump");
+    }
+  }
 }
 
 void Flang::AddPPCTargetArgs(const ArgList &Args,
diff --git a/flang/test/Driver/options-loongarch.f90 b/flang/test/Driver/options-loongarch.f90
new file mode 100644
index 00000000000000..717bf6385b06d7
--- /dev/null
+++ b/flang/test/Driver/options-loongarch.f90
@@ -0,0 +1,43 @@
+!! This test tests options from clang, which are also supported by flang in LoongArch.
+
+! RUN: %flang -c --target=loongarch64-unknown-linux -mlsx %s -### 2>&1 | FileCheck --check-prefixes=LSX,NOLASX %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mno-lsx %s -### 2>&1 | FileCheck --check-prefixes=NOLSX,NOLASX %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mlasx %s -### 2>&1 | FileCheck --check-prefixes=LSX,LASX %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mno-lasx %s -### 2>&1 | FileCheck --check-prefixes=LSX,NOLASX %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -msimd=none %s -### 2>&1 | FileCheck --check-prefixes=NOLSX,NOLASX %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -msimd=lsx %s -### 2>&1 | FileCheck --check-prefixes=LSX,NOLASX %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -msimd=lasx %s -### 2>&1 | FileCheck --check-prefixes=LSX,LASX %s
+! RUN: not %flang -c --target=loongarch64-unknown-linux -msimd=supper %s -### 2>&1 | FileCheck --check-prefix=MSIMD-INVALID %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mfrecipe %s -### 2>&1 | FileCheck --check-prefix=FRECIPE %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mno-frecipe %s -### 2>&1 | FileCheck --check-prefix=NOFRECIPE %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mlam-bh %s -### 2>&1 | FileCheck --check-prefix=LAMBH %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mno-lam-bh %s -### 2>&1 | FileCheck --check-prefix=NOLAMBH %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mlamcas %s -### 2>&1 | FileCheck --check-prefix=LAMCAS %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mno-lamcas %s -### 2>&1 | FileCheck --check-prefix=NOLAMCAS %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mld-seq-sa %s -### 2>&1 | FileCheck --check-prefix=LD-SEQ-SA %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mno-ld-seq-sa %s -### 2>&1 | FileCheck --check-prefix=NOLD-SEQ-SA %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mdiv32 %s -### 2>&1 | FileCheck --check-prefix=DIV32 %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mno-div32 %s -### 2>&1 | FileCheck --check-prefix=NODIV32 %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mannotate-tablejump %s -### 2>&1 | FileCheck --check-prefix=ANOTATE %s
+! RUN: %flang -c --target=loongarch64-unknown-linux -mno-annotate-tablejump %s -### 2>&1 | FileCheck --check-prefix=NOANOTATE %s
+
+! MSIMD-INVALID: error: invalid argument 'supper' to -msimd=; must be one of: none, lsx, lasx
+! FRECIPE: "-target-feature" "+frecipe"
+! NOFRECIPE-NOT: "-target-feature" "+frecipe"
+! LAMBH: "-target-feature" "+lam-bh"
+! NOLAMBH-NOT: "-target-feature" "+lam-bh"
+! LAMCAS: "-target-feature" "+lamcas"
+! NOLAMCAS-NOT: "-target-feature" "+lamcas"
+! LD-SEQ-SA: "-target-feature" "+ld-seq-sa"
+! NOLD-SEQ-SA-NOT: "-target-feature" "+ld-seq-sa"
+! DIV32: "-target-feature" "+div32"
+! NODIV32-NOT: "-target-feature" "+div32"
+! ANOTATE: "-mllvm" "-loongarch-annotate-tablejump"
+! NOANOTATE-NOT: "-loongarch-annotate-tablejump"
+
+! NOLSX-NOT: "-target-feature" "+lsx"
+! NOLASX-NOT: "-target-feature" "+lasx"
+! LSX-DAG: "-target-feature" "+lsx"
+! LASX-DAG: "-target-feature" "+lasx"
+! NOLSX-NOT: "-target-feature" "+lsx"
+! NOLASX-NOT: "-target-feature" "+lasx"

Copy link
Contributor

@SixWeining SixWeining left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the LoongArch bits.

Copy link
Member

@DavidTruby DavidTruby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@zhaoqi5 zhaoqi5 merged commit 669f704 into llvm:main Dec 9, 2024
13 checks passed
@ylzsx ylzsx deleted the cmd-option-enable branch December 25, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category flang:driver flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants