[cfe-commits] r65285 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CGExprScalar.cpp lib/CodeGen/CodeGenFunction.h test/CodeGen/const-init.c

Mike Stump mrs at apple.com
Sun Feb 22 05:27:12 PST 2009


Author: mrs
Date: Sun Feb 22 07:27:11 2009
New Revision: 65285

URL: http://llvm.org/viewvc/llvm-project?rev=65285&view=rev
Log:
Cleanp code with some recent suggestions.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/test/CodeGen/const-init.c

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=65285&r1=65284&r2=65285&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sun Feb 22 07:27:11 2009
@@ -193,13 +193,8 @@
                                               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 @@
                                                   BlockDescPtrTy,
                                                   NULL);
 
-  // FIXME: See struct.__block_descriptor
   getModule().addTypeName("struct.__block_literal_generic",
                           GenericBlockLiteralType);
 
@@ -271,7 +265,6 @@
                                                           Int8PtrTy,
                                                           NULL);
 
-  // FIXME: See struct.__block_descriptor
   getModule().addTypeName("struct.__block_literal_extended_generic",
                           GenericExtendedBlockLiteralType);
 
@@ -312,8 +305,7 @@
 
   // 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 =

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=65285&r1=65284&r2=65285&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sun Feb 22 07:27:11 2009
@@ -616,14 +616,8 @@
 
   // 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<AlignedAttr>())
-        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();

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=65285&r1=65284&r2=65285&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sun Feb 22 07:27:11 2009
@@ -286,15 +286,20 @@
     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<AlignedAttr>())
+        Align = std::max(Align, AA->getAlignment());
+
+    return getBlockOffset(Size, Align);
+  }
   std::map<Decl*, uint64_t> BlockDecls;
 
   void GenerateCode(const FunctionDecl *FD,

Modified: cfe/trunk/test/CodeGen/const-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-init.c?rev=65285&r1=65284&r2=65285&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/const-init.c (original)
+++ cfe/trunk/test/CodeGen/const-init.c Sun Feb 22 07:27:11 2009
@@ -28,13 +28,13 @@
 _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);





More information about the cfe-commits mailing list