[llvm-commits] [llvm-gcc-4.2] r108225 - in /llvm-gcc-4.2/trunk/gcc: llvm-convert.cpp llvm-internal.h

Eric Christopher echristo at apple.com
Mon Jul 12 20:02:18 PDT 2010


Author: echristo
Date: Mon Jul 12 22:02:18 2010
New Revision: 108225

URL: http://llvm.org/viewvc/llvm-project?rev=108225&view=rev
Log:
Rework previous patch for vlas and stack alignment.  Now checks if we
may dynamically realign the stack and works for c++ which is lowered
separately.

Removed the dead variable elimination since vlas are not lowered through
some of this mechanism and we'd miss them otherwise.

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

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=108225&r1=108224&r2=108225&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Mon Jul 12 22:02:18 2010
@@ -185,6 +185,8 @@
   }
 
   AllocaInsertionPoint = 0;
+  GreatestAlignment = TheTarget->getFrameInfo()->getStackAlignment();
+  SeenVLA = NULL;
 
   ExceptionValue = 0;
   ExceptionSelectorValue = 0;
@@ -812,6 +814,15 @@
   }
   UniquedValues.clear();
 
+  // If we've seen a vla in this function and we'll possibly need to
+  // either dynamically realign or this is greater than the maximum stack
+  // alignment, error out now.  This is here so we don't output an error
+  // every time we see a variable.
+  if (SeenVLA &&
+      GreatestAlignment > TheTarget->getFrameInfo()->getStackAlignment())
+      error ("alignment for %q+D conflicts with either a dynamically "
+             "realigned stack or the maximum stack alignment", SeenVLA);
+
   return Fn;
 }
 
@@ -1751,25 +1762,20 @@
       TREE_STATIC(decl) || DECL_EXTERNAL(decl) || type == error_mark_node)
     return;
 
+  // If we've seen a VLA remember it in case we try to dynamically realign
+  // the stack or request an alignment greater than the default stack
+  // alignment.
+  // We're basing the VLA on an expression that is an array that doesn't have
+  // a constant decl size as below.  
+  if (TREE_CODE(type) == ARRAY_TYPE &&
+      DECL_SIZE(decl) != 0 && TREE_CODE(DECL_SIZE_UNIT(decl)) != INTEGER_CST)
+    SeenVLA = decl;
+      
   // Gimple temporaries are handled specially: their DECL_LLVM is set when the
   // definition is encountered.
   if (isGimpleTemporary(decl))
     return;
 
-  /* If this is a vla type and we requested an alignment greater than the stack
-     alignment, error out since we're not going to dynamically realign
-     variable length array allocations.  We're placing this here instead of
-     later in case it's a relatively unused variable.  */
-  if (TREE_CODE (type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (type) &&
-      DECL_ALIGN(decl)/8u > TheTarget->getFrameInfo()->getStackAlignment())
-        error ("alignment for %q+D is greater than the stack alignment, "
-               "we cannot guarantee the alignment.", decl);
-
-  // If this is just the rotten husk of a variable that the gimplifier
-  // 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)
 
@@ -1832,6 +1838,10 @@
   }
 
   AI->setAlignment(Alignment);
+  
+  // Record the alignment if it's the largest we've seen.
+  if (Alignment > GreatestAlignment)
+    GreatestAlignment = Alignment;
 
   SET_DECL_LLVM(decl, AI);
 

Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=108225&r1=108224&r2=108225&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Mon Jul 12 22:02:18 2010
@@ -299,6 +299,15 @@
   /// unique.  These can be simplified once the function has been emitted.
   std::vector<BitCastInst *> UniquedValues;
 
+  /// GreatestAlignment - The largest alignment seen on a variable declaration.
+  /// With stack realignment the TargetMachine's frame info won't be sufficient
+  /// to determine the greatest stack alignment.
+  unsigned GreatestAlignment;
+  
+  /// SeenVLA - Whether or not we have a VLA in the current function.  This
+  /// and dynamic stack realignment currently conflict so we'll use this to
+  /// warn later.
+  tree_node *SeenVLA;
   //===---------------------- Exception Handling --------------------------===//
 
   /// LandingPads - The landing pad for a given EH region.





More information about the llvm-commits mailing list