Skip to content

Commit 65dee89

Browse files
committed
DAG: Add overload of makeLibCall which calls an RTLIB::LibcallImpl
Logically the concrete implementation is what's being called, not the abstract libcall. Many uses conditionalize emitting the call on whether the call is available, so the caller and makeLibCall would both be checking that.
1 parent 064887b commit 65dee89

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4116,12 +4116,21 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
41164116
}
41174117

41184118
/// Returns a pair of (return value, chain).
4119+
/// It is an error to pass RTLIB::Unsupported as \p LibcallImpl
4120+
std::pair<SDValue, SDValue>
4121+
makeLibCall(SelectionDAG &DAG, RTLIB::LibcallImpl LibcallImpl, EVT RetVT,
4122+
ArrayRef<SDValue> Ops, MakeLibCallOptions CallOptions,
4123+
const SDLoc &dl, SDValue Chain = SDValue()) const;
4124+
41194125
/// It is an error to pass RTLIB::UNKNOWN_LIBCALL as \p LC.
41204126
std::pair<SDValue, SDValue> makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC,
41214127
EVT RetVT, ArrayRef<SDValue> Ops,
41224128
MakeLibCallOptions CallOptions,
41234129
const SDLoc &dl,
4124-
SDValue Chain = SDValue()) const;
4130+
SDValue Chain = SDValue()) const {
4131+
return makeLibCall(DAG, getLibcallImpl(LC), RetVT, Ops, CallOptions, dl,
4132+
Chain);
4133+
}
41254134

