[llvm-commits] [dragonegg] r137021 - /dragonegg/trunk/src/Backend.cpp

Duncan Sands baldrick at free.fr
Sat Aug 6 10:00:01 PDT 2011


Author: baldrick
Date: Sat Aug  6 12:00:01 2011
New Revision: 137021

URL: http://llvm.org/viewvc/llvm-project?rev=137021&view=rev
Log:
Go back to the previous scheme for handling aliases, since the scheme
introduced in commit 134356 doesn't work for function aliases.  However,
rather than overriding a LTO pass and outputting the aliases there, do
it at the end of the IPA passes, avoiding the need for GCC to have been
compiled with LTO support.  Move output of global variables to the same
place, since it seems more logical to output these together (and to put
global variables out before aliases).  Fixes PR10587.  Based on a patch
by Peter Collingbourne.

Modified:
    dragonegg/trunk/src/Backend.cpp

Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=137021&r1=137020&r2=137021&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Sat Aug  6 12:00:01 2011
@@ -1659,44 +1659,49 @@
 };
 
 
-/// llvm_finish_unit - Finish the .s file.  This is called by GCC once the
-/// compilation unit has been completely processed.
-static void llvm_finish_unit(void * /*gcc_data*/, void * /*user_data*/) {
+/// llvm_emit_globals - Output GCC global variables and aliases to the LLVM IR.
+static void llvm_emit_globals(void * /*gcc_data*/, void * /*user_data*/) {
   if (errorcount || sorrycount)
     return; // Do not process broken code.
 
-//TODO  timevar_push(TV_LLVM_PERFILE);
-  if (!quiet_flag)
-    errs() << "Finishing compilation unit\n";
-
   InitializeBackend();
 
-  // Output all externally visible global variables and aliases as well as any
-  // internal variables explicitly marked with the 'used' attribute.  All other
-  // internal variables and aliases are output when their user is, or discarded
-  // if unused.
+  // Output all externally visible global variables as well as any internal
+  // variables explicitly marked with the 'used' attribute.  Other internal
+  // variables and aliases are output when their user is, or discarded if
+  // unused.
   for (struct varpool_node *vnode = varpool_nodes; vnode; vnode = vnode->next) {
-    if (!vnode->needed)
+    if (!vnode->needed || vnode->alias)
       continue;
 #if (GCC_MINOR > 5)
     if (vnode->in_other_partition)
       continue;
 #endif
     tree decl = vnode->decl;
-    if (vnode->alias) {
-      tree alias = lookup_attribute("alias", DECL_ATTRIBUTES(decl));
-      assert(alias && "Have alias target but no alias!");
-      alias = TREE_VALUE(TREE_VALUE(alias));
-      alias = get_identifier(TREE_STRING_POINTER(alias));
-      emit_alias(decl, alias);
-      continue;
-    }
     if (TREE_CODE(decl) == VAR_DECL && !DECL_EXTERNAL(decl) &&
         (TREE_PUBLIC(decl) || DECL_PRESERVE_P(decl) ||
          TREE_THIS_VOLATILE(decl)))
       emit_global(decl);
   }
 
+  // Emit any aliases.
+  alias_pair *p;
+  for (unsigned i = 0; VEC_iterate(alias_pair, alias_pairs, i, p); i++)
+    emit_alias(p->decl, p->target);
+}
+
+/// llvm_finish_unit - Finish the .s file.  This is called by GCC once the
+/// compilation unit has been completely processed.
+static void llvm_finish_unit(void * /*gcc_data*/, void * /*user_data*/) {
+  if (errorcount || sorrycount)
+    return; // Do not process broken code.
+
+//TODO  timevar_push(TV_LLVM_PERFILE);
+  if (!quiet_flag)
+    errs() << "Finishing compilation unit\n";
+
+  InitializeBackend();
+
   LLVMContext &Context = getGlobalContext();
 
   createPerFunctionOptimizationPasses();
@@ -2210,6 +2215,13 @@
   register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
 #endif
 
+  // Output GCC global variables and aliases to the LLVM IR.  This needs to be
+  // done before the compilation unit is finished, since aliases are no longer
+  // available then.  On the other hand it seems wise to output them after the
+  // IPA passes have run, since these are the passes that modify globals.
+  register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_END, llvm_emit_globals,
+                    NULL);
+
   if (!EnableGCCOptimizations) {
     // Disable pass_lower_eh_dispatch, which runs after LLVM conversion.
     pass_info.pass = &pass_gimple_null.pass;





More information about the llvm-commits mailing list