[llvm-commits] [gcc-plugin] r80379 - in /gcc-plugin/trunk: bits_and_bobs.cpp bits_and_bobs.h llvm-backend.cpp

Duncan Sands baldrick at free.fr
Fri Aug 28 10:14:20 PDT 2009


Author: baldrick
Date: Fri Aug 28 12:14:20 2009
New Revision: 80379

URL: http://llvm.org/viewvc/llvm-project?rev=80379&view=rev
Log:
Actually output global variables by calling emit_global_to_llvm.
This requires having DECL_LLVM call make_decl_llvm, so hook this
up in a quick and nasty way (will do better later).

Modified:
    gcc-plugin/trunk/bits_and_bobs.cpp
    gcc-plugin/trunk/bits_and_bobs.h
    gcc-plugin/trunk/llvm-backend.cpp

Modified: gcc-plugin/trunk/bits_and_bobs.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/bits_and_bobs.cpp?rev=80379&r1=80378&r2=80379&view=diff

==============================================================================
--- gcc-plugin/trunk/bits_and_bobs.cpp (original)
+++ gcc-plugin/trunk/bits_and_bobs.cpp Fri Aug 28 12:14:20 2009
@@ -25,14 +25,19 @@
 
 bool flag_odr = false;
 
-void llvm_set_decl (tree t, Value *V) {
+Value *llvm_set_decl (tree t, Value *V) {
   assert(HAS_RTL_P(t) && "Expected a gcc decl with RTL!");
   llvm_set_cached(t, V);
+  return V;
 }
 
+extern Value *make_decl_llvm(tree decl);
+
 Value *llvm_get_decl(tree t) {
   assert(HAS_RTL_P(t) && "Expected a gcc decl with RTL!");
-  return (Value *)llvm_get_cached(t);
+  if (Value *V = (Value *)llvm_get_cached(t))
+    return V;
+  return make_decl_llvm(t);
 }
 
 bool llvm_set_decl_p(tree t) {

Modified: gcc-plugin/trunk/bits_and_bobs.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/bits_and_bobs.h?rev=80379&r1=80378&r2=80379&view=diff

==============================================================================
--- gcc-plugin/trunk/bits_and_bobs.h (original)
+++ gcc-plugin/trunk/bits_and_bobs.h Fri Aug 28 12:14:20 2009
@@ -6,7 +6,7 @@
 
 namespace llvm { class Value; }
 
-extern void llvm_set_decl (union tree_node *, Value *);
+extern Value *llvm_set_decl (union tree_node *, Value *);
 extern Value *llvm_get_decl(union tree_node *);
 #define DECL_LLVM(NODE) (llvm_get_decl(NODE))
 #define SET_DECL_LLVM(NODE, LLVM) (llvm_set_decl (NODE,LLVM))

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

==============================================================================
--- gcc-plugin/trunk/llvm-backend.cpp (original)
+++ gcc-plugin/trunk/llvm-backend.cpp Fri Aug 28 12:14:20 2009
@@ -87,6 +87,9 @@
 #include "llvm-debug.h"
 #include "llvm-target.h"
 #include "bits_and_bobs.h"
+extern "C" {
+#include "llvm-cache.h"
+}
 
 // Non-zero if bytecode from PCH is successfully read.
 int flag_llvm_pch_read;
@@ -1439,7 +1442,7 @@
 ///
 /// This function corresponds to make_decl_rtl in varasm.c, and is implicitly
 /// called by DECL_LLVM if a decl doesn't have an LLVM set.
-void make_decl_llvm(tree decl) {
+Value *make_decl_llvm(tree decl) {
 #ifdef ENABLE_CHECKING
   // Check that we are not being given an automatic variable.
   // A weak alias has TREE_PUBLIC set but not the other bits.
@@ -1456,10 +1459,11 @@
   
   // For a duplicate declaration, we can be called twice on the
   // same DECL node.  Don't discard the LLVM already made.
-  if (DECL_LLVM_SET_P(decl)) return;
+  if (Value *V = (Value *)llvm_get_cached(decl))
+    return V;
 
   if (errorcount || sorrycount)
-    return;  // Do not process broken code.
+    return NULL;  // Do not process broken code.
   
   
   // Global register variable with asm name, e.g.:
@@ -1468,7 +1472,7 @@
     // This  just verifies that the variable is ok.  The actual "load/store"
     // code paths handle accesses to the variable.
     ValidateRegisterVariable(decl);
-    return;
+    return NULL;
   }
   
 //TODO  timevar_push(TV_LLVM_GLOBALS);
@@ -1550,7 +1554,7 @@
         G->eraseFromParent();
       }
     }
-    SET_DECL_LLVM(decl, FnEntry);
+    return SET_DECL_LLVM(decl, FnEntry);
   } else {
     assert((TREE_CODE(decl) == VAR_DECL ||
             TREE_CODE(decl) == CONST_DECL) && "Not a function or var decl?");
@@ -1646,7 +1650,7 @@
     if (TREE_CODE(decl) == VAR_DECL && DECL_THREAD_LOCAL_P(decl))
       GV->setThreadLocal(true);
 
-    SET_DECL_LLVM(decl, GV);
+    return SET_DECL_LLVM(decl, GV);
   }
 //TODO  timevar_pop(TV_LLVM_GLOBALS);
 }
@@ -1799,12 +1803,6 @@
 }
 
 
-/// emit_variable - Turn a GCC variable into LLVM IR.  This is called by GCC
-/// once for each variable in the compilation unit.
-static void emit_variable(tree decl) {
-  debug_tree(decl);
-}
-
 /// emit_variables - Turn GCC variables into LLVM IR.
 static unsigned int emit_variables(void) {
   if (!quiet_flag)
@@ -1814,7 +1812,7 @@
 
   struct varpool_node *vnode;
   FOR_EACH_STATIC_VARIABLE (vnode)
-    emit_variable(vnode->decl);
+    emit_global_to_llvm(vnode->decl);
 
   return 0;
 }
@@ -2148,8 +2146,8 @@
   // Perform late initialization just before processing the compilation unit.
   register_callback (plugin_name, PLUGIN_START_UNIT, llvm_start_unit, NULL);
 
-  // Add an ipa pass that emits global variables.  This causes emit_variable to
-  // be called for each GCC static variable.
+  // Add an ipa pass that emits global variables, calling emit_global_to_llvm
+  // for each GCC static variable.
   pass_info.pass = &pass_emit_variables.pass;
   pass_info.reference_pass_name = "matrix-reorg";
   pass_info.ref_pass_instance_number = 0;





More information about the llvm-commits mailing list