diff options
author | John McCall <rjmccall@apple.com> | 2011-02-07 10:33:21 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-02-07 10:33:21 +0000 |
commit | 351762cda239e2bb90fb2084e546878fea90ebf6 (patch) | |
tree | 22efeaf25ffe22b569427e2cb8054db1c5ec5172 /clang/lib/CodeGen/CGBlocks.h | |
parent | 867cb633b428b0017ea8ecf548176ae6000fcef2 (diff) | |
download | bcm5719-llvm-351762cda239e2bb90fb2084e546878fea90ebf6.tar.gz bcm5719-llvm-351762cda239e2bb90fb2084e546878fea90ebf6.zip |
A few more tweaks to the blocks AST representation:
- BlockDeclRefExprs always store VarDecls
- BDREs no longer store copy expressions
- BlockDecls now store a list of captured variables, information about
how they're captured, and a copy expression if necessary
With that in hand, change IR generation to use the captures data in
blocks instead of walking the block independently.
Additionally, optimize block layout by emitting fields in descending
alignment order, with a heuristic for filling in words when alignment
of the end of the block header is insufficient for the most aligned
field.
llvm-svn: 125005
Diffstat (limited to 'clang/lib/CodeGen/CGBlocks.h')
-rw-r--r-- | clang/lib/CodeGen/CGBlocks.h | 69 |
1 files changed, 9 insertions, 60 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.h b/clang/lib/CodeGen/CGBlocks.h index a1453f68161..888fdb6a400 100644 --- a/clang/lib/CodeGen/CGBlocks.h +++ b/clang/lib/CodeGen/CGBlocks.h @@ -47,6 +47,7 @@ namespace clang { namespace CodeGen { class CodeGenModule; +class CGBlockInfo; class BlockBase { public: @@ -100,12 +101,6 @@ public: Block.GlobalUniqueCount = 0; PtrToInt8Ty = llvm::Type::getInt8PtrTy(M.getContext()); } - - bool BlockRequiresCopying(QualType Ty) - { return getContext().BlockRequiresCopying(Ty); } - bool BlockRequiresCopying(const BlockDeclRefExpr *E) - { return E->getCopyConstructorExpr() != 0 || - getContext().BlockRequiresCopying(E->getType()); } }; class BlockFunction : public BlockBase { @@ -118,6 +113,9 @@ protected: public: CodeGenFunction &CGF; + const CodeGen::CGBlockInfo *BlockInfo; + llvm::Value *BlockPointer; + const llvm::PointerType *PtrToInt8Ty; struct HelperInfo { int index; @@ -143,51 +141,8 @@ public: BlockFunction(CodeGenModule &cgm, CodeGenFunction &cgf, CGBuilderTy &B); - /// BlockOffset - The offset in bytes for the next allocation of an - /// imported block variable. - CharUnits BlockOffset; - /// BlockAlign - Maximal alignment needed for the Block expressed in - /// characters. - CharUnits BlockAlign; - - /// getBlockOffset - Allocate a location within the block's storage - /// for a value with the given size and alignment requirements. - CharUnits getBlockOffset(CharUnits Size, CharUnits Align); - - /// SynthesizeCopyDisposeHelpers - True iff the block uses copy/dispose. - bool SynthesizeCopyDisposeHelpers; - - /// BlockLayout - The layout of the block's storage, represented as - /// a sequence of expressions which require such storage. The - /// expressions can be: - /// - a BlockDeclRefExpr, indicating that the given declaration - /// from an enclosing scope is needed by the block; - /// - a DeclRefExpr, which always wraps an anonymous VarDecl with - /// array type, used to insert padding into the block; or - /// - a CXXThisExpr, indicating that the C++ 'this' value should - /// propagate from the parent to the block. - /// This is a really silly representation. - llvm::SmallVector<const Expr *, 8> BlockLayout; - - /// BlockDecls - Offsets for all Decls in BlockDeclRefExprs. - llvm::DenseMap<const Decl*, CharUnits> BlockDecls; - - /// BlockCXXThisOffset - The offset of the C++ 'this' value within - /// the block structure. - CharUnits BlockCXXThisOffset; - - ImplicitParamDecl *BlockStructDecl; - ImplicitParamDecl *getBlockStructDecl() { return BlockStructDecl; } - - llvm::Constant *GenerateCopyHelperFunction(const llvm::StructType *, - std::vector<HelperInfo> *); - llvm::Constant *GenerateDestroyHelperFunction(const llvm::StructType *, - std::vector<HelperInfo> *); - - llvm::Constant *BuildCopyHelper(const llvm::StructType *, - std::vector<HelperInfo> *); - llvm::Constant *BuildDestroyHelper(const llvm::StructType *, - std::vector<HelperInfo> *); + llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo); + llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo); llvm::Constant *GeneratebyrefCopyHelperFunction(const llvm::Type *, int flag, const VarDecl *BD); @@ -195,18 +150,12 @@ public: int flag, const VarDecl *BD); - llvm::Constant *BuildbyrefCopyHelper(const llvm::Type *T, int flag, + llvm::Constant *BuildbyrefCopyHelper(const llvm::Type *T, uint32_t flags, unsigned Align, const VarDecl *BD); - llvm::Constant *BuildbyrefDestroyHelper(const llvm::Type *T, int flag, + llvm::Constant *BuildbyrefDestroyHelper(const llvm::Type *T, uint32_t flags, unsigned Align, const VarDecl *BD); - void BuildBlockRelease(llvm::Value *DeclPtr, int flag = BLOCK_FIELD_IS_BYREF); - - bool BlockRequiresCopying(QualType Ty) - { return getContext().BlockRequiresCopying(Ty); } - bool BlockRequiresCopying(const BlockDeclRefExpr *E) - { return E->getCopyConstructorExpr() != 0 || - getContext().BlockRequiresCopying(E->getType()); } + void BuildBlockRelease(llvm::Value *DeclPtr, uint32_t flags); }; } // end namespace CodeGen |