Blame SOURCES/gcc44-cloog-dl.patch

f28b6a
2009-01-27  Jakub Jelinek  <jakub@redhat.com>
f28b6a
f28b6a
	* Makefile.in (BACKENDLIBS): Link against -ldl instead of -lcloog -lppl.
f28b6a
	(graphite.o): Force -O, remove -fkeep-inline-functions.
f28b6a
	* graphite.c: Include <dlfcn.h>.  Reference libcloog and libppl symbols
f28b6a
	through pointers in cloog_pointers variable.
f28b6a
	(init_cloog_pointers): New function.
f28b6a
	(gcc_type_for_iv_of_clast_loop): Rename stmt_for argument to stmt_fora.
f28b6a
	(graphite_transform_loops): Call init_cloog_pointers.
f28b6a
f28b6a
--- gcc/Makefile.in.jj	2009-01-26 20:50:38.000000000 +0100
f28b6a
+++ gcc/Makefile.in	2009-01-27 14:18:10.000000000 +0100
f28b6a
@@ -915,7 +915,7 @@ BUILD_LIBDEPS= $(BUILD_LIBIBERTY)
f28b6a
 # How to link with both our special library facilities
f28b6a
 # and the system's installed libraries.
f28b6a
 LIBS = @LIBS@ $(CPPLIB) $(LIBINTL) $(LIBICONV) $(LIBIBERTY) $(LIBDECNUMBER)
f28b6a
-BACKENDLIBS = $(CLOOGLIBS) $(PPLLIBS) $(GMPLIBS)
f28b6a
+BACKENDLIBS = $(GMPLIBS) $(if $(CLOOGLIBS),-ldl)
f28b6a
 # Any system libraries needed just for GNAT.
f28b6a
 SYSLIBS = @GNAT_LIBEXC@
f28b6a
 
f28b6a
@@ -3076,6 +3076,9 @@ $(out_object_file): $(out_file) $(CONFIG
f28b6a
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) \
f28b6a
 		$(out_file) $(OUTPUT_OPTION)
f28b6a
 
f28b6a
+graphite.o : \
f28b6a
+  ALL_CFLAGS := -O $(filter-out -fkeep-inline-functions, $(ALL_CFLAGS))
f28b6a
+
f28b6a
 # Build auxiliary files that support ecoff format.
f28b6a
 mips-tfile: mips-tfile.o version.o $(LIBDEPS)
f28b6a
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ mips-tfile.o version.o $(LIBS)
f28b6a
--- gcc/graphite.c.jj	2009-01-24 19:59:02.000000000 +0100
f28b6a
+++ gcc/graphite.c	2009-01-27 14:52:08.000000000 +0100
f28b6a
@@ -59,6 +59,110 @@ along with GCC; see the file COPYING3.  
f28b6a
 #include "cloog/cloog.h"
f28b6a
 #include "graphite.h"
f28b6a
 
