Skip to content

Commit ddb27b1

Browse files
committed
[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
1 parent 2cf0314 commit ddb27b1

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7945,6 +7945,14 @@ void ClangAs::AddX86TargetArgs(const ArgList &Args,
79457945
}
79467946
}
79477947

7948+
void ClangAs::AddLoongArchTargetArgs(const ArgList &Args,
7949+
ArgStringList &CmdArgs) const {
7950+
CmdArgs.push_back("-target-abi");
7951+
CmdArgs.push_back(loongarch::getLoongArchABI(getToolChain().getDriver(), Args,
7952+
getToolChain().getTriple())
7953+
.data());
7954+
}
7955+
79487956
void ClangAs::AddRISCVTargetArgs(const ArgList &Args,
79497957
ArgStringList &CmdArgs) const {
79507958
const llvm::Triple &Triple = getToolChain().getTriple();
@@ -8143,6 +8151,11 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
81438151
}
81448152
break;
81458153

8154+
case llvm::Triple::loongarch32:
8155+
case llvm::Triple::loongarch64:
8156+
AddLoongArchTargetArgs(Args, CmdArgs);
8157+
break;
8158+
81468159
case llvm::Triple::riscv32:
81478160
case llvm::Triple::riscv64:
81488161
AddRISCVTargetArgs(Args, CmdArgs);

clang/lib/Driver/ToolChains/Clang.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
125125
public:
126126
ClangAs(const ToolChain &TC)
127127
: Tool("clang::as", "clang integrated assembler", TC) {}
128+
void AddLoongArchTargetArgs(const llvm::opt::ArgList &Args,
129+
llvm::opt::ArgStringList &CmdArgs) const;
128130
void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
129131
llvm::opt::ArgStringList &CmdArgs) const;
130132
void AddX86TargetArgs(const llvm::opt::ArgList &Args,

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Gnu.h"
1010
#include "Arch/ARM.h"
1111
#include "Arch/CSKY.h"
12+
#include "Arch/LoongArch.h"
1213
#include "Arch/Mips.h"
1314
#include "Arch/PPC.h"
1415
#include "Arch/RISCV.h"
@@ -859,6 +860,13 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
859860

860861
break;
861862
}
863+
// TODO: handle loongarch32.
864+
case llvm::Triple::loongarch64: {
865+
StringRef ABIName =
866+
loongarch::getLoongArchABI(D, Args, getToolChain().getTriple());
867+
CmdArgs.push_back(Args.MakeArgString("-mabi=" + ABIName));
868+
break;
869+
}
862870
case llvm::Triple::mips:
863871
case llvm::Triple::mipsel:
864872
case llvm::Triple::mips64:

clang/test/Driver/loongarch-as.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// This file checks options are correctly passed to as for LoongArch targets.
2+
3+
/// Check `-mabi`.
4+
// RUN: %clang --target=loongarch64 -### -fno-integrated-as -c %s 2>&1 | \
5+
// RUN: FileCheck -DABI=lp64d --check-prefix=ABI %s
6+
// RUN: %clang --target=loongarch64 -mabi=lp64d -### -fno-integrated-as -c %s 2>&1 | \
7+
// RUN: FileCheck -DABI=lp64d --check-prefix=ABI %s
8+
// RUN: %clang --target=loongarch64 -mabi=lp64f -### -fno-integrated-as -c %s 2>&1 | \
9+
// RUN: FileCheck -DABI=lp64f --check-prefix=ABI %s
10+
// RUN: %clang --target=loongarch64 -mabi=lp64s -### -fno-integrated-as -c %s 2>&1 | \
11+
// RUN: FileCheck -DABI=lp64s --check-prefix=ABI %s
12+
13+
// ALL: as
14+
15+
// ABI: "-mabi=[[ABI]]"

clang/test/Driver/loongarch-ias.s

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// This file checks options are correctly passed to cc1as for LoongArch targets.
2+
3+
/// Check `-target-abi`.
4+
// RUN: %clang --target=loongarch32 -### -fintegrated-as -c %s 2>&1 | \
5+
// RUN: FileCheck -DABI=ilp32d --check-prefix=ABI %s
6+
// RUN: %clang --target=loongarch32 -mabi=ilp32d -### -fintegrated-as -c %s 2>&1 | \
7+
// RUN: FileCheck -DABI=ilp32d --check-prefix=ABI %s
8+
// RUN: %clang --target=loongarch32 -mabi=ilp32f -### -fintegrated-as -c %s 2>&1 | \
9+
// RUN: FileCheck -DABI=ilp32f --check-prefix=ABI %s
10+
// RUN: %clang --target=loongarch32 -mabi=ilp32s -### -fintegrated-as -c %s 2>&1 | \
11+
// RUN: FileCheck -DABI=ilp32s --check-prefix=ABI %s
12+
// RUN: %clang --target=loongarch64 -### -fintegrated-as -c %s 2>&1 | \
13+
// RUN: FileCheck -DABI=lp64d --check-prefix=ABI %s
14+
// RUN: %clang --target=loongarch64 -mabi=lp64d -### -fintegrated-as -c %s 2>&1 | \
15+
// RUN: FileCheck -DABI=lp64d --check-prefix=ABI %s
16+
// RUN: %clang --target=loongarch64 -mabi=lp64f -### -fintegrated-as -c %s 2>&1 | \
17+
// RUN: FileCheck -DABI=lp64f --check-prefix=ABI %s
18+
// RUN: %clang --target=loongarch64 -mabi=lp64s -### -fintegrated-as -c %s 2>&1 | \
19+
// RUN: FileCheck -DABI=lp64s --check-prefix=ABI %s
20+
21+
// ALL: -cc1as
22+
23+
// ABI: "-target-abi" "[[ABI]]"

0 commit comments

Comments
 (0)