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
}
}
+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();
}
break;
+ case llvm::Triple::loongarch32:
+ case llvm::Triple::loongarch64:
+ AddLoongArchTargetArgs(Args, CmdArgs);
+ break;
+
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
AddRISCVTargetArgs(Args, CmdArgs);
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,
#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"
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:
--- /dev/null
+/// 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]]"
--- /dev/null
+/// 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]]"