Skip to content

Commit d585f3e

Browse files
committed
DAG: Stop using TargetLibraryInfo for multi-result FP intrinsic codegen
Only use RuntimeLibcallsInfo. Remove the helper functions used to transition.
1 parent 91dee19 commit d585f3e

File tree

5 files changed

+16
-65
lines changed

5 files changed

+16
-65
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,17 +1725,9 @@ class SelectionDAG {
17251725
/// value.
17261726
LLVM_ABI bool
17271727
expandMultipleResultFPLibCall(RTLIB::Libcall LC, SDNode *Node,
1728-
SmallVectorImpl<SDValue> &Results, EVT CallType,
1728+
SmallVectorImpl<SDValue> &Results,
17291729
std::optional<unsigned> CallRetResNo = {});
17301730

1731-
// FIXME: Ths should be removed, and form using RTLIB::Libcall should be
1732-
// preferred. Callers should resolve the exact type libcall to use.
1733-
LLVM_ABI bool
1734-
expandMultipleResultFPLibCall(StringRef LibcallName, CallingConv::ID CC,
1735-
SDNode *Node, SmallVectorImpl<SDValue> &Results,
1736-
std::optional<unsigned> CallRetResNo = {},
1737-
bool IsVectorMasked = false);
1738-
17391731
/// Expand the specified \c ISD::VAARG node as the Legalize pass would.
17401732
LLVM_ABI SDValue expandVAArg(SDNode *Node);
17411733

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4842,7 +4842,7 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
48424842
RTLIB::Libcall LC = Node->getOpcode() == ISD::FSINCOS
48434843
? RTLIB::getSINCOS(VT)
48444844
: RTLIB::getSINCOSPI(VT);
4845-
bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT);
4845+
bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results);
48464846
if (!Expanded) {
48474847
DAG.getContext()->emitError(Twine("no libcall available for ") +
48484848
Node->getOperationName(&DAG));
@@ -4940,7 +4940,7 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
49404940
EVT VT = Node->getValueType(0);
49414941
RTLIB::Libcall LC = Node->getOpcode() == ISD::FMODF ? RTLIB::getMODF(VT)
49424942
: RTLIB::getFREXP(VT);
4943-
bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
4943+
bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results,
49444944
/*CallRetResNo=*/0);
49454945
if (!Expanded)
49464946
llvm_unreachable("Expected scalar FFREXP/FMODF to expand to libcall!");

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,8 +1726,7 @@ void DAGTypeLegalizer::ExpandFloatRes_UnaryWithTwoFPResults(
17261726
SDNode *N, RTLIB::Libcall LC, std::optional<unsigned> CallRetResNo) {
17271727
assert(!N->isStrictFPOpcode() && "strictfp not implemented");
17281728
SmallVector<SDValue> Results;
1729-
DAG.expandMultipleResultFPLibCall(LC, N, Results, N->getValueType(0),
1730-
CallRetResNo);
1729+
DAG.expandMultipleResultFPLibCall(LC, N, Results, CallRetResNo);
17311730
for (auto [ResNo, Res] : enumerate(Results)) {
17321731
SDValue Lo, Hi;
17331732
GetPairElements(Res, Lo, Hi);

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
12751275
? RTLIB::getSINCOS(VT)
12761276
: RTLIB::getSINCOSPI(VT);
12771277
if (LC != RTLIB::UNKNOWN_LIBCALL &&
1278-
DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT))
1278+
DAG.expandMultipleResultFPLibCall(LC, Node, Results))
12791279
return;
12801280

