Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions llvm/include/llvm/CodeGen/SelectionDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -1725,17 +1725,9 @@ class SelectionDAG {
/// value.
LLVM_ABI bool
expandMultipleResultFPLibCall(RTLIB::Libcall LC, SDNode *Node,
SmallVectorImpl<SDValue> &Results, EVT CallType,
SmallVectorImpl<SDValue> &Results,
std::optional<unsigned> CallRetResNo = {});

// FIXME: Ths should be removed, and form using RTLIB::Libcall should be
// preferred. Callers should resolve the exact type libcall to use.
LLVM_ABI bool
expandMultipleResultFPLibCall(StringRef LibcallName, CallingConv::ID CC,
SDNode *Node, SmallVectorImpl<SDValue> &Results,
std::optional<unsigned> CallRetResNo = {},
bool IsVectorMasked = false);

/// Expand the specified \c ISD::VAARG node as the Legalize pass would.
LLVM_ABI SDValue expandVAArg(SDNode *Node);

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4842,7 +4842,7 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
RTLIB::Libcall LC = Node->getOpcode() == ISD::FSINCOS
? RTLIB::getSINCOS(VT)
: RTLIB::getSINCOSPI(VT);
bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT);
bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results);
if (!Expanded) {
DAG.getContext()->emitError(Twine("no libcall available for ") +
Node->getOperationName(&DAG));
Expand Down Expand Up @@ -4940,7 +4940,7 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
EVT VT = Node->getValueType(0);
RTLIB::Libcall LC = Node->getOpcode() == ISD::FMODF ? RTLIB::getMODF(VT)
: RTLIB::getFREXP(VT);
bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results,
/*CallRetResNo=*/0);
if (!Expanded)
llvm_unreachable("Expected scalar FFREXP/FMODF to expand to libcall!");
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,8 +1726,7 @@ void DAGTypeLegalizer::ExpandFloatRes_UnaryWithTwoFPResults(
SDNode *N, RTLIB::Libcall LC, std::optional<unsigned> CallRetResNo) {
assert(!N->isStrictFPOpcode() && "strictfp not implemented");
SmallVector<SDValue> Results;
DAG.expandMultipleResultFPLibCall(LC, N, Results, N->getValueType(0),
CallRetResNo);
DAG.expandMultipleResultFPLibCall(LC, N, Results, CallRetResNo);
for (auto [ResNo, Res] : enumerate(Results)) {
SDValue Lo, Hi;
GetPairElements(Res, Lo, Hi);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
? RTLIB::getSINCOS(VT)
: RTLIB::getSINCOSPI(VT);
if (LC != RTLIB::UNKNOWN_LIBCALL &&
DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT))
DAG.expandMultipleResultFPLibCall(LC, Node, Results))
return;

// TODO: Try to see if there's a narrower call available to use before
Expand All @@ -1286,7 +1286,7 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
EVT VT = Node->getValueType(0);
RTLIB::Libcall LC = RTLIB::getMODF(VT);
if (LC != RTLIB::UNKNOWN_LIBCALL &&
DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
DAG.expandMultipleResultFPLibCall(LC, Node, Results,
/*CallRetResNo=*/0))
return;
break;
Expand Down
60 changes: 10 additions & 50 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2514,56 +2514,14 @@ static bool canFoldStoreIntoLibCallOutputPointers(StoreSDNode *StoreNode,

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

EVT VT = Node->getValueType(0);

RTLIB::LibcallImpl Impl = TLI->getLibcallImpl(LC);
if (Impl == RTLIB::Unsupported)
return false;

StringRef LCName = TLI->getLibcallImplName(Impl);

// FIXME: This should not use TargetLibraryInfo. There should be
// RTLIB::Libcall entries for each used vector type, and directly matched.
auto getVecDesc = [&]() -> VecDesc const * {
for (bool Masked : {false, true}) {
if (VecDesc const *VD = getLibInfo().getVectorMappingInfo(
LCName, VT.getVectorElementCount(), Masked)) {
return VD;
}
}
return nullptr;
};

// For vector types, we must find a vector mapping for the libcall.
VecDesc const *VD = nullptr;
if (VT.isVector() && !CallVT.isVector() && !(VD = getVecDesc()))
RTLIB::LibcallImpl LibcallImpl = TLI->getLibcallImpl(LC);
if (LibcallImpl == RTLIB::Unsupported)
return false;

bool IsMasked = (VD && VD->isMasked()) ||
RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(Impl);

// This wrapper function exists because getVectorMappingInfo works in terms of
// function names instead of RTLIB enums.

// FIXME: If we used a vector mapping, this assumes the calling convention of
// the vector function is the same as the scalar.

StringRef Name = VD ? VD->getVectorFnName() : LCName;

return expandMultipleResultFPLibCall(Name,
TLI->getLibcallImplCallingConv(Impl),
Node, Results, CallRetResNo, IsMasked);
}

// FIXME: This belongs in TargetLowering
bool SelectionDAG::expandMultipleResultFPLibCall(
StringRef Name, CallingConv::ID CC, SDNode *Node,
SmallVectorImpl<SDValue> &Results, std::optional<unsigned> CallRetResNo,
bool IsMasked) {
LLVMContext &Ctx = *getContext();
EVT VT = Node->getValueType(0);
unsigned NumResults = Node->getNumValues();
Expand Down Expand Up @@ -2624,8 +2582,8 @@ bool SelectionDAG::expandMultipleResultFPLibCall(

SDLoc DL(Node);

// Pass the vector mask (if required).
if (IsMasked) {
if (RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(LibcallImpl)) {
// Pass the vector mask (if required).
EVT MaskVT = TLI->getSetCCResultType(getDataLayout(), Ctx, VT);
SDValue Mask = getBoolConstant(true, DL, MaskVT, VT);
Args.emplace_back(Mask, MaskVT.getTypeForEVT(Ctx));
Expand All @@ -2636,10 +2594,12 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
: Type::getVoidTy(Ctx);
SDValue InChain = StoresInChain ? StoresInChain : getEntryNode();
SDValue Callee =
getExternalSymbol(Name.data(), TLI->getPointerTy(getDataLayout()));
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
TLI->getPointerTy(getDataLayout()));
TargetLowering::CallLoweringInfo CLI(*this);
CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(CC, RetType, Callee,
std::move(Args));
CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(
TLI->getLibcallImplCallingConv(LibcallImpl), RetType, Callee,
std::move(Args));

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

Expand Down
Loading