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
40 changes: 1 addition & 39 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3204,26 +3204,6 @@ llvm::CallBase *CallEmission::emitCallSite() {
return call;
}

static llvm::AttributeList
assertTypesInByValAndStructRetAttributes(llvm::FunctionType *fnType,
llvm::AttributeList attrList) {
auto &context = fnType->getContext();
if (context.supportsTypedPointers()) {
for (unsigned i = 0; i < fnType->getNumParams(); ++i) {
auto paramTy = fnType->getParamType(i);
assert(
!attrList.hasParamAttr(i, llvm::Attribute::StructRet) ||
llvm::cast<llvm::PointerType>(paramTy)->isOpaqueOrPointeeTypeMatches(
attrList.getParamStructRetType(i)));
assert(
!attrList.hasParamAttr(i, llvm::Attribute::ByVal) ||
llvm::cast<llvm::PointerType>(paramTy)->isOpaqueOrPointeeTypeMatches(
attrList.getParamByValType(i)));
}
}
return attrList;
}

llvm::CallBase *IRBuilder::CreateCallOrInvoke(
const FunctionPointer &fn, ArrayRef<llvm::Value *> args,
llvm::BasicBlock *invokeNormalDest, llvm::BasicBlock *invokeUnwindDest) {
Expand Down Expand Up @@ -3265,7 +3245,7 @@ llvm::CallBase *IRBuilder::CreateCallOrInvoke(
}
}
}
call->setAttributes(assertTypesInByValAndStructRetAttributes(fnTy, attrs));
call->setAttributes(attrs);
call->setCallingConv(fn.getCallingConv());
return call;
}
Expand Down Expand Up @@ -3462,10 +3442,6 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
resultTy = func->getParamStructRetType(0);
}
auto temp = IGF.createAlloca(resultTy, Alignment(), "indirect.result");
if (IGF.IGM.getLLVMContext().supportsTypedPointers()) {
temp = IGF.Builder.CreateElementBitCast(
temp, fnType->getParamType(0)->getNonOpaquePointerElementType());
}
emitToMemory(temp, substResultTI, isOutlined);
return;
}
Expand All @@ -3492,10 +3468,6 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
auto resultTy = func->getParamStructRetType(1);
auto temp = IGF.createAlloca(resultTy, Alignment(/*safe alignment*/ 16),
"indirect.result");
if (IGF.IGM.getLLVMContext().supportsTypedPointers()) {
temp = IGF.Builder.CreateElementBitCast(
temp, fnType->getParamType(1)->getNonOpaquePointerElementType());
}
emitToMemory(temp, substResultTI, isOutlined);
return;
}
Expand Down Expand Up @@ -5940,34 +5912,24 @@ llvm::FunctionType *FunctionPointer::getFunctionType() const {
}

if (awaitSignature) {
assert(llvm::cast<llvm::PointerType>(Value->getType())
->isOpaqueOrPointeeTypeMatches(awaitSignature));
return cast<llvm::FunctionType>(awaitSignature);
}

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

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

assert(llvm::cast<llvm::PointerType>(Value->getType())
->isOpaqueOrPointeeTypeMatches(gv->getValueType()));
return cast<llvm::FunctionType>(gv->getValueType());
}

