Skip to content

Commit 5d2009c

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 58e7e95 commit 5d2009c

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
@@ -2515,56 +2515,14 @@ static bool canFoldStoreIntoLibCallOutputPointers(StoreSDNode *StoreNode,
25152515

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

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

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

26262584
SDLoc DL(Node);
26272585

2628-
// Pass the vector mask (if required).
2629-
if (IsMasked) {
2586+
if (RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(LibcallImpl)) {
2587+
// Pass the vector mask (if required).
26302588
EVT MaskVT = TLI->getSetCCResultType(getDataLayout(), Ctx, VT);
26312589
SDValue Mask = getBoolConstant(true, DL, MaskVT, VT);
26322590
Args.emplace_back(Mask, MaskVT.getTypeForEVT(Ctx));
@@ -2637,10 +2595,12 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
26372595
: Type::getVoidTy(Ctx);
26382596
SDValue InChain = StoresInChain ? StoresInChain : getEntryNode();
26392597
SDValue Callee =
2640-
getExternalSymbol(Name.data(), TLI->getPointerTy(getDataLayout()));
2598+
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
2599+
TLI->getPointerTy(getDataLayout()));
26412600
TargetLowering::CallLoweringInfo CLI(*this);
2642-
CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(CC, RetType, Callee,
2643-
std::move(Args));
2601+
CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(
2602+
TLI->getLibcallImplCallingConv(LibcallImpl), RetType, Callee,
2603+
std::move(Args));
26442604

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

0 commit comments

Comments
 (0)