12811281
// TODO: Try to see if there's a narrower call available to use before
@@ -1286,7 +1286,7 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
12861286
EVT VT = Node->getValueType(0);
12871287
RTLIB::Libcall LC = RTLIB::getMODF(VT);
12881288
if (LC != RTLIB::UNKNOWN_LIBCALL &&
1289-
DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
1289+
DAG.expandMultipleResultFPLibCall(LC, Node, Results,
12901290
/*CallRetResNo=*/0))
12911291
return;
12921292
break;

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,56 +2514,14 @@ static bool canFoldStoreIntoLibCallOutputPointers(StoreSDNode *StoreNode,
25142514

25152515
bool SelectionDAG::expandMultipleResultFPLibCall(
25162516
RTLIB::Libcall LC, SDNode *Node, SmallVectorImpl<SDValue> &Results,
2517-
EVT CallVT, std::optional<unsigned> CallRetResNo) {
2517+
std::optional<unsigned> CallRetResNo) {
25182518
if (LC == RTLIB::UNKNOWN_LIBCALL)
25192519
return false;
25202520

2521-
EVT VT = Node->getValueType(0);
2522-
2523-
RTLIB::LibcallImpl Impl = TLI->getLibcallImpl(LC);
2524-
if (Impl == RTLIB::Unsupported)
2525-
return false;
2526-
2527-
StringRef LCName = TLI->getLibcallImplName(Impl);
2528-
2529-
// FIXME: This should not use TargetLibraryInfo. There should be
2530-
// RTLIB::Libcall entries for each used vector type, and directly matched.
2531-
auto getVecDesc = [&]() -> VecDesc const * {
2532-
for (bool Masked : {false, true}) {
2533-
if (VecDesc const *VD = getLibInfo().getVectorMappingInfo(
2534-
LCName, VT.getVectorElementCount(), Masked)) {
2535-
return VD;
2536-
}
2537-
}
2538-
return nullptr;
2539-
};
2540-
2541-
// For vector types, we must find a vector mapping for the libcall.
2542-
VecDesc const *VD = nullptr;
2543-
if (VT.isVector() && !CallVT.isVector() && !(VD = getVecDesc()))
2521+
RTLIB::LibcallImpl LibcallImpl = TLI->getLibcallImpl(LC);
2522+
if (LibcallImpl == RTLIB::Unsupported)
25442523
return false;
25452524

2546-
bool IsMasked = (VD && VD->isMasked()) ||
2547-
RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(Impl);
2548-
2549-
// This wrapper function exists because getVectorMappingInfo works in terms of
2550-
// function names instead of RTLIB enums.
2551-
2552-
// FIXME: If we used a vector mapping, this assumes the calling convention of
2553-
// the vector function is the same as the scalar.
2554-
2555-
StringRef Name = VD ? VD->getVectorFnName() : LCName;
2556-
2557-
return expandMultipleResultFPLibCall(Name,
2558-
TLI->getLibcallImplCallingConv(Impl),
2559-
Node, Results, CallRetResNo, IsMasked);
2560-
}
2561-
2562-
// FIXME: This belongs in TargetLowering
2563-
bool SelectionDAG::expandMultipleResultFPLibCall(
2564-
StringRef Name, CallingConv::ID CC, SDNode *Node,
2565-
SmallVectorImpl<SDValue> &Results, std::optional<unsigned> CallRetResNo,
2566-
bool IsMasked) {
25672525
LLVMContext &Ctx = *getContext();
25682526
EVT VT = Node->getValueType(0);
25692527
unsigned NumResults = Node->getNumValues();
@@ -2624,8 +2582,8 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
26242582

26252583
SDLoc DL(Node);
26262584

2627-
// Pass the vector mask (if required).
2628-
if (IsMasked) {
2585+
if (RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(LibcallImpl)) {
2586+
// Pass the vector mask (if required).
26292587
EVT MaskVT = TLI->getSetCCResultType(getDataLayout(), Ctx, VT);
26302588
SDValue Mask = getBoolConstant(true, DL, MaskVT, VT);
26312589
Args.emplace_back(Mask, MaskVT.getTypeForEVT(Ctx));
@@ -2636,10 +2594,12 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
26362594
: Type::getVoidTy(Ctx);
26372595
SDValue InChain = StoresInChain ? StoresInChain : getEntryNode();
26382596
SDValue Callee =
2639-
getExternalSymbol(Name.data(), TLI->getPointerTy(getDataLayout()));
2597+
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
2598+
TLI->getPointerTy(getDataLayout()));
26402599
TargetLowering::CallLoweringInfo CLI(*this);
2641-
CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(CC, RetType, Callee,
2642-
std::move(Args));
2600+
CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(
2601+
TLI->getLibcallImplCallingConv(LibcallImpl), RetType, Callee,
2602+
std::move(Args));
26432603

26442604
auto [Call, CallChain] = TLI->LowerCallTo(CLI);
26452605

0 commit comments

Comments
 (0)