Skip to content

Commit 7bc58a7

Browse files
committed
[RISCV] Support ABI checking with per function target-features
if users don't specific -mattr, the default target-feature come from IR attribute. Reviewers: lenary, asb Reviewed By: lenary, asb Tags: #llvm Differential Revision: https://reviews.llvm.org/D70837
1 parent 3bc2860 commit 7bc58a7

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ class RISCVAsmParser : public MCTargetAsmParser {
194194
Parser.addAliasForDirective(".word", ".4byte");
195195
Parser.addAliasForDirective(".dword", ".8byte");
196196
setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
197+
198+
if (Options.ABIName.back() == 'f' &&
199+
!getSTI().getFeatureBits()[RISCV::FeatureStdExtF]) {
200+
errs() << "Hard-float 'f' ABI can't be used for a target that "
201+
"doesn't support the F instruction set extension (ignoring "
202+
"target-abi)\n";
203+
} else if (Options.ABIName.back() == 'd' &&
204+
!getSTI().getFeatureBits()[RISCV::FeatureStdExtD]) {
205+
errs() << "Hard-float 'd' ABI can't be used for a target that "
206+
"doesn't support the D instruction set extension (ignoring "
207+
"target-abi)\n";
208+
}
197209
}
198210
};
199211

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
5151
RISCVABI::ABI ABI = Subtarget.getTargetABI();
5252
assert(ABI != RISCVABI::ABI_Unknown && "Improperly initialised target ABI");
5353

54+
if ((ABI == RISCVABI::ABI_ILP32F || ABI == RISCVABI::ABI_LP64F) &&
55+
!Subtarget.hasStdExtF()) {
56+
errs() << "Hard-float 'f' ABI can't be used for a target that "
57+
"doesn't support the F instruction set extension (ignoring "
58+
"target-abi)\n";
59+
ABI = Subtarget.is64Bit() ? RISCVABI::ABI_LP64 : RISCVABI::ABI_ILP32;
60+
} else if ((ABI == RISCVABI::ABI_ILP32D || ABI == RISCVABI::ABI_LP64D) &&
61+
!Subtarget.hasStdExtD()) {
62+
errs() << "Hard-float 'd' ABI can't be used for a target that "
63+
"doesn't support the D instruction set extension (ignoring "
64+
"target-abi)\n";
65+
ABI = Subtarget.is64Bit() ? RISCVABI::ABI_LP64 : RISCVABI::ABI_ILP32;
66+
}
67+
5468
switch (ABI) {
5569
default:
5670
report_fatal_error("Don't know how to lower this ABI");

llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,8 @@ ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits,
3737
errs() << "64-bit ABIs are not supported for 32-bit targets (ignoring "
3838
"target-abi)\n";
3939
TargetABI = ABI_Unknown;
40-
} else if (ABIName.endswith("f") && !FeatureBits[RISCV::FeatureStdExtF]) {
41-
errs() << "Hard-float 'f' ABI can't be used for a target that "
42-
"doesn't support the F instruction set extension (ignoring "
43-
"target-abi)\n";
44-
TargetABI = ABI_Unknown;
45-
} else if (ABIName.endswith("d") && !FeatureBits[RISCV::FeatureStdExtD]) {
46-
errs() << "Hard-float 'd' ABI can't be used for a target that "
47-
"doesn't support the D instruction set extension (ignoring "
48-
"target-abi)\n";
49-
TargetABI = ABI_Unknown;
5040
} else if (IsRV32E && TargetABI != ABI_ILP32E && TargetABI != ABI_Unknown) {
41+
// TODO: move this checking to RISCVTargetLowering and RISCVAsmParser
5142
errs()
5243
<< "Only the ilp32e ABI is supported for RV32E (ignoring target-abi)\n";
5344
TargetABI = ABI_Unknown;

llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
; RUN: | FileCheck -check-prefix=RV32IF-ILP32 %s
33
; RUN: llc -mtriple=riscv32 -target-abi ilp32f < %s 2>&1 \
44
; RUN: | FileCheck -check-prefix=RV32IF-ILP32F %s
5+
; RUN: llc -mtriple=riscv32 -mattr=-f -target-abi ilp32f <%s 2>&1 \
6+
; RUN: | FileCheck -check-prefix=RV32I-ILP32F-FAILED %s
7+
8+
; RV32I-ILP32F-FAILED: Hard-float 'f' ABI can't be used for a target that doesn't support the F instruction set extension
59

6-
; RV32IF-ILP32F: Hard-float 'f' ABI can't be used for a target that doesn't support the F instruction set extension (ignoring target-abi)
710

811
define float @foo(i32 %a) nounwind #0 {
9-
; RV32IF-ILP32: # %bb.0:
10-
; RV32IF-ILP32-NEXT: fcvt.s.w ft0, a0
12+
; RV32IF-ILP32: fcvt.s.w ft0, a0
13+
; RV32IF-ILP32-NEXT: fmv.x.w a0, ft0
14+
; RV32IF-ILP32F: fcvt.s.w fa0, a0
15+
; RV32IF-ILP32F-NEXT: ret
1116
%conv = sitofp i32 %a to float
1217
ret float %conv
1318
}

0 commit comments

Comments
 (0)