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
109 changes: 64 additions & 45 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9061,8 +9061,8 @@ static bool isInTailCallPositionWrapper(const CallInst *CI,
std::pair<SDValue, SDValue>
SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
SDValue Mem1, SDValue Size, const CallInst *CI) {
const char *LibCallName = TLI->getLibcallName(RTLIB::MEMCMP);
if (!LibCallName)
RTLIB::LibcallImpl MemcmpImpl = TLI->getLibcallImpl(RTLIB::MEMCMP);
if (MemcmpImpl == RTLIB::Unsupported)
return {};

PointerType *PT = PointerType::getUnqual(*getContext());
Expand All @@ -9075,13 +9075,14 @@ SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
bool IsTailCall =
isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg*/ true);

StringRef LibCallName = TLI->getLibcallImplName(MemcmpImpl);
CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(
TLI->getLibcallCallingConv(RTLIB::MEMCMP),
Type::getInt32Ty(*getContext()),
getExternalSymbol(LibCallName, TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setLibCallee(TLI->getLibcallImplCallingConv(MemcmpImpl),
Type::getInt32Ty(*getContext()),
getExternalSymbol(LibCallName.data(),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setTailCall(IsTailCall);

return TLI->LowerCallTo(CLI);
Expand All @@ -9091,8 +9092,8 @@ std::pair<SDValue, SDValue> SelectionDAG::getStrlen(SDValue Chain,
const SDLoc &dl,
SDValue Src,
const CallInst *CI) {
const char *LibCallName = TLI->getLibcallName(RTLIB::STRLEN);
if (!LibCallName)
RTLIB::LibcallImpl StrlenImpl = TLI->getLibcallImpl(RTLIB::STRLEN);
if (StrlenImpl == RTLIB::Unsupported)
return {};

// Emit a library call.
Expand All @@ -9102,13 +9103,15 @@ std::pair<SDValue, SDValue> SelectionDAG::getStrlen(SDValue Chain,
TargetLowering::CallLoweringInfo CLI(*this);
bool IsTailCall =
isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg*/ true);
StringRef LibcallName = TLI->getLibcallImplName(StrlenImpl);

CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(TLI->getLibcallCallingConv(RTLIB::STRLEN), CI->getType(),
getExternalSymbol(
LibCallName, TLI->getProgramPointerTy(getDataLayout())),
std::move(Args))
.setLibCallee(
TLI->getLibcallImplCallingConv(StrlenImpl), CI->getType(),
getExternalSymbol(LibcallName.data(),
TLI->getProgramPointerTy(getDataLayout())),
std::move(Args))
.setTailCall(IsTailCall);

return TLI->LowerCallTo(CLI);
Expand Down Expand Up @@ -9211,17 +9214,19 @@ SDValue SelectionDAG::getAtomicMemcpy(SDValue Chain, const SDLoc &dl,

RTLIB::Libcall LibraryCall =
RTLIB::getMEMCPY_ELEMENT_UNORDERED_ATOMIC(ElemSz);
if (LibraryCall == RTLIB::UNKNOWN_LIBCALL)
RTLIB::LibcallImpl LibcallImpl = TLI->getLibcallImpl(LibraryCall);
if (LibcallImpl == RTLIB::Unsupported)
report_fatal_error("Unsupported element size");

TargetLowering::CallLoweringInfo CLI(*this);
CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(TLI->getLibcallCallingConv(LibraryCall),
Type::getVoidTy(*getContext()),
getExternalSymbol(TLI->getLibcallName(LibraryCall),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setLibCallee(
TLI->getLibcallImplCallingConv(LibcallImpl),
Type::getVoidTy(*getContext()),
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setDiscardResult()
.setTailCall(isTailCall);

Expand Down Expand Up @@ -9317,17 +9322,19 @@ SDValue SelectionDAG::getAtomicMemmove(SDValue Chain, const SDLoc &dl,

RTLIB::Libcall LibraryCall =
RTLIB::getMEMMOVE_ELEMENT_UNORDERED_ATOMIC(ElemSz);
if (LibraryCall == RTLIB::UNKNOWN_LIBCALL)
RTLIB::LibcallImpl LibcallImpl = TLI->getLibcallImpl(LibraryCall);
if (LibcallImpl == RTLIB::Unsupported)
report_fatal_error("Unsupported element size");

TargetLowering::CallLoweringInfo CLI(*this);
CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(TLI->getLibcallCallingConv(LibraryCall),
Type::getVoidTy(*getContext()),
getExternalSymbol(TLI->getLibcallName(LibraryCall),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setLibCallee(
TLI->getLibcallImplCallingConv(LibcallImpl),
Type::getVoidTy(*getContext()),
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setDiscardResult()
.setTailCall(isTailCall);

Expand Down Expand Up @@ -9388,27 +9395,32 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
// FIXME: pass in SDLoc
CLI.setDebugLoc(dl).setChain(Chain);

const char *BzeroName = getTargetLoweringInfo().getLibcallName(RTLIB::BZERO);
RTLIB::LibcallImpl BzeroImpl = TLI->getLibcallImpl(RTLIB::BZERO);
bool UseBZero = BzeroImpl != RTLIB::Unsupported && isNullConstant(Src);

bool UseBZero = isNullConstant(Src) && BzeroName;
// If zeroing out and bzero is present, use it.
if (UseBZero) {
TargetLowering::ArgListTy Args;
Args.emplace_back(Dst, PointerType::getUnqual(Ctx));
Args.emplace_back(Size, DL.getIntPtrType(Ctx));
CLI.setLibCallee(
TLI->getLibcallCallingConv(RTLIB::BZERO), Type::getVoidTy(Ctx),
getExternalSymbol(BzeroName, TLI->getPointerTy(DL)), std::move(Args));
TLI->getLibcallImplCallingConv(BzeroImpl), Type::getVoidTy(Ctx),
getExternalSymbol(TLI->getLibcallImplName(BzeroImpl).data(),
TLI->getPointerTy(DL)),
std::move(Args));
} else {
RTLIB::LibcallImpl MemsetImpl = TLI->getLibcallImpl(RTLIB::MEMSET);

TargetLowering::ArgListTy Args;
Args.emplace_back(Dst, PointerType::getUnqual(Ctx));
Args.emplace_back(Src, Src.getValueType().getTypeForEVT(Ctx));
Args.emplace_back(Size, DL.getIntPtrType(Ctx));
CLI.setLibCallee(TLI->getLibcallCallingConv(RTLIB::MEMSET),
Dst.getValueType().getTypeForEVT(Ctx),
getExternalSymbol(TLI->getLibcallName(RTLIB::MEMSET),
TLI->getPointerTy(DL)),
std::move(Args));
CLI.setLibCallee(
TLI->getLibcallImplCallingConv(MemsetImpl),
Dst.getValueType().getTypeForEVT(Ctx),
getExternalSymbol(TLI->getLibcallImplName(MemsetImpl).data(),
TLI->getPointerTy(DL)),
std::move(Args));
}

RTLIB::LibcallImpl MemsetImpl = TLI->getLibcallImpl(RTLIB::MEMSET);
Expand Down Expand Up @@ -9440,17 +9452,19 @@ SDValue SelectionDAG::getAtomicMemset(SDValue Chain, const SDLoc &dl,

RTLIB::Libcall LibraryCall =
RTLIB::getMEMSET_ELEMENT_UNORDERED_ATOMIC(ElemSz);
if (LibraryCall == RTLIB::UNKNOWN_LIBCALL)
RTLIB::LibcallImpl LibcallImpl = TLI->getLibcallImpl(LibraryCall);
if (LibcallImpl == RTLIB::Unsupported)
report_fatal_error("Unsupported element size");

TargetLowering::CallLoweringInfo CLI(*this);
CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(TLI->getLibcallCallingConv(LibraryCall),
Type::getVoidTy(*getContext()),
getExternalSymbol(TLI->getLibcallName(LibraryCall),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setLibCallee(
TLI->getLibcallImplCallingConv(LibcallImpl),
Type::getVoidTy(*getContext()),
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setDiscardResult()
.setTailCall(isTailCall);

Expand Down Expand Up @@ -14177,13 +14191,18 @@ SDValue SelectionDAG::makeStateFunctionCall(unsigned LibFunc, SDValue Ptr,
assert(InChain.getValueType() == MVT::Other && "Expected token chain");
TargetLowering::ArgListTy Args;
Args.emplace_back(Ptr, Ptr.getValueType().getTypeForEVT(*getContext()));
RTLIB::Libcall LC = static_cast<RTLIB::Libcall>(LibFunc);
SDValue Callee = getExternalSymbol(TLI->getLibcallName(LC),
TLI->getPointerTy(getDataLayout()));
RTLIB::LibcallImpl LibcallImpl =
TLI->getLibcallImpl(static_cast<RTLIB::Libcall>(LibFunc));
if (LibcallImpl == RTLIB::Unsupported)
reportFatalUsageError("emitting call to unsupported libcall");

SDValue Callee =
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
TLI->getPointerTy(getDataLayout()));
TargetLowering::CallLoweringInfo CLI(*this);
CLI.setDebugLoc(DLoc).setChain(InChain).setLibCallee(
TLI->getLibcallCallingConv(LC), Type::getVoidTy(*getContext()), Callee,
std::move(Args));
TLI->getLibcallImplCallingConv(LibcallImpl),
Type::getVoidTy(*getContext()), Callee, std::move(Args));
return TLI->LowerCallTo(CLI).second;
}

Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,
Args.push_back(Entry);
}

const char *LibcallName = getLibcallName(LC);
if (LC == RTLIB::UNKNOWN_LIBCALL || !LibcallName)
RTLIB::LibcallImpl LibcallImpl = getLibcallImpl(LC);
if (LibcallImpl == RTLIB::Unsupported)
reportFatalInternalError("unsupported library call operation");

SDValue Callee =
DAG.getExternalSymbol(LibcallName, getPointerTy(DAG.getDataLayout()));
SDValue Callee = DAG.getExternalSymbol(getLibcallImplName(LibcallImpl).data(),
getPointerTy(DAG.getDataLayout()));

Type *RetTy = RetVT.getTypeForEVT(*DAG.getContext());
Type *OrigRetTy = RetTy;
Expand All @@ -206,8 +206,8 @@ TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,

CLI.setDebugLoc(dl)
.setChain(InChain)
.setLibCallee(getLibcallCallingConv(LC), RetTy, OrigRetTy, Callee,
std::move(Args))
.setLibCallee(getLibcallImplCallingConv(LibcallImpl), RetTy, OrigRetTy,
Callee, std::move(Args))
.setNoReturn(CallOptions.DoesNotReturn)
.setDiscardResult(!CallOptions.IsReturnValueUsed)
.setIsPostTypeLegalization(CallOptions.IsPostTypeLegalization)
Expand Down
Loading