Skip to content

Commit 2f94890

Browse files
committed
IRGen: Remove supportsTypedPointers, getNonOpaquePointerElementType, isOpaqueOrPointeeTypeMatches
Typed pointers are no longer supported by llvm. rdar://121083958
1 parent a48dc87 commit 2f94890

File tree

7 files changed

+2
-110
lines changed

7 files changed

+2
-110
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,26 +3204,6 @@ llvm::CallBase *CallEmission::emitCallSite() {
32043204
return call;
32053205
}
32063206

3207-
static llvm::AttributeList
3208-
assertTypesInByValAndStructRetAttributes(llvm::FunctionType *fnType,
3209-
llvm::AttributeList attrList) {
3210-
auto &context = fnType->getContext();
3211-
if (context.supportsTypedPointers()) {
3212-
for (unsigned i = 0; i < fnType->getNumParams(); ++i) {
3213-
auto paramTy = fnType->getParamType(i);
3214-
assert(
3215-
!attrList.hasParamAttr(i, llvm::Attribute::StructRet) ||
3216-
llvm::cast<llvm::PointerType>(paramTy)->isOpaqueOrPointeeTypeMatches(
3217-
attrList.getParamStructRetType(i)));
3218-
assert(
3219-
!attrList.hasParamAttr(i, llvm::Attribute::ByVal) ||
3220-
llvm::cast<llvm::PointerType>(paramTy)->isOpaqueOrPointeeTypeMatches(
3221-
attrList.getParamByValType(i)));
3222-
}
3223-
}
3224-
return attrList;
3225-
}
3226-
32273207
llvm::CallBase *IRBuilder::CreateCallOrInvoke(
32283208
const FunctionPointer &fn, ArrayRef<llvm::Value *> args,
32293209
llvm::BasicBlock *invokeNormalDest, llvm::BasicBlock *invokeUnwindDest) {
@@ -3265,7 +3245,7 @@ llvm::CallBase *IRBuilder::CreateCallOrInvoke(
32653245
}
32663246
}
32673247
}
3268-
call->setAttributes(assertTypesInByValAndStructRetAttributes(fnTy, attrs));
3248+
call->setAttributes(attrs);
32693249
call->setCallingConv(fn.getCallingConv());
32703250
return call;
32713251
}
@@ -3462,10 +3442,6 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
34623442
resultTy = func->getParamStructRetType(0);
34633443
}
34643444
auto temp = IGF.createAlloca(resultTy, Alignment(), "indirect.result");
3465-
if (IGF.IGM.getLLVMContext().supportsTypedPointers()) {
3466-
temp = IGF.Builder.CreateElementBitCast(
3467-
temp, fnType->getParamType(0)->getNonOpaquePointerElementType());
3468-
}
34693445
emitToMemory(temp, substResultTI, isOutlined);
34703446
return;
34713447
}
@@ -3492,10 +3468,6 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
34923468
auto resultTy = func->getParamStructRetType(1);
34933469
auto temp = IGF.createAlloca(resultTy, Alignment(/*safe alignment*/ 16),
34943470
"indirect.result");
3495-
if (IGF.IGM.getLLVMContext().supportsTypedPointers()) {
3496-
temp = IGF.Builder.CreateElementBitCast(
3497-
temp, fnType->getParamType(1)->getNonOpaquePointerElementType());
3498-
}
34993471
emitToMemory(temp, substResultTI, isOutlined);
35003472
return;
35013473
}
@@ -5940,34 +5912,24 @@ llvm::FunctionType *FunctionPointer::getFunctionType() const {
59405912
}
59415913

59425914
if (awaitSignature) {
5943-
assert(llvm::cast<llvm::PointerType>(Value->getType())
5944-
->isOpaqueOrPointeeTypeMatches(awaitSignature));
59455915
return cast<llvm::FunctionType>(awaitSignature);
59465916
}
59475917

