[llvm-branch-commits] [llvm-gcc-branch] r99313 - in /llvm-gcc-4.2/branches/Apple/Morbo: ./ gcc/cp/cp-objcp-common.c gcc/cp/cp-objcp-common.h gcc/cp/cp-tree.h gcc/langhooks-def.h gcc/langhooks.c gcc/langhooks.h gcc/llvm-convert.cpp

Stuart Hastings stuart at apple.com
Tue Mar 23 12:02:35 PDT 2010


Author: stuart
Date: Tue Mar 23 14:02:35 2010
New Revision: 99313

URL: http://llvm.org/viewvc/llvm-project?rev=99313&view=rev
Log:
Elide stores of empty structures for correct support of boost::compressed_pair.  Radar 7659636.

Modified:
    llvm-gcc-4.2/branches/Apple/Morbo/   (props changed)
    llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.c
    llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.h
    llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-tree.h
    llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks-def.h
    llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.c
    llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.h
    llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp

Propchange: llvm-gcc-4.2/branches/Apple/Morbo/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar 23 14:02:35 2010
@@ -1 +1 @@
-/llvm-gcc-4.2/trunk:98728,98841,98893
+/llvm-gcc-4.2/trunk:98728,98841,98893,99305

Modified: llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.c?rev=99313&r1=99312&r2=99313&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.c (original)
+++ llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.c Tue Mar 23 14:02:35 2010
@@ -111,6 +111,30 @@
     return lhd_expr_size (exp);
 }
 
+/* LLVM LOCAL begin 7659636 */
+/* lang_hooks.empty_type_p: Return true if the given type has size
+   zero.  */
+
+int
+cp_empty_type_p (tree exp)
+{
+  gcc_assert(TYPE_P(exp));
+  if (VOID_TYPE_P(exp))
+    return 0;
+
+  /* C++ classes with non-trivial constructors or non-trivial
+     assignment operators are assumed non-empty, thus assignments of
+     these types can't be elided.  */
+  if (CLASS_TYPE_P(exp)
+      && (TYPE_HAS_COMPLEX_INIT_REF(exp)
+          || TYPE_HAS_COMPLEX_ASSIGN_REF(exp)))
+    return 0;
+
+  return is_empty_class(exp);
+}
+
+/* LLVM LOCAL end 7659636 */
+
 /* Langhook for tree_size: determine size of our 'x' and 'c' nodes.  */
 size_t
 cp_tree_size (enum tree_code code)

Modified: llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.h?rev=99313&r1=99312&r2=99313&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.h (original)
+++ llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-objcp-common.h Tue Mar 23 14:02:35 2010
@@ -33,6 +33,10 @@
 
 #undef LANG_HOOKS_TREE_SIZE
 #define LANG_HOOKS_TREE_SIZE cp_tree_size
+/* LLVM LOCAL begin 7659636 */
+#undef LANG_HOOKS_EMPTY_TYPE_P
+#define LANG_HOOKS_EMPTY_TYPE_P cp_empty_type_p
+/* LLVM LOCAL end 7659636 */
 #undef LANG_HOOKS_FINISH
 #define LANG_HOOKS_FINISH cxx_finish
 #undef LANG_HOOKS_CLEAR_BINDING_STACK

Modified: llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-tree.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-tree.h?rev=99313&r1=99312&r2=99313&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-tree.h (original)
+++ llvm-gcc-4.2/branches/Apple/Morbo/gcc/cp/cp-tree.h Tue Mar 23 14:02:35 2010
@@ -4639,6 +4639,8 @@
 extern bool cxx_warn_unused_global_decl		(tree);
 extern tree cp_expr_size			(tree);
 extern size_t cp_tree_size			(enum tree_code);
+/* LLVM LOCAL 7659636 */
+extern int cp_empty_type_p                      (tree);
 extern bool cp_var_mod_type_p			(tree, tree);
 extern void cxx_initialize_diagnostics		(struct diagnostic_context *);
 extern int cxx_types_compatible_p		(tree, tree);

Modified: llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks-def.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks-def.h?rev=99313&r1=99312&r2=99313&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks-def.h (original)
+++ llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks-def.h Tue Mar 23 14:02:35 2010
@@ -70,6 +70,8 @@
 extern bool lhd_decl_ok_for_sibcall (tree);
 extern const char *lhd_comdat_group (tree);
 extern tree lhd_expr_size (tree);
