Skip to content

Commit 06db2a0

Browse files
committed
DAG: Use more RTLIB helper functions for getting libcall from type
We had a set of utilities which was only used for some set of floating point libcalls. Add more, most of which are for integer operations. Ideally we would generate these functions from tablegen.
1 parent 2fb2d7e commit 06db2a0

File tree

3 files changed

+248
-124
lines changed

3 files changed

+248
-124
lines changed

llvm/include/llvm/CodeGen/RuntimeLibcallUtil.h

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,46 @@
2222
namespace llvm {
2323
namespace RTLIB {
2424

25+
/// \return The SHL_* value for the given types, or UNKNOWN_LIBCALL if there is
26+
/// none.
27+
LLVM_ABI Libcall getSHL(EVT VT);
28+
29+
/// \return The SRL_* value for the given types, or UNKNOWN_LIBCALL if there is
30+
/// none.
31+
LLVM_ABI Libcall getSRL(EVT VT);
32+
33+
/// \return The SRA_* value for the given types, or UNKNOWN_LIBCALL if there is
34+
/// none.
35+
LLVM_ABI Libcall getSRA(EVT VT);
36+
37+
/// \return The MUL_* value for the given types, or UNKNOWN_LIBCALL if there is
38+
/// none.
39+
LLVM_ABI Libcall getMUL(EVT VT);
40+
41+
/// \return The MULO_* value for the given types, or UNKNOWN_LIBCALL if there is
42+
/// none.
43+
LLVM_ABI Libcall getMULO(EVT VT);
44+
45+
/// \return The SDIV_* value for the given types, or UNKNOWN_LIBCALL if there is
46+
/// none.
47+
LLVM_ABI Libcall getSDIV(EVT VT);
48+
49+
/// \return The UDIV_* value for the given types, or UNKNOWN_LIBCALL if there is
50+
/// none.
51+
LLVM_ABI Libcall getUDIV(EVT VT);
52+
53+
/// \return The SREM_* value for the given types, or UNKNOWN_LIBCALL if there is
54+
/// none.
55+
LLVM_ABI Libcall getSREM(EVT VT);
56+
57+
/// \return The UREM_* value for the given types, or UNKNOWN_LIBCALL if there is
58+
/// none.
59+
LLVM_ABI Libcall getUREM(EVT VT);
60+
61+
/// \return The CTPOP_* value for the given types, or UNKNOWN_LIBCALL if there
62+
/// is none.
63+
LLVM_ABI Libcall getCTPOP(EVT VT);
64+
2565
/// GetFPLibCall - Helper to return the right libcall for the given floating
2666
/// point type, or UNKNOWN_LIBCALL if there is none.
2767
LLVM_ABI Libcall getFPLibCall(EVT VT, Libcall Call_F32, Libcall Call_F64,
@@ -90,7 +130,23 @@ LLVM_ABI Libcall getSINCOS_STRET(EVT RetVT);
90130

91131
/// getMODF - Return the MODF_* value for the given types, or
92132
/// UNKNOWN_LIBCALL if there is none.
93-
LLVM_ABI Libcall getMODF(EVT RetVT);
133+
LLVM_ABI Libcall getMODF(EVT VT);
134+
135+
/// \return the LROUND_* value for the given types, or UNKNOWN_LIBCALL if there
136+
/// is none.
137+
LLVM_ABI Libcall getLROUND(EVT VT);
138+
139+
/// \return the LLROUND_* value for the given types, or UNKNOWN_LIBCALL if there
140+
/// is none.
141+
LLVM_ABI Libcall getLLROUND(EVT VT);
142+
143+
/// \return the LRINT_* value for the given types, or UNKNOWN_LIBCALL if there
144+
/// is none.
145+
LLVM_ABI Libcall getLRINT(EVT RetVT);
146+
147+
/// \return the LLRINT_* value for the given types, or UNKNOWN_LIBCALL if there
148+
/// is none.
149+
LLVM_ABI Libcall getLLRINT(EVT RetVT);
94150

95151
/// Return the SYNC_FETCH_AND_* value for the given opcode and type, or
96152
/// UNKNOWN_LIBCALL if there is none.

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 14 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,13 +4097,7 @@ void DAGTypeLegalizer::ExpandIntRes_CTPOP(SDNode *N, SDValue &Lo, SDValue &Hi) {
40974097
SDLoc DL(N);
40984098

40994099
if (TLI.getOperationAction(ISD::CTPOP, VT) == TargetLoweringBase::LibCall) {
4100-
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
4101-
if (VT == MVT::i32)
4102-
LC = RTLIB::CTPOP_I32;
4103-
else if (VT == MVT::i64)
4104-
LC = RTLIB::CTPOP_I64;
4105-
else if (VT == MVT::i128)
4106-
LC = RTLIB::CTPOP_I128;
4100+
RTLIB::Libcall LC = RTLIB::getCTPOP(VT);
41074101
assert(LC != RTLIB::UNKNOWN_LIBCALL && TLI.getLibcallName(LC) &&
41084102
"LibCall explicitly requested, but not available");
41094103
TargetLowering::MakeLibCallOptions CallOptions;
@@ -4236,55 +4230,19 @@ void DAGTypeLegalizer::ExpandIntRes_XROUND_XRINT(SDNode *N, SDValue &Lo,
42364230
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
42374231
if (N->getOpcode() == ISD::LROUND ||
42384232
N->getOpcode() == ISD::STRICT_LROUND) {
4239-
if (VT == MVT::f32)
4240-
LC = RTLIB::LROUND_F32;
4241-
else if (VT == MVT::f64)
4242-
LC = RTLIB::LROUND_F64;
4243-
else if (VT == MVT::f80)
4244-
LC = RTLIB::LROUND_F80;
4245-
else if (VT == MVT::f128)
4246-
LC = RTLIB::LROUND_F128;
4247-
else if (VT == MVT::ppcf128)
4248-
LC = RTLIB::LROUND_PPCF128;
4233+
LC = RTLIB::getLROUND(VT);
42494234
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected lround input type!");
42504235
} else if (N->getOpcode() == ISD::LRINT ||
42514236
N->getOpcode() == ISD::STRICT_LRINT) {
4252-
if (VT == MVT::f32)
4253-
LC = RTLIB::LRINT_F32;
4254-
else if (VT == MVT::f64)
4255-
LC = RTLIB::LRINT_F64;
4256-
else if (VT == MVT::f80)
4257-
LC = RTLIB::LRINT_F80;
4258-
else if (VT == MVT::f128)
4259-
LC = RTLIB::LRINT_F128;
4260-
else if (VT == MVT::ppcf128)
4261-
LC = RTLIB::LRINT_PPCF128;
4237+
LC = RTLIB::getLRINT(VT);
42624238
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected lrint input type!");
42634239
} else if (N->getOpcode() == ISD::LLROUND ||
42644240
N->getOpcode() == ISD::STRICT_LLROUND) {
4265-
if (VT == MVT::f32)
4266-
LC = RTLIB::LLROUND_F32;
4267-
else if (VT == MVT::f64)
4268-
LC = RTLIB::LLROUND_F64;
4269-
else if (VT == MVT::f80)
4270-
LC = RTLIB::LLROUND_F80;
4271-
else if (VT == MVT::f128)
4272-
LC = RTLIB::LLROUND_F128;
4273-
else if (VT == MVT::ppcf128)
4274-
LC = RTLIB::LLROUND_PPCF128;
4241+
LC = RTLIB::getLLROUND(VT);
42754242
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected llround input type!");
42764243
} else if (N->getOpcode() == ISD::LLRINT ||
42774244
N->getOpcode() == ISD::STRICT_LLRINT) {
4278-
if (VT == MVT::f32)
4279-
LC = RTLIB::LLRINT_F32;
4280-
else if (VT == MVT::f64)
4281-
LC = RTLIB::LLRINT_F64;
4282-
else if (VT == MVT::f80)
4283-
LC = RTLIB::LLRINT_F80;
4284-
else if (VT == MVT::f128)
4285-
LC = RTLIB::LLRINT_F128;
4286-
else if (VT == MVT::ppcf128)
4287-
LC = RTLIB::LLRINT_PPCF128;
4245+
LC = RTLIB::getLLRINT(VT);
42884246
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected llrint input type!");
42894247
} else
42904248
llvm_unreachable("Unexpected opcode!");
@@ -4444,15 +4402,7 @@ void DAGTypeLegalizer::ExpandIntRes_MUL(SDNode *N,
44444402
return;
44454403

44464404
// If nothing else, we can make a libcall.
4447-
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
4448-
if (VT == MVT::i16)
4449-
LC = RTLIB::MUL_I16;
4450-
else if (VT == MVT::i32)
4451-
LC = RTLIB::MUL_I32;
4452-
else if (VT == MVT::i64)
4453-
LC = RTLIB::MUL_I64;
4454-
else if (VT == MVT::i128)
4455-
LC = RTLIB::MUL_I128;
4405+
RTLIB::Libcall LC = RTLIB::getMUL(VT);
44564406

44574407
if (LC == RTLIB::UNKNOWN_LIBCALL || !TLI.getLibcallName(LC)) {
44584408
// Perform a wide multiplication where the wide type is the original VT and
@@ -4824,15 +4774,7 @@ void DAGTypeLegalizer::ExpandIntRes_SDIV(SDNode *N,
48244774
return;
48254775
}
48264776

4827-
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
4828-
if (VT == MVT::i16)
4829-
LC = RTLIB::SDIV_I16;
4830-
else if (VT == MVT::i32)
4831-
LC = RTLIB::SDIV_I32;
4832-
else if (VT == MVT::i64)
4833-
LC = RTLIB::SDIV_I64;
4834-
else if (VT == MVT::i128)
4835-
LC = RTLIB::SDIV_I128;
4777+
RTLIB::Libcall LC = RTLIB::getSDIV(VT);
48364778
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!");
48374779

48384780
TargetLowering::MakeLibCallOptions CallOptions;
@@ -5039,35 +4981,14 @@ void DAGTypeLegalizer::ExpandIntRes_Shift(SDNode *N,
50394981
bool isSigned;
50404982
if (Opc == ISD::SHL) {
50414983
isSigned = false; /*sign irrelevant*/
5042-
if (VT == MVT::i16)
5043-
LC = RTLIB::SHL_I16;
5044-
else if (VT == MVT::i32)
5045-
LC = RTLIB::SHL_I32;
5046-
else if (VT == MVT::i64)
5047-
LC = RTLIB::SHL_I64;
5048-
else if (VT == MVT::i128)
5049-
LC = RTLIB::SHL_I128;
4984+
LC = RTLIB::getSHL(VT);
50504985
} else if (Opc == ISD::SRL) {
50514986
isSigned = false;
5052-
if (VT == MVT::i16)
5053-
LC = RTLIB::SRL_I16;
5054-
else if (VT == MVT::i32)
5055-
LC = RTLIB::SRL_I32;
5056-
else if (VT == MVT::i64)
5057-
LC = RTLIB::SRL_I64;
5058-
else if (VT == MVT::i128)
5059-
LC = RTLIB::SRL_I128;
4987+
LC = RTLIB::getSRL(VT);
50604988
} else {
50614989
assert(Opc == ISD::SRA && "Unknown shift!");
50624990
isSigned = true;
5063-
if (VT == MVT::i16)
5064-
LC = RTLIB::SRA_I16;
5065-
else if (VT == MVT::i32)
5066-
LC = RTLIB::SRA_I32;
5067-
else if (VT == MVT::i64)
5068-
LC = RTLIB::SRA_I64;
5069-
else if (VT == MVT::i128)
5070-
LC = RTLIB::SRA_I128;
4991+
LC = RTLIB::getSRA(VT);
50714992
}
50724993

50734994
if (LC != RTLIB::UNKNOWN_LIBCALL && TLI.getLibcallName(LC)) {
@@ -5153,15 +5074,7 @@ void DAGTypeLegalizer::ExpandIntRes_SREM(SDNode *N,
51535074
return;
51545075
}
51555076

5156-
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
5157-
if (VT == MVT::i16)
5158-
LC = RTLIB::SREM_I16;
5159-
else if (VT == MVT::i32)
5160-
LC = RTLIB::SREM_I32;
5161-
else if (VT == MVT::i64)
5162-
LC = RTLIB::SREM_I64;
5163-
else if (VT == MVT::i128)
5164-
LC = RTLIB::SREM_I128;
5077+
RTLIB::Libcall LC = RTLIB::getSREM(VT);
51655078
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!");
51665079

51675080
TargetLowering::MakeLibCallOptions CallOptions;
@@ -5244,13 +5157,7 @@ void DAGTypeLegalizer::ExpandIntRes_XMULO(SDNode *N,
52445157
Type *PtrTy = PtrVT.getTypeForEVT(*DAG.getContext());
52455158

52465159
// Replace this with a libcall that will check overflow.
5247-
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
5248-
if (VT == MVT::i32)
5249-
LC = RTLIB::MULO_I32;
5250-
else if (VT == MVT::i64)
5251-
LC = RTLIB::MULO_I64;
5252-
else if (VT == MVT::i128)
5253-
LC = RTLIB::MULO_I128;
5160+
RTLIB::Libcall LC = RTLIB::getMULO(VT);
52545161

52555162
// If we don't have the libcall or if the function we are compiling is the
52565163
// implementation of the expected libcall (avoid inf-loop), expand inline.
@@ -5341,15 +5248,7 @@ void DAGTypeLegalizer::ExpandIntRes_UDIV(SDNode *N,
53415248
}
53425249
}
53435250

5344-
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
5345-
if (VT == MVT::i16)
5346-
LC = RTLIB::UDIV_I16;
5347-
else if (VT == MVT::i32)
5348-
LC = RTLIB::UDIV_I32;
5349-
else if (VT == MVT::i64)
5350-
LC = RTLIB::UDIV_I64;
5351-
else if (VT == MVT::i128)
5352-
LC = RTLIB::UDIV_I128;
5251+
RTLIB::Libcall LC = RTLIB::getUDIV(VT);
53535252
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported UDIV!");
53545253

53555254
TargetLowering::MakeLibCallOptions CallOptions;
@@ -5384,15 +5283,7 @@ void DAGTypeLegalizer::ExpandIntRes_UREM(SDNode *N,
53845283
}
53855284
}
53865285

5387-
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
5388-
if (VT == MVT::i16)
5389-
LC = RTLIB::UREM_I16;
5390-
else if (VT == MVT::i32)
5391-
LC = RTLIB::UREM_I32;
5392-
else if (VT == MVT::i64)
5393-
LC = RTLIB::UREM_I64;
5394-
else if (VT == MVT::i128)
5395-
LC = RTLIB::UREM_I128;
5286+
RTLIB::Libcall LC = RTLIB::getUREM(VT);
53965287
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported UREM!");
53975288

53985289
TargetLowering::MakeLibCallOptions CallOptions;

0 commit comments

Comments
 (0)