Skip to content

Commit b2d9356

Browse files
authored
DAG: Make more use of the LibcallImpl overload of getExternalSymbol (#172171)
Also add a new copy for TargetExternalSymbol that AArch64 needs.
1 parent a5625ed commit b2d9356

File tree

4 files changed

+57
-52
lines changed

4 files changed

+57
-52
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,9 @@ class SelectionDAG {
796796
LLVM_ABI SDValue getExternalSymbol(RTLIB::LibcallImpl LCImpl, EVT VT);
797797
LLVM_ABI SDValue getTargetExternalSymbol(const char *Sym, EVT VT,
798798
unsigned TargetFlags = 0);
799+
LLVM_ABI SDValue getTargetExternalSymbol(RTLIB::LibcallImpl LCImpl, EVT VT,
800+
unsigned TargetFlags = 0);
801+
799802
LLVM_ABI SDValue getMCSymbol(MCSymbol *Sym, EVT VT);
800803

801804
LLVM_ABI SDValue getValueType(EVT);

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,12 @@ SDValue SelectionDAG::getTargetExternalSymbol(const char *Sym, EVT VT,
20902090
return SDValue(N, 0);
20912091
}
20922092

2093+
SDValue SelectionDAG::getTargetExternalSymbol(RTLIB::LibcallImpl Libcall,
2094+
EVT VT, unsigned TargetFlags) {
2095+
StringRef SymName = TLI->getLibcallImplName(Libcall);
2096+
return getTargetExternalSymbol(SymName.data(), VT, TargetFlags);
2097+
}
2098+
20932099
SDValue SelectionDAG::getCondCode(ISD::CondCode Cond) {
20942100
if ((unsigned)Cond >= CondCodeNodes.size())
20952101
CondCodeNodes.resize(Cond+1);
@@ -9122,14 +9128,13 @@ SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
91229128
bool IsTailCall =
91239129
isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg*/ true);
91249130

9125-
StringRef LibCallName = TLI->getLibcallImplName(MemcmpImpl);
91269131
CLI.setDebugLoc(dl)
91279132
.setChain(Chain)
9128-
.setLibCallee(TLI->getLibcallImplCallingConv(MemcmpImpl),
9129-
Type::getInt32Ty(*getContext()),
9130-
getExternalSymbol(LibCallName.data(),
9131-
TLI->getPointerTy(getDataLayout())),
9132-
std::move(Args))
9133+
.setLibCallee(
9134+
TLI->getLibcallImplCallingConv(MemcmpImpl),
9135+
Type::getInt32Ty(*getContext()),
9136+
getExternalSymbol(MemcmpImpl, TLI->getPointerTy(getDataLayout())),
9137+
std::move(Args))
91339138
.setTailCall(IsTailCall);
91349139

91359140
return TLI->LowerCallTo(CLI);
@@ -9150,15 +9155,13 @@ std::pair<SDValue, SDValue> SelectionDAG::getStrlen(SDValue Chain,
91509155
TargetLowering::CallLoweringInfo CLI(*this);
91519156
bool IsTailCall =
91529157
isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg*/ true);
9153-
StringRef LibcallName = TLI->getLibcallImplName(StrlenImpl);
91549158

91559159
CLI.setDebugLoc(dl)
91569160
.setChain(Chain)
9157-
.setLibCallee(
9158-
TLI->getLibcallImplCallingConv(StrlenImpl), CI->getType(),
9159-
getExternalSymbol(LibcallName.data(),
9160-
TLI->getProgramPointerTy(getDataLayout())),
9161-
std::move(Args))
9161+
.setLibCallee(TLI->getLibcallImplCallingConv(StrlenImpl), CI->getType(),
9162+
getExternalSymbol(
9163+
StrlenImpl, TLI->getProgramPointerTy(getDataLayout())),
9164+
std::move(Args))
91629165
.setTailCall(IsTailCall);
91639166

91649167
return TLI->LowerCallTo(CLI);
@@ -9236,8 +9239,7 @@ SDValue SelectionDAG::getMemcpy(
92369239
.setLibCallee(
92379240
TLI->getLibcallImplCallingConv(MemCpyImpl),
92389241
Dst.getValueType().getTypeForEVT(*getContext()),
9239-
getExternalSymbol(TLI->getLibcallImplName(MemCpyImpl).data(),
9240-
TLI->getPointerTy(getDataLayout())),
9242+
getExternalSymbol(MemCpyImpl, TLI->getPointerTy(getDataLayout())),
92419243
std::move(Args))
92429244
.setDiscardResult()
92439245
.setTailCall(IsTailCall);
@@ -9271,8 +9273,7 @@ SDValue SelectionDAG::getAtomicMemcpy(SDValue Chain, const SDLoc &dl,
92719273
.setLibCallee(
92729274
TLI->getLibcallImplCallingConv(LibcallImpl),
92739275
Type::getVoidTy(*getContext()),
9274-
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
9275-
TLI->getPointerTy(getDataLayout())),
9276+
getExternalSymbol(LibcallImpl, TLI->getPointerTy(getDataLayout())),
92769277
std::move(Args))
92779278
.setDiscardResult()
92789279
.setTailCall(isTailCall);
@@ -9344,8 +9345,7 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
93449345
.setLibCallee(
93459346
TLI->getLibcallImplCallingConv(MemmoveImpl),
93469347
Dst.getValueType().getTypeForEVT(*getContext()),
9347-
getExternalSymbol(TLI->getLibcallImplName(MemmoveImpl).data(),
9348-
TLI->getPointerTy(getDataLayout())),
9348+
getExternalSymbol(MemmoveImpl, TLI->getPointerTy(getDataLayout())),
93499349
std::move(Args))
93509350
.setDiscardResult()
93519351
.setTailCall(IsTailCall);
@@ -9379,8 +9379,7 @@ SDValue SelectionDAG::getAtomicMemmove(SDValue Chain, const SDLoc &dl,
93799379
.setLibCallee(
93809380
TLI->getLibcallImplCallingConv(LibcallImpl),
93819381
Type::getVoidTy(*getContext()),
9382-
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
9383-
TLI->getPointerTy(getDataLayout())),
9382+
getExternalSymbol(LibcallImpl, TLI->getPointerTy(getDataLayout())),
93849383
std::move(Args))
93859384
.setDiscardResult()
93869385
.setTailCall(isTailCall);
@@ -9452,22 +9451,18 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
94529451
Args.emplace_back(Size, DL.getIntPtrType(Ctx));
94539452
CLI.setLibCallee(
94549453
TLI->getLibcallImplCallingConv(BzeroImpl), Type::getVoidTy(Ctx),
9455-
getExternalSymbol(TLI->getLibcallImplName(BzeroImpl).data(),
9456-
TLI->getPointerTy(DL)),
9457-
std::move(Args));
9454+
getExternalSymbol(BzeroImpl, TLI->getPointerTy(DL)), std::move(Args));
94589455
} else {
94599456
RTLIB::LibcallImpl MemsetImpl = TLI->getLibcallImpl(RTLIB::MEMSET);
94609457

94619458
TargetLowering::ArgListTy Args;
94629459
Args.emplace_back(Dst, PointerType::getUnqual(Ctx));
94639460
Args.emplace_back(Src, Src.getValueType().getTypeForEVT(Ctx));
94649461
Args.emplace_back(Size, DL.getIntPtrType(Ctx));
9465-
CLI.setLibCallee(
9466-
TLI->getLibcallImplCallingConv(MemsetImpl),
9467-
Dst.getValueType().getTypeForEVT(Ctx),
9468-
getExternalSymbol(TLI->getLibcallImplName(MemsetImpl).data(),
9469-
TLI->getPointerTy(DL)),
9470-
std::move(Args));
9462+
CLI.setLibCallee(TLI->getLibcallImplCallingConv(MemsetImpl),
9463+
Dst.getValueType().getTypeForEVT(Ctx),
9464+
getExternalSymbol(MemsetImpl, TLI->getPointerTy(DL)),
9465+
std::move(Args));
94719466
}
94729467

94739468
RTLIB::LibcallImpl MemsetImpl = TLI->getLibcallImpl(RTLIB::MEMSET);
@@ -9509,8 +9504,7 @@ SDValue SelectionDAG::getAtomicMemset(SDValue Chain, const SDLoc &dl,
95099504
.setLibCallee(
95109505
TLI->getLibcallImplCallingConv(LibcallImpl),
95119506
Type::getVoidTy(*getContext()),
9512-
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
9513-
TLI->getPointerTy(getDataLayout())),
9507+
getExternalSymbol(LibcallImpl, TLI->getPointerTy(getDataLayout())),
95149508
std::move(Args))
95159509
.setDiscardResult()
95169510
.setTailCall(isTailCall);
@@ -14244,8 +14238,7 @@ SDValue SelectionDAG::makeStateFunctionCall(unsigned LibFunc, SDValue Ptr,
1424414238
reportFatalUsageError("emitting call to unsupported libcall");
1424514239

1424614240
SDValue Callee =
14247-
getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
14248-
TLI->getPointerTy(getDataLayout()));
14241+
getExternalSymbol(LibcallImpl, TLI->getPointerTy(getDataLayout()));
1424914242
TargetLowering::CallLoweringInfo CLI(*this);
1425014243
CLI.setDebugLoc(DLoc).setChain(InChain).setLibCallee(
1425114244
TLI->getLibcallImplCallingConv(LibcallImpl),

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6005,7 +6005,7 @@ SDValue AArch64TargetLowering::getRuntimePStateSM(SelectionDAG &DAG,
60056005
SDValue Chain, SDLoc DL,
60066006
EVT VT) const {
60076007
RTLIB::Libcall LC = RTLIB::SMEABI_SME_STATE;
6008-
SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC),
6008+
SDValue Callee = DAG.getExternalSymbol(getLibcallImpl(LC),
60096009
getPointerTy(DAG.getDataLayout()));
60106010
Type *Int64Ty = Type::getInt64Ty(*DAG.getContext());
60116011
Type *RetTy = StructType::get(Int64Ty, Int64Ty);
@@ -8413,7 +8413,7 @@ static SDValue emitSMEStateSaveRestore(const AArch64TargetLowering &TLI,
84138413

84148414
RTLIB::Libcall LC =
84158415
IsSave ? RTLIB::SMEABI_SME_SAVE : RTLIB::SMEABI_SME_RESTORE;
8416-
SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
8416+
SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallImpl(LC),
84178417
TLI.getPointerTy(DAG.getDataLayout()));
84188418
auto *RetTy = Type::getVoidTy(*DAG.getContext());
84198419
TargetLowering::CallLoweringInfo CLI(DAG);
@@ -8433,7 +8433,7 @@ static SDValue emitRestoreZALazySave(SDValue Chain, SDLoc DL,
84338433
SDValue RegMask = DAG.getRegisterMask(TRI.getCallPreservedMask(
84348434
DAG.getMachineFunction(), TLI.getLibcallCallingConv(LC)));
84358435
SDValue RestoreRoutine = DAG.getTargetExternalSymbol(
8436-
TLI.getLibcallName(LC), TLI.getPointerTy(DAG.getDataLayout()));
8436+
TLI.getLibcallImpl(LC), TLI.getPointerTy(DAG.getDataLayout()));
84378437
SDValue TPIDR2_EL0 = DAG.getNode(
84388438
ISD::INTRINSIC_W_CHAIN, DL, MVT::i64, Chain,
84398439
DAG.getTargetConstant(Intrinsic::aarch64_sme_get_tpidr2, DL, MVT::i32));
@@ -8944,7 +8944,7 @@ SDValue AArch64TargetLowering::LowerFormalArguments(
89448944
} else if (Attrs.hasAgnosticZAInterface()) {
89458945
RTLIB::Libcall LC = RTLIB::SMEABI_SME_STATE_SIZE;
89468946
SDValue Callee = DAG.getExternalSymbol(
8947-
getLibcallName(LC), getPointerTy(DAG.getDataLayout()));
8947+
getLibcallImpl(LC), getPointerTy(DAG.getDataLayout()));
89488948
auto *RetTy = EVT(MVT::i64).getTypeForEVT(*DAG.getContext());
89498949
TargetLowering::CallLoweringInfo CLI(DAG);
89508950
CLI.setDebugLoc(DL).setChain(Chain).setLibCallee(

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9631,8 +9631,8 @@ SDValue ARMTargetLowering::LowerWindowsDIVLibCall(SDValue Op, SelectionDAG &DAG,
96319631
else
96329632
LC = VT == MVT::i32 ? RTLIB::UDIVREM_I32 : RTLIB::UDIVREM_I64;
96339633

9634-
const char *Name = getLibcallName(LC);
9635-
SDValue ES = DAG.getExternalSymbol(Name, getPointerTy(DL));
9634+
RTLIB::LibcallImpl LCImpl = getLibcallImpl(LC);
9635+
SDValue ES = DAG.getExternalSymbol(LCImpl, getPointerTy(DL));
96369636

96379637
ARMTargetLowering::ArgListTy Args;
96389638

@@ -9643,10 +9643,9 @@ SDValue ARMTargetLowering::LowerWindowsDIVLibCall(SDValue Op, SelectionDAG &DAG,
96439643
}
96449644

96459645
CallLoweringInfo CLI(DAG);
9646-
CLI.setDebugLoc(dl)
9647-
.setChain(Chain)
9648-
.setCallee(CallingConv::ARM_AAPCS_VFP, VT.getTypeForEVT(*DAG.getContext()),
9649-
ES, std::move(Args));
9646+
CLI.setDebugLoc(dl).setChain(Chain).setCallee(
9647+
getLibcallImplCallingConv(LCImpl), VT.getTypeForEVT(*DAG.getContext()),
9648+
ES, std::move(Args));
96509649

96519650
return LowerCallTo(CLI).first;
96529651
}
@@ -20423,18 +20422,23 @@ SDValue ARMTargetLowering::LowerDivRem(SDValue Op, SelectionDAG &DAG) const {
2042320422
DAG.getContext(),
2042420423
Subtarget);
2042520424

20426-
SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC),
20427-
getPointerTy(DAG.getDataLayout()));
20425+
RTLIB::LibcallImpl LCImpl = getLibcallImpl(LC);
20426+
SDValue Callee =
20427+
DAG.getExternalSymbol(LCImpl, getPointerTy(DAG.getDataLayout()));
2042820428

2042920429
Type *RetTy = StructType::get(Ty, Ty);
2043020430

2043120431
if (Subtarget->isTargetWindows())
2043220432
InChain = WinDBZCheckDenominator(DAG, Op.getNode(), InChain);
2043320433

2043420434
TargetLowering::CallLoweringInfo CLI(DAG);
20435-
CLI.setDebugLoc(dl).setChain(InChain)
20436-
.setCallee(getLibcallCallingConv(LC), RetTy, Callee, std::move(Args))
20437-
.setInRegister().setSExtResult(isSigned).setZExtResult(!isSigned);
20435+
CLI.setDebugLoc(dl)
20436+
.setChain(InChain)
20437+
.setCallee(getLibcallImplCallingConv(LCImpl), RetTy, Callee,
20438+
std::move(Args))
20439+
.setInRegister()
20440+
.setSExtResult(isSigned)
20441+
.setZExtResult(!isSigned);
2043820442

2043920443
std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
2044020444
return CallInfo.first;
@@ -20475,17 +20479,22 @@ SDValue ARMTargetLowering::LowerREM(SDNode *N, SelectionDAG &DAG) const {
2047520479
TargetLowering::ArgListTy Args = getDivRemArgList(N, DAG.getContext(),
2047620480
Subtarget);
2047720481
bool isSigned = N->getOpcode() == ISD::SREM;
20478-
SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC),
20479-
getPointerTy(DAG.getDataLayout()));
20482+
20483+
RTLIB::LibcallImpl LCImpl = getLibcallImpl(LC);
20484+
SDValue Callee =
20485+
DAG.getExternalSymbol(LCImpl, getPointerTy(DAG.getDataLayout()));
2048020486

2048120487
if (Subtarget->isTargetWindows())
2048220488
InChain = WinDBZCheckDenominator(DAG, N, InChain);
2048320489

2048420490
// Lower call
2048520491
CallLoweringInfo CLI(DAG);
2048620492
CLI.setChain(InChain)
20487-
.setCallee(CallingConv::ARM_AAPCS, RetTy, Callee, std::move(Args))
20488-
.setSExtResult(isSigned).setZExtResult(!isSigned).setDebugLoc(SDLoc(N));
20493+
.setCallee(getLibcallImplCallingConv(LCImpl), RetTy, Callee,
20494+
std::move(Args))
20495+
.setSExtResult(isSigned)
20496+
.setZExtResult(!isSigned)
20497+
.setDebugLoc(SDLoc(N));
2048920498
std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI);
2049020499

2049120500
// Return second (rem) result operand (first contains div)

0 commit comments

Comments
 (0)