+/* LLVM LOCAL 7659636 */
+extern int lhd_empty_type_p (tree);
 extern size_t lhd_tree_size (enum tree_code);
 extern HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT);
 extern tree lhd_expr_to_decl (tree, bool *, bool *, bool *);
@@ -139,6 +141,8 @@
 #define LANG_HOOKS_DWARF_NAME		lhd_dwarf_name
 #define LANG_HOOKS_GET_CALLEE_FNDECL	lhd_return_null_tree
 #define LANG_HOOKS_EXPR_SIZE		lhd_expr_size
+/* LLVM LOCAL 7659636 */
+#define LANG_HOOKS_EMPTY_TYPE_P		lhd_empty_type_p
 #define LANG_HOOKS_TREE_SIZE		lhd_tree_size
 #define LANG_HOOKS_TYPES_COMPATIBLE_P	lhd_types_compatible_p
 #define LANG_HOOKS_BUILTIN_FUNCTION	builtin_function
@@ -336,6 +340,8 @@
   LANG_HOOKS_GET_CALLEE_FNDECL, \
   LANG_HOOKS_PRINT_ERROR_FUNCTION, \
   LANG_HOOKS_EXPR_SIZE, \
+/* LLVM LOCAL 7659636 */ \
+  LANG_HOOKS_EMPTY_TYPE_P, \
   LANG_HOOKS_TO_TARGET_CHARSET, \
   LANG_HOOKS_ATTRIBUTE_TABLE, \
   LANG_HOOKS_COMMON_ATTRIBUTE_TABLE, \

Modified: llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.c?rev=99313&r1=99312&r2=99313&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.c (original)
+++ llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.c Tue Mar 23 14:02:35 2010
@@ -439,6 +439,21 @@
     return size_in_bytes (TREE_TYPE (exp));
 }
 
+/* LLVM LOCAL begin 7659636 */
+/* lang_hooks.empty_type_p: Return true if the given type has size
+   zero.  */
+
+int
+lhd_empty_type_p (tree exp)
+{
+  gcc_assert(TYPE_P(exp));
+  if (VOID_TYPE_P(exp))
+    return 0;
+  return size_in_bytes(exp) == 0;
+}
+
+/* LLVM LOCAL end 7659636 */
+
 /* lang_hooks.gimplify_expr re-writes *EXPR_P into GIMPLE form.  */
 
 int

Modified: llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.h?rev=99313&r1=99312&r2=99313&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.h (original)
+++ llvm-gcc-4.2/branches/Apple/Morbo/gcc/langhooks.h Tue Mar 23 14:02:35 2010
@@ -410,6 +410,11 @@
      semantics in cases that it doesn't want to handle specially.  */
   tree (*expr_size) (tree);
 
+/* LLVM LOCAL begin 7659636 */
+  /* Return true (non-zero) if the given RECORD_TYPE has size zero.  */
+  int (*empty_type_p) (tree);
+/* LLVM LOCAL end 7659636 */
+
   /* Convert a character from the host's to the target's character
      set.  The character should be in what C calls the "basic source
      character set" (roughly, the set of characters defined by plain

Modified: llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp?rev=99313&r1=99312&r2=99313&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp Tue Mar 23 14:02:35 2010
@@ -3046,6 +3046,20 @@
   tree lhs = TREE_OPERAND (exp, 0);
   tree rhs = TREE_OPERAND (exp, 1);
 
+  // Avoid generating stores of empty types.  This is rare, but necessary
+  // to support the compressed_pair template.
+  if (lang_hooks.empty_type_p(TREE_TYPE(exp))) {
+    if (TREE_SIDE_EFFECTS(rhs)) {
+      // There's a side-effect; alloc a temporary to receive the
+      // value, if any.  Do not store into lhs; we must not
+      // reference it.
+      const Type *RHSTy = ConvertType(TREE_TYPE(rhs));
+      MemRef dest = CreateTempLoc(RHSTy);
+      return Emit(rhs, &dest);
+    } else
+      return (Value *)0;
+  }
+
   // If this is the definition of a gimple temporary, set its DECL_LLVM to the
   // RHS.
   bool LHSSigned = !TYPE_UNSIGNED(TREE_TYPE(lhs));





More information about the llvm-branch-commits mailing list