assert(llvm::cast<llvm::PointerType>(Value->getType())
->isOpaqueOrPointeeTypeMatches(Sig.getType()));
return Sig.getType();
}
6 changes: 0 additions & 6 deletions lib/IRGen/GenDistributed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,12 +712,6 @@ void DistributedAccessor::emit() {

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

for (unsigned index = 0; index < expandedSignature.numTypeMetadataPtrs; ++index) {
auto offset =
Expand Down
7 changes: 0 additions & 7 deletions lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,6 @@ namespace {
bool isOutlined) const override {
auto *fn = src.claimNext();

// We might be presented with a value of the more precise pointer to
// function type "void(*)*" rather than the generic "i8*". Downcast to the
// more general expected type.
if (fn->getContext().supportsTypedPointers() &&
fn->getType()->getNonOpaquePointerElementType()->isFunctionTy())
fn = IGF.Builder.CreateBitCast(fn, getStorageType());

Explosion tmp;
tmp.add(fn);
PODSingleScalarTypeInfo<ThinFuncTypeInfo,LoadableTypeInfo>::initialize(IGF, tmp, addr, isOutlined);
Expand Down
15 changes: 1 addition & 14 deletions lib/IRGen/GenObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,7 @@ getProtocolRefsList(llvm::Constant *protocol) {
return std::make_pair(0, nullptr);
}

if (!protocol->getContext().supportsTypedPointers()) {
auto protocolRefsVar = cast<llvm::GlobalVariable>(objCProtocolList);
auto sizeListPair =
cast<llvm::ConstantStruct>(protocolRefsVar->getInitializer());
auto size =
cast<llvm::ConstantInt>(sizeListPair->getOperand(0))->getZExtValue();
auto protocolRefsList =
cast<llvm::ConstantArray>(sizeListPair->getOperand(1));
return std::make_pair(size, protocolRefsList);
}

auto bitcast = cast<llvm::ConstantExpr>(objCProtocolList);
assert(bitcast->getOpcode() == llvm::Instruction::BitCast);
auto protocolRefsVar = cast<llvm::GlobalVariable>(bitcast->getOperand(0));
auto protocolRefsVar = cast<llvm::GlobalVariable>(objCProtocolList);
auto sizeListPair =
cast<llvm::ConstantStruct>(protocolRefsVar->getInitializer());
auto size =
Expand Down
18 changes: 0 additions & 18 deletions lib/IRGen/GenStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,6 @@ namespace {
clang::QualType(clangDecl->getTypeForDecl(), 0));
auto *dstValue = dst.getAddress();
auto *srcValue = src.getAddress();
if (IGF.IGM.getLLVMContext().supportsTypedPointers()) {
dstValue = IGF.coerceValue(
dst.getAddress(), copyFunction->getFunctionType()->getParamType(0),
IGF.IGM.DataLayout);
srcValue = IGF.coerceValue(
src.getAddress(), copyFunction->getFunctionType()->getParamType(1),
IGF.IGM.DataLayout);
}
IGF.Builder.CreateCall(copyFunction->getFunctionType(), copyFunction,
{dstValue, srcValue});
}
Expand Down Expand Up @@ -634,12 +626,6 @@ namespace {
clangFnAddr = emitCXXConstructorThunkIfNeeded(
IGF.IGM, signature, copyConstructor, name, clangFnAddr);
callee = cast<llvm::Function>(clangFnAddr);
if (IGF.IGM.getLLVMContext().supportsTypedPointers()) {
dest = IGF.coerceValue(dest, callee->getFunctionType()->getParamType(0),
IGF.IGM.DataLayout);
src = IGF.coerceValue(src, callee->getFunctionType()->getParamType(1),
IGF.IGM.DataLayout);
}
llvm::Value *args[] = {dest, src};
if (clangFnAddr == origClangFnAddr) {
// Ensure we can use 'invoke' to trap on uncaught exceptions when
Expand Down Expand Up @@ -705,10 +691,6 @@ namespace {

SmallVector<llvm::Value *, 2> args;
auto *thisArg = address.getAddress();
if (IGF.IGM.getLLVMContext().supportsTypedPointers())
thisArg = IGF.coerceValue(address.getAddress(),
destructorFnAddr->getArg(0)->getType(),
IGF.IGM.DataLayout);
args.push_back(thisArg);
llvm::Value *implicitParam =
clang::CodeGen::getCXXDestructorImplicitParam(
Expand Down
2 changes: 0 additions & 2 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ TypeInfo::~TypeInfo() {
}

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

Expand Down
24 changes: 0 additions & 24 deletions lib/LLVMPasses/LLVMMergeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,29 +1261,6 @@ void SwiftMergeFunctions::writeThunk(Function *ToFunc, Function *Thunk,
++NumSwiftThunksWritten;
}

static llvm::AttributeList
fixUpTypesInByValAndStructRetAttributes(llvm::FunctionType *fnType,
llvm::AttributeList attrList) {
auto &context = fnType->getContext();
if (!context.supportsTypedPointers())
return attrList;

for (unsigned i = 0; i < fnType->getNumParams(); ++i) {
auto paramTy = fnType->getParamType(i);
auto attrListIndex = llvm::AttributeList::FirstArgIndex + i;
if (attrList.hasParamAttr(i, llvm::Attribute::StructRet) &&
paramTy->getNonOpaquePointerElementType() != attrList.getParamStructRetType(i))
attrList = attrList.replaceAttributeTypeAtIndex(
context, attrListIndex, llvm::Attribute::StructRet,
paramTy->getNonOpaquePointerElementType());
if (attrList.hasParamAttr(i, llvm::Attribute::ByVal) &&
paramTy->getNonOpaquePointerElementType() != attrList.getParamByValType(i))
attrList = attrList.replaceAttributeTypeAtIndex(
context, attrListIndex, llvm::Attribute::ByVal,
paramTy->getNonOpaquePointerElementType());
}
return attrList;
}
/// Replace direct callers of Old with New. Also add parameters to the call to
/// \p New, which are defined by the FuncIdx's value in \p Params.
bool SwiftMergeFunctions::replaceDirectCallers(Function *Old, Function *New,
Expand Down Expand Up @@ -1356,7 +1333,6 @@ bool SwiftMergeFunctions::replaceDirectCallers(Function *Old, Function *New,
auto newAttrList = AttributeList::get(Context, /*FnAttrs=*/AttributeSet(),
NewPAL.getRetAttrs(),
NewArgAttrs);
newAttrList = fixUpTypesInByValAndStructRetAttributes(FType, newAttrList);
NewCI->setAttributes(newAttrList);
Value *retVal = createCast(Builder, NewCI, CI->getType());
CI->replaceAllUsesWith(retVal);
Expand Down