Skip to content

Commit e245a54

Browse files
committed
DAG: Move soft float predicate management into RuntimeLibcalls
Work towards making RuntimeLibcalls the centralized location for all libcall information. This requires changing the encoding from tracking the ISD::CondCode to using CmpInst::Predicate.
1 parent af3a251 commit e245a54

File tree

6 files changed

+224
-164
lines changed

6 files changed

+224
-164
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,20 +3572,18 @@ class LLVM_ABI TargetLoweringBase {
35723572

35733573
/// Override the default CondCode to be used to test the result of the
35743574
/// comparison libcall against zero.
3575-
/// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD.
3576-
void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) {
3577-
CmpLibcallCCs[Call] = CC;
3575+
/// FIXME: This should be removed
3576+
void setCmpLibcallCC(RTLIB::Libcall Call, CmpInst::Predicate Pred) {
3577+
Libcalls.setSoftFloatCmpLibcallPredicate(Call, Pred);
35783578
}
35793579

3580-
35813580
/// Get the CondCode that's to be used to test the result of the comparison
35823581
/// libcall against zero.
3583-
/// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD.
3584-
ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const {
3585-
return CmpLibcallCCs[Call];
3582+
CmpInst::Predicate
3583+
getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const {
3584+
return Libcalls.getSoftFloatCmpLibcallPredicate(Call);
35863585
}
35873586

3588-
35893587
/// Set the CallingConv that should be used for the specified libcall.
35903588
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
35913589
Libcalls.setLibcallCallingConv(Call, CC);

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/ArrayRef.h"
1818
#include "llvm/ADT/Sequence.h"
1919
#include "llvm/IR/CallingConv.h"
20+
#include "llvm/IR/InstrTypes.h"
2021
#include "llvm/Support/AtomicOrdering.h"
2122
#include "llvm/Support/Compiler.h"
2223
#include "llvm/TargetParser/Triple.h"
@@ -86,13 +87,35 @@ struct RuntimeLibcallsInfo {
8687
LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL);
8788
}
8889

90+
/// Get the comparison predicate that's to be used to test the result of the
91+
/// comparison libcall against zero. This should only be used with
92+
/// floating-point compare libcalls.
93+
CmpInst::Predicate
94+
getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const {
95+
return SoftFloatCompareLibcallPredicates[Call];
96+
}
97+
98+
// FIXME: This should be removed. This should be private constant.
99+
void setSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call,
100+
CmpInst::Predicate Pred) {
101+
SoftFloatCompareLibcallPredicates[Call] = Pred;
102+
}
103+
89104
private:
90105
/// Stores the name each libcall.
91106
const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
92107

93108
/// Stores the CallingConv that should be used for each libcall.
94109
CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
95110

