[compiler-rt] r177436 - Add a way to register and execute "writeout" functions.

Bill Wendling isanbard at gmail.com
Tue Mar 19 14:01:19 PDT 2013


Author: void
Date: Tue Mar 19 16:01:19 2013
New Revision: 177436

URL: http://llvm.org/viewvc/llvm-project?rev=177436&view=rev
Log:
Add a way to register and execute "writeout" functions.

It may be prohibitively expensive to write out >1000 files at the same time. So
we would rather emit them serially. These functions allow the GCOV
implementation to register the functions that writeout the GCOV information per
compile unit. At exit, they are written.
<rdar://problem/12439551>

Modified:
    compiler-rt/trunk/lib/profile/GCDAProfiling.c

Modified: compiler-rt/trunk/lib/profile/GCDAProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/GCDAProfiling.c?rev=177436&r1=177435&r2=177436&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/GCDAProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/GCDAProfiling.c Tue Mar 19 16:01:19 2013
@@ -48,6 +48,19 @@ typedef unsigned int uint64_t;
 static FILE *output_file = NULL;
 
 /*
+ * A list of functions to write out the data.
+ */
+typedef void (*writeout_fn)();
+
+struct writeout_fn_node {
+  writeout_fn fn;
+  struct writeout_fn_node *next;
+};
+
+struct writeout_fn_node *writeout_fn_head = NULL;
+struct writeout_fn_node *writeout_fn_tail = NULL;
+
+/*
  *  A list of flush functions that our __gcov_flush() function should call.
  */
 typedef void (*flush_fn)();
@@ -305,6 +318,38 @@ void llvm_gcda_end_file() {
 #endif
 }
 
+void llvm_register_writeout_function(writeout_fn fn) {
+  struct writeout_fn_node *new_node = malloc(sizeof(struct writeout_fn_node));
+  new_node->fn = fn;
+  new_node->next = NULL;
+
+  if (!writeout_fn_head) {
+    writeout_fn_head = writeout_fn_tail = new_node;
+  } else {
+    writeout_fn_tail->next = new_node;
+    writeout_fn_tail = new_node;
+  }
+}
+
+void __llvm_writeout_files() {
+  struct writeout_fn_node *curr = writeout_fn_head;
+
+  while (curr) {
+    curr->fn();
+    curr = curr->next;
+  }
+}
+
+void llvm_delete_writeout_function_list() {
+  while (writeout_fn_head) {
+    struct writeout_fn_node *node = writeout_fn_head;
+    writeout_fn_head = writeout_fn_head->next;
+    free(node);
+  }
+  
+  writeout_fn_head = writeout_fn_tail = NULL;
+}
+
 void llvm_register_flush_function(flush_fn fn) {
   struct flush_fn_node *new_node = malloc(sizeof(struct flush_fn_node));
   new_node->fn = fn;





More information about the llvm-commits mailing list