[llvm-commits] [llvm-gcc-4.2] r128230 - in /llvm-gcc-4.2/trunk/gcc: function.c gimplify.c llvm-convert.cpp omp-low.c

Eric Christopher echristo at apple.com
Thu Mar 24 13:18:39 PDT 2011


Author: echristo
Date: Thu Mar 24 15:18:39 2011
New Revision: 128230

URL: http://llvm.org/viewvc/llvm-project?rev=128230&view=rev
Log:
Add an evil hack that adds an argument to alloca calls when we can
interpose them, and falls back if necessary in order to store the
alignment. Previously this code would be broken by multiple vlas
in a single function.

Fixes rdar://9169834

Modified:
    llvm-gcc-4.2/trunk/gcc/function.c
    llvm-gcc-4.2/trunk/gcc/gimplify.c
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
    llvm-gcc-4.2/trunk/gcc/omp-low.c

Modified: llvm-gcc-4.2/trunk/gcc/function.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/function.c?rev=128230&r1=128229&r2=128230&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/function.c (original)
+++ llvm-gcc-4.2/trunk/gcc/function.c Thu Mar 24 15:18:39 2011
@@ -3287,7 +3287,9 @@
 		  DECL_IGNORED_P (addr) = 0;
 		  local = build_fold_indirect_ref (addr);
 
-		  args = tree_cons (NULL, DECL_SIZE_UNIT (parm), NULL);
+      /* LLVM local add alloca alignment */
+      args = tree_cons(NULL, integer_one_node, NULL);
+		  args = tree_cons (NULL, DECL_SIZE_UNIT (parm), args);
 		  t = built_in_decls[BUILT_IN_ALLOCA];
 		  t = build_function_call_expr (t, args);
 		  t = fold_convert (ptr_type, t);

Modified: llvm-gcc-4.2/trunk/gcc/gimplify.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/gimplify.c?rev=128230&r1=128229&r2=128230&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/gimplify.c (original)
+++ llvm-gcc-4.2/trunk/gcc/gimplify.c Thu Mar 24 15:18:39 2011
@@ -1239,7 +1239,7 @@
 	  /* This is a variable-sized decl.  Simplify its size and mark it
 	     for deferred expansion.  Note that mudflap depends on the format
 	     of the emitted code: see mx_register_decls().  */
-	  tree t, args, addr, ptr_type;
+	  tree t, args, addr, ptr_type, align;
 
 	  gimplify_one_sizepos (&DECL_SIZE (decl), stmt_p);
 	  gimplify_one_sizepos (&DECL_SIZE_UNIT (decl), stmt_p);
@@ -1256,14 +1256,15 @@
 	  SET_DECL_VALUE_EXPR (decl, t);
 	  DECL_HAS_VALUE_EXPR_P (decl) = 1;
 
-	  args = tree_cons (NULL, DECL_SIZE_UNIT (decl), NULL);
+    /* LLVM LOCAL begin add alloca alignment */
+    /* We're adding an extra arg with the alignment to the end of the builtin
+       call and making up for it on the other end by not emitting the arg.  */
+    align = build_int_cst(TREE_TYPE(DECL_SIZE_UNIT(decl)),
+                          DECL_ALIGN(decl)/BITS_PER_UNIT);
+    args = tree_cons (NULL, align, NULL);
+    args = tree_cons (NULL,  DECL_SIZE_UNIT (decl), args);
+    /* LLVM LOCAL end add alloca alignment */
 	  t = built_in_decls[BUILT_IN_ALLOCA];
-	  /* LLVM LOCAL begin add alloca alignment */
-    /* We may have specified an alignment on the alloca - store it on the
-       function call so that we can emit this later and not lose it.  */
-    DECL_USER_ALIGN (t) = DECL_USER_ALIGN (decl);
-    DECL_ALIGN(t) = DECL_ALIGN(decl);
-	  /* LLVM LOCAL end add alloca alignment */
 	  
 	  t = build_function_call_expr (t, args);
 	  t = fold_convert (ptr_type, t);

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=128230&r1=128229&r2=128230&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Thu Mar 24 15:18:39 2011
@@ -6772,15 +6772,21 @@
 
 bool TreeToLLVM::EmitBuiltinAlloca(tree exp, Value *&Result) {
   tree arglist = TREE_OPERAND(exp, 1);
-  if (!validate_arglist(arglist, INTEGER_TYPE, VOID_TYPE))
+  tree align_arg = NULL_TREE;
+  if (validate_arglist(arglist, INTEGER_TYPE, INTEGER_TYPE, VOID_TYPE))
+    // Grab the alignment arg - no need to emit this.
+    align_arg = TREE_VALUE (TREE_CHAIN (arglist));
+  // We may just have a single arg call to __builtin_alloca that we couldn't
+  // interpose. Check.
+  else if (validate_arglist(arglist, INTEGER_TYPE, VOID_TYPE))
+    align_arg = integer_one_node;
+  else
     return false;
+
   Value *Amt = Emit(TREE_VALUE(arglist), 0);
   AllocaInst *AI = Builder.CreateAlloca(Type::getInt8Ty(Context), Amt);
   
-  // If this was originally a vla alloca find the alignment and set it
-  // on our alloca.
-  tree fndecl = get_callee_fndecl(exp);
-  unsigned align = DECL_ALIGN(fndecl) ? DECL_ALIGN(fndecl)/8 : 1;
+  unsigned align = TREE_INT_CST_LOW(align_arg);
   AI->setAlignment(align);
   Result = AI;
 

Modified: llvm-gcc-4.2/trunk/gcc/omp-low.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/omp-low.c?rev=128230&r1=128229&r2=128230&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/omp-low.c (original)
+++ llvm-gcc-4.2/trunk/gcc/omp-low.c Thu Mar 24 15:18:39 2011
@@ -1679,7 +1679,9 @@
 	      gcc_assert (DECL_P (ptr));
 
 	      x = TYPE_SIZE_UNIT (TREE_TYPE (new_var));
-	      args = tree_cons (NULL, x, NULL);
+        /* LLVM local add alloca align */
+        args = tree_cons (NULL, integer_one_node, NULL);
+	      args = tree_cons (NULL, x, args);
 	      x = built_in_decls[BUILT_IN_ALLOCA];
 	      x = build_function_call_expr (x, args);
 	      x = fold_convert (TREE_TYPE (ptr), x);
@@ -1713,7 +1715,8 @@
 		}
 	      else
 		{
-		  args = tree_cons (NULL, x, NULL);
+      args = tree_cons (NULL, integer_one_node, NULL);
+		  args = tree_cons (NULL, x, args);
 		  x = built_in_decls[BUILT_IN_ALLOCA];
 		  x = build_function_call_expr (x, args);
 		  x = fold_convert (TREE_TYPE (new_var), x);





More information about the llvm-commits mailing list