Skip to content

Commit 2771d35

Browse files
authored
[NFC ]Add a helper function isTailCall for getting libcall in SelectionDAG (#155256)
Based on comment of #153600 (comment), Add a helper function isTailCall for getting libcall in SelectionDAG.
1 parent b3fa92f commit 2771d35

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9053,6 +9053,18 @@ static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI,
90539053
}
90549054
}
90559055

9056+
static bool isInTailCallPositionWrapper(const CallInst *CI,
9057+
const SelectionDAG *SelDAG,
9058+
bool AllowReturnsFirstArg) {
9059+
if (!CI || !CI->isTailCall())
9060+
return false;
9061+
// TODO: Fix "returns-first-arg" determination so it doesn't depend on which
9062+
// helper symbol we lower to.
9063+
return isInTailCallPosition(*CI, SelDAG->getTarget(),
9064+
AllowReturnsFirstArg &&
9065+
funcReturnsFirstArgOfCall(*CI));
9066+
}
9067+
90569068
std::pair<SDValue, SDValue>
90579069
SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
90589070
SDValue Mem1, SDValue Size, const CallInst *CI) {
@@ -9067,10 +9079,8 @@ SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
90679079
{Size, getDataLayout().getIntPtrType(*getContext())}};
90689080

90699081
TargetLowering::CallLoweringInfo CLI(*this);
9070-
bool IsTailCall = false;
9071-
bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
9072-
IsTailCall = CI && CI->isTailCall() &&
9073-
isInTailCallPosition(*CI, getTarget(), ReturnsFirstArg);
9082+
bool IsTailCall =
9083+
isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg*/ true);
90749084

90759085
CLI.setDebugLoc(dl)
90769086
.setChain(Chain)
@@ -9148,10 +9158,7 @@ SDValue SelectionDAG::getMemcpy(
91489158
IsTailCall = *OverrideTailCall;
91499159
} else {
91509160
bool LowersToMemcpy = StringRef(MemCpyName) == StringRef("memcpy");
9151-
bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
9152-
IsTailCall = CI && CI->isTailCall() &&
9153-
isInTailCallPosition(*CI, getTarget(),
9154-
ReturnsFirstArg && LowersToMemcpy);
9161+
IsTailCall = isInTailCallPositionWrapper(CI, this, LowersToMemcpy);
91559162
}
91569163

91579164
CLI.setDebugLoc(dl)
@@ -9255,10 +9262,7 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
92559262
} else {
92569263
bool LowersToMemmove =
92579264
TLI->getLibcallName(RTLIB::MEMMOVE) == StringRef("memmove");
9258-
bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
9259-
IsTailCall = CI && CI->isTailCall() &&
9260-
isInTailCallPosition(*CI, getTarget(),
9261-
ReturnsFirstArg && LowersToMemmove);
9265+
IsTailCall = isInTailCallPositionWrapper(CI, this, LowersToMemmove);
92629266
}
92639267

92649268
CLI.setDebugLoc(dl)

0 commit comments

Comments
 (0)