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
5 changes: 1 addition & 4 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -3620,10 +3620,7 @@ class LLVM_ABI TargetLoweringBase {
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Call);
}

const char *getMemcpyName() const {
// FIXME: Return StringRef
return Libcalls.getMemcpyName().data();
}
RTLIB::LibcallImpl getMemcpyImpl() const { return Libcalls.getMemcpyImpl(); }

/// Check if this is valid libcall for the current module, otherwise
/// RTLIB::Unsupported.
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ struct RuntimeLibcallsInfo {

/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
/// unsupported.
StringRef getMemcpyName() const {
RTLIB::LibcallImpl getMemcpyImpl() const {
RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
if (Memcpy != RTLIB::Unsupported)
return getLibcallImplName(Memcpy);
return Memcpy;

// Fallback to memmove if memcpy isn't available.
return getLibcallName(RTLIB::MEMMOVE);
return getLibcallImpl(RTLIB::MEMMOVE);
}

bool isAvailable(RTLIB::LibcallImpl Impl) const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ llvm::createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
break;
case TargetOpcode::G_MEMCPY:
RTLibcall = RTLIB::MEMCPY;
Name = TLI.getMemcpyName();
Name = TLI.getLibcallImplName(TLI.getMemcpyImpl()).data();
Args[0].Flags[0].setReturned();
break;
case TargetOpcode::G_MEMMOVE:
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static bool canEmitMemcpy(const TargetMachine *TM, Function *F) {
if (!TM)
return true;
const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
return TLI->getMemcpyName() != nullptr;
return TLI->getMemcpyImpl() != RTLIB::Unsupported;
}

// Return a value appropriate for use with the memset_pattern16 libcall, if
Expand Down
31 changes: 18 additions & 13 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9257,21 +9257,22 @@ SDValue SelectionDAG::getMemcpy(
// FIXME: pass in SDLoc
TargetLowering::CallLoweringInfo CLI(*this);
bool IsTailCall = false;
const char *MemCpyName = TLI->getMemcpyName();
RTLIB::LibcallImpl MemCpyImpl = TLI->getMemcpyImpl();

if (OverrideTailCall.has_value()) {
IsTailCall = *OverrideTailCall;
} else {
bool LowersToMemcpy = StringRef(MemCpyName) == StringRef("memcpy");
bool LowersToMemcpy = MemCpyImpl == RTLIB::impl_memcpy;
IsTailCall = isInTailCallPositionWrapper(CI, this, LowersToMemcpy);
}

CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(
TLI->getLibcallCallingConv(RTLIB::MEMCPY),
TLI->getLibcallImplCallingConv(MemCpyImpl),
Dst.getValueType().getTypeForEVT(*getContext()),
getExternalSymbol(MemCpyName, TLI->getPointerTy(getDataLayout())),
getExternalSymbol(TLI->getLibcallImplName(MemCpyImpl).data(),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setDiscardResult()
.setTailCall(IsTailCall);
Expand Down Expand Up @@ -9361,22 +9362,24 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
// FIXME: pass in SDLoc
TargetLowering::CallLoweringInfo CLI(*this);

RTLIB::LibcallImpl MemmoveImpl = TLI->getLibcallImpl(RTLIB::MEMMOVE);

bool IsTailCall = false;
if (OverrideTailCall.has_value()) {
IsTailCall = *OverrideTailCall;
} else {
bool LowersToMemmove =
TLI->getLibcallName(RTLIB::MEMMOVE) == StringRef("memmove");
bool LowersToMemmove = MemmoveImpl == RTLIB::impl_memmove;
IsTailCall = isInTailCallPositionWrapper(CI, this, LowersToMemmove);
}

CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(TLI->getLibcallCallingConv(RTLIB::MEMMOVE),
Dst.getValueType().getTypeForEVT(*getContext()),
getExternalSymbol(TLI->getLibcallName(RTLIB::MEMMOVE),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setLibCallee(
TLI->getLibcallImplCallingConv(MemmoveImpl),
Dst.getValueType().getTypeForEVT(*getContext()),
getExternalSymbol(TLI->getLibcallImplName(MemmoveImpl).data(),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setDiscardResult()
.setTailCall(IsTailCall);

Expand Down Expand Up @@ -9492,8 +9495,10 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
TLI->getPointerTy(DL)),
std::move(Args));
}
bool LowersToMemset =
TLI->getLibcallName(RTLIB::MEMSET) == StringRef("memset");

RTLIB::LibcallImpl MemsetImpl = TLI->getLibcallImpl(RTLIB::MEMSET);
bool LowersToMemset = MemsetImpl == RTLIB::impl_memset;

// If we're going to use bzero, make sure not to tail call unless the
// subsequent return doesn't need a value, as bzero doesn't return the first
// arg unlike memset.
Expand Down