Skip to content

Commit f8577a2

Browse files
committed
IRGen: Address llvm::Type::getPointerTo deprecation
See llvm/llvm-project#113331.
1 parent 2920ea8 commit f8577a2

39 files changed

+485
-802
lines changed

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 43 additions & 87 deletions
Large diffs are not rendered by default.

lib/IRGen/GenBuiltin.cpp

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ getMaximallyAbstractedLoweredTypeAndTypeInfo(IRGenModule &IGM, Type unloweredTyp
133133
void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
134134
BuiltinInst *Inst, ArrayRef<SILType> argTypes,
135135
Explosion &args, Explosion &out) {
136+
auto &IGM = IGF.IGM;
137+
136138
Identifier FnId = Inst->getName();
137139
SILType resultType = Inst->getType();
138140
SubstitutionMap substitutions = Inst->getSubstitutions();
@@ -849,7 +851,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
849851
valueTy->getPrimitiveSizeInBits());
850852
}
851853

852-
pointer = IGF.Builder.CreateBitCast(pointer, valueTy->getPointerTo());
854+
pointer = IGF.Builder.CreateBitCast(pointer, IGM.PtrTy);
853855

854856
if (Builtin.ID == BuiltinValueKind::AtomicLoad) {
855857
auto load = IGF.Builder.CreateLoad(pointer, valueTy,
@@ -1061,8 +1063,8 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
10611063
|| Builtin.ID == BuiltinValueKind::OnceWithContext) {
10621064
// The input type is statically (Builtin.RawPointer, @convention(thin) () -> ()).
10631065
llvm::Value *PredPtr = args.claimNext();
1064-
// Cast the predicate to a OnceTy pointer.
1065-
PredPtr = IGF.Builder.CreateBitCast(PredPtr, IGF.IGM.OnceTy->getPointerTo());
1066+
// Cast the predicate to a pointer.
1067+
PredPtr = IGF.Builder.CreateBitCast(PredPtr, IGM.PtrTy);
10661068
llvm::Value *FnCode = args.claimNext();
10671069
// Get the context if any.
10681070
llvm::Value *Context;
@@ -1153,9 +1155,8 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
11531155
IsTriviallyDestroyable)
11541156
return;
11551157

1156-
llvm::Value *firstElem =
1157-
IGF.Builder.CreatePtrToInt(IGF.Builder.CreateBitCast(
1158-
ptr, elemTI.getStorageType()->getPointerTo()), IGF.IGM.IntPtrTy);
1158+
llvm::Value *firstElem = IGF.Builder.CreatePtrToInt(
1159+
IGF.Builder.CreateBitCast(ptr, IGM.PtrTy), IGF.IGM.IntPtrTy);
11591160

11601161
auto *origBB = IGF.Builder.GetInsertBlock();
11611162
auto *headerBB = IGF.createBasicBlock("loop_header");
@@ -1173,8 +1174,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
11731174
llvm::Value *offset =
11741175
IGF.Builder.CreateMul(phi, elemTI.getStaticStride(IGF.IGM));
11751176
llvm::Value *added = IGF.Builder.CreateAdd(firstElem, offset);
1176-
llvm::Value *addr = IGF.Builder.CreateIntToPtr(
1177-
added, elemTI.getStorageType()->getPointerTo());
1177+
llvm::Value *addr = IGF.Builder.CreateIntToPtr(added, IGM.PtrTy);
11781178

11791179
bool isOutlined = false;
11801180
elemTI.destroy(IGF, elemTI.getAddressForPointer(addr), elemTy,
@@ -1189,8 +1189,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
11891189
return;
11901190
}
11911191

1192-
ptr = IGF.Builder.CreateBitCast(ptr,
1193-
valueTy.second.getStorageType()->getPointerTo());
1192+
ptr = IGF.Builder.CreateBitCast(ptr, IGM.PtrTy);
11941193
Address array = valueTy.second.getAddressForPointer(ptr);
11951194

11961195
// If the count is statically known to be a constant 1, then just call the
@@ -1242,13 +1241,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
12421241
}
12431242

