[llvm-commits] [gcc-plugin] r82645 - in /gcc-plugin/trunk: llvm-backend.cpp llvm-convert.cpp

Duncan Sands baldrick at free.fr
Wed Sep 23 12:46:15 PDT 2009


Author: baldrick
Date: Wed Sep 23 14:46:15 2009
New Revision: 82645

URL: http://llvm.org/viewvc/llvm-project?rev=82645&view=rev
Log:
A static variable declared in a function may be initialized using
something (like the address of a label) that we only know about
when processing the function.  Do not try to output such globals
in the global variable emission pass.  Instead they will be output
when the function is processed.  In fact, don't bother outputting
any variables that are not externally visible.  Either they are
used by something else (eg: a function) and will be output when
that is processed, or they are not used at all in which case it
is pointless to output them.

Modified:
    gcc-plugin/trunk/llvm-backend.cpp
    gcc-plugin/trunk/llvm-convert.cpp

Modified: gcc-plugin/trunk/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-backend.cpp?rev=82645&r1=82644&r2=82645&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-backend.cpp (original)
+++ gcc-plugin/trunk/llvm-backend.cpp Wed Sep 23 14:46:15 2009
@@ -1720,13 +1720,17 @@
 }
 
 
-/// emit_variables - Turn GCC variables into LLVM IR.
+/// emit_variables - Output GCC global variables to the LLVM IR.
 static unsigned int emit_variables(void) {
   LazilyInitializeModule();
 
+  // Output all externally visible global variables, whether they are used in
+  // this compilation unit or not.  Global variables that are not externally
+  // visible will be output when their user is, or discarded if unused.
   struct varpool_node *vnode;
   FOR_EACH_STATIC_VARIABLE (vnode)
-    emit_global_to_llvm(vnode->decl);
+    if (TREE_PUBLIC(vnode->decl))
+      emit_global_to_llvm(vnode->decl);
 
   return 0;
 }

Modified: gcc-plugin/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-convert.cpp?rev=82645&r1=82644&r2=82645&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Wed Sep 23 14:46:15 2009
@@ -628,11 +628,9 @@
     // Not supported yet.
   }
 
-  // Emit all automatic variables.
+  // Emit any automatic or static variables.
   for (tree vars = DECL_STRUCT_FUNCTION(FnDecl)->local_decls; vars;
        vars = TREE_CHAIN(vars))
-    // Skip static variables and local variables listed multiple times.
-//    if (!TREE_STATIC(TREE_VALUE(vars))) // GCC PR41339
     if (!DECL_LLVM_SET_P(TREE_VALUE(vars)))
       EmitAutomaticVariableDecl(TREE_VALUE(vars));
 





More information about the llvm-commits mailing list