59485918
// Read the function type off the global or else from the Signature.
59495919
if (auto *constant = dyn_cast<llvm::Constant>(Value)) {
59505920
auto *gv = dyn_cast<llvm::GlobalValue>(Value);
59515921
if (!gv) {
5952-
assert(llvm::cast<llvm::PointerType>(Value->getType())
5953-
->isOpaqueOrPointeeTypeMatches(Sig.getType()));
59545922
return Sig.getType();
59555923
}
59565924

59575925
if (useSignature) { // Because of various casting (e.g thin_to_thick) the
59585926
// signature of the function Value might mismatch
59595927
// (e.g no context argument).
5960-
assert(llvm::cast<llvm::PointerType>(Value->getType())
5961-
->isOpaqueOrPointeeTypeMatches(Sig.getType()));
59625928
return Sig.getType();
59635929
}
59645930

5965-
assert(llvm::cast<llvm::PointerType>(Value->getType())
5966-
->isOpaqueOrPointeeTypeMatches(gv->getValueType()));
59675931
return cast<llvm::FunctionType>(gv->getValueType());
59685932
}
59695933

5970-
assert(llvm::cast<llvm::PointerType>(Value->getType())
5971-
->isOpaqueOrPointeeTypeMatches(Sig.getType()));
59725934
return Sig.getType();
59735935
}