12441243
llvm::Value *firstSrcElem = IGF.Builder.CreatePtrToInt(
1245-
IGF.Builder.CreateBitCast(src,
1246-
elemTI.getStorageType()->getPointerTo()),
1247-
IGF.IGM.IntPtrTy);
1244+
IGF.Builder.CreateBitCast(src, IGM.PtrTy), IGF.IGM.IntPtrTy);
12481245
llvm::Value *firstDestElem = IGF.Builder.CreatePtrToInt(
1249-
IGF.Builder.CreateBitCast(dest,
1250-
elemTI.getStorageType()->getPointerTo()),
1251-
IGF.IGM.IntPtrTy);
1246+
IGF.Builder.CreateBitCast(dest, IGM.PtrTy), IGF.IGM.IntPtrTy);
12521247

12531248
auto *origBB = IGF.Builder.GetInsertBlock();
12541249
auto *headerBB = IGF.createBasicBlock("loop_header");
@@ -1280,11 +1275,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
12801275
IGF.Builder.CreateMul(idx, elemTI.getStaticStride(IGF.IGM));
12811276

12821277
llvm::Value *srcAdded = IGF.Builder.CreateAdd(firstSrcElem, offset);
1283-
auto *srcElem = IGF.Builder.CreateIntToPtr(
1284-
srcAdded, elemTI.getStorageType()->getPointerTo());
1278+
auto *srcElem = IGF.Builder.CreateIntToPtr(srcAdded, IGM.PtrTy);
12851279
llvm::Value *dstAdded = IGF.Builder.CreateAdd(firstDestElem, offset);
1286-
auto *destElem = IGF.Builder.CreateIntToPtr(
1287-
dstAdded, elemTI.getStorageType()->getPointerTo());
1280+
auto *destElem = IGF.Builder.CreateIntToPtr(dstAdded, IGM.PtrTy);
12881281

12891282
Address destAddr = elemTI.getAddressForPointer(destElem);
12901283
Address srcAddr = elemTI.getAddressForPointer(srcElem);
@@ -1322,11 +1315,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
13221315

13231316
auto valueTy = getLoweredTypeAndTypeInfo(IGF.IGM,
13241317
substitutions.getReplacementTypes()[0]);
1325-
1326-
dest = IGF.Builder.CreateBitCast(dest,
1327-
valueTy.second.getStorageType()->getPointerTo());
1328-
src = IGF.Builder.CreateBitCast(src,
1329-
valueTy.second.getStorageType()->getPointerTo());
1318+
1319+
dest = IGF.Builder.CreateBitCast(dest, IGM.PtrTy);
1320+
src = IGF.Builder.CreateBitCast(src, IGM.PtrTy);
13301321
Address destArray = valueTy.second.getAddressForPointer(dest);
13311322
Address srcArray = valueTy.second.getAddressForPointer(src);
13321323

lib/IRGen/GenCall.cpp

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,7 @@ namespace {
639639
}
640640

641641
/// Add a pointer to the given type as the next parameter.
642-
void addPointerParameter(llvm::Type *storageType) {
643-
ParamIRTypes.push_back(storageType->getPointerTo());
644-
}
642+
void addOpaquePointerParameter() { ParamIRTypes.push_back(IGM.PtrTy); }
645643

646644
void addCoroutineContextParameter();
647645
void addCoroutineAllocatorParameter();
@@ -674,7 +672,7 @@ llvm::Type *SignatureExpansion::addIndirectResult(SILType resultType,
674672
auto storageTy = resultTI.getStorageType();
675673
addIndirectResultAttributes(IGM, Attrs, ParamIRTypes.size(), claimSRet(),
676674
storageTy, resultTI, useInReg);
677-
addPointerParameter(storageTy);
675+
addOpaquePointerParameter();
678676
return IGM.VoidTy;
679677
}
680678

@@ -749,7 +747,7 @@ void SignatureExpansion::expandIndirectResults() {
749747
}
750748
addIndirectResultAttributes(IGM, Attrs, ParamIRTypes.size(), useSRet,
751749
storageTy, typeInfo);
752-
addPointerParameter(storageTy);
750+
addOpaquePointerParameter();
753751
}
754752
}
755753