f28b6a
+#include <dlfcn.h>
f28b6a
+#define DYNSYMS \
f28b6a
+  DYNSYM (cloog_block_alloc); \
f28b6a
+  DYNSYM (cloog_block_list_free); \
f28b6a
+  DYNSYM (cloog_block_list_malloc); \
f28b6a
+  DYNSYM (cloog_clast_create); \
f28b6a
+  DYNSYM (cloog_clast_free); \
f28b6a
+  DYNSYM (cloog_domain_free); \
f28b6a
+  DYNSYM (cloog_domain_matrix2domain); \
f28b6a
+  DYNSYM (cloog_initialize); \
f28b6a
+  DYNSYM (cloog_loop_malloc); \
f28b6a
+  DYNSYM (cloog_matrix_alloc); \
f28b6a
+  DYNSYM (cloog_matrix_copy); \
f28b6a
+  DYNSYM (cloog_matrix_free); \
f28b6a
+  DYNSYM (cloog_matrix_print); \
f28b6a
+  DYNSYM (cloog_names_malloc); \
f28b6a
+  DYNSYM (cloog_names_scalarize); \
f28b6a
+  DYNSYM (cloog_options_free); \
f28b6a
+  DYNSYM (cloog_options_malloc); \
f28b6a
+  DYNSYM (cloog_program_dump_cloog); \
f28b6a
+  DYNSYM (cloog_program_extract_scalars); \
f28b6a
+  DYNSYM (cloog_program_free); \
f28b6a
+  DYNSYM (cloog_program_generate); \
f28b6a
+  DYNSYM (cloog_program_malloc); \
f28b6a
+  DYNSYM (cloog_program_print); \
f28b6a
+  DYNSYM (cloog_program_scatter); \
f28b6a
+  DYNSYM (cloog_statement_alloc); \
f28b6a
+  DYNSYM (ppl_finalize); \
f28b6a
+  DYNSYM (pprint); \
f28b6a
+  DYNSYM (stmt_block); \
f28b6a
+  DYNSYM (stmt_for); \
f28b6a
+  DYNSYM (stmt_guard); \
f28b6a
+  DYNSYM (stmt_root); \
f28b6a
+  DYNSYM (stmt_user);
f28b6a
+static struct
f28b6a
+{
f28b6a
+  bool inited;
f28b6a
+  void *h;
f28b6a
+#define DYNSYM(x) __typeof (x) *p_##x
f28b6a
+  DYNSYMS
f28b6a
+#undef DYNSYM
f28b6a
+} cloog_pointers;
f28b6a
+
f28b6a
+#define cloog_block_alloc (*cloog_pointers.p_cloog_block_alloc)
f28b6a
+#define cloog_block_list_free (*cloog_pointers.p_cloog_block_list_free)
f28b6a
+#define cloog_block_list_malloc (*cloog_pointers.p_cloog_block_list_malloc)
f28b6a
+#define cloog_clast_create (*cloog_pointers.p_cloog_clast_create)
f28b6a
+#define cloog_clast_free (*cloog_pointers.p_cloog_clast_free)
f28b6a
+#define cloog_domain_free (*cloog_pointers.p_cloog_domain_free)
f28b6a
+#define cloog_domain_matrix2domain (*cloog_pointers.p_cloog_domain_matrix2domain)
f28b6a
+#define cloog_initialize (*cloog_pointers.p_cloog_initialize)
f28b6a
+#define cloog_loop_malloc (*cloog_pointers.p_cloog_loop_malloc)
f28b6a
+#define cloog_matrix_alloc (*cloog_pointers.p_cloog_matrix_alloc)
f28b6a
+#define cloog_matrix_copy (*cloog_pointers.p_cloog_matrix_copy)
f28b6a
+#define cloog_matrix_free (*cloog_pointers.p_cloog_matrix_free)
f28b6a
+#define cloog_matrix_print (*cloog_pointers.p_cloog_matrix_print)
f28b6a
+#define cloog_names_malloc (*cloog_pointers.p_cloog_names_malloc)
f28b6a
+#define cloog_names_scalarize (*cloog_pointers.p_cloog_names_scalarize)
f28b6a
+#define cloog_options_free (*cloog_pointers.p_cloog_options_free)
f28b6a
+#define cloog_options_malloc (*cloog_pointers.p_cloog_options_malloc)
f28b6a
+#define cloog_program_dump_cloog (*cloog_pointers.p_cloog_program_dump_cloog)
f28b6a
+#define cloog_program_extract_scalars (*cloog_pointers.p_cloog_program_extract_scalars)
f28b6a
+#define cloog_program_free (*cloog_pointers.p_cloog_program_free)
f28b6a
+#define cloog_program_generate (*cloog_pointers.p_cloog_program_generate)
f28b6a
+#define cloog_program_malloc (*cloog_pointers.p_cloog_program_malloc)
f28b6a
+#define cloog_program_print (*cloog_pointers.p_cloog_program_print)
f28b6a
+#define cloog_program_scatter (*cloog_pointers.p_cloog_program_scatter)
f28b6a
+#define cloog_statement_alloc (*cloog_pointers.p_cloog_statement_alloc)
f28b6a
+#define ppl_finalize (*cloog_pointers.p_ppl_finalize)
f28b6a
+#define pprint (*cloog_pointers.p_pprint)
f28b6a
+#define stmt_block (*cloog_pointers.p_stmt_block)
f28b6a
+#define stmt_for (*cloog_pointers.p_stmt_for)
f28b6a
+#define stmt_guard (*cloog_pointers.p_stmt_guard)
f28b6a
+#define stmt_root (*cloog_pointers.p_stmt_root)
f28b6a
+#define stmt_user (*cloog_pointers.p_stmt_user)
f28b6a
+
f28b6a
+#define cloog_finalize (*cloog_pointers.p_ppl_finalize)
f28b6a
+
f28b6a
+static bool
f28b6a
+init_cloog_pointers (void)
f28b6a
+{
f28b6a
+  void *h;
f28b6a
+
f28b6a
+  if (cloog_pointers.inited)
f28b6a
+    return cloog_pointers.h != NULL;
f28b6a
+  h = dlopen ("libcloog.so.0", RTLD_LAZY);
f28b6a
+  cloog_pointers.h = h;
f28b6a
+  if (h == NULL)
f28b6a
+    return false;
f28b6a
+#define DYNSYM(x) \
f28b6a
+  do \
f28b6a
+    { \
f28b6a
+      union { __typeof (cloog_pointers.p_##x) p; void *q; } u; \
f28b6a
+      u.q = dlsym (h, #x); \
f28b6a
+      if (u.q == NULL) \
f28b6a
+	return false; \
f28b6a
+      cloog_pointers.p_##x = u.p; \
f28b6a
+    } \
f28b6a
+  while (0)
f28b6a
+  DYNSYMS
f28b6a
+#undef DYNSYM
f28b6a
+  return true;
f28b6a
+}
f28b6a
+
f28b6a
 static VEC (scop_p, heap) *current_scops;
f28b6a
 
f28b6a
 /* Converts a GMP constant V to a tree and returns it.  */
f28b6a
@@ -4019,10 +4151,10 @@ clast_get_body_of_loop (struct clast_stm
f28b6a
    STMT.  */
f28b6a
 
f28b6a
 static tree
f28b6a
-gcc_type_for_iv_of_clast_loop (struct clast_for *stmt_for)
f28b6a
+gcc_type_for_iv_of_clast_loop (struct clast_for *stmt_fora)
f28b6a
 {
f28b6a
-  struct clast_user_stmt *stmt = clast_get_body_of_loop ((struct clast_stmt *) stmt_for);
f28b6a
-  const char *cloog_iv = stmt_for->iterator;
f28b6a
+  struct clast_user_stmt *stmt = clast_get_body_of_loop ((struct clast_stmt *) stmt_fora);
f28b6a
+  const char *cloog_iv = stmt_fora->iterator;
f28b6a
   CloogStatement *cs = stmt->statement;
f28b6a
   graphite_bb_p gbb = (graphite_bb_p) cloog_statement_usr (cs);
f28b6a
 
f28b6a
@@ -6061,6 +6193,12 @@ graphite_transform_loops (void)
f28b6a
   if (number_of_loops () <= 1)
f28b6a
     return;
f28b6a
 
f28b6a
+  if (!init_cloog_pointers ())
f28b6a
+    {
f28b6a
+      sorry ("Graphite loop optimizations cannot be used");
f28b6a
+      return;
f28b6a
+    }
f28b6a
+
f28b6a
   current_scops = VEC_alloc (scop_p, heap, 3);
f28b6a
   recompute_all_dominators ();
f28b6a