Skip to content

Commit b0b98a7

Browse files
arsenmJaddyen
authored andcommitted
DAG: Move soft float predicate management into RuntimeLibcalls (llvm#142905)
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 de8e6bc commit b0b98a7

File tree

5 files changed

+160
-99
lines changed

5 files changed

+160
-99
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

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

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

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

3590-
35913589
/// Set the CallingConv that should be used for the specified libcall.
35923590
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
35933591
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
return ArrayRef(LibcallRoutineNames).drop_back();
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,45 @@ static void setMSP430Libcalls(RuntimeLibcallsInfo &Info, const Triple &TT) {
220220
// TODO: __mspabi_srall, __mspabi_srlll, __mspabi_sllll
221221
}
222222

223+
void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() {
224+
SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F32] = CmpInst::ICMP_EQ;
225+
SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F64] = CmpInst::ICMP_EQ;
226+
SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F128] = CmpInst::ICMP_EQ;
227+
SoftFloatCompareLibcallPredicates[RTLIB::OEQ_PPCF128] = CmpInst::ICMP_EQ;
228+
SoftFloatCompareLibcallPredicates[RTLIB::UNE_F32] = CmpInst::ICMP_NE;
229+
SoftFloatCompareLibcallPredicates[RTLIB::UNE_F64] = CmpInst::ICMP_NE;
230+
SoftFloatCompareLibcallPredicates[RTLIB::UNE_F128] = CmpInst::ICMP_NE;
231+
SoftFloatCompareLibcallPredicates[RTLIB::UNE_PPCF128] = CmpInst::ICMP_NE;
232+
SoftFloatCompareLibcallPredicates[RTLIB::OGE_F32] = CmpInst::ICMP_SGE;
233+
SoftFloatCompareLibcallPredicates[RTLIB::OGE_F64] = CmpInst::ICMP_SGE;
234+
SoftFloatCompareLibcallPredicates[RTLIB::OGE_F128] = CmpInst::ICMP_SGE;
235+
SoftFloatCompareLibcallPredicates[RTLIB::OGE_PPCF128] = CmpInst::ICMP_SGE;
236+
SoftFloatCompareLibcallPredicates[RTLIB::OLT_F32] = CmpInst::ICMP_SLT;
237+
SoftFloatCompareLibcallPredicates[RTLIB::OLT_F64] = CmpInst::ICMP_SLT;
238+
SoftFloatCompareLibcallPredicates[RTLIB::OLT_F128] = CmpInst::ICMP_SLT;
239+
SoftFloatCompareLibcallPredicates[RTLIB::OLT_PPCF128] = CmpInst::ICMP_SLT;
240+
SoftFloatCompareLibcallPredicates[RTLIB::OLE_F32] = CmpInst::ICMP_SLE;
241+
SoftFloatCompareLibcallPredicates[RTLIB::OLE_F64] = CmpInst::ICMP_SLE;
242+
SoftFloatCompareLibcallPredicates[RTLIB::OLE_F128] = CmpInst::ICMP_SLE;
243+
SoftFloatCompareLibcallPredicates[RTLIB::OLE_PPCF128] = CmpInst::ICMP_SLE;
244+
SoftFloatCompareLibcallPredicates[RTLIB::OGT_F32] = CmpInst::ICMP_SGT;
245+
SoftFloatCompareLibcallPredicates[RTLIB::OGT_F64] = CmpInst::ICMP_SGT;
246+
SoftFloatCompareLibcallPredicates[RTLIB::OGT_F128] = CmpInst::ICMP_SGT;
247+
SoftFloatCompareLibcallPredicates[RTLIB::OGT_PPCF128] = CmpInst::ICMP_SGT;
248+
SoftFloatCompareLibcallPredicates[RTLIB::UO_F32] = CmpInst::ICMP_NE;
249+
SoftFloatCompareLibcallPredicates[RTLIB::UO_F64] = CmpInst::ICMP_NE;
250+
SoftFloatCompareLibcallPredicates[RTLIB::UO_F128] = CmpInst::ICMP_NE;
251+
SoftFloatCompareLibcallPredicates[RTLIB::UO_PPCF128] = CmpInst::ICMP_NE;
252+
}
253+
223254
/// Set default libcall names. If a target wants to opt-out of a libcall it
224255
/// should be placed here.
225256
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
226257
std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames),
227258
nullptr);
228259

260+
initSoftFloatCmpLibcallPredicates();
261+
229262
#define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name);
230263
#define LIBCALL_NO_NAME nullptr
231264
#include "llvm/IR/RuntimeLibcalls.def"

0 commit comments

Comments
 (0)