111+
/// The condition type that should be used to test the result of each of the
112+
/// soft floating-point comparison libcall against integer zero.
113+
///
114+
// FIXME: This is only relevant for the handful of floating-point comparison
115+
// runtime calls; it's excessive to have a table entry for every single
116+
// opcode.
117+
CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL];
118+
96119
static bool darwinHasSinCos(const Triple &TT) {
97120
assert(TT.isOSDarwin() && "should be called with darwin triple");
98121
// Don't bother with 32 bit x86.
@@ -108,6 +131,8 @@ struct RuntimeLibcallsInfo {
108131
return true;
109132
}
110133

134+
void initSoftFloatCmpLibcallPredicates();
135+
111136
/// Set default libcall names. If a target wants to opt-out of a libcall it
112137
/// should be placed here.
113138
LLVM_ABI void initLibcalls(const Triple &TT);

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/ADT/STLExtras.h"
1515
#include "llvm/Analysis/ValueTracking.h"
1616
#include "llvm/Analysis/VectorUtils.h"
17+
#include "llvm/CodeGen/Analysis.h"
1718
#include "llvm/CodeGen/CallingConvLower.h"
1819
#include "llvm/CodeGen/CodeGenCommonISel.h"
1920
#include "llvm/CodeGen/MachineFrameInfo.h"
@@ -419,7 +420,7 @@ void TargetLowering::softenSetCCOperands(SelectionDAG &DAG, EVT VT,
419420
NewLHS = Call.first;
420421
NewRHS = DAG.getConstant(0, dl, RetVT);
421422

422-
CCCode = getCmpLibcallCC(LC1);
423+
CCCode = getICmpCondCode(getSoftFloatCmpLibcallPredicate(LC1));
423424
if (ShouldInvertCC) {
424425
assert(RetVT.isInteger());
425426
CCCode = getSetCCInverse(CCCode, RetVT);
@@ -441,7 +442,7 @@ void TargetLowering::softenSetCCOperands(SelectionDAG &DAG, EVT VT,
441442

442443
SDValue Tmp = DAG.getSetCC(dl, SetCCVT, NewLHS, NewRHS, CCCode);
443444
auto Call2 = makeLibCall(DAG, LC2, RetVT, Ops, CallOptions, dl, Chain);
444-
CCCode = getCmpLibcallCC(LC2);
445+
CCCode = getICmpCondCode(getSoftFloatCmpLibcallPredicate(LC2));
445446
if (ShouldInvertCC)
446447
CCCode = getSetCCInverse(CCCode, RetVT);
447448
NewLHS = DAG.getSetCC(dl, SetCCVT, Call2.first, NewRHS, CCCode);

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,48 @@
1111
using namespace llvm;
1212
using namespace RTLIB;
1313

14+
void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() {
15+
std::fill(SoftFloatCompareLibcallPredicates,
16+
SoftFloatCompareLibcallPredicates + RTLIB::UNKNOWN_LIBCALL,
17+
CmpInst::BAD_ICMP_PREDICATE);
18+
SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F32] = CmpInst::ICMP_EQ;
19+
SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F64] = CmpInst::ICMP_EQ;
20+
SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F128] = CmpInst::ICMP_EQ;
21+
SoftFloatCompareLibcallPredicates[RTLIB::OEQ_PPCF128] = CmpInst::ICMP_EQ;
22+
SoftFloatCompareLibcallPredicates[RTLIB::UNE_F32] = CmpInst::ICMP_NE;
23+
SoftFloatCompareLibcallPredicates[RTLIB::UNE_F64] = CmpInst::ICMP_NE;
24+
SoftFloatCompareLibcallPredicates[RTLIB::UNE_F128] = CmpInst::ICMP_NE;
25+
SoftFloatCompareLibcallPredicates[RTLIB::UNE_PPCF128] = CmpInst::ICMP_NE;
26+
SoftFloatCompareLibcallPredicates[RTLIB::OGE_F32] = CmpInst::ICMP_SGE;
27+
SoftFloatCompareLibcallPredicates[RTLIB::OGE_F64] = CmpInst::ICMP_SGE;
28+
SoftFloatCompareLibcallPredicates[RTLIB::OGE_F128] = CmpInst::ICMP_SGE;
29+
SoftFloatCompareLibcallPredicates[RTLIB::OGE_PPCF128] = CmpInst::ICMP_SGE;
30+
SoftFloatCompareLibcallPredicates[RTLIB::OLT_F32] = CmpInst::ICMP_SLT;
31+
SoftFloatCompareLibcallPredicates[RTLIB::OLT_F64] = CmpInst::ICMP_SLT;
32+
SoftFloatCompareLibcallPredicates[RTLIB::OLT_F128] = CmpInst::ICMP_SLT;
33+
SoftFloatCompareLibcallPredicates[RTLIB::OLT_PPCF128] = CmpInst::ICMP_SLT;
34+
SoftFloatCompareLibcallPredicates[RTLIB::OLE_F32] = CmpInst::ICMP_SLE;
35+
SoftFloatCompareLibcallPredicates[RTLIB::OLE_F64] = CmpInst::ICMP_SLE;
36+
SoftFloatCompareLibcallPredicates[RTLIB::OLE_F128] = CmpInst::ICMP_SLE;
37+
SoftFloatCompareLibcallPredicates[RTLIB::OLE_PPCF128] = CmpInst::ICMP_SLE;
38+
SoftFloatCompareLibcallPredicates[RTLIB::OGT_F32] = CmpInst::ICMP_SGT;
39+
SoftFloatCompareLibcallPredicates[RTLIB::OGT_F64] = CmpInst::ICMP_SGT;
40+
SoftFloatCompareLibcallPredicates[RTLIB::OGT_F128] = CmpInst::ICMP_SGT;
41+
SoftFloatCompareLibcallPredicates[RTLIB::OGT_PPCF128] = CmpInst::ICMP_SGT;
42+
SoftFloatCompareLibcallPredicates[RTLIB::UO_F32] = CmpInst::ICMP_NE;
43+
SoftFloatCompareLibcallPredicates[RTLIB::UO_F64] = CmpInst::ICMP_NE;
44+
SoftFloatCompareLibcallPredicates[RTLIB::UO_F128] = CmpInst::ICMP_NE;
45+
SoftFloatCompareLibcallPredicates[RTLIB::UO_PPCF128] = CmpInst::ICMP_NE;
46+
}
47+
1448
/// Set default libcall names. If a target wants to opt-out of a libcall it
1549
/// should be placed here.
1650
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
1751
std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames),
1852
nullptr);
1953

54+
initSoftFloatCmpLibcallPredicates();
55+
2056
#define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name);
2157
#include "llvm/IR/RuntimeLibcalls.def"
2258
#undef HANDLE_LIBCALL

0 commit comments

Comments
 (0)