lib/IRGen/GenDistributed.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,6 @@ void DistributedAccessor::emit() {
712712

713713
// Generic arguments associated with the distributed thunk directly
714714
// e.g. `distributed func echo<T, U>(...)`
715-
assert(
716-
!IGM.getLLVMContext().supportsTypedPointers() ||
717-
expandedSignature.numTypeMetadataPtrs ==
718-
llvm::count_if(targetGenericArguments, [&](const llvm::Type *type) {
719-
return type == IGM.TypeMetadataPtrTy;
720-
}));
721715

722716
for (unsigned index = 0; index < expandedSignature.numTypeMetadataPtrs; ++index) {
723717
auto offset =

lib/IRGen/GenFunc.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,6 @@ namespace {
225225
bool isOutlined) const override {
226226
auto *fn = src.claimNext();
227227

228-
// We might be presented with a value of the more precise pointer to
229-
// function type "void(*)*" rather than the generic "i8*". Downcast to the
230-
// more general expected type.
231-
if (fn->getContext().supportsTypedPointers() &&
232-
fn->getType()->getNonOpaquePointerElementType()->isFunctionTy())
233-
fn = IGF.Builder.CreateBitCast(fn, getStorageType());
234-
235228
Explosion tmp;
236229
tmp.add(fn);
237230
PODSingleScalarTypeInfo<ThinFuncTypeInfo,LoadableTypeInfo>::initialize(IGF, tmp, addr, isOutlined);

lib/IRGen/GenObjC.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,7 @@ getProtocolRefsList(llvm::Constant *protocol) {
459459
return std::make_pair(0, nullptr);
460460
}
461461

462-
if (!protocol->getContext().supportsTypedPointers()) {
463-
auto protocolRefsVar = cast<llvm::GlobalVariable>(objCProtocolList);
464-
auto sizeListPair =
465-
cast<llvm::ConstantStruct>(protocolRefsVar->getInitializer());
466-
auto size =
467-
cast<llvm::ConstantInt>(sizeListPair->getOperand(0))->getZExtValue();
468-
auto protocolRefsList =
469-
cast<llvm::ConstantArray>(sizeListPair->getOperand(1));
470-
return std::make_pair(size, protocolRefsList);
471-
}
472-
473-
auto bitcast = cast<llvm::ConstantExpr>(objCProtocolList);
474-
assert(bitcast->getOpcode() == llvm::Instruction::BitCast);
475-
auto protocolRefsVar = cast<llvm::GlobalVariable>(bitcast->getOperand(0));
462+
auto protocolRefsVar = cast<llvm::GlobalVariable>(objCProtocolList);
476463
auto sizeListPair =
477464
cast<llvm::ConstantStruct>(protocolRefsVar->getInitializer());
478465
auto size =

lib/IRGen/GenStruct.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,6 @@ namespace {
463463
clang::QualType(clangDecl->getTypeForDecl(), 0));
464464
auto *dstValue = dst.getAddress();
465465
auto *srcValue = src.getAddress();
466-
if (IGF.IGM.getLLVMContext().supportsTypedPointers()) {
467-
dstValue = IGF.coerceValue(
468-
dst.getAddress(), copyFunction->getFunctionType()->getParamType(0),
469-
IGF.IGM.DataLayout);
470-
srcValue = IGF.coerceValue(
471-
src.getAddress(), copyFunction->getFunctionType()->getParamType(1),
472-
IGF.IGM.DataLayout);
473-
}
474466
IGF.Builder.CreateCall(copyFunction->getFunctionType(), copyFunction,
475467
{dstValue, srcValue});
476468
}
@@ -634,12 +626,6 @@ namespace {
634626
clangFnAddr = emitCXXConstructorThunkIfNeeded(
635627
IGF.IGM, signature, copyConstructor, name, clangFnAddr);
636628
callee = cast<llvm::Function>(clangFnAddr);
637-
if (IGF.IGM.getLLVMContext().supportsTypedPointers()) {
638-
dest = IGF.coerceValue(dest, callee->getFunctionType()->getParamType(0),
639-
IGF.IGM.DataLayout);
640-
src = IGF.coerceValue(src, callee->getFunctionType()->getParamType(1),
641-
IGF.IGM.DataLayout);
642-
}
643629
llvm::Value *args[] = {dest, src};
644630
if (clangFnAddr == origClangFnAddr) {
645631
// Ensure we can use 'invoke' to trap on uncaught exceptions when
@@ -705,10 +691,6 @@ namespace {
705691

706692
SmallVector<llvm::Value *, 2> args;
707693
auto *thisArg = address.getAddress();
708-
if (IGF.IGM.getLLVMContext().supportsTypedPointers())
709-
thisArg = IGF.coerceValue(address.getAddress(),
710-
destructorFnAddr->getArg(0)->getType(),
711-
IGF.IGM.DataLayout);
712694
args.push_back(thisArg);
713695
llvm::Value *implicitParam =
714696
clang::CodeGen::getCXXDestructorImplicitParam(

lib/IRGen/GenType.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ TypeInfo::~TypeInfo() {
115115
}
116116

117117
Address TypeInfo::getAddressForPointer(llvm::Value *ptr) const {
118-
assert(cast<llvm::PointerType>(ptr->getType())
119-
->isOpaqueOrPointeeTypeMatches(getStorageType()));
120118
return Address(ptr, getStorageType(), getBestKnownAlignment());
121119
}
122120

lib/LLVMPasses/LLVMMergeFunctions.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,29 +1261,6 @@ void SwiftMergeFunctions::writeThunk(Function *ToFunc, Function *Thunk,
12611261
++NumSwiftThunksWritten;
12621262
}
12631263

1264-
static llvm::AttributeList
1265-
fixUpTypesInByValAndStructRetAttributes(llvm::FunctionType *fnType,
1266-
llvm::AttributeList attrList) {
1267-
auto &context = fnType->getContext();
1268-
if (!context.supportsTypedPointers())
1269-
return attrList;
1270-
1271-
for (unsigned i = 0; i < fnType->getNumParams(); ++i) {
1272-
auto paramTy = fnType->getParamType(i);
1273-
auto attrListIndex = llvm::AttributeList::FirstArgIndex + i;
1274-
if (attrList.hasParamAttr(i, llvm::Attribute::StructRet) &&
1275-
paramTy->getNonOpaquePointerElementType() != attrList.getParamStructRetType(i))
1276-
attrList = attrList.replaceAttributeTypeAtIndex(
1277-
context, attrListIndex, llvm::Attribute::StructRet,
1278-
paramTy->getNonOpaquePointerElementType());
1279-
if (attrList.hasParamAttr(i, llvm::Attribute::ByVal) &&
1280-
paramTy->getNonOpaquePointerElementType() != attrList.getParamByValType(i))
1281-
attrList = attrList.replaceAttributeTypeAtIndex(
1282-
context, attrListIndex, llvm::Attribute::ByVal,
1283-
paramTy->getNonOpaquePointerElementType());
1284-
}
1285-
return attrList;
1286-
}
12871264
/// Replace direct callers of Old with New. Also add parameters to the call to
12881265
/// \p New, which are defined by the FuncIdx's value in \p Params.
12891266
bool SwiftMergeFunctions::replaceDirectCallers(Function *Old, Function *New,
@@ -1356,7 +1333,6 @@ bool SwiftMergeFunctions::replaceDirectCallers(Function *Old, Function *New,
13561333
auto newAttrList = AttributeList::get(Context, /*FnAttrs=*/AttributeSet(),
13571334
NewPAL.getRetAttrs(),
13581335
NewArgAttrs);
1359-
newAttrList = fixUpTypesInByValAndStructRetAttributes(FType, newAttrList);
13601336
NewCI->setAttributes(newAttrList);
13611337
Value *retVal = createCast(Builder, NewCI, CI->getType());
13621338
CI->replaceAllUsesWith(retVal);

0 commit comments

Comments
 (0)