[llvm-commits] [llvm-gcc-4.2] r42340 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Tue Sep 25 21:17:07 PDT 2007


Author: baldrick
Date: Tue Sep 25 23:17:07 2007
New Revision: 42340

URL: http://llvm.org/viewvc/llvm-project?rev=42340&view=rev
Log:
Get rid of the old code for aligning locals, which did
funky stuff like
  DECL_ALIGN(decl) = GET_MODE_BITSIZE(DECL_MODE(decl));
(copied from RTL), and instead just set the alignment
according to DECL_ALIGN using the same logic as for
global variables.  This fixes two problems: (1) user
requested alignment was being ignored; and (2) the
compiler wouldn't build on x86 due to long doubles
being given an alignment of 12 (not a power of 2).

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=42340&r1=42339&r2=42340&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Tue Sep 25 23:17:07 2007
@@ -1485,11 +1485,10 @@
   // eliminated all uses of, but is preserving for debug info, ignore it.
   if (TREE_CODE(decl) == VAR_DECL && DECL_VALUE_EXPR(decl))
     return;
-  
-  const Type *Ty;         // Type to allocate
-  Value *Size = 0;        // Amount to alloca (null for 1)
-  unsigned Alignment = 0; // Alignment in bytes.
-  
+
+  const Type *Ty;  // Type to allocate
+  Value *Size = 0; // Amount to alloca (null for 1)
+
   if (DECL_SIZE(decl) == 0) {    // Variable with incomplete type.
     if (DECL_INITIAL(decl) == 0)
       return; // Error message was already done; now avoid a crash.
@@ -1501,14 +1500,6 @@
   } else if (TREE_CODE(DECL_SIZE_UNIT(decl)) == INTEGER_CST) {
     // Variable of fixed size that goes on the stack.
     Ty = ConvertType(type);
-    
-    // Set alignment we actually gave this decl.
-    if (DECL_MODE(decl) == BLKmode)
-      DECL_ALIGN(decl) = BIGGEST_ALIGNMENT;
-    else
-      DECL_ALIGN(decl) = GET_MODE_BITSIZE(DECL_MODE(decl));
-    DECL_USER_ALIGN(decl) = 0;
-    Alignment = DECL_ALIGN(decl)/8;
   } else {
     // Dynamic-size object: must push space on the stack.
     if (TREE_CODE(type) == ARRAY_TYPE
@@ -1528,7 +1519,18 @@
     }
     Size = CastToUIntType(Size, Type::Int32Ty);
   }
-  
+
+  unsigned Alignment = 0; // Alignment in bytes.
+
+  // Set the alignment for the local if one of the following condition is met
+  // 1) DECL_ALIGN_UNIT does not match alignment as per ABI specification
+  // 2) DECL_ALIGN is set by user.
+  if (DECL_ALIGN_UNIT(decl)) {
+    unsigned TargetAlign = getTargetData().getABITypeAlignment(Ty);
+    if (DECL_USER_ALIGN(decl) || TargetAlign != (unsigned)DECL_ALIGN_UNIT(decl))
+      Alignment = DECL_ALIGN_UNIT(decl);
+  }
+
   const char *Name;      // Name of variable
   if (DECL_NAME(decl))
     Name = IDENTIFIER_POINTER(DECL_NAME(decl));





More information about the llvm-commits mailing list