Skip to content

Commit 72882ca

Browse files
zakk0610zmodem
authored andcommitted
[RISCV] Support ABI checking with per function target-features
1. if users don't specific -mattr, the default target-feature come from IR attribute. 2. fixed bug and re-land this patch Reviewers: lenary, asb Reviewed By: lenary Tags: #llvm Differential Revision: https://reviews.llvm.org/D70837 (cherry picked from commit 0cb274d)
1 parent 4d342b7 commit 72882ca

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

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

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

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
@@ -28,17 +28,8 @@ ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits,
2828
errs() << "64-bit ABIs are not supported for 32-bit targets (ignoring "
2929
"target-abi)\n";
3030
TargetABI = ABI_Unknown;
31-
} else if (ABIName.endswith("f") && !FeatureBits[RISCV::FeatureStdExtF]) {
32-
errs() << "Hard-float 'f' ABI can't be used for a target that "
33-
"doesn't support the F instruction set extension (ignoring "
34-
"target-abi)\n";
35-
TargetABI = ABI_Unknown;
36-
} else if (ABIName.endswith("d") && !FeatureBits[RISCV::FeatureStdExtD]) {
37-
errs() << "Hard-float 'd' ABI can't be used for a target that "
38-
"doesn't support the D instruction set extension (ignoring "
39-
"target-abi)\n";
40-
TargetABI = ABI_Unknown;
4131
} else if (IsRV32E && TargetABI != ABI_ILP32E && TargetABI != ABI_Unknown) {
32+
// TODO: move this checking to RISCVTargetLowering and RISCVAsmParser
4233
errs()
4334
<< "Only the ilp32e ABI is supported for RV32E (ignoring target-abi)\n";
4435
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)