[clang] ddb27b1 - [Clang][LoongArch] Pass the -mabi and -target-abi options to as and cc1as respectively
Weining Lu via cfe-commits
cfe-commits at lists.llvm.org
Tue May 16 06:11:08 PDT 2023
Author: Weining Lu
Date: 2023-05-16T21:10:15+08:00
New Revision: ddb27b1870691595173608ce0c4a0c70ad16513d
URL: https://github.com/llvm/llvm-project/commit/ddb27b1870691595173608ce0c4a0c70ad16513d
DIFF: https://github.com/llvm/llvm-project/commit/ddb27b1870691595173608ce0c4a0c70ad16513d.diff
LOG: [Clang][LoongArch] Pass the -mabi and -target-abi options to as and cc1as respectively
This change is necessary to set correct EFlags according to the
options (-m*-float and -mabi=) passed to clang when input is assembly.
Note: `-mabi=` is not documented by `as`.
```
$ as --version
GNU assembler (GNU Binutils) 2.40.50.20230316
...
$ as --target-help
LARCH options:
```
But we can see gcc invokes `as` and passes the `-mabi=` option when compiling C or assembly.
```
$ gcc -c a.c -v 2>&1 -msoft-float | grep "as -v"
as -v -mabi=lp64s -o a.o /tmp/ccFrxzZi.s
$ gcc -c a.s -v 2>&1 -msoft-float | grep "as -v"
as -v -mabi=lp64s -o a.o a.s
```
Reviewed By: xen0n
Differential Revision: https://reviews.llvm.org/D150537
Added:
clang/test/Driver/loongarch-as.s
clang/test/Driver/loongarch-ias.s
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Clang.h
clang/lib/Driver/ToolChains/Gnu.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index a230bc45a08fc..f057e21c17799 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7945,6 +7945,14 @@ void ClangAs::AddX86TargetArgs(const ArgList &Args,
}
}
+void ClangAs::AddLoongArchTargetArgs(const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+ CmdArgs.push_back("-target-abi");
+ CmdArgs.push_back(loongarch::getLoongArchABI(getToolChain().getDriver(), Args,
+ getToolChain().getTriple())
+ .data());
+}
+
void ClangAs::AddRISCVTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
const llvm::Triple &Triple = getToolChain().getTriple();
@@ -8143,6 +8151,11 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
}
break;
+ case llvm::Triple::loongarch32:
+ case llvm::Triple::loongarch64:
+ AddLoongArchTargetArgs(Args, CmdArgs);
+ break;
+
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
AddRISCVTargetArgs(Args, CmdArgs);
diff --git a/clang/lib/Driver/ToolChains/Clang.h b/clang/lib/Driver/ToolChains/Clang.h
index 12e13e2acd862..64fc86b6b0a78 100644
--- a/clang/lib/Driver/ToolChains/Clang.h
+++ b/clang/lib/Driver/ToolChains/Clang.h
@@ -125,6 +125,8 @@ class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
public:
ClangAs(const ToolChain &TC)
: Tool("clang::as", "clang integrated assembler", TC) {}
+ void AddLoongArchTargetArgs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const;
void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
void AddX86TargetArgs(const llvm::opt::ArgList &Args,
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index b0716322bc141..3be65bae81a3d 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -9,6 +9,7 @@
#include "Gnu.h"
#include "Arch/ARM.h"
#include "Arch/CSKY.h"
+#include "Arch/LoongArch.h"
#include "Arch/Mips.h"
#include "Arch/PPC.h"
#include "Arch/RISCV.h"
@@ -859,6 +860,13 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
break;
}
+ // TODO: handle loongarch32.
+ case llvm::Triple::loongarch64: {
+ StringRef ABIName =
+ loongarch::getLoongArchABI(D, Args, getToolChain().getTriple());
+ CmdArgs.push_back(Args.MakeArgString("-mabi=" + ABIName));
+ break;
+ }
case llvm::Triple::mips:
case llvm::Triple::mipsel:
case llvm::Triple::mips64:
diff --git a/clang/test/Driver/loongarch-as.s b/clang/test/Driver/loongarch-as.s
new file mode 100644
index 0000000000000..6f6d87f6ac65c
--- /dev/null
+++ b/clang/test/Driver/loongarch-as.s
@@ -0,0 +1,15 @@
+/// This file checks options are correctly passed to as for LoongArch targets.
+
+/// Check `-mabi`.
+// RUN: %clang --target=loongarch64 -### -fno-integrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=lp64d --check-prefix=ABI %s
+// RUN: %clang --target=loongarch64 -mabi=lp64d -### -fno-integrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=lp64d --check-prefix=ABI %s
+// RUN: %clang --target=loongarch64 -mabi=lp64f -### -fno-integrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=lp64f --check-prefix=ABI %s
+// RUN: %clang --target=loongarch64 -mabi=lp64s -### -fno-integrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=lp64s --check-prefix=ABI %s
+
+// ALL: as
+
+// ABI: "-mabi=[[ABI]]"
diff --git a/clang/test/Driver/loongarch-ias.s b/clang/test/Driver/loongarch-ias.s
new file mode 100644
index 0000000000000..6fec9e6e15919
--- /dev/null
+++ b/clang/test/Driver/loongarch-ias.s
@@ -0,0 +1,23 @@
+/// This file checks options are correctly passed to cc1as for LoongArch targets.
+
+/// Check `-target-abi`.
+// RUN: %clang --target=loongarch32 -### -fintegrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=ilp32d --check-prefix=ABI %s
+// RUN: %clang --target=loongarch32 -mabi=ilp32d -### -fintegrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=ilp32d --check-prefix=ABI %s
+// RUN: %clang --target=loongarch32 -mabi=ilp32f -### -fintegrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=ilp32f --check-prefix=ABI %s
+// RUN: %clang --target=loongarch32 -mabi=ilp32s -### -fintegrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=ilp32s --check-prefix=ABI %s
+// RUN: %clang --target=loongarch64 -### -fintegrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=lp64d --check-prefix=ABI %s
+// RUN: %clang --target=loongarch64 -mabi=lp64d -### -fintegrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=lp64d --check-prefix=ABI %s
+// RUN: %clang --target=loongarch64 -mabi=lp64f -### -fintegrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=lp64f --check-prefix=ABI %s
+// RUN: %clang --target=loongarch64 -mabi=lp64s -### -fintegrated-as -c %s 2>&1 | \
+// RUN: FileCheck -DABI=lp64s --check-prefix=ABI %s
+
+// ALL: -cc1as
+
+// ABI: "-target-abi" "[[ABI]]"
More information about the cfe-commits
mailing list