diff --git a/include/swift/Demangling/DemangleNodes.def b/include/swift/Demangling/DemangleNodes.def index b18ac0b64de28..da4d56ce7fad5 100644 --- a/include/swift/Demangling/DemangleNodes.def +++ b/include/swift/Demangling/DemangleNodes.def @@ -211,6 +211,7 @@ NODE(TypeMetadataCompletionFunction) NODE(TypeMetadataInstantiationCache) NODE(TypeMetadataInstantiationFunction) NODE(TypeMetadataSingletonInitializationCache) +NODE(TypeMetadataDemanglingCache) NODE(TypeMetadataLazyCache) NODE(UncurriedFunctionType) NODE(UnknownIndex) diff --git a/include/swift/IRGen/Linking.h b/include/swift/IRGen/Linking.h index f233a33f1aacb..997efb0edb332 100644 --- a/include/swift/IRGen/Linking.h +++ b/include/swift/IRGen/Linking.h @@ -368,6 +368,10 @@ class LinkEntity { /// The pointer is a canonical TypeBase*. TypeMetadataLazyCacheVariable, + /// A lazy cache variable for fetching type metadata from a mangled name. + /// The pointer is a canonical TypeBase*. + TypeMetadataDemanglingCacheVariable, + /// A reflection metadata descriptor for a builtin or imported type. ReflectionBuiltinDescriptor, @@ -705,6 +709,12 @@ class LinkEntity { return entity; } + static LinkEntity forTypeMetadataDemanglingCacheVariable(CanType type) { + LinkEntity entity; + entity.setForType(Kind::TypeMetadataDemanglingCacheVariable, type); + return entity; + } + static LinkEntity forClassMetadataBaseOffset(ClassDecl *decl) { LinkEntity entity; entity.setForDecl(Kind::ClassMetadataBaseOffset, decl); diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def index c978715fef38a..279046f593950 100644 --- a/include/swift/Runtime/RuntimeFunctions.def +++ b/include/swift/Runtime/RuntimeFunctions.def @@ -1190,7 +1190,7 @@ FUNCTION(IsOptionalType, FUNCTION(Once, swift_once, C_CC, AlwaysAvailable, RETURNS(VoidTy), ARGS(OnceTy->getPointerTo(), Int8PtrTy, Int8PtrTy), - ATTRS()) + ATTRS(NoUnwind)) // void swift_registerProtocols(const ProtocolRecord *begin, // const ProtocolRecord *end) @@ -1398,6 +1398,17 @@ FUNCTION(IntToFloat64, swift_intToFloat64, SwiftCC, AlwaysAvailable, ARGS(SizeTy->getPointerTo(), SizeTy), ATTRS(NoUnwind, ReadOnly)) +// const Metadata *swift_getTypeByMangledNameInContext( +// const char *typeNameStart, +// size_t typeNameLength, +// const TargetContextDescriptor *context, +// const void * const *genericArgs) +FUNCTION(GetTypeByMangledNameInContext, swift_getTypeByMangledNameInContext, + SwiftCC, AlwaysAvailable, + RETURNS(TypeMetadataPtrTy), + ARGS(Int8PtrTy, SizeTy, TypeContextDescriptorPtrTy, Int8PtrPtrTy), + ATTRS(NoUnwind, ArgMemOnly)) + #undef RETURNS #undef ARGS #undef ATTRS diff --git a/lib/Demangling/Demangler.cpp b/lib/Demangling/Demangler.cpp index cebc10b874d30..6b2067f457115 100644 --- a/lib/Demangling/Demangler.cpp +++ b/lib/Demangling/Demangler.cpp @@ -1788,36 +1788,50 @@ NodePointer Demangler::demangleImplFunctionType() { NodePointer Demangler::demangleMetatype() { switch (nextChar()) { + case 'a': + return createWithPoppedType(Node::Kind::TypeMetadataAccessFunction); + case 'A': + return createWithChild(Node::Kind::ReflectionMetadataAssocTypeDescriptor, + popProtocolConformance()); + case 'B': + return createWithChild(Node::Kind::ReflectionMetadataBuiltinDescriptor, + popNode(Node::Kind::Type)); case 'c': return createWithChild(Node::Kind::ProtocolConformanceDescriptor, popProtocolConformance()); + case 'C': { + NodePointer Ty = popNode(Node::Kind::Type); + if (!Ty || !isAnyGeneric(Ty->getChild(0)->getKind())) + return nullptr; + return createWithChild(Node::Kind::ReflectionMetadataSuperclassDescriptor, + Ty->getChild(0)); + } + case 'D': + return createWithPoppedType(Node::Kind::TypeMetadataDemanglingCache); case 'f': return createWithPoppedType(Node::Kind::FullTypeMetadata); - case 'P': - return createWithPoppedType(Node::Kind::GenericTypeMetadataPattern); - case 'a': - return createWithPoppedType(Node::Kind::TypeMetadataAccessFunction); + case 'F': + return createWithChild(Node::Kind::ReflectionMetadataFieldDescriptor, + popNode(Node::Kind::Type)); case 'g': return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessor, popNode()); case 'h': return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorImpl, popNode()); + case 'i': + return createWithPoppedType(Node::Kind::TypeMetadataInstantiationFunction); + case 'I': + return createWithPoppedType(Node::Kind::TypeMetadataInstantiationCache); case 'j': return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorKey, popNode()); case 'k': return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorVar, popNode()); - case 'I': - return createWithPoppedType(Node::Kind::TypeMetadataInstantiationCache); - case 'i': - return createWithPoppedType(Node::Kind::TypeMetadataInstantiationFunction); - case 'r': - return createWithPoppedType(Node::Kind::TypeMetadataCompletionFunction); case 'l': return createWithPoppedType( - Node::Kind::TypeMetadataSingletonInitializationCache); + Node::Kind::TypeMetadataSingletonInitializationCache); case 'L': return createWithPoppedType(Node::Kind::TypeMetadataLazyCache); case 'm': @@ -1828,35 +1842,23 @@ NodePointer Demangler::demangleMetatype() { return createWithPoppedType(Node::Kind::ClassMetadataBaseOffset); case 'p': return createWithChild(Node::Kind::ProtocolDescriptor, popProtocol()); + case 'P': + return createWithPoppedType(Node::Kind::GenericTypeMetadataPattern); case 'Q': return createWithChild(Node::Kind::OpaqueTypeDescriptor, popNode()); + case 'r': + return createWithPoppedType(Node::Kind::TypeMetadataCompletionFunction); + case 's': + return createWithPoppedType(Node::Kind::ObjCResilientClassStub); case 'S': return createWithChild(Node::Kind::ProtocolSelfConformanceDescriptor, popProtocol()); + case 't': + return createWithPoppedType(Node::Kind::FullObjCResilientClassStub); case 'u': return createWithPoppedType(Node::Kind::MethodLookupFunction); case 'U': return createWithPoppedType(Node::Kind::ObjCMetadataUpdateFunction); - case 's': - return createWithPoppedType(Node::Kind::ObjCResilientClassStub); - case 't': - return createWithPoppedType(Node::Kind::FullObjCResilientClassStub); - case 'B': - return createWithChild(Node::Kind::ReflectionMetadataBuiltinDescriptor, - popNode(Node::Kind::Type)); - case 'F': - return createWithChild(Node::Kind::ReflectionMetadataFieldDescriptor, - popNode(Node::Kind::Type)); - case 'A': - return createWithChild(Node::Kind::ReflectionMetadataAssocTypeDescriptor, - popProtocolConformance()); - case 'C': { - NodePointer Ty = popNode(Node::Kind::Type); - if (!Ty || !isAnyGeneric(Ty->getChild(0)->getKind())) - return nullptr; - return createWithChild(Node::Kind::ReflectionMetadataSuperclassDescriptor, - Ty->getChild(0)); - } case 'V': return createWithChild(Node::Kind::PropertyDescriptor, popNode(isEntity)); diff --git a/lib/Demangling/NodePrinter.cpp b/lib/Demangling/NodePrinter.cpp index e85a4eb9c8572..190dfe7924042 100644 --- a/lib/Demangling/NodePrinter.cpp +++ b/lib/Demangling/NodePrinter.cpp @@ -472,6 +472,7 @@ class NodePrinter { case Node::Kind::TypeMetadataInstantiationCache: case Node::Kind::TypeMetadataInstantiationFunction: case Node::Kind::TypeMetadataSingletonInitializationCache: + case Node::Kind::TypeMetadataDemanglingCache: case Node::Kind::TypeMetadataLazyCache: case Node::Kind::UncurriedFunctionType: #define REF_STORAGE(Name, ...) \ @@ -1679,6 +1680,10 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) { Printer << "type metadata completion function for "; print(Node->getChild(0)); return nullptr; + case Node::Kind::TypeMetadataDemanglingCache: + Printer << "demangling cache variable for type metadata for "; + print(Node->getChild(0)); + return nullptr; case Node::Kind::TypeMetadataLazyCache: Printer << "lazy cache variable for type metadata for "; print(Node->getChild(0)); diff --git a/lib/Demangling/OldRemangler.cpp b/lib/Demangling/OldRemangler.cpp index cf08aca4a7f90..ceb13bb0199fb 100644 --- a/lib/Demangling/OldRemangler.cpp +++ b/lib/Demangling/OldRemangler.cpp @@ -513,6 +513,10 @@ void Remangler::mangleTypeMetadataCompletionFunction(Node *node) { mangleSingleChildNode(node); // type } +void Remangler::mangleTypeMetadataDemanglingCache(Node *node) { + unreachable("not supported"); +} + void Remangler::mangleTypeMetadataLazyCache(Node *node) { Buffer << "ML"; mangleSingleChildNode(node); // type diff --git a/lib/Demangling/Remangler.cpp b/lib/Demangling/Remangler.cpp index 32923acb9bf7f..049bc188798d8 100644 --- a/lib/Demangling/Remangler.cpp +++ b/lib/Demangling/Remangler.cpp @@ -2065,6 +2065,11 @@ void Remangler::mangleTypeMetadataCompletionFunction(Node *node) { Buffer << "Mr"; } +void Remangler::mangleTypeMetadataDemanglingCache(Node *node) { + mangleChildNodes(node); + Buffer << "MD"; +} + void Remangler::mangleTypeMetadataLazyCache(Node *node) { mangleChildNodes(node); Buffer << "ML"; diff --git a/lib/IRGen/GenBuiltin.cpp b/lib/IRGen/GenBuiltin.cpp index 40537f6e79181..86c3f99bed213 100644 --- a/lib/IRGen/GenBuiltin.cpp +++ b/lib/IRGen/GenBuiltin.cpp @@ -799,6 +799,8 @@ if (Builtin.ID == BuiltinValueKind::id) { \ // If we know the platform runtime's "done" value, emit the check inline. llvm::BasicBlock *doneBB = nullptr; + + llvm::BasicBlock *beforeBB = IGF.Builder.GetInsertBlock(); if (auto ExpectedPred = IGF.IGM.TargetInfo.OnceDonePredicateValue) { auto PredValue = IGF.Builder.CreateLoad(PredPtr, @@ -806,11 +808,15 @@ if (Builtin.ID == BuiltinValueKind::id) { \ auto ExpectedPredValue = llvm::ConstantInt::getSigned(IGF.IGM.OnceTy, *ExpectedPred); auto PredIsDone = IGF.Builder.CreateICmpEQ(PredValue, ExpectedPredValue); + PredIsDone = IGF.Builder.CreateExpect(PredIsDone, + llvm::ConstantInt::get(IGF.IGM.Int1Ty, 1)); auto notDoneBB = IGF.createBasicBlock("once_not_done"); doneBB = IGF.createBasicBlock("once_done"); IGF.Builder.CreateCondBr(PredIsDone, doneBB, notDoneBB); + + IGF.Builder.SetInsertPoint(&IGF.CurFn->back()); IGF.Builder.emitBlock(notDoneBB); } @@ -822,6 +828,7 @@ if (Builtin.ID == BuiltinValueKind::id) { \ // If we emitted the "done" check inline, join the branches. if (auto ExpectedPred = IGF.IGM.TargetInfo.OnceDonePredicateValue) { IGF.Builder.CreateBr(doneBB); + IGF.Builder.SetInsertPoint(beforeBB); IGF.Builder.emitBlock(doneBB); // We can assume the once predicate is in the "done" state now. auto PredValue = IGF.Builder.CreateLoad(PredPtr, diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 5575ff7a748a8..c996d87679e4f 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -1538,8 +1538,6 @@ void CallEmission::emitToUnmappedExplosion(Explosion &out) { // for methods that have covariant ABI-compatible overrides. auto expectedNativeResultType = nativeSchema.getExpandedType(IGF.IGM); if (result->getType() != expectedNativeResultType) { - assert(origFnType->getLanguage() == SILFunctionLanguage::C || - origFnType->getRepresentation() == SILFunctionTypeRepresentation::Method); result = IGF.coerceValue(result, expectedNativeResultType, IGF.IGM.DataLayout); } diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 41df42e7e7099..ebd1df23a5e0c 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -47,6 +47,7 @@ #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/Path.h" #include "llvm/Support/SaveAndRestore.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/Utils/ModuleUtils.h" #include "Callee.h" @@ -1248,6 +1249,14 @@ void IRGenerator::noteUseOfTypeGlobals(NominalTypeDecl *type, RequireMetadata_t requireMetadata) { if (!type) return; + + // Force emission of ObjC protocol descriptors used by type refs. + if (auto proto = dyn_cast(type)) { + if (proto->isObjC()) { + PrimaryIGM->getAddrOfObjCProtocolRecord(proto, NotForDefinition); + return; + } + } if (!hasLazyMetadata(type)) return; @@ -2562,7 +2571,11 @@ static llvm::GlobalVariable *createGOTEquivalent(IRGenModule &IGM, // rdar://problem/50968433: Unnamed_addr constants appear to get emitted // with incorrect alignment by the LLVM JIT in some cases. Don't use // unnamed_addr as a workaround. - if (!IGM.getOptions().UseJIT) { + // rdar://problem/53836960: i386 ld64 also mis-links relative references + // to GOT entries. + if (!IGM.getOptions().UseJIT + && (!IGM.Triple.isOSDarwin() + || IGM.Triple.getArch() != llvm::Triple::x86)) { gotEquivalent->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); } else { ApplyIRLinkage(IRLinkage::InternalLinkOnceODR) @@ -3411,22 +3424,29 @@ IRGenModule::getAddrOfGenericTypeMetadataAccessFunction( /// Get or create a type metadata cache variable. These are an /// implementation detail of type metadata access functions. llvm::Constant * -IRGenModule::getAddrOfTypeMetadataLazyCacheVariable(CanType type, - ForDefinition_t forDefinition) { +IRGenModule::getAddrOfTypeMetadataLazyCacheVariable(CanType type) { assert(!type->hasArchetype() && !type->hasTypeParameter()); LinkEntity entity = LinkEntity::forTypeMetadataLazyCacheVariable(type); auto variable = - getAddrOfLLVMVariable(entity, forDefinition, DebugTypeInfo()); + getAddrOfLLVMVariable(entity, ForDefinition, DebugTypeInfo()); // Zero-initialize if we're asking for a definition. - if (forDefinition) { - cast(variable)->setInitializer( - llvm::ConstantPointerNull::get(TypeMetadataPtrTy)); - } + cast(variable)->setInitializer( + llvm::ConstantPointerNull::get(TypeMetadataPtrTy)); return variable; } +/// Get or create a type metadata cache variable. These are an +/// implementation detail of type metadata access functions. +llvm::Constant * +IRGenModule::getAddrOfTypeMetadataDemanglingCacheVariable(CanType type, + ConstantInit definition) { + assert(!type->hasArchetype() && !type->hasTypeParameter()); + LinkEntity entity = LinkEntity::forTypeMetadataDemanglingCacheVariable(type); + return getAddrOfLLVMVariable(entity, definition, DebugTypeInfo()); +} + llvm::Constant * IRGenModule::getAddrOfTypeMetadataSingletonInitializationCache( NominalTypeDecl *D, diff --git a/lib/IRGen/GenKeyPath.cpp b/lib/IRGen/GenKeyPath.cpp index 555ce43d44a9a..6c8d9c4502c77 100644 --- a/lib/IRGen/GenKeyPath.cpp +++ b/lib/IRGen/GenKeyPath.cpp @@ -651,7 +651,7 @@ getInitializerForComputedComponent(IRGenModule &IGM, static llvm::Constant * emitMetadataTypeRefForKeyPath(IRGenModule &IGM, CanType type) { // Produce a mangled name for the type. - auto constant = IGM.getTypeRef(type, MangledTypeRefRole::Metadata); + auto constant = IGM.getTypeRef(type, MangledTypeRefRole::Metadata).first; // Mask the bottom bit to tell the key path runtime this is a mangled name // rather than a direct reference. diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp index d946c484a34c8..259e10dd13d7e 100644 --- a/lib/IRGen/GenMeta.cpp +++ b/lib/IRGen/GenMeta.cpp @@ -470,7 +470,7 @@ namespace { void addExtendedContext() { auto string = IGM.getTypeRef(E->getSelfInterfaceType(), E->getGenericSignature(), - MangledTypeRefRole::Metadata); + MangledTypeRefRole::Metadata).first; B.addRelativeAddress(string); } @@ -1594,7 +1594,8 @@ namespace { GenericSignature *genericSig = getType()->getGenericSignature(); B.addRelativeAddress(IGM.getTypeRef(superclassType->getCanonicalType(), genericSig, - MangledTypeRefRole::Metadata)); + MangledTypeRefRole::Metadata) + .first); } else { B.addInt32(0); } @@ -1685,7 +1686,7 @@ namespace { ->getCanonicalType(O->getOpaqueInterfaceGenericSignature()); B.addRelativeAddress(IGM.getTypeRef(underlyingType, - MangledTypeRefRole::Metadata)); + MangledTypeRefRole::Metadata).first); auto opaqueType = O->getDeclaredInterfaceType() ->castTo(); @@ -4266,7 +4267,7 @@ static void addGenericRequirement(IRGenModule &IGM, ConstantStructBuilder &B, B.addInt(IGM.Int32Ty, flags.getIntValue()); auto typeName = - IGM.getTypeRef(paramType, nullptr, MangledTypeRefRole::Metadata); + IGM.getTypeRef(paramType, nullptr, MangledTypeRefRole::Metadata).first; B.addRelativeAddress(typeName); addReference(); } @@ -4334,7 +4335,7 @@ GenericRequirementsMetadata irgen::addGenericRequirements( auto flags = GenericRequirementFlags(abiKind, false, false); auto typeName = IGM.getTypeRef(requirement.getSecondType(), nullptr, - MangledTypeRefRole::Metadata); + MangledTypeRefRole::Metadata).first; addGenericRequirement(IGM, B, metadata, sig, flags, requirement.getFirstType(), diff --git a/lib/IRGen/GenProto.cpp b/lib/IRGen/GenProto.cpp index ec586b5729ca7..9f29e8ba0c2cc 100644 --- a/lib/IRGen/GenProto.cpp +++ b/lib/IRGen/GenProto.cpp @@ -1432,7 +1432,7 @@ llvm::Constant *IRGenModule::getAssociatedTypeWitness(Type type, auto role = inProtocolContext ? MangledTypeRefRole::DefaultAssociatedTypeWitness : MangledTypeRefRole::Metadata; - auto typeRef = getTypeRef(type, /*generic signature*/nullptr, role); + auto typeRef = getTypeRef(type, /*generic signature*/nullptr, role).first; // Set the low bit to indicate that this is a mangled name. auto witness = llvm::ConstantExpr::getPtrToInt(typeRef, IntPtrTy); diff --git a/lib/IRGen/GenReflection.cpp b/lib/IRGen/GenReflection.cpp index e332d26a95ecd..06a00780ca8c2 100644 --- a/lib/IRGen/GenReflection.cpp +++ b/lib/IRGen/GenReflection.cpp @@ -168,15 +168,14 @@ class PrintMetadataSource } }; -llvm::Constant *IRGenModule::getTypeRef(Type type, - GenericSignature *genericSig, - MangledTypeRefRole role) { +std::pair +IRGenModule::getTypeRef(Type type, GenericSignature *genericSig, + MangledTypeRefRole role) { return getTypeRef(type->getCanonicalType(genericSig), role); } -llvm::Constant *IRGenModule::getTypeRef(CanType type, - MangledTypeRefRole role) { - +std::pair +IRGenModule::getTypeRef(CanType type, MangledTypeRefRole role) { switch (role) { case MangledTypeRefRole::DefaultAssociatedTypeWitness: case MangledTypeRefRole::Metadata: @@ -195,7 +194,8 @@ llvm::Constant *IRGenModule::getTypeRef(CanType type, IRGenMangler Mangler; auto SymbolicName = Mangler.mangleTypeForReflection(*this, type); - return getAddrOfStringForTypeRef(SymbolicName, role); + return {getAddrOfStringForTypeRef(SymbolicName, role), + SymbolicName.runtimeSizeInBytes()}; } /// Emit a mangled string referencing a specific protocol conformance, so that @@ -390,7 +390,7 @@ class ReflectionMetadataBuilder { void addTypeRef(CanType type, MangledTypeRefRole role = MangledTypeRefRole::Reflection) { - B.addRelativeAddress(IGM.getTypeRef(type, role)); + B.addRelativeAddress(IGM.getTypeRef(type, role).first); addBuiltinTypeRefs(type); } diff --git a/lib/IRGen/IRBuilder.h b/lib/IRGen/IRBuilder.h index 4c558d32c8652..e53534579890c 100644 --- a/lib/IRGen/IRBuilder.h +++ b/lib/IRGen/IRBuilder.h @@ -303,6 +303,16 @@ class IRBuilder : public IRBuilderBase { llvm::Intrinsic::getDeclaration(getModule(), intrinsicID, typeArgs); return CreateCall(intrinsicFn, args, name); } + + /// Create an expect intrinsic call. + llvm::CallInst *CreateExpect(llvm::Value *value, + llvm::Value *expected, + const Twine &name = "") { + return CreateIntrinsicCall(llvm::Intrinsic::expect, + {value->getType()}, + {value, expected}, + name); + } /// Call the trap intrinsic. If optimizations are enabled, an inline asm /// gadget is emitted before the trap. The gadget inhibits transforms which diff --git a/lib/IRGen/IRGenMangler.h b/lib/IRGen/IRGenMangler.h index 74a5c11eba2c4..b9c553851f0e8 100644 --- a/lib/IRGen/IRGenMangler.h +++ b/lib/IRGen/IRGenMangler.h @@ -32,6 +32,10 @@ struct SymbolicMangling { std::string String; std::vector> SymbolicReferences; + + unsigned runtimeSizeInBytes() const { + return String.size(); + } }; /// The mangler for all kind of symbols produced in IRGen. @@ -87,6 +91,10 @@ class IRGenMangler : public Mangle::ASTMangler { return mangleTypeSymbol(type, "ML"); } + std::string mangleTypeMetadataDemanglingCacheVariable(Type type) { + return mangleTypeSymbol(type, "MD"); + } + std::string mangleTypeFullMetadataFull(Type type) { return mangleTypeSymbol(type, "Mf"); } diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index bc150313cc607..c5536317d4237 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -535,6 +535,7 @@ static bool isReturnAttribute(llvm::Attribute::AttrKind Attr); namespace RuntimeConstants { const auto ReadNone = llvm::Attribute::ReadNone; const auto ReadOnly = llvm::Attribute::ReadOnly; + const auto ArgMemOnly = llvm::Attribute::ArgMemOnly; const auto NoReturn = llvm::Attribute::NoReturn; const auto NoUnwind = llvm::Attribute::NoUnwind; const auto ZExt = llvm::Attribute::ZExt; diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index 8e372a1332a86..1c0dd2e3a38e3 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -1059,9 +1059,12 @@ class IRGenModule { /// reflection metadata. llvm::SetVector BuiltinTypes; - llvm::Constant *getTypeRef(Type type, GenericSignature *genericSig, - MangledTypeRefRole role); - llvm::Constant *getTypeRef(CanType type, MangledTypeRefRole role); + std::pair + getTypeRef(Type type, GenericSignature *genericSig, MangledTypeRefRole role); + + std::pair + getTypeRef(CanType type, MangledTypeRefRole role); + llvm::Constant *emitWitnessTableRefString(CanType type, ProtocolConformanceRef conformance, GenericSignature *genericSig, @@ -1293,8 +1296,9 @@ private: \ NominalTypeDecl *nominal, ArrayRef genericArgs, ForDefinition_t forDefinition); - llvm::Constant *getAddrOfTypeMetadataLazyCacheVariable(CanType type, - ForDefinition_t forDefinition); + llvm::Constant *getAddrOfTypeMetadataLazyCacheVariable(CanType type); + llvm::Constant *getAddrOfTypeMetadataDemanglingCacheVariable(CanType type, + ConstantInit definition); llvm::Constant *getAddrOfClassMetadataBounds(ClassDecl *D, ForDefinition_t forDefinition); diff --git a/lib/IRGen/Linking.cpp b/lib/IRGen/Linking.cpp index 2a3762c3c511f..d6bace8d69b9f 100644 --- a/lib/IRGen/Linking.cpp +++ b/lib/IRGen/Linking.cpp @@ -153,6 +153,9 @@ std::string LinkEntity::mangleAsString() const { case Kind::TypeMetadataLazyCacheVariable: return mangler.mangleTypeMetadataLazyCacheVariable(getType()); + case Kind::TypeMetadataDemanglingCacheVariable: + return mangler.mangleTypeMetadataDemanglingCacheVariable(getType()); + case Kind::TypeMetadataInstantiationCache: return mangler.mangleTypeMetadataInstantiationCache( cast(getDecl())); @@ -473,6 +476,9 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const { // Everything else is only referenced inside its module. return SILLinkage::Private; } + + case Kind::TypeMetadataDemanglingCacheVariable: + return SILLinkage::Shared; case Kind::TypeMetadata: { auto *nominal = getType().getAnyNominal(); @@ -783,6 +789,7 @@ bool LinkEntity::isAvailableExternally(IRGenModule &IGM) const { case Kind::ValueWitness: case Kind::TypeMetadataAccessFunction: case Kind::TypeMetadataLazyCacheVariable: + case Kind::TypeMetadataDemanglingCacheVariable: case Kind::ProtocolWitnessTableLazyAccessFunction: case Kind::ProtocolWitnessTableLazyCacheVariable: case Kind::AssociatedTypeWitnessTableAccessFunction: @@ -827,6 +834,8 @@ llvm::Type *LinkEntity::getDefaultDeclarationType(IRGenModule &IGM) const { return IGM.ObjCClassStructTy; case Kind::TypeMetadataLazyCacheVariable: return IGM.TypeMetadataPtrTy; + case Kind::TypeMetadataDemanglingCacheVariable: + return llvm::StructType::get(IGM.Int32Ty, IGM.Int32Ty); case Kind::TypeMetadataSingletonInitializationCache: // TODO: put a cache variable on IGM return llvm::StructType::get(IGM.getLLVMContext(), @@ -943,6 +952,8 @@ Alignment LinkEntity::getAlignment(IRGenModule &IGM) const { case Kind::OpaqueTypeDescriptorAccessorVar: case Kind::ObjCResilientClassStub: return IGM.getPointerAlignment(); + case Kind::TypeMetadataDemanglingCacheVariable: + return Alignment(8); case Kind::SILFunction: return Alignment(1); default: @@ -1047,6 +1058,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module, case Kind::ValueWitness: case Kind::ValueWitnessTable: case Kind::TypeMetadataLazyCacheVariable: + case Kind::TypeMetadataDemanglingCacheVariable: case Kind::ReflectionBuiltinDescriptor: case Kind::ReflectionFieldDescriptor: case Kind::CoroutineContinuationPrototype: @@ -1170,6 +1182,7 @@ const SourceFile *LinkEntity::getSourceFileForEmission() const { case Kind::ObjCClassRef: case Kind::TypeMetadataAccessFunction: case Kind::TypeMetadataLazyCacheVariable: + case Kind::TypeMetadataDemanglingCacheVariable: return nullptr; // TODO diff --git a/lib/IRGen/MetadataRequest.cpp b/lib/IRGen/MetadataRequest.cpp index 5c2162394b266..5aae1884a7e84 100644 --- a/lib/IRGen/MetadataRequest.cpp +++ b/lib/IRGen/MetadataRequest.cpp @@ -1400,6 +1400,10 @@ void irgen::emitCacheAccessFunction(IRGenModule &IGM, bool isReadNone) { assert((cacheStrategy == CacheStrategy::None) == (cacheVariable == nullptr)); accessor->setDoesNotThrow(); + // Don't inline cache functions, since doing so has little impact on + // overall performance. + accessor->addAttribute(llvm::AttributeList::FunctionIndex, + llvm::Attribute::NoInline); // This function is logically 'readnone': the caller does not need // to reason about any side effects or stores it might perform. @@ -1814,8 +1818,7 @@ irgen::createTypeMetadataAccessFunction(IRGenModule &IGM, CanType type, // For lazy initialization, the cache variable is just a pointer. case CacheStrategy::Lazy: - cacheVariable = - IGM.getAddrOfTypeMetadataLazyCacheVariable(type, ForDefinition); + cacheVariable = IGM.getAddrOfTypeMetadataLazyCacheVariable(type); break; // For in-place initialization, drill down to the first element. @@ -1888,6 +1891,317 @@ irgen::getGenericTypeMetadataAccessFunction(IRGenModule &IGM, return accessor; } +static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) { + // A nongeneric nominal type with nontrivial metadata has an accessor + // already we can just call. + if (auto nom = dyn_cast(type)) { + if (!isa(nom->getDecl()) + && (!nom->getDecl()->isGenericContext() + || nom->getDecl()->getGenericSignature()->areAllParamsConcrete()) + && (!nom->getClassOrBoundGenericClass() + || !nom->getClassOrBoundGenericClass()->hasClangNode() + || nom->getClassOrBoundGenericClass()->isForeign())) { + return false; + } + } + + return true; + +// The visitor below can be used to fine-tune a heuristic to decide whether +// demangling might be better for code size than open-coding an access. In +// my experiments on the Swift standard library and Apple SDK overlays, +// always demangling seemed to have the biggest code size benefit. +#if false + // Guess the number of calls and addresses we need to materialize a + // metadata record in code. + struct OpenCodedMetadataAccessWeightVisitor + : CanTypeVisitor + { + IRGenModule &IGM; + unsigned NumCalls = 0, NumAddresses = 0; + + OpenCodedMetadataAccessWeightVisitor(IRGenModule &IGM) + : IGM(IGM) {} + + void visitBoundGenericType(CanBoundGenericType bgt) { + // Need to materialize all the arguments, then call the metadata + // accessor. + // + // TODO: Also need to count the parent type's generic arguments. + for (auto arg : bgt->getGenericArgs()) { + visit(arg); + } + NumCalls += 1; + } + + void visitNominalType(CanNominalType nom) { + // Some nominal types have trivially-referenceable metadata symbols, + // others may require accessors to trigger instantiation. + // + // TODO: Also need to count the parent type's generic arguments. + if (isTypeMetadataAccessTrivial(IGM, nom)) { + NumAddresses += 1; + } else { + NumCalls += 1; + } + } + + void visitTupleType(CanTupleType tup) { + // The empty tuple has trivial metadata. + if (tup->getNumElements() == 0) { + NumAddresses += 1; + return; + } + // Need to materialize the element types, then call the getTupleMetadata + // accessor. + for (auto elt : tup.getElementTypes()) { + visit(elt); + } + NumCalls += 1; + } + + void visitAnyFunctionType(CanAnyFunctionType fun) { + // Need to materialize the arguments and return, then call the + // getFunctionMetadata accessor. + for (auto arg : fun.getParams()) { + visit(arg.getPlainType()); + } + visit(fun.getResult()); + + NumCalls += 1; + } + + void visitMetatypeType(CanMetatypeType meta) { + // Need to materialize the instance type, then call the + // getMetatypeMetadata accessor. + visit(meta.getInstanceType()); + NumCalls += 1; + } + + void visitProtocolType(CanProtocolType proto) { + // Need to reference the protocol descriptor, then call the + // getExistentialTypeMetadata accessor. + NumAddresses += 1; + NumCalls += 1; + } + + void visitBuiltinType(CanBuiltinType b) { + // Builtins always have trivial metadata. + NumAddresses += 1; + } + + void visitProtocolCompositionType(CanProtocolCompositionType comp) { + unsigned numMembers = comp->getMembers().size(); + // The empty compositions Any and AnyObject are trivial. + if (numMembers == 0) { + NumAddresses += 1; + return; + } + // Need to materialize the base class, if any. + if (comp->getMembers().front()->getClassOrBoundGenericClass()) { + visit(CanType(comp->getMembers().front())); + numMembers -= 1; + } + // Need to reference the protocol descriptors for each protocol. + NumAddresses += numMembers; + // Finally, call the getExistentialTypeMetadata accessor. + NumCalls += 1; + } + + void visitExistentialMetatypeType(CanExistentialMetatypeType meta) { + // The number of accesses turns out the same as the instance type, + // but instead of getExistentialTypeMetadata, we call + // getExistentialMetatypeMetadata + visit(meta.getInstanceType()); + } + + // Shouldn't emit metadata for other kinds of types. + void visitType(CanType t) { + llvm_unreachable("unhandled type?!"); + } + }; + + OpenCodedMetadataAccessWeightVisitor visitor(IGM); + + visitor.visit(type); + + // If we need more than one accessor call, or the access requires too many + // arguments, the mangled name accessor is probably more compact. + return visitor.NumCalls > 1 || visitor.NumAddresses > 1; +#endif + +} + +/// Emit a call to a type metadata accessor using a mangled name. +static MetadataResponse +emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type, + DynamicMetadataRequest request) { + // TODO: We can only answer blocking complete metadata requests with the + // <=5.1 runtime ABI entry points. + assert(request.isStaticallyBlockingComplete() + && "can only form complete metadata by mangled name"); + + auto &IGM = IGF.IGM; + llvm::Constant *mangledString; + unsigned mangledStringSize; + std::tie(mangledString, mangledStringSize) = + IGM.getTypeRef(type, MangledTypeRefRole::Metadata); + + assert(mangledStringSize < 0x80000000u + && "2GB of mangled name ought to be enough for anyone"); + + // Get or create the cache variable if necessary. + auto cache = IGM.getAddrOfTypeMetadataDemanglingCacheVariable(type, + ConstantInit()); + + if (cast(cache->stripPointerCasts())->isDeclaration()) { + ConstantInitBuilder builder(IGM); + auto structBuilder = builder.beginStruct(); + + // A "negative" 64-bit value in the cache indicates the uninitialized state. + // Which word has that bit in the {i32, i32} layout depends on endianness. + + if (IGM.getModule()->getDataLayout().isBigEndian()) { + structBuilder.addInt32(-mangledStringSize); + structBuilder.addRelativeAddress(mangledString); + } else { + structBuilder.addRelativeAddress(mangledString); + structBuilder.addInt32(-mangledStringSize); + } + + auto init = structBuilder.finishAndCreateFuture(); + cache = IGM.getAddrOfTypeMetadataDemanglingCacheVariable(type, init); + } + + // Get or create a shared helper function to do the instantiation. + auto instantiationFn = cast( + IGM.getModule() + ->getOrInsertFunction("__swift_instantiateConcreteTypeFromMangledName", + IGF.IGM.TypeMetadataPtrTy, cache->getType()) + ->stripPointerCasts()); + if (instantiationFn->empty()) { + ApplyIRLinkage(IRLinkage::InternalLinkOnceODR) + .to(instantiationFn); + instantiationFn->setDoesNotAccessMemory(); + instantiationFn->setDoesNotThrow(); + instantiationFn->addAttribute(llvm::AttributeList::FunctionIndex, + llvm::Attribute::NoInline); + + [&IGM, instantiationFn]{ + IRGenFunction subIGF(IGM, instantiationFn); + + auto params = subIGF.collectParameters(); + auto cache = params.claimNext(); + + // Load the existing cache value. + // Conceptually, this needs to establish memory ordering with the + // store we do later in the function: if the metadata value is + // non-null, we must be able to see any stores performed by the + // initialization of the metadata. However, any attempt to read + // from the metadata will be address-dependent on the loaded + // metadata pointer, which is sufficient to provide adequate + // memory ordering guarantees on all the platforms we care about: + // ARM has special rules about address dependencies, and x86's + // memory ordering is strong enough to guarantee the visibility + // even without the address dependency. + // + // And we do not need to worry about the compiler because the + // address dependency naturally forces an order to the memory + // accesses. + // + // Therefore, we can perform a completely naked load here. + // FIXME: Technically should be "consume", but that introduces barriers + // in the current LLVM ARM backend. + auto cacheWordAddr = subIGF.Builder.CreateBitCast(cache, + IGM.Int64Ty->getPointerTo()); + auto load = subIGF.Builder.CreateLoad(cacheWordAddr, Alignment(8)); + // Make this barrier explicit when building for TSan to avoid false positives. + if (IGM.IRGen.Opts.Sanitizers & SanitizerKind::Thread) + load->setOrdering(llvm::AtomicOrdering::Acquire); + else + load->setOrdering(llvm::AtomicOrdering::Monotonic); + + // Compare the load result to see if it's negative. + auto isUnfilledBB = subIGF.createBasicBlock(""); + auto contBB = subIGF.createBasicBlock(""); + llvm::Value *comparison = subIGF.Builder.CreateICmpSLT(load, + llvm::ConstantInt::get(IGM.Int64Ty, 0)); + comparison = subIGF.Builder.CreateExpect(comparison, + llvm::ConstantInt::get(IGM.Int1Ty, 0)); + subIGF.Builder.CreateCondBr(comparison, isUnfilledBB, contBB); + auto loadBB = subIGF.Builder.GetInsertBlock(); + + // If the load is negative, emit the call to instantiate the type + // metadata. + subIGF.Builder.SetInsertPoint(&subIGF.CurFn->back()); + subIGF.Builder.emitBlock(isUnfilledBB); + + // Break up the loaded value into size and relative address to the + // string. + auto size = subIGF.Builder.CreateAShr(load, 32); + size = subIGF.Builder.CreateTruncOrBitCast(size, IGM.SizeTy); + size = subIGF.Builder.CreateNeg(size); + + auto stringAddrOffset = subIGF.Builder.CreateTrunc(load, + IGM.Int32Ty); + stringAddrOffset = subIGF.Builder.CreateSExtOrBitCast(stringAddrOffset, + IGM.SizeTy); + auto stringAddrBase = subIGF.Builder.CreatePtrToInt(cache, IGM.SizeTy); + if (IGM.getModule()->getDataLayout().isBigEndian()) { + stringAddrBase = subIGF.Builder.CreateAdd(stringAddrBase, + llvm::ConstantInt::get(IGM.SizeTy, 4)); + } + auto stringAddr = subIGF.Builder.CreateAdd(stringAddrBase, + stringAddrOffset); + stringAddr = subIGF.Builder.CreateIntToPtr(stringAddr, IGM.Int8PtrTy); + + auto call = + subIGF.Builder.CreateCall(IGM.getGetTypeByMangledNameInContextFn(), + {stringAddr, + size, + // TODO: Use mangled name lookup in generic + // contexts? + llvm::ConstantPointerNull::get(IGM.TypeContextDescriptorPtrTy), + llvm::ConstantPointerNull::get(IGM.Int8PtrPtrTy)}); + call->setDoesNotThrow(); + call->setDoesNotAccessMemory(); + call->setCallingConv(IGM.SwiftCC); + + // Store the result back to the cache. Metadata instantatiation should + // already have emitted the necessary barriers to publish the instantiated + // metadata to other threads, so we only need to expose the pointer. + // Worst case, another thread might race with us and reinstantiate the + // exact same metadata pointer. + auto resultWord = subIGF.Builder.CreatePtrToInt(call, IGM.SizeTy); + resultWord = subIGF.Builder.CreateZExtOrBitCast(resultWord, IGM.Int64Ty); + auto store = subIGF.Builder.CreateStore(resultWord, cacheWordAddr, + Alignment(8)); + store->setOrdering(llvm::AtomicOrdering::Monotonic); + subIGF.Builder.CreateBr(contBB); + + subIGF.Builder.SetInsertPoint(loadBB); + subIGF.Builder.emitBlock(contBB); + auto phi = subIGF.Builder.CreatePHI(IGM.Int64Ty, 2); + phi->addIncoming(load, loadBB); + phi->addIncoming(resultWord, isUnfilledBB); + + auto resultAddr = subIGF.Builder.CreateTruncOrBitCast(phi, IGM.SizeTy); + resultAddr = subIGF.Builder.CreateIntToPtr(resultAddr, + IGM.TypeMetadataPtrTy); + subIGF.Builder.CreateRet(resultAddr); + }(); + } + + auto call = IGF.Builder.CreateCall(instantiationFn, cache); + call->setDoesNotThrow(); + call->setDoesNotAccessMemory(); + + auto response = MetadataResponse::forComplete(call); + + IGF.setScopedLocalTypeMetadata(type, response); + return response; +} + /// Emit a call to the type metadata accessor for the given function. static MetadataResponse emitCallToTypeMetadataAccessFunction(IRGenFunction &IGF, CanType type, @@ -1896,6 +2210,18 @@ emitCallToTypeMetadataAccessFunction(IRGenFunction &IGF, CanType type, if (auto local = IGF.tryGetLocalTypeMetadata(type, request)) return local; + // If the metadata would require multiple runtime calls to build, emit a + // single access by mangled name instead, if we're asking for complete + // metadata. + // + // TODO: The getTypeByMangledNameInContext entry point in Swift <=5.1 can + // only answer requests for complete metadata. We could introduce new + // entry points that could answer all metadata requests. + if (request.isStaticallyBlockingComplete() + && shouldAccessByMangledName(IGF.IGM, type)) { + return emitMetadataAccessByMangledName(IGF, type, request); + } + llvm::Constant *accessor = getOrCreateTypeMetadataAccessFunction(IGF.IGM, type); llvm::CallInst *call = IGF.Builder.CreateCall(accessor, { request.get(IGF) }); diff --git a/test/ClangImporter/attr-swift_private.swift b/test/ClangImporter/attr-swift_private.swift index aa6e0c70fb210..05ddc81835f30 100644 --- a/test/ClangImporter/attr-swift_private.swift +++ b/test/ClangImporter/attr-swift_private.swift @@ -100,10 +100,6 @@ public func testTopLevel() { #endif } -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$sSo10PrivFooSubCMa{{.*}} { -// CHECK: %objc_class** @"OBJC_CLASS_REF_$_PrivFooSub" -// CHECK: } - _ = __PrivAnonymousA _ = __E0PrivA _ = __PrivE1A as __PrivE1 diff --git a/test/IRGen/ELF-objc-sections.swift b/test/IRGen/ELF-objc-sections.swift deleted file mode 100644 index 9e871143eef50..0000000000000 --- a/test/IRGen/ELF-objc-sections.swift +++ /dev/null @@ -1,29 +0,0 @@ -// RUN: %target-swift-frontend -parse-stdlib -enable-objc-interop -disable-objc-attr-requires-foundation-module -I %S/Inputs/usr/include -Xcc --sysroot=/var/empty -emit-ir %s -o - | %FileCheck %s -check-prefix CHECK-ELF - -// REQUIRES: OS=linux-gnu - -import ObjCInterop - -@objc -class C { -} - -extension C : P { - public func method() { - f(I()) - } -} - -@_objc_non_lazy_realization -class D { -} - -// CHECK-ELF-NOT: @"$s4main1CCMf" = {{.*}}, section "__DATA,__objc_data, regular" -// CHECK-ELF: @"\01l_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, section "objc_protolist" -// CHECK-ELF: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section "objc_protorefs", align 8 -// CHECK-ELF: @"OBJC_CLASS_REF_$_I" = {{.*}}, section "objc_classrefs", align 8 -// CHECK-ELF: @"\01L_selector(init)" = {{.*}}, section "objc_selrefs" -// CHECK-ELF: @objc_classes = {{.*}}, section "objc_classlist" -// CHECK-ELF: @objc_categories = {{.*}}, section "objc_catlist" -// CHECK-ELF: @objc_non_lazy_classes = {{.*}}, section "objc_nlclslist", align 8 - diff --git a/test/IRGen/MachO-objc-sections.swift b/test/IRGen/MachO-objc-sections.swift index 313d838579f9c..7f90104983152 100644 --- a/test/IRGen/MachO-objc-sections.swift +++ b/test/IRGen/MachO-objc-sections.swift @@ -21,8 +21,6 @@ class D { // CHECK-MACHO: @"$s4main1CCMf" = {{.*}}, section "__DATA,__objc_data, regular" // CHECK-MACHO: @"\01l_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, section "__DATA,__objc_protolist,coalesced,no_dead_strip" // CHECK-MACHO: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section "__DATA,__objc_protorefs,coalesced,no_dead_strip" -// CHECK-MACHO: @"OBJC_CLASS_REF_$_I" = {{.*}}, section "__DATA,__objc_classrefs,regular,no_dead_strip" -// CHECK-MACHO: @"\01L_selector(init)" = {{.*}}, section "__DATA,__objc_selrefs,literal_pointers,no_dead_strip" // CHECK-MACHO: @objc_classes = {{.*}}, section "__DATA,__objc_classlist,regular,no_dead_strip" // CHECK-MACHO: @objc_categories = {{.*}}, section "__DATA,__objc_catlist,regular,no_dead_strip" // CHECK-MACHO: @objc_non_lazy_classes = {{.*}}, section "__DATA,__objc_nlclslist,regular,no_dead_strip" diff --git a/test/IRGen/access_type_metadata_by_mangled_name.swift b/test/IRGen/access_type_metadata_by_mangled_name.swift new file mode 100644 index 0000000000000..3b94411d1f086 --- /dev/null +++ b/test/IRGen/access_type_metadata_by_mangled_name.swift @@ -0,0 +1,68 @@ +// RUN: %target-swift-frontend -emit-ir -parse-stdlib %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-endian + +// CHECK: @"$s36access_type_metadata_by_mangled_name3FooCyAA3BarCyAA3ZimCyAA4ZangCGGGMD" = linkonce_odr hidden global { i32, i32 } + +// CHECK-little-SAME: @"symbolic 36access_type_metadata_by_mangled_name3FooCyAA3BarCyAA3ZimCyAA4ZangCGGG" +// CHECK-little-SAME: i32 -71 + +// CHECK-big-SAME: i32 -71 +// CHECK-big-SAME: @"symbolic 36access_type_metadata_by_mangled_name3FooCyAA3BarCyAA3ZimCyAA4ZangCGGG" + +// CHECK-SAME: align 8 + +class Foo { + class NestedNonGeneric {} + class NestedGeneric {} +} + +class Bar { } + +class Zim {} + +class Zang { + class NestedNonGeneric {} + class NestedGeneric {} +} + +extension Zim where T == Zang { + class ExtensionNonGeneric {} + class ExtensionGeneric {} +} + +precedencegroup AssignmentPrecedence {} + +protocol Proto {} + +// CHECK-LABEL: define {{.*}} @"$s36access_type_metadata_by_mangled_name4testyXlyF"() +public func test() -> Builtin.AnyObject { + var x: Builtin.AnyObject + + // CHECK: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$s36access_type_metadata_by_mangled_name3FooCyAA3BarCyAA3ZimCyAA4ZangCGGGMD") + x = Foo>>() + // CHECK: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$s36access_type_metadata_by_mangled_name3FooC16NestedNonGenericCyAA4ZangC_GMD") + x = Foo.NestedNonGeneric() + // CHECK: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$s36access_type_metadata_by_mangled_name3FooC13NestedGenericCyAA4ZangC_AGGMD") + x = Foo.NestedGeneric() + // CHECK: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$s36access_type_metadata_by_mangled_name4ZangC13NestedGenericCy_ACGMD") + x = Zang.NestedGeneric() + // CHECK: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$s36access_type_metadata_by_mangled_name3ZimCA2A4ZangCRszlE16ExtensionGenericCyAE_AEGMD") + x = Zim.ExtensionGeneric() + + // Accessing nongeneric nominal type metadata should still go through the + // accessor, which generally has to exist anyway. Using a mangled name would + // only add code size. + // CHECK: call swiftcc %swift.metadata_response @"$s36access_type_metadata_by_mangled_name4ZangCMa" + x = Zang() + // CHECK: call swiftcc %swift.metadata_response @"$s36access_type_metadata_by_mangled_name4ZangC16NestedNonGenericCMa" + x = Zang.NestedNonGeneric() + // CHECK: call swiftcc %swift.metadata_response @"$s36access_type_metadata_by_mangled_name3ZimCA2A4ZangCRszlE19ExtensionNonGenericCyAE_GMa" + x = Zim.ExtensionNonGeneric() + + // Protocols still have only existential type metadata, so it's better + // to access them by mangled name. + // CHECK: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$s36access_type_metadata_by_mangled_name5Proto_pMD") + var y: Any.Type = Proto.self + + return x +} + diff --git a/test/IRGen/access_type_metadata_by_mangled_name_objc.swift b/test/IRGen/access_type_metadata_by_mangled_name_objc.swift new file mode 100644 index 0000000000000..3322426d97dbc --- /dev/null +++ b/test/IRGen/access_type_metadata_by_mangled_name_objc.swift @@ -0,0 +1,21 @@ +// RUN: %empty-directory(%t) +// RUN: %build-irgen-test-overlays +// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) %s -emit-ir | %FileCheck %s + +// REQUIRES: objc_interop + +import Foundation +import CoreCooling + +// CHECK-LABEL: define {{.*}} @"$s41access_type_metadata_by_mangled_name_objc4testyyF"() +public func test() { + var x: Any.Type + + // Access ObjC classes by mangled name. + // CHECK: @"$sSo8NSObjectCMD" + x = NSObject.self + + // Use the metadata accessor for CF classes that already has to exist. + // CHECK: @"$sSo17CCRefrigeratorRefaMa" + x = CCRefrigerator.self +} diff --git a/test/IRGen/big_types_corner_cases.swift b/test/IRGen/big_types_corner_cases.swift index ef49f6cff1a9b..07a1836d1b445 100644 --- a/test/IRGen/big_types_corner_cases.swift +++ b/test/IRGen/big_types_corner_cases.swift @@ -205,15 +205,13 @@ public func testGetFunc() { } // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} hidden swiftcc void @"$s22big_types_corner_cases7TestBigC4testyyF"(%T22big_types_corner_cases7TestBigC* swiftself) -// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$sSayy22big_types_corner_cases9BigStructVcSgGMa" -// CHECK: [[CALL1:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 +// CHECK: [[CALL1:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSayy22big_types_corner_cases9BigStructVcSgGMD" // CHECK: [[CALL2:%.*]] = call i8** @"$sSayy22big_types_corner_cases9BigStructVcSgGSayxGSlsWl // CHECK: call swiftcc void @"$sSlsE10firstIndex5where0B0QzSgSb7ElementQzKXE_tKF"(%TSq.{{.*}}* noalias nocapture sret {{.*}}, i8* bitcast (i1 (%T22big_types_corner_cases9BigStructVytIegnr_Sg*, %swift.refcounted*, %swift.error**)* @"$s22big_types_corner_cases9BigStructVIegy_SgSbs5Error_pIggdzo_ACytIegnr_SgSbsAE_pIegndzo_TRTA" to i8*), %swift.opaque* {{.*}}, %swift.type* [[CALL1]], i8** [[CALL2]], %swift.opaque* noalias nocapture swiftself // CHECK: ret void // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} hidden swiftcc void @"$s22big_types_corner_cases7TestBigC5test2yyF"(%T22big_types_corner_cases7TestBigC* swiftself) -// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$sSaySS2ID_y22big_types_corner_cases9BigStructVcSg7handlertGMa" -// CHECK: [[CALL1:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 +// CHECK: [[CALL1:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSaySS2ID_y22big_types_corner_cases9BigStructVcSg7handlertGMD" // CHECK: [[CALL2:%.*]] = call i8** @"$sSaySS2ID_y22big_types_corner_cases9BigStructVcSg7handlertGSayxGSlsWl" // CHECK: call swiftcc void @"$sSlss16IndexingIteratorVyxG0B0RtzrlE04makeB0ACyF"(%Ts16IndexingIteratorV* noalias nocapture sret {{.*}}, %swift.type* [[CALL1]], i8** [[CALL2]], %swift.opaque* noalias nocapture swiftself {{.*}}) // CHECK: ret void diff --git a/test/IRGen/builtins.swift b/test/IRGen/builtins.swift index ef98ddcfbaaa6..1db50c8b7c9eb 100644 --- a/test/IRGen/builtins.swift +++ b/test/IRGen/builtins.swift @@ -335,14 +335,15 @@ func testCondFail(_ b: Bool, c: Bool) { // CHECK: [[PRED_PTR:%.*]] = bitcast i8* %0 to [[WORD:i64|i32]]* // CHECK-objc: [[PRED:%.*]] = load {{.*}} [[WORD]]* [[PRED_PTR]] // CHECK-objc: [[IS_DONE:%.*]] = icmp eq [[WORD]] [[PRED]], -1 -// CHECK-objc: br i1 [[IS_DONE]], label %[[DONE:.*]], label %[[NOT_DONE:.*]] -// CHECK-objc: [[NOT_DONE]]: -// CHECK: call void @swift_once([[WORD]]* [[PRED_PTR]], i8* %1, i8* undef) -// CHECK-objc: br label %[[DONE]] +// CHECK-objc: [[IS_DONE_X:%.*]] = call i1 @llvm.expect.i1(i1 [[IS_DONE]], i1 true) +// CHECK-objc: br i1 [[IS_DONE_X]], label %[[DONE:.*]], label %[[NOT_DONE:.*]] // CHECK-objc: [[DONE]]: // CHECK-objc: [[PRED:%.*]] = load {{.*}} [[WORD]]* [[PRED_PTR]] // CHECK-objc: [[IS_DONE:%.*]] = icmp eq [[WORD]] [[PRED]], -1 // CHECK-objc: call void @llvm.assume(i1 [[IS_DONE]]) +// CHECK-objc: [[NOT_DONE]]: +// CHECK: call void @swift_once([[WORD]]* [[PRED_PTR]], i8* %1, i8* undef) +// CHECK-objc: br label %[[DONE]] func testOnce(_ p: Builtin.RawPointer, f: @escaping @convention(c) () -> ()) { Builtin.once(p, f) @@ -352,14 +353,15 @@ func testOnce(_ p: Builtin.RawPointer, f: @escaping @convention(c) () -> ()) { // CHECK: [[PRED_PTR:%.*]] = bitcast i8* %0 to [[WORD:i64|i32]]* // CHECK-objc: [[PRED:%.*]] = load {{.*}} [[WORD]]* [[PRED_PTR]] // CHECK-objc: [[IS_DONE:%.*]] = icmp eq [[WORD]] [[PRED]], -1 -// CHECK-objc: br i1 [[IS_DONE]], label %[[DONE:.*]], label %[[NOT_DONE:.*]] -// CHECK-objc: [[NOT_DONE]]: -// CHECK: call void @swift_once([[WORD]]* [[PRED_PTR]], i8* %1, i8* %2) -// CHECK-objc: br label %[[DONE]] +// CHECK-objc: [[IS_DONE_X:%.*]] = call i1 @llvm.expect.i1(i1 [[IS_DONE]], i1 true) +// CHECK-objc: br i1 [[IS_DONE_X]], label %[[DONE:.*]], label %[[NOT_DONE:.*]] // CHECK-objc: [[DONE]]: // CHECK-objc: [[PRED:%.*]] = load {{.*}} [[WORD]]* [[PRED_PTR]] // CHECK-objc: [[IS_DONE:%.*]] = icmp eq [[WORD]] [[PRED]], -1 // CHECK-objc: call void @llvm.assume(i1 [[IS_DONE]]) +// CHECK-objc: [[NOT_DONE]]: +// CHECK: call void @swift_once([[WORD]]* [[PRED_PTR]], i8* %1, i8* %2) +// CHECK-objc: br label %[[DONE]] func testOnceWithContext(_ p: Builtin.RawPointer, f: @escaping @convention(c) (Builtin.RawPointer) -> (), k: Builtin.RawPointer) { Builtin.onceWithContext(p, f, k) } diff --git a/test/IRGen/c_function_pointer.sil b/test/IRGen/c_function_pointer.sil index d846b0450448a..e9f000674ebca 100644 --- a/test/IRGen/c_function_pointer.sil +++ b/test/IRGen/c_function_pointer.sil @@ -16,15 +16,3 @@ entry(%f : $@convention(c) () -> ()): return %z : $() } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.type* @c_function_pointer_metadata() -sil @c_function_pointer_metadata : $@convention(thin) () -> @thick Any.Type { -entry: - // CHECK: call swiftcc %swift.metadata_response @"$syyXCMa"([[INT]] 0) - %m = metatype $@thick (@convention(c) () -> ()).Type - %a = init_existential_metatype %m : $@thick (@convention(c) () -> ()).Type, $@thick Any.Type - return %a : $@thick Any.Type -} - -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$syyXCMa"( -// -- 0x3000001 -- C convention, 1 argument -// CHECK: call %swift.type* @swift_getFunctionTypeMetadata0([[WORD:i(32|64)]] 196608, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) diff --git a/test/IRGen/dllimport.swift b/test/IRGen/dllimport.swift index 296e745b919cb..98fdc11c24591 100644 --- a/test/IRGen/dllimport.swift +++ b/test/IRGen/dllimport.swift @@ -41,15 +41,12 @@ public func g() { // CHECK-NO-OPT-DAG: declare dllimport void @swift_release(%swift.refcounted*) // CHECK-NO-OPT-DAG: declare dllimport %swift.refcounted* @swift_retain(%swift.refcounted* returned) // CHECK-NO-OPT-DAG: @"$s9dllexport1pMp" = external dllimport global %swift.protocol -// CHECK-NO-OPT-DAG: @"$sytN" = external dllimport global %swift.full_type // CHECK-NO-OPT-DAG: declare dllimport swiftcc i8* @"$s9dllexport2ciAA1cCvau"() // CHECK-NO-OPT-DAG: declare dllimport swiftcc %swift.refcounted* @"$s9dllexport1cCfd"(%T9dllexport1cC* swiftself) -// CHECK-NO-OPT-DAG: declare dllimport swiftcc %swift.metadata_response @"$s9dllexport1cCMa"(i32) // CHECK-NO-OPT-DAG: declare dllimport void @swift_deallocClassInstance(%swift.refcounted*, i32, i32) // CHECK-OPT-DAG: declare dllimport %swift.refcounted* @swift_retain(%swift.refcounted* returned) local_unnamed_addr // CHECK-OPT-DAG: @"__imp_$s9dllexport1pMp" = external externally_initialized constant %swift.protocol* // CHECK-OPT-DAG: declare dllimport swiftcc i8* @"$s9dllexport2ciAA1cCvau"() -// CHECK-OPT-DAG: declare dllimport swiftcc %swift.metadata_response @"$s9dllexport1cCMa"(i32) // CHECK-OPT-DAG: declare dllimport void @swift_deallocClassInstance(%swift.refcounted*, i32, i32) // CHECK-OPT-DAG: declare dllimport swiftcc %swift.refcounted* @"$s9dllexport1cCfd"(%T9dllexport1cC* swiftself) diff --git a/test/IRGen/dynamic_cast.sil b/test/IRGen/dynamic_cast.sil index 7033089d942fb..7c0936bc3c991 100644 --- a/test/IRGen/dynamic_cast.sil +++ b/test/IRGen/dynamic_cast.sil @@ -23,8 +23,7 @@ bb0(%0 : $*P): // CHECK: [[T0:%.*]] = alloca [[S:%.*]], align // CHECK: [[T1:%.*]] = bitcast [[S]]* [[T0]] to [[OPAQUE:%swift.opaque]]* // CHECK: [[T2:%.*]] = bitcast [[P:%.*]]* {{%.*}} to [[OPAQUE]]* - // CHECK: [[T3:%.*]] = call swiftcc %swift.metadata_response @"$s12dynamic_cast1P_pMa"([[INT]] 0) - // CHECK: [[T4:%.*]] = extractvalue %swift.metadata_response [[T3]], 0 + // CHECK: [[T4:%.*]] = call {{.*}}@"$s12dynamic_cast1P_pMD" // CHECK: call i1 @swift_dynamicCast([[OPAQUE]]* [[T1]], [[OPAQUE]]* [[T2]], %swift.type* [[T4]], %swift.type* {{.*}}, [[INT]] 7) %1 = alloc_stack $S unconditional_checked_cast_addr P in %0 : $*P to S in %1 : $*S @@ -34,17 +33,13 @@ bb0(%0 : $*P): return %2 : $() } -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s12dynamic_cast1P_pMa"( -// CHECK: call %swift.type* @swift_getExistentialTypeMetadata( - // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @testUnconditional1( sil @testUnconditional1 : $@convention(thin) (@in P) -> () { bb0(%0 : $*P): // CHECK: [[T0:%.*]] = alloca [[S:%.*]], align // CHECK: [[T1:%.*]] = bitcast [[S]]* [[T0]] to [[OPAQUE:%swift.opaque]]* // CHECK: [[T2:%.*]] = bitcast [[P:%.*]]* {{%.*}} to [[OPAQUE]]* - // CHECK: [[T3:%.*]] = call swiftcc %swift.metadata_response @"$s12dynamic_cast1P_pMa"([[INT]] 0) - // CHECK: [[T4:%.*]] = extractvalue %swift.metadata_response [[T3]], 0 + // CHECK: [[T4:%.*]] = call {{.*}}@"$s12dynamic_cast1P_pMD" // CHECK: call i1 @swift_dynamicCast([[OPAQUE]]* [[T1]], [[OPAQUE]]* [[T2]], %swift.type* [[T4]], %swift.type* {{.*}}, [[INT]] 7) %1 = alloc_stack $S unconditional_checked_cast_addr P in %0 : $*P to S in %1 : $*S @@ -60,8 +55,7 @@ bb0(%0 : $*P): // CHECK: [[T0:%.*]] = alloca [[S:%.*]], align // CHECK: [[T1:%.*]] = bitcast [[S]]* [[T0]] to [[OPAQUE:%swift.opaque]]* // CHECK: [[T2:%.*]] = bitcast [[P:%.*]]* {{%.*}} to [[OPAQUE]]* - // CHECK: [[T3:%.*]] = call swiftcc %swift.metadata_response @"$s12dynamic_cast1P_pMa"([[INT]] 0) - // CHECK: [[T4:%.*]] = extractvalue %swift.metadata_response [[T3]], 0 + // CHECK: [[T4:%.*]] = call {{.*}}@"$s12dynamic_cast1P_pMD" // CHECK: [[T5:%.*]] = call i1 @swift_dynamicCast([[OPAQUE]]* [[T1]], [[OPAQUE]]* [[T2]], %swift.type* [[T4]], %swift.type* {{.*}}, [[INT]] 6) // CHECK: br i1 [[T5]], %1 = alloc_stack $S @@ -83,8 +77,7 @@ bb0(%0 : $*P): // CHECK: [[T0:%.*]] = alloca [[S:%.*]], align // CHECK: [[T1:%.*]] = bitcast [[S]]* [[T0]] to [[OPAQUE:%swift.opaque]]* // CHECK: [[T2:%.*]] = bitcast [[P:%.*]]* {{%.*}} to [[OPAQUE]]* - // CHECK: [[T3:%.*]] = call swiftcc %swift.metadata_response @"$s12dynamic_cast1P_pMa"([[INT]] 0) - // CHECK: [[T4:%.*]] = extractvalue %swift.metadata_response [[T3]], 0 + // CHECK: [[T4:%.*]] = call {{.*}}@"$s12dynamic_cast1P_pMD" // CHECK: [[T5:%.*]] = call i1 @swift_dynamicCast([[OPAQUE]]* [[T1]], [[OPAQUE]]* [[T2]], %swift.type* [[T4]], %swift.type* {{.*}}, [[INT]] 2) // CHECK: br i1 [[T5]], %1 = alloc_stack $S @@ -106,8 +99,7 @@ bb0(%0 : $*P): // CHECK: [[T0:%.*]] = alloca [[S:%.*]], align // CHECK: [[T1:%.*]] = bitcast [[S]]* [[T0]] to [[OPAQUE:%swift.opaque]]* // CHECK: [[T2:%.*]] = bitcast [[P:%.*]]* {{%.*}} to [[OPAQUE]]* - // CHECK: [[T3:%.*]] = call swiftcc %swift.metadata_response @"$s12dynamic_cast1P_pMa"([[INT]] 0) - // CHECK: [[T4:%.*]] = extractvalue %swift.metadata_response [[T3]], 0 + // CHECK: [[T4:%.*]] = call {{.*}}@"$s12dynamic_cast1P_pMD" // CHECK: [[T5:%.*]] = call i1 @swift_dynamicCast([[OPAQUE]]* [[T1]], [[OPAQUE]]* [[T2]], %swift.type* [[T4]], %swift.type* {{.*}}, [[INT]] 0) // CHECK: br i1 [[T5]], %1 = alloc_stack $S diff --git a/test/IRGen/error_self_conformance.sil b/test/IRGen/error_self_conformance.sil index d48bbc554e2dd..0ed107914fa6e 100644 --- a/test/IRGen/error_self_conformance.sil +++ b/test/IRGen/error_self_conformance.sil @@ -8,8 +8,7 @@ sil @take_any_error : $@convention(thin) (@in T) -> () sil @test : $@convention(thin) (@in Error) -> () { entry(%0 : $*Error): // CHECK: [[VALUE:%.*]] = bitcast %swift.error** %0 to %swift.opaque* - // CHECK-NEXT: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$ss5Error_pMa"([[INT]] 0) - // CHECK-NEXT: [[ERROR_METADATA:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 + // CHECK-NEXT: [[ERROR_METADATA:%.*]] = call {{.*}}@"$ss5Error_pMD" // CHECK-NEXT: call swiftcc void @take_any_error(%swift.opaque* noalias nocapture [[VALUE]], %swift.type* [[ERROR_METADATA]], i8** @"$ss5ErrorWS") // CHECK-NEXT: ret void %take = function_ref @take_any_error : $@convention(thin) (@in T) -> () diff --git a/test/IRGen/foreign_types.sil b/test/IRGen/foreign_types.sil index 7aa3e1a0a18fc..0f67dbe105044 100644 --- a/test/IRGen/foreign_types.sil +++ b/test/IRGen/foreign_types.sil @@ -36,8 +36,3 @@ bb0: return %ret : $() } -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$sSo14HasNestedUnionVMa"( -// CHECK: call swiftcc %swift.metadata_response @swift_getForeignTypeMetadata([[INT]] %0, {{.*}}@"$sSo14HasNestedUnionVMf" - -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$sSo12AmazingColorVMa"( -// CHECK: call swiftcc %swift.metadata_response @swift_getForeignTypeMetadata([[INT]] %0, {{.*}}@"$sSo12AmazingColorVMf" diff --git a/test/IRGen/function_metadata.swift b/test/IRGen/function_metadata.swift deleted file mode 100644 index 91731db826dc8..0000000000000 --- a/test/IRGen/function_metadata.swift +++ /dev/null @@ -1,62 +0,0 @@ -// RUN: %target-swift-frontend -emit-ir -primary-file %s | %FileCheck %s - -func arch(_ f: F) {} - -// CHECK: define hidden swiftcc void @"$s17function_metadata9test_archyyF"() -func test_arch() { - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$syycMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata0([[WORD:i(32|64)]] 67108864, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch( {() -> () in } ) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySicMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata1([[WORD:i(32|64)]] 67108865, %swift.type* @"$sSiN", %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) {{#[0-9]+}} - arch({(x: Int) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$syyt_tcMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata1([[WORD]] 67108865, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1), %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch({(_: ()) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySizcMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata([[WORD]] 100663297, %swift.type** {{%.*}}, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @parameter-flags, i32 0, i32 0), %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch({(x: inout Int) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySi_Sft_tcMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata1([[WORD]] 67108865, %swift.type* {{%.*}}, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch({(x: (Int, Float)) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySiz_SitcMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata([[WORD]] 100663298, %swift.type** {{%.*}}, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @parameter-flags.16, i32 0, i32 0), %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch({(x: inout Int, y: Int) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySf_SitcMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata2([[WORD]] 67108866, %swift.type* @"$sSfN", %swift.type* @"$sSiN", %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch({(a: Float, b: Int) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySiz_SfSStcMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata([[WORD]] 100663299, %swift.type** {{%.*}}, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @parameter-flags.23, i32 0, i32 0), %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch({(x: inout Int, y: Float, z: String) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySf_SfSitcMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata3([[WORD]] 67108867, %swift.type* @"$sSfN", %swift.type* @"$sSfN", %swift.type* @"$sSiN", %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch({(a: Float, b: Float, c: Int) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySiz_SdSSs4Int8VtcMa" - // CHECK: getelementptr inbounds [4 x %swift.type*], [4 x %swift.type*]* %function-parameters, i32 0, i32 0 - // CHECK: store %swift.type* @"$sSiN", %swift.type** [[T:%.*]], align [[ALIGN:(4|8)]] - // CHECK: getelementptr inbounds [4 x %swift.type*], [4 x %swift.type*]* %function-parameters, i32 0, i32 1 - // CHECK: store %swift.type* @"$sSdN", %swift.type** [[T:%.*]], align [[ALIGN:(4|8)]] - // CHECK: getelementptr inbounds [4 x %swift.type*], [4 x %swift.type*]* %function-parameters, i32 0, i32 2 - // CHECK: store %swift.type* @"$sSSN", %swift.type** [[T:%.*]], align [[ALIGN:(4|8)]] - // CHECK: getelementptr inbounds [4 x %swift.type*], [4 x %swift.type*]* %function-parameters, i32 0, i32 3 - // CHECK: store %swift.type* @"$ss4Int8VN", %swift.type** [[T:%.*]], align [[ALIGN:(4|8)]] - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata([[WORD]] 100663300, %swift.type** {{%.*}}, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @parameter-flags.{{.*}}, i32 0, i32 0), %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) - arch({(x: inout Int, y: Double, z: String, w: Int8) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$syyyccMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata1([[WORD]] 67108865 - arch({(x: @escaping () -> ()) -> () in }) - - // CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySiyXKcMa" - // CHECK: call %swift.type* @swift_getFunctionTypeMetadata([[WORD]] 100663297 - arch({(x: @autoclosure () -> Int) -> Void in }) -} diff --git a/test/IRGen/generic_casts.swift b/test/IRGen/generic_casts.swift index 2c4f61d5f871b..8bff135238236 100644 --- a/test/IRGen/generic_casts.swift +++ b/test/IRGen/generic_casts.swift @@ -97,8 +97,7 @@ func classExistentialToOpaqueArchetype(_ x: ObjCProto1) -> T { // CHECK: [[X:%.*]] = alloca %T13generic_casts10ObjCProto1P // CHECK: [[LOCAL:%.*]] = alloca %T13generic_casts10ObjCProto1P // CHECK: [[LOCAL_OPAQUE:%.*]] = bitcast %T13generic_casts10ObjCProto1P* [[LOCAL]] to %swift.opaque* - // CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s13generic_casts10ObjCProto1_pMa"(i64 0) - // CHECK: [[PROTO_TYPE:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 + // CHECK: [[PROTO_TYPE:%.*]] = call {{.*}}@"$s13generic_casts10ObjCProto1_pMD" // CHECK: call i1 @swift_dynamicCast(%swift.opaque* %0, %swift.opaque* [[LOCAL_OPAQUE]], %swift.type* [[PROTO_TYPE]], %swift.type* %T, i64 7) return x as! T } diff --git a/test/IRGen/generic_metatypes.swift b/test/IRGen/generic_metatypes.swift index 0b236f0e5c210..20604d2fd9ec4 100644 --- a/test/IRGen/generic_metatypes.swift +++ b/test/IRGen/generic_metatypes.swift @@ -38,8 +38,8 @@ func remapToSubstitutedMetatypes(_ x: Foo, y: Bar) -> (Foo.Type, Bar.Type) { // CHECK: call swiftcc %swift.type* [[GENERIC_TYPEOF]](%swift.opaque* noalias nocapture undef, %swift.type* {{.*}} @"$s17generic_metatypes3FooVMf", {{.*}}) - // CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s17generic_metatypes3BarCMa"([[INT]] 0) - // CHECK: [[BAR:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 + // CHECK: [[BAR_REQUEST:%.*]] = call {{.*}}@"$s17generic_metatypes3BarCMa" + // CHECK: [[BAR:%.*]] = extractvalue {{.*}} [[BAR_REQUEST]] // CHECK: [[BAR_META:%.*]] = call swiftcc %swift.type* [[GENERIC_TYPEOF]](%swift.opaque* noalias nocapture {{%.*}}, %swift.type* [[BAR]]) // CHECK: ret %swift.type* [[BAR_META]] return (genericTypeof(x), genericTypeof(y)) @@ -48,8 +48,8 @@ func remapToSubstitutedMetatypes(_ x: Foo, y: Bar) // CHECK-LABEL: define hidden swiftcc void @"$s17generic_metatypes23remapToGenericMetatypesyyF"() func remapToGenericMetatypes() { - // CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s17generic_metatypes3BarCMa"([[INT]] 0) - // CHECK: [[BAR:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 + // CHECK: [[BAR_REQUEST:%.*]] = call {{.*}}@"$s17generic_metatypes3BarCMa" + // CHECK: [[BAR:%.*]] = extractvalue {{.*}} [[BAR_REQUEST]] // CHECK: call swiftcc void @"$s17generic_metatypes0A9Metatypes{{.*}}"(%swift.type* {{.*}} @"$s17generic_metatypes3FooVMf", {{.*}} %swift.type* [[BAR]], %swift.type* {{.*}} @"$s17generic_metatypes3FooVMf", {{.*}} %swift.type* [[BAR]]) genericMetatypes(Foo.self, Bar.self) } @@ -101,25 +101,22 @@ func genericMetatype(_ x: A.Type) {} // CHECK-LABEL: define hidden swiftcc void @"$s17generic_metatypes20makeGenericMetatypesyyF"() {{.*}} { func makeGenericMetatypes() { - // CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes6OneArgVyAA3FooVGMa"([[INT]] 0) [[NOUNWIND_READNONE:#[0-9]+]] + // CHECK: call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s17generic_metatypes6OneArgVyAA3FooVGMD") [[NOUNWIND_READNONE:#[0-9]+]] genericMetatype(OneArg.self) - // CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes7TwoArgsVyAA3FooVAA3BarCGMa"([[INT]] 0) [[NOUNWIND_READNONE]] + // CHECK: call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s17generic_metatypes7TwoArgsVyAA3FooVAA3BarCGMD") [[NOUNWIND_READNONE]] genericMetatype(TwoArgs.self) - // CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes9ThreeArgsVyAA3FooVAA3BarCAEGMa"([[INT]] 0) [[NOUNWIND_READNONE]] + // CHECK: call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s17generic_metatypes9ThreeArgsVyAA3FooVAA3BarCAEGMD") [[NOUNWIND_READNONE]] genericMetatype(ThreeArgs.self) - // CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes8FourArgsVyAA3FooVAA3BarCAeGGMa"([[INT]] 0) [[NOUNWIND_READNONE]] + // CHECK: call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s17generic_metatypes8FourArgsVyAA3FooVAA3BarCAeGGMD") [[NOUNWIND_READNONE]] genericMetatype(FourArgs.self) - // CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes8FiveArgsVyAA3FooVAA3BarCAegEGMa"([[INT]] 0) [[NOUNWIND_READNONE]] + // CHECK: call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s17generic_metatypes8FiveArgsVyAA3FooVAA3BarCAegEGMD") [[NOUNWIND_READNONE]] genericMetatype(FiveArgs.self) } -// CHECK: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s17generic_metatypes6OneArgVyAA3FooVGMa"([[INT]]) [[NOUNWIND_READNONE_OPT:#[0-9]+]] -// CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes6OneArgVMa"([[INT]] %0, %swift.type* {{.*}} @"$s17generic_metatypes3FooVMf", {{.*}}) [[NOUNWIND_READNONE:#[0-9]+]] - // CHECK-LABEL: define hidden swiftcc %swift.metadata_response @"$s17generic_metatypes6OneArgVMa" // CHECK-SAME: ([[INT]], %swift.type*) // CHECK: [[BUFFER:%.*]] = alloca { %swift.type* } @@ -131,12 +128,6 @@ func makeGenericMetatypes() { // CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @swift_getGenericMetadata([[INT]] %0, i8* [[BUFFER_PTR]], %swift.type_descriptor* {{.*}} @"$s17generic_metatypes6OneArgVMn" {{.*}}) // CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s17generic_metatypes7TwoArgsVyAA3FooVAA3BarCGMa" -// CHECK-SAME: ([[INT]]) [[NOUNWIND_READNONE_OPT]] -// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s17generic_metatypes3BarCMa"([[INT]] 255) -// CHECK: [[BAR:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 -// CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes7TwoArgsVMa"([[INT]] %0, %swift.type* {{.*}} @"$s17generic_metatypes3FooVMf", {{.*}}, %swift.type* [[BAR]]) - // CHECK-LABEL: define hidden swiftcc %swift.metadata_response @"$s17generic_metatypes7TwoArgsVMa" // CHECK-SAME: ([[INT]], %swift.type*, %swift.type*) // CHECK: [[BUFFER:%.*]] = alloca { %swift.type*, %swift.type* } @@ -150,12 +141,6 @@ func makeGenericMetatypes() { // CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @swift_getGenericMetadata([[INT]] %0, i8* [[BUFFER_PTR]], %swift.type_descriptor* {{.*}} @"$s17generic_metatypes7TwoArgsVMn" {{.*}}) // CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s17generic_metatypes9ThreeArgsVyAA3FooVAA3BarCAEGMa" -// CHECK-SAME: ([[INT]]) [[NOUNWIND_READNONE_OPT]] -// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s17generic_metatypes3BarCMa"([[INT]] 255) -// CHECK: [[BAR:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 -// CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes9ThreeArgsVMa"([[INT]] %0, %swift.type* {{.*}} @"$s17generic_metatypes3FooVMf", {{.*}}, %swift.type* [[BAR]], %swift.type* {{.*}} @"$s17generic_metatypes3FooVMf", {{.*}}) [[NOUNWIND_READNONE]] - // CHECK-LABEL: define hidden swiftcc %swift.metadata_response @"$s17generic_metatypes9ThreeArgsVMa" // CHECK-SAME: ({{i[0-9]+}}, %swift.type*, %swift.type*, %swift.type*) // CHECK: [[BUFFER:%.*]] = alloca { %swift.type*, %swift.type*, %swift.type* } @@ -171,32 +156,6 @@ func makeGenericMetatypes() { // CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @swift_getGenericMetadata([[INT]] %0, i8* [[BUFFER_PTR]], %swift.type_descriptor* {{.*}} @"$s17generic_metatypes9ThreeArgsVMn" {{.*}}) // CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s17generic_metatypes8FourArgsVyAA3FooVAA3BarCAeGGMa" -// CHECK-SAME: ([[INT]]) [[NOUNWIND_READNONE_OPT]] -// CHECK: [[BUFFER:%.*]] = alloca [4 x i8*] -// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s17generic_metatypes3BarCMa"([[INT]] 255) -// CHECK: [[BAR:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 -// CHECK: call void @llvm.lifetime.start -// CHECK-NEXT: [[SLOT_0:%.*]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BUFFER]], i32 0, i32 0 -// CHECK-NEXT: store {{.*}}@"$s17generic_metatypes3FooVMf"{{.*}}, i8** [[SLOT_0]] -// CHECK-NEXT: [[SLOT_1:%.*]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BUFFER]], i32 0, i32 1 -// CHECK-NEXT: [[T0:%.*]] = bitcast %swift.type* [[BAR]] to i8* -// CHECK-NEXT: store i8* [[T0]], i8** [[SLOT_1]] -// CHECK-NEXT: [[SLOT_2:%.*]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BUFFER]], i32 0, i32 2 -// CHECK-NEXT: store {{.*}}@"$s17generic_metatypes3FooVMf"{{.*}}, i8** [[SLOT_2]] -// CHECK-NEXT: [[SLOT_3:%.*]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BUFFER]], i32 0, i32 3 -// CHECK-NEXT: [[T0:%.*]] = bitcast %swift.type* [[BAR]] to i8* -// CHECK-NEXT: store i8* [[T0]], i8** [[SLOT_3]] -// CHECK-NEXT: [[BUFFER_PTR:%.*]] = bitcast [4 x i8*]* [[BUFFER]] to i8** -// CHECK-NEXT: call swiftcc %swift.metadata_response @"$s17generic_metatypes8FourArgsVMa"([[INT]] %0, i8** [[BUFFER_PTR]]) [[NOUNWIND_ARGMEM:#[0-9]+]] -// CHECK: call void @llvm.lifetime.end.p0i8 - -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s17generic_metatypes8FiveArgsVyAA3FooVAA3BarCAegEGMa" -// CHECK-SAME: ([[INT]]) [[NOUNWIND_READNONE_OPT]] -// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s17generic_metatypes3BarCMa"([[INT]] 255) -// CHECK: [[BAR:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 -// CHECK: call swiftcc %swift.metadata_response @"$s17generic_metatypes8FiveArgsVMa"([[INT]] %0, i8** - // CHECK-LABEL: define hidden swiftcc %swift.metadata_response @"$s17generic_metatypes8FiveArgsVMa" // CHECK-SAME: ([[INT]], i8**) [[NOUNWIND_OPT:#[0-9]+]] // CHECK-NOT: alloc @@ -204,7 +163,5 @@ func makeGenericMetatypes() { // CHECK-NOT: call void @llvm.lifetime.end // CHECK: ret %swift.metadata_response -// CHECK: attributes [[NOUNWIND_READNONE_OPT]] = { nounwind readnone "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "target-cpu" -// CHECK: attributes [[NOUNWIND_OPT]] = { nounwind "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "target-cpu" // CHECK: attributes [[NOUNWIND_READNONE]] = { nounwind readnone } -// CHECK: attributes [[NOUNWIND_ARGMEM]] = { inaccessiblemem_or_argmemonly nounwind } +// CHECK: attributes [[NOUNWIND_OPT]] = { noinline nounwind "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "target-cpu" diff --git a/test/IRGen/generic_tuples.swift b/test/IRGen/generic_tuples.swift index f1a7b00b7c184..84e5e5965a540 100644 --- a/test/IRGen/generic_tuples.swift +++ b/test/IRGen/generic_tuples.swift @@ -62,8 +62,8 @@ func dupC(_ x: T) -> (T, T) { return (x, x) } func callDupC(_ c: C) { _ = dupC(c) } // CHECK-LABEL: define hidden swiftcc void @"$s14generic_tuples8callDupCyyAA1CCF"(%T14generic_tuples1CC*) // CHECK-NEXT: entry: -// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s14generic_tuples1CCMa"(i64 0) -// CHECK-NEXT: [[METATYPE:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 +// CHECK: [[REQUEST:%.*]] = call {{.*}} @"$s14generic_tuples1CCMa" +// CHECK-NEXT: [[METATYPE:%.*]] = extractvalue {{.*}} [[REQUEST]] // CHECK-NEXT: [[TUPLE:%.*]] = call swiftcc { %T14generic_tuples1CC*, %T14generic_tuples1CC* } @"$s14generic_tuples4dupCyx_xtxAA1CCRbzlF"(%T14generic_tuples1CC* %0, %swift.type* [[METATYPE]]) // CHECK-NEXT: [[LEFT:%.*]] = extractvalue { %T14generic_tuples1CC*, %T14generic_tuples1CC* } [[TUPLE]], 0 // CHECK-NEXT: [[RIGHT:%.*]] = extractvalue { %T14generic_tuples1CC*, %T14generic_tuples1CC* } [[TUPLE]], 1 @@ -90,26 +90,3 @@ func unlump2(_ x: (T, Int, T)) -> T { return x.0 } func unlump3(_ x: (T, Int, T)) -> Int { return x.1 } -// CHECK: tuple_existentials -func tuple_existentials() { - // Empty tuple: - var a : Any = () - // CHECK: store %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1), - - // 2 element tuple - var t2 = (1,2.0) - a = t2 - // CHECK: call swiftcc %swift.metadata_response @swift_getTupleTypeMetadata2(i64 %0, {{.*}}@"$sSiN{{.*}}",{{.*}}@"$sSdN{{.*}}", i8* null, i8** null) - - - // 3 element tuple - var t3 = ((),(),()) - a = t3 - // CHECK: call swiftcc %swift.metadata_response @swift_getTupleTypeMetadata3(i64 %0, {{.*}}@"$sytN{{.*}},{{.*}}@"$sytN{{.*}},{{.*}}@"$sytN{{.*}}, i8* null, i8** null) - - // 4 element tuple - var t4 = (1,2,3,4) - a = t4 - // CHECK: call swiftcc %swift.metadata_response @swift_getTupleTypeMetadata(i64 %0, i64 4, {{.*}}, i8* null, i8** null) -} - diff --git a/test/IRGen/lazy_globals.swift b/test/IRGen/lazy_globals.swift index 6083d615bf0a1..ce0f387d9e485 100644 --- a/test/IRGen/lazy_globals.swift +++ b/test/IRGen/lazy_globals.swift @@ -18,19 +18,16 @@ // CHECK: define hidden swiftcc i8* @"$s12lazy_globals1xSivau"() {{.*}} { // CHECK: entry: // CHECK: call void @swift_once(i64* @globalinit_[[T]]_token0, i8* bitcast (void ()* @globalinit_[[T]]_func0 to i8*), i8* undef) -// CHECK: ret i8* bitcast (%TSi* @"$s12lazy_globals1xSivp" to i8*) // CHECK: } // CHECK: define hidden swiftcc i8* @"$s12lazy_globals1ySivau"() {{.*}} { // CHECK: entry: // CHECK: call void @swift_once(i64* @globalinit_[[T]]_token0, i8* bitcast (void ()* @globalinit_[[T]]_func0 to i8*), i8* undef) -// CHECK: ret i8* bitcast (%TSi* @"$s12lazy_globals1ySivp" to i8*) // CHECK: } // CHECK: define hidden swiftcc i8* @"$s12lazy_globals1zSivau"() {{.*}} { // CHECK: entry: // CHECK: call void @swift_once(i64* @globalinit_[[T]]_token0, i8* bitcast (void ()* @globalinit_[[T]]_func0 to i8*), i8* undef) -// CHECK: ret i8* bitcast (%TSi* @"$s12lazy_globals1zSivp" to i8*) // CHECK: } var (x, y, z) = (1, 2, 3) diff --git a/test/IRGen/metadata_dominance.swift b/test/IRGen/metadata_dominance.swift index 78e24c65e84be..3f878c3dd4d5e 100644 --- a/test/IRGen/metadata_dominance.swift +++ b/test/IRGen/metadata_dominance.swift @@ -12,23 +12,21 @@ func cond() -> Bool { return true } func test1() { // CHECK: call swiftcc i1 @"$s18metadata_dominance4condSbyF"() if cond() { -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$syycMa"([[INT]] 0) -// CHECK: [[T0:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 +// CHECK: [[T0:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$syycMD") // CHECK: call swiftcc void @"$s18metadata_dominance04use_A0yyxlF"(%swift.opaque* {{.*}}, %swift.type* [[T0]]) use_metadata(voidToVoid) // CHECK: call swiftcc i1 @"$s18metadata_dominance4condSbyF"() -// CHECK-NOT: @"$syycMa" +// CHECK-NOT: @"$syycMD" // CHECK: call swiftcc void @"$s18metadata_dominance04use_A0yyxlF"(%swift.opaque* {{.*}}, %swift.type* [[T0]]) if cond() { use_metadata(voidToVoid) } else { -// CHECK-NOT: @"$syycMa" +// CHECK-NOT: @"$syycMD" // CHECK: call swiftcc void @"$s18metadata_dominance04use_A0yyxlF"(%swift.opaque* {{.*}}, %swift.type* [[T0]]) use_metadata(voidToVoid) } } -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$syycMa"([[INT]] 0) -// CHECK: [[T1:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 +// CHECK: [[T1:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$syycMD") // CHECK: call swiftcc void @"$s18metadata_dominance04use_A0yyxlF"(%swift.opaque* {{.*}}, %swift.type* [[T1]]) use_metadata(voidToVoid) } @@ -38,20 +36,17 @@ func test2() { // CHECK: call swiftcc i1 @"$s18metadata_dominance4condSbyF"() if cond() { // CHECK: call swiftcc i1 @"$s18metadata_dominance4condSbyF"() -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$syycMa"([[INT]] 0) -// CHECK: [[T0:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 +// CHECK: [[T0:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$syycMD") // CHECK: call swiftcc void @"$s18metadata_dominance04use_A0yyxlF"(%swift.opaque* {{.*}}, %swift.type* [[T0]]) if cond() { use_metadata(voidToVoid) } else { -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$syycMa"([[INT]] 0) -// CHECK: [[T1:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 +// CHECK: [[T1:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$syycMD") // CHECK: call swiftcc void @"$s18metadata_dominance04use_A0yyxlF"(%swift.opaque* {{.*}}, %swift.type* [[T1]]) use_metadata(voidToVoid) } } -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$syycMa"([[INT]] 0) -// CHECK: [[T2:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 +// CHECK: [[T2:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$syycMD") // CHECK: call swiftcc void @"$s18metadata_dominance04use_A0yyxlF"(%swift.opaque* {{.*}}, %swift.type* [[T2]]) use_metadata(voidToVoid) } diff --git a/test/IRGen/nested_generics.swift b/test/IRGen/nested_generics.swift index 4b35efbbbc56c..c6f2eb45e433c 100644 --- a/test/IRGen/nested_generics.swift +++ b/test/IRGen/nested_generics.swift @@ -15,19 +15,12 @@ public func makeAMetadata() { blah(OuterGenericClass.InnerConcreteClass.self) } -// Type constructor for OuterGenericStruct.InnerGenericStruct -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s15nested_generics18OuterGenericStructV05InnerdE0VySi_SSGMa"(i64) -// CHECK: call swiftcc %swift.metadata_response @"$s15nested_generics18OuterGenericStructV05InnerdE0VMa"(i64 %0, %swift.type* @"$sSiN", %swift.type* @"$sSSN") -// CHECK: ret %swift.metadata_response +// Type constructor for OuterGenericStruct +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.metadata_response @"$s15nested_generics18OuterGenericStructVMa"(i64, %swift.type*) // Type constructor for OuterGenericStruct.InnerGenericStruct // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.metadata_response @"$s15nested_generics18OuterGenericStructV05InnerdE0VMa"(i64, %swift.type*, %swift.type*) -// Type constructor for OuterGenericStruct.InnerConcreteStruct -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s15nested_generics18OuterGenericStructV013InnerConcreteE0VySi_GMa"(i64) -// CHECK: call swiftcc %swift.metadata_response @"$s15nested_generics18OuterGenericStructV013InnerConcreteE0VMa"(i64 %0, %swift.type* @"$sSiN") -// CHECK: ret %swift.metadata_response - // Type constructor for OuterGenericStruct.InnerConcreteStruct // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.metadata_response @"$s15nested_generics18OuterGenericStructV013InnerConcreteE0VMa"(i64, %swift.type*) @@ -46,27 +39,15 @@ public struct OuterGenericStruct { } } -// Type constructor for OuterGenericClass.InnerGenericClass -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s15nested_generics17OuterGenericClassC05InnerdE0CySi_SSGMa"(i64) -// CHECK: call swiftcc %swift.metadata_response @"$s15nested_generics17OuterGenericClassC05InnerdE0CMa"(i64 %0, %swift.type* @"$sSiN", %swift.type* @"$sSSN") +// Type constructor for OuterGenericClass +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.metadata_response @"$s15nested_generics17OuterGenericClassCMa"(i64, %swift.type*) // Type constructor for OuterGenericClass.InnerGenericClass // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.metadata_response @"$s15nested_generics17OuterGenericClassC05InnerdE0CMa"(i64, %swift.type*, %swift.type*) -// Type constructor for OuterGenericClass.InnerConcreteClass -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s15nested_generics17OuterGenericClassC013InnerConcreteE0CySi_GMa"(i64) -// CHECK: call swiftcc %swift.metadata_response @"$s15nested_generics17OuterGenericClassC013InnerConcreteE0CMa"(i64 %0, %swift.type* @"$sSiN") -// CHECK: ret %swift.metadata_response - // Type constructor for OuterGenericClass.InnerConcreteClass // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.metadata_response @"$s15nested_generics17OuterGenericClassC013InnerConcreteE0CMa"(i64, %swift.type*) -// Type constructor for OuterGenericStruct -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.metadata_response @"$s15nested_generics18OuterGenericStructVMa"(i64, %swift.type*) - -// Type constructor for OuterGenericClass -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.metadata_response @"$s15nested_generics17OuterGenericClassCMa"(i64, %swift.type*) - public class OuterGenericClass { public class InnerGenericClass { public func method() { diff --git a/test/IRGen/objc_block.sil b/test/IRGen/objc_block.sil index 2b6c08bbe4fec..537cd5408951b 100644 --- a/test/IRGen/objc_block.sil +++ b/test/IRGen/objc_block.sil @@ -24,16 +24,3 @@ entry(%b : $@convention(block) (Foo) -> Foo, %x : $Foo): // CHECK: [[T5:%.*]] = bitcast i8* [[T4]] to %T10objc_block3FooC* // CHECK: ret %T10objc_block3FooC* [[T5]] // CHECK: } - -sil @generic : $@convention(thin) (@in T) -> () - -sil @generic_with_block : $@convention(thin) (@in @convention(block) () -> ()) -> () { -entry(%b : $*@convention(block) () -> ()): - %f = function_ref @generic : $@convention(thin) (@in T) -> () - %z = apply %f<@convention(block) () -> ()>(%b) : $@convention(thin) (@in T) -> () - return %z : $() -} - -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @generic_with_block(%objc_block** noalias nocapture dereferenceable({{.*}})) -// -- 0x100_0001 = block convention, 1 arg -// CHECK: call %swift.type* @swift_getFunctionTypeMetadata0([[WORD:i(32|64)]] 65536, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1)) diff --git a/test/IRGen/objc_generic_class_metadata.sil b/test/IRGen/objc_generic_class_metadata.sil index e01024c7c54ef..a1f529260fd9a 100644 --- a/test/IRGen/objc_generic_class_metadata.sil +++ b/test/IRGen/objc_generic_class_metadata.sil @@ -29,8 +29,7 @@ entry: // All instances of the generic ObjC class are erased to the same metadata // at runtime. - // CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$sSo12GenericClassCMa"([[INT]] 0) - // CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 + // CHECK: [[METADATA:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSo12GenericClassCMD") %a = metatype $@thick GenericClass.Type // CHECK: call swiftcc void @metatype_sink(%swift.type* [[METADATA]], %swift.type* [[METADATA]]) apply %z>(%a) : $@convention(thin) (@thick T.Type) -> () @@ -46,8 +45,7 @@ entry: apply %y>(%c) : $@convention(thin) (@objc_metatype T.Type) -> () // Check that generic classes are erased at depth. - // CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$sSaySo12GenericClassC_SitGMa"([[INT]] 0) - // CHECK: [[TUPLE_METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 + // CHECK: [[TUPLE_METADATA:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSaySo12GenericClassC_SitGMD") %d = metatype $@thick Array<(GenericClass, Int)>.Type // CHECK: call swiftcc void @metatype_sink(%swift.type* [[TUPLE_METADATA]], %swift.type* [[TUPLE_METADATA]]) apply %z, Int)>>(%d) : $@convention(thin) (@thick T.Type) -> () @@ -78,22 +76,6 @@ entry(%0 : $Subclass, %1 : $NSDictionary): unreachable } -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$sSo12GenericClassCMa"( -// CHECK: [[T0:%.*]] = load %objc_class*, %objc_class** @"OBJC_CLASS_REF_$_GenericClass", -// CHECK: call %objc_class* @swift_getInitializedObjCClass(%objc_class* [[T0]]) - -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$sSaySo12GenericClassC_SitGMa" -// CHECK-SAME: ([[INT]]) -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$sSo12GenericClassC_SitMa"([[INT]] 255) -// CHECK: [[TUPLE:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 -// CHECK: call swiftcc %swift.metadata_response @"$sSaMa"([[INT]] %0, %swift.type* [[TUPLE]]) - -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$sSo12GenericClassC_SitMa" -// CHECK-SAME: ([[INT]]) -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$sSo12GenericClassCMa"([[INT]] 255) -// CHECK: [[CLASS:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 -// CHECK: call swiftcc %swift.metadata_response @swift_getTupleTypeMetadata2([[INT]] %0, %swift.type* [[CLASS]], %swift.type* @"$sSiN", i8* null, - class K {} sil @$useMeta : $@convention(thin)

() -> () diff --git a/test/IRGen/objc_protocol_conversion.sil b/test/IRGen/objc_protocol_conversion.sil index 9d5e52e7f7b89..1e6581414a635 100644 --- a/test/IRGen/objc_protocol_conversion.sil +++ b/test/IRGen/objc_protocol_conversion.sil @@ -23,14 +23,3 @@ entry: %p = objc_protocol #OP : $Protocol return %p : $Protocol } - -// The Protocol class has been hidden in newer ObjC APIs, so when we need its -// metadata, we treat it like a foreign class. -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.type* @protocol_metatype() -sil @protocol_metatype : $@convention(thin) () -> @thick Protocol.Type { -entry: - // CHECK: call %objc_class* @objc_lookUpClass - // CHECK: call %swift.type* @swift_getObjCClassMetadata - %t = metatype $@thick Protocol.Type - return %t : $@thick Protocol.Type -} diff --git a/test/IRGen/objc_types_as_member.sil b/test/IRGen/objc_types_as_member.sil index a5b03a0fe1903..6d72b62786c94 100644 --- a/test/IRGen/objc_types_as_member.sil +++ b/test/IRGen/objc_types_as_member.sil @@ -9,8 +9,7 @@ import gizmo sil @use_metatype : $@convention(thin) (@thin T.Type) -> () // CHECK-LABEL: define swiftcc void @test(%TSo014OuterTypeInnerB0C* swiftself, %swift.type* %Self, i8** %SelfWitnessTable) -// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$sSo9OuterTypeCMa"([[INT]] 0) -// CHECK: [[TMP:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 +// CHECK: [[TMP:%.*]] = call {{.*}}@"$sSo9OuterTypeCMD" // CHECK: call swiftcc void @use_metatype(%swift.type* [[TMP]]) // CHECK: ret void @@ -21,9 +20,3 @@ bb0(%0 : $OuterType.InnerType): %3 = apply %1(%2) : $@convention(thin) <τ_0_0> (@thin τ_0_0.Type) -> () return %3 : $() } - -// CHECK-LABEL: define {{.*}}swiftcc %swift.metadata_response @"$sSo9OuterTypeCMa" -// CHECK-SAME: ([[INT]]) -// CHECK: [[TMP:%.*]] = call %objc_class* @swift_getInitializedObjCClass( -// CHECK: call %swift.type* @swift_getObjCClassMetadata(%objc_class* [[TMP]]) -// CHECK: ret diff --git a/test/IRGen/opaque_result_type.swift b/test/IRGen/opaque_result_type.swift index 192f989b8a60b..8fcc636fb60f7 100644 --- a/test/IRGen/opaque_result_type.swift +++ b/test/IRGen/opaque_result_type.swift @@ -162,8 +162,7 @@ public func useFoo(x: String, y: C) { // CHECK-LABEL: define {{.*}} @"$s18opaque_result_type6useFoo1x1yySS_AA1CCtF" // CHECK: [[CONFORMANCE:%.*]] = call swiftcc i8** @swift_getOpaqueTypeConformance(i8* {{.*}}, %swift.type_descriptor* {{.*}}s18opaque_result_type3baz1zQrx_tAA1PRzAA1QRzlFQOMQ{{.*}}, [[WORD:i32|i64]] 1) -// CHECK: [[MD:%.*]] = call swiftcc %swift.metadata_response @"$s18opaque_result_type3baz1zQrx_tAA1PRzAA1QRzlFQOyAA1CCQo_Ma" -// CHECK: [[TYPE:%.*]] = extractvalue %swift.metadata_response [[MD]], 0 +// CHECK: [[TYPE:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s18opaque_result_type3baz1zQrx_tAA1PRzAA1QRzlFQOyAA1CCQo_MD") // CHECK: call swiftcc i8** @swift_getAssociatedConformanceWitness(i8** [[CONFORMANCE]], %swift.type* [[TYPE]] // CHECK-LABEL: define {{.*}} @"$sSS18opaque_result_type1PAA1AAaBP_AA1OPWT" diff --git a/test/IRGen/opaque_result_type_availability.swift b/test/IRGen/opaque_result_type_availability.swift index b5fdfb74cfb5e..cb36b80538d4e 100644 --- a/test/IRGen/opaque_result_type_availability.swift +++ b/test/IRGen/opaque_result_type_availability.swift @@ -18,7 +18,5 @@ public func main() { generic(x: foo(), y: foo()) } -// MAYBE-AVAILABLE: declare{{.*}} extern_weak {{.*}} @swift_getOpaqueTypeMetadata // MAYBE-AVAILABLE: declare{{.*}} extern_weak {{.*}} @swift_getOpaqueTypeConformance -// ALWAYS-AVAILABLE-NOT: declare{{.*}} extern_weak {{.*}} @swift_getOpaqueTypeMetadata // ALWAYS-AVAILABLE-NOT: declare{{.*}} extern_weak {{.*}} @swift_getOpaqueTypeConformance diff --git a/test/IRGen/protocol_metadata.swift b/test/IRGen/protocol_metadata.swift index 193baf387bd64..64314b4f252bf 100644 --- a/test/IRGen/protocol_metadata.swift +++ b/test/IRGen/protocol_metadata.swift @@ -17,14 +17,6 @@ protocol C : class { func c() } protocol AB : A, B { func ab() } protocol ABO : A, B, O { func abo() } -// -- @objc protocol O uses ObjC symbol mangling and layout -// CHECK-LABEL: @_PROTOCOL__TtP17protocol_metadata1O_ = private constant -// CHECK-SAME: @_PROTOCOL_INSTANCE_METHODS__TtP17protocol_metadata1O_, -// -- size, flags: 1 = Swift -// CHECK-SAME: i32 96, i32 1 -// CHECK-SAME: @_PROTOCOL_METHOD_TYPES__TtP17protocol_metadata1O_ -// CHECK-SAME: } - // CHECK: [[A_NAME:@.*]] = private constant [2 x i8] c"A\00" // CHECK-LABEL: @"$s17protocol_metadata1AMp" = hidden constant @@ -59,6 +51,14 @@ protocol ABO : A, B, O { func abo() } // CHECK-SAME: i32 0 // CHECK-SAME: } +// -- @objc protocol O uses ObjC symbol mangling and layout +// CHECK-LABEL: @_PROTOCOL__TtP17protocol_metadata1O_ = private constant +// CHECK-SAME: @_PROTOCOL_INSTANCE_METHODS__TtP17protocol_metadata1O_, +// -- size, flags: 1 = Swift +// CHECK-SAME: i32 96, i32 1 +// CHECK-SAME: @_PROTOCOL_METHOD_TYPES__TtP17protocol_metadata1O_ +// CHECK-SAME: } + // -- @objc protocol OPT uses ObjC symbol mangling and layout // CHECK: @_PROTOCOL__TtP17protocol_metadata3OPT_ = private constant { {{.*}} i32, [4 x i8*]*, i8*, i8* } { // CHECK-SAME: @_PROTOCOL_INSTANCE_METHODS_OPT__TtP17protocol_metadata3OPT_, @@ -117,29 +117,3 @@ protocol Comprehensive { // CHECK-SAME: %swift.protocol_requirement { i32 4, i32 0 }, // CHECK-SAME: %swift.protocol_requirement { i32 6, i32 0 } - -func reify_metadata(_ x: T) {} - -// CHECK: define hidden swiftcc void @"$s17protocol_metadata0A6_types{{[_0-9a-zA-Z]*}}F" -func protocol_types(_ a: A, - abc: A & B & C, - abco: A & B & C & O) { - // CHECK: store [[INT]] ptrtoint ({{.*}} @"$s17protocol_metadata1AMp" to [[INT]]) - // CHECK: call %swift.type* @swift_getExistentialTypeMetadata(i1 true, %swift.type* null, i64 1, [[INT]]* {{%.*}}) - reify_metadata(a) - // CHECK: store [[INT]] ptrtoint ({{.*}} @"$s17protocol_metadata1AMp" - // CHECK: store [[INT]] ptrtoint ({{.*}} @"$s17protocol_metadata1BMp" - // CHECK: store [[INT]] ptrtoint ({{.*}} @"$s17protocol_metadata1CMp" - // CHECK: call %swift.type* @swift_getExistentialTypeMetadata(i1 false, %swift.type* null, i64 3, [[INT]]* {{%.*}}) - reify_metadata(abc) - // CHECK: store [[INT]] ptrtoint ({{.*}} @"$s17protocol_metadata1AMp" - // CHECK: store [[INT]] ptrtoint ({{.*}} @"$s17protocol_metadata1BMp" - // CHECK: store [[INT]] ptrtoint ({{.*}} @"$s17protocol_metadata1CMp" - // CHECK: [[O_REF:%.*]] = load i8*, i8** @"\01l_OBJC_PROTOCOL_REFERENCE_$__TtP17protocol_metadata1O_" - // CHECK: [[O_REF_INT:%.*]] = ptrtoint i8* [[O_REF]] to [[INT]] - // CHECK: [[O_REF_DESCRIPTOR:%.*]] = or [[INT]] [[O_REF_INT]], 1 - // CHECK: store [[INT]] [[O_REF_DESCRIPTOR]] - // CHECK: call %swift.type* @swift_getExistentialTypeMetadata(i1 false, %swift.type* null, i64 4, [[INT]]* {{%.*}}) - reify_metadata(abco) -} - diff --git a/test/IRGen/signature_conformances_multifile.swift b/test/IRGen/signature_conformances_multifile.swift index 2a61ef465b138..04467441de505 100644 --- a/test/IRGen/signature_conformances_multifile.swift +++ b/test/IRGen/signature_conformances_multifile.swift @@ -6,10 +6,9 @@ // CHECK-LABEL: define hidden swiftcc void @"$s32signature_conformances_multifile5passQyyF"() func passQ() { // CHECK: call swiftcc void @"$s32signature_conformances_multifile12AlsoConformsVACyxGycfC"(%swift.type* @"$sSiN") - // CHECK: %0 = call swiftcc %swift.metadata_response @"$s32signature_conformances_multifile12AlsoConformsVySiGMa" - // CHECK: %1 = extractvalue %swift.metadata_response %0 - // CHECK: %2 = call i8** @"$s32signature_conformances_multifile12AlsoConformsVySiGACyxGAA1QAAWl"() - // CHECK: call swiftcc void @"$s32signature_conformances_multifile6takesQyyxAA1QRzlF"(%swift.opaque* noalias nocapture undef, %swift.type* %1, i8** %2) + // CHECK: %0 = call {{.*}} @"$s32signature_conformances_multifile12AlsoConformsVySiGMD" + // CHECK: %1 = call i8** @"$s32signature_conformances_multifile12AlsoConformsVySiGACyxGAA1QAAWl"() + // CHECK: call swiftcc void @"$s32signature_conformances_multifile6takesQyyxAA1QRzlF"(%swift.opaque* noalias nocapture undef, %swift.type* %0, i8** %1) takesQ(AlsoConforms()) // CHECK: ret void @@ -18,10 +17,9 @@ func passQ() { // CHECK-LABEL: define hidden swiftcc void @"$s32signature_conformances_multifile5passPyyF"() func passP() { // CHECK: call swiftcc void @"$s32signature_conformances_multifile8ConformsVACyxq_GycfC"(%swift.type* @"$sSiN", %swift.type* @"$sSSN") - // CHECK: %0 = call swiftcc %swift.metadata_response @"$s32signature_conformances_multifile8ConformsVySiSSGMa" - // CHECK: %1 = extractvalue %swift.metadata_response %0 - // CHECK: %2 = call i8** @"$s32signature_conformances_multifile8ConformsVySiSSGACyxq_GAA1PAAWl"() - // CHECK: call swiftcc void @"$s32signature_conformances_multifile6takesPyyxAA1PRzlF"(%swift.opaque* noalias nocapture undef, %swift.type* %1, i8** %2) + // CHECK: %0 = call {{.*}} @"$s32signature_conformances_multifile8ConformsVySiSSGMD" + // CHECK: %1 = call i8** @"$s32signature_conformances_multifile8ConformsVySiSSGACyxq_GAA1PAAWl"() + // CHECK: call swiftcc void @"$s32signature_conformances_multifile6takesPyyxAA1PRzlF"(%swift.opaque* noalias nocapture undef, %swift.type* %0, i8** %1) takesP(Conforms()) // CHECK: ret void diff --git a/test/IRGen/subclass.swift b/test/IRGen/subclass.swift index 447317e74f567..d7bcd7a06880b 100644 --- a/test/IRGen/subclass.swift +++ b/test/IRGen/subclass.swift @@ -63,7 +63,7 @@ class G : A { // CHECK: define hidden swiftcc %T8subclass1GCySiG* @"$s8subclass9a_to_gint1aAA1GCySiGAA1AC_tF"(%T8subclass1AC*) {{.*}} { func a_to_gint(a: A) -> G { - // CHECK: call swiftcc %swift.metadata_response @"$s8subclass1GCySiGMa"(i64 0) + // CHECK: call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s8subclass1GCySiGMD") // CHECK: call i8* @swift_dynamicCastClassUnconditional return a as! G } diff --git a/test/IRGen/subclass_existentials.sil b/test/IRGen/subclass_existentials.sil index b60254bce1d59..b2f50de2f9bf2 100644 --- a/test/IRGen/subclass_existentials.sil +++ b/test/IRGen/subclass_existentials.sil @@ -41,25 +41,10 @@ sil @takesMetadata : $@convention(thin) (@thick T.Type) -> () // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @checkMetadata() // CHECK-NEXT: entry: -// CHECK-NEXT: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s21subclass_existentials1P_AA1CCXcMa"([[INT]] 0) -// CHECK-NEXT: [[TYPE:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 +// CHECK-NEXT: [[TYPE:%.*]] = call {{.*}}@"$s21subclass_existentials1P_AA1CCXcMD" // CHECK-NEXT: call swiftcc void @takesMetadata(%swift.type* [[TYPE]], %swift.type* [[TYPE]]) // CHECK-NEXT: ret void -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s21subclass_existentials1P_AA1CCXcMa" -// CHECK-SAME: ([[INT]]) -// CHECK: entry: -// CHECK-NEXT: [[PROTOCOL_ARRAY:%.*]] = alloca [1 x [[INT]]] -// CHECK: cacheIsNull: -// CHECK: [[PROTOCOLS:%.*]] = bitcast [1 x [[INT]]]* [[PROTOCOL_ARRAY]] to [[INT]]* -// CHECK-NEXT: [[PROTOCOL:%.*]] = getelementptr inbounds [[INT]], [[INT]]* [[PROTOCOLS]], i32 0 -// CHECK-NEXT: store [[INT]] ptrtoint ({{.*}} @"$s21subclass_existentials1PMp" to [[INT]]), [[INT]]* [[PROTOCOL]] -// CHECK-NEXT: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s21subclass_existentials1CCMa"([[INT]] 255) -// CHECK-NEXT: [[SUPERCLASS:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 -// CHECK-NEXT: extractvalue %swift.metadata_response [[TMP]], 1 -// CHECK-NEXT: [[METATYPE:%.*]] = call %swift.type* @swift_getExistentialTypeMetadata(i1 false, %swift.type* [[SUPERCLASS]], {{i32|i64}} 1, [[INT]]* [[PROTOCOLS]]) -// CHECK: ret - sil [ossa] @checkMetadata : $@convention(thin) () -> () { bb0: %0 = function_ref @takesMetadata : $@convention(thin) <τ_0_0> (@thick τ_0_0.Type) -> () diff --git a/test/IRGen/super.sil b/test/IRGen/super.sil index 1abffda7d616e..db77f61d997f4 100644 --- a/test/IRGen/super.sil +++ b/test/IRGen/super.sil @@ -214,8 +214,7 @@ sil_vtable Derived { } // CHECK-LABEL: define{{.*}} @test_super_method_of_generic_base -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s5super4BaseCyAA3StrVGMa"([[INT]] 0) -// CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 +// CHECK: [[METADATA:%.*]] = call {{.*}}@"$s5super4BaseCyAA3StrVGMD" // CHECK: [[BASEMETADATA:%.*]] = bitcast %swift.type* [[METADATA]] to void (%T5super4BaseC*)** // CHECK: [[GEP:%.*]] = getelementptr inbounds void (%T5super4BaseC*)*, void (%T5super4BaseC*)** [[BASEMETADATA]] // CHECK: [[SUPERMT:%.*]] = load void (%T5super4BaseC*)*, void (%T5super4BaseC*)** [[GEP]] diff --git a/test/IRGen/typemetadata.sil b/test/IRGen/typemetadata.sil deleted file mode 100644 index 61b158b36a9b0..0000000000000 --- a/test/IRGen/typemetadata.sil +++ /dev/null @@ -1,77 +0,0 @@ -// RUN: %target-swift-frontend -enable-objc-interop -emit-ir %s | %FileCheck %s -DINT=i%target-ptrsize -check-prefix CHECK -check-prefix CHECK-%target-import-type -// RUN: %target-swift-frontend -Osize -enable-objc-interop -emit-ir %s | %FileCheck %s --check-prefix=OSIZE -DINT=i%target-ptrsize - -// REQUIRES: CPU=x86_64 - -sil_stage canonical - -import Builtin - -struct S {} - -class C {} -sil_vtable C {} - -sil @_TFC12typemetadata1Cd : $@convention(method) (@owned C) -> @owned Builtin.NativeObject - -sil @_TFC12typemetadata1CD : $@convention(method) (@owned C) -> () - -sil @test0 : $@convention(thin) () -> () { -bb0: - %0 = metatype $@thin S.Type - %1 = metatype $@thick C.Type - %2 = metatype $@thick (S, C).Type - %100 = tuple () - return %100 : $() -} - -// CHECK-LABEL: define hidden swiftcc %swift.metadata_response @"$s12typemetadata1CCMa" -// CHECK-SAME: ([[INT]]) -// CHECK-DIRECT: [[T0:%.*]] = load %swift.type*, %swift.type** @"$s12typemetadata1CCML", align 8 -// CHECK-INDIRECT: [[T0:%.*]] = load %swift.type*, %swift.type** getelementptr inbounds ({ %swift.type*, i8* }, { %swift.type*, i8* }* @"$s12typemetadata1CCMl", i32 0, i32 0), align 8 -// CHECK-NEXT: [[T1:%.*]] = icmp eq %swift.type* [[T0]], null -// CHECK-NEXT: br i1 [[T1]] - -// CHECK-DIRECT: [[T0:%.*]] = call %objc_class* @swift_getInitializedObjCClass({{.*}} @"$s12typemetadata1CCMf", {{.*}}) -// CHECK-DIRECT-NEXT: [[T1:%.*]] = bitcast %objc_class* [[T0]] to %swift.type* -// CHECK-DIRECT: store atomic %swift.type* [[T1]], %swift.type** @"$s12typemetadata1CCML" release, align 8 -// CHECK-DIRECT-NEXT: br label - -// CHECK-INDIRECT: [[T0:%.*]] = call swiftcc %swift.metadata_response -// @swift_getSingletonMetdata([[INT]] %0, %swift.type_descriptor* bitcast (<{ {{.*}} }>* @"$s12typemetadata1CCMn" to %swift.type_descriptor*)) -// CHECK-INDIRECT-NEXT: [[T1:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 -// CHECK-INDIRECT-NEXT: [[T2:%.*]] = extractvalue %swift.metadata_response [[T0]], 1 -// CHECK-INDIRECT-NEXT: br label - -// CHECK: [[RES:%.*]] = phi -// CHECK-INDIRECT: [[T2:%.*]] = phi [[INT]] -// CHECK-NEXT: [[T0:%.*]] = insertvalue %swift.metadata_response undef, %swift.type* [[RES]], 0 -// CHECK-DIRECT-NEXT: [[T1:%.*]] = insertvalue %swift.metadata_response [[T0]], i64 0, 1 -// CHECK-INDIRECT-NEXT: [[T1:%.*]] = insertvalue %swift.metadata_response [[T0]], i64 [[T2]], 1 -// CHECK-NEXT: ret %swift.metadata_response [[T1]] - -// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$s12typemetadata1SV_AA1CCtMa" -// CHECK-SAME: ([[INT]]) -// CHECK: [[T0:%.*]] = load %swift.type*, %swift.type** @"$s12typemetadata1SV_AA1CCtML", align 8 -// CHECK-NEXT: [[T1:%.*]] = icmp eq %swift.type* [[T0]], null -// CHECK-NEXT: br i1 [[T1]] -// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s12typemetadata1CCMa"([[INT]] 255) -// CHECK: [[T0:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0 -// CHECK-NEXT: extractvalue %swift.metadata_response [[TMP]], 1 -// CHECK-NEXT: [[T1:%.*]] = call swiftcc %swift.metadata_response @swift_getTupleTypeMetadata2([[INT]] %0, %swift.type* {{.*}} @"$s12typemetadata1SVMf", {{.*}} %swift.type* [[T0]], i8* null, i8** null) -// CHECK-NEXT: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[T1]], 0 -// CHECK-NEXT: [[STATE:%.*]] = extractvalue %swift.metadata_response [[T1]], 1 -// CHECK-NEXT: [[T0:%.*]] = icmp eq [[INT]] [[STATE]], 0 -// CHECK-NEXT: br i1 [[T0]], -// CHECK: store atomic %swift.type* [[METADATA]], %swift.type** @"$s12typemetadata1SV_AA1CCtML" release, align 8 -// CHECK-NEXT: br label -// CHECK: [[RES:%.*]] = phi %swift.type* -// CHECK-NEXT: [[RES_STATE:%.*]] = phi [[INT]] -// CHECK-NEXT: [[T0:%.*]] = insertvalue %swift.metadata_response undef, %swift.type* [[RES]], 0 -// CHECK-NEXT: [[T1:%.*]] = insertvalue %swift.metadata_response [[T0]], [[INT]] [[RES_STATE]], 1 -// CHECK-NEXT: ret %swift.metadata_response [[T1]] - -// OSIZE: define hidden swiftcc %swift.metadata_response @"$s12typemetadata1CCMa" -// OSIZE-SAME: ([[INT]]) [[ATTR:#[0-9]+]] { -// OSIZE: [[ATTR]] = {{{.*}}noinline - diff --git a/test/IRGen/weak_import_availability.swift b/test/IRGen/weak_import_availability.swift index 58f07e0351a47..2cc783036b7c3 100644 --- a/test/IRGen/weak_import_availability.swift +++ b/test/IRGen/weak_import_availability.swift @@ -61,9 +61,6 @@ public func useConditionallyAvailableStruct() { blackHole(ConditionallyAvailableStruct.self) } -// CHECK-OLD-LABEL: declare extern_weak swiftcc %swift.metadata_response @"$s31weak_import_availability_helper28ConditionallyAvailableStructVMa"(i64) -// CHECK-NEW-LABEL: declare swiftcc %swift.metadata_response @"$s31weak_import_availability_helper28ConditionallyAvailableStructVMa"(i64) - @available(macOS 10.50, *) public func useConditionallyAvailableMethod(s: ConditionallyAvailableStruct) { s.conditionallyAvailableMethod() diff --git a/test/IRGen/weak_import_clang.swift b/test/IRGen/weak_import_clang.swift index a4732ca563c06..df29eed02992e 100644 --- a/test/IRGen/weak_import_clang.swift +++ b/test/IRGen/weak_import_clang.swift @@ -18,9 +18,6 @@ import Foundation // CHECK-10_50: @weak_variable = extern_weak global // CHECK-10_51: @weak_variable = extern_weak global -// CHECK-10_50: @"OBJC_CLASS_$_NSUserNotificationAction" = extern_weak global %objc_class -// CHECK-10_51: @"OBJC_CLASS_$_NSUserNotificationAction" = external global %objc_class - func testObjCClass() { if #available(OSX 10.51, *) { let action = NSUserNotificationAction() diff --git a/test/Inputs/conditional_conformance_basic_conformances.swift b/test/Inputs/conditional_conformance_basic_conformances.swift index c65dcc03fc48d..0667489b77866 100644 --- a/test/Inputs/conditional_conformance_basic_conformances.swift +++ b/test/Inputs/conditional_conformance_basic_conformances.swift @@ -66,8 +66,7 @@ public func single_concrete() { } // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s42conditional_conformance_basic_conformances15single_concreteyyF"() // CHECK-NEXT: entry: -// CHECK-NEXT: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s42conditional_conformance_basic_conformances6SingleVyAA4IsP2VGMa"(i64 0) -// CHECK-NEXT: [[Single_TYPE:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 +// CHECK-NEXT: [[Single_TYPE:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s42conditional_conformance_basic_conformances6SingleVyAA4IsP2VGMD") // CHECK-NEXT: [[Single_P1:%.*]] = call i8** @"$s42conditional_conformance_basic_conformances6SingleVyAA4IsP2VGACyxGAA2P1A2A0G0RzlWl"() // CHECK-NEXT: call swiftcc void @"$s42conditional_conformance_basic_conformances8takes_p1yyxmAA2P1RzlF"(%swift.type* [[Single_TYPE]], %swift.type* [[Single_TYPE]], i8** [[Single_P1]]) // CHECK-NEXT: ret void @@ -203,8 +202,7 @@ public func double_concrete_concrete() { } // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s42conditional_conformance_basic_conformances016double_concrete_F0yyF"() // CHECK-NEXT: entry: -// CHECK-NEXT: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s42conditional_conformance_basic_conformances6DoubleVyAA4IsP2VAA0F2P3VGMa"(i64 0) -// CHECK-NEXT: [[Double_TYPE:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 +// CHECK-NEXT: [[Double_TYPE:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s42conditional_conformance_basic_conformances6DoubleVyAA4IsP2VAA0F2P3VGMD") // CHECK-NEXT: [[Double_P1:%.*]] = call i8** @"$s42conditional_conformance_basic_conformances6DoubleVyAA4IsP2VAA0F2P3VGACyxq_GAA2P1A2A0G0RzAA0H0R_rlWl"() // CHECK-NEXT: call swiftcc void @"$s42conditional_conformance_basic_conformances8takes_p1yyxmAA2P1RzlF"(%swift.type* [[Double_TYPE]], %swift.type* [[Double_TYPE]], i8** [[Double_P1]]) // CHECK-NEXT: ret void diff --git a/test/Inputs/conditional_conformance_subclass.swift b/test/Inputs/conditional_conformance_subclass.swift index e0052d254d3d2..31731f6d46a5a 100644 --- a/test/Inputs/conditional_conformance_subclass.swift +++ b/test/Inputs/conditional_conformance_subclass.swift @@ -66,8 +66,7 @@ public func subclassgeneric_concrete() { // CHECK-LABEL: define{{( dllexport| protected)?}} swiftcc void @"$s32conditional_conformance_subclass24subclassgeneric_concreteyyF"() // CHECK-NEXT: entry: -// CHECK-NEXT: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s32conditional_conformance_subclass15SubclassGenericCyAA4IsP2VGMa"(i64 0) -// CHECK-NEXT: [[SubclassGeneric_TYPE:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 +// CHECK-NEXT: [[SubclassGeneric_TYPE:%.*]] = call {{.*}}@"$s32conditional_conformance_subclass15SubclassGenericCyAA4IsP2VGMD" // CHECK-NEXT: [[Base_P1:%.*]] = call i8** @"$s32conditional_conformance_subclass15SubclassGenericCyAA4IsP2VGAA4BaseCyxGAA2P1A2A0G0RzlWl"() // CHECK-NEXT: call swiftcc void @"$s32conditional_conformance_subclass8takes_p1yyxmAA2P1RzlF"(%swift.type* [[SubclassGeneric_TYPE]], %swift.type* [[SubclassGeneric_TYPE]], i8** [[Base_P1]]) // CHECK-NEXT: ret void diff --git a/test/Inputs/conditional_conformance_with_assoc.swift b/test/Inputs/conditional_conformance_with_assoc.swift index 70c6e3c153059..cb5749883d7ef 100644 --- a/test/Inputs/conditional_conformance_with_assoc.swift +++ b/test/Inputs/conditional_conformance_with_assoc.swift @@ -183,8 +183,7 @@ public func concrete_concrete() { // CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s34conditional_conformance_with_assoc09concrete_E0yyF"() // CHECK-NEXT: entry: -// CHECK-NEXT: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s34conditional_conformance_with_assoc6DoubleVyAA8IsAlsoP2VAA0F2P3VGMa"(i64 0) -// CHECK-NEXT: [[X:%.*]] = extractvalue %swift.metadata_response [[T0]], 0 +// CHECK-NEXT: [[X:%.*]] = call {{.*}} @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s34conditional_conformance_with_assoc6DoubleVyAA8IsAlsoP2VAA0F2P3VGMD") // CHECK-NEXT: [[Z:%.*]] = call i8** @"$s34conditional_conformance_with_assoc6DoubleVyAA8IsAlsoP2VAA0F2P3VGACyxq_GAA2P1A2A0I0R_AA0H03AT2RpzAakM_AmaLP3AT3RPzrlWl"() // CHECK-NEXT: call swiftcc void @"$s34conditional_conformance_with_assoc8takes_p1yyxmAA2P1RzlF"(%swift.type* [[X]], %swift.type* [[X]], i8** [[Z]]) // CHECK-NEXT: ret void diff --git a/test/RemoteAST/objc_classes.swift b/test/RemoteAST/objc_classes.swift index 86be4be063812..d1c715613c531 100644 --- a/test/RemoteAST/objc_classes.swift +++ b/test/RemoteAST/objc_classes.swift @@ -46,4 +46,4 @@ printType(OurObjCProtocol.self) printType(Optional.self) // CHECK: Optional -stopRemoteAST() \ No newline at end of file +stopRemoteAST() diff --git a/test/lit.cfg b/test/lit.cfg index ede72624511aa..35032a6ebb3c8 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -319,6 +319,7 @@ lit_config.note('Using resource dir: ' + test_resource_dir) # Parse the variant triple. (run_cpu, run_vendor, run_os, run_vers) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups() run_ptrsize = '64' if ('64' in run_cpu or run_cpu == "s390x") else '32' +run_endian = 'little' if run_cpu != 's390x' else 'big' sdk_overlay_link_path = "" sdk_overlay_linker_opt = "" @@ -654,6 +655,7 @@ config.substitutions.append(('%sanitizers-target-triple', config.variant_triple.replace("ios7", "ios8"))) config.substitutions.append(('%target-cpu', run_cpu)) +config.substitutions.append(('%target-endian', run_endian)) config.substitutions.append(('%target-os', run_os)) config.substitutions.append(('%target-ptrsize', run_ptrsize)) diff --git a/test/multifile/multiconformanceimpls/main.swift b/test/multifile/multiconformanceimpls/main.swift index 915a8802c4e14..a7628757ec155 100644 --- a/test/multifile/multiconformanceimpls/main.swift +++ b/test/multifile/multiconformanceimpls/main.swift @@ -16,6 +16,10 @@ // REQUIRES: executable_test +// FIXME: Fetching metadata by mangled name does not consider the provenance of +// retroactive conformances. rdar://problem/53828345 +// REQUIRES: 53828345 + import A import B import C