41264135
/// Check whether parameters to a call that are passed in callee saved
41274136
/// registers are the same as from the calling function. This needs to be

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ bool DAGTypeLegalizer::SoftenFloatRes_UnaryWithTwoFPResults(
802802
assert(VT == N->getValueType(1) &&
803803
"expected both return values to have the same type");
804804

805-
if (TLI.getLibcallImpl(LC) == RTLIB::Unsupported)
805+
RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
806+
if (LCImpl == RTLIB::Unsupported)
806807
return false;
807808

808809
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
@@ -831,8 +832,9 @@ bool DAGTypeLegalizer::SoftenFloatRes_UnaryWithTwoFPResults(
831832
CallOptions.setTypeListBeforeSoften({OpsVT}, VT)
832833
.setOpsTypeOverrides(CallOpsTypeOverrides);
833834

834-
auto [ReturnVal, Chain] = TLI.makeLibCall(DAG, LC, NVT, Ops, CallOptions, DL,
835-
/*Chain=*/SDValue());
835+
auto [ReturnVal, Chain] =
836+
TLI.makeLibCall(DAG, LCImpl, NVT, Ops, CallOptions, DL,
837+
/*Chain=*/SDValue());
836838

837839
auto CreateStackLoad = [&, Chain = Chain](SDValue StackSlot) {
838840
int FrameIdx = cast<FrameIndexSDNode>(StackSlot)->getIndex();

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,8 @@ SDValue DAGTypeLegalizer::PromoteIntOp_ExpOp(SDNode *N) {
26922692
RTLIB::Libcall LC = IsPowI ? RTLIB::getPOWI(N->getValueType(0))
26932693
: RTLIB::getLDEXP(N->getValueType(0));
26942694

2695-
if (TLI.getLibcallImpl(LC) == RTLIB::Unsupported) {
2695+
RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
2696+
if (LCImpl == RTLIB::Unsupported) {
26962697
// Scalarize vector FPOWI instead of promoting the type. This allows the
26972698
// scalar FPOWIs to be visited and converted to libcalls before promoting
26982699
// the type.
@@ -2719,7 +2720,7 @@ SDValue DAGTypeLegalizer::PromoteIntOp_ExpOp(SDNode *N) {
27192720
CallOptions.setIsSigned(true);
27202721
SDValue Ops[2] = {N->getOperand(0 + OpOffset), N->getOperand(1 + OpOffset)};
27212722
std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(
2722-
DAG, LC, N->getValueType(0), Ops, CallOptions, SDLoc(N), Chain);
2723+
DAG, LCImpl, N->getValueType(0), Ops, CallOptions, SDLoc(N), Chain);
27232724
ReplaceValueWith(SDValue(N, 0), Tmp.first);
27242725
if (IsStrict)
27252726
ReplaceValueWith(SDValue(N, 1), Tmp.second);
@@ -3187,16 +3188,19 @@ std::pair <SDValue, SDValue> DAGTypeLegalizer::ExpandAtomic(SDNode *Node) {
31873188
EVT RetVT = Node->getValueType(0);
31883189
TargetLowering::MakeLibCallOptions CallOptions;
31893190
SmallVector<SDValue, 4> Ops;
3190-
if (TLI.getLibcallName(LC)) {
3191+
3192+
RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
3193+
if (LCImpl != RTLIB::Unsupported) {
31913194
Ops.append(Node->op_begin() + 2, Node->op_end());
31923195
Ops.push_back(Node->getOperand(1));
31933196
} else {
31943197
LC = RTLIB::getSYNC(Opc, VT);
31953198
assert(LC != RTLIB::UNKNOWN_LIBCALL &&
31963199
"Unexpected atomic op or value type!");
31973200
Ops.append(Node->op_begin() + 1, Node->op_end());
3201+
LCImpl = TLI.getLibcallImpl(LC);
31983202
}
3199-
return TLI.makeLibCall(DAG, LC, RetVT, Ops, CallOptions, SDLoc(Node),
3203+
return TLI.makeLibCall(DAG, LCImpl, RetVT, Ops, CallOptions, SDLoc(Node),
32003204
Node->getOperand(0));
32013205
}
32023206

@@ -4403,8 +4407,8 @@ void DAGTypeLegalizer::ExpandIntRes_MUL(SDNode *N,
44034407

44044408
// If nothing else, we can make a libcall.
44054409
RTLIB::Libcall LC = RTLIB::getMUL(VT);
4406-
4407-
if (LC == RTLIB::UNKNOWN_LIBCALL || !TLI.getLibcallName(LC)) {
4410+
RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
4411+
if (LCImpl == RTLIB::Unsupported) {
44084412
// Perform a wide multiplication where the wide type is the original VT and
44094413
// the 4 parts are the split arguments.
44104414
TLI.forceExpandMultiply(DAG, dl, /*Signed=*/false, Lo, Hi, LL, RL, LH, RH);
@@ -4416,8 +4420,8 @@ void DAGTypeLegalizer::ExpandIntRes_MUL(SDNode *N,
44164420
SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
44174421
TargetLowering::MakeLibCallOptions CallOptions;
44184422
CallOptions.setIsSigned(true);
4419-
SplitInteger(TLI.makeLibCall(DAG, LC, VT, Ops, CallOptions, dl).first,
4420-
Lo, Hi);
4423+
SplitInteger(TLI.makeLibCall(DAG, LCImpl, VT, Ops, CallOptions, dl).first, Lo,
4424+
Hi);
44214425
}
44224426

44234427
void DAGTypeLegalizer::ExpandIntRes_READCOUNTER(SDNode *N, SDValue &Lo,
@@ -4991,14 +4995,16 @@ void DAGTypeLegalizer::ExpandIntRes_Shift(SDNode *N,
49914995
LC = RTLIB::getSRA(VT);
49924996
}
49934997

4994-
if (LC != RTLIB::UNKNOWN_LIBCALL && TLI.getLibcallName(LC)) {
4998+
if (RTLIB::LibcallImpl LibcallImpl = TLI.getLibcallImpl(LC)) {
49954999
EVT ShAmtTy =
49965000
EVT::getIntegerVT(*DAG.getContext(), DAG.getLibInfo().getIntSize());
49975001
SDValue ShAmt = DAG.getZExtOrTrunc(N->getOperand(1), dl, ShAmtTy);
49985002
SDValue Ops[2] = {N->getOperand(0), ShAmt};
49995003
TargetLowering::MakeLibCallOptions CallOptions;
50005004
CallOptions.setIsSigned(isSigned);
5001-
SplitInteger(TLI.makeLibCall(DAG, LC, VT, Ops, CallOptions, dl).first, Lo, Hi);
5005+
SplitInteger(
5006+
TLI.makeLibCall(DAG, LibcallImpl, VT, Ops, CallOptions, dl).first, Lo,
5007+
Hi);
50025008
return;
50035009
}
50045010

@@ -5158,11 +5164,12 @@ void DAGTypeLegalizer::ExpandIntRes_XMULO(SDNode *N,
51585164

51595165
// Replace this with a libcall that will check overflow.
51605166
RTLIB::Libcall LC = RTLIB::getMULO(VT);
5167+
RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
51615168

51625169
// If we don't have the libcall or if the function we are compiling is the
51635170
// implementation of the expected libcall (avoid inf-loop), expand inline.
5164-
if (LC == RTLIB::UNKNOWN_LIBCALL || !TLI.getLibcallName(LC) ||
5165-
TLI.getLibcallName(LC) == DAG.getMachineFunction().getName()) {
5171+
if (LCImpl == RTLIB::Unsupported ||
5172+
TLI.getLibcallImplName(LCImpl) == DAG.getMachineFunction().getName()) {
51665173
// FIXME: This is not an optimal expansion, but better than crashing.
51675174
SDValue MulLo, MulHi;
51685175
TLI.forceExpandWideMUL(DAG, dl, /*Signed=*/true, N->getOperand(0),
@@ -5200,12 +5207,14 @@ void DAGTypeLegalizer::ExpandIntRes_XMULO(SDNode *N,
52005207
Entry.IsZExt = false;
52015208
Args.push_back(Entry);
52025209

5203-
SDValue Func = DAG.getExternalSymbol(TLI.getLibcallName(LC), PtrVT);
5210+
SDValue Func =
5211+
DAG.getExternalSymbol(TLI.getLibcallImplName(LCImpl).data(), PtrVT);
52045212

52055213
TargetLowering::CallLoweringInfo CLI(DAG);
52065214
CLI.setDebugLoc(dl)
52075215
.setChain(Chain)
5208-
.setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Func, std::move(Args))
5216+
.setLibCallee(TLI.getLibcallImplCallingConv(LCImpl), RetTy, Func,
5217+
std::move(Args))
52095218
.setSExtResult();
52105219

52115220
std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@ void TargetLoweringBase::ArgListEntry::setAttributes(const CallBase *Call,
152152
/// Generate a libcall taking the given operands as arguments and returning a
153153
/// result of type RetVT.
154154
std::pair<SDValue, SDValue>
155-
TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,
156-
ArrayRef<SDValue> Ops,
157-
MakeLibCallOptions CallOptions,
158-
const SDLoc &dl,
155+
TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::LibcallImpl LibcallImpl,
156+
EVT RetVT, ArrayRef<SDValue> Ops,
157+
MakeLibCallOptions CallOptions, const SDLoc &dl,
159158
SDValue InChain) const {
159+
if (LibcallImpl == RTLIB::Unsupported)
160+
reportFatalInternalError("unsupported library call operation");
161+
160162
if (!InChain)
161163
InChain = DAG.getEntryNode();
162164

@@ -185,10 +187,6 @@ TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,
185187
Args.push_back(Entry);
186188
}
187189

188-
RTLIB::LibcallImpl LibcallImpl = getLibcallImpl(LC);
189-
if (LibcallImpl == RTLIB::Unsupported)
190-
reportFatalInternalError("unsupported library call operation");
191-
192190
SDValue Callee = DAG.getExternalSymbol(getLibcallImplName(LibcallImpl).data(),
193191
getPointerTy(DAG.getDataLayout()));
194192

0 commit comments

Comments
 (0)