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 | 6b5a61b6dc400027fd793dcadceeb9da944a37ea (patch) | |
tree | 8fd6aca5e8914908e0ee03c007988ea87219d2b8 /lib/AST | |
parent | 683564a7a93c952f1fbe573b55c542418d29d859 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125005 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST')
-rw-r--r-- | lib/AST/ASTContext.cpp | 9 | ||||
-rw-r--r-- | lib/AST/Decl.cpp | 23 | ||||
-rw-r--r-- | lib/AST/Expr.cpp | 7 | ||||
-rw-r--r-- | lib/AST/StmtDumper.cpp | 52 | ||||
-rw-r--r-- | lib/AST/StmtProfile.cpp | 2 |
5 files changed, 62 insertions, 31 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index d96d079908..63e84d4131 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3693,10 +3693,11 @@ std::string charUnitsToString(const CharUnits &CU) { return llvm::itostr(CU.getQuantity()); } -/// getObjCEncodingForBlockDecl - Return the encoded type for this block +/// getObjCEncodingForBlock - Return the encoded type for this block /// declaration. -void ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr, - std::string& S) const { +std::string ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr) const { + std::string S; + const BlockDecl *Decl = Expr->getBlockDecl(); QualType BlockTy = Expr->getType()->getAs<BlockPointerType>()->getPointeeType(); @@ -3739,6 +3740,8 @@ void ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr, S += charUnitsToString(ParmOffset); ParmOffset += getObjCEncodingTypeSize(PType); } + + return S; } void ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index db69e0878a..4fb47bfcdc 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -2104,21 +2104,26 @@ void BlockDecl::setParams(ParmVarDecl **NewParamInfo, } } -void BlockDecl::setCapturedDecls(ASTContext &Context, - VarDecl * const *begin, - VarDecl * const *end, - bool capturesCXXThis) { +void BlockDecl::setCaptures(ASTContext &Context, + const Capture *begin, + const Capture *end, + bool capturesCXXThis) { CapturesCXXThis = capturesCXXThis; if (begin == end) { - NumCapturedDecls = 0; - CapturedDecls = 0; + NumCaptures = 0; + Captures = 0; return; } - NumCapturedDecls = end - begin; - CapturedDecls = new (Context) VarDecl*[NumCapturedDecls]; - memcpy(CapturedDecls, begin, NumCapturedDecls * sizeof(VarDecl*)); + NumCaptures = end - begin; + + // Avoid new Capture[] because we don't want to provide a default + // constructor. + size_t allocationSize = NumCaptures * sizeof(Capture); + void *buffer = Context.Allocate(allocationSize, /*alignment*/sizeof(void*)); + memcpy(buffer, begin, allocationSize); + Captures = static_cast<Capture*>(buffer); } SourceRange BlockDecl::getSourceRange() const { diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 04498f7b9a..b22d9d5452 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -2961,13 +2961,12 @@ Stmt::child_iterator ObjCMessageExpr::child_end() { } // Blocks -BlockDeclRefExpr::BlockDeclRefExpr(ValueDecl *d, QualType t, ExprValueKind VK, +BlockDeclRefExpr::BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, SourceLocation l, bool ByRef, - bool constAdded, Stmt *copyConstructorVal) + bool constAdded) : Expr(BlockDeclRefExprClass, t, VK, OK_Ordinary, false, false, d->isParameterPack()), - D(d), Loc(l), IsByRef(ByRef), - ConstQualAdded(constAdded), CopyConstructorVal(copyConstructorVal) + D(d), Loc(l), IsByRef(ByRef), ConstQualAdded(constAdded) { bool TypeDependent = false; bool ValueDependent = false; diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp index 8b62dcc940..5def7d9a0b 100644 --- a/lib/AST/StmtDumper.cpp +++ b/lib/AST/StmtDumper.cpp @@ -100,6 +100,7 @@ namespace { OS << ":'" << QualType::getAsString(D_split) << "'"; } } + void DumpDeclRef(Decl *node); void DumpStmt(const Stmt *Node) { Indent(); OS << "(" << Node->getStmtClassName() @@ -153,6 +154,7 @@ namespace { void VisitBinaryOperator(BinaryOperator *Node); void VisitCompoundAssignOperator(CompoundAssignOperator *Node); void VisitAddrLabelExpr(AddrLabelExpr *Node); + void VisitBlockExpr(BlockExpr *Node); // C++ void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node); @@ -362,21 +364,21 @@ void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) { DumpExpr(Node); OS << " "; - switch (Node->getDecl()->getKind()) { - default: OS << "Decl"; break; - case Decl::Function: OS << "FunctionDecl"; break; - case Decl::Var: OS << "Var"; break; - case Decl::ParmVar: OS << "ParmVar"; break; - case Decl::EnumConstant: OS << "EnumConstant"; break; - case Decl::Typedef: OS << "Typedef"; break; - case Decl::Record: OS << "Record"; break; - case Decl::Enum: OS << "Enum"; break; - case Decl::CXXRecord: OS << "CXXRecord"; break; - case Decl::ObjCInterface: OS << "ObjCInterface"; break; - case Decl::ObjCClass: OS << "ObjCClass"; break; + DumpDeclRef(Node->getDecl()); +} + +void StmtDumper::DumpDeclRef(Decl *d) { + OS << d->getDeclKindName() << ' ' << (void*) d; + + if (NamedDecl *nd = dyn_cast<NamedDecl>(d)) { + OS << " '"; + nd->getDeclName().printName(OS); + OS << "'"; } - OS << "='" << Node->getDecl() << "' " << (void*)Node->getDecl(); + if (ValueDecl *vd = dyn_cast<ValueDecl>(d)) { + OS << ' '; DumpType(vd->getType()); + } } void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) { @@ -474,6 +476,30 @@ void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) { DumpType(Node->getComputationResultType()); } +void StmtDumper::VisitBlockExpr(BlockExpr *Node) { + DumpExpr(Node); + + IndentLevel++; + BlockDecl *block = Node->getBlockDecl(); + if (block->capturesCXXThis()) { + OS << '\n'; Indent(); OS << "(capture this)"; + } + for (BlockDecl::capture_iterator + i = block->capture_begin(), e = block->capture_end(); i != e; ++i) { + OS << '\n'; + Indent(); + OS << "(capture "; + if (i->isByRef()) OS << "byref "; + if (i->isNested()) OS << "nested "; + DumpDeclRef(i->getVariable()); + if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr()); + OS << ")"; + } + IndentLevel--; + + DumpSubTree(block->getBody()); +} + // GNU extensions. void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) { diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index e75c274015..842a2d92d8 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -425,8 +425,6 @@ void StmtProfiler::VisitBlockDeclRefExpr(BlockDeclRefExpr *S) { VisitDecl(S->getDecl()); ID.AddBoolean(S->isByRef()); ID.AddBoolean(S->isConstQualAdded()); - if (S->getCopyConstructorExpr()) - Visit(S->getCopyConstructorExpr()); } static Stmt::StmtClass DecodeOperatorCall(CXXOperatorCallExpr *S, |