Lines Matching +full:entry +full:- +full:method

1 //===------- CGObjCMac.cpp - Interface to Apple Objective-C Runtime -------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This provides Objective-C code generation targeting the Apple runtime.
11 //===----------------------------------------------------------------------===//
64 /// the all-integer/pointer case.
66 // Add the non-lazy-bind attribute, since objc_msgSend is likely to in getMessageSendFn()
91 /// floating-point stack; without a special entrypoint, the nil case
104 /// would be unbalanced. Only used on 64-bit X86.
180 /// ObjectPtrTy - LLVM type for object handles (typeof(id))
183 /// PtrObjectPtrTy - LLVM type for id *
186 /// SelectorPtrTy - LLVM type for selector handles (typeof(SEL))
190 /// ProtocolPtrTy - LLVM type for external protocol handles
208 // SuperCTy - clang type for struct objc_super.
210 // SuperPtrCTy - clang type for struct objc_super *.
213 /// SuperTy - LLVM type for struct objc_super.
215 /// SuperPtrTy - LLVM type for struct objc_super *.
218 /// PropertyTy - LLVM type for struct objc_property (struct _prop_t
222 /// PropertyListTy - LLVM type for struct objc_property_list
225 /// PropertyListPtrTy - LLVM type for struct objc_property_list*.
228 // MethodTy - LLVM type for struct objc_method.
231 /// CacheTy - LLVM type for struct objc_cache.
233 /// CachePtrTy - LLVM type for struct objc_cache *.
244 Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(), Ctx.BoolTy}; in getGetPropertyFn()
260 Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(), in getSetPropertyFn()
288 Params.push_back(Ctx.getPointerDiffType()->getCanonicalTypeUnqualified()); in getOptimizedSetPropertyFn()
365 /// GcReadWeakFn -- LLVM objc_read_weak (id *src) function.
368 llvm::Type *args[] = { ObjectPtrTy->getPointerTo() }; in getGcReadWeakFn()
374 /// GcAssignWeakFn -- LLVM objc_assign_weak function.
377 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo() }; in getGcAssignWeakFn()
383 /// GcAssignGlobalFn -- LLVM objc_assign_global function.
386 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo() }; in getGcAssignGlobalFn()
392 /// GcAssignThreadLocalFn -- LLVM objc_assign_threadlocal function.
395 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo() }; in getGcAssignThreadLocalFn()
401 /// GcAssignIvarFn -- LLVM objc_assign_ivar function.
404 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo(), in getGcAssignIvarFn()
411 /// GcMemmoveCollectableFn -- LLVM objc_memmove_collectable function.
419 /// GcAssignStrongCastFn -- LLVM objc_assign_strongCast function.
422 llvm::Type *args[] = { ObjectPtrTy, ObjectPtrTy->getPointerTo() }; in getGcAssignStrongCastFn()
428 /// ExceptionThrowFn - LLVM objc_exception_throw function.
437 /// ExceptionRethrowFn - LLVM objc_exception_rethrow function.
444 /// SyncEnterFn - LLVM object_sync_enter function.
453 /// SyncExitFn - LLVM object_sync_exit function.
497 /// ObjCTypesHelper - Helper class that encapsulates lazy
501 /// SymtabTy - LLVM type for struct objc_symtab.
503 /// SymtabPtrTy - LLVM type for struct objc_symtab *.
505 /// ModuleTy - LLVM type for struct objc_module.
508 /// ProtocolTy - LLVM type for struct objc_protocol.
510 /// ProtocolPtrTy - LLVM type for struct objc_protocol *.
512 /// ProtocolExtensionTy - LLVM type for struct
515 /// ProtocolExtensionTy - LLVM type for struct
518 /// MethodDescriptionTy - LLVM type for struct
521 /// MethodDescriptionListTy - LLVM type for struct
524 /// MethodDescriptionListPtrTy - LLVM type for struct
527 /// ProtocolListTy - LLVM type for struct objc_property_list.
529 /// ProtocolListPtrTy - LLVM type for struct objc_property_list*.
531 /// CategoryTy - LLVM type for struct objc_category.
533 /// ClassTy - LLVM type for struct objc_class.
535 /// ClassPtrTy - LLVM type for struct objc_class *.
537 /// ClassExtensionTy - LLVM type for struct objc_class_ext.
539 /// ClassExtensionPtrTy - LLVM type for struct objc_class_ext *.
541 // IvarTy - LLVM type for struct objc_ivar.
543 /// IvarListTy - LLVM type for struct objc_ivar_list.
545 /// IvarListPtrTy - LLVM type for struct objc_ivar_list *.
547 /// MethodListTy - LLVM type for struct objc_method_list.
549 /// MethodListPtrTy - LLVM type for struct objc_method_list *.
552 /// ExceptionDataTy - LLVM type for struct _objc_exception_data.
555 /// ExceptionTryEnterFn - LLVM objc_exception_try_enter function.
557 llvm::Type *params[] = { ExceptionDataTy->getPointerTo() }; in getExceptionTryEnterFn()
563 /// ExceptionTryExitFn - LLVM objc_exception_try_exit function.
565 llvm::Type *params[] = { ExceptionDataTy->getPointerTo() }; in getExceptionTryExitFn()
571 /// ExceptionExtractFn - LLVM objc_exception_extract function.
573 llvm::Type *params[] = { ExceptionDataTy->getPointerTo() }; in getExceptionExtractFn()
579 /// ExceptionMatchFn - LLVM objc_exception_match function.
587 /// SetJmpFn - LLVM _setjmp function.
590 llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() }; in getSetJmpFn()
602 /// ObjCNonFragileABITypesHelper - will have all types needed by objective-c's
606 // MethodListnfABITy - LLVM for struct _method_list_t
609 // MethodListnfABIPtrTy - LLVM for struct _method_list_t*
618 // ProtocolListnfABITy - LLVM for struct _objc_protocol_list
621 // ProtocolListnfABIPtrTy - LLVM for struct _objc_protocol_list*
624 // ClassnfABITy - LLVM for struct _class_t
627 // ClassnfABIPtrTy - LLVM for struct _class_t*
630 // IvarnfABITy - LLVM for struct _ivar_t
633 // IvarListnfABITy - LLVM for struct _ivar_list_t
639 // ClassRonfABITy - LLVM for struct _class_ro_t
642 // ImpnfABITy - LLVM for id (*)(id, SEL, ...)
645 // CategorynfABITy - LLVM for struct _category_t
650 // MessageRefTy - LLVM for:
656 // MessageRefCTy - clang type for struct _message_ref_t
659 // MessageRefPtrTy - LLVM for struct _message_ref_t*
661 // MessageRefCPtrTy - clang type for struct _message_ref_t*
664 // SuperMessageRefTy - LLVM for:
671 // SuperMessageRefPtrTy - LLVM for struct _super_message_ref_t*
730 /// Loads from a classref. For Objective-C stub classes, this invokes the
734 // Add the non-lazy-bind attribute, since objc_loadClassref is likely to in getLoadClassrefFn()
752 cast<llvm::Function>(F.getCallee())->setLinkage( in getLoadClassrefFn()
789 /// a non-pointer. Note that this instruction is equal
796 /// subsequent word-size instructions do not begin at a multiple of
805 /// The next I+1 words are __strong pointers to Objective-C
812 /// The next I+1 words are __weak pointers to Objective-C
817 /// Objective-C objects or blocks.
821 /// as-yet-unspecified ownership semantics. If we add more
857 /// LazySymbols - Symbols to generate a lazy reference for. See
861 /// DefinedSymbols - External symbols which are defined by this
863 /// special linker symbols which ensure that Objective-C modules are
867 /// ClassNames - uniqued class names.
870 /// MethodVarNames - uniqued method variable names.
873 /// DefinedCategoryNames - list of category names in form Class_Category.
876 /// MethodVarTypes - uniqued method type signatures. We have to use
880 /// MethodDefinitions - map of methods which have been defined in
884 /// DirectMethodDefinitions - map of direct methods which have been defined in
888 /// PropertyNames - uniqued method variable names.
891 /// ClassReferences - uniqued class references.
894 /// SelectorReferences - uniqued selector references.
897 /// Protocols - Protocols for which an objc_protocol structure has
902 /// DefinedProtocols - Protocols which have actually been
906 /// DefinedClasses - List of defined classes.
909 /// ImplementedClasses - List of @implemented classes.
912 /// DefinedNonLazyClasses - List of defined "non-lazy" classes.
915 /// DefinedCategories - List of defined categories.
918 /// DefinedStubCategories - List of defined categories on class stubs.
921 /// DefinedNonLazyCategories - List of defined "non-lazy" categories.
925 /// int * but is actually an Obj-C class pointer.
933 /// GetMethodVarName - Return a unique constant for the given
938 /// GetMethodVarType - Return a unique constant for the given
939 /// method's type encoding string. The return value has type char *.
946 /// GetPropertyName - Return a unique constant for the given
954 /// GetClassName - Return a unique constant for the given selector's
961 /// BuildIvarLayout - Builds ivar layout bitmap for the class
964 /// \param hasMRCWeakIvars - Whether we are compiling in MRC and there
967 /// actually have any entries, because the ivar might be under-aligned.
1008 /// GetIvarLayoutName - Returns a unique constant for the given
1013 /// EmitPropertyList - Emit the given property list. The return
1021 /// EmitProtocolMethodTypes - Generate the array of extended method type
1027 /// GetProtocolRef - Return a reference to the internal protocol
1041 /// CreateMetadataVar - Create a global variable with internal
1042 /// linkage for use by the Objective-C runtime.
1048 /// \param Name - The variable name.
1049 /// \param Init - The variable initializer; this is also used to
1051 /// \param Section - The section the variable should go into, or empty.
1052 /// \param Align - The alignment for the variable, or 0.
1053 /// \param AddToUsed - Whether the variable should be added to
1082 /// EmitImageInfo - Emit the image info marker used to encode some module
1109 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1177 for (auto *MD : PD->methods()) { in get()
1178 size_t index = (2 * size_t(MD->isOptional())) in get()
1179 + (size_t(MD->isClassMethod())); in get()
1188 // In both ABIs, the method types list is parallel with the in emitExtendedTypesArray()
1199 result.push_back(self->GetMethodVarType(MD, true)); in emitExtendedTypesArray()
1209 return self->emitMethodList(PD->getObjCRuntimeNameAsString(), in emitMethodList()
1222 /// EmitModuleInfo - Another marker encoding module level
1226 /// EmitModuleSymols - Emit module symbols, the list of defined
1230 /// FinishModule - Write out global data structures at the end of
1234 /// EmitClassExtension - Generate the class extension structure used
1242 /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1252 /// EmitSuperClassRef - Emits reference to class's main metadata class.
1255 /// EmitIvarList - Emit the ivar list for the given
1263 /// EmitMetaClass - Emit a forward reference to the class structure
1268 /// EmitMetaClass - Emit a class structure for the metaclass of the
1280 /// EmitMethodList - Emit the method list for the given
1285 /// GetOrEmitProtocol - Get the protocol object for the given
1290 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1296 /// EmitProtocolExtension - Generate the protocol extension
1304 /// EmitProtocolList - Generate the list of referenced
1310 /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
1328 const ObjCMethodDecl *Method) override;
1336 const ObjCMethodDecl *Method) override;
1347 const ObjCMethodDecl *Method) override;
1408 /// SuperClassReferences - uniqued super class references.
1411 /// MetaClassReferences - uniqued meta class references.
1414 /// EHTypeReferences - uniqued class ehtype references.
1417 /// VTableDispatchMethods - List of methods for which we generate
1418 /// vtable-based message dispatch.
1421 /// DefinedMetaClasses - List of defined meta-classes.
1424 /// isVTableDispatchedSelector - Returns true if SEL is a
1425 /// vtable-based selector.
1428 /// FinishNonFragileABIModule - Write out global data structures at the end of
1432 /// AddModuleClassList - Add the given list of class pointers to the
1452 /// Emit the method list for the given implementation. The return value
1457 /// EmitIvarList - Emit the ivar list for the given
1468 /// GetOrEmitProtocol - Get the protocol object for the given
1473 /// GetOrEmitProtocolRef - Get a forward reference to the protocol
1479 /// EmitProtocolList - Generate the list of referenced
1493 const ObjCMethodDecl *Method);
1495 /// GetClassGlobal - Return the global variable for the Objective-C
1508 llvm::GlobalVariable *Entry);
1510 /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1521 /// EmitSuperClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
1526 /// EmitMetaClassRef - Return a Value * of the address of _class_t
1527 /// meta-data
1531 /// ObjCIvarOffsetVariable - Returns the ivar offset variable for
1538 /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
1543 /// GetInterfaceEHType - Get the cached ehtype for the given Objective-C
1567 /// ImplementationIsNonLazy - Check whether the given category or
1568 /// class implementation is "non-lazy".
1573 // Annotate the load as an invariant load iff inside an instance method in IsIvarOffsetKnownIdempotent()
1574 // and ivar belongs to instance method's class and one of its super class. in IsIvarOffsetKnownIdempotent()
1580 // base of the ivar access is a parameter to an Objective C method. in IsIvarOffsetKnownIdempotent()
1585 // and that the method may be inlined, this optimization actually in IsIvarOffsetKnownIdempotent()
1589 if (MD->isInstanceMethod() && !MD->isDirectMethod()) in IsIvarOffsetKnownIdempotent()
1590 if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) in IsIvarOffsetKnownIdempotent()
1591 return IV->getContainingInterface()->isSuperClassOf(ID); in IsIvarOffsetKnownIdempotent()
1598 for (; ID; ID = ID->getSuperClass()) { in isClassLayoutKnownStatically()
1601 if (ID->getIdentifier()->getName() == "NSObject") in isClassLayoutKnownStatically()
1606 if (!ID->getImplementation()) in isClassLayoutKnownStatically()
1625 const ObjCMethodDecl *Method) override;
1633 const ObjCMethodDecl *Method) override;
1646 const ObjCMethodDecl *Method) override in GetSelector() argument
1647 { return EmitSelector(CGF, Method->getSelector()); } in GetSelector()
1721 /// A helper class for performing the null-initialization of a return
1727 /// Perform a null-check of the given receiver.
1729 // Make blocks for the null-receiver and call edges. in init()
1730 NullBB = CGF.createBasicBlock("msgSend.null-receiver"); in init()
1734 // null-receiver block. There's no point in trying to avoid it: in init()
1736 // we shouldn't have done this null-check in the first place. in init()
1744 /// Complete the null-return operation. It is valid to call this
1751 const ObjCMethodDecl *Method) { in complete()
1752 // If we never had to do a null-check, just use the raw result. in complete()
1756 // IP, which can happen if the method we're calling is marked noreturn. in complete()
1766 // Okay, start emitting the null-receiver block. in complete()
1770 if (Method) { in complete()
1771 CGObjCRuntime::destroyCalleeDestroyedArguments(CGF, Method, CallArgs); in complete()
1778 if (result.isScalar() && resultType->isVoidType()) { in complete()
1779 // No jumps required if the message-send was noreturn. in complete()
1786 // Derive the null-initialization value. in complete()
1795 llvm::PHINode *phi = CGF.Builder.CreatePHI(null->getType(), 2); in complete()
1796 phi->addIncoming(result.getScalarVal(), callBB); in complete()
1797 phi->addIncoming(null, NullBB); in complete()
1803 // cases where the ABI has us returning (1) non-agg values in in complete()
1806 assert(result.isAggregate() && "null init of non-aggregate result?"); in complete()
1818 llvm::Type *scalarTy = callResult.first->getType(); in complete()
1823 real->addIncoming(callResult.first, callBB); in complete()
1824 real->addIncoming(scalarZero, NullBB); in complete()
1826 imag->addIncoming(callResult.second, callBB); in complete()
1827 imag->addIncoming(scalarZero, NullBB); in complete()
1836 /// getConstantGEP() - Help routine to construct simple GEPs.
1844 return llvm::ConstantExpr::getGetElementPtr(C->getValueType(), C, Idxs); in getConstantGEP()
1847 /// hasObjCExceptionAttribute - Return true if this class or any super
1851 if (OID->hasAttr<ObjCExceptionAttr>()) in hasObjCExceptionAttribute()
1853 if (const ObjCInterfaceDecl *Super = OID->getSuperClass()) in hasObjCExceptionAttribute()
1876 GV->setSection(SectionName); in finishAndCreateGlobal()
1888 /// GetClass - Return a reference to the class for the given interface
1895 /// GetSelector - Return the pointer to the unique'd string for this selector.
1903 *Method) { in GetSelector() argument
1904 return EmitSelector(CGF, Method->getSelector()); in GetSelector()
1908 if (T->isObjCIdType() || in GetEHType()
1909 T->isObjCQualifiedIdType()) { in GetEHType()
1913 if (T->isObjCClassType() || in GetEHType()
1914 T->isObjCQualifiedClassType()) { in GetEHType()
1918 if (T->isObjCObjectPointerType()) in GetEHType()
1953 StringRef String = Literal->getString(); in GetConstantStringEntry()
1989 llvm::StringMapEntry<llvm::GlobalVariable *> &Entry = in GenerateConstantNSString() local
1992 if (auto *C = Entry.second) in GenerateConstantNSString()
1994 C, C->getValueType(), CharUnits::fromQuantity(C->getAlignment())); in GenerateConstantNSString()
2014 llvm::ConstantDataArray::getString(VMContext, Entry.first()); in GenerateConstantNSString()
2019 auto *GV = new llvm::GlobalVariable(CGM.getModule(), C->getType(), isConstant, in GenerateConstantNSString()
2021 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in GenerateConstantNSString()
2024 GV->setAlignment(llvm::Align(1)); in GenerateConstantNSString()
2039 GV->setSection(CGM.getLangOpts().ObjCRuntime.isNonFragile() in GenerateConstantNSString()
2042 Entry.second = GV; in GenerateConstantNSString()
2044 return ConstantAddress(GV, GV->getValueType(), Alignment); in GenerateConstantNSString()
2053 /// which class's method should be called.
2064 const ObjCMethodDecl *Method) { in GenerateMessageSendSuper() argument
2079 // Message sent to 'super' in a class method defined in a category in GenerateMessageSendSuper()
2081 // If we are in a class method, we must retrieve the in GenerateMessageSendSuper()
2085 Target = EmitClassRef(CGF, Class->getSuperClass()); in GenerateMessageSendSuper()
2098 Target = EmitClassRef(CGF, Class->getSuperClass()); in GenerateMessageSendSuper()
2112 ObjCTypes.SuperPtrCTy, true, CallArgs, Method, Class, in GenerateMessageSendSuper()
2124 const ObjCMethodDecl *Method) { in GenerateMessageSend() argument
2127 Method, Class, ObjCTypes); in GenerateMessageSend()
2139 const ObjCMethodDecl *Method, in EmitMessageSend() argument
2150 if (!Method || !Method->isDirectMethod()) in EmitMessageSend()
2154 // If we're calling a method, use the formal signature. in EmitMessageSend()
2155 MessageSendInfo MSI = getMessageSendInfo(Method, ResultType, ActualArgs); in EmitMessageSend()
2157 if (Method) in EmitMessageSend()
2158 assert(CGM.getContext().getCanonicalType(Method->getReturnType()) == in EmitMessageSend()
2163 canMessageReceiverBeNull(CGF, Method, IsSuper, ClassReceiver, Arg0); in EmitMessageSend()
2169 if (Method && Method->isDirectMethod()) { in EmitMessageSend()
2171 Fn = GenerateDirectMethod(Method, Method->getClassInterface()); in EmitMessageSend()
2203 // Emit a null-check if there's a consumed argument other than the receiver. in EmitMessageSend()
2204 if (!RequiresNullCheck && Method && Method->hasParamDestroyedInCallee()) in EmitMessageSend()
2223 // Mark the call as noreturn if the method is marked noreturn and the in EmitMessageSend()
2225 if (Method && Method->hasAttr<NoReturnAttr>() && !ReceiverCanBeNull) { in EmitMessageSend()
2226 CallSite->setDoesNotReturn(); in EmitMessageSend()
2230 RequiresNullCheck ? Method : nullptr); in EmitMessageSend()
2258 if (FQT->isObjCObjectPointerType() || FQT->isBlockPointerType()) in GetGCAttrTypeForType()
2263 if (const PointerType *PT = FQT->getAs<PointerType>()) in GetGCAttrTypeForType()
2264 return GetGCAttrTypeForType(Ctx, PT->getPointeeType(), /*pointee*/ true); in GetGCAttrTypeForType()
2297 /// Whether the offsets in IvarsInfo might be out-of-order.
2377 for (const auto &CI : blockDecl->captures()) { in visitBlock()
2379 QualType type = variable->getType(); in visitBlock()
2389 // adding them out-of-order, make sure we sort later. in visitBlock()
2400 assert(!type->isArrayType() && "array variable should not be caught"); in visitBlock()
2401 if (const RecordType *record = type->getAs<RecordType>()) { in visitBlock()
2416 /// getBlockCaptureLifetime - This routine returns life time of the captured
2417 /// block variable for the purpose of block layout meta-data generation. FQT is
2429 // In MRC, retainable pointers are owned by non-__block variables. in getBlockCaptureLifetime()
2430 if (FQT->isObjCObjectPointerType() || FQT->isBlockPointerType()) in getBlockCaptureLifetime()
2464 bool IsUnion = (RD && RD->isUnion()); in BuildRCRecordLayout()
2484 if (!Field->getIdentifier() || Field->isBitField()) { in BuildRCRecordLayout()
2491 QualType FQT = Field->getType(); in BuildRCRecordLayout()
2492 if (FQT->isRecordType() || FQT->isUnionType()) { in BuildRCRecordLayout()
2493 if (FQT->isUnionType()) in BuildRCRecordLayout()
2496 BuildRCBlockVarRecordLayout(FQT->castAs<RecordType>(), in BuildRCRecordLayout()
2503 uint64_t ElCount = CArray->getZExtSize(); in BuildRCRecordLayout()
2505 FQT = CArray->getElementType(); in BuildRCRecordLayout()
2508 ElCount *= CArray->getZExtSize(); in BuildRCRecordLayout()
2509 FQT = CArray->getElementType(); in BuildRCRecordLayout()
2511 if (FQT->isRecordType() && ElCount) { in BuildRCRecordLayout()
2512 int OldIndex = RunSkipBlockVars.size() - 1; in BuildRCRecordLayout()
2513 auto *RT = FQT->castAs<RecordType>(); in BuildRCRecordLayout()
2519 for (int FirstIndex = RunSkipBlockVars.size() - 1 ;ElIx < ElCount; ElIx++) { in BuildRCRecordLayout()
2530 CharUnits FieldSize = CGM.getContext().getTypeSizeInChars(Field->getType()); in BuildRCRecordLayout()
2547 if (LastFieldBitfieldOrUnnamed->isBitField()) { in BuildRCRecordLayout()
2550 = LastFieldBitfieldOrUnnamed->getBitWidthValue(CGM.getContext()); in BuildRCRecordLayout()
2556 getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(), in BuildRCRecordLayout()
2561 assert(!LastFieldBitfieldOrUnnamed->getIdentifier() &&"Expected unnamed"); in BuildRCRecordLayout()
2564 = CGM.getContext().getTypeSizeInChars(LastFieldBitfieldOrUnnamed->getType()); in BuildRCRecordLayout()
2566 getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(), in BuildRCRecordLayout()
2575 getBlockCaptureLifetime(MaxField->getType(), ByrefLayout), in BuildRCRecordLayout()
2584 const RecordDecl *RD = RT->getDecl(); in BuildRCBlockVarRecordLayout()
2585 SmallVector<const FieldDecl*, 16> Fields(RD->fields()); in BuildRCBlockVarRecordLayout()
2593 /// InlineLayoutInstruction - This routine produce an inline instruction for the
2727 end_byte_pos - start_byte_pos + RunSkipBlockVars[j-1].block_var_size; in getBitmapBlockLayout()
2730 RunSkipBlockVars[j].block_var_bytepos - in getBitmapBlockLayout()
2731 RunSkipBlockVars[j-1].block_var_bytepos - RunSkipBlockVars[j-1].block_var_size; in getBitmapBlockLayout()
2737 size_in_bytes -= residue_in_bytes; in getBitmapBlockLayout()
2747 size_in_words -= 16; in getBitmapBlockLayout()
2752 unsigned char inst = (opcode << 4) | (size_in_words-1); in getBitmapBlockLayout()
2757 (BLOCK_LAYOUT_NON_OBJECT_BYTES << 4) | (residue_in_bytes.getQuantity()-1); in getBitmapBlockLayout()
2833 if (i < e-1) in getBitmapBlockLayout()
2840 auto *Entry = CreateCStringLiteral(BitMap, ObjCLabelType::ClassName, in getBitmapBlockLayout() local
2843 return getConstantGEP(VMContext, Entry, 0, 0); in getBitmapBlockLayout()
2859 // happens when the block is non-escaping). in getBlockLayoutInfoString()
2906 for (const auto &CI : blockDecl->captures()) { in fillRunSkipBlockVars()
2908 QualType type = variable->getType(); in fillRunSkipBlockVars()
2916 CharUnits::fromQuantity(layout->getElementOffset(capture.getIndex())); in fillRunSkipBlockVars()
2918 assert(!type->isArrayType() && "array variable should not be caught"); in fillRunSkipBlockVars()
2920 if (const RecordType *record = type->getAs<RecordType>()) { in fillRunSkipBlockVars()
2950 assert(!T->isArrayType() && "__block array variable should not be caught"); in BuildByrefLayout()
2954 if (const RecordType *record = T->getAs<RecordType>()) { in BuildByrefLayout()
2977 DefinedProtocols.insert(PD->getIdentifier()); in GenerateProtocol()
2982 if (Protocols.count(PD->getIdentifier())) in GenerateProtocol()
2987 if (DefinedProtocols.count(PD->getIdentifier())) in GetProtocolRef()
3001 ID->getObjCRuntimeNameAsString())) in EmitClassRefViaRuntime()
3009 call->setDoesNotThrow(); in EmitClassRefViaRuntime()
3014 // Objective-C 1.0 extensions
3026 llvm::GlobalVariable *Entry = Protocols[PD->getIdentifier()]; in GetOrEmitProtocol() local
3029 if (Entry && Entry->hasInitializer()) in GetOrEmitProtocol()
3030 return Entry; in GetOrEmitProtocol()
3033 if (const ObjCProtocolDecl *Def = PD->getDefinition()) in GetOrEmitProtocol()
3040 // Construct method lists. in GetOrEmitProtocol()
3046 values.add(GetClassName(PD->getObjCRuntimeNameAsString())); in GetOrEmitProtocol()
3047 values.add(EmitProtocolList("OBJC_PROTOCOL_REFS_" + PD->getName(), in GetOrEmitProtocol()
3048 PD->protocol_begin(), PD->protocol_end())); in GetOrEmitProtocol()
3054 if (Entry) { in GetOrEmitProtocol()
3056 assert(Entry->hasPrivateLinkage()); in GetOrEmitProtocol()
3057 values.finishAndSetAsInitializer(Entry); in GetOrEmitProtocol()
3059 Entry = values.finishAndCreateGlobal("OBJC_PROTOCOL_" + PD->getName(), in GetOrEmitProtocol()
3063 Entry->setSection("__OBJC,__protocol,regular,no_dead_strip"); in GetOrEmitProtocol()
3065 Protocols[PD->getIdentifier()] = Entry; in GetOrEmitProtocol()
3067 CGM.addCompilerUsedGlobal(Entry); in GetOrEmitProtocol()
3069 return Entry; in GetOrEmitProtocol()
3073 llvm::GlobalVariable *&Entry = Protocols[PD->getIdentifier()]; in GetOrEmitProtocolRef() local
3075 if (!Entry) { in GetOrEmitProtocolRef()
3079 Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolTy, in GetOrEmitProtocolRef()
3081 nullptr, "OBJC_PROTOCOL_" + PD->getName()); in GetOrEmitProtocolRef()
3082 Entry->setSection("__OBJC,__protocol,regular,no_dead_strip"); in GetOrEmitProtocolRef()
3084 Entry->setAlignment(llvm::Align(4)); in GetOrEmitProtocolRef()
3087 return Entry; in GetOrEmitProtocolRef()
3111 EmitProtocolMethodTypes("OBJC_PROTOCOL_METHOD_TYPES_" + PD->getName(), in EmitProtocolExtension()
3116 EmitPropertyList("OBJC_$_PROP_PROTO_LIST_" + PD->getName(), nullptr, PD, in EmitProtocolExtension()
3119 EmitPropertyList("OBJC_$_CLASS_PROP_PROTO_LIST_" + PD->getName(), nullptr, in EmitProtocolExtension()
3123 if (optInstanceMethods->isNullValue() && in EmitProtocolExtension()
3124 optClassMethods->isNullValue() && in EmitProtocolExtension()
3125 extendedMethodTypes->isNullValue() && in EmitProtocolExtension()
3126 instanceProperties->isNullValue() && in EmitProtocolExtension()
3127 classProperties->isNullValue()) { in EmitProtocolExtension()
3144 return CreateMetadataVar("_OBJC_PROTOCOLEXT_" + PD->getName(), values, in EmitProtocolExtension()
3199 for (const auto *PD : Proto->properties()) { in PushProtocolProperties()
3200 if (IsClassProperty != PD->isClassProperty()) in PushProtocolProperties()
3202 if (!PropertySet.insert(PD->getIdentifier()).second) in PushProtocolProperties()
3207 for (const auto *P : Proto->protocols()) in PushProtocolProperties()
3229 // Make this entry NULL for OS X with deployment target < 10.11, for iOS in EmitPropertyList()
3241 for (const ObjCCategoryDecl *ClassExt : OID->known_extensions()) in EmitPropertyList()
3242 for (auto *PD : ClassExt->properties()) { in EmitPropertyList()
3243 if (IsClassProperty != PD->isClassProperty()) in EmitPropertyList()
3245 if (PD->isDirectProperty()) in EmitPropertyList()
3247 PropertySet.insert(PD->getIdentifier()); in EmitPropertyList()
3251 for (const auto *PD : OCD->properties()) { in EmitPropertyList()
3252 if (IsClassProperty != PD->isClassProperty()) in EmitPropertyList()
3256 if (!PropertySet.insert(PD->getIdentifier()).second) in EmitPropertyList()
3258 if (PD->isDirectProperty()) in EmitPropertyList()
3264 for (const auto *P : OID->all_referenced_protocols()) in EmitPropertyList()
3268 for (const auto *P : CD->protocols()) in EmitPropertyList()
3286 property.add(GetPropertyName(PD->getIdentifier())); in EmitPropertyList()
3342 const ObjCInterfaceDecl *Interface = OCD->getClassInterface(); in GenerateCategory()
3344 Interface->FindCategoryDeclaration(OCD->getIdentifier()); in GenerateCategory()
3347 llvm::raw_svector_ostream(ExtName) << Interface->getName() << '_' in GenerateCategory()
3348 << OCD->getName(); in GenerateCategory()
3359 for (const auto *MD : OCD->methods()) { in GenerateCategory()
3360 if (!MD->isDirectMethod()) in GenerateCategory()
3361 Methods[unsigned(MD->isClassMethod())].push_back(MD); in GenerateCategory()
3364 Values.add(GetClassName(OCD->getName())); in GenerateCategory()
3365 Values.add(GetClassName(Interface->getObjCRuntimeNameAsString())); in GenerateCategory()
3366 LazySymbols.insert(Interface->getIdentifier()); in GenerateCategory()
3375 Category->protocol_begin(), Category->protocol_end())); in GenerateCategory()
3398 // method definition entries must be clear for next implementation. in GenerateCategory()
3403 /// Apparently: is not a meta-class.
3406 /// Is a meta-class.
3409 /// Has a non-trivial constructor or destructor.
3424 /// Is a meta-class.
3430 /// Has a non-trivial constructor or destructor.
3439 /// (Obsolete) ARC-specific: this class has a .release_ivars method
3445 /// Class has non-trivial destructors, but zero-initialization is okay.
3458 if (auto recType = type->getAs<RecordType>()) { in hasWeakMember()
3459 for (auto *field : recType->getDecl()->fields()) { in hasWeakMember()
3460 if (hasWeakMember(field->getType())) in hasWeakMember()
3477 ID->getClassInterface()->all_declared_ivar_begin(); in hasMRCWeakIvars()
3478 ivar; ivar = ivar->getNextIvar()) { in hasMRCWeakIvars()
3479 if (hasWeakMember(ivar->getType())) in hasMRCWeakIvars()
3498 // Objective-C 1.0 extensions (<rdr://4585769>)
3507 &CGM.getContext().Idents.get(ID->getObjCRuntimeNameAsString()); in GenerateClass()
3510 std::string ClassName = ID->getNameAsString(); in GenerateClass()
3513 const_cast<ObjCInterfaceDecl*>(ID->getClassInterface()); in GenerateClass()
3515 EmitProtocolList("OBJC_CLASS_PROTOCOLS_" + ID->getName(), in GenerateClass()
3516 Interface->all_referenced_protocol_begin(), in GenerateClass()
3517 Interface->all_referenced_protocol_end()); in GenerateClass()
3519 if (ID->hasNonZeroConstructors() || ID->hasDestructors()) in GenerateClass()
3532 // FIXME: Set CXX-structors flag. in GenerateClass()
3533 if (ID->getClassInterface()->getVisibility() == HiddenVisibility) in GenerateClass()
3542 for (const auto *MD : ID->methods()) { in GenerateClass()
3543 if (!MD->isDirectMethod()) in GenerateClass()
3544 Methods[unsigned(MD->isClassMethod())].push_back(MD); in GenerateClass()
3547 for (const auto *PID : ID->property_impls()) { in GenerateClass()
3548 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) { in GenerateClass()
3549 if (PID->getPropertyDecl()->isDirectProperty()) in GenerateClass()
3551 if (ObjCMethodDecl *MD = PID->getGetterMethodDecl()) in GenerateClass()
3554 if (ObjCMethodDecl *MD = PID->getSetterMethodDecl()) in GenerateClass()
3563 if (ObjCInterfaceDecl *Super = Interface->getSuperClass()) { in GenerateClass()
3565 LazySymbols.insert(Super->getIdentifier()); in GenerateClass()
3567 values.add(GetClassName(Super->getObjCRuntimeNameAsString())); in GenerateClass()
3571 values.add(GetClassName(ID->getObjCRuntimeNameAsString())); in GenerateClass()
3577 values.add(emitMethodList(ID->getName(), MethodListType::InstanceMethods, in GenerateClass()
3592 assert(GV->getValueType() == ObjCTypes.ClassTy && in GenerateClass()
3595 GV->setSection(Section); in GenerateClass()
3596 GV->setAlignment(CGM.getPointerAlign().getAsAlign()); in GenerateClass()
3602 // method definition entries must be clear for next implementation. in GenerateClass()
3612 if (ID->getClassInterface()->getVisibility() == HiddenVisibility) in EmitMetaClass()
3618 const ObjCInterfaceDecl *Root = ID->getClassInterface(); in EmitMetaClass()
3619 while (const ObjCInterfaceDecl *Super = Root->getSuperClass()) in EmitMetaClass()
3621 values.add(GetClassName(Root->getObjCRuntimeNameAsString())); in EmitMetaClass()
3625 if (ObjCInterfaceDecl *Super = ID->getClassInterface()->getSuperClass()) { in EmitMetaClass()
3626 values.add(GetClassName(Super->getObjCRuntimeNameAsString())); in EmitMetaClass()
3630 values.add(GetClassName(ID->getObjCRuntimeNameAsString())); in EmitMetaClass()
3636 values.add(emitMethodList(ID->getName(), MethodListType::ClassMethods, in EmitMetaClass()
3648 Name += ID->getName(); in EmitMetaClass()
3653 assert(GV->getValueType() == ObjCTypes.ClassTy && in EmitMetaClass()
3661 GV->setSection("__OBJC,__meta_class,regular,no_dead_strip"); in EmitMetaClass()
3668 std::string Name = "OBJC_METACLASS_" + ID->getNameAsString(); in EmitMetaClassRef()
3684 assert(GV->getValueType() == ObjCTypes.ClassTy && in EmitMetaClassRef()
3690 std::string Name = "OBJC_CLASS_" + ID->getNameAsString(); in EmitSuperClassRef()
3698 assert(GV->getValueType() == ObjCTypes.ClassTy && in EmitSuperClassRef()
3705 data that doesn't fit in the normal fragile-ABI class structure, and
3731 + ID->getName(), in EmitClassExtension()
3732 ID, ID->getClassInterface(), ObjCTypes, isMetaclass); in EmitClassExtension()
3735 if (layout->isNullValue() && propertyList->isNullValue()) { in EmitClassExtension()
3748 return CreateMetadataVar("OBJC_CLASSEXT_" + ID->getName(), values, in EmitClassExtension()
3775 const ObjCInterfaceDecl *OID = ID->getClassInterface(); in EmitIvarList()
3782 for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin(); in EmitIvarList()
3783 IVD; IVD = IVD->getNextIvar()) { in EmitIvarList()
3784 // Ignore unnamed bit-fields. in EmitIvarList()
3785 if (!IVD->getDeclName()) in EmitIvarList()
3789 ivar.add(GetMethodVarName(IVD->getIdentifier())); in EmitIvarList()
3807 GV = CreateMetadataVar("OBJC_INSTANCE_VARIABLES_" + ID->getName(), ivarList, in EmitIvarList()
3813 /// Build a struct objc_method_description constant for the given method.
3822 description.add(GetMethodVarName(MD->getSelector())); in emitMethodDescriptionConstant()
3827 /// Build a struct objc_method constant for the given method.
3832 /// void *method;
3837 assert(fn && "no definition registered for method"); in emitMethodConstant()
3839 auto method = builder.beginStruct(ObjCTypes.MethodTy); in emitMethodConstant() local
3840 method.add(GetMethodVarName(MD->getSelector())); in emitMethodConstant()
3841 method.add(GetMethodVarType(MD)); in emitMethodConstant()
3842 method.add(fn); in emitMethodConstant()
3843 method.finishAndAddTo(builder); in emitMethodConstant()
3937 if (!MD->isDirectMethod()) in emitMethodList()
3949 llvm::Function *Method; in GenerateMethod() local
3951 if (OMD->isDirectMethod()) { in GenerateMethod()
3952 Method = GenerateDirectMethod(OMD, CD); in GenerateMethod()
3959 Method = in GenerateMethod()
3964 MethodDefinitions.insert(std::make_pair(OMD, Method)); in GenerateMethod()
3966 return Method; in GenerateMethod()
3972 auto *COMD = OMD->getCanonicalDecl(); in GenerateDirectMethod()
3977 // Objective-C allows for the declaration and implementation types in GenerateDirectMethod()
3980 // If we're being asked for the Function associated for a method in GenerateDirectMethod()
3986 if (!OMD->getBody() || COMD->getReturnType() == OMD->getReturnType()) in GenerateDirectMethod()
3987 return I->second; in GenerateDirectMethod()
3988 OldFn = I->second; in GenerateDirectMethod()
3998 Fn->takeName(OldFn); in GenerateDirectMethod()
3999 OldFn->replaceAllUsesWith(Fn); in GenerateDirectMethod()
4000 OldFn->eraseFromParent(); in GenerateDirectMethod()
4003 I->second = Fn; in GenerateDirectMethod()
4020 auto selfAddr = CGF.GetAddrOfLocalVar(OMD->getSelfDecl()); in GenerateDirectMethodPrologue()
4036 if (OMD->isClassMethod()) { in GenerateDirectMethodPrologue()
4045 // TODO: If this method is inlined, the caller might know that `self` is in GenerateDirectMethodPrologue()
4046 // already initialized; for example, it might be an ordinary Objective-C in GenerateDirectMethodPrologue()
4047 // method which always receives an initialized `self`, or it might have just in GenerateDirectMethodPrologue()
4057 // Nullable `Class` expressions cannot be messaged with a direct method in GenerateDirectMethodPrologue()
4070 auto selfTy = cast<llvm::PointerType>(selfValue->getType()); in GenerateDirectMethodPrologue()
4080 auto retTy = OMD->getReturnType(); in GenerateDirectMethodPrologue()
4082 if (!retTy->isVoidType()) { in GenerateDirectMethodPrologue()
4094 if (OMD->getCmdDecl()->isUsed()) { in GenerateDirectMethodPrologue()
4097 CGF.EmitVarDecl(*OMD->getCmdDecl()); in GenerateDirectMethodPrologue()
4099 CGF.GetAddrOfLocalVar(OMD->getCmdDecl())); in GenerateDirectMethodPrologue()
4113 GV->setSection(Section); in CreateMetadataVar()
4124 llvm::Type *Ty = Init->getType(); in CreateMetadataVar()
4130 GV->setSection(Section); in CreateMetadataVar()
4131 GV->setAlignment(Align.getAsAlign()); in CreateMetadataVar()
4174 new llvm::GlobalVariable(CGM.getModule(), Value->getType(), in CreateCStringLiteral()
4178 GV->setSection(Section); in CreateCStringLiteral()
4179 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in CreateCStringLiteral()
4180 GV->setAlignment(CharUnits::One().getAsAlign()); in CreateCStringLiteral()
4276 CGF.EmitStmt(FinallyStmt->getFinallyBody()); in Emit()
4316 /// Create the fragile-ABI read and write hazards based on the current
4328 I = CGF.CurFn->begin(), E = CGF.CurFn->end(); I != E; ++I) in FragileHazards()
4333 // Create a read hazard for the allocas. This inhibits dead-store in FragileHazards()
4369 Call->addParamAttr(Pair.index(), llvm::Attribute::get( in emitWriteHazard()
4371 cast<llvm::AllocaInst>(Pair.value())->getAllocatedType())); in emitWriteHazard()
4377 call->setDoesNotThrow(); in emitReadHazard()
4378 call->setCallingConv(CGF.getRuntimeCC()); in emitReadHazard()
4380 call->addParamAttr(Pair.index(), llvm::Attribute::get( in emitReadHazard()
4382 cast<llvm::AllocaInst>(Pair.value())->getAllocatedType())); in emitReadHazard()
4394 FI = CGF.CurFn->begin(), FE = CGF.CurFn->end(); FI != FE; ++FI) { in emitHazardsInNewBlocks()
4403 // Ignore instructions that aren't non-intrinsic calls. in emitHazardsInNewBlocks()
4440 llvm::BasicBlock &Entry = CGF.CurFn->getEntryBlock(); in collectLocals() local
4442 I = Entry.begin(), E = Entry.end(); I != E; ++I) in collectLocals()
4450 tys[i] = Locals[i]->getType(); in GetAsmFnType()
4456 Objective-C setjmp-longjmp (sjlj) Exception Handling
4457 --
4460 - a pointer to the exception that was caught
4461 - a pointer to the previous exception data buffer
4462 - two pointers of reserved storage
4464 of the stack kept in thread-local storage.
4476 There's no reason an implementation couldn't use a light-weight
4477 setjmp here --- something like __builtin_setjmp, but API-compatible
4485 inhibit optimizing locals across the setjmp->catch edge.
4487 The basic framework for a @try-catch-finally is as follows:
4506 ... jump-through-finally to finally_rethrow ...
4511 ... jump-through-finally to finally_rethrow ...
4514 ... jump-through-finally to finally_end ...
4536 - If there are no catch blocks, then we avoid emitting the second
4539 - If there is a catch-all catch block (i.e. @catch(...) or @catch(id
4542 - FIXME: If there is no @finally block we can do a few more
4545 Rethrows and Jumps-Through-Finally
4546 --
4548 '@throw;' is supported by pushing the currently-caught exception
4552 normal cleanup. We do not register an EH cleanup; fragile-ABI ObjC
4566 // A destination for the fall-through edges of the catch handlers to in EmitTryOrSynchronizedStmt()
4588 SyncArgSlot = CGF.CreateTempAlloca(SyncArg->getType(), in EmitTryOrSynchronizedStmt()
4607 // - no catches match and we're branching through the cleanup in EmitTryOrSynchronizedStmt()
4609 // - a catch matched and we're falling out of the catch handler. in EmitTryOrSynchronizedStmt()
4610 // The setjmp-safety rule here is that we should always store to this in EmitTryOrSynchronizedStmt()
4629 // - Call objc_exception_try_enter to push ExceptionData on top of in EmitTryOrSynchronizedStmt()
4634 // - Call setjmp on the exception data buffer. in EmitTryOrSynchronizedStmt()
4642 SetJmpResult->setCanReturnTwice(); in EmitTryOrSynchronizedStmt()
4663 // Don't optimize loads of the in-scope locals across this point. in EmitTryOrSynchronizedStmt()
4669 // Tell the cleanup not to re-pop the exit. in EmitTryOrSynchronizedStmt()
4687 bool HasFinally = (AtTryStmt->getFinallyStmt() != nullptr); in EmitTryOrSynchronizedStmt()
4692 // Save the currently-propagating exception before in EmitTryOrSynchronizedStmt()
4694 PropagatingExnVar = CGF.CreateTempAlloca(Caught->getType(), in EmitTryOrSynchronizedStmt()
4707 SetJmpResult->setCanReturnTwice(); in EmitTryOrSynchronizedStmt()
4725 for (const ObjCAtCatchStmt *CatchStmt : AtTryStmt->catch_stmts()) { in EmitTryOrSynchronizedStmt()
4726 const VarDecl *CatchParam = CatchStmt->getCatchParamDecl(); in EmitTryOrSynchronizedStmt()
4733 OPT = CatchParam->getType()->getAs<ObjCObjectPointerType>(); in EmitTryOrSynchronizedStmt()
4739 if (OPT && (OPT->isObjCIdType() || OPT->isObjCQualifiedIdType())) in EmitTryOrSynchronizedStmt()
4743 // If this is a catch-all, we don't need to test anything. in EmitTryOrSynchronizedStmt()
4755 CGF.EmitStmt(CatchStmt->getCatchBody()); in EmitTryOrSynchronizedStmt()
4764 assert(OPT && "Unexpected non-object pointer type in @catch"); in EmitTryOrSynchronizedStmt()
4765 const ObjCObjectType *ObjTy = OPT->getObjectType(); in EmitTryOrSynchronizedStmt()
4768 ObjCInterfaceDecl *IDecl = ObjTy->getInterface(); in EmitTryOrSynchronizedStmt()
4769 assert(IDecl && "Catch parameter must have Objective-C type!"); in EmitTryOrSynchronizedStmt()
4798 CGF.ConvertType(CatchParam->getType())); in EmitTryOrSynchronizedStmt()
4801 CGF.EmitStmt(CatchStmt->getCatchBody()); in EmitTryOrSynchronizedStmt()
4815 if (Caught->use_empty()) in EmitTryOrSynchronizedStmt()
4816 Caught->eraseFromParent(); in EmitTryOrSynchronizedStmt()
4826 // unnecessary because there's no local-accessing code between in EmitTryOrSynchronizedStmt()
4831 // propagating-exception slot. in EmitTryOrSynchronizedStmt()
4858 // If we have a propagating-exception variable, check it. in EmitTryOrSynchronizedStmt()
4894 ->setDoesNotReturn(); in EmitThrowStmt()
4902 /// EmitObjCWeakRead - Code gen for loading value of a __weak
4917 /// EmitObjCWeakAssign - Code gen for assigning to a __weak object.
4922 llvm::Type * SrcTy = src->getType(); in EmitObjCWeakAssign()
4938 /// EmitObjCGlobalAssign - Code gen for assigning to a __strong object.
4944 llvm::Type * SrcTy = src->getType(); in EmitObjCGlobalAssign()
4964 /// EmitObjCIvarAssign - Code gen for assigning to a __strong object.
4970 assert(ivarOffset && "EmitObjCIvarAssign - ivarOffset is NULL"); in EmitObjCIvarAssign()
4971 llvm::Type * SrcTy = src->getType(); in EmitObjCIvarAssign()
4986 /// EmitObjCStrongCastAssign - Code gen for assigning to a __strong cast object.
4991 llvm::Type * SrcTy = src->getType(); in EmitObjCStrongCastAssign()
5015 /// EmitObjCValueForIvar - Code Gen for ivar reference.
5023 ObjectTy->castAs<ObjCObjectType>()->getInterface(); in EmitObjCValueForIvar()
5061 "Objective-C support is unimplemented for object file format"); in GetSectionName()
5067 /// EmitImageInfo - Emit the image info marker used to encode some module
5096 // Generate module-level named metadata to convey this information to the in EmitImageInfo()
5097 // linker and code-gen. in EmitImageInfo()
5101 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Version", ObjCABI); in EmitImageInfo()
5102 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Image Info Version", in EmitImageInfo()
5104 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Image Info Section", in EmitImageInfo()
5109 // Non-GC overrides those files which specify GC. in EmitImageInfo()
5111 "Objective-C Garbage Collection", in EmitImageInfo()
5116 "Objective-C Garbage Collection", in EmitImageInfo()
5122 Mod.addModuleFlag(llvm::Module::Error, "Objective-C GC Only", in EmitImageInfo()
5127 llvm::MDString::get(VMContext, "Objective-C Garbage Collection"), in EmitImageInfo()
5130 Mod.addModuleFlag(llvm::Module::Require, "Objective-C GC Only", in EmitImageInfo()
5137 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Is Simulated", in EmitImageInfo()
5141 Mod.addModuleFlag(llvm::Module::Error, "Objective-C Class Properties", in EmitImageInfo()
5191 if (ObjCImplementationDecl *IMP = ID->getImplementation()) in EmitModuleSymbols()
5193 if (ID->isWeakImported() && !IMP->isWeakImported()) in EmitModuleSymbols()
5194 DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage); in EmitModuleSymbols()
5213 llvm::GlobalVariable *&Entry = ClassReferences[II]; in EmitClassRefFromId() local
5215 if (!Entry) { in EmitClassRefFromId()
5216 Entry = in EmitClassRefFromId()
5217 CreateMetadataVar("OBJC_CLASS_REFERENCES_", GetClassName(II->getName()), in EmitClassRefFromId()
5222 return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry, in EmitClassRefFromId()
5229 // use the Objective-C runtime to get the class. in EmitClassRef()
5230 if (ID->hasAttr<ObjCRuntimeVisibleAttr>()) in EmitClassRef()
5234 &CGM.getContext().Idents.get(ID->getObjCRuntimeNameAsString()); in EmitClassRef()
5250 llvm::GlobalVariable *&Entry = SelectorReferences[Sel]; in EmitSelectorAddr() local
5251 if (!Entry) { in EmitSelectorAddr()
5252 Entry = CreateMetadataVar( in EmitSelectorAddr()
5255 Entry->setExternallyInitialized(true); in EmitSelectorAddr()
5258 return ConstantAddress(Entry, ObjCTypes.SelectorPtrTy, Align); in EmitSelectorAddr()
5262 llvm::GlobalVariable *&Entry = ClassNames[RuntimeName]; in GetClassName() local
5263 if (!Entry) in GetClassName()
5264 Entry = CreateCStringLiteral(RuntimeName, ObjCLabelType::ClassName); in GetClassName()
5265 return getConstantGEP(VMContext, Entry, 0, 0); in GetClassName()
5272 /// GetIvarLayoutName - Returns a unique constant for the given
5281 const RecordDecl *RD = RT->getDecl(); in visitRecord()
5285 if (RD->isUnion()) in visitRecord()
5289 visitAggregate(RD->field_begin(), RD->field_end(), offset, in visitRecord()
5290 [&](const FieldDecl *field) -> CharUnits { in visitRecord()
5293 auto offsetInBits = recLayout->getFieldOffset(field->getFieldIndex()); in visitRecord()
5306 if (field->isBitField()) { in visitAggregate()
5320 QualType fieldType = field->getType(); in visitField()
5326 fieldType = arrayType->getElementType(); in visitField()
5330 numElts *= arrayType->getZExtSize(); in visitField()
5331 fieldType = arrayType->getElementType(); in visitField()
5334 assert(!fieldType->isArrayType() && "ivar of non-constant array type?"); in visitField()
5336 // If we ended up with a zero-sized array, we've done what we can do within in visitField()
5341 if (auto recType = fieldType->getAs<RecordType>()) { in visitField()
5346 // If we have an array, replicate the first entry's layout information. in visitField()
5347 auto numEltEntries = IvarsInfo.size() - oldEnd; in visitField()
5367 // If it matches what we're looking for, add an entry. in visitField()
5376 /// buildBitmap - This routine does the horsework of taking the offsets of
5410 unsigned claimed = std::min(MaxNibble - lastSkip, numWords); in buildBitmap()
5411 numWords -= claimed; in buildBitmap()
5419 numWords -= MaxNibble; in buildBitmap()
5435 unsigned claimed = std::min(MaxNibble - lastScan, numWords); in buildBitmap()
5436 numWords -= claimed; in buildBitmap()
5444 numWords -= MaxNibble; in buildBitmap()
5457 CharUnits beginOfScan = request.Offset - InstanceBegin; in buildBitmap()
5465 // isn't the true start of the ivars, because in the fragile-ARC case in buildBitmap()
5479 skip(beginOfScanInWords - endOfLastScanInWords); in buildBitmap()
5491 scan(endOfScanInWords - beginOfScanInWords); in buildBitmap()
5500 // or necessary for the ARC-style layout strings. in buildBitmap()
5503 (InstanceEnd - InstanceBegin + WordSize - CharUnits::One()) / WordSize; in buildBitmap()
5505 skip(lastOffsetInWords - endOfLastScanInWords); in buildBitmap()
5512 auto *Entry = CGObjC.CreateCStringLiteral( in buildBitmap() local
5514 return getConstantGEP(CGM.getLLVMContext(), Entry, 0, 0); in buildBitmap()
5517 /// BuildIvarLayout - Builds ivar layout bitmap for the class
5521 /// Each byte is divided up in two nibbles (4-bit each). Left nibble is count
5526 /// - id, Class
5527 /// - object *
5528 /// - __strong anything
5531 /// - __weak anything
5545 const ObjCInterfaceDecl *OI = OMD->getClassInterface(); in BuildIvarLayout()
5549 // inaccurately in the non-fragile ABI; the runtime knows how to fix this in BuildIvarLayout()
5552 // ARC layout strings only include the class's ivars. In non-fragile in BuildIvarLayout()
5560 for (const ObjCIvarDecl *IVD = OI->all_declared_ivar_begin(); in BuildIvarLayout()
5561 IVD; IVD = IVD->getNextIvar()) in BuildIvarLayout()
5587 [&](const ObjCIvarDecl *ivar) -> CharUnits { in BuildIvarLayout()
5600 OMD->getClassInterface()->getName().str().c_str()); in BuildIvarLayout()
5607 llvm::GlobalVariable *&Entry = MethodVarNames[Sel]; in GetMethodVarName() local
5609 if (!Entry) in GetMethodVarName()
5610 Entry = CreateCStringLiteral(Sel.getAsString(), ObjCLabelType::MethodVarName); in GetMethodVarName()
5611 return getConstantGEP(VMContext, Entry, 0, 0); in GetMethodVarName()
5621 CGM.getContext().getObjCEncodingForType(Field->getType(), TypeStr, Field); in GetMethodVarType()
5623 llvm::GlobalVariable *&Entry = MethodVarTypes[TypeStr]; in GetMethodVarType() local
5624 if (!Entry) in GetMethodVarType()
5625 Entry = CreateCStringLiteral(TypeStr, ObjCLabelType::MethodVarType); in GetMethodVarType()
5626 return getConstantGEP(VMContext, Entry, 0, 0); in GetMethodVarType()
5634 llvm::GlobalVariable *&Entry = MethodVarTypes[TypeStr]; in GetMethodVarType() local
5635 if (!Entry) in GetMethodVarType()
5636 Entry = CreateCStringLiteral(TypeStr, ObjCLabelType::MethodVarType); in GetMethodVarType()
5637 return getConstantGEP(VMContext, Entry, 0, 0); in GetMethodVarType()
5642 llvm::GlobalVariable *&Entry = PropertyNames[Ident]; in GetPropertyName() local
5643 if (!Entry) in GetPropertyName()
5644 Entry = CreateCStringLiteral(Ident->getName(), ObjCLabelType::PropertyName); in GetPropertyName()
5645 return getConstantGEP(VMContext, Entry, 0, 0); in GetPropertyName()
5663 for (auto &entry : Protocols) { in FinishModule() local
5664 llvm::GlobalVariable *global = entry.second; in FinishModule()
5665 if (global->hasInitializer()) in FinishModule()
5671 values.add(GetClassName(entry.first->getName())); in FinishModule()
5693 OS << "\t.objc_class_name_" << Sym->getName() << "=0\n" in FinishModule()
5694 << "\t.globl .objc_class_name_" << Sym->getName() << "\n"; in FinishModule()
5696 OS << "\t.lazy_reference .objc_class_name_" << Sym->getName() << "\n"; in FinishModule()
5756 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(), in ObjCCommonTypesHelper()
5759 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(), in ObjCCommonTypesHelper()
5762 RD->completeDefinition(); in ObjCCommonTypesHelper()
5845 ProtocolListTy->setBody(llvm::PointerType::getUnqual(ProtocolListTy), LongTy, in ObjCTypesHelper()
5855 ProtocolTy->setBody(ProtocolExtensionPtrTy, Int8PtrTy, in ObjCTypesHelper()
5905 ClassTy->setBody(llvm::PointerType::getUnqual(ClassTy), in ObjCTypesHelper()
5951 // specific. 18 is what's used on 32-bit X86. in ObjCTypesHelper()
6009 ProtocolListnfABITy->setBody(LongTy, in ObjCNonFragileABITypesHelper()
6057 // ImpnfABITy - LLVM for id (*)(id, SEL, ...) in ObjCNonFragileABITypesHelper()
6060 ->getPointerTo(); in ObjCNonFragileABITypesHelper()
6071 ClassnfABITy->setBody(llvm::PointerType::getUnqual(ClassnfABITy), in ObjCNonFragileABITypesHelper()
6098 // MessageRefTy - LLVM for: in ObjCNonFragileABITypesHelper()
6108 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(), in ObjCNonFragileABITypesHelper()
6111 RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), SourceLocation(), in ObjCNonFragileABITypesHelper()
6114 RD->completeDefinition(); in ObjCNonFragileABITypesHelper()
6120 // MessageRefPtrTy - LLVM for struct _message_ref_t* in ObjCNonFragileABITypesHelper()
6123 // SuperMessageRefTy - LLVM for: in ObjCNonFragileABITypesHelper()
6131 // SuperMessageRefPtrTy - LLVM for struct _super_message_ref_t* in ObjCNonFragileABITypesHelper()
6175 CGM.getModule(), Init->getType(), false, in AddModuleClassList()
6177 GV->setAlignment(CGM.getDataLayout().getABITypeAlign(Init->getType())); in AddModuleClassList()
6178 GV->setSection(SectionName); in AddModuleClassList()
6191 if (ObjCImplementationDecl *IMP = ID->getImplementation()) in FinishNonFragileABIModule()
6193 if (ID->isWeakImported() && !IMP->isWeakImported()) { in FinishNonFragileABIModule()
6194 DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage); in FinishNonFragileABIModule()
6195 DefinedMetaClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage); in FinishNonFragileABIModule()
6222 /// isVTableDispatchedSelector - Returns true if SEL is not in the list of
6224 /// except for the 19 selectors in the list, we generate 32bit-style
6227 // At various points we've experimented with using vtable-based in isVTableDispatchedSelector()
6238 // If so, see whether this selector is in the white-list of things which must in isVTableDispatchedSelector()
6248 // These are vtable-based if GC is disabled. in isVTableDispatchedSelector()
6264 // These are vtable-based if GC is enabled. in isVTableDispatchedSelector()
6283 /// BuildClassRoTInitializer - generate meta-data for:
6303 std::string ClassName = std::string(ID->getObjCRuntimeNameAsString()); in BuildClassRoTInitializer()
6323 values.add(GetClassName(ID->getObjCRuntimeNameAsString())); in BuildClassRoTInitializer()
6328 for (const auto *MD : ID->class_methods()) in BuildClassRoTInitializer()
6329 if (!MD->isDirectMethod()) in BuildClassRoTInitializer()
6332 for (const auto *MD : ID->instance_methods()) in BuildClassRoTInitializer()
6333 if (!MD->isDirectMethod()) in BuildClassRoTInitializer()
6337 values.add(emitMethodList(ID->getObjCRuntimeNameAsString(), in BuildClassRoTInitializer()
6343 const ObjCInterfaceDecl *OID = ID->getClassInterface(); in BuildClassRoTInitializer()
6346 + OID->getObjCRuntimeNameAsString(), in BuildClassRoTInitializer()
6347 OID->all_referenced_protocol_begin(), in BuildClassRoTInitializer()
6348 OID->all_referenced_protocol_end())); in BuildClassRoTInitializer()
6354 "_OBJC_$_CLASS_PROP_LIST_" + ID->getObjCRuntimeNameAsString(), in BuildClassRoTInitializer()
6355 ID, ID->getClassInterface(), ObjCTypes, true)); in BuildClassRoTInitializer()
6360 "_OBJC_$_PROP_LIST_" + ID->getObjCRuntimeNameAsString(), in BuildClassRoTInitializer()
6361 ID, ID->getClassInterface(), ObjCTypes, false)); in BuildClassRoTInitializer()
6407 GV->setSection("__DATA, __objc_data"); in BuildClassObject()
6408 GV->setAlignment(CGM.getDataLayout().getABITypeAlign(ObjCTypes.ClassnfABITy)); in BuildClassObject()
6411 GV->setVisibility(llvm::GlobalValue::HiddenVisibility); in BuildClassObject()
6417 return OD->getClassMethod(GetNullarySelector("load")) != nullptr || in ImplementationIsNonLazy()
6418 OD->getClassInterface()->hasAttr<ObjCNonLazyClassAttr>() || in ImplementationIsNonLazy()
6419 OD->hasAttr<ObjCNonLazyClassAttr>(); in ImplementationIsNonLazy()
6445 for (const auto *Result : DC->lookup(&II)) in getStorage()
6451 if (VD->hasAttr<DLLExportAttr>()) in getStorage()
6453 if (VD->hasAttr<DLLImportAttr>()) in getStorage()
6465 ObjCEmptyCacheVar->setDLLStorageClass(getStorage(CGM, "_objc_empty_cache")); in GenerateClass()
6476 llvm::ConstantPointerNull::get(ObjCTypes.ImpnfABITy->getPointerTo()); in GenerateClass()
6487 const auto *CI = ID->getClassInterface(); in GenerateClass()
6488 assert(CI && "CGObjCNonFragileABIMac::GenerateClass - class is 0"); in GenerateClass()
6492 ? !CI->hasAttr<DLLExportAttr>() in GenerateClass()
6493 : CI->getVisibility() == HiddenVisibility; in GenerateClass()
6499 if (ID->hasNonZeroConstructors() || ID->hasDestructors()) { in GenerateClass()
6501 if (!ID->hasNonZeroConstructors()) in GenerateClass()
6505 if (!CI->getSuperClass()) { in GenerateClass()
6513 const ObjCInterfaceDecl *Root = ID->getClassInterface(); in GenerateClass()
6514 while (const ObjCInterfaceDecl *Super = Root->getSuperClass()) in GenerateClass()
6517 const auto *Super = CI->getSuperClass(); in GenerateClass()
6536 if (ID->hasNonZeroConstructors() || ID->hasDestructors()) { in GenerateClass()
6541 // anything except zero-initialization during construction. This in GenerateClass()
6543 // also imagine there being C++ types with non-trivial default in GenerateClass()
6545 if (!ID->hasNonZeroConstructors()) in GenerateClass()
6552 if (!CI->getSuperClass()) { in GenerateClass()
6557 const auto *Super = CI->getSuperClass(); in GenerateClass()
6572 // Determine if this class is also "non-lazy". in GenerateClass()
6579 // Make sure method definition entries are all clear for next implementation. in GenerateClass()
6583 /// GenerateProtocolRef - This routine is called to generate code for
6589 /// which will hold address of the protocol meta-data.
6595 // of protocol's meta-data (not a reference to it!) in GenerateProtocolRef()
6596 assert(!PD->isNonRuntimeProtocol() && in GenerateProtocolRef()
6601 ProtocolName += PD->getObjCRuntimeNameAsString(); in GenerateProtocolRef()
6607 return CGF.Builder.CreateAlignedLoad(PTGV->getValueType(), PTGV, Align); in GenerateProtocolRef()
6608 PTGV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, in GenerateProtocolRef()
6611 PTGV->setSection(GetSectionName("__objc_protorefs", in GenerateProtocolRef()
6613 PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); in GenerateProtocolRef()
6614 PTGV->setAlignment(Align.getAsAlign()); in GenerateProtocolRef()
6616 PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolName)); in GenerateProtocolRef()
6618 return CGF.Builder.CreateAlignedLoad(PTGV->getValueType(), PTGV, Align); in GenerateProtocolRef()
6621 /// GenerateCategory - Build metadata for a category implementation.
6634 const ObjCInterfaceDecl *Interface = OCD->getClassInterface(); in GenerateCategory()
6638 ExtCatName += Interface->getObjCRuntimeNameAsString(); in GenerateCategory()
6640 ExtCatName += OCD->getNameAsString(); in GenerateCategory()
6644 values.add(GetClassName(OCD->getIdentifier()->getName())); in GenerateCategory()
6645 // meta-class entry symbol in GenerateCategory()
6648 (Interface->getObjCRuntimeNameAsString() + "_$_" + OCD->getName()).str(); in GenerateCategory()
6652 for (const auto *MD : OCD->methods()) { in GenerateCategory()
6653 if (MD->isDirectMethod()) in GenerateCategory()
6655 if (MD->isInstanceMethod()) { in GenerateCategory()
6670 instanceMethodList->isNullValue() && classMethodList->isNullValue(); in GenerateCategory()
6673 Interface->FindCategoryDeclaration(OCD->getIdentifier()); in GenerateCategory()
6677 << Interface->getObjCRuntimeNameAsString() << "_$_" << OCD->getName(); in GenerateCategory()
6680 Interface->getObjCRuntimeNameAsString() + "_$_" + in GenerateCategory()
6681 Category->getName(), in GenerateCategory()
6682 Category->protocol_begin(), Category->protocol_end()); in GenerateCategory()
6691 isEmptyCategory &= protocolList->isNullValue() && in GenerateCategory()
6692 propertyList->isNullValue() && in GenerateCategory()
6693 classPropertyList->isNullValue(); in GenerateCategory()
6714 if (Interface->hasAttr<ObjCClassStubAttr>()) in GenerateCategory()
6719 // Determine if this category is also "non-lazy". in GenerateCategory()
6722 // method definition entries must be clear for next implementation. in GenerateCategory()
6726 /// emitMethodConstant - Return a struct objc_method constant. If
6728 /// the method must have a definition registered with the runtime.
6738 auto method = builder.beginStruct(ObjCTypes.MethodTy); in emitMethodConstant() local
6739 method.add(GetMethodVarName(MD->getSelector())); in emitMethodConstant()
6740 method.add(GetMethodVarType(MD)); in emitMethodConstant()
6743 // Protocol methods have no implementation. So, this entry is always NULL. in emitMethodConstant()
6744 method.addNullPointer(ObjCTypes.Int8PtrProgramASTy); in emitMethodConstant()
6747 assert(fn && "no definition for method?"); in emitMethodConstant()
6748 method.add(fn); in emitMethodConstant()
6751 method.finishAndAddTo(builder); in emitMethodConstant()
6754 /// Build meta-data for method declarations.
6825 /// ObjCIvarOffsetVariable - Returns the ivar offset variable for
6830 const ObjCInterfaceDecl *Container = Ivar->getContainingInterface(); in ObjCIvarOffsetVariable()
6832 Name += Container->getObjCRuntimeNameAsString(); in ObjCIvarOffsetVariable()
6834 Name += Ivar->getName(); in ObjCIvarOffsetVariable()
6843 Ivar->getAccessControl() == ObjCIvarDecl::Private || in ObjCIvarOffsetVariable()
6844 Ivar->getAccessControl() == ObjCIvarDecl::Package; in ObjCIvarOffsetVariable()
6846 const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface(); in ObjCIvarOffsetVariable()
6848 if (ContainingID->hasAttr<DLLImportAttr>()) in ObjCIvarOffsetVariable()
6850 ->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); in ObjCIvarOffsetVariable()
6851 else if (ContainingID->hasAttr<DLLExportAttr>() && !IsPrivateOrPackage) in ObjCIvarOffsetVariable()
6853 ->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); in ObjCIvarOffsetVariable()
6864 IvarOffsetGV->setInitializer( in EmitIvarOffsetVar()
6866 IvarOffsetGV->setAlignment( in EmitIvarOffsetVar()
6872 if (Ivar->getAccessControl() == ObjCIvarDecl::Private || in EmitIvarOffsetVar()
6873 Ivar->getAccessControl() == ObjCIvarDecl::Package || in EmitIvarOffsetVar()
6874 ID->getVisibility() == HiddenVisibility) in EmitIvarOffsetVar()
6875 IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility); in EmitIvarOffsetVar()
6877 IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility); in EmitIvarOffsetVar()
6884 IvarOffsetGV->setConstant(true); in EmitIvarOffsetVar()
6887 IvarOffsetGV->setSection("__DATA, __objc_ivar"); in EmitIvarOffsetVar()
6891 /// EmitIvarList - Emit the ivar list for the given
6918 const ObjCInterfaceDecl *OID = ID->getClassInterface(); in EmitIvarList()
6919 assert(OID && "CGObjCNonFragileABIMac::EmitIvarList - null interface"); in EmitIvarList()
6923 for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin(); in EmitIvarList()
6924 IVD; IVD = IVD->getNextIvar()) { in EmitIvarList()
6925 // Ignore unnamed bit-fields. in EmitIvarList()
6926 if (!IVD->getDeclName()) in EmitIvarList()
6930 ivar.add(EmitIvarOffsetVar(ID->getClassInterface(), IVD, in EmitIvarList()
6932 ivar.add(GetMethodVarName(IVD->getIdentifier())); in EmitIvarList()
6935 CGM.getTypes().ConvertTypeForMem(IVD->getType()); in EmitIvarList()
6938 IVD->getType().getTypePtr()) >> 3; in EmitIvarList()
6962 ivarList, Prefix + OID->getObjCRuntimeNameAsString(), CGM); in EmitIvarList()
6969 llvm::GlobalVariable *&Entry = Protocols[PD->getIdentifier()]; in GetOrEmitProtocolRef() local
6971 assert(!PD->isNonRuntimeProtocol() && in GetOrEmitProtocolRef()
6972 "attempting to GetOrEmit a non-runtime protocol"); in GetOrEmitProtocolRef()
6973 if (!Entry) { in GetOrEmitProtocolRef()
6979 << PD->getObjCRuntimeNameAsString(); in GetOrEmitProtocolRef()
6981 Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy, in GetOrEmitProtocolRef()
6985 Entry->setComdat(CGM.getModule().getOrInsertComdat(Protocol)); in GetOrEmitProtocolRef()
6988 return Entry; in GetOrEmitProtocolRef()
6991 /// GetOrEmitProtocol - Generate the protocol meta-data:
7013 llvm::GlobalVariable *Entry = Protocols[PD->getIdentifier()]; in GetOrEmitProtocol() local
7016 if (Entry && Entry->hasInitializer()) in GetOrEmitProtocol()
7017 return Entry; in GetOrEmitProtocol()
7020 assert(PD->hasDefinition() && in GetOrEmitProtocol()
7022 PD = PD->getDefinition(); in GetOrEmitProtocol()
7031 values.add(GetClassName(PD->getObjCRuntimeNameAsString())); in GetOrEmitProtocol()
7033 + PD->getObjCRuntimeNameAsString(), in GetOrEmitProtocol()
7034 PD->protocol_begin(), in GetOrEmitProtocol()
7035 PD->protocol_end())); in GetOrEmitProtocol()
7045 "_OBJC_$_PROP_LIST_" + PD->getObjCRuntimeNameAsString(), in GetOrEmitProtocol()
7052 + PD->getObjCRuntimeNameAsString(), in GetOrEmitProtocol()
7060 "_OBJC_$_CLASS_PROP_LIST_" + PD->getObjCRuntimeNameAsString(), in GetOrEmitProtocol()
7063 if (Entry) { in GetOrEmitProtocol()
7065 Entry->setLinkage(llvm::GlobalValue::WeakAnyLinkage); in GetOrEmitProtocol()
7066 values.finishAndSetAsInitializer(Entry); in GetOrEmitProtocol()
7070 << "_OBJC_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString(); in GetOrEmitProtocol()
7072 Entry = values.finishAndCreateGlobal(symbolName, CGM.getPointerAlign(), in GetOrEmitProtocol()
7076 Entry->setComdat(CGM.getModule().getOrInsertComdat(symbolName)); in GetOrEmitProtocol()
7078 Protocols[PD->getIdentifier()] = Entry; in GetOrEmitProtocol()
7080 Entry->setVisibility(llvm::GlobalValue::HiddenVisibility); in GetOrEmitProtocol()
7081 CGM.addUsedGlobal(Entry); in GetOrEmitProtocol()
7083 // Use this protocol meta-data to build protocol list table in section in GetOrEmitProtocol()
7087 << PD->getObjCRuntimeNameAsString(); in GetOrEmitProtocol()
7091 false, llvm::GlobalValue::WeakAnyLinkage, Entry, in GetOrEmitProtocol()
7094 PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolRef)); in GetOrEmitProtocol()
7095 PTGV->setAlignment( in GetOrEmitProtocol()
7097 PTGV->setSection(GetSectionName("__objc_protolist", in GetOrEmitProtocol()
7099 PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); in GetOrEmitProtocol()
7101 return Entry; in GetOrEmitProtocol()
7104 /// EmitProtocolList - Generate protocol list meta-data:
7144 // A null-terminated array of protocols. in EmitProtocolList()
7159 /// EmitObjCValueForIvar - Code Gen for nonfragile ivar reference.
7171 ObjCInterfaceDecl *ID = ObjectTy->castAs<ObjCObjectType>()->getInterface(); in EmitObjCValueForIvar()
7185 ComputeIvarBaseOffset(CGM, Interface->getImplementation(), Ivar)); in EmitIvarOffset()
7189 CGF.Builder.CreateAlignedLoad(GV->getValueType(), GV, in EmitIvarOffset()
7193 ->setMetadata(llvm::LLVMContext::MD_invariant_load, in EmitIvarOffset()
7219 /// Emit a "vtable" message send. We emit a weak hidden-visibility
7225 /// substitutes a stub function which simply tail-calls through the
7227 /// which tail-calls objc_msgSend. Both stubs adjust the selector
7238 const ObjCMethodDecl *method) { in EmitVTableMessageSend() argument
7242 // First argument: the receiver / super-call structure. in EmitVTableMessageSend()
7253 MessageSendInfo MSI = getMessageSendInfo(method, resultType, args); in EmitVTableMessageSend()
7262 // except normal, non-super message-sends. in EmitVTableMessageSend()
7306 messageRef->setVisibility(llvm::GlobalValue::HiddenVisibility); in EmitVTableMessageSend()
7307 messageRef->setSection(GetSectionName("__objc_msgrefs", "coalesced")); in EmitVTableMessageSend()
7311 if (CGM.getLangOpts().ObjCAutoRefCount && method) in EmitVTableMessageSend()
7312 for (const auto *ParamDecl : method->parameters()) { in EmitVTableMessageSend()
7313 if (ParamDecl->isDestroyedInCallee()) { in EmitVTableMessageSend()
7337 requiresnullCheck ? method : nullptr); in EmitVTableMessageSend()
7349 const ObjCMethodDecl *Method) { in GenerateMessageSend() argument
7353 false, CallArgs, Method) in GenerateMessageSend()
7356 false, CallArgs, Method, Class, ObjCTypes); in GenerateMessageSend()
7365 return GetClassGlobal((prefix + ID->getObjCRuntimeNameAsString()).str(), in GetClassGlobal()
7367 ID->isWeakImported(), in GetClassGlobal()
7370 && ID->hasAttr<DLLImportAttr>()); in GetClassGlobal()
7382 if (!GV || GV->getValueType() != ObjCTypes.ClassnfABITy) { in GetClassGlobal()
7387 NewGV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); in GetClassGlobal()
7390 GV->replaceAllUsesWith(NewGV); in GetClassGlobal()
7391 GV->eraseFromParent(); in GetClassGlobal()
7397 assert(GV->getLinkage() == L); in GetClassGlobal()
7406 if (!ID->hasAttr<ObjCClassStubAttr>()) in GetClassGlobalForClassRef()
7411 // Stub classes are pointer-aligned. Classrefs pointing at stub classes in GetClassGlobalForClassRef()
7420 llvm::GlobalVariable *Entry) { in EmitLoadOfClassRef() argument
7421 if (ID && ID->hasAttr<ObjCClassStubAttr>()) { in EmitLoadOfClassRef()
7422 // Classrefs pointing at Objective-C stub classes must be loaded by calling in EmitLoadOfClassRef()
7425 ObjCTypes.getLoadClassrefFn(), Entry, "load_classref_result"); in EmitLoadOfClassRef()
7429 return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry, Align); in EmitLoadOfClassRef()
7436 llvm::GlobalVariable *&Entry = ClassReferences[II]; in EmitClassRefFromId() local
7438 if (!Entry) { in EmitClassRefFromId()
7443 ClassGV = GetClassGlobal((getClassSymbolPrefix() + II->getName()).str(), in EmitClassRefFromId()
7445 assert(ClassGV->getType() == ObjCTypes.ClassnfABIPtrTy && in EmitClassRefFromId()
7451 Entry = new llvm::GlobalVariable( in EmitClassRefFromId()
7452 CGM.getModule(), ClassGV->getType(), false, in EmitClassRefFromId()
7455 Entry->setAlignment(CGF.getPointerAlign().getAsAlign()); in EmitClassRefFromId()
7456 if (!ID || !ID->hasAttr<ObjCClassStubAttr>()) in EmitClassRefFromId()
7457 Entry->setSection(SectionName); in EmitClassRefFromId()
7459 CGM.addCompilerUsedGlobal(Entry); in EmitClassRefFromId()
7462 return EmitLoadOfClassRef(CGF, ID, Entry); in EmitClassRefFromId()
7468 // use the Objective-C runtime to get the class. in EmitClassRef()
7469 if (ID->hasAttr<ObjCRuntimeVisibleAttr>()) in EmitClassRef()
7472 return EmitClassRefFromId(CGF, ID->getIdentifier(), ID); in EmitClassRef()
7484 llvm::GlobalVariable *&Entry = SuperClassReferences[ID->getIdentifier()]; in EmitSuperClassRef() local
7486 if (!Entry) { in EmitSuperClassRef()
7490 Entry = new llvm::GlobalVariable(CGM.getModule(), ClassGV->getType(), false, in EmitSuperClassRef()
7493 Entry->setAlignment(CGF.getPointerAlign().getAsAlign()); in EmitSuperClassRef()
7494 Entry->setSection(SectionName); in EmitSuperClassRef()
7495 CGM.addCompilerUsedGlobal(Entry); in EmitSuperClassRef()
7498 return EmitLoadOfClassRef(CGF, ID, Entry); in EmitSuperClassRef()
7501 /// EmitMetaClassRef - Return a Value * of the address of _class_t
7502 /// meta-data
7508 llvm::GlobalVariable * &Entry = MetaClassReferences[ID->getIdentifier()]; in EmitMetaClassRef() local
7509 if (!Entry) { in EmitMetaClassRef()
7513 Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassnfABIPtrTy, in EmitMetaClassRef()
7516 Entry->setAlignment(Align.getAsAlign()); in EmitMetaClassRef()
7517 Entry->setSection(SectionName); in EmitMetaClassRef()
7518 CGM.addCompilerUsedGlobal(Entry); in EmitMetaClassRef()
7521 return CGF.Builder.CreateAlignedLoad(ObjCTypes.ClassnfABIPtrTy, Entry, Align); in EmitMetaClassRef()
7524 /// GetClass - Return a reference to the class for the given interface
7528 if (ID->isWeakImported()) { in GetClass()
7532 cast<llvm::GlobalVariable>(ClassGV)->hasExternalWeakLinkage()); in GetClass()
7540 /// which class's method should be called.
7551 const ObjCMethodDecl *Method) { in GenerateMessageSendSuper() argument
7566 Target = EmitMetaClassRef(CGF, Class, Class->isWeakImported()); in GenerateMessageSendSuper()
7580 true, CallArgs, Method) in GenerateMessageSendSuper()
7583 true, CallArgs, Method, Class, ObjCTypes); in GenerateMessageSendSuper()
7591 LI->setMetadata(llvm::LLVMContext::MD_invariant_load, in EmitSelector()
7597 llvm::GlobalVariable *&Entry = SelectorReferences[Sel]; in EmitSelectorAddr() local
7599 if (!Entry) { in EmitSelectorAddr()
7602 Entry = new llvm::GlobalVariable( in EmitSelectorAddr()
7606 Entry->setExternallyInitialized(true); in EmitSelectorAddr()
7607 Entry->setSection(SectionName); in EmitSelectorAddr()
7608 Entry->setAlignment(Align.getAsAlign()); in EmitSelectorAddr()
7609 CGM.addCompilerUsedGlobal(Entry); in EmitSelectorAddr()
7612 return ConstantAddress(Entry, ObjCTypes.SelectorPtrTy, Align); in EmitSelectorAddr()
7615 /// EmitObjCIvarAssign - Code gen for assigning to a __strong object.
7622 llvm::Type * SrcTy = src->getType(); in EmitObjCIvarAssign()
7637 /// EmitObjCStrongCastAssign - Code gen for assigning to a __strong cast object.
7643 llvm::Type * SrcTy = src->getType(); in EmitObjCStrongCastAssign()
7667 /// EmitObjCWeakRead - Code gen for loading value of a __weak
7683 /// EmitObjCWeakAssign - Code gen for assigning to a __weak object.
7688 llvm::Type * SrcTy = src->getType(); in EmitObjCWeakAssign()
7704 /// EmitObjCGlobalAssign - Code gen for assigning to a __strong object.
7710 llvm::Type * SrcTy = src->getType(); in EmitObjCGlobalAssign()
7740 if (T->isObjCIdType() || T->isObjCQualifiedIdType()) { in GetEHType()
7748 IDEHType->setDLLStorageClass(getStorage(CGM, "OBJC_EHTYPE_id")); in GetEHType()
7753 // All other types should be Objective-C interface pointer types. in GetEHType()
7754 const ObjCObjectPointerType *PT = T->getAs<ObjCObjectPointerType>(); in GetEHType()
7757 const ObjCInterfaceType *IT = PT->getInterfaceType(); in GetEHType()
7760 return GetInterfaceEHType(IT->getDecl(), NotForDefinition); in GetEHType()
7770 /// EmitThrowStmt - Generate code for a throw statement.
7779 Call->setDoesNotReturn(); in EmitThrowStmt()
7783 Call->setDoesNotReturn(); in EmitThrowStmt()
7794 llvm::GlobalVariable * &Entry = EHTypeReferences[ID->getIdentifier()]; in GetInterfaceEHType() local
7795 StringRef ClassName = ID->getObjCRuntimeNameAsString(); in GetInterfaceEHType()
7797 // If we don't need a definition, return the entry if found or check in GetInterfaceEHType()
7800 if (Entry) in GetInterfaceEHType()
7801 return Entry; in GetInterfaceEHType()
7807 Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.EHTypeTy, in GetInterfaceEHType()
7810 CGM.setGVProperties(Entry, ID); in GetInterfaceEHType()
7811 return Entry; in GetInterfaceEHType()
7815 // Otherwise we need to either make a new entry or fill in the initializer. in GetInterfaceEHType()
7816 assert((!Entry || !Entry->hasInitializer()) && "Duplicate EHType definition"); in GetInterfaceEHType()
7826 VTableGV->setDLLStorageClass(getStorage(CGM, VTableName)); in GetInterfaceEHType()
7833 llvm::ConstantExpr::getInBoundsGetElementPtr(VTableGV->getValueType(), in GetInterfaceEHType()
7841 if (Entry) { in GetInterfaceEHType()
7842 values.finishAndSetAsInitializer(Entry); in GetInterfaceEHType()
7843 Entry->setAlignment(CGM.getPointerAlign().getAsAlign()); in GetInterfaceEHType()
7845 Entry = values.finishAndCreateGlobal("OBJC_EHTYPE_$_" + ClassName, in GetInterfaceEHType()
7850 CGM.setGVProperties(Entry, ID); in GetInterfaceEHType()
7852 assert(Entry->getLinkage() == L); in GetInterfaceEHType()
7855 if (ID->getVisibility() == HiddenVisibility) in GetInterfaceEHType()
7856 Entry->setVisibility(llvm::GlobalValue::HiddenVisibility); in GetInterfaceEHType()
7860 Entry->setSection("__DATA,__objc_const"); in GetInterfaceEHType()
7862 return Entry; in GetInterfaceEHType()