Lines Matching refs:CGM
51 static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,
56 static llvm::Constant *buildCopyHelper(CodeGenModule &CGM, in buildCopyHelper() argument
58 return CodeGenFunction(CGM).GenerateCopyHelperFunction(blockInfo); in buildCopyHelper()
62 static llvm::Constant *buildDisposeHelper(CodeGenModule &CGM, in buildDisposeHelper() argument
64 return CodeGenFunction(CGM).GenerateDestroyHelperFunction(blockInfo); in buildDisposeHelper()
120 CodeGenModule &CGM);
123 CodeGenModule &CGM) { in getBlockDescriptorName() argument
128 if (CGM.getLangOpts().Exceptions) in getBlockDescriptorName()
130 if (CGM.getCodeGenOpts().ObjCAutoRefCountExceptions) in getBlockDescriptorName()
135 findBlockCapturedManagedEntities(BlockInfo, CGM.getContext().getLangOpts(), in getBlockDescriptorName()
147 BlockInfo.BlockAlign, CGM); in getBlockDescriptorName()
153 BlockInfo.BlockAlign, CGM); in getBlockDescriptorName()
155 BlockInfo.BlockAlign, CGM); in getBlockDescriptorName()
162 CGM.getContext().getObjCEncodingForBlock(BlockInfo.getBlockExpr()); in getBlockDescriptorName()
167 Name += "l" + CGM.getObjCRuntime().getRCBlockLayoutStr(CGM, BlockInfo); in getBlockDescriptorName()
185 static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM, in buildBlockDescriptor() argument
187 ASTContext &C = CGM.getContext(); in buildBlockDescriptor()
190 cast<llvm::IntegerType>(CGM.getTypes().ConvertType(C.UnsignedLongTy)); in buildBlockDescriptor()
192 if (CGM.getLangOpts().OpenCL) in buildBlockDescriptor()
195 CGM.getLLVMContext(), C.getTargetAddressSpace(LangAS::opencl_constant)); in buildBlockDescriptor()
197 i8p = CGM.VoidPtrTy; in buildBlockDescriptor()
203 CGM.getLangOpts().getGC() == LangOptions::NonGC) { in buildBlockDescriptor()
204 descName = getBlockDescriptorName(blockInfo, CGM); in buildBlockDescriptor()
205 if (llvm::GlobalValue *desc = CGM.getModule().getNamedValue(descName)) in buildBlockDescriptor()
207 CGM.getBlockDescriptorType()); in buildBlockDescriptor()
212 ConstantInitBuilder builder(CGM); in buildBlockDescriptor()
228 llvm::Constant *copyHelper = buildCopyHelper(CGM, blockInfo); in buildBlockDescriptor()
232 llvm::Constant *disposeHelper = buildDisposeHelper(CGM, blockInfo); in buildBlockDescriptor()
243 CGM.getContext().getObjCEncodingForBlock(blockInfo.getBlockExpr()); in buildBlockDescriptor()
245 CGM.GetAddrOfConstantCString(typeAtEncoding).getPointer(), i8p)); in buildBlockDescriptor()
249 if (CGM.getLangOpts().getGC() != LangOptions::NonGC) in buildBlockDescriptor()
250 elements.add(CGM.getObjCRuntime().BuildGCBlockLayout(CGM, blockInfo)); in buildBlockDescriptor()
252 elements.add(CGM.getObjCRuntime().BuildRCBlockLayout(CGM, blockInfo)); in buildBlockDescriptor()
274 elements.finishAndCreateGlobal(descName, CGM.getPointerAlign(), in buildBlockDescriptor()
278 if (CGM.supportsCOMDAT()) in buildBlockDescriptor()
279 global->setComdat(CGM.getModule().getOrInsertComdat(descName)); in buildBlockDescriptor()
284 return llvm::ConstantExpr::getBitCast(global, CGM.getBlockDescriptorType()); in buildBlockDescriptor()
412 static llvm::Constant *tryCaptureAsConstant(CodeGenModule &CGM, in tryCaptureAsConstant() argument
430 if (CGM.getLangOpts().CPlusPlus && !isSafeForCXXConstantCapture(type)) in tryCaptureAsConstant()
439 return ConstantEmitter(CGM, CGF).tryEmitAbstractForInitializer(*var); in tryCaptureAsConstant()
448 static void initializeForBlockHeader(CodeGenModule &CGM, CGBlockInfo &info, in initializeForBlockHeader() argument
452 if (CGM.getLangOpts().OpenCL) { in initializeForBlockHeader()
456 CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic); in initializeForBlockHeader()
458 CharUnits::fromQuantity(CGM.getTarget().getPointerAlign(GenericAS) / 8); in initializeForBlockHeader()
460 CharUnits::fromQuantity(CGM.getTarget().getPointerWidth(GenericAS) / 8); in initializeForBlockHeader()
461 assert(CGM.getIntSize() <= GenPtrSize); in initializeForBlockHeader()
462 assert(CGM.getIntAlign() <= GenPtrAlign); in initializeForBlockHeader()
463 assert((2 * CGM.getIntSize()).isMultipleOf(GenPtrAlign)); in initializeForBlockHeader()
464 elementTypes.push_back(CGM.IntTy); /* total size */ in initializeForBlockHeader()
465 elementTypes.push_back(CGM.IntTy); /* align */ in initializeForBlockHeader()
467 CGM.getOpenCLRuntime() in initializeForBlockHeader()
470 2 * CGM.getIntSize().getQuantity() + GenPtrSize.getQuantity(); in initializeForBlockHeader()
473 CGM.getTargetCodeGenInfo().getTargetOpenCLBlockHelper()) { in initializeForBlockHeader()
477 unsigned Align = CGM.getDataLayout().getABITypeAlignment(I); in initializeForBlockHeader()
481 Offset += CGM.getDataLayout().getTypeAllocSize(I); in initializeForBlockHeader()
490 assert(CGM.getIntSize() <= CGM.getPointerSize()); in initializeForBlockHeader()
491 assert(CGM.getIntAlign() <= CGM.getPointerAlign()); in initializeForBlockHeader()
492 assert((2 * CGM.getIntSize()).isMultipleOf(CGM.getPointerAlign())); in initializeForBlockHeader()
493 info.BlockAlign = CGM.getPointerAlign(); in initializeForBlockHeader()
494 info.BlockSize = 3 * CGM.getPointerSize() + 2 * CGM.getIntSize(); in initializeForBlockHeader()
495 elementTypes.push_back(CGM.VoidPtrTy); in initializeForBlockHeader()
496 elementTypes.push_back(CGM.IntTy); in initializeForBlockHeader()
497 elementTypes.push_back(CGM.IntTy); in initializeForBlockHeader()
498 elementTypes.push_back(CGM.VoidPtrTy); in initializeForBlockHeader()
499 elementTypes.push_back(CGM.getBlockDescriptorType()); in initializeForBlockHeader()
522 static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF, in computeBlockInfo() argument
524 ASTContext &C = CGM.getContext(); in computeBlockInfo()
528 initializeForBlockHeader(CGM, info, elementTypes); in computeBlockInfo()
531 CGM.getTargetCodeGenInfo().getTargetOpenCLBlockHelper()) in computeBlockInfo()
536 llvm::StructType::get(CGM.getLLVMContext(), elementTypes, true); in computeBlockInfo()
541 CGM.getLangOpts().getGC() == LangOptions::NonGC) in computeBlockInfo()
559 llvm::Type *llvmType = CGM.getTypes().ConvertType(thisType); in computeBlockInfo()
560 auto TInfo = CGM.getContext().getTypeInfoInChars(thisType); in computeBlockInfo()
577 CharUnits align = CGM.getPointerAlign(); in computeBlockInfo()
584 layout.push_back(BlockLayoutChunk(align, CGM.getPointerSize(), in computeBlockInfo()
586 CGM.VoidPtrTy, variable->getType())); in computeBlockInfo()
592 if (llvm::Constant *constant = tryCaptureAsConstant(CGM, CGF, variable)) { in computeBlockInfo()
640 } else if (CGM.getLangOpts().CPlusPlus) { in computeBlockInfo()
657 CGM.getTypes().ConvertTypeForMem(VT); in computeBlockInfo()
666 llvm::StructType::get(CGM.getLLVMContext(), elementTypes, true); in computeBlockInfo()
743 elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty, in computeBlockInfo()
761 elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty, in computeBlockInfo()
774 llvm::StructType::get(CGM.getLLVMContext(), elementTypes, true); in computeBlockInfo()
784 if (llvm::Constant *Block = CGM.getAddrOfGlobalBlockIfEmitted(blockExpr)) in EmitBlockLiteral()
788 computeBlockInfo(CGM, this, blockInfo); in EmitBlockLiteral()
797 bool IsOpenCL = CGM.getContext().getLangOpts().OpenCL; in EmitBlockLiteral()
799 IsOpenCL ? CGM.getOpenCLRuntime().getGenericVoidPointerType() : VoidPtrTy; in EmitBlockLiteral()
802 CGM.getTarget().getPointerWidth( in EmitBlockLiteral()
803 CGM.getContext().getTargetAddressSpace(GenVoidPtrAddr)) / in EmitBlockLiteral()
807 CodeGenFunction BlockCGF{CGM, true}; in EmitBlockLiteral()
815 return CGM.getAddrOfGlobalBlockIfEmitted(blockInfo.BlockExpression); in EmitBlockLiteral()
830 ? CGM.getNSConcreteGlobalBlock() in EmitBlockLiteral()
831 : CGM.getNSConcreteStackBlock(); in EmitBlockLiteral()
835 descriptor = buildBlockDescriptor(CGM, blockInfo); in EmitBlockLiteral()
888 CGM.getTargetCodeGenInfo().getTargetOpenCLBlockHelper()) { in EmitBlockLiteral()
893 CGM.getDataLayout().getTypeAllocSize(I.first->getType())), in EmitBlockLiteral()
992 CGM.getCodeGenOpts().OptimizationLevel != 0) { in EmitBlockLiteral()
1059 CGM.getCodeGenOpts().OptimizationLevel != 0) { in EmitBlockLiteral()
1060 assert(CGM.getLangOpts().ObjCAutoRefCount && in EmitBlockLiteral()
1101 CGM.getOpenCLRuntime().recordBlockInfo(blockInfo.BlockExpression, InvokeFn, in EmitBlockLiteral()
1182 llvm::Type *GenBlockTy = CGM.getGenericBlockLiteralType(); in EmitBlockCallExpr()
1194 CGM.getOpenCLRuntime().getGenericVoidPointerType(); in EmitBlockCallExpr()
1205 Func = CGM.getOpenCLRuntime().getInvokeFunction(E->getCallee()); in EmitBlockCallExpr()
1230 CGM.getTypes().arrangeBlockFunctionCall(Args, FuncTy); in EmitBlockCallExpr()
1233 llvm::Type *BlockFTy = CGM.getTypes().GetFunctionType(FnInfo); in EmitBlockCallExpr()
1309 static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM, in buildGlobalBlock() argument
1316 assert(!CGM.getAddrOfGlobalBlockIfEmitted(blockInfo.BlockExpression) && in buildGlobalBlock()
1320 ConstantInitBuilder builder(CGM); in buildGlobalBlock()
1323 bool IsOpenCL = CGM.getLangOpts().OpenCL; in buildGlobalBlock()
1324 bool IsWindows = CGM.getTarget().getTriple().isOSWindows(); in buildGlobalBlock()
1328 fields.addNullPointer(CGM.Int8PtrPtrTy); in buildGlobalBlock()
1330 fields.add(CGM.getNSConcreteGlobalBlock()); in buildGlobalBlock()
1337 fields.addInt(CGM.IntTy, flags.getBitMask()); in buildGlobalBlock()
1340 fields.addInt(CGM.IntTy, 0); in buildGlobalBlock()
1342 fields.addInt(CGM.IntTy, blockInfo.BlockSize.getQuantity()); in buildGlobalBlock()
1343 fields.addInt(CGM.IntTy, blockInfo.BlockAlign.getQuantity()); in buildGlobalBlock()
1351 fields.add(buildBlockDescriptor(CGM, blockInfo)); in buildGlobalBlock()
1353 CGM.getTargetCodeGenInfo().getTargetOpenCLBlockHelper()) { in buildGlobalBlock()
1354 for (auto I : Helper->getCustomFieldValues(CGM, blockInfo)) { in buildGlobalBlock()
1360 if (CGM.getContext().getLangOpts().OpenCL) in buildGlobalBlock()
1361 AddrSpace = CGM.getContext().getTargetAddressSpace(LangAS::opencl_global); in buildGlobalBlock()
1372 auto *Init = llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy, in buildGlobalBlock()
1374 &CGM.getModule()); in buildGlobalBlock()
1375 llvm::IRBuilder<> b(llvm::BasicBlock::Create(CGM.getLLVMContext(), "entry", in buildGlobalBlock()
1377 b.CreateAlignedStore(CGM.getNSConcreteGlobalBlock(), in buildGlobalBlock()
1379 CGM.getPointerAlign().getAsAlign()); in buildGlobalBlock()
1383 auto *InitVar = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), in buildGlobalBlock()
1387 CGM.addUsedGlobal(InitVar); in buildGlobalBlock()
1392 CGM.getTypes().ConvertType(blockInfo.getBlockExpr()->getType()); in buildGlobalBlock()
1395 CGM.setAddrOfGlobalBlock(blockInfo.BlockExpression, Result); in buildGlobalBlock()
1396 if (CGM.getContext().getLangOpts().OpenCL) in buildGlobalBlock()
1397 CGM.getOpenCLRuntime().recordBlockInfo( in buildGlobalBlock()
1413 if (CGM.getCodeGenOpts().hasReducedDebugInfo()) { in setBlockContextParameter()
1481 IdentifierInfo *II = &CGM.getContext().Idents.get(".block_descriptor"); in GenerateBlockFunction()
1494 CGM.getTypes().arrangeBlockFunctionDeclaration(fnType, args); in GenerateBlockFunction()
1495 if (CGM.ReturnSlotInterferesWithArgs(fnInfo)) in GenerateBlockFunction()
1498 llvm::FunctionType *fnLLVMType = CGM.getTypes().GetFunctionType(fnInfo); in GenerateBlockFunction()
1500 StringRef name = CGM.getBlockMangledName(GD, blockDecl); in GenerateBlockFunction()
1502 fnLLVMType, llvm::GlobalValue::InternalLinkage, name, &CGM.getModule()); in GenerateBlockFunction()
1503 CGM.SetInternalFunctionAttributes(blockDecl, fn, fnInfo); in GenerateBlockFunction()
1507 ? CGM.getOpenCLRuntime().getGenericVoidPointerType() in GenerateBlockFunction()
1509 buildGlobalBlock(CGM, blockInfo, in GenerateBlockFunction()
1523 if (CGM.getCodeGenOpts().OptimizationLevel == 0) { in GenerateBlockFunction()
1585 if (CGM.getCodeGenOpts().hasReducedDebugInfo()) { in GenerateBlockFunction()
1738 CodeGenModule &CGM) { in getBlockCaptureStr() argument
1740 ASTContext &Ctx = CGM.getContext(); in getBlockCaptureStr()
1766 CGM.getCXXABI().getMangleContext().mangleTypeName(CaptureTy, Out); in getBlockCaptureStr()
1833 CharUnits BlockAlignment, CaptureStrKind StrKind, CodeGenModule &CGM) { in getCopyDestroyHelperFuncName() argument
1840 if (CGM.getLangOpts().Exceptions) in getCopyDestroyHelperFuncName()
1842 if (CGM.getCodeGenOpts().ObjCAutoRefCountExceptions) in getCopyDestroyHelperFuncName()
1848 Name += getBlockCaptureStr(E, StrKind, BlockAlignment, CGM); in getCopyDestroyHelperFuncName()
1899 CodeGenModule &CGM) { in setBlockHelperAttributesVisibility() argument
1901 CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI); in setBlockHelperAttributesVisibility()
1905 CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn, /*IsThunk=*/false); in setBlockHelperAttributesVisibility()
1906 CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn); in setBlockHelperAttributesVisibility()
1923 CaptureStrKind::CopyHelper, CGM); in GenerateCopyHelperFunction()
1925 if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName)) in GenerateCopyHelperFunction()
1939 CGM.getTypes().arrangeBuiltinFunctionDeclaration(ReturnTy, args); in GenerateCopyHelperFunction()
1943 llvm::FunctionType *LTy = CGM.getTypes().GetFunctionType(FI); in GenerateCopyHelperFunction()
1947 FuncName, &CGM.getModule()); in GenerateCopyHelperFunction()
1948 if (CGM.supportsCOMDAT()) in GenerateCopyHelperFunction()
1949 Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName)); in GenerateCopyHelperFunction()
1962 CGM); in GenerateCopyHelperFunction()
2010 if (CGM.getCodeGenOpts().OptimizationLevel == 0) { in GenerateCopyHelperFunction()
2040 EmitRuntimeCallOrInvoke(CGM.getBlockObjectAssign(), args); in GenerateCopyHelperFunction()
2042 EmitNounwindRuntimeCall(CGM.getBlockObjectAssign(), args); in GenerateCopyHelperFunction()
2120 CaptureStrKind::DisposeHelper, CGM); in GenerateDestroyHelperFunction()
2122 if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName)) in GenerateDestroyHelperFunction()
2134 CGM.getTypes().arrangeBuiltinFunctionDeclaration(ReturnTy, args); in GenerateDestroyHelperFunction()
2138 llvm::FunctionType *LTy = CGM.getTypes().GetFunctionType(FI); in GenerateDestroyHelperFunction()
2142 FuncName, &CGM.getModule()); in GenerateDestroyHelperFunction()
2143 if (CGM.supportsCOMDAT()) in GenerateDestroyHelperFunction()
2144 Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName)); in GenerateDestroyHelperFunction()
2157 CGM); in GenerateDestroyHelperFunction()
2212 llvm::FunctionCallee fn = CGF.CGM.getBlockObjectAssign(); in emitCopy()
2266 if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0) { in emitCopy()
2388 CGF.CGM.getTypes().arrangeBuiltinFunctionDeclaration(ReturnTy, args); in generateByrefCopyHelper()
2390 llvm::FunctionType *LTy = CGF.CGM.getTypes().GetFunctionType(FI); in generateByrefCopyHelper()
2396 "__Block_byref_object_copy_", &CGF.CGM.getModule()); in generateByrefCopyHelper()
2410 CGF.CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI); in generateByrefCopyHelper()
2442 static llvm::Constant *buildByrefCopyHelper(CodeGenModule &CGM, in buildByrefCopyHelper() argument
2445 CodeGenFunction CGF(CGM); in buildByrefCopyHelper()
2463 CGF.CGM.getTypes().arrangeBuiltinFunctionDeclaration(R, args); in generateByrefDisposeHelper()
2465 llvm::FunctionType *LTy = CGF.CGM.getTypes().GetFunctionType(FI); in generateByrefDisposeHelper()
2472 &CGF.CGM.getModule()); in generateByrefDisposeHelper()
2485 CGF.CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI); in generateByrefDisposeHelper()
2505 static llvm::Constant *buildByrefDisposeHelper(CodeGenModule &CGM, in buildByrefDisposeHelper() argument
2508 CodeGenFunction CGF(CGM); in buildByrefDisposeHelper()
2515 static T *buildByrefHelpers(CodeGenModule &CGM, const BlockByrefInfo &byrefInfo, in buildByrefHelpers() argument
2522 = CGM.ByrefHelpersCache.FindNodeOrInsertPos(id, insertPos); in buildByrefHelpers()
2525 generator.CopyHelper = buildByrefCopyHelper(CGM, byrefInfo, generator); in buildByrefHelpers()
2526 generator.DisposeHelper = buildByrefDisposeHelper(CGM, byrefInfo, generator); in buildByrefHelpers()
2528 T *copy = new (CGM.getContext()) T(std::forward<T>(generator)); in buildByrefHelpers()
2529 CGM.ByrefHelpersCache.InsertNode(copy, insertPos); in buildByrefHelpers()
2554 CGM.getContext().getBlockVarCopyInit(&var).getCopyExpr(); in buildByrefHelpers()
2558 CGM, byrefInfo, CXXByrefHelpers(valueAlignment, type, copyExpr)); in buildByrefHelpers()
2566 CGM, byrefInfo, NonTrivialCStructByrefHelpers(valueAlignment, type)); in buildByrefHelpers()
2587 return ::buildByrefHelpers(CGM, byrefInfo, in buildByrefHelpers()
2595 return ::buildByrefHelpers(CGM, byrefInfo, in buildByrefHelpers()
2601 return ::buildByrefHelpers(CGM, byrefInfo, in buildByrefHelpers()
2611 } else if (CGM.getContext().isObjCNSObjectType(type) || in buildByrefHelpers()
2621 return ::buildByrefHelpers(CGM, byrefInfo, in buildByrefHelpers()
2727 } else if (CGM.getDataLayout().getABITypeAlignment(varTy) in getBlockByrefInfo()
2814 if (CGM.getLangOpts().ObjCGCBitmapPrint) { in emitByrefStructureInit()
2837 CharUnits byrefSize = CGM.GetTargetTypeStoreSize(byrefType); in emitByrefStructureInit()
2849 auto layoutInfo = CGM.getObjCRuntime().BuildByrefLayout(CGM, type); in emitByrefStructureInit()
2856 llvm::FunctionCallee F = CGM.getBlockObjectDispose(); in BuildBlockRelease()
2876 static void configureBlocksRuntimeObject(CodeGenModule &CGM, in configureBlocksRuntimeObject() argument
2880 if (CGM.getTarget().getTriple().isOSBinFormatCOFF()) { in configureBlocksRuntimeObject()
2881 IdentifierInfo &II = CGM.getContext().Idents.get(C->getName()); in configureBlocksRuntimeObject()
2882 TranslationUnitDecl *TUDecl = CGM.getContext().getTranslationUnitDecl(); in configureBlocksRuntimeObject()
2905 if (CGM.getLangOpts().BlocksRuntimeOptional && GV->isDeclaration() && in configureBlocksRuntimeObject()
2909 CGM.setDSOLocal(GV); in configureBlocksRuntimeObject()