@@ -787,9 +785,9 @@ namespace {
787785
/// Is the yielded value formally indirect?
788786
bool isFormalIndirect() const { return YieldTy.isAddress(); }
789787

790-
llvm::PointerType *getIndirectPointerType() const {
788+
llvm::PointerType *getIndirectPointerType(IRGenModule &IGM) const {
791789
assert(isIndirect());
792-
return YieldTI.getStorageType()->getPointerTo();
790+
return IGM.PtrTy;
793791
}
794792

795793
const NativeConventionSchema &getDirectSchema() const {
@@ -849,7 +847,7 @@ void SignatureExpansion::expandCoroutineResult(bool forContinuation) {
849847

850848
// If the individual value must be yielded indirectly, add a pointer.
851849
if (schema.isIndirect()) {
852-
components.push_back(schema.getIndirectPointerType());
850+
components.push_back(schema.getIndirectPointerType(IGM));
853851
continue;
854852
}
855853

@@ -891,7 +889,7 @@ void SignatureExpansion::expandCoroutineResult(bool forContinuation) {
891889
// trusting LLVM's?
892890
CoroInfo.indirectResultsType =
893891
llvm::StructType::get(IGM.getLLVMContext(), overflowTypes);
894-
components.back() = CoroInfo.indirectResultsType->getPointerTo();
892+
components.back() = IGM.PtrTy;
895893
}
896894

897895
ResultIRType = components.size() == 1
@@ -1724,7 +1722,7 @@ void SignatureExpansion::expandExternalSignatureTypes() {
17241722
Alignment(AI.getIndirectAlign().getQuantity()),
17251723
paramTI.getStorageType());
17261724
}
1727-
addPointerParameter(paramTI.getStorageType());
1725+
addOpaquePointerParameter();
17281726
break;
17291727
}
17301728
case clang::CodeGen::ABIArgInfo::Expand:
@@ -1799,8 +1797,7 @@ const TypeInfo &SignatureExpansion::expand(unsigned paramIdx) {
17991797
case ParameterConvention::Indirect_In_CXX:
18001798
addIndirectValueParameterAttributes(IGM, Attrs, ti, ParamIRTypes.size(),
18011799
isAddressableParam(paramIdx));
1802-
addPointerParameter(IGM.getStorageType(getSILFuncConventions().getSILType(
1803-
param, IGM.getMaximalTypeExpansionContext())));
1800+
addOpaquePointerParameter();
18041801
return ti;
18051802

18061803
case ParameterConvention::Indirect_Inout:
@@ -1809,15 +1806,14 @@ const TypeInfo &SignatureExpansion::expand(unsigned paramIdx) {
18091806
IGM, paramSILType, Attrs, ti, ParamIRTypes.size(),
18101807
conv == ParameterConvention::Indirect_InoutAliasable,
18111808
isAddressableParam(paramIdx));
1812-
addPointerParameter(IGM.getStorageType(getSILFuncConventions().getSILType(
1813-
param, IGM.getMaximalTypeExpansionContext())));
1809+
addOpaquePointerParameter();
18141810
return ti;
18151811

18161812
case ParameterConvention::Pack_Guaranteed:
18171813
case ParameterConvention::Pack_Owned:
18181814
case ParameterConvention::Pack_Inout:
18191815
addPackParameterAttributes(IGM, paramSILType, Attrs, ParamIRTypes.size());
1820-
addPointerParameter(ti.getStorageType());
1816+
addOpaquePointerParameter();
18211817
return ti;
18221818

18231819
case ParameterConvention::Direct_Owned:
@@ -1834,7 +1830,7 @@ const TypeInfo &SignatureExpansion::expand(unsigned paramIdx) {
18341830
addIndirectValueParameterAttributes(IGM, Attrs, ti,
18351831
ParamIRTypes.size(),
18361832
/*addressable*/ false);
1837-
ParamIRTypes.push_back(ti.getStorageType()->getPointerTo());
1833+
addOpaquePointerParameter();
18381834
return ti;
18391835
}
18401836
if (nativeSchema.empty()) {
@@ -1989,8 +1985,8 @@ void SignatureExpansion::expandParameters(
19891985
auto fnConv = getSILFuncConventions();
19901986
for (auto indirectResultType : fnConv.getIndirectSILResultTypes(
19911987
IGM.getMaximalTypeExpansionContext())) {
1992-
auto storageTy = IGM.getStorageType(indirectResultType);
1993-
addPointerParameter(storageTy);
1988+
(void)indirectResultType;
1989+
addOpaquePointerParameter();
19941990
}
19951991
break;
19961992
}
@@ -2079,8 +2075,7 @@ void SignatureExpansion::expandParameters(
20792075
if (FnType->hasErrorResult()) {
20802076
if (claimError())
20812077
IGM.addSwiftErrorAttributes(Attrs, ParamIRTypes.size());
2082-
llvm::Type *errorType = getErrorRegisterType();
2083-
ParamIRTypes.push_back(errorType->getPointerTo());
2078+
addOpaquePointerParameter();
20842079
if (recordedABIDetails)
20852080
recordedABIDetails->hasErrorResult = true;
20862081
if (getSILFuncConventions().isTypedError()) {
@@ -2098,7 +2093,7 @@ void SignatureExpansion::expandParameters(
20982093
getSILFuncConventions().hasIndirectSILErrorResults() ||
20992094
native.requiresIndirect() ||
21002095
nativeError.shouldReturnTypedErrorIndirectly()) {
2101-
ParamIRTypes.push_back(IGM.getStorageType(errorType)->getPointerTo());
2096+
addOpaquePointerParameter();
21022097
}
21032098
}
21042099
}
@@ -2241,8 +2236,7 @@ void SignatureExpansion::addIndirectThrowingResult() {
22412236
getSILFuncConventions().hasIndirectSILErrorResults() ||
22422237
native.requiresIndirect() ||
22432238
nativeError.shouldReturnTypedErrorIndirectly()) {
2244-
auto errorStorageTy = errorTI.getStorageType();
2245-
ParamIRTypes.push_back(errorStorageTy->getPointerTo());
2239+
addOpaquePointerParameter();
22462240
}
22472241
}
22482242

@@ -2566,8 +2560,7 @@ llvm::Value *emitIndirectAsyncFunctionPointer(IRGenFunction &IGF,
25662560

25672561
llvm::Value *UntaggedPointer = IGF.Builder.CreateAnd(PtrToInt, NegativeOne);
25682562
llvm::Value *IntToPtr =
2569-
IGF.Builder.CreateIntToPtr(UntaggedPointer,
2570-
AsyncFunctionPointerPtrTy->getPointerTo());
2563+
IGF.Builder.CreateIntToPtr(UntaggedPointer, IGF.IGM.PtrTy);
25712564
llvm::Value *Load = IGF.Builder.CreateLoad(
25722565
IntToPtr, AsyncFunctionPointerPtrTy, PointerAlignment);
25732566

@@ -2596,8 +2589,8 @@ llvm::Value *emitIndirectCoroFunctionPointer(IRGenFunction &IGF,
25962589
IGF.Builder.CreateBitCast(pointer, CoroFunctionPointerPtrTy);
25972590

25982591
llvm::Value *UntaggedPointer = IGF.Builder.CreateAnd(PtrToInt, NegativeOne);
2599-
llvm::Value *IntToPtr = IGF.Builder.CreateIntToPtr(
2600-
UntaggedPointer, CoroFunctionPointerPtrTy->getPointerTo());
2592+
llvm::Value *IntToPtr =
2593+
IGF.Builder.CreateIntToPtr(UntaggedPointer, IGF.IGM.PtrTy);
26012594
llvm::Value *Load = IGF.Builder.CreateLoad(IntToPtr, CoroFunctionPointerPtrTy,
26022595
PointerAlignment);
26032596

@@ -3236,9 +3229,8 @@ class AsyncCallEmission final : public CallEmission {
32363229
getCallee().getFunctionPointer().getKind());
32373230

32383231
return FunctionPointer::createForAsyncCall(
3239-
IGF.Builder.CreateBitCast(calleeFunction,
3240-
awaitEntrySig.getType()->getPointerTo()),
3241-
codeAuthInfo, awaitSig, awaitEntrySig.getType());
3232+
IGF.Builder.CreateBitCast(calleeFunction, IGF.IGM.PtrTy), codeAuthInfo,
3233+
awaitSig, awaitEntrySig.getType());
32423234
}
32433235

32443236
SILType getParameterType(unsigned index) override {
@@ -3913,8 +3905,9 @@ void CallEmission::emitYieldsToExplosion(Explosion &out) {
39133905

39143906
// If the schema says it's indirect, then we expect a pointer.
39153907
if (schema.isIndirect()) {
3916-
auto pointer = IGF.Builder.CreateBitCast(rawYieldComponents.claimNext(),
3917-
schema.getIndirectPointerType());
3908+
auto pointer =
3909+
IGF.Builder.CreateBitCast(rawYieldComponents.claimNext(),
3910+
schema.getIndirectPointerType(IGF.IGM));
39183911

39193912
// If it's formally indirect, then we should just add that pointer
39203913
// to the output.
@@ -5190,8 +5183,7 @@ static llvm::Constant *getCoroAllocFn(IRGenModule &IGM) {
51905183
{llvm::ConstantInt::get(IGF.IGM.Int32Ty, 0),
51915184
llvm::ConstantInt::get(IGF.IGM.Int32Ty, 1)});
51925185
auto *callee = IGF.Builder.CreateLoad(
5193-
Address(calleePtr, IGF.IGM.CoroAllocateFnTy->getPointerTo(),
5194-
IGF.IGM.getPointerAlignment()),
5186+
Address(calleePtr, IGF.IGM.PtrTy, IGF.IGM.getPointerAlignment()),
51955187
"allocate_fn");
51965188
auto fnPtr = FunctionPointer::createUnsigned(
51975189
FunctionPointer::Kind::Function, callee,
@@ -5268,8 +5260,7 @@ static llvm::Constant *getCoroDeallocFn(IRGenModule &IGM) {
52685260
{llvm::ConstantInt::get(IGF.IGM.Int32Ty, 0),
52695261
llvm::ConstantInt::get(IGF.IGM.Int32Ty, 2)});
52705262
auto *callee = IGF.Builder.CreateLoad(
5271-
Address(calleePtr, IGF.IGM.CoroDeallocateFnTy->getPointerTo(),
5272-
IGF.IGM.getPointerAlignment()),
5263+
Address(calleePtr, IGF.IGM.PtrTy, IGF.IGM.getPointerAlignment()),
52735264
"deallocate_fn");
52745265
auto fnPtr = FunctionPointer::createUnsigned(
52755266
FunctionPointer::Kind::Function, callee,
@@ -6412,8 +6403,7 @@ Explosion IRGenFunction::coerceValueTo(SILType fromTy, Explosion &from,
64126403
auto temporary = toTI.allocateStack(*this, toTy, "coerce.temp");
64136404

64146405
auto addr =
6415-
Address(Builder.CreateBitCast(temporary.getAddressPointer(),
6416-
fromTI.getStorageType()->getPointerTo()),
6406+
Address(Builder.CreateBitCast(temporary.getAddressPointer(), IGM.PtrTy),
64176407
fromTI.getStorageType(), temporary.getAlignment());
64186408
fromTI.initialize(*this, from, addr, false);
64196409

@@ -6549,7 +6539,7 @@ Signature irgen::emitCastOfFunctionPointer(IRGenFunction &IGF,
65496539
: IGF.IGM.getSignature(fnType);
65506540

65516541
// Emit the cast.
6552-
fnPtr = IGF.Builder.CreateBitCast(fnPtr, sig.getType()->getPointerTo());
6542+
fnPtr = IGF.Builder.CreateBitCast(fnPtr, IGF.IGM.PtrTy);
65536543

65546544
// Return the information.
65556545
return sig;
@@ -7038,7 +7028,7 @@ IRGenFunction::getFunctionPointerForResumeIntrinsic(llvm::Value *resume) {
70387028
Signature(fnTy, attrs, IGM.SwiftAsyncCC);
70397029
auto fnPtr = FunctionPointer::createUnsigned(
70407030
FunctionPointer::Kind::Function,
7041-
Builder.CreateBitOrPointerCast(resume, fnTy->getPointerTo()), signature);
7031+
Builder.CreateBitOrPointerCast(resume, IGM.PtrTy), signature);
70427032
return fnPtr;
70437033
}
70447034

lib/IRGen/GenCast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ void irgen::emitScalarCheckedCast(IRGenFunction &IGF,
10081008
IGF.IGM.getPointerAlignment(),
10091009
"castSrc");
10101010
IGF.Builder.CreateStore(metatypeVal, src);
1011-
llvm::PointerType *destPtrType = IGF.IGM.getStoragePointerType(targetLoweredType);
1011+
llvm::PointerType *destPtrType = IGF.IGM.PtrTy;
10121012
Address dest = IGF.createAlloca(destPtrType,
10131013
IGF.IGM.getPointerAlignment(),
10141014
"castDest");

0 commit comments

Comments
 (0)