From 20733cd4fd5c9755cdfab583db862223c93732c8 Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Sun, 22 Feb 2009 13:27:11 +0000 Subject: [PATCH] Cleanp code with some recent suggestions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65285 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBlocks.cpp | 10 +--------- lib/CodeGen/CGExprScalar.cpp | 8 +------- lib/CodeGen/CodeGenFunction.h | 15 ++++++++++----- test/CodeGen/const-init.c | 4 ++-- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 60bf73f0b4..d368d20bce 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -193,13 +193,8 @@ const llvm::Type *CodeGenModule::getBlockDescriptorType() { UnsignedLongTy, NULL); - // FIXME: This breaks an unrelated testcase in the testsuite, we - // _want_ llvm to not use structural equality, sometimes. What - // should we do, modify the testcase and do this anyway, or... -#if 0 getModule().addTypeName("struct.__block_descriptor", BlockDescriptorType); -#endif return BlockDescriptorType; } @@ -232,7 +227,6 @@ CodeGenModule::getGenericBlockLiteralType() { BlockDescPtrTy, NULL); - // FIXME: See struct.__block_descriptor getModule().addTypeName("struct.__block_literal_generic", GenericBlockLiteralType); @@ -271,7 +265,6 @@ CodeGenModule::getGenericExtendedBlockLiteralType() { Int8PtrTy, NULL); - // FIXME: See struct.__block_descriptor getModule().addTypeName("struct.__block_literal_extended_generic", GenericExtendedBlockLiteralType); @@ -312,8 +305,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) { // Get the function pointer from the literal. llvm::Value *FuncPtr = Builder.CreateStructGEP(BlockLiteral, 3, "tmp"); - // FIXME: second argument should be false? - llvm::Value *Func = Builder.CreateLoad(FuncPtr, FuncPtr, "tmp"); + llvm::Value *Func = Builder.CreateLoad(FuncPtr, false, "tmp"); // Cast the function pointer to the right type. const llvm::Type *BlockFTy = diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 63aa4e0a20..a271e76bf1 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -616,14 +616,8 @@ Value *ScalarExprEmitter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { // See if we have already allocated an offset for this variable. if (offset == 0) { - int Size = CGF.CGM.getTargetData().getTypeStoreSizeInBits(Ty) / 8; - - unsigned Align = CGF.CGM.getContext().getTypeAlign(E->getDecl()->getType()); - if (const AlignedAttr* AA = E->getDecl()->getAttr()) - Align = std::max(Align, AA->getAlignment()); - // if not, allocate one now. - offset = CGF.getBlockOffset(Size, Align); + offset = CGF.getBlockOffset(E->getDecl()); } llvm::Value *BlockLiteral = CGF.LoadBlockStruct(); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 2de696d664..cffa7fa5ec 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -286,15 +286,20 @@ public: assert (((Align & 7) == 0) && "alignment must be on at least byte boundaries"); // Ensure proper alignment, even if it means we have to have a gap - if (BlockOffset % (Align >> 3)) { - BlockOffset += (Align >> 3) - (BlockOffset % (Align >> 3)); - assert ((BlockOffset % (Align >> 3)) == 0 - && "alignment calculation is wrong"); - } + BlockOffset = llvm::RoundUpToAlignment(BlockOffset, Align/8); BlockOffset += Size; return BlockOffset-Size; } + uint64_t getBlockOffset(ValueDecl *D) { + uint64_t Size = getContext().getTypeSize(D->getType()) / 8; + + unsigned Align = getContext().getTypeAlign(D->getType()); + if (const AlignedAttr* AA = D->getAttr()) + Align = std::max(Align, AA->getAlignment()); + + return getBlockOffset(Size, Align); + } std::map BlockDecls; void GenerateCode(const FunctionDecl *FD, diff --git a/test/CodeGen/const-init.c b/test/CodeGen/const-init.c index a709cef218..0ca7c24f0b 100644 --- a/test/CodeGen/const-init.c +++ b/test/CodeGen/const-init.c @@ -28,13 +28,13 @@ _Complex double g1x = 1.0f; _Complex double g1y = 1.0fi; // RUN: grep '@g1 = global { i8, i8 } { i8 1, i8 10 }' %t && _Complex char g1 = (char) 1 + (char) 10 * 1i; -// RUN: grep '@g2 = global { i32, i32 } { i32 1, i32 10 }' %t && +// RUN: grep '@g2 = global .struct.__block_descriptor { i32 1, i32 10 }' %t && _Complex int g2 = 1 + 10i; // RUN: grep '@g3 = global { float, float } { float 1.000000e+00, float 1.000000e+01 }' %t && _Complex float g3 = 1.0 + 10.0i; // RUN: grep '@g4 = global { double, double } { double 1.000000e+00, double 1.000000e+01 }' %t && _Complex double g4 = 1.0 + 10.0i; -// RUN: grep '@g5 = global { i32, i32 } zeroinitializer' %t && +// RUN: grep '@g5 = global .struct.__block_descriptor zeroinitializer' %t && _Complex int g5 = (2 + 3i) == (5 + 7i); // RUN: grep '@g6 = global { double, double } { double -1.100000e+01, double 2.900000e+01 }' %t && _Complex double g6 = (2.0 + 3.0i) * (5.0 + 7.0i); -- 2.40.0