clang
3.7.0
|
#include "CGBlocks.h"
#include "CGDebugInfo.h"
#include "CGObjCRuntime.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "clang/AST/DeclObjC.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Module.h"
#include <algorithm>
#include <cstdio>
Go to the source code of this file.
Functions | |
static llvm::Constant * | buildGlobalBlock (CodeGenModule &CGM, const CGBlockInfo &blockInfo, llvm::Constant *blockFn) |
Build the given block as a global block. More... | |
static llvm::Constant * | buildCopyHelper (CodeGenModule &CGM, const CGBlockInfo &blockInfo) |
Build the helper function to copy a block. More... | |
static llvm::Constant * | buildDisposeHelper (CodeGenModule &CGM, const CGBlockInfo &blockInfo) |
Build the helper function to dispose of a block. More... | |
static llvm::Constant * | buildBlockDescriptor (CodeGenModule &CGM, const CGBlockInfo &blockInfo) |
static bool | isSafeForCXXConstantCapture (QualType type) |
Determines if the given type is safe for constant capture in C++. More... | |
static llvm::Constant * | tryCaptureAsConstant (CodeGenModule &CGM, CodeGenFunction *CGF, const VarDecl *var) |
static CharUnits | getLowBit (CharUnits v) |
static void | initializeForBlockHeader (CodeGenModule &CGM, CGBlockInfo &info, SmallVectorImpl< llvm::Type * > &elementTypes) |
static void | computeBlockInfo (CodeGenModule &CGM, CodeGenFunction *CGF, CGBlockInfo &info) |
static void | enterBlockScope (CodeGenFunction &CGF, BlockDecl *block) |
static CGBlockInfo * | findAndRemoveBlockInfo (CGBlockInfo **head, const BlockDecl *block) |
Find the layout for the given block in a linked list and remove it. More... | |
static llvm::Constant * | generateByrefCopyHelper (CodeGenFunction &CGF, llvm::StructType &byrefType, unsigned valueFieldIndex, CodeGenModule::ByrefHelpers &byrefInfo) |
static llvm::Constant * | buildByrefCopyHelper (CodeGenModule &CGM, llvm::StructType &byrefType, unsigned byrefValueIndex, CodeGenModule::ByrefHelpers &info) |
Build the copy helper for a __block variable. More... | |
static llvm::Constant * | generateByrefDisposeHelper (CodeGenFunction &CGF, llvm::StructType &byrefType, unsigned byrefValueIndex, CodeGenModule::ByrefHelpers &byrefInfo) |
Generate code for a __block variable's dispose helper. More... | |
static llvm::Constant * | buildByrefDisposeHelper (CodeGenModule &CGM, llvm::StructType &byrefType, unsigned byrefValueIndex, CodeGenModule::ByrefHelpers &info) |
Build the dispose helper for a __block variable. More... | |
template<class T > | |
static T * | buildByrefHelpers (CodeGenModule &CGM, llvm::StructType &byrefTy, unsigned byrefValueIndex, T &byrefInfo) |
static void | configureBlocksRuntimeObject (CodeGenModule &CGM, llvm::Constant *C) |
Adjust the declaration of something from the blocks API. More... | |
Variables | |
const unsigned | BlockHeaderSize = 5 |
The number of fields in a block header. More... | |
|
static |
buildBlockDescriptor - Build the block descriptor meta-data for a block. buildBlockDescriptor is accessed from 5th field of the Block_literal meta-data and contains stationary information about the block literal. Its definition will have 4 (or optinally 6) words.
Definition at line 76 of file CGBlocks.cpp.
References clang::CodeGen::CGBlockInfo::BlockSize, buildCopyHelper(), buildDisposeHelper(), clang::CodeGen::CGObjCRuntime::BuildGCBlockLayout(), clang::CodeGen::CGObjCRuntime::BuildRCBlockLayout(), AttributeLangSupport::C, clang::CodeGen::CodeGenTypes::ConvertType(), clang::CodeGen::CodeGenModule::GetAddrOfConstantCString(), clang::CodeGen::CodeGenModule::getBlockDescriptorType(), clang::CodeGen::CGBlockInfo::getBlockExpr(), clang::CodeGen::CodeGenModule::getContext(), clang::ASTContext::getLangOpts(), clang::CodeGen::CodeGenModule::getLangOpts(), clang::CodeGen::CodeGenModule::getLLVMContext(), clang::CodeGen::CodeGenModule::getModule(), clang::ASTContext::getObjCEncodingForBlock(), clang::CodeGen::CodeGenModule::getObjCRuntime(), clang::CharUnits::getQuantity(), clang::ASTContext::getTargetAddressSpace(), clang::CodeGen::CodeGenModule::getTypes(), clang::InternalLinkage, clang::CodeGen::CGBlockInfo::NeedsCopyDispose, clang::LangOptions::NonGC, NULL, clang::LangAS::opencl_constant, clang::ASTContext::UnsignedLongTy, and clang::ASTContext::VoidPtrTy.
Referenced by buildGlobalBlock(), and clang::CodeGen::CodeGenFunction::EmitBlockLiteral().
|
static |
Build the copy helper for a __block variable.
Definition at line 1827 of file CGBlocks.cpp.
References generateByrefCopyHelper().
Referenced by buildByrefHelpers().
|
static |
Build the dispose helper for a __block variable.
Definition at line 1888 of file CGBlocks.cpp.
References generateByrefDisposeHelper().
Referenced by buildByrefHelpers().
|
static |
Lazily build the copy and dispose helpers for a __block variable with the given information.
Definition at line 1898 of file CGBlocks.cpp.
References buildByrefCopyHelper(), buildByrefDisposeHelper(), clang::CodeGen::CodeGenModule::ByrefHelpersCache, clang::CharUnits::fromQuantity(), clang::CodeGen::CodeGenModule::getContext(), clang::ast_matchers::id(), and clang::CodeGen::CodeGenTypeCache::PointerAlignInBytes.
Referenced by clang::CodeGen::CodeGenFunction::emitByrefStructureInit().
|
static |
Build the helper function to copy a block.
Definition at line 51 of file CGBlocks.cpp.
References clang::CodeGen::CodeGenFunction::GenerateCopyHelperFunction().
Referenced by buildBlockDescriptor().
|
static |
Build the helper function to dispose of a block.
Definition at line 57 of file CGBlocks.cpp.
References clang::CodeGen::CodeGenFunction::GenerateDestroyHelperFunction().
Referenced by buildBlockDescriptor().
|
static |
Build the given block as a global block.
Definition at line 1063 of file CGBlocks.cpp.
References clang::CodeGen::BLOCK_HAS_SIGNATURE, clang::CodeGen::BLOCK_IS_GLOBAL, clang::CodeGen::BLOCK_USE_STRET, clang::CodeGen::CGBlockInfo::BlockAlign, BlockHeaderSize, buildBlockDescriptor(), clang::CodeGen::CGBlockInfo::CanBeGlobal, clang::CodeGen::CodeGenTypes::ConvertType(), clang::CodeGen::BlockFlags::getBitMask(), clang::CodeGen::CGBlockInfo::getBlockExpr(), clang::CodeGen::CodeGenModule::getModule(), clang::CodeGen::CodeGenModule::getNSConcreteGlobalBlock(), clang::CharUnits::getQuantity(), clang::Expr::getType(), clang::CodeGen::CodeGenModule::getTypes(), clang::InternalLinkage, clang::CodeGen::CodeGenTypeCache::IntTy, and clang::CodeGen::CGBlockInfo::UsesStret.
Referenced by clang::CodeGen::CodeGenFunction::EmitBlockLiteral(), and clang::CodeGen::CodeGenModule::GetAddrOfGlobalBlock().
|
static |
Compute the layout of the given block. Attempts to lay the block out with minimal space requirements.
Definition at line 337 of file CGBlocks.cpp.
References clang::CodeGen::CGBlockInfo::BlockAlign, clang::CodeGen::CGBlockInfo::BlockHeaderForcedGapOffset, clang::CodeGen::CGBlockInfo::BlockHeaderForcedGapSize, clang::CodeGen::CGBlockInfo::BlockSize, AttributeLangSupport::C, clang::CodeGen::CGBlockInfo::CanBeGlobal, clang::BlockDecl::capture_begin(), clang::BlockDecl::capture_end(), clang::CodeGen::CGBlockInfo::Captures, clang::BlockDecl::captures(), clang::BlockDecl::capturesCXXThis(), clang::CodeGen::CodeGenTypes::ConvertType(), clang::CodeGen::CodeGenTypes::ConvertTypeForMem(), clang::CodeGen::CodeGenFunction::CurFuncDecl, clang::Type::getAsCXXRecordDecl(), clang::CodeGen::CGBlockInfo::getBlockDecl(), clang::CodeGen::CodeGenModule::getContext(), clang::ASTContext::getDeclAlign(), clang::ASTContext::getLangOpts(), clang::CodeGen::CodeGenModule::getLangOpts(), clang::CodeGen::CodeGenModule::getLLVMContext(), getLowBit(), clang::QualType::getObjCLifetime(), clang::CharUnits::getQuantity(), clang::ValueDecl::getType(), clang::ASTContext::getTypeInfoInChars(), clang::CodeGen::CodeGenModule::getTypes(), clang::ASTContext::getTypeSizeInChars(), clang::CodeGen::CGBlockInfo::HasCapturedVariableLayout, clang::BlockDecl::hasCaptures(), clang::CodeGen::CGBlockInfo::HasCXXObject, initializeForBlockHeader(), clang::CodeGen::CodeGenTypeCache::Int8Ty, clang::Type::isObjCRetainableType(), clang::CodeGen::CGBlockInfo::Capture::makeConstant(), clang::CodeGen::CGBlockInfo::NeedsCopyDispose, clang::LangOptions::NonGC, clang::Qualifiers::OCL_Autoreleasing, clang::Qualifiers::OCL_ExplicitNone, clang::Qualifiers::OCL_None, clang::Qualifiers::OCL_Strong, clang::Qualifiers::OCL_Weak, clang::CharUnits::RoundUpToAlignment(), clang::CodeGen::CGBlockInfo::StructureType, tryCaptureAsConstant(), clang::ASTContext::VoidPtrTy, and clang::CharUnits::Zero().
Referenced by clang::CodeGen::CodeGenFunction::EmitBlockLiteral(), enterBlockScope(), and clang::CodeGen::CodeGenModule::GetAddrOfGlobalBlock().
|
static |
Adjust the declaration of something from the blocks API.
Definition at line 2267 of file CGBlocks.cpp.
References clang::CodeGen::CodeGenModule::getLangOpts().
Referenced by clang::CodeGen::CodeGenModule::getBlockObjectAssign(), clang::CodeGen::CodeGenModule::getBlockObjectDispose(), clang::CodeGen::CodeGenModule::getNSConcreteGlobalBlock(), and clang::CodeGen::CodeGenModule::getNSConcreteStackBlock().
|
static |
Enter the scope of a block. This should be run at the entrance to a full-expression so that the block's cleanups are pushed at the right place in the stack.
Definition at line 572 of file CGBlocks.cpp.
References clang::CodeGen::CodeGenFunction::Builder, clang::BlockDecl::captures(), clang::CodeGen::CodeGenFunction::CGM, computeBlockInfo(), clang::CodeGen::CodeGenFunction::CreateTempAlloca(), clang::CodeGen::CodeGenFunction::CurFn, clang::CodeGen::CodeGenFunction::destroyARCStrongImprecise, clang::QualType::DK_none, clang::QualType::DK_objc_strong_lifetime, clang::CodeGen::CodeGenFunction::EHStack, clang::CodeGen::CodeGenFunction::FirstBlockInfo, clang::CodeGen::CodeGenFunction::getDestroyer(), clang::CodeGen::CGBlockInfo::Capture::getIndex(), clang::ValueDecl::getType(), clang::CodeGen::CodeGenFunction::HaveInsertPoint(), clang::CodeGen::InactiveNormalAndEHCleanup, clang::CodeGen::InactiveNormalCleanup, clang::CodeGen::CGBlockInfo::Capture::isConstant(), clang::QualType::isDestructedType(), clang::CodeGen::CodeGenFunction::needsEHCleanup(), clang::CodeGen::CGBlockInfo::NextBlockInfo, clang::CodeGen::CodeGenFunction::pushDestroy(), clang::CodeGen::CGBlockInfo::Capture::setCleanup(), and clang::CodeGen::EHScopeStack::stable_begin().
Referenced by clang::CodeGen::CodeGenFunction::enterNonTrivialFullExpression().
|
static |
Find the layout for the given block in a linked list and remove it.
Definition at line 657 of file CGBlocks.cpp.
References clang::CodeGen::CGBlockInfo::getBlockDecl(), and clang::CodeGen::CGBlockInfo::NextBlockInfo.
Referenced by clang::CodeGen::CodeGenFunction::EmitBlockLiteral().
|
static |
Definition at line 1760 of file CGBlocks.cpp.
References clang::CodeGen::CodeGenTypes::arrangeFreeFunctionDeclaration(), clang::CodeGen::CodeGenFunction::Builder, clang::CodeGen::CodeGenFunction::CGM, clang::Create(), clang::FunctionDecl::Create(), clang::CodeGen::CodeGenModule::ByrefHelpers::emitCopy(), clang::CodeGen::CodeGenFunction::FinishFunction(), clang::IdentifierTable::get(), clang::CodeGen::CodeGenFunction::GetAddrOfLocalVar(), clang::CodeGen::CodeGenFunction::getContext(), clang::CodeGen::CodeGenTypes::GetFunctionType(), clang::CodeGen::CodeGenModule::getModule(), clang::ASTContext::getTranslationUnitDecl(), clang::CodeGen::CodeGenModule::getTypes(), clang::ASTContext::Idents, clang::CodeGen::CodeGenTypeCache::Int8PtrTy, clang::InternalLinkage, clang::CodeGen::CodeGenModule::ByrefHelpers::needsCopy(), clang::SC_Static, clang::CodeGen::CodeGenFunction::StartFunction(), clang::ASTContext::VoidPtrTy, and clang::ASTContext::VoidTy.
Referenced by buildByrefCopyHelper().
|
static |
Generate code for a __block variable's dispose helper.
Definition at line 1837 of file CGBlocks.cpp.
References clang::CodeGen::CodeGenTypes::arrangeFreeFunctionDeclaration(), clang::CodeGen::CodeGenFunction::Builder, clang::CodeGen::CodeGenFunction::CGM, clang::Create(), clang::FunctionDecl::Create(), clang::CodeGen::CodeGenModule::ByrefHelpers::emitDispose(), clang::CodeGen::CodeGenFunction::FinishFunction(), clang::IdentifierTable::get(), clang::CodeGen::CodeGenFunction::GetAddrOfLocalVar(), clang::CodeGen::CodeGenFunction::getContext(), clang::CodeGen::CodeGenTypes::GetFunctionType(), clang::CodeGen::CodeGenModule::getModule(), clang::ASTContext::getTranslationUnitDecl(), clang::CodeGen::CodeGenModule::getTypes(), clang::ASTContext::Idents, clang::CodeGen::CodeGenTypeCache::Int8PtrTy, clang::InternalLinkage, clang::CodeGen::CodeGenModule::ByrefHelpers::needsDispose(), clang::SC_Static, clang::CodeGen::CodeGenFunction::StartFunction(), clang::ASTContext::VoidPtrTy, and clang::ASTContext::VoidTy.
Referenced by buildByrefDisposeHelper().
Get the low bit of a nonzero character count. This is the alignment of the nth byte if the 0th byte is universally aligned.
Definition at line 299 of file CGBlocks.cpp.
References clang::CharUnits::fromQuantity(), and clang::CharUnits::getQuantity().
Referenced by computeBlockInfo().
|
static |
Definition at line 303 of file CGBlocks.cpp.
References clang::CodeGen::CGBlockInfo::BlockAlign, BlockHeaderSize, clang::CodeGen::CGBlockInfo::BlockSize, AttributeLangSupport::C, clang::CodeGen::CodeGenTypes::ConvertType(), clang::CodeGen::CodeGenModule::getBlockDescriptorType(), clang::CodeGen::CodeGenModule::getContext(), clang::ASTContext::getTypeInfoInChars(), clang::CodeGen::CodeGenModule::getTypes(), clang::ASTContext::IntTy, and clang::ASTContext::VoidPtrTy.
Referenced by computeBlockInfo().
Determines if the given type is safe for constant capture in C++.
Definition at line 248 of file CGBlocks.cpp.
References clang::Type::getAs(), clang::Type::getBaseElementTypeUnsafe(), and clang::RecordType::getDecl().
Referenced by tryCaptureAsConstant().
|
static |
It is illegal to modify a const object after initialization. Therefore, if a const object has a constant initializer, we don't actually need to keep storage for it in the block; we'll just rematerialize it at the start of the block function. This is acceptable because we make no promises about address stability of captured variables.
Definition at line 272 of file CGBlocks.cpp.
References clang::CodeGen::CodeGenModule::EmitConstantInit(), clang::VarDecl::getInit(), clang::CodeGen::CodeGenModule::getLangOpts(), clang::ValueDecl::getType(), clang::QualType::isConstQualified(), isSafeForCXXConstantCapture(), and clang::ast_matchers::type.
Referenced by computeBlockInfo().
const unsigned BlockHeaderSize = 5 |
The number of fields in a block header.
Definition at line 187 of file CGBlocks.cpp.
Referenced by buildGlobalBlock(), and initializeForBlockHeader().