[llvm-commits] [gcc-plugin] r80797 - in /gcc-plugin/trunk: TODO llvm-backend.cpp

Duncan Sands baldrick at free.fr
Wed Sep 2 08:56:00 PDT 2009


Author: baldrick
Date: Wed Sep  2 10:55:59 2009
New Revision: 80797

URL: http://llvm.org/viewvc/llvm-project?rev=80797&view=rev
Log:
Make sure the garbage collector doesn't blow away
our cache by registering it as a GC root.  (Using
GC memory for this cache may seem useless, but this
is needed for the later step of having the GC auto
remove deleted trees used as keys).  Functions are
garbage collected after we turn them into LLVM IR
(not immediately, because they are still pointed
to by current_function_decl and cfun, but during
the GC run scheduled after the following function
is emitted), but only if the GC thinks it is under
memory pressure.  Add a note to teach the GC about
LLVM memory allocations.

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

Modified: gcc-plugin/trunk/TODO
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/TODO?rev=80797&r1=80796&r2=80797&view=diff

==============================================================================
--- gcc-plugin/trunk/TODO (original)
+++ gcc-plugin/trunk/TODO Wed Sep  2 10:55:59 2009
@@ -30,3 +30,16 @@
 
 Teach the build system that the plugin needs to be rebuilt if any of the bits of
 LLVM/gcc it depends on changes.
+
+
+Memory management
+-----------------
+
+After we codegen them, GCC functions will be garbage collected if the garbage
+collector runs.  However the garbage collector is only run if lots of memory
+was allocated since the last run.  GCC doesn't know how much memory LLVM is
+allocating, so we may be allocating vast amounts of LLVM memory converting
+gimple into LLVM IR, but nonetheless the garbage collector won't free up GCC
+memory for us, even though there might be lots of memory to free.  Work out
+some way of teaching the garbage collector about the amount of memory allocated
+by LLVM.

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

==============================================================================
--- gcc-plugin/trunk/llvm-backend.cpp (original)
+++ gcc-plugin/trunk/llvm-backend.cpp Wed Sep  2 10:55:59 2009
@@ -1864,7 +1864,7 @@
   // Finally, we have written out this function!
   TREE_ASM_WRITTEN(current_function_decl) = 1;
 
-  execute_free_datastructures ();
+  execute_free_datastructures();
 
   // When debugging, append the LLVM IR to the dump file.
   if (dump_file) {
@@ -2079,6 +2079,10 @@
 };
 
 
+// Garbage collector roots.
+extern const struct ggc_root_tab gt_pch_rc__gt_llvm_cache_h[];
+
+
 /// llvm_plugin_info - Information about this plugin.  Users can access this
 /// using "gcc --help -v".
 static struct plugin_info llvm_plugin_info = {
@@ -2132,6 +2136,10 @@
   // writing anything at all to the assembly file - only we get to write to it.
   TakeoverAsmOutput();
 
+  // Register our garbage collector roots.
+  register_callback (plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL,
+                     (void *)gt_pch_rc__gt_llvm_cache_h);
+
   // Perform late initialization just before processing the compilation unit.
   register_callback (plugin_name, PLUGIN_START_UNIT, llvm_start_unit, NULL);
 





More information about the llvm-commits mailing list