Skip to content

Commit 3041001

Browse files
authored
[LoongArch] Enable all -target-abi options
This is a pre-commit for modifying `computeTargetABI` logic. This patch will provide warning prompts when using those ABIs that have not yet been standardized. Reviewed By: xen0n, SixWeining Pull Request: llvm#92222
1 parent ca02f36 commit 3041001

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,15 +3575,14 @@ static bool CC_LoongArch(const DataLayout &DL, LoongArchABI::ABI ABI,
35753575
switch (ABI) {
35763576
default:
35773577
llvm_unreachable("Unexpected ABI");
3578-
case LoongArchABI::ABI_ILP32S:
3578+
break;
35793579
case LoongArchABI::ABI_ILP32F:
35803580
case LoongArchABI::ABI_LP64F:
3581-
report_fatal_error("Unimplemented ABI");
3582-
break;
35833581
case LoongArchABI::ABI_ILP32D:
35843582
case LoongArchABI::ABI_LP64D:
35853583
UseGPRForFloat = !IsFixed;
35863584
break;
3585+
case LoongArchABI::ABI_ILP32S:
35873586
case LoongArchABI::ABI_LP64S:
35883587
break;
35893588
}

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,41 @@
1414
#include "LoongArchBaseInfo.h"
1515
#include "llvm/ADT/ArrayRef.h"
1616
#include "llvm/MC/MCSubtargetInfo.h"
17+
#include "llvm/Support/ErrorHandling.h"
1718
#include "llvm/Support/raw_ostream.h"
1819
#include "llvm/TargetParser/Triple.h"
1920

2021
namespace llvm {
2122

2223
namespace LoongArchABI {
2324

25+
// Check if ABI has been standardized; issue a warning if it hasn't.
26+
// FIXME: Once all ABIs are standardized, this will be removed.
27+
static ABI checkABIStandardized(ABI Abi) {
28+
StringRef ABIName;
29+
switch (Abi) {
30+
case ABI_ILP32S:
31+
ABIName = "ilp32s";
32+
break;
33+
case ABI_ILP32F:
34+
ABIName = "ilp32f";
35+
break;
36+
case ABI_ILP32D:
37+
ABIName = "ilp32d";
38+
break;
39+
case ABI_LP64F:
40+
ABIName = "lp64f";
41+
break;
42+
case ABI_LP64S:
43+
case ABI_LP64D:
44+
return Abi;
45+
default:
46+
llvm_unreachable("");
47+
}
48+
errs() << "warning: '" << ABIName << "' has not been standardized\n";
49+
return Abi;
50+
}
51+
2452
ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
2553
ABI ArgProvidedABI = getTargetABI(ABIName);
2654
bool Is64Bit = TT.isArch64Bit();
@@ -50,15 +78,15 @@ ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
5078
errs() << "'" << ABIName
5179
<< "' is not a recognized ABI for this target, ignoring and using "
5280
"triple-implied ABI\n";
53-
return TripleABI;
81+
return checkABIStandardized(TripleABI);
5482

5583
case LoongArchABI::ABI_ILP32S:
5684
case LoongArchABI::ABI_ILP32F:
5785
case LoongArchABI::ABI_ILP32D:
5886
if (Is64Bit) {
5987
errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
6088
"target-abi and using triple-implied ABI\n";
61-
return TripleABI;
89+
return checkABIStandardized(TripleABI);
6290
}
6391
break;
6492

@@ -68,7 +96,7 @@ ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
6896
if (!Is64Bit) {
6997
errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
7098
"target-abi and using triple-implied ABI\n";
71-
return TripleABI;
99+
return checkABIStandardized(TripleABI);
72100
}
73101
break;
74102
}
@@ -77,7 +105,7 @@ ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
77105
errs() << "warning: triple-implied ABI conflicts with provided target-abi '"
78106
<< ABIName << "', using target-abi\n";
79107

80-
return ArgProvidedABI;
108+
return checkABIStandardized(ArgProvidedABI);
81109
}
82110

83111
ABI getTargetABI(StringRef ABIName) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32s < %s 2>&1 \
2+
; RUN: | FileCheck %s -DABI=ilp32s --check-prefixes=CHECK,WARNING
3+
; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32f < %s 2>&1 \
4+
; RUN: | FileCheck %s -DABI=ilp32f --check-prefixes=CHECK,WARNING
5+
; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32d < %s 2>&1 \
6+
; RUN: | FileCheck %s -DABI=ilp32d --check-prefixes=CHECK,WARNING
7+
; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64f < %s 2>&1 \
8+
; RUN: | FileCheck %s -DABI=lp64f --check-prefixes=CHECK,WARNING
9+
10+
; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64s < %s 2>&1 \
11+
; RUN: | FileCheck %s --check-prefixes=CHECK,NO-WARNING
12+
; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64d < %s 2>&1 \
13+
; RUN: | FileCheck %s --check-prefixes=CHECK,NO-WARNING
14+
15+
;; Check if the ABI has been standardized; issue a warning if it hasn't.
16+
17+
; WARNING: warning: '[[ABI]]' has not been standardized
18+
19+
; NO-WARNING-NOT: warning
20+
21+
define void @nothing() nounwind {
22+
; CHECK-LABEL: nothing:
23+
; CHECK: # %bb.0:
24+
; CHECK-NEXT: ret
25+
ret void
26+
}

0 commit comments

Comments
 (0)