[cfe-commits] r82508 - in /cfe/trunk/lib/CodeGen: CGBlocks.cpp CGBlocks.h CGDebugInfo.cpp CGDecl.cpp
Daniel Dunbar
daniel at zuster.org
Tue Sep 22 03:26:30 PDT 2009
Hi Mike,
>From the gdb test suite results it looks like things got a bit worse,
we went from 725 failures to 768. Expected?
- Daniel
On Mon, Sep 21, 2009 at 7:12 PM, Mike Stump <mrs at apple.com> wrote:
> Author: mrs
> Date: Mon Sep 21 21:12:52 2009
> New Revision: 82508
>
> URL: http://llvm.org/viewvc/llvm-project?rev=82508&view=rev
> Log:
> Improve debug info generation for __block variables.
>
> Modified:
> cfe/trunk/lib/CodeGen/CGBlocks.cpp
> cfe/trunk/lib/CodeGen/CGBlocks.h
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/lib/CodeGen/CGDecl.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=82508&r1=82507&r2=82508&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Mon Sep 21 21:12:52 2009
> @@ -218,9 +218,12 @@
>
> llvm::Value* Addr = Builder.CreateStructGEP(V, i+5, "tmp");
> NoteForHelper[helpersize].index = i+5;
> - NoteForHelper[helpersize].RequiresCopying = BlockRequiresCopying(VD->getType());
> + NoteForHelper[helpersize].RequiresCopying
> + = BlockRequiresCopying(VD->getType());
> NoteForHelper[helpersize].flag
> - = VD->getType()->isBlockPointerType() ? BLOCK_FIELD_IS_BLOCK : BLOCK_FIELD_IS_OBJECT;
> + = (VD->getType()->isBlockPointerType()
> + ? BLOCK_FIELD_IS_BLOCK
> + : BLOCK_FIELD_IS_OBJECT);
>
> if (LocalDeclMap[VD]) {
> if (BDRE->isByRef()) {
> @@ -386,6 +389,10 @@
> return GenericExtendedBlockLiteralType;
> }
>
> +bool BlockFunction::BlockRequiresCopying(QualType Ty) {
> + return CGM.BlockRequiresCopying(Ty);
> +}
> +
> RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) {
> const BlockPointerType *BPT =
> E->getCallee()->getType()->getAs<BlockPointerType>();
>
> Modified: cfe/trunk/lib/CodeGen/CGBlocks.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.h?rev=82508&r1=82507&r2=82508&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGBlocks.h (original)
> +++ cfe/trunk/lib/CodeGen/CGBlocks.h Mon Sep 21 21:12:52 2009
> @@ -115,6 +115,16 @@
> PtrToInt8Ty = llvm::PointerType::getUnqual(
> llvm::Type::getInt8Ty(M.getContext()));
> }
> +
> + bool BlockRequiresCopying(QualType Ty) {
> + if (Ty->isBlockPointerType())
> + return true;
> + if (getContext().isObjCNSObjectType(Ty))
> + return true;
> + if (Ty->isObjCObjectPointerType())
> + return true;
> + return false;
> + }
> };
>
> class BlockFunction : public BlockBase {
> @@ -219,15 +229,7 @@
> llvm::Value *getBlockObjectDispose();
> void BuildBlockRelease(llvm::Value *DeclPtr, int flag = BLOCK_FIELD_IS_BYREF);
>
> - bool BlockRequiresCopying(QualType Ty) {
> - if (Ty->isBlockPointerType())
> - return true;
> - if (getContext().isObjCNSObjectType(Ty))
> - return true;
> - if (Ty->isObjCObjectPointerType())
> - return true;
> - return false;
> - }
> + bool BlockRequiresCopying(QualType Ty);
> };
>
> } // end namespace CodeGen
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=82508&r1=82507&r2=82508&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Sep 21 21:12:52 2009
> @@ -918,7 +918,139 @@
> return;
>
> llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
> - llvm::DIType Ty = getOrCreateType(Decl->getType(), Unit);
> + QualType Type = Decl->getType();
> + llvm::DIType Ty = getOrCreateType(Type, Unit);
> + if (Decl->hasAttr<BlocksAttr>()) {
> + llvm::DICompileUnit DefUnit;
> + unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
> +
> + llvm::SmallVector<llvm::DIDescriptor, 5> EltTys;
> +
> + llvm::DIType FieldTy;
> +
> + QualType FType;
> + uint64_t FieldSize, FieldOffset;
> + unsigned FieldAlign;
> +
> + llvm::DIArray Elements;
> + llvm::DIType EltTy;
> +
> + // Build up structure for the byref. See BuildByRefType.
> + FieldOffset = 0;
> + FType = M->getContext().getPointerType(M->getContext().VoidTy);
> + FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
> + FieldSize = M->getContext().getTypeSize(FType);
> + FieldAlign = M->getContext().getTypeAlign(FType);
> + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
> + "__isa", DefUnit,
> + 0, FieldSize, FieldAlign,
> + FieldOffset, 0, FieldTy);
> + EltTys.push_back(FieldTy);
> + FieldOffset += FieldSize;
> +
> + FType = M->getContext().getPointerType(M->getContext().VoidTy);
> + FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
> + FieldSize = M->getContext().getTypeSize(FType);
> + FieldAlign = M->getContext().getTypeAlign(FType);
> + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
> + "__forwarding", DefUnit,
> + 0, FieldSize, FieldAlign,
> + FieldOffset, 0, FieldTy);
> + EltTys.push_back(FieldTy);
> + FieldOffset += FieldSize;
> +
> + FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty;
> + FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
> + FieldSize = M->getContext().getTypeSize(FType);
> + FieldAlign = M->getContext().getTypeAlign(FType);
> + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
> + "__flags", DefUnit,
> + 0, FieldSize, FieldAlign,
> + FieldOffset, 0, FieldTy);
> + EltTys.push_back(FieldTy);
> + FieldOffset += FieldSize;
> +
> + FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty;
> + FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
> + FieldSize = M->getContext().getTypeSize(FType);
> + FieldAlign = M->getContext().getTypeAlign(FType);
> + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
> + "__size", DefUnit,
> + 0, FieldSize, FieldAlign,
> + FieldOffset, 0, FieldTy);
> + EltTys.push_back(FieldTy);
> + FieldOffset += FieldSize;
> +
> + bool HasCopyAndDispose = M->BlockRequiresCopying(Type);
> + if (HasCopyAndDispose) {
> + FType = M->getContext().getPointerType(M->getContext().VoidTy);
> + FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
> + FieldSize = M->getContext().getTypeSize(FType);
> + FieldAlign = M->getContext().getTypeAlign(FType);
> + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
> + "__copy_helper", DefUnit,
> + 0, FieldSize, FieldAlign,
> + FieldOffset, 0, FieldTy);
> + EltTys.push_back(FieldTy);
> + FieldOffset += FieldSize;
> +
> + FType = M->getContext().getPointerType(M->getContext().VoidTy);
> + FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
> + FieldSize = M->getContext().getTypeSize(FType);
> + FieldAlign = M->getContext().getTypeAlign(FType);
> + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
> + "__destroy_helper", DefUnit,
> + 0, FieldSize, FieldAlign,
> + FieldOffset, 0, FieldTy);
> + EltTys.push_back(FieldTy);
> + FieldOffset += FieldSize;
> + }
> +
> + unsigned Align = M->getContext().getDeclAlignInBytes(Decl);
> + if (Align > M->getContext().Target.getPointerAlign(0) / 8) {
> + unsigned AlignedOffsetInBytes
> + = llvm::RoundUpToAlignment(FieldOffset, Align);
> + unsigned NumPaddingBytes
> + = AlignedOffsetInBytes = FieldOffset;
> +
> + if (NumPaddingBytes > 0) {
> + llvm::APInt pad(32, NumPaddingBytes);
> + FType = M->getContext().getConstantArrayType(M->getContext().CharTy,
> + pad, ArrayType::Normal, 0);
> + FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
> + FieldSize = M->getContext().getTypeSize(FType);
> + FieldAlign = M->getContext().getTypeAlign(FType);
> + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member,
> + Unit, "", DefUnit,
> + 0, FieldSize, FieldAlign,
> + FieldOffset, 0, FieldTy);
> + EltTys.push_back(FieldTy);
> + FieldOffset += FieldSize;
> + }
> + }
> +
> + FType = Type;
> + FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
> + FieldSize = M->getContext().getTypeSize(FType);
> + FieldAlign = M->getContext().getTypeAlign(FType);
> + std::string Name = Decl->getNameAsString();
> +
> + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
> + Name, DefUnit,
> + 0, FieldSize, FieldAlign,
> + FieldOffset, 0, FieldTy);
> + EltTys.push_back(FieldTy);
> + FieldOffset += FieldSize;
> +
> + Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
> +
> + unsigned Flags = llvm::DIType::FlagBlockByrefStruct;
> +
> + Ty = DebugFactory.CreateCompositeType(Tag, Unit, "",
> + llvm::DICompileUnit(),
> + 0, FieldOffset, 0, 0, Flags,
> + llvm::DIType(), Elements);
> + }
>
> // Get location information.
> SourceManager &SM = M->getContext().getSourceManager();
>
> Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=82508&r1=82507&r2=82508&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Sep 21 21:12:52 2009
> @@ -213,8 +213,9 @@
> /// void *__forwarding;
> /// int32_t __flags;
> /// int32_t __size;
> -/// void *__copy_helper;
> -/// void *__destroy_helper;
> +/// void *__copy_helper; // only if needed
> +/// void *__destroy_helper; // only if needed
> +/// char padding[X]; // only if needed
> /// T x;
> /// } x
> ///
> @@ -390,21 +391,6 @@
> DI->setLocation(D.getLocation());
> if (Target.useGlobalsForAutomaticVariables()) {
> DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr), &D);
> - } else if (isByRef) {
> - // FIXME: This code is broken and will not emit debug info for the
> - // variable. The right way to do this would be to tell LLVM that this is a
> - // byref pointer, and what the offset is. Unfortunately, right now it's
> - // not possible unless we create a DIType that corresponds to the byref
> - // struct.
> - /*
> - llvm::Value *Loc;
> - bool needsCopyDispose = BlockRequiresCopying(Ty);
> - Loc = Builder.CreateStructGEP(DeclPtr, 1, "forwarding");
> - Loc = Builder.CreateLoad(Loc, false);
> - Loc = Builder.CreateBitCast(Loc, DeclPtr->getType());
> - Loc = Builder.CreateStructGEP(Loc, needsCopyDispose*2+4, "x");
> - DI->EmitDeclareOfAutoVariable(&D, Loc, Builder);
> - */
> } else
> DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder);
> }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list