Skip to content

Commit 25d7dd2

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 232ebc7 commit 25d7dd2

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
@@ -16,6 +16,7 @@
1616

1717
#include "llvm/ADT/ArrayRef.h"
1818
#include "llvm/IR/CallingConv.h"
19+
#include "llvm/IR/InstrTypes.h"
1920
#include "llvm/Support/AtomicOrdering.h"
2021
#include "llvm/Support/Compiler.h"
2122
#include "llvm/TargetParser/Triple.h"
@@ -73,13 +74,35 @@ struct RuntimeLibcallsInfo {
7374
LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL);
7475
}
7576

77+
/// Get the comparison predicate that's to be used to test the result of the
78+
/// comparison libcall against zero. This should only be used with
79+
/// floating-point compare libcalls.
80+
CmpInst::Predicate
81+
getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const {
82+
return SoftFloatCompareLibcallPredicates[Call];
83+
}
84+
85+
// FIXME: This should be removed. This should be private constant.
86+
void setSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call,
87+
CmpInst::Predicate Pred) {
88+
SoftFloatCompareLibcallPredicates[Call] = Pred;
89+
}
90+
7691
private:
7792
/// Stores the name each libcall.
7893
const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
7994

8095
/// Stores the CallingConv that should be used for each libcall.
8196
CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
8297

98+
/// The condition type that should be used to test the result of each of the
99+
/// soft floating-point comparison libcall against integer zero.
100+
///
101+
// FIXME: This is only relevant for the handful of floating-point comparison
102+
// runtime calls; it's excessive to have a table entry for every single
103+
// opcode.
104+
CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL];
105+
83106
static bool darwinHasSinCos(const Triple &TT) {
84107
assert(TT.isOSDarwin() && "should be called with darwin triple");
85108
// Don't bother with 32 bit x86.
@@ -95,6 +118,8 @@ struct RuntimeLibcallsInfo {
95118
return true;
96119
}
97120

121+
void initSoftFloatCmpLibcallPredicates();
122+
98123
/// Set default libcall names. If a target wants to opt-out of a libcall it
99124
/// should be placed here.
100125
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)